Skip to content

Commit d1c6c22

Browse files
committed
Use ObservationLock
1 parent 845448e commit d1c6c22

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

src/comparator.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ 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::IntoObservationToken;
37+
use crate::observable::ObservationLock;
3838
use crate::rcc::{Clocks, Rcc};
3939
use crate::stm32::{COMP, EXTI};
4040

@@ -398,8 +398,8 @@ pub trait ComparatorExt<COMP> {
398398
where
399399
PP: PositiveInput<COMP>,
400400
NP: NegativeInput<COMP>,
401-
P: IntoObservationToken<Peripheral = PP>,
402-
N: IntoObservationToken<Peripheral = NP>;
401+
P: ObservationLock<Peripheral = PP>,
402+
N: ObservationLock<Peripheral = NP>;
403403
}
404404

405405
macro_rules! impl_comparator {
@@ -415,8 +415,8 @@ macro_rules! impl_comparator {
415415
where
416416
PP: PositiveInput<$COMP>,
417417
NP: NegativeInput<$COMP>,
418-
P: IntoObservationToken<Peripheral = PP>,
419-
N: IntoObservationToken<Peripheral = NP>,
418+
P: ObservationLock<Peripheral = PP>,
419+
N: ObservationLock<Peripheral = NP>,
420420
{
421421
PP::setup(&mut self);
422422
PP::setup(&mut self);
@@ -453,8 +453,8 @@ macro_rules! impl_comparator {
453453
where
454454
PP: PositiveInput<$COMP>,
455455
NP: NegativeInput<$COMP>,
456-
P: IntoObservationToken<Peripheral = PP>,
457-
N: IntoObservationToken<Peripheral = NP>,
456+
P: ObservationLock<Peripheral = PP>,
457+
N: ObservationLock<Peripheral = NP>,
458458
{
459459
comp.comparator(positive_input, negative_input, config, clocks)
460460
}

src/observable.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use crate::Sealed;
22
use core::marker::PhantomData;
33

4-
pub trait IntoObservationToken: Sized + crate::Sealed {
5-
type Peripheral;
6-
fn into_ot(self) -> ObservationToken<Self::Peripheral>;
4+
pub trait ObservationLock: Sized + crate::Sealed {
5+
type Peripheral: Observable;
76
}
87

98
/// A struct to hold peripherals which are to be observed.
@@ -16,7 +15,7 @@ pub struct Observed<P, const OBSERVER_COUNT: usize> {
1615
peripheral: P,
1716
}
1817

19-
impl<P, const OBSERVER_COUNT: usize> Observed<P, OBSERVER_COUNT> {
18+
impl<P: Observable, const OBSERVER_COUNT: usize> Observed<P, OBSERVER_COUNT> {
2019
/// Release the observation of this peripheral
2120
///
2221
/// This returns the underlaying perpheral type. Since it is no longer
@@ -46,20 +45,13 @@ pub trait Observable: Sized {
4645
}
4746
}
4847

49-
impl<P: Observable + Sealed> IntoObservationToken for P {
48+
impl<P: Observable + Sealed> ObservationLock for P {
5049
type Peripheral = P;
51-
fn into_ot(self) -> ObservationToken<Self::Peripheral> {
52-
let (_peripheral, [ot]) = self.observe();
53-
ot
54-
}
5550
}
5651

5752
impl<P: Observable + Sealed> Sealed for ObservationToken<P> {}
58-
impl<P: Observable + Sealed> IntoObservationToken for ObservationToken<P> {
53+
impl<P: Observable + Sealed> ObservationLock for ObservationToken<P> {
5954
type Peripheral = P;
60-
fn into_ot(self) -> Self {
61-
self
62-
}
6355
}
6456

6557
impl<P, const N: usize> AsRef<P> for Observed<P, N> {

0 commit comments

Comments
 (0)