NRF52840 BLE LED/Button Pairing

Hello. 

I am modifying the nRF52840DK NRF desktop firmware for a custom mouse application. Using the standard firmware, LED2 is used as the status LED for connectivity. What is the best way to reconfigure the status LED (LED3 or LED4)? I can't find any setting in the nRF Kconfig GUI. Also, is there any way to reconfigure other buttons as the peer control? 

Thank you.

Parents
  • Hi,

    I believe you have to do it in the .dts file for your project. The board or your project would have an LED2 section as "gpio-led" in the board's DTS file. You can still name it LED2 but change the pin assignment and re-build. Or you can add a new LED3/4 in your DTS file following the same conventions as LED2, configure LED3/4 instead of LED2 in your source, and rebuild.

    Example:

    board_device_tree.dts

    / { 
    	leds {
    	compatible = "gpio-leds";
    
    	led1: led_1{
    		gpios = < &gpio0 24 GPIO_ACTIVE_HIGH>;
    		label = "Green LED";
    	};
    
    	led2: led_2{
    		gpios = < &gpio1 16 GPIO_ACTIVE_HIGH>;
    		label = "Blue LED";
    	};
    }

    led.c:

    /* The devicetree node identifier for the leds. */
    #define LED_GREEN_NODE DT_NODELABEL(led1)
    #define LED_BLUE_NODE DT_NODELABEL(led2)
    
    static const struct gpio_dt_spec led_green = GPIO_DT_SPEC_GET(LED_GREEN_NODE, gpios);
    static const struct gpio_dt_spec led_blue = GPIO_DT_SPEC_GET(LED_BLUE_NODE, gpios);
    
    K_THREAD_DEFINE(green_blinky_tid, LED_STACKSIZE, green_blinky, NULL, NULL, NULL, 2, 0, 0);
    K_THREAD_DEFINE(blue_blinky_tid, LED_STACKSIZE, blue_blinky, NULL, NULL, NULL, 2, 0, 0);
    
    void green_blinky(void)
    {
    	int ret; 
    	
    	gpio_pin_configure_dt(&led_green, GPIO_OUTPUT_ACTIVE);
    
    	if (!gpio_is_ready_dt(&led_green))
    	{
    		return;
    	}
    
    	while (1)
    	{
    		ret = gpio_pin_toggle_dt(&led_green);
    		if (ret < 0) {
    			return;
    		}
    		k_msleep(SLEEP_TIME_MS);
    	}
    	return;
    
    }
    
    void blue_blinky(void)
    {
    	int ret;
    	
    	gpio_pin_configure_dt(&led_blue, GPIO_OUTPUT_ACTIVE);
    
    	if (!gpio_is_ready_dt(&led_blue))
    	{
    		return;
    	}
    
    	while (1)
    	{
    		ret = gpio_pin_toggle_dt(&led_blue);
    		if (ret < 0) {
    			return;
    		}
    		k_msleep(SLEEP_TIME_MS / 2);
    	}
    	return;
    }

    Something along those lines.

    Cheers,

    Alberto

Reply
  • Hi,

    I believe you have to do it in the .dts file for your project. The board or your project would have an LED2 section as "gpio-led" in the board's DTS file. You can still name it LED2 but change the pin assignment and re-build. Or you can add a new LED3/4 in your DTS file following the same conventions as LED2, configure LED3/4 instead of LED2 in your source, and rebuild.

    Example:

    board_device_tree.dts

    / { 
    	leds {
    	compatible = "gpio-leds";
    
    	led1: led_1{
    		gpios = < &gpio0 24 GPIO_ACTIVE_HIGH>;
    		label = "Green LED";
    	};
    
    	led2: led_2{
    		gpios = < &gpio1 16 GPIO_ACTIVE_HIGH>;
    		label = "Blue LED";
    	};
    }

    led.c:

    /* The devicetree node identifier for the leds. */
    #define LED_GREEN_NODE DT_NODELABEL(led1)
    #define LED_BLUE_NODE DT_NODELABEL(led2)
    
    static const struct gpio_dt_spec led_green = GPIO_DT_SPEC_GET(LED_GREEN_NODE, gpios);
    static const struct gpio_dt_spec led_blue = GPIO_DT_SPEC_GET(LED_BLUE_NODE, gpios);
    
    K_THREAD_DEFINE(green_blinky_tid, LED_STACKSIZE, green_blinky, NULL, NULL, NULL, 2, 0, 0);
    K_THREAD_DEFINE(blue_blinky_tid, LED_STACKSIZE, blue_blinky, NULL, NULL, NULL, 2, 0, 0);
    
    void green_blinky(void)
    {
    	int ret; 
    	
    	gpio_pin_configure_dt(&led_green, GPIO_OUTPUT_ACTIVE);
    
    	if (!gpio_is_ready_dt(&led_green))
    	{
    		return;
    	}
    
    	while (1)
    	{
    		ret = gpio_pin_toggle_dt(&led_green);
    		if (ret < 0) {
    			return;
    		}
    		k_msleep(SLEEP_TIME_MS);
    	}
    	return;
    
    }
    
    void blue_blinky(void)
    {
    	int ret;
    	
    	gpio_pin_configure_dt(&led_blue, GPIO_OUTPUT_ACTIVE);
    
    	if (!gpio_is_ready_dt(&led_blue))
    	{
    		return;
    	}
    
    	while (1)
    	{
    		ret = gpio_pin_toggle_dt(&led_blue);
    		if (ret < 0) {
    			return;
    		}
    		k_msleep(SLEEP_TIME_MS / 2);
    	}
    	return;
    }

    Something along those lines.

    Cheers,

    Alberto

Children
No Data
Related