K1Guitar/device/AD85020B/Drv_AD85020B.h

62 lines
2.4 KiB
C
Raw Permalink 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 = 软件 I2CGPIO 位翻转,不依赖硬件 I2C 外设)
两套实现都保留在 Drv_AD85020B.c 里,改这个宏即可切换 */
#define AD85020B_I2C_USE_HW 1
/* I2C 引脚PB6 = SCLPB7 = 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_HEADPHONEVOL 0x87 // 耳机音量控制
/* 软件复位配置SCTL6寄存器BIT5=SW_RSTB0=复位1=正常 */
#define AD85020B_SW_RESET 0x50 // BIT5=00x50二进制1010000BIT5=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_Init(void);
#endif