Refactor VND7050AJ sensor configuration to eliminate redundancy

- Create centralized sensor multiplexer node (vnd7050aj_mux) with shared configuration
- Consolidate ADC channel, GPIO pins, and reference voltage in single location
- Update sensor bindings to reference centralized mux via sensor-mux property
- Add channel-based sensor selection using mux-channel property (0-3)
- Refactor ADC sensor library to use centralized GPIO and channel control
- Update valve library to use new vnd7050aj_mux node reference
- Eliminate duplicate ADC/GPIO definitions between voltage and current sensors
- Ensure configuration consistency and prevent mismatched settings

Benefits:
- Single source of truth for VND7050AJ hardware configuration
- Impossible to have inconsistent GPIO/ADC settings between sensors
- Simplified maintenance and scalability for additional sensors
- Clean channel-based multiplexer selection interface
This commit is contained in:
2025-07-08 17:05:34 +02:00
parent a9a0626913
commit 222ffea568
6 changed files with 185 additions and 240 deletions

View File

@@ -1,15 +1,23 @@
/ {
vnd7050aj: vnd7050aj {
compatible = "vnd7050aj-valve-controller";
/* VND7050AJ Sensor Multiplexer - Centralized configuration */
vnd7050aj_mux: sensor-multiplexer {
compatible = "vnd7050aj,sensor-mux";
status = "okay";
// VND7050AJ GPIO pin definitions
in0-gpios = <&gpiob 7 GPIO_ACTIVE_HIGH>; // IN0 (PB7) - Input 0 control signal
in1-gpios = <&gpiob 9 GPIO_ACTIVE_HIGH>; // IN1 (PB9) - Input 1 control signal
rst-gpios = <&gpiob 3 GPIO_ACTIVE_HIGH>; // RST (PB3) - Reset pin for VND7050AJ
sen-gpios = <&gpiob 4 GPIO_ACTIVE_HIGH>; // SEN (PB4) - Sense Enable for current monitoring
s0-gpios = <&gpiob 6 GPIO_ACTIVE_HIGH>; // S0 (PB6) - Status/Select 0 output from VND7050AJ
s1-gpios = <&gpiob 5 GPIO_ACTIVE_HIGH>; // S1 (PB5) - Status/Select 1 output from VND7050AJ
/* Shared ADC configuration */
io-channels = <&adc1 1>; /* ADC1 channel 1 (PA0) */
io-channel-names = "sensor-input";
reference-mv = <3300>;
/* VND7050AJ GPIO pin definitions - shared by all sensors */
sen-gpios = <&gpiob 4 GPIO_ACTIVE_HIGH>; /* SEN (PB4) - Sense Enable */
s0-gpios = <&gpiob 6 GPIO_ACTIVE_HIGH>; /* S0 (PB6) - Mux select bit 0 */
s1-gpios = <&gpiob 5 GPIO_ACTIVE_HIGH>; /* S1 (PB5) - Mux select bit 1 */
/* Valve control pins (separate from sensor mux) */
in0-gpios = <&gpiob 7 GPIO_ACTIVE_HIGH>; /* IN0 (PB7) - Valve input 0 */
in1-gpios = <&gpiob 9 GPIO_ACTIVE_HIGH>; /* IN1 (PB9) - Valve input 1 */
rst-gpios = <&gpiob 3 GPIO_ACTIVE_HIGH>; /* RST (PB3) - Reset pin */
};
adc_sensors {
@@ -17,32 +25,22 @@
supply_voltage: supply-voltage {
compatible = "custom,supply-voltage";
io-channels = <&adc1 1>; /* ADC1 channel 1 (PA0) */
io-channel-names = "voltage";
reference-mv = <3300>;
sensor-mux = <&vnd7050aj_mux>; /* Reference to shared mux config */
/* Sensor-specific configuration */
voltage-divider-ratio = <4>; /* Adjust based on your voltage divider */
/* GPIO control pins using VND7050AJ pins */
sen-gpios = <&gpiob 4 GPIO_ACTIVE_HIGH>; /* SEN (PB4) - enable sensor */
s0-gpios = <&gpiob 6 GPIO_ACTIVE_HIGH>; /* S0 (PB6) - mux select bit 0 */
s1-gpios = <&gpiob 5 GPIO_ACTIVE_HIGH>; /* S1 (PB5) - mux select bit 1 */
measurement-delay-ms = <5>; /* 5ms delay after GPIO setup */
mux-channel = <0>; /* Channel 0: s1=0, s0=0 */
measurement-delay-ms = <5>; /* 5ms delay after GPIO setup */
};
motor_current: motor-current {
compatible = "custom,motor-current";
io-channels = <&adc1 1>; /* Same ADC channel, different mux setting */
io-channel-names = "current";
reference-mv = <3300>;
sensor-mux = <&vnd7050aj_mux>; /* Reference to shared mux config */
/* Sensor-specific configuration */
current-sense-resistor-mohm = <100>; /* 100mΩ sense resistor */
/* GPIO control pins using VND7050AJ pins */
sen-gpios = <&gpiob 4 GPIO_ACTIVE_HIGH>; /* SEN (PB4) - enable sensor */
s0-gpios = <&gpiob 6 GPIO_ACTIVE_HIGH>; /* S0 (PB6) - mux select bit 0 */
s1-gpios = <&gpiob 5 GPIO_ACTIVE_HIGH>; /* S1 (PB5) - mux select bit 1 */
measurement-delay-ms = <10>; /* 10ms delay for current settling */
mux-channel = <1>; /* Channel 1: s1=0, s0=1 */
measurement-delay-ms = <10>; /* 10ms delay for current settling */
};
};
};
@@ -86,15 +84,6 @@
st,adc-prescaler = <4>;
#address-cells = <1>;
#size-cells = <0>;
// Definition des ADC-Kanals für MULTISENSE (PA0)
channel@1 { // ADC1_IN1 ist Kanal 1
reg = <1>; // Kanalnummer
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,resolution = <12>;
};
};
&pinctrl {

View File

@@ -1,16 +1,13 @@
description: Custom motor current measurement with GPIO control
# Custom motor current sensor binding
description: Motor current sensor using VND7050AJ multiplexer
compatible: "custom,motor-current"
properties:
io-channels:
type: phandle-array
sensor-mux:
type: phandle
required: true
description: ADC channel for current measurement
io-channel-names:
type: string-array
description: Names for the ADC channels
description: Reference to the VND7050AJ sensor multiplexer node
current-sense-resistor-mohm:
type: int
@@ -19,30 +16,17 @@ properties:
amplifier-gain:
type: int
required: false
default: 1
description: Current sense amplifier gain
reference-mv:
mux-channel:
type: int
default: 3300
description: ADC reference voltage in millivolts
sen-gpios:
type: phandle-array
required: true
description: GPIO to enable/disable the current measurement sensor
s0-gpios:
type: phandle-array
required: true
description: GPIO for multiplexer control bit 0
s1-gpios:
type: phandle-array
required: true
description: GPIO for multiplexer control bit 1
description: Multiplexer channel number (0-3) for this sensor
measurement-delay-ms:
type: int
required: false
default: 10
description: Delay in milliseconds after setting GPIOs before ADC measurement
description: Delay in milliseconds after GPIO setup before measurement

View File

@@ -1,63 +1,26 @@
description: Custom supply voltage measurement with GPIO control
# Custom supply voltage sensor binding
description: Supply voltage sensor using VND7050AJ multiplexer
compatible: "custom,supply-voltage"
properties:
io-channels:
type: phandle-array
sensor-mux:
type: phandle
required: true
description: ADC channel for voltage measurement
io-channel-names:
type: string-array
description: Names for the ADC channels
description: Reference to the VND7050AJ sensor multiplexer node
voltage-divider-ratio:
type: int
required: true
description: Voltage divider ratio for scaling
description: Voltage divider ratio for scaling measurements
reference-mv:
mux-channel:
type: int
default: 3300
description: ADC reference voltage in millivolts
sen-gpios:
type: phandle-array
required: true
description: GPIO to enable/disable the voltage measurement sensor
s0-gpios:
type: phandle-array
required: true
description: GPIO for multiplexer control bit 0
s1-gpios:
type: phandle-array
required: true
description: GPIO for multiplexer control bit 1
description: Multiplexer channel number (0-3) for this sensor
measurement-delay-ms:
type: int
default: 10
description: Delay in milliseconds after setting GPIOs before ADC measurement
sen-gpios:
type: phandle-array
required: true
description: GPIO for SEN (Sense Enable) pin
s0-gpios:
type: phandle-array
required: true
description: GPIO for S0 (Select 0) pin
s1-gpios:
type: phandle-array
required: true
description: GPIO for S1 (Select 1) pin
measurement-delay-ms:
type: int
default: 10
description: Delay in milliseconds after setting control pins before ADC reading
required: false
default: 5
description: Delay in milliseconds after GPIO setup before measurement

View File

@@ -0,0 +1,50 @@
# VND7050AJ Sensor Multiplexer binding
description: VND7050AJ sensor multiplexer for ADC channel selection
compatible: "vnd7050aj,sensor-mux"
properties:
io-channels:
type: phandle-array
required: true
description: ADC channel phandle and specifier for sensor input
io-channel-names:
type: string-array
required: true
description: Names for the ADC channels
reference-mv:
type: int
required: true
description: ADC reference voltage in millivolts
sen-gpios:
type: phandle-array
required: true
description: GPIO for sensor enable (SEN pin)
s0-gpios:
type: phandle-array
required: true
description: GPIO for multiplexer select bit 0 (S0 pin)
s1-gpios:
type: phandle-array
required: true
description: GPIO for multiplexer select bit 1 (S1 pin)
in0-gpios:
type: phandle-array
required: false
description: GPIO for valve input 0 control (IN0 pin)
in1-gpios:
type: phandle-array
required: false
description: GPIO for valve input 1 control (IN1 pin)
rst-gpios:
type: phandle-array
required: false
description: GPIO for reset control (RST pin)