From a64b5c84de9782624dc1f91324b0fa7bcef3c3d7 Mon Sep 17 00:00:00 2001 From: arturo182 Date: Sat, 3 Feb 2018 13:45:18 +0100 Subject: [PATCH] nrf: Fix missing LED GPIO initialization led_init was never called, which means the GPIOs were never set to output and the LEDs didn't work. --- ports/nrf/modules/machine/led.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/ports/nrf/modules/machine/led.c b/ports/nrf/modules/machine/led.c index 3eec949e9e..423c70bb86 100644 --- a/ports/nrf/modules/machine/led.c +++ b/ports/nrf/modules/machine/led.c @@ -63,13 +63,6 @@ STATIC const pyb_led_obj_t pyb_led_obj[] = { #define NUM_LEDS MP_ARRAY_SIZE(pyb_led_obj) -void led_init(void) { - for (uint8_t i = 0; i < NUM_LEDS; i++) { - LED_OFF(pyb_led_obj[i].hw_pin); - hal_gpio_cfg_pin(0, pyb_led_obj[i].hw_pin, HAL_GPIO_MODE_OUTPUT, HAL_GPIO_PULL_DISABLED); - } -} - void led_state(pyb_led_obj_t * led_obj, int state) { if (state == 1) { LED_ON(led_obj->hw_pin); @@ -108,6 +101,9 @@ STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_ nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "LED(%d) does not exist", led_id)); } + hal_gpio_cfg_pin(0, pyb_led_obj[led_id - 1].hw_pin, HAL_GPIO_MODE_OUTPUT, HAL_GPIO_PULL_DISABLED); + LED_OFF(pyb_led_obj[led_id - 1].hw_pin); + // return static led object return (mp_obj_t)&pyb_led_obj[led_id - 1]; }