Skip to content

Commit eee668e

Browse files
committed
fix bxcan, use generic into_af in examples
1 parent 28596b4 commit eee668e

File tree

8 files changed

+31
-33
lines changed

8 files changed

+31
-33
lines changed

examples/can.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,20 @@ fn main() -> ! {
4343
// Configure CAN RX and TX pins (AF9)
4444
let rx = gpioa
4545
.pa11
46-
.into_af9_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
46+
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
4747
let tx = gpioa
4848
.pa12
49-
.into_af9_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
49+
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
5050

5151
// Initialize the CAN peripheral
52-
let mut can = Can::new(dp.CAN, tx, rx, &mut rcc.apb1);
53-
5452
// Use loopback mode: No pins need to be assigned to peripheral.
5553
// APB1 (PCLK1): 64MHz, Bit rate: 500kBit/s, Sample Point 87.5%
5654
// Value was calculated with http://www.bittiming.can-wiki.info/
57-
can.modify_config()
55+
let mut can = bxcan::Can::builder(Can::new(dp.CAN, tx, rx, &mut rcc.apb1))
5856
.set_bit_timing(0x001c_0003)
5957
.set_loopback(false)
60-
.set_silent(false);
58+
.set_silent(false)
59+
.leave_disabled();
6160

6261
let mut filters = can.modify_filters();
6362

@@ -67,7 +66,7 @@ fn main() -> ! {
6766
drop(filters);
6867

6968
// Sync to the bus and start normal operation.
70-
block!(can.enable()).ok();
69+
block!(can.enable_non_blocking()).ok();
7170

7271
let mut led0 = gpiob
7372
.pb15

examples/i2c_scanner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ fn main() -> ! {
3131
let mut scl =
3232
gpiob
3333
.pb6
34-
.into_af4_open_drain(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
34+
.into_af_open_drain(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
3535
let mut sda =
3636
gpiob
3737
.pb7
38-
.into_af4_open_drain(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
38+
.into_af_open_drain(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
3939
scl.internal_pull_up(&mut gpiob.pupdr, true);
4040
sda.internal_pull_up(&mut gpiob.pupdr, true);
4141
let mut i2c = hal::i2c::I2c::new(

examples/pwm.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,38 @@ fn main() -> ! {
3434
let mut gpioa = dp.GPIOA.split(&mut rcc.ahb);
3535
let pa4 = gpioa
3636
.pa4
37-
.into_af2_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
37+
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
3838
let pa6 = gpioa
3939
.pa6
40-
.into_af2_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
40+
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
4141
let pa7 = gpioa
4242
.pa7
43-
.into_af2_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
43+
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
4444

4545
let mut gpiob = dp.GPIOB.split(&mut rcc.ahb);
4646
let pb0 = gpiob
4747
.pb0
48-
.into_af2_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
48+
.into_af_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
4949
let pb1 = gpiob
5050
.pb1
51-
.into_af2_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
51+
.into_af_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
5252
let pb4 = gpiob
5353
.pb4
54-
.into_af2_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
54+
.into_af_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
5555
let pb5 = gpiob
5656
.pb5
57-
.into_af2_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
57+
.into_af_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
5858
let pb8 = gpiob
5959
.pb8
60-
.into_af1_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrh);
60+
.into_af_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrh);
6161
let pb10 = gpiob
6262
.pb10
63-
.into_af1_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrh);
63+
.into_af_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrh);
6464

6565
let mut gpioc = dp.GPIOC.split(&mut rcc.ahb);
6666
let pc10 = gpioc
6767
.pc10
68-
.into_af4_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh);
68+
.into_af_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh);
6969

7070
// TIM3
7171
//

examples/serial_dma.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ fn main() -> ! {
3535
let pins = (
3636
gpioa
3737
.pa9
38-
.into_af7_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh),
38+
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh),
3939
gpioa
4040
.pa10
41-
.into_af7_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh),
41+
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh),
4242
);
4343
let serial = Serial::new(dp.USART1, pins, 9600.Bd(), clocks, &mut rcc.apb2);
4444
let (tx, rx) = serial.split();

examples/serial_echo_rtic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ mod app {
6969
// configure this pin to make use of its `USART1_TX` alternative function
7070
// (AF mapping taken from table 14 "Alternate functions for port A" of the datasheet at
7171
// https://www.st.com/en/microcontrollers-microprocessors/stm32f303vc.html)
72-
.into_af7_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh),
72+
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh),
7373
gpioa
7474
// Rx pin
7575
.pa10
7676
// configure this pin to make use of its `USART1_RX` alternative function
7777
// (AF mapping taken from table 14 "Alternate functions for port A" of the datasheet at
7878
// https://www.st.com/en/microcontrollers-microprocessors/stm32f303vc.html)
79-
.into_af7_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh),
79+
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh),
8080
);
8181
pins.1.internal_pull_up(&mut gpioa.pupdr, true);
8282
let mut serial: SerialType =

examples/spi.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ fn main() -> ! {
3232
// Configure pins for SPI
3333
let sck = gpioc
3434
.pc10
35-
.into_af6_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh);
35+
.into_af_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh);
3636
let miso = gpioc
3737
.pc11
38-
.into_af6_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh);
38+
.into_af_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh);
3939
let mosi = gpioc
4040
.pc12
41-
.into_af6_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh);
41+
.into_af_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh);
4242

4343
let mut spi = Spi::new(dp.SPI3, (sck, miso, mosi), 3.MHz(), clocks, &mut rcc.apb1);
4444

examples/usb_serial.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,10 @@ fn main() -> ! {
5353
usb_dp.set_low().ok();
5454
delay(clocks.sysclk().0 / 100);
5555

56-
let usb_dm =
57-
gpioa
58-
.pa11
59-
.into_af14_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
60-
let usb_dp = usb_dp.into_af14_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
56+
let usb_dm = gpioa
57+
.pa11
58+
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
59+
let usb_dp = usb_dp.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
6160

6261
let usb = Peripheral {
6362
usb: dp.USB,

src/can.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ where
5555
Rx: RxPin,
5656
{
5757
/// Create a new `bxcan::CAN` instance.
58-
pub fn new(can: pac::CAN, tx: Tx, rx: Rx, apb1: &mut APB1) -> bxcan::Can<Self> {
58+
pub fn new(can: pac::CAN, tx: Tx, rx: Rx, apb1: &mut APB1) -> Self {
5959
pac::CAN::enable(apb1);
6060
pac::CAN::reset(apb1);
6161

62-
bxcan::Can::builder(Can { can, tx, rx }).enable()
62+
Can { can, tx, rx }
6363
}
6464

6565
/// Releases the CAN peripheral and associated pins

0 commit comments

Comments
 (0)