From 3086b23eb4848d825b2406ff7cde37aa4d21aef9 Mon Sep 17 00:00:00 2001 From: thalesfragoso Date: Mon, 6 Apr 2020 16:33:24 -0300 Subject: [PATCH] Revert back to StableDeref --- Cargo.toml | 4 ++++ examples/rtfm_frame_serial_dma.rs | 9 ++++++--- src/dma.rs | 26 ++++++++++++++------------ src/serial.rs | 9 +++++---- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a2fbc87d..fda23279 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,10 @@ default-features = false version = "1.0.2" default-features = false +[dependencies.stable_deref_trait] +default-features = false +version = "1.1" + [dependencies.embedded-hal] version = "0.2.3" features = ["unproven"] diff --git a/examples/rtfm_frame_serial_dma.rs b/examples/rtfm_frame_serial_dma.rs index bfbb597f..21781e8c 100644 --- a/examples/rtfm_frame_serial_dma.rs +++ b/examples/rtfm_frame_serial_dma.rs @@ -8,9 +8,8 @@ #![no_main] #![no_std] -use panic_halt as _; use hal::{ - dma::{self, consts, FrameReader, FrameSender, DMAFrame}, + dma::{self, consts, DMAFrame, FrameReader, FrameSender}, prelude::*, rcc::{ClockSecuritySystem, CrystalBypass, MsiFreq}, serial::{self, Config, Serial}, @@ -19,11 +18,15 @@ use heapless::{ pool, pool::singleton::{Box, Pool}, }; +use panic_halt as _; use rtfm::app; use stm32l4xx_hal as hal; // The pool gives out `Box`s that can hold 8 bytes -pool!(SerialDMAPool: DMAFrame); +pool!( + #[allow(non_upper_case_globals)] + SerialDMAPool: DMAFrame +); #[app(device = stm32l4xx_hal::stm32, peripherals = true)] const APP: () = { diff --git a/src/dma.rs b/src/dma.rs index 86f3f7ed..053588c3 100644 --- a/src/dma.rs +++ b/src/dma.rs @@ -13,6 +13,7 @@ use crate::rcc::AHB1; use as_slice::AsSlice; pub use generic_array::typenum::consts; use generic_array::{ArrayLength, GenericArray}; +use stable_deref_trait::StableDeref; #[derive(Debug)] pub enum Error { @@ -36,7 +37,7 @@ pub enum Half { /// Frame reader "worker", access and handling of frame reads is made through this structure. pub struct FrameReader where - BUFFER: Sized + Deref> + DerefMut + 'static, + BUFFER: Sized + StableDeref> + DerefMut + 'static, N: ArrayLength>, { buffer: BUFFER, @@ -47,7 +48,7 @@ where impl FrameReader where - BUFFER: Sized + Deref> + DerefMut + 'static, + BUFFER: Sized + StableDeref> + DerefMut + 'static, N: ArrayLength>, { pub(crate) fn new( @@ -68,7 +69,7 @@ where /// structure. pub struct FrameSender where - BUFFER: Sized + Deref> + DerefMut + 'static, + BUFFER: Sized + StableDeref> + DerefMut + 'static, N: ArrayLength>, { buffer: Option, @@ -78,7 +79,7 @@ where impl FrameSender where - BUFFER: Sized + Deref> + DerefMut + 'static, + BUFFER: Sized + StableDeref> + DerefMut + 'static, N: ArrayLength>, { pub(crate) fn new(channel: CHANNEL) -> FrameSender { @@ -275,7 +276,7 @@ where impl CircBuffer { pub(crate) fn new(buf: BUFFER, chan: CHANNEL) -> Self where - BUFFER: Deref + 'static, + BUFFER: StableDeref + 'static, { CircBuffer { buffer: buf, @@ -301,7 +302,7 @@ pub struct Transfer { impl Transfer where - BUFFER: Deref + 'static, + BUFFER: StableDeref + 'static, { pub(crate) fn r(buffer: BUFFER, channel: CHANNEL, payload: PAYLOAD) -> Self { Transfer { @@ -315,7 +316,7 @@ where impl Transfer where - BUFFER: Deref + 'static, + BUFFER: StableDeref + 'static, { pub(crate) fn w(buffer: BUFFER, channel: CHANNEL, payload: PAYLOAD) -> Self { Transfer { @@ -368,8 +369,9 @@ macro_rules! dma { use crate::stm32::{$DMAX, dma1}; use core::mem::MaybeUninit; use generic_array::ArrayLength; - use core::ops::{Deref, DerefMut}; + use core::ops::DerefMut; use core::ptr; + use stable_deref_trait::StableDeref; use crate::dma::{CircBuffer, FrameReader, FrameSender, DMAFrame, DmaExt, Error, Event, Half, Transfer, W}; use crate::rcc::AHB1; @@ -491,7 +493,7 @@ macro_rules! dma { impl FrameSender where - BUFFER: Sized + Deref> + DerefMut + 'static, + BUFFER: Sized + StableDeref> + DerefMut + 'static, N: ArrayLength>, { /// This method should be called in the transfer complete interrupt of the @@ -559,7 +561,7 @@ macro_rules! dma { impl FrameReader where - BUFFER: Sized + Deref> + DerefMut + 'static, + BUFFER: Sized + StableDeref> + DerefMut + 'static, N: ArrayLength>, { /// This function should be called from the transfer complete interrupt of @@ -689,7 +691,7 @@ macro_rules! dma { pub fn partial_peek(&mut self, f: F) -> Result where F: FnOnce(&[T], Half) -> Result<(usize, R), ()>, - B: Deref + 'static, + B: StableDeref + 'static, H: AsSlice, { // this inverts expectation and returns the half being _written_ @@ -730,7 +732,7 @@ macro_rules! dma { pub fn peek(&mut self, f: F) -> Result where F: FnOnce(&[T], Half) -> R, - B: Deref + 'static, + B: StableDeref + 'static, H: AsSlice, { let half_being_read = self.readable_half()?; diff --git a/src/serial.rs b/src/serial.rs index 06560722..021d3e38 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -6,10 +6,11 @@ use as_slice::AsMutSlice; use core::fmt; use core::marker::PhantomData; use core::mem::MaybeUninit; -use core::ops::{Deref, DerefMut}; +use core::ops::DerefMut; use core::ptr; use core::sync::atomic::{self, Ordering}; use generic_array::ArrayLength; +use stable_deref_trait::StableDeref; use crate::hal::serial::{self, Write}; use nb; @@ -909,7 +910,7 @@ macro_rules! hal { mut buffer: B, ) -> CircBuffer where - B: Deref + DerefMut + 'static, + B: StableDeref + DerefMut + 'static, H: AsMutSlice { let buf = buffer[0].as_mut_slice(); @@ -957,7 +958,7 @@ macro_rules! hal { buffer: BUFFER, ) -> FrameReader where - BUFFER: Sized + Deref> + DerefMut + 'static, + BUFFER: Sized + StableDeref> + DerefMut + 'static, N: ArrayLength>, { let usart = unsafe{ &(*$USARTX::ptr()) }; @@ -1055,7 +1056,7 @@ macro_rules! hal { mut channel: $tx_chan, ) -> FrameSender where - BUFFER: Sized + Deref> + DerefMut + 'static, + BUFFER: Sized + StableDeref> + DerefMut + 'static, N: ArrayLength>, { let usart = unsafe{ &(*$USARTX::ptr()) };