From 13db07642e46df6c38f81642ade7a8e23a6edb45 Mon Sep 17 00:00:00 2001 From: hasslesstech Date: Sun, 9 Mar 2025 15:24:26 +0200 Subject: [PATCH] add CS43L22 Audio chip testing functions --- Core/Inc/CS43L22.h | 7 +++++ Core/Src/CS43L22.c | 67 ++++++++++++++++++++++++++++++++++++++++ Core/Src/main.c | 30 +++++++++++------- Debug/Core/Src/subdir.mk | 5 ++- Debug/objects.list | 1 + test1.ioc | 15 +++++---- 6 files changed, 106 insertions(+), 19 deletions(-) create mode 100644 Core/Inc/CS43L22.h create mode 100644 Core/Src/CS43L22.c diff --git a/Core/Inc/CS43L22.h b/Core/Inc/CS43L22.h new file mode 100644 index 0000000..ebe3c1c --- /dev/null +++ b/Core/Inc/CS43L22.h @@ -0,0 +1,7 @@ +#ifndef __CS43L22 +#define __CS43L22 + +void CS43L22_run_test(void); +void CS43L22_cleanup(void); + +#endif diff --git a/Core/Src/CS43L22.c b/Core/Src/CS43L22.c new file mode 100644 index 0000000..9b00e4d --- /dev/null +++ b/Core/Src/CS43L22.c @@ -0,0 +1,67 @@ +#include "main.h" +#include "lcd.h" +#include "CS43L22.h" + +extern I2C_HandleTypeDef hi2c1; + +void CS43L22_run_test(void) +{ + DISPLAY_CLEAR; + display_write_data_seq("CS43L22 Audio"); + + HAL_StatusTypeDef op_result; + size_t err_count = 0; + + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_4, GPIO_PIN_SET); + + uint8_t data_buffer[2] = {0x0D, 0x01}; + + for (size_t t = 0; t < 5; t++) { + op_result = HAL_I2C_Master_Transmit(&hi2c1, 0x94, data_buffer, 2, 2000); + + if (op_result) { + err_count++; + + DISPLAY_CLEAR; + display_write_data_seq("CS43L22 Audio"); + + DISPLAY_SET_CURSOR(1, 0); + display_write_data_seq("W "); + display_write_data_byte('1' + t); + display_write_data_seq("/5 "); + + switch (op_result) { + case HAL_ERROR: + display_write_data_seq("ERROR"); + break; + case HAL_BUSY: + display_write_data_seq("BUSY"); + break; + case HAL_TIMEOUT: + display_write_data_seq("TIMEOUT"); + break; + } + + HAL_Delay(2000); + } else { + break; + } + } + + DISPLAY_CLEAR; + display_write_data_seq("CS43L22 Audio"); + + if (err_count) { + DISPLAY_SET_CURSOR(1, 1); + display_write_data_byte('0' + err_count % 10); + display_write_data_seq(" Errors"); + } else { + DISPLAY_SET_CURSOR(1, 1); + display_write_data_seq("OK"); + } +} + +void CS43L22_cleanup(void) +{ + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_4, GPIO_PIN_RESET); +} diff --git a/Core/Src/main.c b/Core/Src/main.c index 5e256f0..0cdbf32 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -27,6 +27,7 @@ #include "DNI.h" #include "PCA9685.h" #include "24AA02E48.h" +#include "CS43L22.h" /* USER CODE END Includes */ @@ -59,17 +60,19 @@ void ((*executors[])(void)) = { DNI_show_celsius, DNI_show_fahrenheit, PCA9685_run_test, - EEPROM_24AA02E48_run_test + EEPROM_24AA02E48_run_test, + CS43L22_run_test }; void ((*cleanup_functions[])(void)) = { NULL, NULL, PCA9685_cleanup, - NULL + NULL, + CS43L22_cleanup }; -int delay_between_runs[] = {250, 250, -1, -1}; +int delay_between_runs[] = {250, 250, -1, -1, -1}; size_t current_executor_id = 0; @@ -89,6 +92,12 @@ static void MX_I2C1_Init(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ +void switch_to_next_test(void) +{ + current_executor_id += 1; + current_executor_id %= 5; +} + void buttons_switch_to_interrupt(void) { // save current executor ID @@ -209,12 +218,6 @@ void button_init_and_test(void) HAL_Delay(200); } -void switch_to_next_test(void) -{ - current_executor_id += 1; - current_executor_id %= 4; -} - /* USER CODE END 0 */ /** @@ -443,7 +446,8 @@ static void MX_GPIO_Init(void) |GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15 + |GPIO_PIN_4, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_RESET); @@ -463,8 +467,10 @@ static void MX_GPIO_Init(void) GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); - /*Configure GPIO pins : PD12 PD13 PD14 PD15 */ - GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15; + /*Configure GPIO pins : PD12 PD13 PD14 PD15 + PD4 */ + GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15 + |GPIO_PIN_4; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; diff --git a/Debug/Core/Src/subdir.mk b/Debug/Core/Src/subdir.mk index 3037b60..de6e5de 100644 --- a/Debug/Core/Src/subdir.mk +++ b/Debug/Core/Src/subdir.mk @@ -6,6 +6,7 @@ # Add inputs and outputs from these tool invocations to the build variables C_SRCS += \ ../Core/Src/24AA02E48.c \ +../Core/Src/CS43L22.c \ ../Core/Src/DNI.c \ ../Core/Src/PCA9685.c \ ../Core/Src/lcd.c \ @@ -18,6 +19,7 @@ C_SRCS += \ OBJS += \ ./Core/Src/24AA02E48.o \ +./Core/Src/CS43L22.o \ ./Core/Src/DNI.o \ ./Core/Src/PCA9685.o \ ./Core/Src/lcd.o \ @@ -30,6 +32,7 @@ OBJS += \ C_DEPS += \ ./Core/Src/24AA02E48.d \ +./Core/Src/CS43L22.d \ ./Core/Src/DNI.d \ ./Core/Src/PCA9685.d \ ./Core/Src/lcd.d \ @@ -48,7 +51,7 @@ Core/Src/%.o Core/Src/%.su Core/Src/%.cyclo: ../Core/Src/%.c Core/Src/subdir.mk clean: clean-Core-2f-Src clean-Core-2f-Src: - -$(RM) ./Core/Src/24AA02E48.cyclo ./Core/Src/24AA02E48.d ./Core/Src/24AA02E48.o ./Core/Src/24AA02E48.su ./Core/Src/DNI.cyclo ./Core/Src/DNI.d ./Core/Src/DNI.o ./Core/Src/DNI.su ./Core/Src/PCA9685.cyclo ./Core/Src/PCA9685.d ./Core/Src/PCA9685.o ./Core/Src/PCA9685.su ./Core/Src/lcd.cyclo ./Core/Src/lcd.d ./Core/Src/lcd.o ./Core/Src/lcd.su ./Core/Src/main.cyclo ./Core/Src/main.d ./Core/Src/main.o ./Core/Src/main.su ./Core/Src/stm32f4xx_hal_msp.cyclo ./Core/Src/stm32f4xx_hal_msp.d ./Core/Src/stm32f4xx_hal_msp.o ./Core/Src/stm32f4xx_hal_msp.su ./Core/Src/stm32f4xx_it.cyclo ./Core/Src/stm32f4xx_it.d ./Core/Src/stm32f4xx_it.o ./Core/Src/stm32f4xx_it.su ./Core/Src/syscalls.cyclo ./Core/Src/syscalls.d ./Core/Src/syscalls.o ./Core/Src/syscalls.su ./Core/Src/sysmem.cyclo ./Core/Src/sysmem.d ./Core/Src/sysmem.o ./Core/Src/sysmem.su ./Core/Src/system_stm32f4xx.cyclo ./Core/Src/system_stm32f4xx.d ./Core/Src/system_stm32f4xx.o ./Core/Src/system_stm32f4xx.su + -$(RM) ./Core/Src/24AA02E48.cyclo ./Core/Src/24AA02E48.d ./Core/Src/24AA02E48.o ./Core/Src/24AA02E48.su ./Core/Src/CS43L22.cyclo ./Core/Src/CS43L22.d ./Core/Src/CS43L22.o ./Core/Src/CS43L22.su ./Core/Src/DNI.cyclo ./Core/Src/DNI.d ./Core/Src/DNI.o ./Core/Src/DNI.su ./Core/Src/PCA9685.cyclo ./Core/Src/PCA9685.d ./Core/Src/PCA9685.o ./Core/Src/PCA9685.su ./Core/Src/lcd.cyclo ./Core/Src/lcd.d ./Core/Src/lcd.o ./Core/Src/lcd.su ./Core/Src/main.cyclo ./Core/Src/main.d ./Core/Src/main.o ./Core/Src/main.su ./Core/Src/stm32f4xx_hal_msp.cyclo ./Core/Src/stm32f4xx_hal_msp.d ./Core/Src/stm32f4xx_hal_msp.o ./Core/Src/stm32f4xx_hal_msp.su ./Core/Src/stm32f4xx_it.cyclo ./Core/Src/stm32f4xx_it.d ./Core/Src/stm32f4xx_it.o ./Core/Src/stm32f4xx_it.su ./Core/Src/syscalls.cyclo ./Core/Src/syscalls.d ./Core/Src/syscalls.o ./Core/Src/syscalls.su ./Core/Src/sysmem.cyclo ./Core/Src/sysmem.d ./Core/Src/sysmem.o ./Core/Src/sysmem.su ./Core/Src/system_stm32f4xx.cyclo ./Core/Src/system_stm32f4xx.d ./Core/Src/system_stm32f4xx.o ./Core/Src/system_stm32f4xx.su .PHONY: clean-Core-2f-Src diff --git a/Debug/objects.list b/Debug/objects.list index f035123..4e4f91d 100644 --- a/Debug/objects.list +++ b/Debug/objects.list @@ -1,4 +1,5 @@ "./Core/Src/24AA02E48.o" +"./Core/Src/CS43L22.o" "./Core/Src/DNI.o" "./Core/Src/PCA9685.o" "./Core/Src/lcd.o" diff --git a/test1.ioc b/test1.ioc index 05bd977..223ff54 100644 --- a/test1.ioc +++ b/test1.ioc @@ -33,11 +33,12 @@ Mcu.Pin14=PC8 Mcu.Pin15=PC9 Mcu.Pin16=PA15 Mcu.Pin17=PC11 -Mcu.Pin18=PB6 -Mcu.Pin19=PB7 +Mcu.Pin18=PD4 +Mcu.Pin19=PB6 Mcu.Pin2=PE7 -Mcu.Pin20=PB9 -Mcu.Pin21=VP_SYS_VS_Systick +Mcu.Pin20=PB7 +Mcu.Pin21=PB9 +Mcu.Pin22=VP_SYS_VS_Systick Mcu.Pin3=PE10 Mcu.Pin4=PE11 Mcu.Pin5=PE12 @@ -45,7 +46,7 @@ Mcu.Pin6=PE13 Mcu.Pin7=PE14 Mcu.Pin8=PE15 Mcu.Pin9=PD12 -Mcu.PinsNb=22 +Mcu.PinsNb=23 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32F407VGTx @@ -91,6 +92,8 @@ PD14.Locked=true PD14.Signal=GPIO_Output PD15.Locked=true PD15.Signal=GPIO_Output +PD4.Locked=true +PD4.Signal=GPIO_Output PE10.Locked=true PE10.Signal=GPIO_Output PE11.Locked=true @@ -136,7 +139,7 @@ ProjectManager.ToolChainLocation= ProjectManager.UAScriptAfterPath= ProjectManager.UAScriptBeforePath= ProjectManager.UnderRoot=true -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_ADC1_Init-ADC1-false-HAL-true +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_ADC1_Init-ADC1-false-HAL-true,4-MX_I2C1_Init-I2C1-false-HAL-true RCC.AHBFreq_Value=16000000 RCC.APB1Freq_Value=16000000 RCC.APB1TimFreq_Value=16000000