Skip to content

Commit 44696d4

Browse files
committed
both embedded-hals for Qei
1 parent 11b9530 commit 44696d4

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

src/qei.rs

+23-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
//! # Quadrature Encoder Interface
2-
use crate::{
3-
hal::{self, Direction},
4-
pac::RCC,
5-
rcc,
6-
};
2+
3+
use crate::{pac::RCC, rcc};
74

85
pub trait Pins<TIM> {}
96
use crate::timer::PinC1;
@@ -48,22 +45,39 @@ impl<TIM: Instance, PINS> Qei<TIM, PINS> {
4845
}
4946
}
5047

51-
impl<TIM: Instance, PINS> hal::Qei for Qei<TIM, PINS> {
48+
impl<TIM: Instance, PINS> embedded_hal::Qei for Qei<TIM, PINS> {
5249
type Count = TIM::Count;
5350

5451
fn count(&self) -> Self::Count {
5552
self.tim.read_count() as Self::Count
5653
}
5754

58-
fn direction(&self) -> Direction {
55+
fn direction(&self) -> embedded_hal::Direction {
5956
if self.tim.read_direction() {
60-
hal::Direction::Upcounting
57+
embedded_hal::Direction::Upcounting
6158
} else {
62-
hal::Direction::Downcounting
59+
embedded_hal::Direction::Downcounting
6360
}
6461
}
6562
}
6663

64+
impl<TIM: Instance, PINS> embedded_hal_one::qei::blocking::Qei for Qei<TIM, PINS> {
65+
type Error = core::convert::Infallible;
66+
type Count = TIM::Count;
67+
68+
fn count(&self) -> Result<Self::Count, Self::Error> {
69+
Ok(self.tim.read_count() as Self::Count)
70+
}
71+
72+
fn direction(&self) -> Result<embedded_hal_one::qei::Direction, Self::Error> {
73+
Ok(if self.tim.read_direction() {
74+
embedded_hal_one::qei::Direction::Upcounting
75+
} else {
76+
embedded_hal_one::qei::Direction::Downcounting
77+
})
78+
}
79+
}
80+
6781
pub trait Instance: crate::Sealed + rcc::Enable + rcc::Reset {
6882
type Count;
6983

src/rng.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
use core::cmp;
2424
use core::mem;
2525

26-
use crate::hal::blocking::rng;
2726
use crate::pac;
2827
use crate::pac::RNG;
2928
use crate::rcc::{Clocks, Enable, Reset};
3029
use crate::time::U32Ext;
3130
use core::num::NonZeroU32;
3231
use core::ops::Shl;
32+
use embedded_hal::blocking::rng;
3333
use rand_core::RngCore;
3434

3535
/// Random number generator specific errors

src/watchdog.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! Watchdog peripherals
22
33
use crate::{
4-
hal::watchdog::{Watchdog, WatchdogEnable},
54
pac::{DBGMCU, IWDG},
65
time::MilliSeconds,
76
};
7+
use embedded_hal::watchdog::{Watchdog, WatchdogEnable};
88

99
/// Wraps the Independent Watchdog (IWDG) peripheral
1010
pub struct IndependentWatchdog {

0 commit comments

Comments
 (0)