@@ -35,49 +35,71 @@ use thread_priority::*;
35
35
36
36
use crate :: measurement:: { Measurement , Timestamp } ;
37
37
38
+ struct ChannelDesc {
39
+ kernel_name : & ' static str ,
40
+ calibration_path : & ' static str ,
41
+ name : & ' static str ,
42
+ }
43
+
38
44
// Hard coded list of channels using the internal STM32MP1 ADC.
39
45
// Consists of the IIO channel name, the location of the calibration data
40
46
// in the device tree and an internal name for the channel.
41
- const CHANNELS_STM32 : & [ ( & str , & str , & str ) ] = & [
42
- (
43
- "voltage13" ,
44
- "baseboard-factory-data/usb-host-curr" ,
45
- "usb-host-curr" ,
46
- ) ,
47
- (
48
- "voltage15" ,
49
- "baseboard-factory-data/usb-host1-curr" ,
50
- "usb-host1-curr" ,
51
- ) ,
52
- (
53
- "voltage0" ,
54
- "baseboard-factory-data/usb-host2-curr" ,
55
- "usb-host2-curr" ,
56
- ) ,
57
- (
58
- "voltage1" ,
59
- "baseboard-factory-data/usb-host3-curr" ,
60
- "usb-host3-curr" ,
61
- ) ,
62
- ( "voltage2" , "baseboard-factory-data/out0-volt" , "out0-volt" ) ,
63
- ( "voltage10" , "baseboard-factory-data/out1-volt" , "out1-volt" ) ,
64
- (
65
- "voltage5" ,
66
- "baseboard-factory-data/iobus-curr" ,
67
- "iobus-curr" ,
68
- ) ,
69
- (
70
- "voltage9" ,
71
- "baseboard-factory-data/iobus-volt" ,
72
- "iobus-volt" ,
73
- ) ,
47
+ const CHANNELS_STM32 : & [ 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
+ } ,
74
88
] ;
75
89
76
90
// The same as for the STM32MP1 channels but for the discrete ADC on the power
77
91
// board.
78
- const CHANNELS_PWR : & [ ( & str , & str , & str ) ] = & [
79
- ( "voltage" , "powerboard-factory-data/pwr-volt" , "pwr-volt" ) ,
80
- ( "current" , "powerboard-factory-data/pwr-curr" , "pwr-curr" ) ,
92
+ const CHANNELS_PWR : & [ ChannelDesc ] = & [
93
+ ChannelDesc {
94
+ kernel_name : "voltage" ,
95
+ calibration_path : "powerboard-factory-data/pwr-volt" ,
96
+ name : "pwr-volt" ,
97
+ } ,
98
+ ChannelDesc {
99
+ kernel_name : "current" ,
100
+ calibration_path : "powerboard-factory-data/pwr-curr" ,
101
+ name : "pwr-curr" ,
102
+ } ,
81
103
] ;
82
104
83
105
#[ derive( Clone , Copy ) ]
@@ -235,10 +257,10 @@ impl IioThread {
235
257
236
258
let stm32_channels: Vec < Channel > = CHANNELS_STM32
237
259
. iter ( )
238
- . map ( |( iio_name , _ , _ ) | {
260
+ . map ( |ChannelDesc { kernel_name , .. } | {
239
261
let ch = stm32_adc
240
- . find_channel ( iio_name , false )
241
- . unwrap_or_else ( || panic ! ( "Failed to open iio channel {}" , iio_name ) ) ;
262
+ . find_channel ( kernel_name , false )
263
+ . unwrap_or_else ( || panic ! ( "Failed to open iio channel {}" , kernel_name ) ) ;
242
264
243
265
ch. enable ( ) ;
244
266
ch
@@ -247,10 +269,10 @@ impl IioThread {
247
269
248
270
let pwr_channels: Vec < Channel > = CHANNELS_PWR
249
271
. iter ( )
250
- . map ( |( iio_name , _ , _ ) | {
272
+ . map ( |ChannelDesc { kernel_name , .. } | {
251
273
pwr_adc
252
- . find_channel ( iio_name , false )
253
- . unwrap_or_else ( || panic ! ( "Failed to open iio channel {}" , iio_name ) )
274
+ . find_channel ( kernel_name , false )
275
+ . unwrap_or_else ( || panic ! ( "Failed to open iio channel {}" , kernel_name ) )
254
276
} )
255
277
. collect ( ) ;
256
278
@@ -371,10 +393,17 @@ impl IioThread {
371
393
. iter ( )
372
394
. chain ( CHANNELS_PWR )
373
395
. enumerate ( )
374
- . find ( |( _, ( _ , _ , name) ) | name == & ch_name)
396
+ . find ( |( _, ChannelDesc { name, .. } ) | name == & ch_name)
375
397
. ok_or ( anyhow ! ( "Could not get adc channel {}" , ch_name) )
376
- . and_then ( |( idx, ( _, calib_name, _) ) | {
377
- CalibratedChannel :: from_name ( self . clone ( ) , idx, calib_name)
378
- } )
398
+ . and_then (
399
+ |(
400
+ idx,
401
+ ChannelDesc {
402
+ calibration_path, ..
403
+ } ,
404
+ ) | {
405
+ CalibratedChannel :: from_name ( self . clone ( ) , idx, calibration_path)
406
+ } ,
407
+ )
379
408
}
380
409
}
0 commit comments