Skip to content

Commit a26bfb0

Browse files
committed
QeiExt
1 parent d1bb6e6 commit a26bfb0

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2222
- Use fugit rate types instead of custom [#430]
2323
- Add channel events, make Event use bitflags (simplify interrupt handling) [#425]
2424
- reexport `digital::v2::PinState` again [#428]
25-
- Timer impls with time based on `fugit` moved to `fugit` module, added `Pwm` and `fugit-timer` impls [#423]
25+
- Timer impls with time based on `fugit::Duration` same as `Hertz` moved to `timer` module,
26+
added appropriate `Ext` traits implemented on peripherals directly,
27+
added `Pwm` and `fugit-timer` impls [#423] [#449]
2628

2729
### Fixed
2830

@@ -60,6 +62,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
6062
[#430]: https://github.com/stm32-rs/stm32f4xx-hal/pull/430
6163
[#447]: https://github.com/stm32-rs/stm32f4xx-hal/pull/447
6264
[#448]: https://github.com/stm32-rs/stm32f4xx-hal/pull/448
65+
[#449]: https://github.com/stm32-rs/stm32f4xx-hal/pull/449
6366

6467
### Changed
6568

examples/qei.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use panic_halt as _;
1414

1515
use cortex_m_rt::entry;
1616
use embedded_hal::Direction as RotaryDirection;
17-
use stm32f4xx_hal::{pac, prelude::*, qei::Qei, timer::Timer};
17+
use stm32f4xx_hal::{pac, prelude::*, qei::Qei};
1818

1919
#[entry]
2020
fn main() -> ! {
@@ -31,7 +31,7 @@ fn main() -> ! {
3131
let clocks = rcc.cfgr.freeze();
3232

3333
// Create a delay abstraction based on SysTick.
34-
let mut delay = Timer::syst(cp.SYST, &clocks).delay();
34+
let mut delay = cp.SYST.delay(&clocks);
3535

3636
let gpioa = dp.GPIOA.split();
3737

examples/serial-9bit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use panic_halt as _;
3434
use cortex_m_rt::entry;
3535
use stm32f4xx_hal as hal;
3636

37-
use crate::hal::{block, pac, prelude::*, serial::config::Config, timer::Timer};
37+
use crate::hal::{block, pac, prelude::*, serial::config::Config};
3838

3939
use core::ops::Range;
4040

@@ -55,7 +55,7 @@ fn main() -> ! {
5555

5656
let clocks = rcc.cfgr.use_hse(8.MHz()).freeze();
5757

58-
let mut delay = Timer::syst(cp.SYST, &clocks).delay();
58+
let mut delay = cp.SYST.delay(&clocks);
5959

6060
// define RX/TX pins
6161
let tx_pin = gpioa.pa2.into_alternate();

src/prelude.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub use crate::gpio::ExtiPin as _stm32f4xx_hal_gpio_ExtiPin;
6464
pub use crate::gpio::GpioExt as _stm32f4xx_hal_gpio_GpioExt;
6565
pub use crate::i2c::I2cExt as _stm32f4xx_hal_i2c_I2cExt;
6666
pub use crate::i2s::I2sExt as _stm32f4xx_hal_i2s_I2sExt;
67+
pub use crate::qei::QeiExt as _stm32f4xx_hal_QeiExt;
6768
pub use crate::rcc::RccExt as _stm32f4xx_hal_rcc_RccExt;
6869
#[cfg(all(feature = "device-selected", feature = "rng"))]
6970
pub use crate::rng::RngExt as _stm32f4xx_hal_rng_RngExt;

src/qei.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ use crate::{pac::RCC, rcc, timer::General};
44
pub trait Pins<TIM> {}
55
use crate::timer::CPin;
66

7+
pub trait QeiExt<PINS>: Sized {
8+
fn qei(self, pins: PINS) -> Qei<Self, PINS>;
9+
}
10+
11+
impl<TIM, PINS> QeiExt<PINS> for TIM
12+
where
13+
TIM: Instance,
14+
PINS: Pins<TIM>,
15+
{
16+
fn qei(self, pins: PINS) -> Qei<Self, PINS> {
17+
Qei::new(self, pins)
18+
}
19+
}
20+
721
impl<TIM, PC1, PC2> Pins<TIM> for (PC1, PC2)
822
where
923
PC1: CPin<TIM, 0>,
@@ -17,13 +31,12 @@ pub struct Qei<TIM, PINS> {
1731
pins: PINS,
1832
}
1933

20-
impl<TIM: Instance, PC1, PC2> Qei<TIM, (PC1, PC2)>
34+
impl<TIM: Instance, PINS> Qei<TIM, PINS>
2135
where
22-
PC1: CPin<TIM, 0>,
23-
PC2: CPin<TIM, 1>,
36+
PINS: Pins<TIM>,
2437
{
2538
/// Configures a TIM peripheral as a quadrature encoder interface input
26-
pub fn new(mut tim: TIM, pins: (PC1, PC2)) -> Self {
39+
pub fn new(mut tim: TIM, pins: PINS) -> Self {
2740
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
2841
let rcc = unsafe { &(*RCC::ptr()) };
2942
// Enable and reset clock.

src/timer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub mod pwm;
2626
pub use pwm::*;
2727
#[cfg(not(feature = "stm32f410"))]
2828
pub mod pwm_input;
29+
#[cfg(not(feature = "stm32f410"))]
2930
pub use pwm_input::PwmInput;
3031
#[cfg(feature = "rtic")]
3132
#[cfg(not(feature = "stm32f410"))]

0 commit comments

Comments
 (0)