@@ -65,8 +65,8 @@ static const board_led_obj_t board_led_obj[] = {
65
65
#if MICROPY_HW_LED_TRICOLOR
66
66
67
67
{{& board_led_type }, BOARD_LED_RED , MICROPY_HW_LED_RED , 0 , MICROPY_HW_LED_PULLUP },
68
- {{& board_led_type }, BOARD_LED_GREEN , MICROPY_HW_LED_GREEN ,0 , MICROPY_HW_LED_PULLUP },
69
- {{& board_led_type }, BOARD_LED_BLUE , MICROPY_HW_LED_BLUE ,0 , MICROPY_HW_LED_PULLUP },
68
+ {{& board_led_type }, BOARD_LED_GREEN , MICROPY_HW_LED_GREEN , 0 , MICROPY_HW_LED_PULLUP },
69
+ {{& board_led_type }, BOARD_LED_BLUE , MICROPY_HW_LED_BLUE , 0 , MICROPY_HW_LED_PULLUP },
70
70
#endif
71
71
#if (MICROPY_HW_LED_COUNT >= 1 )
72
72
{{& board_led_type }, BOARD_LED1 , MICROPY_HW_LED1 , 0 ,
@@ -115,17 +115,17 @@ void led_init(void) {
115
115
}
116
116
}
117
117
118
- void led_state (board_led_obj_t * led_obj , int state ) {
118
+ void led_state (board_led_t led , int state ) {
119
119
if (state == 1 ) {
120
- led_on (led_obj );
120
+ led_on (( board_led_obj_t * ) & board_led_obj [ led - 1 ] );
121
121
122
122
} else {
123
- led_off (led_obj );
123
+ led_off (( board_led_obj_t * ) & board_led_obj [ led - 1 ] );
124
124
}
125
125
}
126
126
127
- void led_toggle (board_led_obj_t * led_obj ) {
128
- nrf_gpio_pin_toggle (led_obj -> hw_pin );
127
+ void led_toggle (board_led_t led ) {
128
+ nrf_gpio_pin_toggle (board_led_obj [ led - 1 ]. hw_pin );
129
129
}
130
130
131
131
@@ -162,23 +162,23 @@ STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_
162
162
/// Turn the LED on.
163
163
mp_obj_t led_obj_on (mp_obj_t self_in ) {
164
164
board_led_obj_t * self = self_in ;
165
- led_state (self , 1 );
165
+ led_state (self -> led_id , 1 );
166
166
return mp_const_none ;
167
167
}
168
168
169
169
/// \method off()
170
170
/// Turn the LED off.
171
171
mp_obj_t led_obj_off (mp_obj_t self_in ) {
172
172
board_led_obj_t * self = self_in ;
173
- led_state (self , 0 );
173
+ led_state (self -> led_id , 0 );
174
174
return mp_const_none ;
175
175
}
176
176
177
177
/// \method toggle()
178
178
/// Toggle the LED between on and off.
179
179
mp_obj_t led_obj_toggle (mp_obj_t self_in ) {
180
180
board_led_obj_t * self = self_in ;
181
- led_toggle (self );
181
+ led_toggle (self -> led_id );
182
182
return mp_const_none ;
183
183
}
184
184
@@ -202,4 +202,13 @@ const mp_obj_type_t board_led_type = {
202
202
.locals_dict = (mp_obj_dict_t * )& led_locals_dict ,
203
203
};
204
204
205
+ #else
206
+ // For boards with no LEDs, we leave an empty function here so that we don't
207
+ // have to put conditionals everywhere.
208
+ void led_init (void ) {
209
+ }
210
+ void led_state (board_led_t led , int state ) {
211
+ }
212
+ void led_toggle (board_led_t led ) {
213
+ }
205
214
#endif // MICROPY_HW_HAS_LED
0 commit comments