diff options
| author | Mathis Deroo <[email protected]> | 2025-12-08 15:24:12 -0800 |
|---|---|---|
| committer | Mathis Deroo <[email protected]> | 2025-12-09 10:52:11 -0800 |
| commit | f81eeee3c1bfa1cab534181ff6349a0998fc26ea (patch) | |
| tree | 32e9fb50b30d3f7161cc656e1534f06aeb393dee /embassy-mcxa/src | |
| parent | 20ed25fbad4e7651316b4841aefdf62ee197ea31 (diff) | |
Use field accessors for FIFO results instead of hardcoded ones
Signed-off-by: Mathis Deroo <[email protected]>
Diffstat (limited to 'embassy-mcxa/src')
| -rw-r--r-- | embassy-mcxa/src/adc.rs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/embassy-mcxa/src/adc.rs b/embassy-mcxa/src/adc.rs index af7191573..900a3a40a 100644 --- a/embassy-mcxa/src/adc.rs +++ b/embassy-mcxa/src/adc.rs | |||
| @@ -143,9 +143,9 @@ pub enum Error { | |||
| 143 | /// Contains the conversion value and metadata about the conversion. | 143 | /// Contains the conversion value and metadata about the conversion. |
| 144 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 144 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 145 | pub struct ConvResult { | 145 | pub struct ConvResult { |
| 146 | pub command_id_source: u32, | 146 | pub command_id_source: u8, |
| 147 | pub loop_count_index: u32, | 147 | pub loop_count_index: u8, |
| 148 | pub trigger_id_source: u32, | 148 | pub trigger_id_source: u8, |
| 149 | pub conv_value: u16, | 149 | pub conv_value: u16, |
| 150 | } | 150 | } |
| 151 | 151 | ||
| @@ -566,17 +566,16 @@ impl<'a, I: Instance, M: ModeAdc> Adc<'a, I, M> { | |||
| 566 | /// - `Err(Error::FifoEmpty)` if the FIFO is empty | 566 | /// - `Err(Error::FifoEmpty)` if the FIFO is empty |
| 567 | pub fn get_conv_result(&self) -> Result<ConvResult> { | 567 | pub fn get_conv_result(&self) -> Result<ConvResult> { |
| 568 | let adc = I::ptr(); | 568 | let adc = I::ptr(); |
| 569 | let fifo = adc.resfifo0().read().bits(); | 569 | let fifo = adc.resfifo0().read(); |
| 570 | const VALID_MASK: u32 = 1 << 31; | 570 | if !fifo.valid().is_valid() { |
| 571 | if fifo & VALID_MASK == 0 { | ||
| 572 | return Err(Error::FifoEmpty); | 571 | return Err(Error::FifoEmpty); |
| 573 | } | 572 | } |
| 574 | 573 | ||
| 575 | Ok(ConvResult { | 574 | Ok(ConvResult { |
| 576 | command_id_source: (fifo >> 24) & 0x0F, | 575 | command_id_source: fifo.cmdsrc().bits(), |
| 577 | loop_count_index: (fifo >> 20) & 0x0F, | 576 | loop_count_index: fifo.loopcnt().bits(), |
| 578 | trigger_id_source: (fifo >> 16) & 0x0F, | 577 | trigger_id_source: fifo.tsrc().bits(), |
| 579 | conv_value: (fifo & 0xFFFF) as u16, | 578 | conv_value: fifo.d().bits(), |
| 580 | }) | 579 | }) |
| 581 | } | 580 | } |
| 582 | } | 581 | } |
