This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Designate ADC pins through devicetree (Zephyr OS)

Is there a way to specify which AIN should be used through the devicetree API? For example, here is a code snippet:

static struct adc_channel_cfg adc_meas_config =
{
    .gain = ADC_GAIN_1_6,
    .reference = ADC_REF_INTERNAL,
    .acquisition_time = ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 40),
    .channel_id = 0,
    .input_positive = NRF_SAADC_INPUT_AIN6
};

How would I use the devicetree API to replace the NRF_SAADC_INPUT_AIN6 in that assignment with something from the devicetree? I know how to do this with GPIO assignments like this:

In the DTS file:
    control_pins {
        compatible = "gpio-leds";
        en_5v: en_5v {
            gpios = <&gpio0 13 GPIO_INT_ACTIVE_HIGH>;
            label = "5V Enable";
        };
    };

In the C file: 
    DT_GPIO_PIN_BY_IDX(DT_NODELABEL(en_5v), gpios, 0)

Parents Reply
  • Is there a way through the DTS file to assign an analog pin to a name? This would be useful for projects which use similar measurement circuitry but are based on different parts (e.g. one project uses 9160 and another uses 5340 but both have a battery voltage measurement circuit). Then the C code which takes the measurement would be more portable.

    Is there a way to use custom fields which could be assigned in the DTS file for this purpose?

Children
Related