K1Guitar/device/AD85020B/Drv_AD85020B.h

84 lines
3.7 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* @Author: CTW
* @Date: 2025-11-07 14:37:14
* @FilePath: \PhoenixSMGT_Testproject\Drivers\AD85050\Drv_AD85020B.h
* @note: 从 STM32 HAL 库移植到 AT32F403A。
* 同时保留两套 I2C 实现(硬件 I2C1 / 软件 GPIO 模拟),用宏切换。
*/
#ifndef __DRV_AD85020B_H
#define __DRV_AD85020B_H
#include <stdint.h>
#include "at32f403a_407.h"
/* ================= I2C 实现选择 =================
1 = 硬件 I2C1(默认,走官方 i2c_application 库,PB6=SCL/PB7=SDA)
0 = 软件 I2C(GPIO 位翻转,不依赖硬件 I2C 外设)
两套实现都保留在 Drv_AD85020B.c 里,改这个宏即可切换 */
#define AD85020B_I2C_USE_HW 1
/* I2C 引脚:PB6 = SCL,PB7 = SDA */
#define AD85020B_I2C_PORT GPIOB
#define AD85020B_SCL_PIN GPIO_PINS_6
#define AD85020B_SDA_PIN GPIO_PINS_7
/* 器件 7 位地址:SA0=0、SA1=0 → 0x30
硬件 I2C:官方库 i2c_memory_write/read 期望 8 位格式地址(=7位<<1),传 0x60
软件 I2C:字节 = 7位<<1 | R/W,写 0x60 / 读 0x61 */
#define AD85020B_I2C_ADDR 0x30 /* 7 位地址 */
#define AD85020B_I2C_ADDR_W 0x60 /* 写地址(8 位格式) */
#define AD85020B_I2C_ADDR_R 0x61 /* 读地址(8 位格式) */
/* 硬件 I2C 轮询超时 */
#define AD85020B_I2C_TIMEOUT 1000
/* 寄存器地址(文档直接提取) */
#define AD85020B_REG_SCTL6 0x1A // 软件复位寄存器
#define AD85020B_REG_SCTL1 0x00 // 输入格式配置
#define AD85020B_REG_SCTL2 0x01 // 采样率配置
#define AD85020B_REG_SCTL3 0x02 // 静音控制
#define AD85020B_REG_MVOL 0x03 // 主音量控制
#define AD85020B_REG_SCTL4 0x0C /* EQ / DEQ / 音调;样机 0x90:EQ 开、左右独立 */
#define AD85020B_SCTL4_PROTO_EQ 0x90
#define AD85020B_REG_HEADPHONEVOL 0x87 // 耳机音量控制
/* 系数 RAM 间接访问(手册 0x1D~0x2D)
寄存器表 CFA 为 8 位;RAM 图地址到 0xB0。按样机抓包把完整地址写入 0x1D。 */
#define AD85020B_REG_CFA 0x1D /* CFA[7:0] RAM 基址 */
#define AD85020B_REG_A1_T 0x1E /* 系数 top [23:16] */
#define AD85020B_REG_A1_M 0x1F /* 系数 middle [15:8] */
#define AD85020B_REG_A1_B 0x20 /* 系数 bottom [7:0] */
#define AD85020B_REG_CFRW 0x2D /* CfRW 读写触发 */
#define AD85020B_CFRW_W1 0x01 /* 写单系数 */
#define AD85020B_CFRW_WA 0x02
#define AD85020B_CFRW_R1 0x04 /* 读单系数 */
#define AD85020B_CFRW_RA 0x08
#define AD85020B_CFRW_W3 0x10
#define AD85020B_CFRW_R3 0x20
#define AD85020B_CFRW_RBS 0x40 /* 0=bank0/CH1, 1=bank1/CH2 */
#define AD85020B_RAM_CH2_EQ16_A1 0xA0 /* CH2EQ16A1 */
#define AD85020B_RAM_CH2_EQ18_A0 0xAE /* CH2EQ18A0 */
/* 软件复位配置:SCTL6寄存器BIT5=SW_RSTB,0=复位,1=正常 */
#define AD85020B_SW_RESET 0x50 // BIT5=0(0x50二进制1010000,BIT5=0)
#define AD85020B_SW_NORMAL 0x70 // BIT5=1(复位后恢复正常)
/* 返回值类型 */
typedef enum
{
AD85020B_OK = 0,
AD85020B_ERROR = 1,
AD85020B_TIMEOUT = 2
} AD85020B_StatusTypeDef;
/* 函数声明(两模式共用接口,内部按 AD85020B_I2C_USE_HW 分发) */
void AD85020B_I2C_Init(void);
AD85020B_StatusTypeDef AD85020B_I2C_Write(uint8_t reg, uint8_t data);
AD85020B_StatusTypeDef AD85020B_I2C_Read(uint8_t reg, uint8_t *data);
AD85020B_StatusTypeDef AD85020B_RamWrite24(uint8_t ram_addr, uint8_t bank, uint32_t value);
AD85020B_StatusTypeDef AD85020B_RamRead24(uint8_t ram_addr, uint8_t bank, uint32_t *value);
AD85020B_StatusTypeDef AD85020B_Init(void);
#endif