add or remove button in overlay file

Hi,

Using VisualStudioCode/NRF Connect:  Im looking into the sample 'button'.  (this because i like to add GPIO-pins to connect to an interrupt)

In the button example  an interrupt means is used on a button, so thats fine.

Now i would like to add a button  in an overlay-file 

there are 4 buttons in nrf5340_cpuapp_common.dts

Is it possible to ADD buttons in an overlay file  nrf5340dk_nrf5340_cpuapp.overlay

..what should i need to put in that overlay file?

 

(And is it possible to remove a button ?, how is that to be done?)

Best Regards,

Theo  

Parents
  • Hi,

    As you can see, in the code, only one button is used. So if you need to add more buttons, you will have to do the change in the main.c first. 

    In the dts file, the sw0 is set to button0, sw1 is set to button1 and so on.

    So you will just have to add more sw nodes in the main.c

    But if you need to make a change, say, change the current button to button1, you can write that in the overlay file.

    For eg, now you get the output at button0 and if you want that in button1, you can create the following overlay file:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    /{
    aliases {
    sw0 = &button1;
    };
    };
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    More information about writing the overlay file can be found in the Devicetree HOWTOs of Zephyr.

    Regards,

    Priyanka

  • Hi Priyanka,

    Thanks for the answer.

    But it is not exactly what I mean,   I would like to use MORE then 4 buttons , so lets say adding a 5-th button. Can that be done in the overlay file ?

    Best Regards,

    Theo

  • Hi,

    You should be able to define more buttons similar to how the other 4 buttons are defines in the devicetree.

    For eg,

    Fullscreen
    1
    2
    3
    4
    button5: button_5 {
    gpios = <&gpio0 PIN_NUMBER (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
    label = "Push button switch 5";
    };
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Regards,

    Priyanka

  • Thank you Priyanka,

    That works.

    And what if i would like to remove one of the 4- original buttons,   is it possible to remove a button with the overlay file ?    (or disable a button)

    Best Regards,

    Theo

  • Why do you wish to disable the button? Do you want to use the gpio pin assigned to the button?

    -Priyanka

  • Ah Ok..,   yes a gpio-pin of a button i would like to use for something else

  • So if you wish to disable a button, you could try disabling the gpio pin assigned to the buttons. This can be don in the overlay file.

    Take a look at the Buttons and LEDs for the nRF5340DK. Also, if you wish to use those gpio pins, I think you might have to physically remove the buttons maybe. But there are a lot of other gpio pins Smiley

    -Priyanka

Reply
  • So if you wish to disable a button, you could try disabling the gpio pin assigned to the buttons. This can be don in the overlay file.

    Take a look at the Buttons and LEDs for the nRF5340DK. Also, if you wish to use those gpio pins, I think you might have to physically remove the buttons maybe. But there are a lot of other gpio pins Smiley

    -Priyanka

Children