Skip to content

Commit 555b0e1

Browse files
committed
Allow Serial::new instead of Serial::usartX
This requires changing I2C to a more generic implementation, where the specific UART peripheral implementation get's dispatch upon it's Instance trait. The specific UART is longer hard coded into, but instead is referenced via pointer (trait). This also allows to reduce the usart macro implementation, so that the code is easier to follow. But this leads to code duplication, as code for the Write and Read trait of embedded-hal can no longer be shared between Serial and Tx | Rx. Also, the underlying UART peripheral of Tx and Rx after split has to be tracked at runtime, instead of being decoded at compile time (via macro). In addition to all of this the Idle interrupt event was also added.
1 parent 4084456 commit 555b0e1

File tree

7 files changed

+472
-309
lines changed

7 files changed

+472
-309
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1919
- `ld` feature, which enables the memory.x generation ([#216])
2020
- Implement `DelayMs` for `Milliseconds` and `DelayUs` for `Microseconds` ([#234])
2121
- ADC can now be `free()`'d ([#212])
22+
- Serial does now implement `embedded_hal::serial::{Read, Write}`.
23+
No `split()` necessary. ([#232])
24+
- Serial can now listen for the "Transmission Complete" `Tc` interrupt event ([#232])
25+
- Serial can now listen for the `Idle` interrupt event ([#238])
2226

2327
### Changed
2428

@@ -70,6 +74,7 @@ let clocks = rcc
7074
- Remove `stm32` module. Use `use stm32f3xx_hal::pac` instead.
7175
This module was a deprecated in [v0.5.0][] and is now subject for
7276
removal. ([#220])
77+
- `Serial::uart1` ... functions are renamed to `Serial::new`. ([#212])
7378

7479
## [v0.6.1] - 2020-12-10
7580

@@ -325,6 +330,7 @@ let clocks = rcc
325330
[filter]: https://defmt.ferrous-systems.com/filtering.html
326331

327332
[#234]: https://github.com/stm32-rs/stm32f3xx-hal/pull/234
333+
[#232]: https://github.com/stm32-rs/stm32f3xx-hal/pull/232
328334
[#229]: https://github.com/stm32-rs/stm32f3xx-hal/pull/229
329335
[#227]: https://github.com/stm32-rs/stm32f3xx-hal/pull/227
330336
[#220]: https://github.com/stm32-rs/stm32f3xx-hal/pull/220

examples/serial_dma.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn main() -> ! {
2929
.pa10
3030
.into_af7_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh),
3131
);
32-
let serial = Serial::usart1(dp.USART1, pins, 9600.Bd(), clocks, &mut rcc.apb2);
32+
let serial = Serial::new(dp.USART1, pins, 9600.Bd(), clocks, &mut rcc.apb2);
3333
let (tx, rx) = serial.split();
3434

3535
let dma1 = dp.DMA1.split(&mut rcc.ahb);

examples/serial_echo_rtic.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,8 @@ mod app {
6464
.into_af7_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh),
6565
);
6666
pins.1.internal_pull_up(&mut gpioa.pupdr, true);
67-
let mut serial: SerialType = Serial::usart1(
68-
cx.device.USART1,
69-
pins,
70-
19200_u32.Bd(),
71-
clocks,
72-
&mut rcc.apb2,
73-
);
67+
let mut serial: SerialType =
68+
Serial::new(cx.device.USART1, pins, 19200.Bd(), clocks, &mut rcc.apb2);
7469
serial.listen(Event::Rxne);
7570

7671
rprintln!("post init");

src/gpio.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ pub struct Pin<Gpio, Index, Mode> {
275275
_mode: PhantomData<Mode>,
276276
}
277277

278+
// Make all GPIO peripheral trait extensions sealable.
279+
impl<Gpio, Index, Mode> crate::private::Sealed for Pin<Gpio, Index, Mode> {}
280+
278281
/// Fully erased pin
279282
///
280283
/// This moves the pin type information to be known

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,9 @@ cfg_if! {
203203
}
204204
}
205205
}
206+
207+
mod private {
208+
/// Private sealed trait to seal all GPIO implementations
209+
/// which do implement peripheral functionalities.
210+
pub trait Sealed {}
211+
}

0 commit comments

Comments
 (0)