From 0eb025d3d4988ced83f26f7e0b4ca10713659f81 Mon Sep 17 00:00:00 2001 From: hasslesstech Date: Mon, 14 Apr 2025 19:33:13 +0300 Subject: [PATCH] add new UI for testing phase, update modules to indicate success or failure in the return value --- Core/Inc/24AA02E48.h | 2 +- Core/Inc/CS43L22.h | 2 +- Core/Inc/DNI.h | 4 +-- Core/Inc/LIS302DL.h | 4 +-- Core/Inc/LSM9DS1.h | 4 +-- Core/Inc/MP45DT02.h | 2 +- Core/Inc/PCA9685.h | 2 +- Core/Inc/SST25VF016B.h | 2 +- Core/Src/24AA02E48.c | 6 +++- Core/Src/CS43L22.c | 6 +++- Core/Src/DNI.c | 8 +++-- Core/Src/LIS302DL.c | 12 ++++++-- Core/Src/LSM9DS1.c | 12 ++++++-- Core/Src/MP45DT02.c | 6 ++-- Core/Src/PCA9685.c | 6 +++- Core/Src/SST25VF016B.c | 15 ++++++++-- Core/Src/main.c | 67 +++++++++++++++++++++++++++++++++++++----- 17 files changed, 127 insertions(+), 33 deletions(-) diff --git a/Core/Inc/24AA02E48.h b/Core/Inc/24AA02E48.h index e39d5a4..51cc8b0 100644 --- a/Core/Inc/24AA02E48.h +++ b/Core/Inc/24AA02E48.h @@ -1,6 +1,6 @@ #ifndef __EEPROM_24AA02E48 #define __EEPROM_24AA02E48 -void EEPROM_24AA02E48_run_test(void); +int EEPROM_24AA02E48_run_test(void); #endif diff --git a/Core/Inc/CS43L22.h b/Core/Inc/CS43L22.h index ebe3c1c..faec784 100644 --- a/Core/Inc/CS43L22.h +++ b/Core/Inc/CS43L22.h @@ -1,7 +1,7 @@ #ifndef __CS43L22 #define __CS43L22 -void CS43L22_run_test(void); +int CS43L22_run_test(void); void CS43L22_cleanup(void); #endif diff --git a/Core/Inc/DNI.h b/Core/Inc/DNI.h index 0f9794d..341de70 100644 --- a/Core/Inc/DNI.h +++ b/Core/Inc/DNI.h @@ -3,7 +3,7 @@ extern ADC_HandleTypeDef hadc1; -void DNI_show_celsius(void); -void DNI_show_fahrenheit(void); +int DNI_show_celsius(void); +int DNI_show_fahrenheit(void); #endif diff --git a/Core/Inc/LIS302DL.h b/Core/Inc/LIS302DL.h index b4bfb0a..3c62336 100644 --- a/Core/Inc/LIS302DL.h +++ b/Core/Inc/LIS302DL.h @@ -1,7 +1,7 @@ #ifndef __LIS302DL #define __LIS302DL -void LIS302DL_run_test(void); -void LIS302DL_run_test_dynamic(void); +int LIS302DL_run_test(void); +int LIS302DL_run_test_dynamic(void); #endif diff --git a/Core/Inc/LSM9DS1.h b/Core/Inc/LSM9DS1.h index 611659d..998be9b 100644 --- a/Core/Inc/LSM9DS1.h +++ b/Core/Inc/LSM9DS1.h @@ -1,8 +1,8 @@ #ifndef __LSM9DS1 #define __LSM9DS1 -void LSM9DS1_test_accel(void); +int LSM9DS1_test_accel(void); void LSM9DS1_cleanup_accel(void); -void LSM9DS1_test_magnet(void); +int LSM9DS1_test_magnet(void); #endif diff --git a/Core/Inc/MP45DT02.h b/Core/Inc/MP45DT02.h index f09e1bf..92dbb4e 100644 --- a/Core/Inc/MP45DT02.h +++ b/Core/Inc/MP45DT02.h @@ -1,6 +1,6 @@ #ifndef __MP45DT02 #define __MP45DT02 -void MP45DT02_run_test(void); +int MP45DT02_run_test(void); #endif diff --git a/Core/Inc/PCA9685.h b/Core/Inc/PCA9685.h index 14b9bb8..00e4eaf 100644 --- a/Core/Inc/PCA9685.h +++ b/Core/Inc/PCA9685.h @@ -1,7 +1,7 @@ #ifndef __PCA9685 #define __PCA9685 -void PCA9685_run_test(void); +int PCA9685_run_test(void); void PCA9685_cleanup(void); #endif diff --git a/Core/Inc/SST25VF016B.h b/Core/Inc/SST25VF016B.h index 69a7db1..ab48cf0 100644 --- a/Core/Inc/SST25VF016B.h +++ b/Core/Inc/SST25VF016B.h @@ -1,6 +1,6 @@ #ifndef __SST25VF016B #define __SST25VF016B -void SST25VF016B_run_test(void); +int SST25VF016B_run_test(void); #endif diff --git a/Core/Src/24AA02E48.c b/Core/Src/24AA02E48.c index 8ebce17..9b53ad6 100644 --- a/Core/Src/24AA02E48.c +++ b/Core/Src/24AA02E48.c @@ -4,7 +4,7 @@ extern I2C_HandleTypeDef hi2c1; -void EEPROM_24AA02E48_run_test(void) +int EEPROM_24AA02E48_run_test(void) { DISPLAY_CLEAR; display_write_data_seq("24AA02E48 EEPROM"); @@ -94,9 +94,13 @@ void EEPROM_24AA02E48_run_test(void) display_write_data_byte('0' + err_count % 10); display_write_data_seq("E "); display_write_data_seq((char *) data_buffer); + + return 1; } else { DISPLAY_SET_CURSOR(1, 1); display_write_data_seq("OK "); display_write_data_seq((char *) data_buffer); + + return 0; } } diff --git a/Core/Src/CS43L22.c b/Core/Src/CS43L22.c index d0e2335..f00c32c 100644 --- a/Core/Src/CS43L22.c +++ b/Core/Src/CS43L22.c @@ -4,7 +4,7 @@ extern I2C_HandleTypeDef hi2c1; -void CS43L22_run_test(void) +int CS43L22_run_test(void) { DISPLAY_CLEAR; display_write_data_seq("CS43L22 Audio"); @@ -57,9 +57,13 @@ void CS43L22_run_test(void) DISPLAY_SET_CURSOR(1, 1); display_write_data_byte('0' + err_count % 10); display_write_data_seq(" Errors"); + + return 1; } else { DISPLAY_SET_CURSOR(1, 1); display_write_data_seq("OK"); + + return 0; } } diff --git a/Core/Src/DNI.c b/Core/Src/DNI.c index 291e73a..23c826d 100644 --- a/Core/Src/DNI.c +++ b/Core/Src/DNI.c @@ -73,7 +73,7 @@ static void DNI_print_fahrenheit(int temperature) DNI_print(temperature); } -void DNI_show_celsius(void) +int DNI_show_celsius(void) { DISPLAY_CLEAR; DISPLAY_SET_INCREMENT; @@ -83,9 +83,11 @@ void DNI_show_celsius(void) uint32_t value = DNI_read(); int temp = DNI_convert_to_celsius(value); DNI_print_celsius(temp); + + return 0; } -void DNI_show_fahrenheit(void) +int DNI_show_fahrenheit(void) { DISPLAY_CLEAR; DISPLAY_SET_INCREMENT; @@ -95,4 +97,6 @@ void DNI_show_fahrenheit(void) uint32_t value = DNI_read(); int temp = DNI_convert_to_fahrenheit(value); DNI_print_fahrenheit(temp); + + return 0; } diff --git a/Core/Src/LIS302DL.c b/Core/Src/LIS302DL.c index 9b8b499..4795faf 100644 --- a/Core/Src/LIS302DL.c +++ b/Core/Src/LIS302DL.c @@ -105,7 +105,7 @@ static void retrieve_data(size_t *err_count, uint8_t *data_xyz, char *postfix) FAILSAFE_POST_OP("RZ"); } -void LIS302DL_run_test(void) +int LIS302DL_run_test(void) { DISPLAY_CLEAR; display_write_data_seq("LIS302DL Accel"); @@ -129,13 +129,17 @@ void LIS302DL_run_test(void) display_write_data_byte('0' + err_count / 10 % 10); display_write_data_byte('0' + err_count % 10); display_write_data_seq(" errs"); + + return 1; } else { DISPLAY_SET_CURSOR(1, 1); display_write_data_seq("OK"); + + return 0; } } -void LIS302DL_run_test_dynamic(void) +int LIS302DL_run_test_dynamic(void) { DISPLAY_CLEAR; display_write_data_seq("LIS302DL Accel D"); @@ -159,8 +163,12 @@ void LIS302DL_run_test_dynamic(void) display_write_data_byte('0' + err_count / 10 % 10); display_write_data_byte('0' + err_count % 10); display_write_data_seq(" errs"); + + return 1; } else { DISPLAY_SET_CURSOR(1, 1); display_write_data_seq("OK"); + + return 0; } } diff --git a/Core/Src/LSM9DS1.c b/Core/Src/LSM9DS1.c index ed2aa8b..4f44248 100644 --- a/Core/Src/LSM9DS1.c +++ b/Core/Src/LSM9DS1.c @@ -52,7 +52,7 @@ static void print_error_magnet(HAL_StatusTypeDef result, size_t *err_count, size print_error_message(result, err_count, t, prefix); } -void LSM9DS1_test_accel(void) +int LSM9DS1_test_accel(void) { DISPLAY_CLEAR; display_write_data_seq("LSM9DS1 Accel"); @@ -84,11 +84,15 @@ void LSM9DS1_test_accel(void) if (!err_count) { DISPLAY_SET_CURSOR(1, 1); display_write_data_seq("OK"); + + return 0; } else { DISPLAY_SET_CURSOR(1, 0); display_write_data_byte('0' + ((err_count / 10) % 10)); display_write_data_byte('0' + (err_count % 10)); display_write_data_seq(" errors"); + + return 1; } } @@ -99,7 +103,7 @@ void LSM9DS1_cleanup_accel(void) HAL_I2C_Master_Transmit(&hi2c1, 0xD6, buffer, 2, 1000); } -void LSM9DS1_test_magnet(void) +int LSM9DS1_test_magnet(void) { DISPLAY_CLEAR; display_write_data_seq("LSM9DS1 Magnet"); @@ -122,10 +126,14 @@ void LSM9DS1_test_magnet(void) if (!err_count) { DISPLAY_SET_CURSOR(1, 1); display_write_data_seq("OK"); + + return 0; } else { DISPLAY_SET_CURSOR(1, 0); display_write_data_byte('0' + ((err_count / 10) % 10)); display_write_data_byte('0' + (err_count % 10)); display_write_data_seq(" errors"); + + return 1; } } diff --git a/Core/Src/MP45DT02.c b/Core/Src/MP45DT02.c index 3f4fe0f..c10a586 100644 --- a/Core/Src/MP45DT02.c +++ b/Core/Src/MP45DT02.c @@ -6,7 +6,7 @@ extern I2S_HandleTypeDef hi2s2; -void MP45DT02_run_test(void) +int MP45DT02_run_test(void) { DISPLAY_CLEAR; display_write_data_seq("MP45DT02 Mic"); @@ -30,7 +30,7 @@ void MP45DT02_run_test(void) display_write_data_seq(" full 0 samples"); } - return; + return 0; } // if ended up here, then no samples equaled to 1; that is not a good sign @@ -50,4 +50,6 @@ void MP45DT02_run_test(void) DISPLAY_SET_CURSOR(1, 0); display_write_data_seq("No good samples!"); + + return 1; } diff --git a/Core/Src/PCA9685.c b/Core/Src/PCA9685.c index 6772093..26438c5 100644 --- a/Core/Src/PCA9685.c +++ b/Core/Src/PCA9685.c @@ -4,7 +4,7 @@ extern I2C_HandleTypeDef hi2c1; -void PCA9685_run_test(void) +int PCA9685_run_test(void) { DISPLAY_CLEAR; display_write_data_seq("PCA9685 PWM"); @@ -68,9 +68,13 @@ void PCA9685_run_test(void) display_write_data_byte('0' + err_count / 10 % 10); display_write_data_byte('0' + err_count % 10); display_write_data_seq(" errors"); + + return 1; } else { DISPLAY_SET_CURSOR(1, 1); display_write_data_seq("OK OUT ENABLED"); + + return 0; } } diff --git a/Core/Src/SST25VF016B.c b/Core/Src/SST25VF016B.c index d866039..5ab1291 100644 --- a/Core/Src/SST25VF016B.c +++ b/Core/Src/SST25VF016B.c @@ -4,13 +4,14 @@ extern SPI_HandleTypeDef hspi1; -void SST25VF016B_run_test(void) +int SST25VF016B_run_test(void) { DISPLAY_CLEAR; display_write_data_seq("SST25VF016B Flas"); HAL_StatusTypeDef op_result; size_t err_count = 0; + size_t chip_id_fault = 0; uint8_t tx_buffer[8] = {0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; uint8_t rx_buffer[9]; @@ -46,8 +47,6 @@ void SST25VF016B_run_test(void) display_write_data_seq("TIMEOUT"); break; } - - HAL_Delay(2000); } else { break; } @@ -62,6 +61,8 @@ void SST25VF016B_run_test(void) DISPLAY_SET_CURSOR(1, 1); display_write_data_byte('0' + err_count % 10); display_write_data_seq(" Errors"); + + return 1; } else { for (size_t i = 0; i < 4; i += 2) { // odd reads MUST result in 0xBF @@ -70,6 +71,9 @@ void SST25VF016B_run_test(void) display_write_data_byte('B'); display_write_data_byte('1'+i); display_write_data_seq(" WRONG"); + + chip_id_fault = 1; + goto write_retrieved_data; } } @@ -81,6 +85,9 @@ void SST25VF016B_run_test(void) display_write_data_byte('B'); display_write_data_byte('1'+i); display_write_data_seq(" WRONG"); + + chip_id_fault = 1; + goto write_retrieved_data; } } @@ -94,4 +101,6 @@ void SST25VF016B_run_test(void) display_write_data_seq((char *) &(rx_buffer[4])); HAL_GPIO_WritePin(GPIOD, GPIO_PIN_7, GPIO_PIN_SET); + + return (err_count || chip_id_fault); } diff --git a/Core/Src/main.c b/Core/Src/main.c index ef4a826..1d160a6 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -68,7 +68,7 @@ extern size_t display_current_frame; /* USER CODE BEGIN PV */ -void ((*executors[])(void)) = { +int ((*executors[])(void)) = { DNI_show_celsius, DNI_show_fahrenheit, PCA9685_run_test, @@ -307,16 +307,62 @@ int main(void) button_init_and_test(); // perform all tests - display_to_framebuffer(); + size_t successful_tests = 0; + size_t failed_tests = 0; - for (display_current_frame = 0; display_current_frame < 11; display_current_frame++) + //display_to_framebuffer(); + + for (display_current_frame = 1; display_current_frame < 12; display_current_frame++) { - executors[display_current_frame](); + DISPLAY_CLEAR; + display_write_data_seq("Testing..."); + + DISPLAY_SET_CURSOR(1, 2); + display_write_data_seq("P:"); + display_write_data_byte('0' + (successful_tests / 10) % 10); + display_write_data_byte('0' + (successful_tests) % 10); + + DISPLAY_SET_CURSOR(1, 10); + display_write_data_seq("F:"); + display_write_data_byte('0' + (failed_tests / 10) % 10); + display_write_data_byte('0' + (failed_tests) % 10); + + display_to_framebuffer(); + + // test + if (executors[display_current_frame-1]()) + failed_tests++; + else + successful_tests++; + + // cleanup (if required) + if (cleanup_functions[display_current_frame-1]) + cleanup_functions[display_current_frame-1](); + + display_to_direct(); + + HAL_Delay(150); } + // render final result to first framebuffer + display_to_framebuffer(); + display_current_frame = 0; + + DISPLAY_CLEAR; + display_write_data_seq("All tests done!"); + + DISPLAY_SET_CURSOR(1, 2); + display_write_data_seq("P:"); + display_write_data_byte('0' + (successful_tests / 10) % 10); + display_write_data_byte('0' + (successful_tests) % 10); + + DISPLAY_SET_CURSOR(1, 10); + display_write_data_seq("F:"); + display_write_data_byte('0' + (failed_tests / 10) % 10); + display_write_data_byte('0' + (failed_tests) % 10); + display_to_direct(); - display_current_frame = 0; if (buttons_interrupt_enabled) buttons_switch_to_input(); @@ -342,6 +388,7 @@ int main(void) !(GPIOC->IDR & GPIO_PIN_8) ) { display_current_frame += 1; + display_current_frame %= 12; break; } @@ -351,15 +398,19 @@ int main(void) !(GPIOC->IDR & GPIO_PIN_6) ) { display_current_frame -= 1; + + if (display_current_frame == 0xFFFFFFFFU) + display_current_frame = 11; + break; } - // execute this test live + // return to summary frame else if ( !(GPIOA->IDR & GPIO_PIN_15) ) { - // not implemented - continue; + display_current_frame = 0; + break; } } }