Skip to content

Commit

Permalink
Implemented(?) HypedADC
Browse files Browse the repository at this point in the history
  • Loading branch information
H00pyFr00d committed Oct 14, 2024
1 parent d6e19e5 commit 47aee15
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/io/src/adc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use embassy_stm32::{adc::AnyAdcChannel}

// ADC trait used to abstract the ADC peripheral
pub trait HypedADC {
// Read AIN value
// Return a voltage between 0 and 1.8V
fn readValue(&mut self) -> Option<f32>;
pub trait HypedAdc {
fn read_value(&mut self, channel: AnyAdcChannel<T>) -> Option<u16>;
}
21 changes: 21 additions & 0 deletions lib/io/stm32l476rg/src/adc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use embassy_stm32::{adc::Adc}
use hyped_io::Adc::HypedAdc;

pub struct Stm32l476rgAdc<'d, T> {
adc: Adc<'d, T>,
}

impl<'d> HypedAdc for Stm32l476rgAdc<'d> {
/// Reading from ADC requires a channel
fn read_value(&mut self, channel: AnyAdcChannel<T>) -> Option<f32> {
adc.blocking_read(&mut self, channel)
}
}

impl<'d> Stm32l476rgAdc<'d> {
/// Create a new instance of our ADC implementation for the STM32L476RG
pub fn new(adc: Adc<'d, T>) -> Self {
Self { adc }
}
}

0 comments on commit 47aee15

Please sign in to comment.