diff options
| author | Thales Fragoso <[email protected]> | 2021-02-13 21:41:36 -0300 |
|---|---|---|
| committer | Thales Fragoso <[email protected]> | 2021-02-13 21:41:36 -0300 |
| commit | b69f72e055cb741a7f599832792933acc00f5fdf (patch) | |
| tree | f8066e2835a4cce320d2f62a9751901b2931b461 | |
| parent | a7797a918d3a42f9244a853d2a47aced0ceb900a (diff) | |
Get rid of some warnings
40 files changed, 182 insertions, 216 deletions
diff --git a/embassy-macros/src/lib.rs b/embassy-macros/src/lib.rs index 23f1cda99..0708b17ef 100644 --- a/embassy-macros/src/lib.rs +++ b/embassy-macros/src/lib.rs | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | extern crate proc_macro; | 3 | extern crate proc_macro; |
| 4 | 4 | ||
| 5 | use darling::FromMeta; | 5 | use darling::FromMeta; |
| 6 | use proc_macro::{Diagnostic, Level, Span, TokenStream}; | 6 | use proc_macro::{Span, TokenStream}; |
| 7 | use quote::{format_ident, quote}; | 7 | use quote::{format_ident, quote}; |
| 8 | use syn::spanned::Spanned; | 8 | use syn::spanned::Spanned; |
| 9 | 9 | ||
| @@ -39,7 +39,7 @@ pub fn task(args: TokenStream, item: TokenStream) -> TokenStream { | |||
| 39 | .emit(); | 39 | .emit(); |
| 40 | fail = true; | 40 | fail = true; |
| 41 | } | 41 | } |
| 42 | if task_fn.sig.generics.params.len() != 0 { | 42 | if !task_fn.sig.generics.params.is_empty() { |
| 43 | task_fn | 43 | task_fn |
| 44 | .sig | 44 | .sig |
| 45 | .span() | 45 | .span() |
diff --git a/embassy-nrf-examples/src/bin/buffered_uart.rs b/embassy-nrf-examples/src/bin/buffered_uart.rs index 7c7283fc2..84bc742f3 100644 --- a/embassy-nrf-examples/src/bin/buffered_uart.rs +++ b/embassy-nrf-examples/src/bin/buffered_uart.rs | |||
| @@ -66,9 +66,7 @@ async fn run() { | |||
| 66 | 66 | ||
| 67 | // Reverse buf | 67 | // Reverse buf |
| 68 | for i in 0..4 { | 68 | for i in 0..4 { |
| 69 | let tmp = buf[i]; | 69 | buf.swap(i, 7 - i); |
| 70 | buf[i] = buf[7 - i]; | ||
| 71 | buf[7 - i] = tmp; | ||
| 72 | } | 70 | } |
| 73 | 71 | ||
| 74 | info!("writing..."); | 72 | info!("writing..."); |
diff --git a/embassy-nrf-examples/src/bin/gpiote_channel.rs b/embassy-nrf-examples/src/bin/gpiote_channel.rs index 5470c47cd..4c4dabc6d 100644 --- a/embassy-nrf-examples/src/bin/gpiote_channel.rs +++ b/embassy-nrf-examples/src/bin/gpiote_channel.rs | |||
| @@ -12,7 +12,7 @@ use nrf52840_hal::gpio; | |||
| 12 | 12 | ||
| 13 | use embassy::executor::{task, Executor}; | 13 | use embassy::executor::{task, Executor}; |
| 14 | use embassy::util::Forever; | 14 | use embassy::util::Forever; |
| 15 | use embassy_nrf::gpiote::{Channels, Gpiote, InputChannel, InputChannelPolarity}; | 15 | use embassy_nrf::gpiote::{Gpiote, InputChannel, InputChannelPolarity}; |
| 16 | use embassy_nrf::interrupt; | 16 | use embassy_nrf::interrupt; |
| 17 | 17 | ||
| 18 | #[task] | 18 | #[task] |
diff --git a/embassy-nrf-examples/src/bin/gpiote_port.rs b/embassy-nrf-examples/src/bin/gpiote_port.rs index 9d999f951..0f1637faf 100644 --- a/embassy-nrf-examples/src/bin/gpiote_port.rs +++ b/embassy-nrf-examples/src/bin/gpiote_port.rs | |||
| @@ -6,7 +6,6 @@ | |||
| 6 | mod example_common; | 6 | mod example_common; |
| 7 | use example_common::*; | 7 | use example_common::*; |
| 8 | 8 | ||
| 9 | use core::mem; | ||
| 10 | use core::pin::Pin; | 9 | use core::pin::Pin; |
| 11 | use cortex_m_rt::entry; | 10 | use cortex_m_rt::entry; |
| 12 | use defmt::panic; | 11 | use defmt::panic; |
diff --git a/embassy-nrf-examples/src/bin/multiprio.rs b/embassy-nrf-examples/src/bin/multiprio.rs index 8c2ec19af..89c285fa5 100644 --- a/embassy-nrf-examples/src/bin/multiprio.rs +++ b/embassy-nrf-examples/src/bin/multiprio.rs | |||
| @@ -61,7 +61,6 @@ | |||
| 61 | mod example_common; | 61 | mod example_common; |
| 62 | use example_common::*; | 62 | use example_common::*; |
| 63 | 63 | ||
| 64 | use cortex_m::peripheral::NVIC; | ||
| 65 | use cortex_m_rt::entry; | 64 | use cortex_m_rt::entry; |
| 66 | use defmt::panic; | 65 | use defmt::panic; |
| 67 | use nrf52840_hal::clocks; | 66 | use nrf52840_hal::clocks; |
diff --git a/embassy-nrf-examples/src/bin/qspi.rs b/embassy-nrf-examples/src/bin/qspi.rs index 4edbd3f91..39326fa00 100644 --- a/embassy-nrf-examples/src/bin/qspi.rs +++ b/embassy-nrf-examples/src/bin/qspi.rs | |||
| @@ -7,7 +7,7 @@ mod example_common; | |||
| 7 | use example_common::*; | 7 | use example_common::*; |
| 8 | 8 | ||
| 9 | use cortex_m_rt::entry; | 9 | use cortex_m_rt::entry; |
| 10 | use defmt::{assert_eq, panic, *}; | 10 | use defmt::{assert_eq, panic}; |
| 11 | use nrf52840_hal::gpio; | 11 | use nrf52840_hal::gpio; |
| 12 | 12 | ||
| 13 | use embassy::executor::{task, Executor}; | 13 | use embassy::executor::{task, Executor}; |
diff --git a/embassy-nrf-examples/src/bin/rtc_async.rs b/embassy-nrf-examples/src/bin/rtc_async.rs index 5260c69a8..5fb68633e 100644 --- a/embassy-nrf-examples/src/bin/rtc_async.rs +++ b/embassy-nrf-examples/src/bin/rtc_async.rs | |||
| @@ -6,11 +6,10 @@ | |||
| 6 | mod example_common; | 6 | mod example_common; |
| 7 | use example_common::*; | 7 | use example_common::*; |
| 8 | 8 | ||
| 9 | use core::mem::MaybeUninit; | ||
| 10 | use cortex_m_rt::entry; | 9 | use cortex_m_rt::entry; |
| 11 | use defmt::panic; | 10 | use defmt::panic; |
| 12 | use embassy::executor::{task, Executor}; | 11 | use embassy::executor::{task, Executor}; |
| 13 | use embassy::time::{Clock, Duration, Timer}; | 12 | use embassy::time::{Duration, Timer}; |
| 14 | use embassy::util::Forever; | 13 | use embassy::util::Forever; |
| 15 | use embassy_nrf::pac; | 14 | use embassy_nrf::pac; |
| 16 | use embassy_nrf::{interrupt, rtc}; | 15 | use embassy_nrf::{interrupt, rtc}; |
diff --git a/embassy-nrf-examples/src/bin/uart.rs b/embassy-nrf-examples/src/bin/uart.rs index c5468d32b..8b540fca9 100644 --- a/embassy-nrf-examples/src/bin/uart.rs +++ b/embassy-nrf-examples/src/bin/uart.rs | |||
| @@ -75,7 +75,7 @@ async fn run(uart: pac::UARTE0, port: pac::P0) { | |||
| 75 | }; | 75 | }; |
| 76 | let received = &mut buf[..received_len]; | 76 | let received = &mut buf[..received_len]; |
| 77 | 77 | ||
| 78 | if received.len() > 0 { | 78 | if !received.is_empty() { |
| 79 | info!("read done, got {:[u8]}", received); | 79 | info!("read done, got {:[u8]}", received); |
| 80 | 80 | ||
| 81 | // Echo back received data | 81 | // Echo back received data |
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index c61d111f0..d1908cf09 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs | |||
| @@ -20,10 +20,7 @@ use crate::interrupt::{self, OwnedInterrupt}; | |||
| 20 | use crate::pac; | 20 | use crate::pac; |
| 21 | use crate::util::peripheral::{PeripheralMutex, PeripheralState}; | 21 | use crate::util::peripheral::{PeripheralMutex, PeripheralState}; |
| 22 | use crate::util::ring_buffer::RingBuffer; | 22 | use crate::util::ring_buffer::RingBuffer; |
| 23 | use crate::{ | 23 | use crate::{fmt::*, util::low_power_wait_until}; |
| 24 | fmt::{panic, todo, *}, | ||
| 25 | util::low_power_wait_until, | ||
| 26 | }; | ||
| 27 | 24 | ||
| 28 | // Re-export SVD variants to allow user to directly set values | 25 | // Re-export SVD variants to allow user to directly set values |
| 29 | pub use crate::hal::uarte::Pins; | 26 | pub use crate::hal::uarte::Pins; |
| @@ -257,7 +254,7 @@ impl<'a, U: Instance, T: TimerInstance, P1: ConfigurablePpi, P2: ConfigurablePpi | |||
| 257 | 254 | ||
| 258 | // We have data ready in buffer? Return it. | 255 | // We have data ready in buffer? Return it. |
| 259 | let buf = state.rx.pop_buf(); | 256 | let buf = state.rx.pop_buf(); |
| 260 | if buf.len() != 0 { | 257 | if !buf.is_empty() { |
| 261 | trace!(" got {:?} {:?}", buf.as_ptr() as u32, buf.len()); | 258 | trace!(" got {:?} {:?}", buf.as_ptr() as u32, buf.len()); |
| 262 | let buf: &[u8] = buf; | 259 | let buf: &[u8] = buf; |
| 263 | let buf: &[u8] = unsafe { mem::transmute(buf) }; | 260 | let buf: &[u8] = unsafe { mem::transmute(buf) }; |
| @@ -287,7 +284,7 @@ impl<'a, U: Instance, T: TimerInstance, P1: ConfigurablePpi, P2: ConfigurablePpi | |||
| 287 | trace!("poll_write: {:?}", buf.len()); | 284 | trace!("poll_write: {:?}", buf.len()); |
| 288 | 285 | ||
| 289 | let tx_buf = state.tx.push_buf(); | 286 | let tx_buf = state.tx.push_buf(); |
| 290 | if tx_buf.len() == 0 { | 287 | if tx_buf.is_empty() { |
| 291 | trace!("poll_write: pending"); | 288 | trace!("poll_write: pending"); |
| 292 | state.tx_waker.register(cx.waker()); | 289 | state.tx_waker.register(cx.waker()); |
| 293 | return Poll::Pending; | 290 | return Poll::Pending; |
| @@ -343,7 +340,7 @@ impl<'a, U: Instance, T: TimerInstance, P1: ConfigurablePpi, P2: ConfigurablePpi | |||
| 343 | trace!(" irq_rx: in state idle"); | 340 | trace!(" irq_rx: in state idle"); |
| 344 | 341 | ||
| 345 | let buf = self.rx.push_buf(); | 342 | let buf = self.rx.push_buf(); |
| 346 | if buf.len() != 0 { | 343 | if !buf.is_empty() { |
| 347 | trace!(" irq_rx: starting {:?}", buf.len()); | 344 | trace!(" irq_rx: starting {:?}", buf.len()); |
| 348 | self.rx_state = RxState::Receiving; | 345 | self.rx_state = RxState::Receiving; |
| 349 | 346 | ||
| @@ -394,7 +391,7 @@ impl<'a, U: Instance, T: TimerInstance, P1: ConfigurablePpi, P2: ConfigurablePpi | |||
| 394 | TxState::Idle => { | 391 | TxState::Idle => { |
| 395 | trace!(" irq_tx: in state Idle"); | 392 | trace!(" irq_tx: in state Idle"); |
| 396 | let buf = self.tx.pop_buf(); | 393 | let buf = self.tx.pop_buf(); |
| 397 | if buf.len() != 0 { | 394 | if !buf.is_empty() { |
| 398 | trace!(" irq_tx: starting {:?}", buf.len()); | 395 | trace!(" irq_tx: starting {:?}", buf.len()); |
| 399 | self.tx_state = TxState::Transmitting(buf.len()); | 396 | self.tx_state = TxState::Transmitting(buf.len()); |
| 400 | 397 | ||
diff --git a/embassy-nrf/src/fmt.rs b/embassy-nrf/src/fmt.rs index 4da69766c..1be1057a7 100644 --- a/embassy-nrf/src/fmt.rs +++ b/embassy-nrf/src/fmt.rs | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | #![allow(clippy::module_inception)] | ||
| 2 | 3 | ||
| 3 | #[cfg(all(feature = "defmt", feature = "log"))] | 4 | #[cfg(all(feature = "defmt", feature = "log"))] |
| 4 | compile_error!("You may not enable both `defmt` and `log` features."); | 5 | compile_error!("You may not enable both `defmt` and `log` features."); |
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index 89aab5bc6..0e48a7164 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs | |||
| @@ -7,7 +7,6 @@ use core::task::{Context, Poll}; | |||
| 7 | use embassy::gpio::{WaitForHigh, WaitForLow}; | 7 | use embassy::gpio::{WaitForHigh, WaitForLow}; |
| 8 | use embassy::util::Signal; | 8 | use embassy::util::Signal; |
| 9 | 9 | ||
| 10 | use crate::fmt::{panic, *}; | ||
| 11 | use crate::hal::gpio::{Input, Level, Output, Pin as GpioPin, Port}; | 10 | use crate::hal::gpio::{Input, Level, Output, Pin as GpioPin, Port}; |
| 12 | use crate::interrupt; | 11 | use crate::interrupt; |
| 13 | use crate::interrupt::OwnedInterrupt; | 12 | use crate::interrupt::OwnedInterrupt; |
| @@ -141,10 +140,10 @@ impl Gpiote { | |||
| 141 | unsafe fn on_irq(_ctx: *mut ()) { | 140 | unsafe fn on_irq(_ctx: *mut ()) { |
| 142 | let g = &*GPIOTE::ptr(); | 141 | let g = &*GPIOTE::ptr(); |
| 143 | 142 | ||
| 144 | for i in 0..8 { | 143 | for (event_in, signal) in g.events_in.iter().zip(CHANNEL_SIGNALS.iter()) { |
| 145 | if g.events_in[i].read().bits() != 0 { | 144 | if event_in.read().bits() != 0 { |
| 146 | g.events_in[i].write(|w| w); | 145 | event_in.write(|w| w); |
| 147 | CHANNEL_SIGNALS[i].signal(()); | 146 | signal.signal(()); |
| 148 | } | 147 | } |
| 149 | } | 148 | } |
| 150 | 149 | ||
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs index 753a5985b..a93b5e891 100644 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | use crate::fmt::{assert, assert_eq, panic, *}; | 1 | use crate::fmt::{assert, assert_eq, *}; |
| 2 | use core::future::Future; | 2 | use core::future::Future; |
| 3 | 3 | ||
| 4 | use crate::hal::gpio::{Output, Pin as GpioPin, Port as GpioPort, PushPull}; | 4 | use crate::hal::gpio::{Output, Pin as GpioPin, Port as GpioPort, PushPull}; |
| 5 | use crate::interrupt::{OwnedInterrupt, QSPIInterrupt}; | 5 | use crate::interrupt::{OwnedInterrupt, QSPIInterrupt}; |
| 6 | use crate::pac::{Interrupt, QSPI}; | 6 | use crate::pac::QSPI; |
| 7 | 7 | ||
| 8 | pub use crate::pac::qspi::ifconfig0::ADDRMODE_A as AddressMode; | 8 | pub use crate::pac::qspi::ifconfig0::ADDRMODE_A as AddressMode; |
| 9 | pub use crate::pac::qspi::ifconfig0::PPSIZE_A as WritePageSize; | 9 | pub use crate::pac::qspi::ifconfig0::PPSIZE_A as WritePageSize; |
| @@ -156,7 +156,7 @@ impl Qspi { | |||
| 156 | pub fn sleep(&mut self) { | 156 | pub fn sleep(&mut self) { |
| 157 | info!("flash: sleeping"); | 157 | info!("flash: sleeping"); |
| 158 | info!("flash: state = {:?}", self.inner.status.read().bits()); | 158 | info!("flash: state = {:?}", self.inner.status.read().bits()); |
| 159 | self.inner.ifconfig1.modify(|r, w| w.dpmen().enter()); | 159 | self.inner.ifconfig1.modify(|_, w| w.dpmen().enter()); |
| 160 | info!("flash: state = {:?}", self.inner.status.read().bits()); | 160 | info!("flash: state = {:?}", self.inner.status.read().bits()); |
| 161 | cortex_m::asm::delay(1000000); | 161 | cortex_m::asm::delay(1000000); |
| 162 | info!("flash: state = {:?}", self.inner.status.read().bits()); | 162 | info!("flash: state = {:?}", self.inner.status.read().bits()); |
| @@ -166,68 +166,66 @@ impl Qspi { | |||
| 166 | .write(|w| w.tasks_deactivate().set_bit()); | 166 | .write(|w| w.tasks_deactivate().set_bit()); |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | pub fn custom_instruction<'a>( | 169 | pub async fn custom_instruction<'a>( |
| 170 | &'a mut self, | 170 | &'a mut self, |
| 171 | opcode: u8, | 171 | opcode: u8, |
| 172 | req: &'a [u8], | 172 | req: &'a [u8], |
| 173 | resp: &'a mut [u8], | 173 | resp: &'a mut [u8], |
| 174 | ) -> impl Future<Output = Result<(), Error>> + 'a { | 174 | ) -> Result<(), Error> { |
| 175 | async move { | 175 | let bomb = DropBomb::new(); |
| 176 | let bomb = DropBomb::new(); | ||
| 177 | 176 | ||
| 178 | assert!(req.len() <= 8); | 177 | assert!(req.len() <= 8); |
| 179 | assert!(resp.len() <= 8); | 178 | assert!(resp.len() <= 8); |
| 180 | 179 | ||
| 181 | let mut dat0: u32 = 0; | 180 | let mut dat0: u32 = 0; |
| 182 | let mut dat1: u32 = 0; | 181 | let mut dat1: u32 = 0; |
| 183 | 182 | ||
| 184 | for i in 0..4 { | 183 | for i in 0..4 { |
| 185 | if i < req.len() { | 184 | if i < req.len() { |
| 186 | dat0 |= (req[i] as u32) << (i * 8); | 185 | dat0 |= (req[i] as u32) << (i * 8); |
| 187 | } | ||
| 188 | } | 186 | } |
| 189 | for i in 0..4 { | 187 | } |
| 190 | if i + 4 < req.len() { | 188 | for i in 0..4 { |
| 191 | dat1 |= (req[i + 4] as u32) << (i * 8); | 189 | if i + 4 < req.len() { |
| 192 | } | 190 | dat1 |= (req[i + 4] as u32) << (i * 8); |
| 193 | } | 191 | } |
| 192 | } | ||
| 194 | 193 | ||
| 195 | let len = core::cmp::max(req.len(), resp.len()) as u8; | 194 | let len = core::cmp::max(req.len(), resp.len()) as u8; |
| 196 | 195 | ||
| 197 | self.inner.cinstrdat0.write(|w| unsafe { w.bits(dat0) }); | 196 | self.inner.cinstrdat0.write(|w| unsafe { w.bits(dat0) }); |
| 198 | self.inner.cinstrdat1.write(|w| unsafe { w.bits(dat1) }); | 197 | self.inner.cinstrdat1.write(|w| unsafe { w.bits(dat1) }); |
| 199 | self.inner.events_ready.reset(); | 198 | self.inner.events_ready.reset(); |
| 200 | self.inner.cinstrconf.write(|w| { | 199 | self.inner.cinstrconf.write(|w| { |
| 201 | let w = unsafe { w.opcode().bits(opcode) }; | 200 | let w = unsafe { w.opcode().bits(opcode) }; |
| 202 | let w = unsafe { w.length().bits(len + 1) }; | 201 | let w = unsafe { w.length().bits(len + 1) }; |
| 203 | let w = w.lio2().bit(true); | 202 | let w = w.lio2().bit(true); |
| 204 | let w = w.lio3().bit(true); | 203 | let w = w.lio3().bit(true); |
| 205 | let w = w.wipwait().bit(true); | 204 | let w = w.wipwait().bit(true); |
| 206 | let w = w.wren().bit(true); | 205 | let w = w.wren().bit(true); |
| 207 | let w = w.lfen().bit(false); | 206 | let w = w.lfen().bit(false); |
| 208 | let w = w.lfstop().bit(false); | 207 | let w = w.lfstop().bit(false); |
| 209 | w | 208 | w |
| 210 | }); | 209 | }); |
| 211 | 210 | ||
| 212 | SIGNAL.wait().await; | 211 | SIGNAL.wait().await; |
| 213 | 212 | ||
| 214 | let dat0 = self.inner.cinstrdat0.read().bits(); | 213 | let dat0 = self.inner.cinstrdat0.read().bits(); |
| 215 | let dat1 = self.inner.cinstrdat1.read().bits(); | 214 | let dat1 = self.inner.cinstrdat1.read().bits(); |
| 216 | for i in 0..4 { | 215 | for i in 0..4 { |
| 217 | if i < resp.len() { | 216 | if i < resp.len() { |
| 218 | resp[i] = (dat0 >> (i * 8)) as u8; | 217 | resp[i] = (dat0 >> (i * 8)) as u8; |
| 219 | } | ||
| 220 | } | 218 | } |
| 221 | for i in 0..4 { | 219 | } |
| 222 | if i + 4 < resp.len() { | 220 | for i in 0..4 { |
| 223 | resp[i] = (dat1 >> (i * 8)) as u8; | 221 | if i + 4 < resp.len() { |
| 224 | } | 222 | resp[i] = (dat1 >> (i * 8)) as u8; |
| 225 | } | 223 | } |
| 224 | } | ||
| 226 | 225 | ||
| 227 | bomb.defuse(); | 226 | bomb.defuse(); |
| 228 | 227 | ||
| 229 | Ok(()) | 228 | Ok(()) |
| 230 | } | ||
| 231 | } | 229 | } |
| 232 | } | 230 | } |
| 233 | 231 | ||
diff --git a/embassy-nrf/src/rtc.rs b/embassy-nrf/src/rtc.rs index dde0fd4ca..616254025 100644 --- a/embassy-nrf/src/rtc.rs +++ b/embassy-nrf/src/rtc.rs | |||
| @@ -4,7 +4,6 @@ use core::sync::atomic::{AtomicU32, Ordering}; | |||
| 4 | 4 | ||
| 5 | use embassy::time::Clock; | 5 | use embassy::time::Clock; |
| 6 | 6 | ||
| 7 | use crate::fmt::*; | ||
| 8 | use crate::interrupt; | 7 | use crate::interrupt; |
| 9 | use crate::interrupt::{CriticalSection, Mutex, OwnedInterrupt}; | 8 | use crate::interrupt::{CriticalSection, Mutex, OwnedInterrupt}; |
| 10 | use crate::pac::rtc0; | 9 | use crate::pac::rtc0; |
| @@ -19,6 +18,7 @@ fn compare_n(n: usize) -> u32 { | |||
| 19 | 1 << (n + 16) | 18 | 1 << (n + 16) |
| 20 | } | 19 | } |
| 21 | 20 | ||
| 21 | #[cfg(tests)] | ||
| 22 | mod test { | 22 | mod test { |
| 23 | use super::*; | 23 | use super::*; |
| 24 | 24 | ||
| @@ -159,7 +159,9 @@ impl<T: Instance> RTC<T> { | |||
| 159 | alarm.timestamp.set(u64::MAX); | 159 | alarm.timestamp.set(u64::MAX); |
| 160 | 160 | ||
| 161 | // Call after clearing alarm, so the callback can set another alarm. | 161 | // Call after clearing alarm, so the callback can set another alarm. |
| 162 | alarm.callback.get().map(|(f, ctx)| f(ctx)); | 162 | if let Some((f, ctx)) = alarm.callback.get() { |
| 163 | f(ctx); | ||
| 164 | } | ||
| 163 | } | 165 | } |
| 164 | 166 | ||
| 165 | fn set_alarm_callback(&self, n: usize, callback: fn(*mut ()), ctx: *mut ()) { | 167 | fn set_alarm_callback(&self, n: usize, callback: fn(*mut ()), ctx: *mut ()) { |
diff --git a/embassy-nrf/src/util/peripheral.rs b/embassy-nrf/src/util/peripheral.rs index 1cc04f4ab..fee343d90 100644 --- a/embassy-nrf/src/util/peripheral.rs +++ b/embassy-nrf/src/util/peripheral.rs | |||
| @@ -68,7 +68,7 @@ impl<S: PeripheralState> PeripheralMutex<S> { | |||
| 68 | 68 | ||
| 69 | impl<S: PeripheralState> Drop for PeripheralMutex<S> { | 69 | impl<S: PeripheralState> Drop for PeripheralMutex<S> { |
| 70 | fn drop(&mut self) { | 70 | fn drop(&mut self) { |
| 71 | if let Some((state, irq)) = &mut self.inner { | 71 | if let Some((_state, irq)) = &mut self.inner { |
| 72 | irq.disable(); | 72 | irq.disable(); |
| 73 | irq.remove_handler(); | 73 | irq.remove_handler(); |
| 74 | } | 74 | } |
diff --git a/embassy-nrf/src/util/ring_buffer.rs b/embassy-nrf/src/util/ring_buffer.rs index f395785a5..f2b9f7359 100644 --- a/embassy-nrf/src/util/ring_buffer.rs +++ b/embassy-nrf/src/util/ring_buffer.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | use crate::fmt::{assert, panic, todo, *}; | 1 | use crate::fmt::{assert, *}; |
| 2 | 2 | ||
| 3 | pub struct RingBuffer<'a> { | 3 | pub struct RingBuffer<'a> { |
| 4 | buf: &'a mut [u8], | 4 | buf: &'a mut [u8], |
diff --git a/embassy-std-examples/src/bin/serial.rs b/embassy-std-examples/src/bin/serial.rs index b66b7de20..cad64fb2f 100644 --- a/embassy-std-examples/src/bin/serial.rs +++ b/embassy-std-examples/src/bin/serial.rs | |||
| @@ -5,7 +5,7 @@ mod serial_port; | |||
| 5 | 5 | ||
| 6 | use async_io::Async; | 6 | use async_io::Async; |
| 7 | use embassy::executor::task; | 7 | use embassy::executor::task; |
| 8 | use embassy::io::{AsyncBufRead, AsyncBufReadExt, AsyncWrite, AsyncWriteExt}; | 8 | use embassy::io::AsyncBufReadExt; |
| 9 | use embassy::util::Forever; | 9 | use embassy::util::Forever; |
| 10 | use embassy_std::Executor; | 10 | use embassy_std::Executor; |
| 11 | use log::*; | 11 | use log::*; |
diff --git a/embassy-stm32f4-examples/src/bin/exti.rs b/embassy-stm32f4-examples/src/bin/exti.rs index ec4490b16..79348777d 100644 --- a/embassy-stm32f4-examples/src/bin/exti.rs +++ b/embassy-stm32f4-examples/src/bin/exti.rs | |||
| @@ -7,25 +7,20 @@ | |||
| 7 | mod example_common; | 7 | mod example_common; |
| 8 | use example_common::{panic, *}; | 8 | use example_common::{panic, *}; |
| 9 | 9 | ||
| 10 | use cortex_m::singleton; | ||
| 11 | use cortex_m_rt::entry; | 10 | use cortex_m_rt::entry; |
| 12 | use embassy::executor::{task, Executor}; | 11 | use embassy::executor::{task, Executor}; |
| 13 | use embassy::gpio::*; | 12 | use embassy::gpio::*; |
| 14 | use embassy::util::Forever; | 13 | use embassy::util::Forever; |
| 15 | use embassy_stm32f4::exti; | 14 | use embassy_stm32f4::exti; |
| 16 | use embassy_stm32f4::exti::*; | ||
| 17 | use embassy_stm32f4::interrupt; | 15 | use embassy_stm32f4::interrupt; |
| 18 | use embassy_stm32f4::serial; | ||
| 19 | use futures::pin_mut; | 16 | use futures::pin_mut; |
| 20 | use stm32f4xx_hal::serial::config::Config; | 17 | use stm32f4xx_hal::prelude::*; |
| 21 | use stm32f4xx_hal::stm32; | 18 | use stm32f4xx_hal::stm32; |
| 22 | use stm32f4xx_hal::syscfg; | ||
| 23 | use stm32f4xx_hal::{prelude::*, serial::config}; | ||
| 24 | 19 | ||
| 25 | static EXTI: Forever<exti::ExtiManager> = Forever::new(); | 20 | static EXTI: Forever<exti::ExtiManager> = Forever::new(); |
| 26 | 21 | ||
| 27 | #[task] | 22 | #[task] |
| 28 | async fn run(dp: stm32::Peripherals, cp: cortex_m::Peripherals) { | 23 | async fn run(dp: stm32::Peripherals, _cp: cortex_m::Peripherals) { |
| 29 | let gpioa = dp.GPIOA.split(); | 24 | let gpioa = dp.GPIOA.split(); |
| 30 | 25 | ||
| 31 | let button = gpioa.pa0.into_pull_up_input(); | 26 | let button = gpioa.pa0.into_pull_up_input(); |
diff --git a/embassy-stm32f4-examples/src/bin/hello.rs b/embassy-stm32f4-examples/src/bin/hello.rs index 706501e35..d62378712 100644 --- a/embassy-stm32f4-examples/src/bin/hello.rs +++ b/embassy-stm32f4-examples/src/bin/hello.rs | |||
| @@ -5,18 +5,10 @@ | |||
| 5 | 5 | ||
| 6 | #[path = "../example_common.rs"] | 6 | #[path = "../example_common.rs"] |
| 7 | mod example_common; | 7 | mod example_common; |
| 8 | use example_common::{panic, *}; | 8 | use example_common::*; |
| 9 | 9 | ||
| 10 | use cortex_m::singleton; | ||
| 11 | use cortex_m_rt::entry; | 10 | use cortex_m_rt::entry; |
| 12 | use embassy::executor::{task, Executor}; | 11 | use stm32f4xx_hal::prelude::*; |
| 13 | use embassy::uart::Uart; | ||
| 14 | use embassy::util::Forever; | ||
| 15 | use embassy_stm32f4::interrupt; | ||
| 16 | use embassy_stm32f4::serial; | ||
| 17 | use stm32f4xx_hal::serial::config::Config; | ||
| 18 | use stm32f4xx_hal::stm32; | ||
| 19 | use stm32f4xx_hal::{prelude::*, serial::config}; | ||
| 20 | 12 | ||
| 21 | #[entry] | 13 | #[entry] |
| 22 | fn main() -> ! { | 14 | fn main() -> ! { |
diff --git a/embassy-stm32f4-examples/src/bin/serial.rs b/embassy-stm32f4-examples/src/bin/serial.rs index 7338d4fe0..f8e7f7f48 100644 --- a/embassy-stm32f4-examples/src/bin/serial.rs +++ b/embassy-stm32f4-examples/src/bin/serial.rs | |||
| @@ -14,12 +14,12 @@ use embassy::uart::Uart; | |||
| 14 | use embassy::util::Forever; | 14 | use embassy::util::Forever; |
| 15 | use embassy_stm32f4::interrupt; | 15 | use embassy_stm32f4::interrupt; |
| 16 | use embassy_stm32f4::serial; | 16 | use embassy_stm32f4::serial; |
| 17 | use stm32f4xx_hal::prelude::*; | ||
| 17 | use stm32f4xx_hal::serial::config::Config; | 18 | use stm32f4xx_hal::serial::config::Config; |
| 18 | use stm32f4xx_hal::stm32; | 19 | use stm32f4xx_hal::stm32; |
| 19 | use stm32f4xx_hal::{prelude::*, serial::config}; | ||
| 20 | 20 | ||
| 21 | #[task] | 21 | #[task] |
| 22 | async fn run(dp: stm32::Peripherals, cp: cortex_m::Peripherals) { | 22 | async fn run(dp: stm32::Peripherals, _cp: cortex_m::Peripherals) { |
| 23 | // https://gist.github.com/thalesfragoso/a07340c5df6eee3b04c42fdc69ecdcb1 | 23 | // https://gist.github.com/thalesfragoso/a07340c5df6eee3b04c42fdc69ecdcb1 |
| 24 | let gpioa = dp.GPIOA.split(); | 24 | let gpioa = dp.GPIOA.split(); |
| 25 | let rcc = dp.RCC.constrain(); | 25 | let rcc = dp.RCC.constrain(); |
diff --git a/embassy-stm32f4/src/exti.rs b/embassy-stm32f4/src/exti.rs index 9b722374c..bf9cc582f 100644 --- a/embassy-stm32f4/src/exti.rs +++ b/embassy-stm32f4/src/exti.rs | |||
| @@ -19,7 +19,7 @@ pub struct ExtiManager { | |||
| 19 | 19 | ||
| 20 | impl<'a> ExtiManager { | 20 | impl<'a> ExtiManager { |
| 21 | pub fn new(_exti: EXTI, syscfg: SysCfg) -> Self { | 21 | pub fn new(_exti: EXTI, syscfg: SysCfg) -> Self { |
| 22 | Self { syscfg: syscfg } | 22 | Self { syscfg } |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | pub fn new_pin<T, I>(&'static mut self, mut pin: T, interrupt: I) -> ExtiPin<T, I> | 25 | pub fn new_pin<T, I>(&'static mut self, mut pin: T, interrupt: I) -> ExtiPin<T, I> |
| @@ -30,8 +30,8 @@ impl<'a> ExtiManager { | |||
| 30 | pin.make_interrupt_source(&mut self.syscfg); | 30 | pin.make_interrupt_source(&mut self.syscfg); |
| 31 | 31 | ||
| 32 | ExtiPin { | 32 | ExtiPin { |
| 33 | pin: pin, | 33 | pin, |
| 34 | interrupt: interrupt, | 34 | interrupt, |
| 35 | _mgr: self, | 35 | _mgr: self, |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
diff --git a/embassy-stm32f4/src/fmt.rs b/embassy-stm32f4/src/fmt.rs index 4da69766c..1be1057a7 100644 --- a/embassy-stm32f4/src/fmt.rs +++ b/embassy-stm32f4/src/fmt.rs | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | #![allow(clippy::module_inception)] | ||
| 2 | 3 | ||
| 3 | #[cfg(all(feature = "defmt", feature = "log"))] | 4 | #[cfg(all(feature = "defmt", feature = "log"))] |
| 4 | compile_error!("You may not enable both `defmt` and `log` features."); | 5 | compile_error!("You may not enable both `defmt` and `log` features."); |
diff --git a/embassy-stm32f4/src/lib.rs b/embassy-stm32f4/src/lib.rs index 57b9db965..02668b7eb 100644 --- a/embassy-stm32f4/src/lib.rs +++ b/embassy-stm32f4/src/lib.rs | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | #![feature(generic_associated_types)] | 2 | #![feature(generic_associated_types)] |
| 3 | #![feature(asm)] | 3 | #![feature(asm)] |
| 4 | #![feature(type_alias_impl_trait)] | 4 | #![feature(type_alias_impl_trait)] |
| 5 | #![feature(let_chains)] | ||
| 6 | 5 | ||
| 7 | #[cfg(not(any( | 6 | #[cfg(not(any( |
| 8 | feature = "stm32f401", | 7 | feature = "stm32f401", |
diff --git a/embassy-stm32f4/src/serial.rs b/embassy-stm32f4/src/serial.rs index f73c1b7c9..57fa14175 100644 --- a/embassy-stm32f4/src/serial.rs +++ b/embassy-stm32f4/src/serial.rs | |||
| @@ -7,32 +7,21 @@ | |||
| 7 | use core::future::Future; | 7 | use core::future::Future; |
| 8 | use core::ptr; | 8 | use core::ptr; |
| 9 | use core::sync::atomic::{self, Ordering}; | 9 | use core::sync::atomic::{self, Ordering}; |
| 10 | use core::task::{Context, Poll}; | ||
| 11 | 10 | ||
| 12 | use embassy::interrupt::OwnedInterrupt; | 11 | use embassy::interrupt::OwnedInterrupt; |
| 13 | use embassy::uart::{Error, Uart}; | 12 | use embassy::uart::{Error, Uart}; |
| 14 | use embassy::util::Signal; | 13 | use embassy::util::Signal; |
| 15 | use embedded_dma::StaticWriteBuffer; | ||
| 16 | 14 | ||
| 17 | use crate::hal::dma::config::DmaConfig; | 15 | use crate::hal::dma::config::DmaConfig; |
| 18 | use crate::hal::dma::traits::{PeriAddress, Stream}; | 16 | use crate::hal::dma::traits::{PeriAddress, Stream}; |
| 19 | use crate::hal::dma::{ | 17 | use crate::hal::dma::{Stream2, Stream7, StreamsTuple, Transfer}; |
| 20 | Channel4, MemoryToPeripheral, PeripheralToMemory, Stream2, Stream7, StreamsTuple, Transfer, | ||
| 21 | }; | ||
| 22 | use crate::hal::gpio::gpioa::{PA10, PA9}; | ||
| 23 | use crate::hal::gpio::{Alternate, AF7}; | ||
| 24 | use crate::hal::prelude::*; | ||
| 25 | use crate::hal::rcc::Clocks; | 18 | use crate::hal::rcc::Clocks; |
| 26 | use crate::hal::serial::config::{ | 19 | use crate::hal::serial::config::{Config as SerialConfig, DmaConfig as SerialDmaConfig}; |
| 27 | Config as SerialConfig, DmaConfig as SerialDmaConfig, Parity, StopBits, WordLength, | ||
| 28 | }; | ||
| 29 | use crate::hal::serial::Pins; | 20 | use crate::hal::serial::Pins; |
| 30 | use crate::hal::serial::{Event as SerialEvent, Serial as HalSerial}; | 21 | use crate::hal::serial::{Event as SerialEvent, Serial as HalSerial}; |
| 31 | use crate::hal::time::Bps; | ||
| 32 | 22 | ||
| 33 | use crate::interrupt; | 23 | use crate::interrupt; |
| 34 | 24 | ||
| 35 | use crate::pac::Interrupt; | ||
| 36 | use crate::pac::{DMA2, USART1}; | 25 | use crate::pac::{DMA2, USART1}; |
| 37 | 26 | ||
| 38 | /// Interface to the Serial peripheral | 27 | /// Interface to the Serial peripheral |
diff --git a/embassy/src/executor/mod.rs b/embassy/src/executor/mod.rs index 3ba0cea60..65db28fcd 100644 --- a/embassy/src/executor/mod.rs +++ b/embassy/src/executor/mod.rs | |||
| @@ -16,7 +16,7 @@ mod util; | |||
| 16 | mod waker; | 16 | mod waker; |
| 17 | 17 | ||
| 18 | use self::util::UninitCell; | 18 | use self::util::UninitCell; |
| 19 | use crate::fmt::{panic, *}; | 19 | use crate::fmt::panic; |
| 20 | use crate::interrupt::OwnedInterrupt; | 20 | use crate::interrupt::OwnedInterrupt; |
| 21 | use crate::time::Alarm; | 21 | use crate::time::Alarm; |
| 22 | 22 | ||
| @@ -56,10 +56,10 @@ impl<F: Future + 'static> Task<F> { | |||
| 56 | } | 56 | } |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | return SpawnToken { | 59 | SpawnToken { |
| 60 | raw_task: None, | 60 | raw_task: None, |
| 61 | phantom: PhantomData, | 61 | phantom: PhantomData, |
| 62 | }; | 62 | } |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | unsafe fn poll(p: NonNull<raw::Task>) { | 65 | unsafe fn poll(p: NonNull<raw::Task>) { |
diff --git a/embassy/src/executor/timer_queue.rs b/embassy/src/executor/timer_queue.rs index c722ae00b..38c237572 100644 --- a/embassy/src/executor/timer_queue.rs +++ b/embassy/src/executor/timer_queue.rs | |||
| @@ -2,7 +2,7 @@ use core::cell::Cell; | |||
| 2 | use core::cmp::min; | 2 | use core::cmp::min; |
| 3 | use core::ptr; | 3 | use core::ptr; |
| 4 | use core::ptr::NonNull; | 4 | use core::ptr::NonNull; |
| 5 | use core::sync::atomic::{AtomicPtr, Ordering}; | 5 | use core::sync::atomic::Ordering; |
| 6 | 6 | ||
| 7 | use super::raw::{Task, STATE_TIMER_QUEUED}; | 7 | use super::raw::{Task, STATE_TIMER_QUEUED}; |
| 8 | use crate::time::Instant; | 8 | use crate::time::Instant; |
diff --git a/embassy/src/fmt.rs b/embassy/src/fmt.rs index 4da69766c..1be1057a7 100644 --- a/embassy/src/fmt.rs +++ b/embassy/src/fmt.rs | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | #![allow(clippy::module_inception)] | ||
| 2 | 3 | ||
| 3 | #[cfg(all(feature = "defmt", feature = "log"))] | 4 | #[cfg(all(feature = "defmt", feature = "log"))] |
| 4 | compile_error!("You may not enable both `defmt` and `log` features."); | 5 | compile_error!("You may not enable both `defmt` and `log` features."); |
diff --git a/embassy/src/interrupt.rs b/embassy/src/interrupt.rs index 45676b31c..9ed0d3293 100644 --- a/embassy/src/interrupt.rs +++ b/embassy/src/interrupt.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | use core::mem; | ||
| 2 | use core::ptr; | 1 | use core::ptr; |
| 3 | use core::sync::atomic::{AtomicBool, AtomicPtr, Ordering}; | 2 | use core::sync::atomic::{AtomicPtr, Ordering}; |
| 4 | use cortex_m::peripheral::NVIC; | 3 | use cortex_m::peripheral::NVIC; |
| 5 | 4 | ||
| 6 | pub use embassy_macros::interrupt_declare as declare; | 5 | pub use embassy_macros::interrupt_declare as declare; |
diff --git a/embassy/src/io/util/copy_buf.rs b/embassy/src/io/util/copy_buf.rs index c037f3b02..c7e324d92 100644 --- a/embassy/src/io/util/copy_buf.rs +++ b/embassy/src/io/util/copy_buf.rs | |||
| @@ -71,7 +71,7 @@ where | |||
| 71 | 71 | ||
| 72 | let i = ready!(Pin::new(&mut this.writer).poll_write(cx, buffer))?; | 72 | let i = ready!(Pin::new(&mut this.writer).poll_write(cx, buffer))?; |
| 73 | if i == 0 { | 73 | if i == 0 { |
| 74 | return Poll::Ready(Err(Error::WriteZero.into())); | 74 | return Poll::Ready(Err(Error::WriteZero)); |
| 75 | } | 75 | } |
| 76 | *this.amt += i; | 76 | *this.amt += i; |
| 77 | this.reader.as_mut().consume(i); | 77 | this.reader.as_mut().consume(i); |
diff --git a/embassy/src/io/util/drain.rs b/embassy/src/io/util/drain.rs index d3f21d071..2542876d8 100644 --- a/embassy/src/io/util/drain.rs +++ b/embassy/src/io/util/drain.rs | |||
| @@ -1,10 +1,8 @@ | |||
| 1 | use core::iter::Iterator; | ||
| 2 | use core::pin::Pin; | 1 | use core::pin::Pin; |
| 3 | use futures::future::Future; | 2 | use futures::future::Future; |
| 4 | use futures::ready; | ||
| 5 | use futures::task::{Context, Poll}; | 3 | use futures::task::{Context, Poll}; |
| 6 | 4 | ||
| 7 | use super::super::error::{Error, Result}; | 5 | use super::super::error::Result; |
| 8 | use super::super::traits::AsyncBufRead; | 6 | use super::super::traits::AsyncBufRead; |
| 9 | 7 | ||
| 10 | pub struct Drain<'a, R: ?Sized> { | 8 | pub struct Drain<'a, R: ?Sized> { |
diff --git a/embassy/src/io/util/mod.rs b/embassy/src/io/util/mod.rs index a9a00f809..de6643cb3 100644 --- a/embassy/src/io/util/mod.rs +++ b/embassy/src/io/util/mod.rs | |||
| @@ -75,14 +75,14 @@ pub trait AsyncBufReadExt: AsyncBufRead { | |||
| 75 | ReadWhile::new(self, f, buf) | 75 | ReadWhile::new(self, f, buf) |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | fn skip_while<'a, F: Fn(u8) -> bool>(&'a mut self, f: F) -> SkipWhile<'a, Self, F> | 78 | fn skip_while<F: Fn(u8) -> bool>(&mut self, f: F) -> SkipWhile<Self, F> |
| 79 | where | 79 | where |
| 80 | Self: Unpin, | 80 | Self: Unpin, |
| 81 | { | 81 | { |
| 82 | SkipWhile::new(self, f) | 82 | SkipWhile::new(self, f) |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | fn drain<'a>(&'a mut self) -> Drain<'a, Self> | 85 | fn drain(&mut self) -> Drain<Self> |
| 86 | where | 86 | where |
| 87 | Self: Unpin, | 87 | Self: Unpin, |
| 88 | { | 88 | { |
| @@ -96,14 +96,14 @@ pub trait AsyncBufReadExt: AsyncBufRead { | |||
| 96 | Read::new(self, buf) | 96 | Read::new(self, buf) |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | fn read_buf<'a>(&'a mut self) -> ReadBuf<'a, Self> | 99 | fn read_buf(&mut self) -> ReadBuf<Self> |
| 100 | where | 100 | where |
| 101 | Self: Unpin, | 101 | Self: Unpin, |
| 102 | { | 102 | { |
| 103 | ReadBuf::new(self) | 103 | ReadBuf::new(self) |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | fn read_byte<'a>(&'a mut self) -> ReadByte<'a, Self> | 106 | fn read_byte(&mut self) -> ReadByte<Self> |
| 107 | where | 107 | where |
| 108 | Self: Unpin, | 108 | Self: Unpin, |
| 109 | { | 109 | { |
| @@ -147,12 +147,19 @@ pub trait AsyncWriteExt: AsyncWrite { | |||
| 147 | WriteAll::new(self, buf) | 147 | WriteAll::new(self, buf) |
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | fn write_byte<'a>(&'a mut self, byte: u8) -> WriteByte<'a, Self> | 150 | fn write_byte(&mut self, byte: u8) -> WriteByte<Self> |
| 151 | where | 151 | where |
| 152 | Self: Unpin, | 152 | Self: Unpin, |
| 153 | { | 153 | { |
| 154 | WriteByte::new(self, byte) | 154 | WriteByte::new(self, byte) |
| 155 | } | 155 | } |
| 156 | |||
| 157 | fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self> | ||
| 158 | where | ||
| 159 | Self: Unpin, | ||
| 160 | { | ||
| 161 | Write::new(self, buf) | ||
| 162 | } | ||
| 156 | } | 163 | } |
| 157 | 164 | ||
| 158 | impl<R: AsyncWrite + ?Sized> AsyncWriteExt for R {} | 165 | impl<R: AsyncWrite + ?Sized> AsyncWriteExt for R {} |
diff --git a/embassy/src/io/util/read_byte.rs b/embassy/src/io/util/read_byte.rs index 7b7865ba9..e5bbcb1ff 100644 --- a/embassy/src/io/util/read_byte.rs +++ b/embassy/src/io/util/read_byte.rs | |||
| @@ -25,7 +25,7 @@ impl<'a, R: AsyncBufRead + ?Sized + Unpin> Future for ReadByte<'a, R> { | |||
| 25 | let Self { reader } = &mut *self; | 25 | let Self { reader } = &mut *self; |
| 26 | let mut reader = Pin::new(reader); | 26 | let mut reader = Pin::new(reader); |
| 27 | let rbuf = ready!(reader.as_mut().poll_fill_buf(cx))?; | 27 | let rbuf = ready!(reader.as_mut().poll_fill_buf(cx))?; |
| 28 | if rbuf.len() == 0 { | 28 | if rbuf.is_empty() { |
| 29 | return Poll::Ready(Err(Error::UnexpectedEof)); | 29 | return Poll::Ready(Err(Error::UnexpectedEof)); |
| 30 | } | 30 | } |
| 31 | 31 | ||
diff --git a/embassy/src/io/util/read_exact.rs b/embassy/src/io/util/read_exact.rs index b7f7355ef..80c9376d5 100644 --- a/embassy/src/io/util/read_exact.rs +++ b/embassy/src/io/util/read_exact.rs | |||
| @@ -31,7 +31,7 @@ impl<R: AsyncBufRead + ?Sized + Unpin> Future for ReadExact<'_, R> { | |||
| 31 | let this = &mut *self; | 31 | let this = &mut *self; |
| 32 | while !this.buf.is_empty() { | 32 | while !this.buf.is_empty() { |
| 33 | let buf = ready!(Pin::new(&mut this.reader).poll_fill_buf(cx))?; | 33 | let buf = ready!(Pin::new(&mut this.reader).poll_fill_buf(cx))?; |
| 34 | if buf.len() == 0 { | 34 | if buf.is_empty() { |
| 35 | return Poll::Ready(Err(Error::UnexpectedEof)); | 35 | return Poll::Ready(Err(Error::UnexpectedEof)); |
| 36 | } | 36 | } |
| 37 | 37 | ||
diff --git a/embassy/src/io/util/read_to_end.rs b/embassy/src/io/util/read_to_end.rs index 2da6c74d8..d09999ad0 100644 --- a/embassy/src/io/util/read_to_end.rs +++ b/embassy/src/io/util/read_to_end.rs | |||
| @@ -29,7 +29,7 @@ impl<'a, R: AsyncBufRead + ?Sized + Unpin> Future for ReadToEnd<'a, R> { | |||
| 29 | let mut reader = Pin::new(reader); | 29 | let mut reader = Pin::new(reader); |
| 30 | loop { | 30 | loop { |
| 31 | let rbuf = ready!(reader.as_mut().poll_fill_buf(cx))?; | 31 | let rbuf = ready!(reader.as_mut().poll_fill_buf(cx))?; |
| 32 | if rbuf.len() == 0 { | 32 | if rbuf.is_empty() { |
| 33 | return Poll::Ready(Ok(*n)); | 33 | return Poll::Ready(Ok(*n)); |
| 34 | } | 34 | } |
| 35 | 35 | ||
diff --git a/embassy/src/io/util/read_while.rs b/embassy/src/io/util/read_while.rs index ab46cee38..e24638039 100644 --- a/embassy/src/io/util/read_while.rs +++ b/embassy/src/io/util/read_while.rs | |||
| @@ -35,7 +35,7 @@ impl<'a, R: AsyncBufRead + ?Sized + Unpin, F: Fn(u8) -> bool> Future for ReadWhi | |||
| 35 | let mut reader = Pin::new(reader); | 35 | let mut reader = Pin::new(reader); |
| 36 | loop { | 36 | loop { |
| 37 | let rbuf = ready!(reader.as_mut().poll_fill_buf(cx))?; | 37 | let rbuf = ready!(reader.as_mut().poll_fill_buf(cx))?; |
| 38 | if rbuf.len() == 0 { | 38 | if rbuf.is_empty() { |
| 39 | return Poll::Ready(Err(Error::UnexpectedEof)); | 39 | return Poll::Ready(Err(Error::UnexpectedEof)); |
| 40 | } | 40 | } |
| 41 | 41 | ||
diff --git a/embassy/src/io/util/skip_while.rs b/embassy/src/io/util/skip_while.rs index 8c81ad209..6f0e167df 100644 --- a/embassy/src/io/util/skip_while.rs +++ b/embassy/src/io/util/skip_while.rs | |||
| @@ -28,7 +28,7 @@ impl<'a, R: AsyncBufRead + ?Sized + Unpin, F: Fn(u8) -> bool> Future for SkipWhi | |||
| 28 | let mut reader = Pin::new(reader); | 28 | let mut reader = Pin::new(reader); |
| 29 | loop { | 29 | loop { |
| 30 | let buf = ready!(reader.as_mut().poll_fill_buf(cx))?; | 30 | let buf = ready!(reader.as_mut().poll_fill_buf(cx))?; |
| 31 | if buf.len() == 0 { | 31 | if buf.is_empty() { |
| 32 | return Poll::Ready(Err(Error::UnexpectedEof)); | 32 | return Poll::Ready(Err(Error::UnexpectedEof)); |
| 33 | } | 33 | } |
| 34 | 34 | ||
diff --git a/embassy/src/time/instant.rs b/embassy/src/time/instant.rs index e1aff11c4..06ab84c75 100644 --- a/embassy/src/time/instant.rs +++ b/embassy/src/time/instant.rs | |||
| @@ -1,4 +1,3 @@ | |||
| 1 | use core::convert::TryInto; | ||
| 2 | use core::fmt; | 1 | use core::fmt; |
| 3 | use core::ops::{Add, AddAssign, Sub, SubAssign}; | 2 | use core::ops::{Add, AddAssign, Sub, SubAssign}; |
| 4 | 3 | ||
| @@ -49,7 +48,7 @@ impl Instant { | |||
| 49 | 48 | ||
| 50 | pub fn duration_since(&self, earlier: Instant) -> Duration { | 49 | pub fn duration_since(&self, earlier: Instant) -> Duration { |
| 51 | Duration { | 50 | Duration { |
| 52 | ticks: (self.ticks - earlier.ticks).try_into().unwrap(), | 51 | ticks: self.ticks.checked_sub(earlier.ticks).unwrap(), |
| 53 | } | 52 | } |
| 54 | } | 53 | } |
| 55 | 54 | ||
| @@ -58,7 +57,7 @@ impl Instant { | |||
| 58 | None | 57 | None |
| 59 | } else { | 58 | } else { |
| 60 | Some(Duration { | 59 | Some(Duration { |
| 61 | ticks: (self.ticks - earlier.ticks).try_into().unwrap(), | 60 | ticks: self.ticks - earlier.ticks, |
| 62 | }) | 61 | }) |
| 63 | } | 62 | } |
| 64 | } | 63 | } |
| @@ -68,7 +67,7 @@ impl Instant { | |||
| 68 | ticks: if self.ticks < earlier.ticks { | 67 | ticks: if self.ticks < earlier.ticks { |
| 69 | 0 | 68 | 0 |
| 70 | } else { | 69 | } else { |
| 71 | (self.ticks - earlier.ticks).try_into().unwrap() | 70 | self.ticks - earlier.ticks |
| 72 | }, | 71 | }, |
| 73 | } | 72 | } |
| 74 | } | 73 | } |
| @@ -79,12 +78,12 @@ impl Instant { | |||
| 79 | 78 | ||
| 80 | pub fn checked_add(&self, duration: Duration) -> Option<Instant> { | 79 | pub fn checked_add(&self, duration: Duration) -> Option<Instant> { |
| 81 | self.ticks | 80 | self.ticks |
| 82 | .checked_add(duration.ticks.into()) | 81 | .checked_add(duration.ticks) |
| 83 | .map(|ticks| Instant { ticks }) | 82 | .map(|ticks| Instant { ticks }) |
| 84 | } | 83 | } |
| 85 | pub fn checked_sub(&self, duration: Duration) -> Option<Instant> { | 84 | pub fn checked_sub(&self, duration: Duration) -> Option<Instant> { |
| 86 | self.ticks | 85 | self.ticks |
| 87 | .checked_sub(duration.ticks.into()) | 86 | .checked_sub(duration.ticks) |
| 88 | .map(|ticks| Instant { ticks }) | 87 | .map(|ticks| Instant { ticks }) |
| 89 | } | 88 | } |
| 90 | } | 89 | } |
diff --git a/embassy/src/util/mutex.rs b/embassy/src/util/mutex.rs index f87d70034..ed2fd7852 100644 --- a/embassy/src/util/mutex.rs +++ b/embassy/src/util/mutex.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use core::cell::UnsafeCell; | 1 | use core::cell::UnsafeCell; |
| 2 | use cortex_m::interrupt::CriticalSection; | 2 | use cortex_m::interrupt::CriticalSection; |
| 3 | 3 | ||
| 4 | use crate::fmt::{assert, panic, *}; | 4 | use crate::fmt::assert; |
| 5 | 5 | ||
| 6 | /// A "mutex" based on critical sections | 6 | /// A "mutex" based on critical sections |
| 7 | /// | 7 | /// |
diff --git a/embassy/src/util/portal.rs b/embassy/src/util/portal.rs index 05bdccf58..f4f2824aa 100644 --- a/embassy/src/util/portal.rs +++ b/embassy/src/util/portal.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | use crate::fmt::panic; | 1 | use crate::fmt::panic; |
| 2 | use core::cell::UnsafeCell; | 2 | use core::cell::UnsafeCell; |
| 3 | use core::future::Future; | ||
| 4 | use core::mem; | 3 | use core::mem; |
| 5 | use core::mem::MaybeUninit; | 4 | use core::mem::MaybeUninit; |
| 6 | 5 | ||
| @@ -34,93 +33,89 @@ impl<T> Portal<T> { | |||
| 34 | } | 33 | } |
| 35 | } | 34 | } |
| 36 | 35 | ||
| 37 | pub fn wait_once<'a, R, F>(&'a self, mut func: F) -> impl Future<Output = R> + 'a | 36 | pub async fn wait_once<'a, R, F>(&'a self, mut func: F) -> R |
| 38 | where | 37 | where |
| 39 | F: FnMut(T) -> R + 'a, | 38 | F: FnMut(T) -> R + 'a, |
| 40 | { | 39 | { |
| 41 | async move { | 40 | let bomb = DropBomb::new(); |
| 42 | let bomb = DropBomb::new(); | ||
| 43 | |||
| 44 | let signal = Signal::new(); | ||
| 45 | let mut result: MaybeUninit<R> = MaybeUninit::uninit(); | ||
| 46 | let mut call_func = |val: T| { | ||
| 47 | unsafe { | ||
| 48 | let state = &mut *self.state.get(); | ||
| 49 | *state = State::None; | ||
| 50 | result.as_mut_ptr().write(func(val)) | ||
| 51 | }; | ||
| 52 | signal.signal(()); | ||
| 53 | }; | ||
| 54 | |||
| 55 | let func_ptr: *mut dyn FnMut(T) = &mut call_func as _; | ||
| 56 | let func_ptr: *mut dyn FnMut(T) = unsafe { mem::transmute(func_ptr) }; | ||
| 57 | 41 | ||
| 42 | let signal = Signal::new(); | ||
| 43 | let mut result: MaybeUninit<R> = MaybeUninit::uninit(); | ||
| 44 | let mut call_func = |val: T| { | ||
| 58 | unsafe { | 45 | unsafe { |
| 59 | let state = &mut *self.state.get(); | 46 | let state = &mut *self.state.get(); |
| 60 | match state { | 47 | *state = State::None; |
| 61 | State::None => {} | 48 | result.as_mut_ptr().write(func(val)) |
| 62 | _ => panic!("Multiple tasks waiting on same portal"), | 49 | }; |
| 63 | } | 50 | signal.signal(()); |
| 64 | *state = State::Waiting(func_ptr); | 51 | }; |
| 52 | |||
| 53 | let func_ptr: *mut dyn FnMut(T) = &mut call_func as _; | ||
| 54 | let func_ptr: *mut dyn FnMut(T) = unsafe { mem::transmute(func_ptr) }; | ||
| 55 | |||
| 56 | unsafe { | ||
| 57 | let state = &mut *self.state.get(); | ||
| 58 | match state { | ||
| 59 | State::None => {} | ||
| 60 | _ => panic!("Multiple tasks waiting on same portal"), | ||
| 65 | } | 61 | } |
| 62 | *state = State::Waiting(func_ptr); | ||
| 63 | } | ||
| 66 | 64 | ||
| 67 | signal.wait().await; | 65 | signal.wait().await; |
| 68 | 66 | ||
| 69 | bomb.defuse(); | 67 | bomb.defuse(); |
| 70 | 68 | ||
| 71 | unsafe { result.assume_init() } | 69 | unsafe { result.assume_init() } |
| 72 | } | ||
| 73 | } | 70 | } |
| 74 | 71 | ||
| 75 | pub fn wait_many<'a, R, F>(&'a self, mut func: F) -> impl Future<Output = R> + 'a | 72 | pub async fn wait_many<'a, R, F>(&'a self, mut func: F) -> R |
| 76 | where | 73 | where |
| 77 | F: FnMut(T) -> Option<R> + 'a, | 74 | F: FnMut(T) -> Option<R> + 'a, |
| 78 | { | 75 | { |
| 79 | async move { | 76 | let bomb = DropBomb::new(); |
| 80 | let bomb = DropBomb::new(); | 77 | |
| 81 | 78 | let signal = Signal::new(); | |
| 82 | let signal = Signal::new(); | 79 | let mut result: MaybeUninit<R> = MaybeUninit::uninit(); |
| 83 | let mut result: MaybeUninit<R> = MaybeUninit::uninit(); | 80 | let mut call_func = |val: T| { |
| 84 | let mut call_func = |val: T| { | 81 | unsafe { |
| 85 | unsafe { | 82 | let state = &mut *self.state.get(); |
| 86 | let state = &mut *self.state.get(); | 83 | |
| 87 | 84 | let func_ptr = match *state { | |
| 88 | let func_ptr = match *state { | 85 | State::Waiting(p) => p, |
| 89 | State::Waiting(p) => p, | 86 | _ => unreachable!(), |
| 90 | _ => unreachable!(), | 87 | }; |
| 91 | }; | 88 | |
| 92 | 89 | // Set state to Running while running the function to avoid reentrancy. | |
| 93 | // Set state to Running while running the function to avoid reentrancy. | 90 | *state = State::Running; |
| 94 | *state = State::Running; | 91 | |
| 95 | 92 | *state = match func(val) { | |
| 96 | *state = match func(val) { | 93 | None => State::Waiting(func_ptr), |
| 97 | None => State::Waiting(func_ptr), | 94 | Some(res) => { |
| 98 | Some(res) => { | 95 | result.as_mut_ptr().write(res); |
| 99 | result.as_mut_ptr().write(res); | 96 | signal.signal(()); |
| 100 | signal.signal(()); | 97 | State::None |
| 101 | State::None | 98 | } |
| 102 | } | ||
| 103 | }; | ||
| 104 | }; | 99 | }; |
| 105 | }; | 100 | }; |
| 101 | }; | ||
| 106 | 102 | ||
| 107 | let func_ptr: *mut dyn FnMut(T) = &mut call_func as _; | 103 | let func_ptr: *mut dyn FnMut(T) = &mut call_func as _; |
| 108 | let func_ptr: *mut dyn FnMut(T) = unsafe { mem::transmute(func_ptr) }; | 104 | let func_ptr: *mut dyn FnMut(T) = unsafe { mem::transmute(func_ptr) }; |
| 109 | 105 | ||
| 110 | unsafe { | 106 | unsafe { |
| 111 | let state = &mut *self.state.get(); | 107 | let state = &mut *self.state.get(); |
| 112 | match *state { | 108 | match *state { |
| 113 | State::None => {} | 109 | State::None => {} |
| 114 | _ => panic!("Multiple tasks waiting on same portal"), | 110 | _ => panic!("Multiple tasks waiting on same portal"), |
| 115 | } | ||
| 116 | *state = State::Waiting(func_ptr); | ||
| 117 | } | 111 | } |
| 112 | *state = State::Waiting(func_ptr); | ||
| 113 | } | ||
| 118 | 114 | ||
| 119 | signal.wait().await; | 115 | signal.wait().await; |
| 120 | 116 | ||
| 121 | bomb.defuse(); | 117 | bomb.defuse(); |
| 122 | 118 | ||
| 123 | unsafe { result.assume_init() } | 119 | unsafe { result.assume_init() } |
| 124 | } | ||
| 125 | } | 120 | } |
| 126 | } | 121 | } |
diff --git a/embassy/src/util/signal.rs b/embassy/src/util/signal.rs index c8b7a61a6..89cc03f2c 100644 --- a/embassy/src/util/signal.rs +++ b/embassy/src/util/signal.rs | |||
| @@ -32,9 +32,8 @@ impl<T: Send> Signal<T> { | |||
| 32 | pub fn signal(&self, val: T) { | 32 | pub fn signal(&self, val: T) { |
| 33 | cortex_m::interrupt::free(|_| unsafe { | 33 | cortex_m::interrupt::free(|_| unsafe { |
| 34 | let state = &mut *self.state.get(); | 34 | let state = &mut *self.state.get(); |
| 35 | match mem::replace(state, State::Signaled(val)) { | 35 | if let State::Waiting(waker) = mem::replace(state, State::Signaled(val)) { |
| 36 | State::Waiting(waker) => waker.wake(), | 36 | waker.wake(); |
| 37 | _ => {} | ||
| 38 | } | 37 | } |
| 39 | }) | 38 | }) |
| 40 | } | 39 | } |
| @@ -98,9 +97,7 @@ impl<'a, I: OwnedInterrupt> InterruptFuture<'a, I> { | |||
| 98 | interrupt.unpend(); | 97 | interrupt.unpend(); |
| 99 | interrupt.enable(); | 98 | interrupt.enable(); |
| 100 | 99 | ||
| 101 | Self { | 100 | Self { interrupt } |
| 102 | interrupt: interrupt, | ||
| 103 | } | ||
| 104 | } | 101 | } |
| 105 | 102 | ||
| 106 | unsafe fn interrupt_handler(ctx: *mut ()) { | 103 | unsafe fn interrupt_handler(ctx: *mut ()) { |
| @@ -109,7 +106,7 @@ impl<'a, I: OwnedInterrupt> InterruptFuture<'a, I> { | |||
| 109 | _ => unreachable!(), | 106 | _ => unreachable!(), |
| 110 | }; | 107 | }; |
| 111 | 108 | ||
| 112 | if ctx as *const _ != ptr::null() { | 109 | if !ctx.is_null() { |
| 113 | executor::raw::wake_task(ptr::NonNull::new_unchecked(ctx as _)); | 110 | executor::raw::wake_task(ptr::NonNull::new_unchecked(ctx as _)); |
| 114 | } | 111 | } |
| 115 | 112 | ||
diff --git a/embassy/src/util/waker.rs b/embassy/src/util/waker.rs index 83fd8b4ff..68e45cf1a 100644 --- a/embassy/src/util/waker.rs +++ b/embassy/src/util/waker.rs | |||
| @@ -40,7 +40,9 @@ impl WakerRegistration { | |||
| 40 | 40 | ||
| 41 | /// Wake the registered waker, if any. | 41 | /// Wake the registered waker, if any. |
| 42 | pub fn wake(&mut self) { | 42 | pub fn wake(&mut self) { |
| 43 | self.waker.take().map(|w| w.wake()); | 43 | if let Some(w) = self.waker.take() { |
| 44 | w.wake() | ||
| 45 | } | ||
| 44 | } | 46 | } |
| 45 | 47 | ||
| 46 | pub fn context(&self) -> Option<Context<'_>> { | 48 | pub fn context(&self) -> Option<Context<'_>> { |
