From 20ed25fbad4e7651316b4841aefdf62ee197ea31 Mon Sep 17 00:00:00 2001 From: Mathis Deroo Date: Mon, 8 Dec 2025 15:17:54 -0800 Subject: set_conv_command_config returns Result instead of panic if index > 7 Signed-off-by: Mathis Deroo --- embassy-mcxa/src/adc.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'embassy-mcxa') 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> { /// # Arguments /// * `index` - Command index /// * `config` - Command configuration - pub fn set_conv_command_config(&self, index: u32, config: &ConvCommandConfig) { + /// + /// # Returns + /// * `Ok(())` if the command was configured successfully + /// * `Err(Error::InvalidConfig)` if the index is out of range + pub fn set_conv_command_config(&self, index: u32, config: &ConvCommandConfig) -> Result<()> { let adc = I::ptr(); + if index < 1 || index > 7 { + return Err(Error::InvalidConfig); + } + macro_rules! write_cmd { ($idx:expr) => {{ paste! { @@ -475,8 +483,10 @@ impl<'a, I: Instance, M: ModeAdc> Adc<'a, I, M> { 5 => write_cmd!(5), 6 => write_cmd!(6), 7 => write_cmd!(7), - _ => panic!("Invalid command index: must be between 1 and 7"), + _ => unreachable!(), } + + Ok(()) } /// Get default conversion trigger configuration. -- cgit