aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-rp/src/adc.rs11
-rw-r--r--embassy-rp/src/clocks.rs4
-rw-r--r--embassy-rp/src/flash.rs4
-rw-r--r--embassy-rp/src/gpio.rs6
-rw-r--r--embassy-rp/src/i2c.rs6
-rw-r--r--embassy-rp/src/i2c_slave.rs16
-rw-r--r--embassy-rp/src/lib.rs4
-rw-r--r--embassy-rp/src/multicore.rs2
-rw-r--r--embassy-rp/src/pio/mod.rs12
-rw-r--r--embassy-rp/src/pwm.rs6
-rw-r--r--embassy-rp/src/relocate.rs6
-rw-r--r--embassy-rp/src/rtc/mod.rs3
-rw-r--r--embassy-rp/src/uart/buffered.rs4
-rw-r--r--embassy-rp/src/uart/mod.rs2
14 files changed, 37 insertions, 49 deletions
diff --git a/embassy-rp/src/adc.rs b/embassy-rp/src/adc.rs
index 21360bf66..4c01fe195 100644
--- a/embassy-rp/src/adc.rs
+++ b/embassy-rp/src/adc.rs
@@ -19,14 +19,9 @@ static WAKER: AtomicWaker = AtomicWaker::new();
19 19
20/// ADC config. 20/// ADC config.
21#[non_exhaustive] 21#[non_exhaustive]
22#[derive(Default)]
22pub struct Config {} 23pub struct Config {}
23 24
24impl Default for Config {
25 fn default() -> Self {
26 Self {}
27 }
28}
29
30enum Source<'p> { 25enum Source<'p> {
31 Pin(PeripheralRef<'p, AnyPin>), 26 Pin(PeripheralRef<'p, AnyPin>),
32 TempSensor(PeripheralRef<'p, ADC_TEMP_SENSOR>), 27 TempSensor(PeripheralRef<'p, ADC_TEMP_SENSOR>),
@@ -175,7 +170,7 @@ impl<'d, M: Mode> Adc<'d, M> {
175 while !r.cs().read().ready() {} 170 while !r.cs().read().ready() {}
176 match r.cs().read().err() { 171 match r.cs().read().err() {
177 true => Err(Error::ConversionFailed), 172 true => Err(Error::ConversionFailed),
178 false => Ok(r.result().read().result().into()), 173 false => Ok(r.result().read().result()),
179 } 174 }
180 } 175 }
181} 176}
@@ -221,7 +216,7 @@ impl<'d> Adc<'d, Async> {
221 Self::wait_for_ready().await; 216 Self::wait_for_ready().await;
222 match r.cs().read().err() { 217 match r.cs().read().err() {
223 true => Err(Error::ConversionFailed), 218 true => Err(Error::ConversionFailed),
224 false => Ok(r.result().read().result().into()), 219 false => Ok(r.result().read().result()),
225 } 220 }
226 } 221 }
227 222
diff --git a/embassy-rp/src/clocks.rs b/embassy-rp/src/clocks.rs
index 19232b801..b02f3796f 100644
--- a/embassy-rp/src/clocks.rs
+++ b/embassy-rp/src/clocks.rs
@@ -1,5 +1,4 @@
1//! Clock configuration for the RP2040 1//! Clock configuration for the RP2040
2use core::arch::asm;
3use core::marker::PhantomData; 2use core::marker::PhantomData;
4use core::sync::atomic::{AtomicU16, AtomicU32, Ordering}; 3use core::sync::atomic::{AtomicU16, AtomicU32, Ordering};
5 4
@@ -8,7 +7,6 @@ use pac::clocks::vals::*;
8 7
9use crate::gpio::sealed::Pin; 8use crate::gpio::sealed::Pin;
10use crate::gpio::AnyPin; 9use crate::gpio::AnyPin;
11use crate::pac::common::{Reg, RW};
12use crate::{pac, reset, Peripheral}; 10use crate::{pac, reset, Peripheral};
13 11
14// NOTE: all gpin handling is commented out for future reference. 12// NOTE: all gpin handling is commented out for future reference.
@@ -737,7 +735,7 @@ fn configure_pll(p: pac::pll::Pll, input_freq: u32, config: PllConfig) -> u32 {
737 assert!(config.refdiv >= 1 && config.refdiv <= 63); 735 assert!(config.refdiv >= 1 && config.refdiv <= 63);
738 assert!(ref_freq >= 5_000_000 && ref_freq <= 800_000_000); 736 assert!(ref_freq >= 5_000_000 && ref_freq <= 800_000_000);
739 let vco_freq = ref_freq.saturating_mul(config.fbdiv as u32); 737 let vco_freq = ref_freq.saturating_mul(config.fbdiv as u32);
740 assert!(vco_freq >= 750_000_000 && vco_freq <= 1800_000_000); 738 assert!(vco_freq >= 750_000_000 && vco_freq <= 1_800_000_000);
741 739
742 // Load VCO-related dividers before starting VCO 740 // Load VCO-related dividers before starting VCO
743 p.cs().write(|w| w.set_refdiv(config.refdiv as _)); 741 p.cs().write(|w| w.set_refdiv(config.refdiv as _));
diff --git a/embassy-rp/src/flash.rs b/embassy-rp/src/flash.rs
index 2d673cf6c..8bac93684 100644
--- a/embassy-rp/src/flash.rs
+++ b/embassy-rp/src/flash.rs
@@ -326,9 +326,9 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Flash<'d, T, Async, FLASH_SIZE> {
326 // If the destination address is already aligned, then we can just DMA directly 326 // If the destination address is already aligned, then we can just DMA directly
327 if (bytes.as_ptr() as u32) % 4 == 0 { 327 if (bytes.as_ptr() as u32) % 4 == 0 {
328 // Safety: alignment and size have been checked for compatibility 328 // Safety: alignment and size have been checked for compatibility
329 let mut buf: &mut [u32] = 329 let buf: &mut [u32] =
330 unsafe { core::slice::from_raw_parts_mut(bytes.as_mut_ptr() as *mut u32, bytes.len() / 4) }; 330 unsafe { core::slice::from_raw_parts_mut(bytes.as_mut_ptr() as *mut u32, bytes.len() / 4) };
331 self.background_read(offset, &mut buf)?.await; 331 self.background_read(offset, buf)?.await;
332 return Ok(()); 332 return Ok(());
333 } 333 }
334 334
diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs
index 62eeb4cf6..405bddfd8 100644
--- a/embassy-rp/src/gpio.rs
+++ b/embassy-rp/src/gpio.rs
@@ -225,8 +225,8 @@ fn irq_handler<const N: usize>(bank: pac::io::Io, wakers: &[AtomicWaker; N]) {
225 // The status register is divided into groups of four, one group for 225 // The status register is divided into groups of four, one group for
226 // each pin. Each group consists of four trigger levels LEVEL_LOW, 226 // each pin. Each group consists of four trigger levels LEVEL_LOW,
227 // LEVEL_HIGH, EDGE_LOW, and EDGE_HIGH for each pin. 227 // LEVEL_HIGH, EDGE_LOW, and EDGE_HIGH for each pin.
228 let pin_group = (pin % 8) as usize; 228 let pin_group = pin % 8;
229 let event = (intsx.read().0 >> pin_group * 4) & 0xf as u32; 229 let event = (intsx.read().0 >> (pin_group * 4)) & 0xf;
230 230
231 // no more than one event can be awaited per pin at any given time, so 231 // no more than one event can be awaited per pin at any given time, so
232 // we can just clear all interrupt enables for that pin without having 232 // we can just clear all interrupt enables for that pin without having
@@ -238,7 +238,7 @@ fn irq_handler<const N: usize>(bank: pac::io::Io, wakers: &[AtomicWaker; N]) {
238 w.set_level_high(pin_group, true); 238 w.set_level_high(pin_group, true);
239 w.set_level_low(pin_group, true); 239 w.set_level_low(pin_group, true);
240 }); 240 });
241 wakers[pin as usize].wake(); 241 wakers[pin].wake();
242 } 242 }
243 } 243 }
244} 244}
diff --git a/embassy-rp/src/i2c.rs b/embassy-rp/src/i2c.rs
index ac0eac96d..26a819b25 100644
--- a/embassy-rp/src/i2c.rs
+++ b/embassy-rp/src/i2c.rs
@@ -352,7 +352,7 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl
352 } 352 }
353} 353}
354 354
355pub(crate) fn set_up_i2c_pin<'d, P, T>(pin: &P) 355pub(crate) fn set_up_i2c_pin<P, T>(pin: &P)
356where 356where
357 P: core::ops::Deref<Target = T>, 357 P: core::ops::Deref<Target = T>,
358 T: crate::gpio::Pin, 358 T: crate::gpio::Pin,
@@ -749,7 +749,7 @@ where
749 749
750 let addr: u16 = address.into(); 750 let addr: u16 = address.into();
751 751
752 if operations.len() > 0 { 752 if !operations.is_empty() {
753 Self::setup(addr)?; 753 Self::setup(addr)?;
754 } 754 }
755 let mut iterator = operations.iter_mut(); 755 let mut iterator = operations.iter_mut();
@@ -762,7 +762,7 @@ where
762 self.read_async_internal(buffer, false, last).await?; 762 self.read_async_internal(buffer, false, last).await?;
763 } 763 }
764 Operation::Write(buffer) => { 764 Operation::Write(buffer) => {
765 self.write_async_internal(buffer.into_iter().cloned(), last).await?; 765 self.write_async_internal(buffer.iter().cloned(), last).await?;
766 } 766 }
767 } 767 }
768 } 768 }
diff --git a/embassy-rp/src/i2c_slave.rs b/embassy-rp/src/i2c_slave.rs
index 97ca17295..e2d4fbac0 100644
--- a/embassy-rp/src/i2c_slave.rs
+++ b/embassy-rp/src/i2c_slave.rs
@@ -289,7 +289,7 @@ impl<'d, T: Instance> I2cSlave<'d, T> {
289 pub async fn respond_to_read(&mut self, buffer: &[u8]) -> Result<ReadStatus, Error> { 289 pub async fn respond_to_read(&mut self, buffer: &[u8]) -> Result<ReadStatus, Error> {
290 let p = T::regs(); 290 let p = T::regs();
291 291
292 if buffer.len() == 0 { 292 if buffer.is_empty() {
293 return Err(Error::InvalidResponseBufferLength); 293 return Err(Error::InvalidResponseBufferLength);
294 } 294 }
295 295
@@ -318,15 +318,13 @@ impl<'d, T: Instance> I2cSlave<'d, T> {
318 } 318 }
319 319
320 Poll::Pending 320 Poll::Pending
321 } else if stat.rx_done() {
322 p.ic_clr_rx_done().read();
323 Poll::Ready(Ok(ReadStatus::Done))
324 } else if stat.rd_req() && stat.tx_empty() {
325 Poll::Ready(Ok(ReadStatus::NeedMoreBytes))
321 } else { 326 } else {
322 if stat.rx_done() { 327 Poll::Pending
323 p.ic_clr_rx_done().read();
324 Poll::Ready(Ok(ReadStatus::Done))
325 } else if stat.rd_req() && stat.tx_empty() {
326 Poll::Ready(Ok(ReadStatus::NeedMoreBytes))
327 } else {
328 Poll::Pending
329 }
330 } 328 }
331 }, 329 },
332 |_me| { 330 |_me| {
diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs
index 46973fdc8..7092b3fab 100644
--- a/embassy-rp/src/lib.rs
+++ b/embassy-rp/src/lib.rs
@@ -238,8 +238,8 @@ select_bootloader! {
238} 238}
239 239
240/// Installs a stack guard for the CORE0 stack in MPU region 0. 240/// Installs a stack guard for the CORE0 stack in MPU region 0.
241/// Will fail if the MPU is already confgigured. This function requires 241/// Will fail if the MPU is already configured. This function requires
242/// a `_stack_end` symbol to be defined by the linker script, and expexcts 242/// a `_stack_end` symbol to be defined by the linker script, and expects
243/// `_stack_end` to be located at the lowest address (largest depth) of 243/// `_stack_end` to be located at the lowest address (largest depth) of
244/// the stack. 244/// the stack.
245/// 245///
diff --git a/embassy-rp/src/multicore.rs b/embassy-rp/src/multicore.rs
index 252f30dc1..d9d65694a 100644
--- a/embassy-rp/src/multicore.rs
+++ b/embassy-rp/src/multicore.rs
@@ -59,7 +59,7 @@ static IS_CORE1_INIT: AtomicBool = AtomicBool::new(false);
59 59
60#[inline(always)] 60#[inline(always)]
61fn core1_setup(stack_bottom: *mut usize) { 61fn core1_setup(stack_bottom: *mut usize) {
62 if let Err(_) = install_stack_guard(stack_bottom) { 62 if install_stack_guard(stack_bottom).is_err() {
63 // currently only happens if the MPU was already set up, which 63 // currently only happens if the MPU was already set up, which
64 // would indicate that the core is already in use from outside 64 // would indicate that the core is already in use from outside
65 // embassy, somehow. trap if so since we can't deal with that. 65 // embassy, somehow. trap if so since we can't deal with that.
diff --git a/embassy-rp/src/pio/mod.rs b/embassy-rp/src/pio/mod.rs
index ca9795024..804a7636d 100644
--- a/embassy-rp/src/pio/mod.rs
+++ b/embassy-rp/src/pio/mod.rs
@@ -268,7 +268,7 @@ impl<'l, PIO: Instance> Pin<'l, PIO> {
268 } 268 }
269 269
270 /// Set the pin's input sync bypass. 270 /// Set the pin's input sync bypass.
271 pub fn set_input_sync_bypass<'a>(&mut self, bypass: bool) { 271 pub fn set_input_sync_bypass(&mut self, bypass: bool) {
272 let mask = 1 << self.pin(); 272 let mask = 1 << self.pin();
273 if bypass { 273 if bypass {
274 PIO::PIO.input_sync_bypass().write_set(|w| *w = mask); 274 PIO::PIO.input_sync_bypass().write_set(|w| *w = mask);
@@ -463,7 +463,7 @@ impl<'d, PIO: Instance, const SM: usize> Drop for StateMachine<'d, PIO, SM> {
463 } 463 }
464} 464}
465 465
466fn assert_consecutive<'d, PIO: Instance>(pins: &[&Pin<'d, PIO>]) { 466fn assert_consecutive<PIO: Instance>(pins: &[&Pin<PIO>]) {
467 for (p1, p2) in pins.iter().zip(pins.iter().skip(1)) { 467 for (p1, p2) in pins.iter().zip(pins.iter().skip(1)) {
468 // purposely does not allow wrap-around because we can't claim pins 30 and 31. 468 // purposely does not allow wrap-around because we can't claim pins 30 and 31.
469 assert!(p1.pin() + 1 == p2.pin(), "pins must be consecutive"); 469 assert!(p1.pin() + 1 == p2.pin(), "pins must be consecutive");
@@ -749,7 +749,7 @@ impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> {
749 w.set_set_count(1); 749 w.set_set_count(1);
750 }); 750 });
751 // SET PINDIRS, (dir) 751 // SET PINDIRS, (dir)
752 unsafe { sm.exec_instr(0b111_00000_100_00000 | dir as u16) }; 752 unsafe { sm.exec_instr(0b1110_0000_1000_0000 | dir as u16) };
753 } 753 }
754 }); 754 });
755 } 755 }
@@ -764,7 +764,7 @@ impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> {
764 w.set_set_count(1); 764 w.set_set_count(1);
765 }); 765 });
766 // SET PINS, (dir) 766 // SET PINS, (dir)
767 unsafe { sm.exec_instr(0b111_00000_000_00000 | level as u16) }; 767 unsafe { sm.exec_instr(0b1110_0000_0000_0000 | level as u16) };
768 } 768 }
769 }); 769 });
770 } 770 }
@@ -867,9 +867,7 @@ impl<'d, PIO: Instance> Common<'d, PIO> {
867 prog: &Program<SIZE>, 867 prog: &Program<SIZE>,
868 ) -> Result<LoadedProgram<'d, PIO>, LoadError> { 868 ) -> Result<LoadedProgram<'d, PIO>, LoadError> {
869 match prog.origin { 869 match prog.origin {
870 Some(origin) => self 870 Some(origin) => self.try_load_program_at(prog, origin).map_err(LoadError::AddressInUse),
871 .try_load_program_at(prog, origin)
872 .map_err(|a| LoadError::AddressInUse(a)),
873 None => { 871 None => {
874 // naively search for free space, allowing wraparound since 872 // naively search for free space, allowing wraparound since
875 // PIO does support that. with only 32 instruction slots it 873 // PIO does support that. with only 32 instruction slots it
diff --git a/embassy-rp/src/pwm.rs b/embassy-rp/src/pwm.rs
index 784a05f92..e6f3b2aa2 100644
--- a/embassy-rp/src/pwm.rs
+++ b/embassy-rp/src/pwm.rs
@@ -114,8 +114,8 @@ impl<'d, T: Channel> Pwm<'d, T> {
114 } 114 }
115 Self { 115 Self {
116 inner, 116 inner,
117 pin_a: a.into(), 117 pin_a: a,
118 pin_b: b.into(), 118 pin_b: b,
119 } 119 }
120 } 120 }
121 121
@@ -190,7 +190,7 @@ impl<'d, T: Channel> Pwm<'d, T> {
190 } 190 }
191 191
192 fn configure(p: pac::pwm::Channel, config: &Config) { 192 fn configure(p: pac::pwm::Channel, config: &Config) {
193 if config.divider > FixedU16::<fixed::types::extra::U4>::from_bits(0xFF_F) { 193 if config.divider > FixedU16::<fixed::types::extra::U4>::from_bits(0xFFF) {
194 panic!("Requested divider is too large"); 194 panic!("Requested divider is too large");
195 } 195 }
196 196
diff --git a/embassy-rp/src/relocate.rs b/embassy-rp/src/relocate.rs
index b35b4ed72..40cb2667b 100644
--- a/embassy-rp/src/relocate.rs
+++ b/embassy-rp/src/relocate.rs
@@ -22,15 +22,15 @@ where
22{ 22{
23 type Item = u16; 23 type Item = u16;
24 fn next(&mut self) -> Option<Self::Item> { 24 fn next(&mut self) -> Option<Self::Item> {
25 self.iter.next().and_then(|&instr| { 25 self.iter.next().map(|&instr| {
26 Some(if instr & 0b1110_0000_0000_0000 == 0 { 26 if instr & 0b1110_0000_0000_0000 == 0 {
27 // this is a JMP instruction -> add offset to address 27 // this is a JMP instruction -> add offset to address
28 let address = (instr & 0b1_1111) as u8; 28 let address = (instr & 0b1_1111) as u8;
29 let address = address.wrapping_add(self.offset) % 32; 29 let address = address.wrapping_add(self.offset) % 32;
30 instr & (!0b11111) | address as u16 30 instr & (!0b11111) | address as u16
31 } else { 31 } else {
32 instr 32 instr
33 }) 33 }
34 }) 34 })
35 } 35 }
36} 36}
diff --git a/embassy-rp/src/rtc/mod.rs b/embassy-rp/src/rtc/mod.rs
index b696989f5..c8691bdc2 100644
--- a/embassy-rp/src/rtc/mod.rs
+++ b/embassy-rp/src/rtc/mod.rs
@@ -29,8 +29,7 @@ impl<'d, T: Instance> Rtc<'d, T> {
29 // Set the RTC divider 29 // Set the RTC divider
30 inner.regs().clkdiv_m1().write(|w| w.set_clkdiv_m1(clk_rtc_freq() - 1)); 30 inner.regs().clkdiv_m1().write(|w| w.set_clkdiv_m1(clk_rtc_freq() - 1));
31 31
32 let result = Self { inner }; 32 Self { inner }
33 result
34 } 33 }
35 34
36 /// Enable or disable the leap year check. The rp2040 chip will always add a Feb 29th on every year that is divisable by 4, but this may be incorrect (e.g. on century years). This function allows you to disable this check. 35 /// Enable or disable the leap year check. The rp2040 chip will always add a Feb 29th on every year that is divisable by 4, but this may be incorrect (e.g. on century years). This function allows you to disable this check.
diff --git a/embassy-rp/src/uart/buffered.rs b/embassy-rp/src/uart/buffered.rs
index 99c958129..7622539f1 100644
--- a/embassy-rp/src/uart/buffered.rs
+++ b/embassy-rp/src/uart/buffered.rs
@@ -467,7 +467,7 @@ impl<'d, T: Instance> Drop for BufferedUartRx<'d, T> {
467 467
468 // TX is inactive if the the buffer is not available. 468 // TX is inactive if the the buffer is not available.
469 // We can now unregister the interrupt handler 469 // We can now unregister the interrupt handler
470 if state.tx_buf.len() == 0 { 470 if state.tx_buf.is_empty() {
471 T::Interrupt::disable(); 471 T::Interrupt::disable();
472 } 472 }
473 } 473 }
@@ -480,7 +480,7 @@ impl<'d, T: Instance> Drop for BufferedUartTx<'d, T> {
480 480
481 // RX is inactive if the the buffer is not available. 481 // RX is inactive if the the buffer is not available.
482 // We can now unregister the interrupt handler 482 // We can now unregister the interrupt handler
483 if state.rx_buf.len() == 0 { 483 if state.rx_buf.is_empty() {
484 T::Interrupt::disable(); 484 T::Interrupt::disable();
485 } 485 }
486 } 486 }
diff --git a/embassy-rp/src/uart/mod.rs b/embassy-rp/src/uart/mod.rs
index f372cb640..65dcf4eb4 100644
--- a/embassy-rp/src/uart/mod.rs
+++ b/embassy-rp/src/uart/mod.rs
@@ -322,7 +322,7 @@ impl<'d, T: Instance, M: Mode> UartRx<'d, T, M> {
322 322
323impl<'d, T: Instance, M: Mode> Drop for UartRx<'d, T, M> { 323impl<'d, T: Instance, M: Mode> Drop for UartRx<'d, T, M> {
324 fn drop(&mut self) { 324 fn drop(&mut self) {
325 if let Some(_) = self.rx_dma { 325 if self.rx_dma.is_some() {
326 T::Interrupt::disable(); 326 T::Interrupt::disable();
327 // clear dma flags. irq handlers use these to disambiguate among themselves. 327 // clear dma flags. irq handlers use these to disambiguate among themselves.
328 T::regs().uartdmacr().write_clear(|reg| { 328 T::regs().uartdmacr().write_clear(|reg| {