From af15b49bfe30d82b7fcb17511d7e1830b2216f03 Mon Sep 17 00:00:00 2001 From: Philipp Scheff Date: Mon, 3 Jul 2023 22:57:33 +0200 Subject: [PATCH] fmt --- embassy-stm32/src/can/bxcan.rs | 31 +++++++++++++++++-------------- examples/stm32f7/src/bin/can.rs | 16 ++++++++++------ 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index 4afbb5687..260f567b4 100644 --- a/embassy-stm32/src/can/bxcan.rs +++ b/embassy-stm32/src/can/bxcan.rs @@ -1,9 +1,8 @@ +use core::cell::{RefCell, RefMut}; use core::future::poll_fn; use core::marker::PhantomData; use core::ops::{Deref, DerefMut}; use core::task::Poll; -use core::cell::RefMut; -use core::cell::RefCell; pub use bxcan; use bxcan::{Data, ExtendedId, Frame, Id, StandardId}; @@ -155,7 +154,11 @@ impl<'d, T: Instance> Can<'d, T> { pub fn set_bitrate(&mut self, bitrate: u32) { let bit_timing = Self::calc_bxcan_timings(T::frequency(), bitrate).unwrap(); - self.can.borrow_mut().modify_config().set_bit_timing(bit_timing).leave_disabled(); + self.can + .borrow_mut() + .modify_config() + .set_bit_timing(bit_timing) + .leave_disabled(); } /// Queues the message to be sent but exerts backpressure @@ -432,19 +435,19 @@ impl<'d, T: Instance> Drop for Can<'d, T> { } } -// impl<'d, T: Instance> Deref for Can<'d, T> { -// type Target = bxcan::Can>; +impl<'d, T: Instance> Deref for Can<'d, T> { + type Target = RefCell>>; -// fn deref(&self) -> &Self::Target { -// self.can.borrow() -// } -// } + fn deref(&self) -> &Self::Target { + &self.can + } +} -// impl<'d, T: Instance> DerefMut for Can<'d, T> { -// fn deref_mut(&mut self) -> &mut Self::Target { -// self.can.borrow_mut() -// } -// } +impl<'d, T: Instance> DerefMut for Can<'d, T> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.can + } +} pub(crate) mod sealed { use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; diff --git a/examples/stm32f7/src/bin/can.rs b/examples/stm32f7/src/bin/can.rs index d821039c2..65af9845e 100644 --- a/examples/stm32f7/src/bin/can.rs +++ b/examples/stm32f7/src/bin/can.rs @@ -2,15 +2,17 @@ #![no_main] #![feature(type_alias_impl_trait)] -use core::borrow::BorrowMut; -use core::borrow::Borrow; +use core::borrow::{Borrow, BorrowMut}; + use cortex_m_rt::entry; 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, Data}; -use embassy_stm32::can::{Can,CanTx,CanRx, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler}; +use embassy_stm32::can::bxcan::{Data, Fifo, Frame, StandardId}; +use embassy_stm32::can::{ + Can, CanRx, CanTx, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler, +}; use embassy_stm32::gpio::{Input, Pull}; use embassy_stm32::peripherals::CAN3; use {defmt_rtt as _, panic_probe as _}; @@ -44,8 +46,10 @@ async fn main(spawner: Spawner) { let rx_pin = Input::new(&mut p.PA15, Pull::Up); core::mem::forget(rx_pin); - let CAN: &'static mut Can<'static,CAN3> = static_cell::make_static!(Can::new(p.CAN3, p.PA8, p.PA15, Irqs)); - CAN.as_mut().modify_filters().enable_bank(0, Fifo::Fifo0, Mask32::accept_all()); + let CAN: &'static mut Can<'static, CAN3> = static_cell::make_static!(Can::new(p.CAN3, p.PA8, p.PA15, Irqs)); + CAN.as_mut() + .modify_filters() + .enable_bank(0, Fifo::Fifo0, Mask32::accept_all()); CAN.as_mut() .modify_config()