Skip to content

Commit

Permalink
Merge branch 'main' into kacper/hype-92-implement-current-sensor-for-…
Browse files Browse the repository at this point in the history
…levitation
  • Loading branch information
Aux1r committed Feb 13, 2025
2 parents bdfced2 + 775f8f2 commit 62b542c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/io/hyped_adc/hyped_adc_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ fn impl_hyped_adc(ast: &syn::DeriveInput) -> TokenStream {
let (impl_generics, ty_generics, _) = generics.split_for_impl();
let gen = quote! {
impl #impl_generics HypedAdc for #name #ty_generics {
/// Read a value from the ADC channel
fn read_value(&mut self) -> u16 {
self.adc.blocking_read(&mut self.channel)
}

fn get_resolution(&self) -> u16 {
/// STM32 boards have a resolution of 12 bits
4096
}
}

impl #impl_generics #name #ty_generics {
Expand Down
8 changes: 7 additions & 1 deletion lib/io/hyped_adc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

/// ADC trait used to abstract the ADC peripheral
pub trait HypedAdc {
/// Read value from the ADC channel
fn read_value(&mut self) -> u16;
/// Get resolution of ADC
fn get_resolution(&self) -> u16;
}

pub mod mock_adc {
Expand All @@ -16,12 +19,15 @@ pub mod mock_adc {
}

impl crate::HypedAdc for MockAdc {
/// Reads a value from the ADC
fn read_value(&mut self) -> u16 {
let next_value: u16 = self.next_values.pop().unwrap_or(self.current_value);
self.current_value = next_value;
self.current_value
}

fn get_resolution(&self) -> u16 {
4096
}
}

impl MockAdc {
Expand Down

0 comments on commit 62b542c

Please sign in to comment.