Skip to content

Commit 8ce51c0

Browse files
committed
Remap, Rmp, RFrom
1 parent 47287a4 commit 8ce51c0

33 files changed

+1671
-822
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Breaking changes
1111

1212
- 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.
13+
~~Use enums of pin tuples and `Enum::from<(tuple)>` for pin remap before passing to peripheral.~~
14+
Use pin enums and `impl RInto<(enum), R>` for peripheral constructors.
15+
Add `RInto` trait and `Rmp` peripheral wrapper, add `remap` for peripherals.
1416
Remove `RemapStruct`s. [#462] [#506] [#509]
1517
- Use independent `Spi` and `SpiSlave` structures instead of `OP` generic [#462]
1618
- Take `&Clocks` instead of `Clocks` [#498]

examples/can-echo.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ fn main() -> ! {
2424
// Other boards might have a crystal with another frequency or none at all.
2525
rcc.cfgr.use_hse(8.MHz()).freeze(&mut flash.acr);
2626

27-
let mut afio = dp.AFIO.constrain();
28-
2927
let mut can1 = {
3028
let gpioa = dp.GPIOA.split();
3129
let rx = gpioa.pa11;
@@ -34,7 +32,7 @@ fn main() -> ! {
3432
let can = dp.CAN1.can(
3533
#[cfg(not(feature = "connectivity"))]
3634
dp.USB,
37-
(tx, rx, &mut afio.mapr),
35+
(tx, rx),
3836
);
3937

4038
// APB1 (PCLK1): 8MHz, Bit rate: 125kBit/s, Sample Point 87.5%
@@ -51,7 +49,7 @@ fn main() -> ! {
5149
#[cfg(feature = "connectivity")]
5250
let _can2 = {
5351
let gpiob = dp.GPIOB.split();
54-
let can = dp.CAN2.can((gpiob.pb6, gpiob.pb5, &mut afio.mapr));
52+
let can = dp.CAN2.can((gpiob.pb6, gpiob.pb5));
5553

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

examples/can-rtic.rs

Lines changed: 3 additions & 8 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, gpio::Floating, pac::CAN1, prelude::*};
58+
use stm32f1xx_hal::{can::Can, pac::CAN1, prelude::*};
5959

6060
#[local]
6161
struct Local {
@@ -86,17 +86,12 @@ mod app {
8686
let gpioa = cx.device.GPIOA.split();
8787
let can_rx_pin = gpioa.pa11;
8888
let can_tx_pin = gpioa.pa12;
89-
let mut afio = cx.device.AFIO.constrain();
9089

9190
#[cfg(not(feature = "connectivity"))]
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-
);
91+
let can = Can::new(cx.device.CAN1, cx.device.USB, (can_tx_pin, can_rx_pin));
9792

9893
#[cfg(feature = "connectivity")]
99-
let can = Can::<_, Floating>::new(cx.device.CAN1, (can_tx_pin, can_rx_pin, &mut afio.mapr));
94+
let can = Can::new(cx.device.CAN1, (can_tx_pin, can_rx_pin));
10095

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

examples/i2c-bme280/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ cortex-m = "0.7.6"
1616

1717
[dependencies.stm32f1xx-hal]
1818
path = "../.."
19-
version = "0.9.0"
20-
features = ["stm32f103", "rt", "stm32-usbd"]
19+
features = ["stm32f103", "stm32-usbd"]
2120

2221
[profile.dev]
2322
incremental = false

examples/i2c-bme280/src/main.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,24 @@ fn main() -> ! {
5959
// Acquire the GPIOB peripheral
6060
let mut gpiob = dp.GPIOB.split();
6161

62-
let scl = gpiob.pb6.into_alternate_open_drain(&mut gpiob.crl);
63-
let sda = gpiob.pb7.into_alternate_open_drain(&mut gpiob.crl);
62+
let scl = gpiob.pb6;
63+
let sda = gpiob.pb7;
6464

65-
let i2c = BlockingI2c::i2c1(
66-
dp.I2C1,
67-
(scl, sda),
68-
&mut afio.mapr,
69-
Mode::Fast {
70-
frequency: 400.kHz(),
71-
duty_cycle: DutyCycle::Ratio16to9,
72-
},
73-
clocks,
74-
1000,
75-
10,
76-
1000,
77-
1000,
78-
);
65+
let i2c = dp
66+
.I2C1
67+
//.remap(&mut afio.mapr) // add this if want to use PB8, PB9 instead
68+
.blocking_i2c(
69+
(scl, sda),
70+
Mode::Fast {
71+
frequency: 400.kHz(),
72+
duty_cycle: DutyCycle::Ratio16to9,
73+
},
74+
&clocks,
75+
1000,
76+
10,
77+
1000,
78+
1000,
79+
);
7980

8081
// The Adafruit boards have address 0x77 without closing the jumper on the back, the BME280 lib connects to 0x77 with `new_secondary`, use
8182
// `new_primary` for 0x76 if you close the jumper/solder bridge.

examples/mfrc522.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,18 @@ fn main() -> ! {
2525

2626
let _stim = &mut cp.ITM.stim[0];
2727
let rcc = dp.RCC.constrain();
28-
let mut afio = dp.AFIO.constrain();
2928
let mut flash = dp.FLASH.constrain();
3029
let mut gpioa = dp.GPIOA.split();
3130
let mut gpioc = dp.GPIOC.split();
3231

3332
let clocks = rcc.cfgr.freeze(&mut flash.acr);
3433

35-
let sck = gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl);
34+
let sck = gpioa.pa5;
3635
let miso = gpioa.pa6;
37-
let mosi = gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl);
36+
let mosi = gpioa.pa7;
3837
let spi = Spi::new(
3938
dp.SPI1,
40-
(sck, miso, mosi, &mut afio.mapr),
39+
(Some(sck), Some(miso), Some(mosi)),
4140
MODE,
4241
1.MHz(),
4342
&clocks,

examples/mpu9250.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,24 @@ fn main() -> ! {
2424

2525
let clocks = rcc.cfgr.freeze(&mut flash.acr);
2626

27-
let mut afio = dp.AFIO.constrain();
28-
2927
let mut gpioa = dp.GPIOA.split();
3028
// let mut gpiob = dp.GPIOB.split();
3129

3230
let nss = gpioa.pa4.into_push_pull_output(&mut gpioa.crl);
3331

3432
// SPI1
35-
let sck = gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl);
33+
let sck = gpioa.pa5;
3634
let miso = gpioa.pa6;
37-
let mosi = gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl);
35+
let mosi = gpioa.pa7;
3836

3937
// SPI2
40-
// let sck = gpiob.pb13.into_alternate_push_pull(&mut gpiob.crh);
38+
// let sck = gpiob.pb13;
4139
// let miso = gpiob.pb14;
42-
// let mosi = gpiob.pb15.into_alternate_push_pull(&mut gpiob.crh);
40+
// let mosi = gpiob.pb15;
4341

4442
let spi = Spi::new(
4543
dp.SPI1,
46-
(sck, miso, mosi, &mut afio.mapr),
44+
(Some(sck), Some(miso), Some(mosi)),
4745
mpu9250::MODE.into(),
4846
1.MHz(),
4947
&clocks,

examples/serial-dma-circ.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() -> ! {
2626

2727
let clocks = rcc.cfgr.freeze(&mut flash.acr);
2828

29-
let mut afio = p.AFIO.constrain();
29+
//let mut afio = p.AFIO.constrain();
3030
let channels = p.DMA1.split();
3131

3232
let mut gpioa = p.GPIOA.split();
@@ -50,7 +50,7 @@ fn main() -> ! {
5050

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

examples/serial-dma-peek.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn main() -> ! {
2525

2626
let clocks = rcc.cfgr.freeze(&mut flash.acr);
2727

28-
let mut afio = p.AFIO.constrain();
28+
//let mut afio = p.AFIO.constrain();
2929
let channels = p.DMA1.split();
3030

3131
let mut gpioa = p.GPIOA.split();
@@ -47,12 +47,7 @@ fn main() -> ! {
4747
// let tx = gpiob.pb10.into_alternate_push_pull(&mut gpiob.crh);
4848
// let rx = gpiob.pb11;
4949

50-
let serial = Serial::new(
51-
p.USART1,
52-
(tx, rx, &mut afio.mapr),
53-
Config::default(),
54-
&clocks,
55-
);
50+
let serial = Serial::new(p.USART1, (tx, rx), Config::default(), &clocks);
5651

5752
let rx = serial.rx.with_dma(channels.5);
5853
let buf = singleton!(: [u8; 8] = [0; 8]).unwrap();

examples/serial-dma-rx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn main() -> ! {
2525

2626
let clocks = rcc.cfgr.freeze(&mut flash.acr);
2727

28-
let mut afio = p.AFIO.constrain();
28+
//let mut afio = p.AFIO.constrain();
2929
let channels = p.DMA1.split();
3030

3131
let mut gpioa = p.GPIOA.split();
@@ -49,7 +49,7 @@ fn main() -> ! {
4949

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

0 commit comments

Comments
 (0)