Skip to content

Commit aacd8eb

Browse files
committed
both embedded-hals for Qei
1 parent b5169cf commit aacd8eb

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

src/qei.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
//! # Quadrature Encoder Interface
2-
use crate::{
3-
hal::{self, Direction},
4-
pac::RCC,
5-
rcc,
6-
timer::General,
7-
};
2+
use crate::{pac::RCC, rcc, timer::General};
83

94
pub trait Pins<TIM> {}
105
use crate::timer::{CPin, C1, C2};
@@ -48,22 +43,39 @@ impl<TIM: Instance, PINS> Qei<TIM, PINS> {
4843
}
4944
}
5045

51-
impl<TIM: Instance, PINS> hal::Qei for Qei<TIM, PINS> {
46+
impl<TIM: Instance, PINS> embedded_hal::Qei for Qei<TIM, PINS> {
5247
type Count = TIM::Width;
5348

5449
fn count(&self) -> Self::Count {
5550
self.tim.read_count() as Self::Count
5651
}
5752

58-
fn direction(&self) -> Direction {
53+
fn direction(&self) -> embedded_hal::Direction {
5954
if self.tim.read_direction() {
60-
hal::Direction::Upcounting
55+
embedded_hal::Direction::Upcounting
6156
} else {
62-
hal::Direction::Downcounting
57+
embedded_hal::Direction::Downcounting
6358
}
6459
}
6560
}
6661

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

src/rng.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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)