diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index a2794c4..b6cbcbe 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -6,7 +6,7 @@ - + @@ -18,7 +18,7 @@ - + diff --git a/Core/Src/app.c b/Core/Src/app.c index 1f6c9bc..ab7cc70 100644 --- a/Core/Src/app.c +++ b/Core/Src/app.c @@ -15,17 +15,70 @@ #define HEARTBEAT 1000 extern I2C_HandleTypeDef hi2c1; +extern I2S_HandleTypeDef hi2s3; CS43L22 cs43l22; GPIO_InitTypeDef heartBeatLed = {.Pin = GPIO_PIN_13, .Mode = GPIO_MODE_OUTPUT_PP, .Speed = GPIO_SPEED_LOW}; uint32_t ts_blink = 0; uint8_t chipID = 0, revID = 0; +uint16_t data = 0; + +void dacRegDump() +{ + uint8_t regDump[CS43L22_RESGISTER_COUNT] = {0}; + if(!CS43L22_RegisterDump(&cs43l22, regDump)) + printf("Failed to dump registers\r\n"); + else + { + printf("CS43L22 Register dump :\r\n"); + for(int i = 0; i < CS43L22_RESGISTER_COUNT / 3; i++) + { + printf("%#X = %#X, %#X = %#X, %#X = %#X\r\n", CS43L22_GetRegisterArray()[i*3], regDump[i*3] + , CS43L22_GetRegisterArray()[i*3 + 1], regDump[i*3 + 1] + , CS43L22_GetRegisterArray()[i*3 + 2], regDump[i*3 + 2]); + } + } +} void setup(void) { HAL_GPIO_Init(GPIOD, &heartBeatLed); - CS43L22_Init(&cs43l22, &hi2c1); + + if(!CS43L22_Init(&cs43l22, &hi2c1)) + printf("Failed to init DAC\r\n"); + + dacRegDump(); + //We disable the DAC + if(!CS43L22_WriteRegister(&cs43l22, POWER_CTL_1, 0b00000001)) + printf("Fail POWER_CTL_1\r\n"); + + //We set the auto clocking + if(!CS43L22_WriteRegister(&cs43l22, CLOCKING_CTL, 0b10000001)) + printf("Fail CLOCKING_CTL\r\n"); + + //... + if(!CS43L22_WriteRegister(&cs43l22, INTERFACE_CTL_1, 0b00000100)) + printf("Fail POWER_CTL_1\r\n"); + + if(!CS43L22_WriteRegister(&cs43l22, POWER_CTL_2, 0b10101111)) + printf("Fail POWER_CTL_2\r\n"); + + //We set the frequency + if(!CS43L22_WriteRegister(&cs43l22, BEEP_FREQ_ON_TIME, 0b00010000)) + printf("Fail BEEP_FREQ_ON_TIME\r\n"); + + //We set the volume + if(!CS43L22_WriteRegister(&cs43l22, BEEP_VOL_OFF_TIME, 0b00000110)) + printf("Fail BEEP_VOL_OFF_TIME\r\n"); + + //We activate the beep to continuous + if(!CS43L22_WriteRegister(&cs43l22, BEEP_TONE_CFG, 0b11100000)) + printf("Fail BEEP_TONE_CFG\r\n"); + + //We enable the DAC + if(!CS43L22_WriteRegister(&cs43l22, POWER_CTL_1, 0b10011110)) + printf("Fail POWER_CTL_1\r\n"); } void loop(void) diff --git a/Drivers/CS43L22/CS43L22.c b/Drivers/CS43L22/CS43L22.c index 3389bf6..4722356 100644 --- a/Drivers/CS43L22/CS43L22.c +++ b/Drivers/CS43L22/CS43L22.c @@ -9,8 +9,60 @@ //CS43L22 I2C address static const uint8_t CS43L22_ADDR = 0x4A << 1; -//CS43L22 register definition -static const uint8_t _ID = 0x01; +//CS43L22 register address array for easy register dump.. +static const uint8_t REG_ARRAY[CS43L22_RESGISTER_COUNT] = {0x01, 0x02, 0x04, + 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, + 0x0C, 0x0D, 0x0E, + 0x0F, 0x14, 0x15, + 0x1A, 0x1B, 0x1C, + 0x1D, 0x1E, 0x1F, + 0x20, 0x21, 0x22, + 0x23, 0x24, 0x25, + 0x26, 0x27, 0x28, + 0x29, 0x2E, 0x2F, + 0x30, 0x31, 0x34}; + +//CS43L22 36 register definition enum +typedef enum +{ + _ID = 0, + _POWER_CTL_1, + _POWER_CTL_2, + _CLOCKING_CTL, + _INTERFACE_CTL_1, + _INTERFACE_CTL_2, + _PASSTHROUGH_A_SELECT, + _PASSTHROUGH_B_SELECT, + _ANALOG_ZC_AND_SR_SETTING, + _PASSTHROUGH_GANG_CONTROL, + _PLAYBACK_CTL_1, + _MISC_CTL, + _PLAYBACK_CTL_2, + _PASSTHROUGH_A_VOL, + _PASSTHROUGH_B_VOL, + _PCMA_VOL, + _PCMB_VOL, + _BEEP_FREQ_ON_TIME, + _BEEP_VOL_OFF_TIME, + _BEEP_TONE_CFG, + _TONE_CTL, + _MASTER_A_VOL, + _MASTER_B_VOL, + _HEADPHONE_A_VOLUME, + _HEADPHONE_B_VOLUME, + _SPEAKER_A_VOLUME, + _SPEAKER_B_VOLUME, + _CHANNEL_MIXER_AND_SWAP, + _LIMIT_CTL_1_THRESHOLDS, + _LIMIT_CTL_2_THRESHOLDS, + _LIMITER_ATTACK_RATE, + _OVERFLOW_AND_CLOCK_STATUS, + _BATTERY_COMPENSATION, + _VP_BATTERY_LEVEL, + _SPEAKER_STATUS, + _CHARGE_PUMP_FREQUENCY, +} CS43L22_REGISTER_e; //Driver function definition bool CS43L22_Init(CS43L22 *device, I2C_HandleTypeDef *i2cHandler) @@ -23,6 +75,11 @@ bool CS43L22_Init(CS43L22 *device, I2C_HandleTypeDef *i2cHandler) return true; } +const uint8_t * const CS43L22_GetRegisterArray(void) +{ + return REG_ARRAY; +} + bool CS43L22_Reset(CS43L22 *device) { HAL_GPIO_WritePin(GPIOD, GPIO_PIN_4, GPIO_PIN_RESET); @@ -56,3 +113,17 @@ bool CS43L22_WriteRegister(CS43L22 *device, uint8_t registerAddr, uint8_t data) uint8_t regAndData[] = {registerAddr, data}; return HAL_I2C_Master_Transmit(device->i2cHandler, CS43L22_ADDR, regAndData, 2, HAL_MAX_DELAY) == HAL_OK ? true : false; } + +bool CS43L22_RegisterDump(CS43L22 *device, uint8_t registers[36]) +{ + if(!registers) + return false; + + for(uint8_t i = 0; i < sizeof(REG_ARRAY); i++) + { + if(!CS43L22_ReadRegister(device, REG_ARRAY[i], registers + i)) + return false; + } + + return true; +} diff --git a/Drivers/CS43L22/CS43L22.h b/Drivers/CS43L22/CS43L22.h index b118852..1374c02 100644 --- a/Drivers/CS43L22/CS43L22.h +++ b/Drivers/CS43L22/CS43L22.h @@ -12,8 +12,44 @@ #include "stm32f4xx_hal.h" #include "MY_TYPES.h" -//CS43L22 register definition +#define CS43L22_RESGISTER_COUNT 36 +//CS43L22 register definitio #define ID 0x01 +#define POWER_CTL_1 0x02 +#define POWER_CTL_2 0x04 +#define CLOCKING_CTL 0x05 +#define INTERFACE_CTL_1 0x06 +#define INTERFACE_CTL_2 0x07 +#define PASSTHROUGH_A_SELECT 0x08 +#define PASSTHROUGH_B_SELECT 0x09 +#define ANALOG_ZC_AND_SR_SETTING 0x0A +#define PASSTHROUGH_GANG_CONTROL 0x0C +#define PLAYBACK_CTL_1 0x0D +#define MISC_CTL 0x0E +#define PLAYBACK_CTL_2 0x0F +#define PASSTHROUGH_A_VOL 0x14 +#define PASSTHROUGH_B_VOL 0x15 +#define PCMA_VOL 0x1A +#define PCMB_VOL 0x1B +#define BEEP_FREQ_ON_TIME 0x1C +#define BEEP_VOL_OFF_TIME 0x1D +#define BEEP_TONE_CFG 0x1E +#define TONE_CTL 0x1F +#define MASTER_A_VOL 0x20 +#define MASTER_B_VOL 0x21 +#define HEADPHONE_A_VOLUME 0x22 +#define HEADPHONE_B_VOLUME 0x23 +#define SPEAKER_A_VOLUME 0x24 +#define SPEAKER_B_VOLUME 0x25 +#define CHANNEL_MIXER_AND_SWAP 0x26 +#define LIMIT_CTL_1_THRESHOLDS 0x27 +#define LIMIT_CTL_2_THRESHOLDS 0x28 +#define LIMITER_ATTACK_RATE 0x29 +#define OVERFLOW_AND_CLOCK_STATUS 0x2E +#define BATTERY_COMPENSATION 0x2F +#define VP_BATTERY_LEVEL 0x30 +#define SPEAKER_STATUS 0x31 +#define CHARGE_PUMP_FREQUENCY 0x34 //CS43L22 Structure typedef struct @@ -23,11 +59,13 @@ typedef struct //Driver function declaration bool CS43L22_Init(CS43L22 *device, I2C_HandleTypeDef *i2cHandler); +const uint8_t * const CS43L22_GetRegisterArray(void); bool CS43L22_Reset(CS43L22 *device); bool CS43L22_ApplyConfig(CS43L22 *device); bool CS43L22_GetDeviceID(CS43L22 *device, uint8_t *chipID, uint8_t *chipREVID); bool CS43L22_ReadRegister(CS43L22 *device, uint8_t registerAddr, uint8_t *data); bool CS43L22_WriteRegister(CS43L22 *device, uint8_t registerAddr, uint8_t data); +bool CS43L22_RegisterDump(CS43L22 *device, uint8_t registers[36]); #endif //CS43L22_H