Skip to content

Commit 0c2f39f

Browse files
committed
adc: move channel description into separate module
Signed-off-by: Leonard Göhrs <[email protected]>
1 parent 4ef6ee7 commit 0c2f39f

File tree

6 files changed

+153
-118
lines changed

6 files changed

+153
-118
lines changed

src/adc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl Adc {
8585
hardware_generation: HardwareGeneration,
8686
) -> Result<Self> {
8787
let stm32_thread = IioThread::new_stm32(wtb, hardware_generation).await?;
88-
let powerboard_thread = IioThread::new_powerboard(wtb).await?;
88+
let powerboard_thread = IioThread::new_powerboard(wtb, hardware_generation).await?;
8989

9090
let adc = Self {
9191
usb_host_curr: AdcChannel {

src/adc/iio/demo_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl IioThread {
195195
Ok(this)
196196
}
197197

198-
pub async fn new_powerboard<W>(_wtb: &W) -> Result<Arc<Self>> {
198+
pub async fn new_powerboard<W, G>(_wtb: &W, _hardware_generation: G) -> Result<Arc<Self>> {
199199
let mut demo_magic = block_on(DEMO_MAGIC_POWERBOARD.lock());
200200

201201
// Only ever set up a single demo_mode "IioThread" per ADC

src/adc/iio/hardware.rs

Lines changed: 10 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -35,115 +35,9 @@ use crate::measurement::{Measurement, Timestamp};
3535
use crate::system::HardwareGeneration;
3636
use crate::watched_tasks::WatchedTasksBuilder;
3737

38-
struct ChannelDesc {
39-
kernel_name: &'static str,
40-
calibration_path: &'static str,
41-
name: &'static str,
42-
}
38+
mod channels;
4339

44-
// Hard coded list of channels using the internal STM32MP1 ADC.
45-
// Consists of the IIO channel name, the location of the calibration data
46-
// in the device tree and an internal name for the channel.
47-
const CHANNELS_STM32_GEN1_GEN2: &[ChannelDesc] = &[
48-
ChannelDesc {
49-
kernel_name: "voltage13",
50-
calibration_path: "baseboard-factory-data/usb-host-curr",
51-
name: "usb-host-curr",
52-
},
53-
ChannelDesc {
54-
kernel_name: "voltage15",
55-
calibration_path: "baseboard-factory-data/usb-host1-curr",
56-
name: "usb-host1-curr",
57-
},
58-
ChannelDesc {
59-
kernel_name: "voltage0",
60-
calibration_path: "baseboard-factory-data/usb-host2-curr",
61-
name: "usb-host2-curr",
62-
},
63-
ChannelDesc {
64-
kernel_name: "voltage1",
65-
calibration_path: "baseboard-factory-data/usb-host3-curr",
66-
name: "usb-host3-curr",
67-
},
68-
ChannelDesc {
69-
kernel_name: "voltage2",
70-
calibration_path: "baseboard-factory-data/out0-volt",
71-
name: "out0-volt",
72-
},
73-
ChannelDesc {
74-
kernel_name: "voltage10",
75-
calibration_path: "baseboard-factory-data/out1-volt",
76-
name: "out1-volt",
77-
},
78-
ChannelDesc {
79-
kernel_name: "voltage5",
80-
calibration_path: "baseboard-factory-data/iobus-curr",
81-
name: "iobus-curr",
82-
},
83-
ChannelDesc {
84-
kernel_name: "voltage9",
85-
calibration_path: "baseboard-factory-data/iobus-volt",
86-
name: "iobus-volt",
87-
},
88-
];
89-
90-
const CHANNELS_STM32_GEN3: &[ChannelDesc] = &[
91-
ChannelDesc {
92-
kernel_name: "voltage13",
93-
calibration_path: "baseboard-factory-data/usb-host-curr",
94-
name: "usb-host-curr",
95-
},
96-
ChannelDesc {
97-
kernel_name: "voltage15",
98-
calibration_path: "baseboard-factory-data/usb-host1-curr",
99-
name: "usb-host1-curr",
100-
},
101-
ChannelDesc {
102-
kernel_name: "voltage18",
103-
calibration_path: "baseboard-factory-data/usb-host2-curr",
104-
name: "usb-host2-curr",
105-
},
106-
ChannelDesc {
107-
kernel_name: "voltage14",
108-
calibration_path: "baseboard-factory-data/usb-host3-curr",
109-
name: "usb-host3-curr",
110-
},
111-
ChannelDesc {
112-
kernel_name: "voltage2",
113-
calibration_path: "baseboard-factory-data/out0-volt",
114-
name: "out0-volt",
115-
},
116-
ChannelDesc {
117-
kernel_name: "voltage10",
118-
calibration_path: "baseboard-factory-data/out1-volt",
119-
name: "out1-volt",
120-
},
121-
ChannelDesc {
122-
kernel_name: "voltage5",
123-
calibration_path: "baseboard-factory-data/iobus-curr",
124-
name: "iobus-curr",
125-
},
126-
ChannelDesc {
127-
kernel_name: "voltage9",
128-
calibration_path: "baseboard-factory-data/iobus-volt",
129-
name: "iobus-volt",
130-
},
131-
];
132-
133-
// The same as for the STM32MP1 channels but for the discrete ADC on the power
134-
// board.
135-
const CHANNELS_PWR: &[ChannelDesc] = &[
136-
ChannelDesc {
137-
kernel_name: "voltage",
138-
calibration_path: "powerboard-factory-data/pwr-volt",
139-
name: "pwr-volt",
140-
},
141-
ChannelDesc {
142-
kernel_name: "current",
143-
calibration_path: "powerboard-factory-data/pwr-curr",
144-
name: "pwr-curr",
145-
},
146-
];
40+
use channels::{ChannelDesc, Channels};
14741

14842
const TRIGGER_HR_PWR_DIR: &str = "/sys/kernel/config/iio/triggers/hrtimer/tacd-pwr";
14943

@@ -479,10 +373,7 @@ impl IioThread {
479373
wtb: &mut WatchedTasksBuilder,
480374
hardware_generation: HardwareGeneration,
481375
) -> Result<Arc<Self>> {
482-
let channels = match hardware_generation {
483-
HardwareGeneration::Gen1 | HardwareGeneration::Gen2 => CHANNELS_STM32_GEN1_GEN2,
484-
HardwareGeneration::Gen3 => CHANNELS_STM32_GEN3,
485-
};
376+
let channels = hardware_generation.channels_stm32();
486377

487378
Self::new(
488379
wtb,
@@ -496,20 +387,25 @@ impl IioThread {
496387
.await
497388
}
498389

499-
pub async fn new_powerboard(wtb: &mut WatchedTasksBuilder) -> Result<Arc<Self>> {
390+
pub async fn new_powerboard(
391+
wtb: &mut WatchedTasksBuilder,
392+
hardware_generation: HardwareGeneration,
393+
) -> Result<Arc<Self>> {
500394
let hr_trigger_path = Path::new(TRIGGER_HR_PWR_DIR);
501395

502396
if !hr_trigger_path.is_dir() {
503397
create_dir(hr_trigger_path)?;
504398
}
505399

400+
let channels = hardware_generation.channels_pwr();
401+
506402
Self::new(
507403
wtb,
508404
"adc-powerboard",
509405
"lmp92064",
510406
"tacd-pwr",
511407
20,
512-
CHANNELS_PWR,
408+
channels,
513409
1,
514410
)
515411
.await

src/adc/iio/hardware/channels.rs

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
use crate::system::HardwareGeneration;
2+
3+
pub(super) struct ChannelDesc {
4+
pub kernel_name: &'static str,
5+
pub calibration_path: &'static str,
6+
pub name: &'static str,
7+
}
8+
9+
// Hard coded list of channels using the internal STM32MP1 ADC.
10+
// Consists of the IIO channel name, the location of the calibration data
11+
// in the device tree and an internal name for the channel.
12+
const CHANNELS_STM32_GEN1_GEN2: &[ChannelDesc] = &[
13+
ChannelDesc {
14+
kernel_name: "voltage13",
15+
calibration_path: "baseboard-factory-data/usb-host-curr",
16+
name: "usb-host-curr",
17+
},
18+
ChannelDesc {
19+
kernel_name: "voltage15",
20+
calibration_path: "baseboard-factory-data/usb-host1-curr",
21+
name: "usb-host1-curr",
22+
},
23+
ChannelDesc {
24+
kernel_name: "voltage0",
25+
calibration_path: "baseboard-factory-data/usb-host2-curr",
26+
name: "usb-host2-curr",
27+
},
28+
ChannelDesc {
29+
kernel_name: "voltage1",
30+
calibration_path: "baseboard-factory-data/usb-host3-curr",
31+
name: "usb-host3-curr",
32+
},
33+
ChannelDesc {
34+
kernel_name: "voltage2",
35+
calibration_path: "baseboard-factory-data/out0-volt",
36+
name: "out0-volt",
37+
},
38+
ChannelDesc {
39+
kernel_name: "voltage10",
40+
calibration_path: "baseboard-factory-data/out1-volt",
41+
name: "out1-volt",
42+
},
43+
ChannelDesc {
44+
kernel_name: "voltage5",
45+
calibration_path: "baseboard-factory-data/iobus-curr",
46+
name: "iobus-curr",
47+
},
48+
ChannelDesc {
49+
kernel_name: "voltage9",
50+
calibration_path: "baseboard-factory-data/iobus-volt",
51+
name: "iobus-volt",
52+
},
53+
];
54+
55+
const CHANNELS_STM32_GEN3: &[ChannelDesc] = &[
56+
ChannelDesc {
57+
kernel_name: "voltage13",
58+
calibration_path: "baseboard-factory-data/usb-host-curr",
59+
name: "usb-host-curr",
60+
},
61+
ChannelDesc {
62+
kernel_name: "voltage15",
63+
calibration_path: "baseboard-factory-data/usb-host1-curr",
64+
name: "usb-host1-curr",
65+
},
66+
ChannelDesc {
67+
kernel_name: "voltage18",
68+
calibration_path: "baseboard-factory-data/usb-host2-curr",
69+
name: "usb-host2-curr",
70+
},
71+
ChannelDesc {
72+
kernel_name: "voltage14",
73+
calibration_path: "baseboard-factory-data/usb-host3-curr",
74+
name: "usb-host3-curr",
75+
},
76+
ChannelDesc {
77+
kernel_name: "voltage2",
78+
calibration_path: "baseboard-factory-data/out0-volt",
79+
name: "out0-volt",
80+
},
81+
ChannelDesc {
82+
kernel_name: "voltage10",
83+
calibration_path: "baseboard-factory-data/out1-volt",
84+
name: "out1-volt",
85+
},
86+
ChannelDesc {
87+
kernel_name: "voltage5",
88+
calibration_path: "baseboard-factory-data/iobus-curr",
89+
name: "iobus-curr",
90+
},
91+
ChannelDesc {
92+
kernel_name: "voltage9",
93+
calibration_path: "baseboard-factory-data/iobus-volt",
94+
name: "iobus-volt",
95+
},
96+
];
97+
98+
// The same as for the STM32MP1 channels but for the discrete ADC on the power
99+
// board.
100+
const CHANNELS_PWR: &[ChannelDesc] = &[
101+
ChannelDesc {
102+
kernel_name: "voltage",
103+
calibration_path: "powerboard-factory-data/pwr-volt",
104+
name: "pwr-volt",
105+
},
106+
ChannelDesc {
107+
kernel_name: "current",
108+
calibration_path: "powerboard-factory-data/pwr-curr",
109+
name: "pwr-curr",
110+
},
111+
];
112+
113+
pub(super) trait Channels {
114+
fn channels_stm32(&self) -> &'static [ChannelDesc];
115+
fn channels_pwr(&self) -> &'static [ChannelDesc];
116+
}
117+
118+
impl Channels for HardwareGeneration {
119+
fn channels_stm32(&self) -> &'static [ChannelDesc] {
120+
// LXA TAC hardware generation 3 has move some of the ADC channels around
121+
// so that channel 0 and 1 are no longer used.
122+
// Channel 0 and 1 are special in that they do not use the pinmuxing support
123+
// of the STM32MP1 SoC.
124+
// Instead they are always connected to the ADC.
125+
// This causes issues when the ADC peripheral is put into stanby,
126+
// because current will leak into these pins in that case.
127+
128+
match self {
129+
HardwareGeneration::Gen1 | HardwareGeneration::Gen2 => CHANNELS_STM32_GEN1_GEN2,
130+
HardwareGeneration::Gen3 => CHANNELS_STM32_GEN3,
131+
}
132+
}
133+
134+
fn channels_pwr(&self) -> &'static [ChannelDesc] {
135+
// The pin assignment of the power board is currently independent from the
136+
// hardware generation.
137+
CHANNELS_PWR
138+
}
139+
}

src/adc/iio/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl IioThread {
117117
Ok(Arc::new(Self { channels }))
118118
}
119119

120-
pub async fn new_powerboard<W>(_wtb: &W) -> Result<Arc<Self>> {
120+
pub async fn new_powerboard<W, G>(_wtb: &W, _hardware_generation: G) -> Result<Arc<Self>> {
121121
let mut channels = Vec::new();
122122

123123
for name in CHANNELS_PWR {

src/digital_io/gpio/demo_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl LineHandle {
3333
// communicate with this function so that toggling an output
3434
// has an effect on the measured values.
3535
let iio_thread_stm32 = block_on(IioThread::new_stm32(&(), ())).unwrap();
36-
let iio_thread_pwr = block_on(IioThread::new_powerboard(&())).unwrap();
36+
let iio_thread_pwr = block_on(IioThread::new_powerboard(&(), ())).unwrap();
3737

3838
match self.name.as_str() {
3939
"OUT_0" => iio_thread_stm32

0 commit comments

Comments
 (0)