From a4c0f52714ed176587cb43f98ea7f3b2264c600e Mon Sep 17 00:00:00 2001 From: Matt van de Werken Date: Thu, 2 Jul 2020 17:36:27 +1000 Subject: [PATCH] stm32/led: Support an extra 2 LEDs in board configuration. Although the pyboard has only 4 LEDs, there are some boards that (may) have more. This commit adds 2 more LEDs to the led.c file that if defined in the board-specific config file will be compiled in. --- ports/stm32/led.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ports/stm32/led.c b/ports/stm32/led.c index adcb240cc0..078327462a 100644 --- a/ports/stm32/led.c +++ b/ports/stm32/led.c @@ -58,6 +58,12 @@ STATIC const pyb_led_obj_t pyb_led_obj[] = { {{&pyb_led_type}, 3, MICROPY_HW_LED3}, #if defined(MICROPY_HW_LED4) {{&pyb_led_type}, 4, MICROPY_HW_LED4}, + #if defined(MICROPY_HW_LED5) + {{&pyb_led_type}, 5, MICROPY_HW_LED5}, + #if defined(MICROPY_HW_LED6) + {{&pyb_led_type}, 6, MICROPY_HW_LED6}, + #endif + #endif #endif #endif #endif @@ -77,7 +83,9 @@ void led_init(void) { #if defined(MICROPY_HW_LED1_PWM) \ || defined(MICROPY_HW_LED2_PWM) \ || defined(MICROPY_HW_LED3_PWM) \ - || defined(MICROPY_HW_LED4_PWM) + || defined(MICROPY_HW_LED4_PWM) \ + || defined(MICROPY_HW_LED5_PWM) \ + || defined(MICROPY_HW_LED6_PWM) // The following is semi-generic code to control LEDs using PWM. // It currently supports TIM1, TIM2 and TIM3, channels 1-4. @@ -98,6 +106,12 @@ void led_init(void) { #ifndef MICROPY_HW_LED4_PWM #define MICROPY_HW_LED4_PWM { NULL, 0, 0, 0 } #endif +#ifndef MICROPY_HW_LED5_PWM +#define MICROPY_HW_LED5_PWM { NULL, 0, 0, 0 } +#endif +#ifndef MICROPY_HW_LED6_PWM +#define MICROPY_HW_LED6_PWM { NULL, 0, 0, 0 } +#endif #define LED_PWM_TIM_PERIOD (10000) // TIM runs at 1MHz and fires every 10ms @@ -116,6 +130,8 @@ STATIC const led_pwm_config_t led_pwm_config[] = { MICROPY_HW_LED2_PWM, MICROPY_HW_LED3_PWM, MICROPY_HW_LED4_PWM, + MICROPY_HW_LED5_PWM, + MICROPY_HW_LED6_PWM, }; STATIC uint8_t led_pwm_state = 0;