Skip to content

Commit a4c0f52

Browse files
mvdw73dpgeorge
authored andcommitted
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.
1 parent 8f35107 commit a4c0f52

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

ports/stm32/led.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ STATIC const pyb_led_obj_t pyb_led_obj[] = {
5858
{{&pyb_led_type}, 3, MICROPY_HW_LED3},
5959
#if defined(MICROPY_HW_LED4)
6060
{{&pyb_led_type}, 4, MICROPY_HW_LED4},
61+
#if defined(MICROPY_HW_LED5)
62+
{{&pyb_led_type}, 5, MICROPY_HW_LED5},
63+
#if defined(MICROPY_HW_LED6)
64+
{{&pyb_led_type}, 6, MICROPY_HW_LED6},
65+
#endif
66+
#endif
6167
#endif
6268
#endif
6369
#endif
@@ -77,7 +83,9 @@ void led_init(void) {
7783
#if defined(MICROPY_HW_LED1_PWM) \
7884
|| defined(MICROPY_HW_LED2_PWM) \
7985
|| defined(MICROPY_HW_LED3_PWM) \
80-
|| defined(MICROPY_HW_LED4_PWM)
86+
|| defined(MICROPY_HW_LED4_PWM) \
87+
|| defined(MICROPY_HW_LED5_PWM) \
88+
|| defined(MICROPY_HW_LED6_PWM)
8189

8290
// The following is semi-generic code to control LEDs using PWM.
8391
// It currently supports TIM1, TIM2 and TIM3, channels 1-4.
@@ -98,6 +106,12 @@ void led_init(void) {
98106
#ifndef MICROPY_HW_LED4_PWM
99107
#define MICROPY_HW_LED4_PWM { NULL, 0, 0, 0 }
100108
#endif
109+
#ifndef MICROPY_HW_LED5_PWM
110+
#define MICROPY_HW_LED5_PWM { NULL, 0, 0, 0 }
111+
#endif
112+
#ifndef MICROPY_HW_LED6_PWM
113+
#define MICROPY_HW_LED6_PWM { NULL, 0, 0, 0 }
114+
#endif
101115

102116
#define LED_PWM_TIM_PERIOD (10000) // TIM runs at 1MHz and fires every 10ms
103117

@@ -116,6 +130,8 @@ STATIC const led_pwm_config_t led_pwm_config[] = {
116130
MICROPY_HW_LED2_PWM,
117131
MICROPY_HW_LED3_PWM,
118132
MICROPY_HW_LED4_PWM,
133+
MICROPY_HW_LED5_PWM,
134+
MICROPY_HW_LED6_PWM,
119135
};
120136

121137
STATIC uint8_t led_pwm_state = 0;

0 commit comments

Comments
 (0)