LED implementation on nrF9160 with nRF connect 2.1.2

Hi all ,

I had my code working on nRF connect 1.6.0 and now had to upgrade it to work with nRF connect 2.1.2.

I read the migration guide for  nRF connect 1.x.x to 2.x.x  but still can't fully understand how to port my working code on nRF connect 1.6.0 that controlled the LEDs to nRF connect 2.1.2

Here is the nRF connect 1.6.0:

void init_leds(void)
{
        /* GPIOs:  p0.02 == RED */
        red_gpio = DT_GPIO_PIN(DT_ALIAS(LED_RED_LABEL), gpios);

        /* GPIOs:  p0.03 == BLUE */
        blue_gpio=  DT_GPIO_PIN(DT_ALIAS(LED_BLUE_LABEL), gpios);

   dev_red = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(LED_RED_LABEL), gpios));
        NULL_ERROR_CHECK_RETURN_VOID(dev_red);
        dev_blue = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(LED_BLUE_LABEL), gpios));
   NULL_ERROR_CHECK_RETURN_VOID(dev_blue);
       
        gpio_pin_configure(dev_red, red_gpio, GPIO_OUTPUT_ACTIVE | DT_GPIO_FLAGS(DT_ALIAS(LED_RED_LABEL), gpios));
        gpio_pin_configure(dev_blue, blue_gpio, GPIO_OUTPUT_ACTIVE | DT_GPIO_FLAGS(DT_ALIAS(LED_BLUE_LABEL), gpios));
}

void led_control(int led, int cmd)
{  
    switch (led)
    {
        case LED_RED:
              gpio_pin_set(dev_red, red_gpio, cmd);
              break;
        case LED_BLUE:
              gpio_pin_set(dev_blue, blue_gpio, cmd);
              break;
        default:
              LOG_WRN("GPIO %d is not connected to any LED",led);
            break;
    }  
}
Can someone guide me what to do ?
Thanks in advance ,
Rafalino
Parents Reply Children
  • Hello Einar ,

    It turned out to be something with parentheses since when I changed 

    red_led_gpio = GPIO_DT_SPEC_GET_BY_IDX(DT_N_S_leds_S_led_0, gpios, 0);

    into :
    red_led_gpio.port = DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(DT_N_S_leds_S_led_0, gpios, 0));
         red_led_gpio.pin = DT_GPIO_PIN_BY_IDX(DT_N_S_leds_S_led_0, gpios, 0);
         red_led_gpio.dt_flags = DT_GPIO_FLAGS_BY_IDX(DT_N_S_leds_S_led_0, gpios, 0);


     It eliminated the erros.
     
    Thanks you for your assistance.
Related