Skip to content

Commit faeda4e

Browse files
authored
Merge pull request #462 from stm32-rs/maps
remap enums
2 parents 062d493 + 0f9680f commit faeda4e

30 files changed

+1256
-795
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Breaking changes
11+
12+
- Relax pin type generics for `Serial`, `I2c`, `Spi`, `Can`. [#462]
13+
Use enums of pin tuples and `Enum::from<(tuple)>` for pin remap before passing to peripheral.
14+
Remove `RemapStruct`s. [#462]
15+
- Use independent `Spi` and `SpiSlave` structures instead of `OP` generic [#462]
16+
- Take `&Clocks` instead of `Clocks` [#498]
17+
1018
### Changed
1119

1220
- PWM timer auto reload value is now preloaded/buffered [#453]
1321
- Move from bors/manual merge to GH merge queue [#467]
1422
- Replace UB code by a legitimate pointer access [#480]
1523
- Fix flash error flag clearing [#489]
1624
- Clarify README for windows users [#496]
17-
- Take `&Clocks` instead of `Clocks`
1825

1926
### Added
2027

@@ -28,6 +35,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2835

2936
[#416]: https://github.com/stm32-rs/stm32f1xx-hal/pull/416
3037
[#453]: https://github.com/stm32-rs/stm32f1xx-hal/pull/453
38+
[#462]: https://github.com/stm32-rs/stm32f1xx-hal/pull/462
3139
[#467]: https://github.com/stm32-rs/stm32f1xx-hal/pull/467
3240
[#479]: https://github.com/stm32-rs/stm32f1xx-hal/pull/479
3341
[#480]: https://github.com/stm32-rs/stm32f1xx-hal/pull/480
@@ -36,6 +44,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3644
[#489]: https://github.com/stm32-rs/stm32f1xx-hal/pull/489
3745
[#494]: https://github.com/stm32-rs/stm32f1xx-hal/pull/494
3846
[#496]: https://github.com/stm32-rs/stm32f1xx-hal/pull/496
47+
[#498]: https://github.com/stm32-rs/stm32f1xx-hal/pull/498
3948

4049
## [v0.10.0] - 2022-12-12
4150

examples/can-echo.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use panic_halt as _;
1010
use bxcan::filter::Mask32;
1111
use cortex_m_rt::entry;
1212
use nb::block;
13-
use stm32f1xx_hal::{can::Can, pac, prelude::*};
13+
use stm32f1xx_hal::{gpio::Floating, pac, prelude::*};
1414

1515
#[entry]
1616
fn main() -> ! {
@@ -27,15 +27,15 @@ fn main() -> ! {
2727
let mut afio = dp.AFIO.constrain();
2828

2929
let mut can1 = {
30-
#[cfg(not(feature = "connectivity"))]
31-
let can = Can::new(dp.CAN1, dp.USB);
32-
#[cfg(feature = "connectivity")]
33-
let can = Can::new(dp.CAN1);
30+
let gpioa = dp.GPIOA.split();
31+
let rx = gpioa.pa11;
32+
let tx = gpioa.pa12;
3433

35-
let mut gpioa = dp.GPIOA.split();
36-
let rx = gpioa.pa11.into_floating_input(&mut gpioa.crh);
37-
let tx = gpioa.pa12.into_alternate_push_pull(&mut gpioa.crh);
38-
can.assign_pins((tx, rx), &mut afio.mapr);
34+
let can = dp.CAN1.can::<Floating>(
35+
#[cfg(not(feature = "connectivity"))]
36+
dp.USB,
37+
(tx, rx, &mut afio.mapr),
38+
);
3939

4040
// APB1 (PCLK1): 8MHz, Bit rate: 125kBit/s, Sample Point 87.5%
4141
// Value was calculated with http://www.bittiming.can-wiki.info/
@@ -50,12 +50,10 @@ fn main() -> ! {
5050

5151
#[cfg(feature = "connectivity")]
5252
let _can2 = {
53-
let can = Can::new(dp.CAN2);
54-
55-
let mut gpiob = dp.GPIOB.split();
56-
let rx = gpiob.pb5.into_floating_input(&mut gpiob.crl);
57-
let tx = gpiob.pb6.into_alternate_push_pull(&mut gpiob.crl);
58-
can.assign_pins((tx, rx), &mut afio.mapr);
53+
let gpiob = dp.GPIOB.split();
54+
let can = dp
55+
.CAN2
56+
.can::<Floating>((gpiob.pb6, gpiob.pb5, &mut afio.mapr));
5957

6058
// APB1 (PCLK1): 8MHz, Bit rate: 125kBit/s, Sample Point 87.5%
6159
// Value was calculated with http://www.bittiming.can-wiki.info/

examples/can-loopback.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use panic_halt as _;
1212

1313
use cortex_m_rt::entry;
1414
use nb::block;
15-
use stm32f1xx_hal::{can::Can, pac, prelude::*};
15+
use stm32f1xx_hal::{can::Can, gpio::Floating, pac, prelude::*};
1616

1717
#[entry]
1818
fn main() -> ! {
@@ -25,11 +25,11 @@ fn main() -> ! {
2525
// resonator must be used.
2626
rcc.cfgr.use_hse(8.MHz()).freeze(&mut flash.acr);
2727

28-
#[cfg(not(feature = "connectivity"))]
29-
let can = Can::new(dp.CAN1, dp.USB);
30-
31-
#[cfg(feature = "connectivity")]
32-
let can = Can::new(dp.CAN1);
28+
let can = Can::<_, Floating>::new_loopback(
29+
dp.CAN1,
30+
#[cfg(not(feature = "connectivity"))]
31+
dp.USB,
32+
);
3333

3434
// Use loopback mode: No pins need to be assigned to peripheral.
3535
// APB1 (PCLK1): 8MHz, Bit rate: 500Bit/s, Sample Point 87.5%

examples/can-rtic.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ mod app {
5555
use super::{enqueue_frame, PriorityFrame};
5656
use bxcan::{filter::Mask32, ExtendedId, Fifo, Frame, Interrupts, Rx0, StandardId, Tx};
5757
use heapless::binary_heap::{BinaryHeap, Max};
58-
use stm32f1xx_hal::{can::Can, pac::CAN1, prelude::*};
58+
use stm32f1xx_hal::{can::Can, gpio::Floating, pac::CAN1, prelude::*};
5959

6060
#[local]
6161
struct Local {
@@ -82,18 +82,21 @@ mod app {
8282
.pclk2(64.MHz())
8383
.freeze(&mut flash.acr);
8484

85+
// Select pins for CAN1.
86+
let gpioa = cx.device.GPIOA.split();
87+
let can_rx_pin = gpioa.pa11;
88+
let can_tx_pin = gpioa.pa12;
89+
let mut afio = cx.device.AFIO.constrain();
90+
8591
#[cfg(not(feature = "connectivity"))]
86-
let can = Can::new(cx.device.CAN1, cx.device.USB);
92+
let can = Can::<_, Floating>::new(
93+
cx.device.CAN1,
94+
cx.device.USB,
95+
(can_tx_pin, can_rx_pin, &mut afio.mapr),
96+
);
8797

8898
#[cfg(feature = "connectivity")]
89-
let can = Can::new(cx.device.CAN1);
90-
91-
// Select pins for CAN1.
92-
let mut gpioa = cx.device.GPIOA.split();
93-
let can_rx_pin = gpioa.pa11.into_floating_input(&mut gpioa.crh);
94-
let can_tx_pin = gpioa.pa12.into_alternate_push_pull(&mut gpioa.crh);
95-
let mut afio = cx.device.AFIO.constrain();
96-
can.assign_pins((can_tx_pin, can_rx_pin), &mut afio.mapr);
99+
let can = Can::<_, Floating>::new(cx.device.CAN1, (can_tx_pin, can_rx_pin, &mut afio.mapr));
97100

98101
// APB1 (PCLK1): 16MHz, Bit rate: 1000kBit/s, Sample Point 87.5%
99102
// Value was calculated with http://www.bittiming.can-wiki.info/

examples/mfrc522.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ use panic_itm as _;
77
use cortex_m::iprintln;
88

99
use cortex_m_rt::entry;
10-
use embedded_hal_02::spi::{Mode, Phase, Polarity};
1110
use mfrc522::Mfrc522;
12-
use stm32f1xx_hal::{pac, prelude::*, spi::Spi};
11+
use stm32f1xx_hal::{
12+
pac,
13+
prelude::*,
14+
spi::{Mode, Phase, Polarity, Spi},
15+
};
1316
pub const MODE: Mode = Mode {
1417
polarity: Polarity::IdleLow,
1518
phase: Phase::CaptureOnFirstTransition,
@@ -32,10 +35,9 @@ fn main() -> ! {
3235
let sck = gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl);
3336
let miso = gpioa.pa6;
3437
let mosi = gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl);
35-
let spi = Spi::spi1(
38+
let spi = Spi::new(
3639
dp.SPI1,
37-
(sck, miso, mosi),
38-
&mut afio.mapr,
40+
(sck, miso, mosi, &mut afio.mapr),
3941
MODE,
4042
1.MHz(),
4143
&clocks,

examples/serial-dma-circ.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ fn main() -> ! {
5050

5151
let serial = Serial::new(
5252
p.USART1,
53-
(tx, rx),
54-
&mut afio.mapr,
53+
(tx, rx, &mut afio.mapr),
5554
Config::default().baudrate(9_600.bps()),
5655
&clocks,
5756
);

examples/serial-dma-peek.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ fn main() -> ! {
4949

5050
let serial = Serial::new(
5151
p.USART1,
52-
(tx, rx),
53-
&mut afio.mapr,
52+
(tx, rx, &mut afio.mapr),
5453
Config::default(),
5554
&clocks,
5655
);

examples/serial-dma-rx.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ fn main() -> ! {
4949

5050
let serial = Serial::new(
5151
p.USART1,
52-
(tx, rx),
53-
&mut afio.mapr,
52+
(tx, rx, &mut afio.mapr),
5453
Config::default().baudrate(9_600.bps()),
5554
&clocks,
5655
);

examples/serial-dma-tx.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ fn main() -> ! {
4949

5050
let serial = Serial::new(
5151
p.USART1,
52-
(tx, rx),
53-
&mut afio.mapr,
52+
(tx, rx, &mut afio.mapr),
5453
Config::default().baudrate(9600.bps()),
5554
&clocks,
5655
);

examples/serial-fmt.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ fn main() -> ! {
6161
// the registers are used to enable and configure the device.
6262
let serial = Serial::new(
6363
p.USART3,
64-
(tx, rx),
65-
&mut afio.mapr,
64+
(tx, rx, &mut afio.mapr),
6665
Config::default().baudrate(9600.bps()),
6766
&clocks,
6867
);

0 commit comments

Comments
 (0)