Fix examples and improve imports required.

This commit is contained in:
Corey Schuhen 2024-03-05 20:51:05 +10:00
parent a9ff38003b
commit 65b38cf755
4 changed files with 24 additions and 15 deletions

View File

@ -6,7 +6,7 @@ use core::task::Poll;
pub mod bx;
use bx::{Data, ExtendedId, Frame, Id, StandardId};
pub use bx::{filter, Data, ExtendedId, Fifo, Frame, Id, StandardId};
use embassy_hal_internal::{into_ref, PeripheralRef};
use futures::FutureExt;

View File

@ -3,9 +3,10 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::can::bx::filter::Mask32;
use embassy_stm32::can::bx::{Fifo, Frame, Id, StandardId};
use embassy_stm32::can::{Can, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler};
use embassy_stm32::can::{
filter, Can, Fifo, Frame, Id, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, StandardId,
TxInterruptHandler,
};
use embassy_stm32::peripherals::CAN;
use embassy_stm32::{bind_interrupts, Config};
use {defmt_rtt as _, panic_probe as _};
@ -31,7 +32,7 @@ async fn main(_spawner: Spawner) {
can.as_mut()
.modify_filters()
.enable_bank(0, Fifo::Fifo0, Mask32::accept_all());
.enable_bank(0, Fifo::Fifo0, filter::Mask32::accept_all());
can.as_mut()
.modify_config()

View File

@ -4,9 +4,10 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::bind_interrupts;
use embassy_stm32::can::bxcan::filter::Mask32;
use embassy_stm32::can::bxcan::{Fifo, Frame, StandardId};
use embassy_stm32::can::{Can, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler};
use embassy_stm32::can::filter::Mask32;
use embassy_stm32::can::{
Can, Fifo, Frame, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, StandardId, TxInterruptHandler,
};
use embassy_stm32::gpio::{Input, Pull};
use embassy_stm32::peripherals::CAN1;
use embassy_time::Instant;

View File

@ -1,16 +1,18 @@
#![no_std]
#![no_main]
use core::num::{NonZeroU16, NonZeroU8};
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::bind_interrupts;
use embassy_stm32::can::bxcan::filter::Mask32;
use embassy_stm32::can::bxcan::{Fifo, Frame, StandardId};
use embassy_stm32::can::filter::Mask32;
use embassy_stm32::can::{
Can, CanTx, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler,
Can, CanTx, Fifo, Frame, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, StandardId,
TxInterruptHandler,
};
use embassy_stm32::gpio::{Input, Pull};
use embassy_stm32::peripherals::CAN3;
use embassy_stm32::{bind_interrupts, can};
use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
@ -22,7 +24,7 @@ bind_interrupts!(struct Irqs {
});
#[embassy_executor::task]
pub async fn send_can_message(tx: &'static mut CanTx<'static, 'static, CAN3>) {
pub async fn send_can_message(tx: &'static mut CanTx<'static, CAN3>) {
loop {
let frame = Frame::new_data(unwrap!(StandardId::new(0 as _)), [0]);
tx.write(&frame).await;
@ -51,13 +53,18 @@ async fn main(spawner: Spawner) {
can.as_mut()
.modify_config()
.set_bit_timing(0x001c0001) // http://www.bittiming.can-wiki.info/
.set_bit_timing(can::util::NominalBitTiming {
prescaler: NonZeroU16::new(2).unwrap(),
seg1: NonZeroU8::new(13).unwrap(),
seg2: NonZeroU8::new(2).unwrap(),
sync_jump_width: NonZeroU8::new(1).unwrap(),
}) // http://www.bittiming.can-wiki.info/
.set_loopback(true)
.enable();
let (tx, mut rx) = can.split();
static CAN_TX: StaticCell<CanTx<'static, 'static, CAN3>> = StaticCell::new();
static CAN_TX: StaticCell<CanTx<'static, CAN3>> = StaticCell::new();
let tx = CAN_TX.init(tx);
spawner.spawn(send_can_message(tx)).unwrap();