Update formatting.

This commit is contained in:
Corey Schuhen 2023-12-11 21:25:05 +10:00
parent 13af76af88
commit b34c8e3eb1

View File

@ -4,13 +4,12 @@
use defmt::*; use defmt::*;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_stm32::bind_interrupts;
use embassy_stm32::can::bxcan::filter::Mask32; use embassy_stm32::can::bxcan::filter::Mask32;
use embassy_stm32::can::bxcan::{Fifo, Frame, StandardId, Id}; use embassy_stm32::can::bxcan::{Fifo, Frame, Id, StandardId};
use embassy_stm32::can::{Can, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler}; use embassy_stm32::can::{Can, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler};
use embassy_stm32::Config;
use embassy_stm32::peripherals::CAN; use embassy_stm32::peripherals::CAN;
use embassy_stm32::{bind_interrupts, Config};
use {defmt_rtt as _, panic_probe as _}; use {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs { bind_interrupts!(struct Irqs {
@ -23,10 +22,8 @@ bind_interrupts!(struct Irqs {
// This example is configured to work with real CAN transceivers on B8/B9. // This example is configured to work with real CAN transceivers on B8/B9.
// See other examples for loopback. // See other examples for loopback.
#[embassy_executor::main] #[embassy_executor::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Config::default()); let p = embassy_stm32::init(Config::default());
// Set alternate pin mapping to B8/B9 // Set alternate pin mapping to B8/B9
@ -34,7 +31,6 @@ async fn main(_spawner: Spawner) {
let mut can = Can::new(p.CAN, p.PB8, p.PB9, Irqs); let mut can = Can::new(p.CAN, p.PB8, p.PB9, Irqs);
can.as_mut() can.as_mut()
.modify_filters() .modify_filters()
.enable_bank(0, Fifo::Fifo0, Mask32::accept_all()); .enable_bank(0, Fifo::Fifo0, Mask32::accept_all());
@ -44,34 +40,27 @@ async fn main(_spawner: Spawner) {
.set_loopback(false) .set_loopback(false)
.set_silent(false) .set_silent(false)
.leave_disabled(); .leave_disabled();
can.set_bitrate(250_000); can.set_bitrate(250_000);
can.enable().await; can.enable().await;
let mut i: u8 = 0; let mut i: u8 = 0;
loop { loop {
let tx_frame = Frame::new_data(unwrap!(StandardId::new(i as _)), [i]); let tx_frame = Frame::new_data(unwrap!(StandardId::new(i as _)), [i]);
can.write(&tx_frame).await; can.write(&tx_frame).await;
match can.read().await { match can.read().await {
Ok(env) => { Ok(env) => match env.frame.id() {
Id::Extended(id) => {
match env.frame.id() { defmt::println!("Extended Frame id={:x}", id.as_raw());
Id::Extended(id) => { }
defmt::println!("Extended Frame id={:x}", id.as_raw()); Id::Standard(id) => {
}, defmt::println!("Standard Frame id={:x}", id.as_raw());
Id::Standard(id) => {
defmt::println!("Standard Frame id={:x}", id.as_raw());
},
} }
}, },
Err(err) => { Err(err) => {
defmt::println!("Error {}", err); defmt::println!("Error {}", err);
} }
} }
i += 1; i += 1;