Setting up multiple ADC channels in the device tree

Hi,

I am working on setting up multiple ADC channels in the device tree. My starting point is here, which seemed to be an unofficial ADC example that many ADC-related posts referred to.

I can make it work for a single-ended mode as well as a differential mode involving two channels in the source code, but it is difficult to find a suitable guide for setting up the ADC channels in the device tree. After reading off many posts, I came up with the following lines of code in the overlay file:

I set these io-channels and they all show up in zephyr.dts but unfortunately I don't know how to utilize these names yet.
 
Note that I commented out the compatible = "nordic_nrf_saadc", since it caused binding failure and system crash. 

Firstly, I wonder if my approach allows to set up all 8 ADC channels and how to configure all of them in the source code and how I can utilize the names I assigned to each ADC channels. My current source code looks like:
Lastly, is it better to instantiate each channel into an individual node like the following? If so, can I use the node name freely instead of n: node? 
Thank you in advance!
  • Hello, Ted!

    Have you had a look at the Device Tree API documentation for IO Channels? Specifically the DT_IO_CHANNELS_INPUT_BY_NAME macro. I haven't tried these myself, but from what I can see they fit your requirements.

    Regarding your second question I believe you can instantiate all the channels in a single node like they have done in the example code in the documentation.

    Best regards,
    Carl Richard

  • Hi Carl,

    Thank you for the reply. In fact, I used the DT macro to enable the GPIO pins but was unsuccessful with the ADC stuff. The only relevant part was:

    Please note that it didn't need the io-channels to be specified in the overlay file, but those were configured in the source code side instead and it worked fine:
    So my question is, what are the benefits of instantiating these ADC channels in the device tree rather than doing it in the source code?