From 6e4199ed284eb37fc7a628ae733042bbbc6b3fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CMunteanu?= Date: Tue, 30 Jul 2024 16:19:34 +0300 Subject: [PATCH] updated code --- apis/peripherals/adc/src/lib.rs | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/apis/peripherals/adc/src/lib.rs b/apis/peripherals/adc/src/lib.rs index 0c015304..e1ec778d 100644 --- a/apis/peripherals/adc/src/lib.rs +++ b/apis/peripherals/adc/src/lib.rs @@ -28,8 +28,14 @@ impl Adc { } // Initiate a sample reading - pub fn read_single_sample(channel: size) -> Result<(), ErrorCode> { - S::command(DRIVER_NUM, SINGLE_SAMPLE, channel, 0).to_result() + pub fn read_single_sample(channel: usize) -> Result<(), ErrorCode> { + S::command( + DRIVER_NUM, + SINGLE_SAMPLE, + (channel as usize).try_into().unwrap(), + 0, + ) + .to_result() } // Register a listener to be called when the ADC conversion is finished @@ -47,7 +53,7 @@ impl Adc { /// Initiates a synchronous ADC conversion /// Returns the converted ADC value or an error - pub fn read_single_sample_sync(channel: u32) -> Result { + pub fn read_single_sample_sync(channel: usize) -> Result { let sample: Cell> = Cell::new(None); let listener = ADCListener(|adc_val| { sample.set(Some(adc_val)); @@ -67,13 +73,25 @@ impl Adc { } /// Returns the number of ADC resolution bits - pub fn get_resolution_bits(channel: size) -> Result { - S::command(DRIVER_NUM, GET_RES_BITS, channel, 0).to_result() + pub fn get_resolution_bits(channel: usize) -> Result { + S::command( + DRIVER_NUM, + GET_RES_BITS, + (channel as usize).try_into().unwrap(), + 0, + ) + .to_result() } /// Returns the reference voltage in millivolts (mV) - pub fn get_reference_voltage_mv(channel: u32) -> Result { - S::command(DRIVER_NUM, GET_VOLTAGE_REF, channel, 0).to_result() + pub fn get_reference_voltage_mv(channel: usize) -> Result { + S::command( + DRIVER_NUM, + GET_VOLTAGE_REF, + (channel as usize).try_into().unwrap(), + 0, + ) + .to_result() } }