Updated code

This commit is contained in:
Th3maz1ng 2021-04-04 22:50:51 +02:00
parent 9b6a8e3d56
commit 272eaff9ba
4 changed files with 168 additions and 6 deletions

View File

@ -6,7 +6,7 @@
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-93366929328412182" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-151908837636153822" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
@ -18,7 +18,7 @@
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-93366929328412182" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-151908837636153822" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>

View File

@ -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)

View File

@ -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;
}

View File

@ -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