Replace adc-gain DT binding with adc-inputs
Preparation for cleanup of ADC driver.
This commit is contained in:
@@ -69,35 +69,35 @@
|
||||
};
|
||||
};
|
||||
|
||||
v-low {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 0>;
|
||||
numerator = <105600>;
|
||||
denominator = <5600>;
|
||||
};
|
||||
adc-inputs {
|
||||
compatible = "adc-inputs";
|
||||
|
||||
v-high {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 1>;
|
||||
numerator = <105600>;
|
||||
denominator = <5600>;
|
||||
enable-gpios = <&gpioc 14 GPIO_ACTIVE_HIGH>;
|
||||
};
|
||||
v-low {
|
||||
io-channels = <&adc1 0>;
|
||||
multiplier = <105600>;
|
||||
divider = <5600>;
|
||||
};
|
||||
|
||||
i-load {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 5>;
|
||||
// amp gain: 50, resistor: 3 mOhm
|
||||
numerator = <1000>;
|
||||
denominator = <150>; // 3*50
|
||||
};
|
||||
v-high {
|
||||
io-channels = <&adc1 1>;
|
||||
multiplier = <105600>;
|
||||
divider = <5600>;
|
||||
enable-gpios = <&gpioc 14 GPIO_ACTIVE_HIGH>;
|
||||
};
|
||||
|
||||
i-dcdc {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 6>;
|
||||
// amp gain: 50, resistor: 3 mOhm
|
||||
numerator = <1000>;
|
||||
denominator = <150>; // 3*50
|
||||
i-load {
|
||||
io-channels = <&adc1 5>;
|
||||
// amp gain: 50, resistor: 3 mOhm
|
||||
multiplier = <1000>;
|
||||
divider = <150>; // 3*50
|
||||
};
|
||||
|
||||
i-dcdc {
|
||||
io-channels = <&adc1 6>;
|
||||
// amp gain: 50, resistor: 3 mOhm
|
||||
multiplier = <1000>;
|
||||
divider = <150>; // 3*50
|
||||
};
|
||||
};
|
||||
|
||||
aliases {
|
||||
|
||||
@@ -63,50 +63,48 @@
|
||||
};
|
||||
};
|
||||
|
||||
v-low {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 12>;
|
||||
numerator = <105600>;
|
||||
denominator = <5600>;
|
||||
};
|
||||
adc-inputs {
|
||||
compatible = "adc-inputs";
|
||||
|
||||
v-high {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 15>;
|
||||
numerator = <102200>;
|
||||
denominator = <2200>;
|
||||
};
|
||||
v-low {
|
||||
io-channels = <&adc1 12>;
|
||||
multiplier = <105600>;
|
||||
divider = <5600>;
|
||||
};
|
||||
|
||||
v-pwm {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 4>;
|
||||
numerator = <25224>; // (12*8.2 + 120*8.2 + 120*12) * 10
|
||||
denominator = <984>; // (8.2*12) * 10
|
||||
raw-offset = <2338>; // 4096 / (1 + 8.2/120 + 8.2/12)
|
||||
};
|
||||
v-high {
|
||||
io-channels = <&adc1 15>;
|
||||
multiplier = <102200>;
|
||||
divider = <2200>;
|
||||
};
|
||||
|
||||
i-dcdc {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc2 1>;
|
||||
// amp gain: 20, resistor: 2 mOhm
|
||||
numerator = <1000>; // 1000
|
||||
denominator = <40>; // 2*20
|
||||
};
|
||||
v-pwm {
|
||||
io-channels = <&adc1 4>;
|
||||
multiplier = <25224>; // (12*8.2 + 120*8.2 + 120*12) * 10
|
||||
divider = <984>; // (8.2*12) * 10
|
||||
offset = <2338>; // 4096 / (1 + 8.2/120 + 8.2/12)
|
||||
};
|
||||
|
||||
i-load {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc2 2>;
|
||||
// amp gain: 68/2.2, resistor: 2 mOhm
|
||||
numerator = <2200>; // 1000*2.2
|
||||
denominator = <136>; // 2*68
|
||||
};
|
||||
i-dcdc {
|
||||
io-channels = <&adc2 1>;
|
||||
// amp gain: 20, resistor: 2 mOhm
|
||||
multiplier = <1000>; // 1000
|
||||
divider = <40>; // 2*20
|
||||
};
|
||||
|
||||
i-pwm {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc2 5>;
|
||||
// amp gain: 68/2.2, resistor: 2 mOhm
|
||||
numerator = <2200>; // 1000*2.2
|
||||
denominator = <136>; // 2*68
|
||||
i-load {
|
||||
io-channels = <&adc2 2>;
|
||||
// amp gain: 68/2.2, resistor: 2 mOhm
|
||||
multiplier = <2200>; // 1000*2.2
|
||||
divider = <136>; // 2*68
|
||||
};
|
||||
|
||||
i-pwm {
|
||||
io-channels = <&adc2 5>;
|
||||
// amp gain: 68/2.2, resistor: 2 mOhm
|
||||
multiplier = <2200>; // 1000*2.2
|
||||
divider = <136>; // 2*68
|
||||
};
|
||||
};
|
||||
|
||||
soc {
|
||||
|
||||
@@ -73,34 +73,34 @@
|
||||
};
|
||||
};
|
||||
|
||||
v-low {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 0>;
|
||||
numerator = <110000>;
|
||||
denominator = <10000>;
|
||||
};
|
||||
adc-inputs {
|
||||
compatible = "adc-inputs";
|
||||
|
||||
v-high {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 1>;
|
||||
numerator = <105600>;
|
||||
denominator = <5600>;
|
||||
};
|
||||
v-low {
|
||||
io-channels = <&adc1 0>;
|
||||
multiplier = <110000>;
|
||||
divider = <10000>;
|
||||
};
|
||||
|
||||
i-load {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 5>;
|
||||
// amp gain: 150/2.2, resistor: 2 mOhm
|
||||
numerator = <2200>; // 1000*2.2
|
||||
denominator = <300>; // 2*150
|
||||
};
|
||||
v-high {
|
||||
io-channels = <&adc1 1>;
|
||||
multiplier = <105600>;
|
||||
divider = <5600>;
|
||||
};
|
||||
|
||||
i-dcdc {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 6>;
|
||||
// amp gain: 150/2.2, resistor: 2 mOhm
|
||||
numerator = <2200>; // 1000*2.2
|
||||
denominator = <300>; // 2*150
|
||||
i-load {
|
||||
io-channels = <&adc1 5>;
|
||||
// amp gain: 150/2.2, resistor: 2 mOhm
|
||||
multiplier = <2200>; // 1000*2.2
|
||||
divider = <300>; // 2*150
|
||||
};
|
||||
|
||||
i-dcdc {
|
||||
io-channels = <&adc1 6>;
|
||||
// amp gain: 150/2.2, resistor: 2 mOhm
|
||||
multiplier = <2200>; // 1000*2.2
|
||||
divider = <300>; // 2*150
|
||||
};
|
||||
};
|
||||
|
||||
aliases {
|
||||
|
||||
@@ -44,26 +44,27 @@
|
||||
};
|
||||
};
|
||||
|
||||
v-low {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 12>;
|
||||
numerator = <105600>;
|
||||
denominator = <5600>;
|
||||
};
|
||||
adc-inputs {
|
||||
compatible = "adc-inputs";
|
||||
|
||||
v-high {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 15>;
|
||||
numerator = <102200>;
|
||||
denominator = <2200>;
|
||||
};
|
||||
v-low {
|
||||
io-channels = <&adc1 12>;
|
||||
multiplier = <105600>;
|
||||
divider = <5600>;
|
||||
};
|
||||
|
||||
i-dcdc {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc2 1>;
|
||||
// amp gain: 68/2.2, resistor: 2 mOhm
|
||||
numerator = <2200>; // 1000*2.2
|
||||
denominator = <136>; // 2*68
|
||||
v-high {
|
||||
io-channels = <&adc1 15>;
|
||||
multiplier = <102200>;
|
||||
divider = <2200>;
|
||||
};
|
||||
|
||||
i-dcdc {
|
||||
io-channels = <&adc2 1>;
|
||||
// amp gain: 68/2.2, resistor: 2 mOhm
|
||||
multiplier = <2200>; // 1000*2.2
|
||||
divider = <136>; // 2*68
|
||||
};
|
||||
};
|
||||
|
||||
soc {
|
||||
|
||||
@@ -75,36 +75,36 @@
|
||||
};
|
||||
};
|
||||
|
||||
v-low {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 0>;
|
||||
numerator = <132000>;
|
||||
denominator = <12000>;
|
||||
};
|
||||
adc-inputs {
|
||||
compatible = "adc-inputs";
|
||||
|
||||
v-pwm {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 1>;
|
||||
numerator = <25224>; // (12*8.2 + 120*8.2 + 120*12) * 10
|
||||
denominator = <984>; // (8.2*12) * 10
|
||||
raw-offset = <2338>; // 4096 / (1 + 8.2/120 + 8.2/12)
|
||||
};
|
||||
v-low {
|
||||
io-channels = <&adc1 0>;
|
||||
multiplier = <132000>;
|
||||
divider = <12000>;
|
||||
};
|
||||
|
||||
i-load {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 5>;
|
||||
// amp gain: 68/2.2, resistor: 2 mOhm
|
||||
// fix for hardware bug in overcurrent comparator voltage divider wiring
|
||||
numerator = <2931>; // 1000 * (39+12+8.2) / (12+8.2) = 2930.69
|
||||
denominator = <62>; // 2*68/2.2 = 61.8181
|
||||
};
|
||||
v-pwm {
|
||||
io-channels = <&adc1 1>;
|
||||
multiplier = <25224>; // (12*8.2 + 120*8.2 + 120*12) * 10
|
||||
divider = <984>; // (8.2*12) * 10
|
||||
offset = <2338>; // 4096 / (1 + 8.2/120 + 8.2/12)
|
||||
};
|
||||
|
||||
i-pwm {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 6>;
|
||||
// amp gain: 68/2.2, resistor: 2 mOhm
|
||||
numerator = <2200>; // 1000*2.2
|
||||
denominator = <136>; // 2*68
|
||||
i-load {
|
||||
io-channels = <&adc1 5>;
|
||||
// amp gain: 68/2.2, resistor: 2 mOhm
|
||||
// fix for hardware bug in overcurrent comparator voltage divider wiring
|
||||
multiplier = <2931>; // 1000 * (39+12+8.2) / (12+8.2) = 2930.69
|
||||
divider = <62>; // 2*68/2.2 = 61.8181
|
||||
};
|
||||
|
||||
i-pwm {
|
||||
io-channels = <&adc1 6>;
|
||||
// amp gain: 68/2.2, resistor: 2 mOhm
|
||||
multiplier = <2200>; // 1000*2.2
|
||||
divider = <136>; // 2*68
|
||||
};
|
||||
};
|
||||
|
||||
aliases {
|
||||
|
||||
+1
-1
@@ -162,7 +162,7 @@ void daq_update()
|
||||
|
||||
#if DT_OUTPUTS_PWM_SWITCH_PRESENT
|
||||
pwm_switch.ext_voltage = lv_bus.voltage -
|
||||
adc_scaled(ADC_POS_V_PWM, vref, ADC_GAIN(V_PWM), DT_ADC_GAIN_V_PWM_RAW_OFFSET);
|
||||
adc_scaled(ADC_POS_V_PWM, vref, ADC_GAIN(V_PWM), DT_ADC_INPUTS_V_PWM_OFFSET);
|
||||
#endif
|
||||
|
||||
#if DT_OUTPUTS_LOAD_PRESENT
|
||||
|
||||
@@ -34,7 +34,7 @@ extern "C" {
|
||||
#define VREF (VREFINT_VALUE * VREFINT_CAL / adc_value(ADC_POS_VREF_MCU))
|
||||
#endif
|
||||
|
||||
#define ADC_GAIN(name) ((float)DT_ADC_GAIN_##name##_NUMERATOR / DT_ADC_GAIN_##name##_DENOMINATOR)
|
||||
#define ADC_GAIN(name) ((float)DT_ADC_INPUTS_##name##_MULTIPLIER / DT_ADC_INPUTS_##name##_DIVIDER)
|
||||
|
||||
/**
|
||||
* Struct to definie upper and lower limit alerts for any ADC channel
|
||||
|
||||
+4
-4
@@ -187,10 +187,10 @@ static void adc_init(ADC_TypeDef *adc)
|
||||
|
||||
static void adc_setup()
|
||||
{
|
||||
#ifdef DT_ADC_GAIN_V_HIGH_ENABLE_GPIOS_PIN
|
||||
struct device *dev = device_get_binding(DT_ADC_GAIN_V_HIGH_ENABLE_GPIOS_CONTROLLER);
|
||||
gpio_pin_configure(dev, DT_ADC_GAIN_V_HIGH_ENABLE_GPIOS_PIN,
|
||||
DT_ADC_GAIN_V_HIGH_ENABLE_GPIOS_FLAGS | GPIO_OUTPUT_ACTIVE);
|
||||
#ifdef DT_ADC_INPUTS_V_HIGH_ENABLE_GPIOS_PIN
|
||||
struct device *dev = device_get_binding(DT_ADC_INPUTS_V_HIGH_ENABLE_GPIOS_CONTROLLER);
|
||||
gpio_pin_configure(dev, DT_ADC_INPUTS_V_HIGH_ENABLE_GPIOS_PIN,
|
||||
DT_ADC_INPUTS_V_HIGH_ENABLE_GPIOS_FLAGS | GPIO_OUTPUT_ACTIVE);
|
||||
#endif
|
||||
|
||||
adc_init(ADC1);
|
||||
|
||||
+13
-13
@@ -101,21 +101,21 @@ static const enum pin_state_t led_pin_setup[NUM_LEDS][NUM_LED_PINS] = {
|
||||
#define NTC_BETA_VALUE 3435
|
||||
#define NTC_SERIES_RESISTOR 8200.0
|
||||
|
||||
#define DT_ADC_GAIN_V_HIGH_NUMERATOR 105600
|
||||
#define DT_ADC_GAIN_V_HIGH_DENOMINATOR 5600
|
||||
#define DT_ADC_GAIN_V_LOW_NUMERATOR 105600
|
||||
#define DT_ADC_GAIN_V_LOW_DENOMINATOR 5600
|
||||
#define DT_ADC_GAIN_V_PWM_NUMERATOR 25224 // see pwm_2420_lus.dtx
|
||||
#define DT_ADC_GAIN_V_PWM_DENOMINATOR 984
|
||||
#define DT_ADC_GAIN_V_PWM_RAW_OFFSET 2338
|
||||
#define DT_ADC_INPUTS_V_HIGH_MULTIPLIER 105600
|
||||
#define DT_ADC_INPUTS_V_HIGH_DIVIDER 5600
|
||||
#define DT_ADC_INPUTS_V_LOW_MULTIPLIER 105600
|
||||
#define DT_ADC_INPUTS_V_LOW_DIVIDER 5600
|
||||
#define DT_ADC_INPUTS_V_PWM_MULTIPLIER 25224 // see pwm_2420_lus.dtx
|
||||
#define DT_ADC_INPUTS_V_PWM_DIVIDER 984
|
||||
#define DT_ADC_INPUTS_V_PWM_OFFSET 2338
|
||||
|
||||
// amp gain: 50, resistor: 4 mOhm
|
||||
#define DT_ADC_GAIN_I_LOAD_NUMERATOR 1000
|
||||
#define DT_ADC_GAIN_I_LOAD_DENOMINATOR (4 * 50)
|
||||
#define DT_ADC_GAIN_I_DCDC_NUMERATOR 1000
|
||||
#define DT_ADC_GAIN_I_DCDC_DENOMINATOR (4 * 50)
|
||||
#define DT_ADC_GAIN_I_PWM_NUMERATOR 1000
|
||||
#define DT_ADC_GAIN_I_PWM_DENOMINATOR (4 * 50)
|
||||
#define DT_ADC_INPUTS_I_LOAD_MULTIPLIER 1000
|
||||
#define DT_ADC_INPUTS_I_LOAD_DIVIDER (4 * 50)
|
||||
#define DT_ADC_INPUTS_I_DCDC_MULTIPLIER 1000
|
||||
#define DT_ADC_INPUTS_I_DCDC_DIVIDER (4 * 50)
|
||||
#define DT_ADC_INPUTS_I_PWM_MULTIPLIER 1000
|
||||
#define DT_ADC_INPUTS_I_PWM_DIVIDER (4 * 50)
|
||||
|
||||
// position in the array written by the DMA controller
|
||||
enum {
|
||||
|
||||
@@ -1,33 +1,32 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright (c) 2020 Martin Jäger / Libre Solar
|
||||
|
||||
# Based on official Zephyr binding "voltage-divider" by Peter Bigot
|
||||
description: Description for an ADC input including gain (multiplier/divider) and offset
|
||||
|
||||
description: |
|
||||
Description for a gain (voltage divider or amplifier) at an ADC input
|
||||
compatible: "adc-inputs"
|
||||
|
||||
compatible: "adc-gain"
|
||||
|
||||
properties:
|
||||
child-binding:
|
||||
description: ADC inputs child node
|
||||
properties:
|
||||
io-channels:
|
||||
type: phandle-array
|
||||
required: true
|
||||
description: |
|
||||
Channels available with this divider configuration.
|
||||
ADC channel for this input.
|
||||
|
||||
numerator:
|
||||
multiplier:
|
||||
type: int
|
||||
required: true
|
||||
description: |
|
||||
Resistance of the lower leg of the voltage divider
|
||||
Resistance of the lower leg of the voltage divider.
|
||||
|
||||
denominator:
|
||||
divider:
|
||||
type: int
|
||||
required: true
|
||||
description: |
|
||||
Resistance of the full path through the voltage divider.
|
||||
|
||||
raw-offset:
|
||||
offset:
|
||||
type: int
|
||||
required: false
|
||||
description: |
|
||||
@@ -51,19 +51,21 @@
|
||||
/delete-node/ boot0;
|
||||
};
|
||||
|
||||
i-load {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 6>;
|
||||
// amp gain: 50, resistor: 4 mOhm
|
||||
numerator = <1000>;
|
||||
denominator = <200>; // 4*50
|
||||
};
|
||||
adc-inputs {
|
||||
compatible = "adc-inputs";
|
||||
|
||||
i-dcdc {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 7>;
|
||||
// amp gain: 50, resistor: 4 mOhm
|
||||
numerator = <1000>;
|
||||
denominator = <200>; // 4*50
|
||||
i-load {
|
||||
io-channels = <&adc1 6>;
|
||||
// amp gain: 50, resistor: 4 mOhm
|
||||
multiplier = <1000>;
|
||||
divider = <200>; // 4*50
|
||||
};
|
||||
|
||||
i-dcdc {
|
||||
io-channels = <&adc1 7>;
|
||||
// amp gain: 50, resistor: 4 mOhm
|
||||
multiplier = <1000>;
|
||||
divider = <200>; // 4*50
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -10,11 +10,14 @@
|
||||
version-num = <2>;
|
||||
};
|
||||
|
||||
i-load {
|
||||
compatible = "adc-gain";
|
||||
io-channels = <&adc1 5>;
|
||||
// amp gain: 68/2.2, resistor: 2 mOhm
|
||||
numerator = <1000>;
|
||||
denominator = <62>; // 2*68/2.2 = 61.8181
|
||||
adc-inputs {
|
||||
compatible = "adc-inputs";
|
||||
|
||||
i-load {
|
||||
io-channels = <&adc1 5>;
|
||||
// amp gain: 68/2.2, resistor: 2 mOhm
|
||||
multiplier = <1000>;
|
||||
divider = <62>; // 2*68/2.2 = 61.8181
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user