This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push: new f144169f44 Initialize led driver during bringup for nucleo-f446re board. f144169f44 is described below commit f144169f444576405c9b9d8dced4325ff225deaf Author: Hank Wu <h...@greentechrobotics.com> AuthorDate: Fri Sep 29 15:04:30 2023 +1300 Initialize led driver during bringup for nucleo-f446re board. --- boards/arm/stm32/nucleo-f446re/src/stm32_bringup.c | 14 +++ .../arm/stm32/nucleo-f446re/src/stm32_userleds.c | 132 ++++----------------- 2 files changed, 34 insertions(+), 112 deletions(-) diff --git a/boards/arm/stm32/nucleo-f446re/src/stm32_bringup.c b/boards/arm/stm32/nucleo-f446re/src/stm32_bringup.c index ecf39eda0f..f7cbabbc36 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 <nuttx/video/fb.h> #endif +#ifdef CONFIG_USERLED +# include <nuttx/leds/userled.h> +#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 6f41a7e389..931ea5f040 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 = -{ - .notify = led_pm_notify, - .prepare = led_pm_prepare, -}; -#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. - * - ****************************************************************************/ +/* This array maps an LED number to GPIO pin configuration */ -#ifdef CONFIG_PM -static void led_pm_notify(struct pm_callback_s *cb, int domain, - enum pm_state_e pmstate) +static const uint32_t g_ledcfg[BOARD_NLEDS] = { - 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 + GPIO_LD2, +}; /**************************************************************************** * 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; -/**************************************************************************** - * Name: stm32_led_pminitialize - ****************************************************************************/ + /* Configure LED GPIOs for output */ -#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); + for (i = 0; i < BOARD_NLEDS; i++) + { + stm32_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0); + } } -#endif /* CONFIG_PM */ #endif /* !CONFIG_ARCH_LEDS */