Skip to content

Commit

Permalink
Use proto-hal for 'entitlement' instead of 'observation'
Browse files Browse the repository at this point in the history
  • Loading branch information
usbalbin committed Dec 28, 2024
1 parent 8fa58c9 commit 62e65e1
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 215 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ version = "0.0.2"
nb = "0.1.1"
#stm32g4 = { git = "https://github.com/stm32-rs/stm32-rs-nightlies" } #"0.15.1"
stm32g4 = { version = "0.19.0", package = "stm32g4-staging" }
proto-hal = { git = "https://github.com/AdinAck/proto-hal", rev = "9030895" }
paste = "1.0"
bitflags = "1.2"
vcell = "0.1"
Expand Down
6 changes: 3 additions & 3 deletions examples/observe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ use hal::{
comparator::{ComparatorExt, ComparatorSplit, Config},
delay::SYSTDelayExt as _,
gpio::GpioExt,
observable::Observable as _,
rcc::RccExt,
stm32,
};
use proto_hal::stasis::Freeze;
use rt::entry;
use stm32g4xx_hal::{self as hal, adc::config::SampleTime, delay::DelayExt as _};

Expand All @@ -38,7 +38,7 @@ fn main() -> ! {
let (pa1, [pa1_token]) = gpioa // <- The pin to keep track of
.pa1
.into_analog()
.observe();
.freeze();
let pa0 = gpioa.pa0.into_analog(); // <- Reference voltage

// Only pa1_token and pa0 consumed here
Expand All @@ -57,7 +57,7 @@ fn main() -> ! {
// Can not reconfigure pa1 here
loop {
// Can still use pa1 here
let sample = adc.convert(pa1.as_ref(), SampleTime::Cycles_640_5);
let sample = adc.convert(&pa1, SampleTime::Cycles_640_5);
info!("Reading: {}", sample);
delay.delay(1000.millis());
}
Expand Down
21 changes: 16 additions & 5 deletions src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use embedded_hal::{
adc::{Channel, OneShot},
blocking::delay::DelayUs,
};
use proto_hal::stasis;

use self::config::ExternalTrigger12;

Expand Down Expand Up @@ -136,7 +137,9 @@ impl Temperature {
macro_rules! adc_pins {
($($pin:ty => ($adc:ident, $chan:expr)),+ $(,)*) => {
$(
impl Channel<stm32::$adc> for $pin {
impl<P> Channel<stm32::$adc> for P
where P: stasis::EntitlementLock<Resource = $pin>
{
type ID = u8;
fn channel() -> u8 { $chan }
}
Expand All @@ -147,22 +150,30 @@ macro_rules! adc_pins {
macro_rules! adc_opamp {
($($opamp:ty => ($adc:ident, $chan:expr)),+ $(,)*) => {
$(
impl<A> Channel<stm32::$adc> for opamp::Follower<$opamp, A, InternalOutput> {
impl<A, P> Channel<stm32::$adc> for P
where P: stasis::EntitlementLock<Resource = opamp::Follower<$opamp, A, InternalOutput>>
{
type ID = u8;
fn channel() -> u8 { $chan }
}

impl<A, B> Channel<stm32::$adc> for opamp::OpenLoop<$opamp, A, B, InternalOutput> {
impl<A, B, P> Channel<stm32::$adc> for P
where P: stasis::EntitlementLock<Resource = opamp::OpenLoop<$opamp, A, B, InternalOutput>>
{
type ID = u8;
fn channel() -> u8 { $chan }
}

impl<A> Channel<stm32::$adc> for opamp::Pga<$opamp, A, InternalOutput> {
impl<A, P> Channel<stm32::$adc> for P
where P: stasis::EntitlementLock<Resource = opamp::Pga<$opamp, A, InternalOutput>>
{
type ID = u8;
fn channel() -> u8 { $chan }
}

impl Channel<stm32::$adc> for opamp::Locked<$opamp, InternalOutput> {
impl<P> Channel<stm32::$adc> for P
where P: stasis::EntitlementLock<Resource = opamp::Locked<$opamp, InternalOutput>>
{
type ID = u8;
fn channel() -> u8 { $chan }
}
Expand Down
17 changes: 8 additions & 9 deletions src/comparator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ use crate::gpio::{
use crate::gpio::gpioc::{PC0, PC1};
use crate::gpio::gpioe::{PE7, PE8};
use crate::gpio::gpiof::PF1;
use crate::observable::ObservationLock;
use crate::rcc::{Clocks, Rcc};
use crate::stm32::{COMP, EXTI};
use proto_hal::stasis;

/// Enabled Comparator (type state)
pub struct Enabled;
Expand Down Expand Up @@ -265,8 +265,7 @@ pub mod refint_input {
const USE_RESISTOR_DIVIDER: bool = $use_r_div;
}

impl crate::observable::Observable for $t {}
impl crate::Sealed for $t {}
impl proto_hal::stasis::Freeze for $t {}
};
}

Expand Down Expand Up @@ -398,8 +397,8 @@ pub trait ComparatorExt<COMP> {
where
PP: PositiveInput<COMP>,
NP: NegativeInput<COMP>,
P: ObservationLock<Peripheral = PP>,
N: ObservationLock<Peripheral = NP>;
P: stasis::EntitlementLock<Resource = PP>,
N: stasis::EntitlementLock<Resource = NP>;
}

macro_rules! impl_comparator {
Expand All @@ -415,8 +414,8 @@ macro_rules! impl_comparator {
where
PP: PositiveInput<$COMP>,
NP: NegativeInput<$COMP>,
P: ObservationLock<Peripheral = PP>,
N: ObservationLock<Peripheral = NP>,
P: stasis::EntitlementLock<Resource = PP>,
N: stasis::EntitlementLock<Resource = NP>,
{
PP::setup(&mut self);
PP::setup(&mut self);
Expand Down Expand Up @@ -453,8 +452,8 @@ macro_rules! impl_comparator {
where
PP: PositiveInput<$COMP>,
NP: NegativeInput<$COMP>,
P: ObservationLock<Peripheral = PP>,
N: ObservationLock<Peripheral = NP>,
P: stasis::EntitlementLock<Resource = PP>,
N: stasis::EntitlementLock<Resource = NP>,
{
comp.comparator(positive_input, negative_input, config, clocks)
}
Expand Down
3 changes: 1 addition & 2 deletions src/dac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ macro_rules! dac_helper {
}
}

impl<const MODE_BITS: u8, ED> crate::Sealed for $CX<MODE_BITS, ED> { }
impl<const MODE_BITS: u8, ED> crate::observable::Observable for $CX<MODE_BITS, ED> { }
impl<const MODE_BITS: u8, ED> proto_hal::stasis::Freeze for $CX<MODE_BITS, ED> { }

impl<const MODE_BITS: u8, ED> $CX<MODE_BITS, ED> {
/// Calibrate the DAC output buffer by performing a "User
Expand Down
3 changes: 1 addition & 2 deletions src/gpio.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! General Purpose Input / Output
use core::marker::PhantomData;

use crate::observable::Observable;
use crate::rcc::Rcc;
use crate::stm32::EXTI;
use crate::syscfg::SysCfg;
Expand Down Expand Up @@ -380,7 +379,7 @@ macro_rules! gpio {
}
}

impl<MODE> Observable for $PXi<MODE> { }
impl<MODE> proto_hal::stasis::Freeze for $PXi<MODE> { }

impl<MODE> $PXi<MODE> {
/// Configures the pin to operate as a floating input pin
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ pub mod exti;
pub mod flash;
pub mod gpio;
pub mod i2c;
pub mod observable;
pub mod opamp;
pub mod prelude;
pub mod pwm;
Expand Down
161 changes: 0 additions & 161 deletions src/observable.rs

This file was deleted.

Loading

0 comments on commit 62e65e1

Please sign in to comment.