diff options
| author | Mathis Deroo <[email protected]> | 2025-12-08 11:12:33 -0800 |
|---|---|---|
| committer | Mathis Deroo <[email protected]> | 2025-12-09 10:52:10 -0800 |
| commit | b9bb7c0ebdbe19832ed9e9d75b12df86523c5fd2 (patch) | |
| tree | 440507d4ce5fd24de91d1f0bf10019e7cf4ad811 /embassy-mcxa | |
| parent | f20e4225ddd03f89dc48835355eeff5c2143038a (diff) | |
Modify set_conv_command_config to support command index from 1 to 7
Signed-off-by: Mathis Deroo <[email protected]>
Diffstat (limited to 'embassy-mcxa')
| -rw-r--r-- | embassy-mcxa/src/adc.rs | 94 |
1 files changed, 51 insertions, 43 deletions
diff --git a/embassy-mcxa/src/adc.rs b/embassy-mcxa/src/adc.rs index 1e3a6952a..c2ea06e89 100644 --- a/embassy-mcxa/src/adc.rs +++ b/embassy-mcxa/src/adc.rs | |||
| @@ -101,17 +101,17 @@ impl Default for LpadcConfig { | |||
| 101 | /// Defines the parameters for a single ADC conversion operation. | 101 | /// Defines the parameters for a single ADC conversion operation. |
| 102 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 102 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 103 | pub struct ConvCommandConfig { | 103 | pub struct ConvCommandConfig { |
| 104 | pub sample_channel_mode: Ctype, | 104 | pub sample_channel_mode: u8, |
| 105 | pub channel_number: Adch, | 105 | pub channel_number: u8, |
| 106 | pub chained_next_command_number: Next, | 106 | pub chained_next_command_number: u8, |
| 107 | pub enable_auto_channel_increment: bool, | 107 | pub enable_auto_channel_increment: bool, |
| 108 | pub loop_count: u8, | 108 | pub loop_count: u8, |
| 109 | pub hardware_average_mode: Avgs, | 109 | pub hardware_average_mode: u8, |
| 110 | pub sample_time_mode: Sts, | 110 | pub sample_time_mode: u8, |
| 111 | pub hardware_compare_mode: Cmpen, | 111 | pub hardware_compare_mode: u8, |
| 112 | pub hardware_compare_value_high: u32, | 112 | pub hardware_compare_value_high: u32, |
| 113 | pub hardware_compare_value_low: u32, | 113 | pub hardware_compare_value_low: u32, |
| 114 | pub conversion_resolution_mode: Mode, | 114 | pub conversion_resolution_mode: u8, |
| 115 | pub enable_wait_trigger: bool, | 115 | pub enable_wait_trigger: bool, |
| 116 | } | 116 | } |
| 117 | 117 | ||
| @@ -361,17 +361,17 @@ impl<'a, I: Instance> Adc<'a, I> { | |||
| 361 | /// Default conversion command configuration | 361 | /// Default conversion command configuration |
| 362 | pub fn get_default_conv_command_config(&self) -> ConvCommandConfig { | 362 | pub fn get_default_conv_command_config(&self) -> ConvCommandConfig { |
| 363 | ConvCommandConfig { | 363 | ConvCommandConfig { |
| 364 | sample_channel_mode: Ctype::SingleEndedASideChannel, | 364 | sample_channel_mode: Ctype::SingleEndedASideChannel as u8, |
| 365 | channel_number: Adch::SelectCh0, | 365 | channel_number: Adch::SelectCh0 as u8, |
| 366 | chained_next_command_number: Next::NoNextCmdTerminateOnFinish, | 366 | chained_next_command_number: Next::NoNextCmdTerminateOnFinish as u8, |
| 367 | enable_auto_channel_increment: false, | 367 | enable_auto_channel_increment: false, |
| 368 | loop_count: 0, | 368 | loop_count: 0, |
| 369 | hardware_average_mode: Avgs::NoAverage, | 369 | hardware_average_mode: Avgs::NoAverage as u8, |
| 370 | sample_time_mode: Sts::Sample3p5, | 370 | sample_time_mode: Sts::Sample3p5 as u8, |
| 371 | hardware_compare_mode: Cmpen::DisabledAlwaysStoreResult, | 371 | hardware_compare_mode: Cmpen::DisabledAlwaysStoreResult as u8, |
| 372 | hardware_compare_value_high: 0, | 372 | hardware_compare_value_high: 0, |
| 373 | hardware_compare_value_low: 0, | 373 | hardware_compare_value_low: 0, |
| 374 | conversion_resolution_mode: Mode::Data12Bits, | 374 | conversion_resolution_mode: Mode::Data12Bits as u8, |
| 375 | enable_wait_trigger: false, | 375 | enable_wait_trigger: false, |
| 376 | } | 376 | } |
| 377 | } | 377 | } |
| @@ -382,40 +382,48 @@ impl<'a, I: Instance> Adc<'a, I> { | |||
| 382 | /// Commands define how conversions are performed (channel, resolution, etc.). | 382 | /// Commands define how conversions are performed (channel, resolution, etc.). |
| 383 | /// | 383 | /// |
| 384 | /// # Arguments | 384 | /// # Arguments |
| 385 | /// * `index` - Command index (currently only 1 is supported) | 385 | /// * `index` - Command index |
| 386 | /// * `config` - Command configuration | 386 | /// * `config` - Command configuration |
| 387 | ///TBD Need to add cmdlx and cmdhx with x {2..7} | ||
| 388 | pub fn set_conv_command_config(&self, index: u32, config: &ConvCommandConfig) { | 387 | pub fn set_conv_command_config(&self, index: u32, config: &ConvCommandConfig) { |
| 389 | let adc = &*I::ptr(); | 388 | let adc = &*I::ptr(); |
| 390 | 389 | ||
| 390 | macro_rules! write_cmd { | ||
| 391 | ($idx:expr) => {{ | ||
| 392 | paste! { | ||
| 393 | adc.[<cmdl $idx>]().write(|w| unsafe { | ||
| 394 | w.adch() | ||
| 395 | .bits(config.channel_number) | ||
| 396 | .mode() | ||
| 397 | .bit(config.conversion_resolution_mode != 0) | ||
| 398 | }); | ||
| 399 | adc.[<cmdh $idx>]().write(|w| unsafe { | ||
| 400 | w.next() | ||
| 401 | .bits(config.chained_next_command_number) | ||
| 402 | .loop_() | ||
| 403 | .bits(config.loop_count) | ||
| 404 | .avgs() | ||
| 405 | .bits(config.hardware_average_mode) | ||
| 406 | .sts() | ||
| 407 | .bits(config.sample_time_mode) | ||
| 408 | .cmpen() | ||
| 409 | .bits(config.hardware_compare_mode) | ||
| 410 | .wait_trig() | ||
| 411 | .bit(config.enable_wait_trigger) | ||
| 412 | .lwi() | ||
| 413 | .bit(config.enable_auto_channel_increment) | ||
| 414 | }); | ||
| 415 | } | ||
| 416 | }}; | ||
| 417 | } | ||
| 418 | |||
| 391 | match index { | 419 | match index { |
| 392 | 1 => { | 420 | 1 => write_cmd!(1), |
| 393 | adc.cmdl1().write(|w| { | 421 | 2 => write_cmd!(2), |
| 394 | w.adch() | 422 | 3 => write_cmd!(3), |
| 395 | .variant(config.channel_number) | 423 | 4 => write_cmd!(4), |
| 396 | .mode() | 424 | 5 => write_cmd!(5), |
| 397 | .variant(config.conversion_resolution_mode) | 425 | 6 => write_cmd!(6), |
| 398 | }); | 426 | 7 => write_cmd!(7), |
| 399 | adc.cmdh1().write(|w| unsafe { | ||
| 400 | w.next() | ||
| 401 | .variant(config.chained_next_command_number) | ||
| 402 | .loop_() | ||
| 403 | .bits(config.loop_count) | ||
| 404 | .avgs() | ||
| 405 | .variant(config.hardware_average_mode) | ||
| 406 | .sts() | ||
| 407 | .variant(config.sample_time_mode) | ||
| 408 | .cmpen() | ||
| 409 | .variant(config.hardware_compare_mode); | ||
| 410 | if config.enable_wait_trigger { | ||
| 411 | w.wait_trig().enabled(); | ||
| 412 | } | ||
| 413 | if config.enable_auto_channel_increment { | ||
| 414 | w.lwi().enabled(); | ||
| 415 | } | ||
| 416 | w | ||
| 417 | }); | ||
| 418 | } | ||
| 419 | _ => panic!("Invalid command index: must be between 1 and 7"), | 427 | _ => panic!("Invalid command index: must be between 1 and 7"), |
| 420 | } | 428 | } |
| 421 | } | 429 | } |
