diff --git a/boards/arm/stm32/nucleo-f4x1re/src/stm32_bringup.c b/boards/arm/stm32/nucleo-f4x1re/src/stm32_bringup.c index 33d30903c6..a2aabd8f3b 100644 --- a/boards/arm/stm32/nucleo-f4x1re/src/stm32_bringup.c +++ b/boards/arm/stm32/nucleo-f4x1re/src/stm32_bringup.c @@ -37,6 +37,10 @@ #include +#ifdef CONFIG_USERLED +# include +#endif + #include "nucleo-f4x1re.h" #include @@ -45,6 +49,17 @@ #include "board_qencoder.h" #endif +#undef HAVE_LEDS +#if !defined(CONFIG_ARCH_LEDS) && defined(CONFIG_USERLED_LOWER) +# define HAVE_LEDS 1 +#endif + +#ifdef CONFIG_EXAMPLES_LEDS_DEVPATH +# define LED_DRIVER_PATH CONFIG_EXAMPLES_LEDS_DEVPATH +#else +# define LED_DRIVER_PATH "/dev/userleds" +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -67,6 +82,17 @@ int stm32_bringup(void) { int ret = OK; +#ifdef HAVE_LEDS + /* Register the LED driver */ + + ret = userled_lower_initialize(LED_DRIVER_PATH); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret); + return ret; + } +#endif + /* Configure SPI-based devices */ #ifdef CONFIG_STM32_SPI1 diff --git a/boards/arm/stm32/nucleo-f4x1re/src/stm32_userleds.c b/boards/arm/stm32/nucleo-f4x1re/src/stm32_userleds.c index 89caf861cf..92d0b5b08b 100644 --- a/boards/arm/stm32/nucleo-f4x1re/src/stm32_userleds.c +++ b/boards/arm/stm32/nucleo-f4x1re/src/stm32_userleds.c @@ -164,7 +164,7 @@ uint32_t board_userled_initialize(void) void board_userled(int led, bool ledon) { - if (led == 1) + if (BOARD_LD2_BIT == (1 << led)) { stm32_gpiowrite(GPIO_LD2, ledon); } @@ -176,9 +176,29 @@ void board_userled(int led, bool ledon) void board_userled_all(uint32_t ledset) { + /* An output of '1' illuminates the LED */ + stm32_gpiowrite(GPIO_LD2, (ledset & BOARD_LD2_BIT) != 0); } +#ifdef CONFIG_USERLED_LOWER_READSTATE +/**************************************************************************** + * Name: board_userled_getall + ****************************************************************************/ + +void board_userled_getall(uint32_t *ledset) +{ + /* Clear the LED bits */ + + *ledset = 0; + + /* Get LED state. An output of '1' illuminates the LED. */ + + *ledset |= ((stm32_gpioread(GPIO_LD2) & 1) << BOARD_LD2); +} + +#endif /* CONFIG_USERLED_LOWER_READSTATE */ + /**************************************************************************** * Name: stm32_led_pminitialize ****************************************************************************/