From e3b3aa303cc614c98e3ce57386aa13c8dad6b314 Mon Sep 17 00:00:00 2001 From: lains <383502+lains@users.noreply.github.com> Date: Wed, 7 Feb 2024 11:07:53 +0100 Subject: [PATCH] Make LED references board-independent --- inc/main.h | 19 +++++++++++++++++++ src/hal/Stm32LcdDriver.cpp | 8 ++++++-- src/hal/Stm32SerialDriver.cpp | 4 +++- src/main.cpp | 22 +++++++++++++--------- 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/inc/main.h b/inc/main.h index 9daa896..d4a9996 100644 --- a/inc/main.h +++ b/inc/main.h @@ -15,6 +15,25 @@ #include "stm32469i_discovery_qspi.h" #endif +#ifdef USE_STM32469I_DISCOVERY +#define LED_GREEN LED1 +#define LED_ORANGE LED2 +#define LED_RED LED3 +#define LED_BLUE LED4 +#endif +#ifdef LED_BLUE +#define LED_LCD_REFRESH LED_BLUE +#endif +#ifdef LED_RED +#define LED_ERROR LED_RED +#endif +#ifdef LED_ORANGE +#define LED_SERIAL_RX LED_ORANGE +#endif +#ifdef LED_GREEN +#define LED_TIC_FRAME_RX LED_GREEN +#endif + void Error_Handler(void); void OnError_Handler(uint32_t condition); diff --git a/src/hal/Stm32LcdDriver.cpp b/src/hal/Stm32LcdDriver.cpp index ae01938..c3c69c0 100644 --- a/src/hal/Stm32LcdDriver.cpp +++ b/src/hal/Stm32LcdDriver.cpp @@ -63,12 +63,16 @@ void HAL_DSI_EndOfRefreshCallback(DSI_HandleTypeDef *hdsi) { if (Stm32LcdDriver::get().displayState == Stm32LcdDriver::SwitchToDraftIsPending) { set_active_fb(Stm32LcdDriver::get().draftFramebuffer); Stm32LcdDriver::get().displayState = Stm32LcdDriver::DisplayingDraft; - BSP_LED_Off(LED4); +#ifdef LED_LCD_REFRESH + BSP_LED_Off(LED_LCD_REFRESH); +#endif } else if (Stm32LcdDriver::get().displayState == Stm32LcdDriver::SwitchToFinalIsPending) { set_active_fb(Stm32LcdDriver::get().finalFramebuffer); Stm32LcdDriver::get().displayState = Stm32LcdDriver::DisplayingFinal; - BSP_LED_On(LED4); +#ifdef LED_LCD_REFRESH + BSP_LED_On(LED_LCD_REFRESH); +#endif } } diff --git a/src/hal/Stm32SerialDriver.cpp b/src/hal/Stm32SerialDriver.cpp index b8fd965..ff5b974 100644 --- a/src/hal/Stm32SerialDriver.cpp +++ b/src/hal/Stm32SerialDriver.cpp @@ -158,7 +158,9 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) if (huart->Instance==USART6) { unsigned char Received_Data = UART6_rxBuffer[0]; onTicUartRx((uint8_t)Received_Data); - BSP_LED_Toggle(LED3); // Toggle the orange LED when new serial data is received on the TIC UART +#ifdef LED_SERIAL_RX + BSP_LED_Toggle(LED_SERIAL_RX); // Toggle the orange LED when new serial data is received on the TIC UART +#endif UART6_Enable_interrupt_callback(huart); } } diff --git a/src/main.cpp b/src/main.cpp index a02e0de..33e3848 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,7 +50,9 @@ const unsigned int BytesPerPixel = 4; /* For ARGB8888 mode */ void OnError_Handler(uint32_t condition) { if(condition) { - BSP_LED_On(LED2); +#ifdef LED_ERROR + BSP_LED_On(LED_ERROR); +#endif while(1) { ; } /* Blocking on error */ } } @@ -111,16 +113,16 @@ int main(void) { /* Configure the system clock to 180 MHz */ SystemClock_Config(); - /* Configure LED1, LED2, LED3 and LED4 on USE_STM32469I_DISCOVERY */ + /* Configure the 4 available LEDs on USE_STM32469I_DISCOVERY */ #ifdef USE_STM32469I_DISCOVERY - BSP_LED_Init(LED1); - BSP_LED_Init(LED2); - BSP_LED_Init(LED3); - BSP_LED_Init(LED4); + BSP_LED_Init(LED_GREEN); + BSP_LED_Init(LED_RED); + BSP_LED_Init(LED_ORANGE); + BSP_LED_Init(LED_BLUE); #endif - BSP_LED_On(LED2); + BSP_LED_On(LED_ORANGE); waitDelay(250); - BSP_LED_Off(LED2); + BSP_LED_Off(LED_ORANGE); /* Initialize the SDRAM */ BSP_SDRAM_Init(); @@ -143,7 +145,9 @@ int main(void) { TicFrameParser ticParser(PowerHistory::unWrapOnNewPowerData, (void *)(&powerHistory)); auto onFrameCompleteBlinkGreenLedAndInvokeHandler = [](void* context) { - BSP_LED_Toggle(LED1); // Toggle the green LED when a frame has been completely received +#ifdef LED_TIC_FRAME_RX + BSP_LED_Toggle(LED_TIC_FRAME_RX); // Toggle the green LED when a frame has been completely received +#endif TicFrameParser::unwrapInvokeOnFrameComplete(context); /* Invoke the frameparser's onFrameComplete handler */ };