diff options
| author | Mathis Deroo <[email protected]> | 2025-12-08 15:17:54 -0800 |
|---|---|---|
| committer | Mathis Deroo <[email protected]> | 2025-12-09 10:52:11 -0800 |
| commit | 20ed25fbad4e7651316b4841aefdf62ee197ea31 (patch) | |
| tree | 1607205c383d92aef73f395d073ee3e49585bc98 | |
| parent | 759ab109806f447a1193954a453828b860104c3a (diff) | |
set_conv_command_config returns Result instead of panic if index > 7
Signed-off-by: Mathis Deroo <[email protected]>
| -rw-r--r-- | embassy-mcxa/src/adc.rs | 14 | ||||
| -rw-r--r-- | examples/mcxa/src/bin/adc_interrupt.rs | 2 | ||||
| -rw-r--r-- | examples/mcxa/src/bin/adc_polling.rs | 2 |
3 files changed, 14 insertions, 4 deletions
diff --git a/embassy-mcxa/src/adc.rs b/embassy-mcxa/src/adc.rs index 16b40fa45..af7191573 100644 --- a/embassy-mcxa/src/adc.rs +++ b/embassy-mcxa/src/adc.rs | |||
| @@ -435,9 +435,17 @@ impl<'a, I: Instance, M: ModeAdc> Adc<'a, I, M> { | |||
| 435 | /// # Arguments | 435 | /// # Arguments |
| 436 | /// * `index` - Command index | 436 | /// * `index` - Command index |
| 437 | /// * `config` - Command configuration | 437 | /// * `config` - Command configuration |
| 438 | pub fn set_conv_command_config(&self, index: u32, config: &ConvCommandConfig) { | 438 | /// |
| 439 | /// # Returns | ||
| 440 | /// * `Ok(())` if the command was configured successfully | ||
| 441 | /// * `Err(Error::InvalidConfig)` if the index is out of range | ||
| 442 | pub fn set_conv_command_config(&self, index: u32, config: &ConvCommandConfig) -> Result<()> { | ||
| 439 | let adc = I::ptr(); | 443 | let adc = I::ptr(); |
| 440 | 444 | ||
| 445 | if index < 1 || index > 7 { | ||
| 446 | return Err(Error::InvalidConfig); | ||
| 447 | } | ||
| 448 | |||
| 441 | macro_rules! write_cmd { | 449 | macro_rules! write_cmd { |
| 442 | ($idx:expr) => {{ | 450 | ($idx:expr) => {{ |
| 443 | paste! { | 451 | paste! { |
| @@ -475,8 +483,10 @@ impl<'a, I: Instance, M: ModeAdc> Adc<'a, I, M> { | |||
| 475 | 5 => write_cmd!(5), | 483 | 5 => write_cmd!(5), |
| 476 | 6 => write_cmd!(6), | 484 | 6 => write_cmd!(6), |
| 477 | 7 => write_cmd!(7), | 485 | 7 => write_cmd!(7), |
| 478 | _ => panic!("Invalid command index: must be between 1 and 7"), | 486 | _ => unreachable!(), |
| 479 | } | 487 | } |
| 488 | |||
| 489 | Ok(()) | ||
| 480 | } | 490 | } |
| 481 | 491 | ||
| 482 | /// Get default conversion trigger configuration. | 492 | /// Get default conversion trigger configuration. |
diff --git a/examples/mcxa/src/bin/adc_interrupt.rs b/examples/mcxa/src/bin/adc_interrupt.rs index 67fcf6361..257e04491 100644 --- a/examples/mcxa/src/bin/adc_interrupt.rs +++ b/examples/mcxa/src/bin/adc_interrupt.rs | |||
| @@ -52,7 +52,7 @@ async fn main(_spawner: Spawner) { | |||
| 52 | let mut conv_command_config = adc.get_default_conv_command_config(); | 52 | let mut conv_command_config = adc.get_default_conv_command_config(); |
| 53 | conv_command_config.channel_number = Adch::SelectCorrespondingChannel8; | 53 | conv_command_config.channel_number = Adch::SelectCorrespondingChannel8; |
| 54 | conv_command_config.conversion_resolution_mode = Mode::Data16Bits; | 54 | conv_command_config.conversion_resolution_mode = Mode::Data16Bits; |
| 55 | adc.set_conv_command_config(1, &conv_command_config); | 55 | adc.set_conv_command_config(1, &conv_command_config).unwrap(); |
| 56 | 56 | ||
| 57 | let mut conv_trigger_config = adc.get_default_conv_trigger_config(); | 57 | let mut conv_trigger_config = adc.get_default_conv_trigger_config(); |
| 58 | conv_trigger_config.target_command_id = Tcmd::ExecuteCmd1; | 58 | conv_trigger_config.target_command_id = Tcmd::ExecuteCmd1; |
diff --git a/examples/mcxa/src/bin/adc_polling.rs b/examples/mcxa/src/bin/adc_polling.rs index 14d47329a..b11b8957f 100644 --- a/examples/mcxa/src/bin/adc_polling.rs +++ b/examples/mcxa/src/bin/adc_polling.rs | |||
| @@ -47,7 +47,7 @@ async fn main(_spawner: Spawner) { | |||
| 47 | let mut conv_command_config = adc.get_default_conv_command_config(); | 47 | let mut conv_command_config = adc.get_default_conv_command_config(); |
| 48 | conv_command_config.channel_number = Adch::SelectCorrespondingChannel8; | 48 | conv_command_config.channel_number = Adch::SelectCorrespondingChannel8; |
| 49 | conv_command_config.conversion_resolution_mode = Mode::Data16Bits; | 49 | conv_command_config.conversion_resolution_mode = Mode::Data16Bits; |
| 50 | adc.set_conv_command_config(1, &conv_command_config); | 50 | adc.set_conv_command_config(1, &conv_command_config).unwrap(); |
| 51 | 51 | ||
| 52 | let mut conv_trigger_config = adc.get_default_conv_trigger_config(); | 52 | let mut conv_trigger_config = adc.get_default_conv_trigger_config(); |
| 53 | conv_trigger_config.target_command_id = Tcmd::ExecuteCmd1; | 53 | conv_trigger_config.target_command_id = Tcmd::ExecuteCmd1; |
