How to obtain the port from the button devicetree specification?

Dear Community,

Following the Nordic's sample of the (<ncs root>/nrf/sample/caf) the LED module & (CAF) Button module demonstrate the LED states & LED effects (awesome!)
After reading the code and tweaking it a bit (set the step from 15 to 31 for a very smooth visual effect).
I decided to migrate it to my hardware board (with a nrf52840) and play a little more.

So it begin with configuring the actual buttons and led reflecting its presence in the board dts or overlay.
for the demo this information is kept in the button_def.h and led_state_def.h
unfortunately, this example has some hardcoded values for button port (it does not come devicetree)

{.port = 0, .pin = DT_GPIO_PIN(DT_NODELABEL(button3), gpios)},

I already did pull-out some gray hears from my head to figure a solution.

1st question: How to obtain the port from the button specification? Which marco?

Any hint / tip / help or advice is most welcome!

Second question:
   For the common application framework - LED module - how to configure a multi-color led (that has no blue) (thus; only red+green led in one house?) 
   As a current work around i added blue + pwm and assign it to a dummy/empty pin (but the final designed product has no spare pins available) so how to overcome?

Parents Reply
  • Hello   

    I did try both suggestion, and both did not compile
    reasson: both suggestions the compiler cannot convert a device pointer into a logic gpio port number.

    The Nordic samples of the CAF button & led module uses a logical gprio port index and in the examples
    this port index is hardcoded to 0.

    Me as developer has to adapting the CAF to my own custom board
    resulting change .dts, kConfig 
    and correct the hardcoded 0 in programmed the caf led and caf button modules.

    After reading a lot about devicetree and binding documentation on zephyr & nordic websites.

    I think the correct solution to obtain the logical port index from a button is:
    DT_NODE_CHILD_IDX(DT_NODELABEL(button0)) 
     
    for example :
      if button0 is connected to P1.07 (aka pin7 of port1)
         then the below statement return 1
    DT_NODE_CHILD_IDX(DT_NODELABEL(button0)) 
      
    note: I still have to test my solution.


Children
Related