From f144169f444576405c9b9d8dced4325ff225deaf Mon Sep 17 00:00:00 2001 From: Hank Wu Date: Fri, 29 Sep 2023 15:04:30 +1300 Subject: [PATCH] Initialize led driver during bringup for nucleo-f446re board. --- .../stm32/nucleo-f446re/src/stm32_bringup.c | 14 ++ .../stm32/nucleo-f446re/src/stm32_userleds.c | 136 +++--------------- 2 files changed, 36 insertions(+), 114 deletions(-) diff --git a/boards/arm/stm32/nucleo-f446re/src/stm32_bringup.c b/boards/arm/stm32/nucleo-f446re/src/stm32_bringup.c index ecf39eda0f2..f7cbabbc36c 100644 --- a/boards/arm/stm32/nucleo-f446re/src/stm32_bringup.c +++ b/boards/arm/stm32/nucleo-f446re/src/stm32_bringup.c @@ -54,6 +54,10 @@ # include #endif +#ifdef CONFIG_USERLED +# include +#endif + #include "stm32_romfs.h" #include "nucleo-f446re.h" @@ -250,6 +254,16 @@ int stm32_bringup(void) } #endif +#ifdef CONFIG_USERLED + /* Register the LED driver */ + + ret = userled_lower_initialize("/dev/userleds"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret); + } +#endif + #ifdef CONFIG_DAC /* Initialize DAC and register the DAC driver. */ diff --git a/boards/arm/stm32/nucleo-f446re/src/stm32_userleds.c b/boards/arm/stm32/nucleo-f446re/src/stm32_userleds.c index 6f41a7e389a..931ea5f0401 100644 --- a/boards/arm/stm32/nucleo-f446re/src/stm32_userleds.c +++ b/boards/arm/stm32/nucleo-f446re/src/stm32_userleds.c @@ -39,106 +39,16 @@ #ifndef CONFIG_ARCH_LEDS -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/* LED Power Management */ - -#ifdef CONFIG_PM -static void led_pm_notify(struct pm_callback_s *cb, int domain, - enum pm_state_e pmstate); -static int led_pm_prepare(struct pm_callback_s *cb, int domain, - enum pm_state_e pmstate); -#endif - /**************************************************************************** * Private Data ****************************************************************************/ -#ifdef CONFIG_PM -static struct pm_callback_s g_ledscb = +/* This array maps an LED number to GPIO pin configuration */ + +static const uint32_t g_ledcfg[BOARD_NLEDS] = { - .notify = led_pm_notify, - .prepare = led_pm_prepare, + GPIO_LD2, }; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: led_pm_notify - * - * Description: - * Notify the driver of new power state. This callback is called after - * all drivers have had the opportunity to prepare for the new power state. - * - ****************************************************************************/ - -#ifdef CONFIG_PM -static void led_pm_notify(struct pm_callback_s *cb, int domain, - enum pm_state_e pmstate) -{ - switch (pmstate) - { - case(PM_NORMAL): - { - /* Restore normal LEDs operation */ - } - break; - - case(PM_IDLE): - { - /* Entering IDLE mode - Turn leds off */ - } - break; - - case(PM_STANDBY): - { - /* Entering STANDBY mode - Logic for PM_STANDBY goes here */ - } - break; - - case(PM_SLEEP): - { - /* Entering SLEEP mode - Logic for PM_SLEEP goes here */ - } - break; - - default: - { - /* Should not get here */ - } - break; - } -} -#endif - -/**************************************************************************** - * Name: led_pm_prepare - * - * Description: - * Request the driver to prepare for a new power state. This is a warning - * that the system is about to enter into a new power state. The driver - * should begin whatever operations that may be required to enter power - * state. The driver may abort the state change mode by returning a - * non-zero value from the callback function. - * - ****************************************************************************/ - -#ifdef CONFIG_PM -static int led_pm_prepare(struct pm_callback_s *cb, int domain, - enum pm_state_e pmstate) -{ - /* No preparation to change power modes is required by the LEDs driver. - * We always accept the state change by returning OK. - */ - - return OK; -} -#endif /**************************************************************************** * Public Functions @@ -150,9 +60,15 @@ static int led_pm_prepare(struct pm_callback_s *cb, int domain, uint32_t board_userled_initialize(void) { - /* Configure LD2 GPIO for output */ + int i; + + /* Configure LED GPIOs for output */ + + for (i = 0; i < BOARD_NLEDS; i++) + { + stm32_configgpio(g_ledcfg[i]); + } - stm32_configgpio(GPIO_LD2); return BOARD_NLEDS; } @@ -162,9 +78,9 @@ uint32_t board_userled_initialize(void) void board_userled(int led, bool ledon) { - if (led == 1) + if ((unsigned)led < BOARD_NLEDS) { - stm32_gpiowrite(GPIO_LD2, ledon); + stm32_gpiowrite(g_ledcfg[led], ledon); } } @@ -174,22 +90,14 @@ void board_userled(int led, bool ledon) void board_userled_all(uint32_t ledset) { - stm32_gpiowrite(GPIO_LD2, (ledset & BOARD_LD2_BIT) != 0); + int i; + + /* Configure LED GPIOs for output */ + + for (i = 0; i < BOARD_NLEDS; i++) + { + stm32_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0); + } } -/**************************************************************************** - * Name: stm32_led_pminitialize - ****************************************************************************/ - -#ifdef CONFIG_PM -void stm32_led_pminitialize(void) -{ - /* Register to receive power management callbacks */ - - int ret = pm_register(&g_ledscb); - DEBUGASSERT(ret == OK); - UNUSED(ret); -} -#endif /* CONFIG_PM */ - #endif /* !CONFIG_ARCH_LEDS */