Skip to content

Commit 9042dda

Browse files
committed
both embedded-hals for Qei
1 parent 574c293 commit 9042dda

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::{CPin, C1, C2};
@@ -47,22 +44,39 @@ impl<TIM: Instance, PINS> Qei<TIM, PINS> {
4744
}
4845
}
4946

50-
impl<TIM: Instance, PINS> hal::Qei for Qei<TIM, PINS> {
47+
impl<TIM: Instance, PINS> embedded_hal::Qei for Qei<TIM, PINS> {
5148
type Count = TIM::Count;
5249

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

57-
fn direction(&self) -> Direction {
54+
fn direction(&self) -> embedded_hal::Direction {
5855
if self.tim.read_direction() {
59-
hal::Direction::Upcounting
56+
embedded_hal::Direction::Upcounting
6057
} else {
61-
hal::Direction::Downcounting
58+
embedded_hal::Direction::Downcounting
6259
}
6360
}
6461
}
6562

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

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)