Skip to content

Commit 62e65e1

Browse files
committed
Use proto-hal for 'entitlement' instead of 'observation'
1 parent 8fa58c9 commit 62e65e1

File tree

9 files changed

+59
-215
lines changed

9 files changed

+59
-215
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ version = "0.0.2"
1515
nb = "0.1.1"
1616
#stm32g4 = { git = "https://github.com/stm32-rs/stm32-rs-nightlies" } #"0.15.1"
1717
stm32g4 = { version = "0.19.0", package = "stm32g4-staging" }
18+
proto-hal = { git = "https://github.com/AdinAck/proto-hal", rev = "9030895" }
1819
paste = "1.0"
1920
bitflags = "1.2"
2021
vcell = "0.1"

examples/observe.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ use hal::{
1818
comparator::{ComparatorExt, ComparatorSplit, Config},
1919
delay::SYSTDelayExt as _,
2020
gpio::GpioExt,
21-
observable::Observable as _,
2221
rcc::RccExt,
2322
stm32,
2423
};
24+
use proto_hal::stasis::Freeze;
2525
use rt::entry;
2626
use stm32g4xx_hal::{self as hal, adc::config::SampleTime, delay::DelayExt as _};
2727

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

4444
// Only pa1_token and pa0 consumed here
@@ -57,7 +57,7 @@ fn main() -> ! {
5757
// Can not reconfigure pa1 here
5858
loop {
5959
// Can still use pa1 here
60-
let sample = adc.convert(pa1.as_ref(), SampleTime::Cycles_640_5);
60+
let sample = adc.convert(&pa1, SampleTime::Cycles_640_5);
6161
info!("Reading: {}", sample);
6262
delay.delay(1000.millis());
6363
}

src/adc.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use embedded_hal::{
2424
adc::{Channel, OneShot},
2525
blocking::delay::DelayUs,
2626
};
27+
use proto_hal::stasis;
2728

2829
use self::config::ExternalTrigger12;
2930

@@ -136,7 +137,9 @@ impl Temperature {
136137
macro_rules! adc_pins {
137138
($($pin:ty => ($adc:ident, $chan:expr)),+ $(,)*) => {
138139
$(
139-
impl Channel<stm32::$adc> for $pin {
140+
impl<P> Channel<stm32::$adc> for P
141+
where P: stasis::EntitlementLock<Resource = $pin>
142+
{
140143
type ID = u8;
141144
fn channel() -> u8 { $chan }
142145
}
@@ -147,22 +150,30 @@ macro_rules! adc_pins {
147150
macro_rules! adc_opamp {
148151
($($opamp:ty => ($adc:ident, $chan:expr)),+ $(,)*) => {
149152
$(
150-
impl<A> Channel<stm32::$adc> for opamp::Follower<$opamp, A, InternalOutput> {
153+
impl<A, P> Channel<stm32::$adc> for P
154+
where P: stasis::EntitlementLock<Resource = opamp::Follower<$opamp, A, InternalOutput>>
155+
{
151156
type ID = u8;
152157
fn channel() -> u8 { $chan }
153158
}
154159

155-
impl<A, B> Channel<stm32::$adc> for opamp::OpenLoop<$opamp, A, B, InternalOutput> {
160+
impl<A, B, P> Channel<stm32::$adc> for P
161+
where P: stasis::EntitlementLock<Resource = opamp::OpenLoop<$opamp, A, B, InternalOutput>>
162+
{
156163
type ID = u8;
157164
fn channel() -> u8 { $chan }
158165
}
159166

160-
impl<A> Channel<stm32::$adc> for opamp::Pga<$opamp, A, InternalOutput> {
167+
impl<A, P> Channel<stm32::$adc> for P
168+
where P: stasis::EntitlementLock<Resource = opamp::Pga<$opamp, A, InternalOutput>>
169+
{
161170
type ID = u8;
162171
fn channel() -> u8 { $chan }
163172
}
164173

165-
impl Channel<stm32::$adc> for opamp::Locked<$opamp, InternalOutput> {
174+
impl<P> Channel<stm32::$adc> for P
175+
where P: stasis::EntitlementLock<Resource = opamp::Locked<$opamp, InternalOutput>>
176+
{
166177
type ID = u8;
167178
fn channel() -> u8 { $chan }
168179
}

src/comparator.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ use crate::gpio::{
3434
use crate::gpio::gpioc::{PC0, PC1};
3535
use crate::gpio::gpioe::{PE7, PE8};
3636
use crate::gpio::gpiof::PF1;
37-
use crate::observable::ObservationLock;
3837
use crate::rcc::{Clocks, Rcc};
3938
use crate::stm32::{COMP, EXTI};
39+
use proto_hal::stasis;
4040

4141
/// Enabled Comparator (type state)
4242
pub struct Enabled;
@@ -265,8 +265,7 @@ pub mod refint_input {
265265
const USE_RESISTOR_DIVIDER: bool = $use_r_div;
266266
}
267267

268-
impl crate::observable::Observable for $t {}
269-
impl crate::Sealed for $t {}
268+
impl proto_hal::stasis::Freeze for $t {}
270269
};
271270
}
272271

@@ -398,8 +397,8 @@ pub trait ComparatorExt<COMP> {
398397
where
399398
PP: PositiveInput<COMP>,
400399
NP: NegativeInput<COMP>,
401-
P: ObservationLock<Peripheral = PP>,
402-
N: ObservationLock<Peripheral = NP>;
400+
P: stasis::EntitlementLock<Resource = PP>,
401+
N: stasis::EntitlementLock<Resource = NP>;
403402
}
404403

405404
macro_rules! impl_comparator {
@@ -415,8 +414,8 @@ macro_rules! impl_comparator {
415414
where
416415
PP: PositiveInput<$COMP>,
417416
NP: NegativeInput<$COMP>,
418-
P: ObservationLock<Peripheral = PP>,
419-
N: ObservationLock<Peripheral = NP>,
417+
P: stasis::EntitlementLock<Resource = PP>,
418+
N: stasis::EntitlementLock<Resource = NP>,
420419
{
421420
PP::setup(&mut self);
422421
PP::setup(&mut self);
@@ -453,8 +452,8 @@ macro_rules! impl_comparator {
453452
where
454453
PP: PositiveInput<$COMP>,
455454
NP: NegativeInput<$COMP>,
456-
P: ObservationLock<Peripheral = PP>,
457-
N: ObservationLock<Peripheral = NP>,
455+
P: stasis::EntitlementLock<Resource = PP>,
456+
N: stasis::EntitlementLock<Resource = NP>,
458457
{
459458
comp.comparator(positive_input, negative_input, config, clocks)
460459
}

src/dac.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ macro_rules! dac_helper {
218218
}
219219
}
220220

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

224223
impl<const MODE_BITS: u8, ED> $CX<MODE_BITS, ED> {
225224
/// Calibrate the DAC output buffer by performing a "User

src/gpio.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! General Purpose Input / Output
22
use core::marker::PhantomData;
33

4-
use crate::observable::Observable;
54
use crate::rcc::Rcc;
65
use crate::stm32::EXTI;
76
use crate::syscfg::SysCfg;
@@ -380,7 +379,7 @@ macro_rules! gpio {
380379
}
381380
}
382381

383-
impl<MODE> Observable for $PXi<MODE> { }
382+
impl<MODE> proto_hal::stasis::Freeze for $PXi<MODE> { }
384383

385384
impl<MODE> $PXi<MODE> {
386385
/// Configures the pin to operate as a floating input pin

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ pub mod exti;
8484
pub mod flash;
8585
pub mod gpio;
8686
pub mod i2c;
87-
pub mod observable;
8887
pub mod opamp;
8988
pub mod prelude;
9089
pub mod pwm;

src/observable.rs

Lines changed: 0 additions & 161 deletions
This file was deleted.

0 commit comments

Comments
 (0)