/* * app.c * * Created on: Apr 3, 2021 * Author: Think */ #include #include #include #include #include "app.h" #include "stm32f4xx_hal.h" #include "CS43L22.h" #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); 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) { if(HAL_GetTick() - ts_blink > HEARTBEAT) { HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_13); if(!CS43L22_GetDeviceID(&cs43l22, &chipID, &revID)) printf("Failed to retrieve CS43L22 ID\r\n"); else printf("Device id : %u, revID : %u\r\n", chipID, revID); dacRegDump(); ts_blink = HAL_GetTick(); } }