Skip to content

Commit bcb3ab4

Browse files
committed
stmhal: Toggle LED using ODR ^= pin_mask.
1 parent 2547928 commit bcb3ab4

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

stmhal/led.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,9 @@ void led_toggle(pyb_led_t led) {
148148
}
149149
#endif
150150

151+
// toggle the output data register to toggle the LED state
151152
const pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin;
152-
GPIO_TypeDef *gpio = led_pin->gpio;
153-
154-
// We don't know if we're turning the LED on or off, but we don't really
155-
// care. Just invert the state.
156-
if (gpio->ODR & led_pin->pin_mask) {
157-
// pin is high, make it low
158-
gpio->BSRRH = led_pin->pin_mask;
159-
} else {
160-
// pin is low, make it high
161-
gpio->BSRRL = led_pin->pin_mask;
162-
}
153+
led_pin->gpio->ODR ^= led_pin->pin_mask;
163154
}
164155

165156
int led_get_intensity(pyb_led_t led) {

0 commit comments

Comments
 (0)