From b46447bb2fdde3e4e621be0476e6cbcbac1e2fdc Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Sun, 3 Mar 2024 08:43:58 +0000 Subject: [PATCH 1/2] Implement Default for structs which have a no-argument new() constructor --- rp2040-hal/src/async_utils.rs | 7 +++++++ rp2040-hal/src/multicore.rs | 6 ++++++ rp2040-hal/src/sio.rs | 6 ++++++ rp2040-hal/src/vector_table.rs | 6 ++++++ 4 files changed, 25 insertions(+) diff --git a/rp2040-hal/src/async_utils.rs b/rp2040-hal/src/async_utils.rs index 54421ed2c..3bfee7233 100644 --- a/rp2040-hal/src/async_utils.rs +++ b/rp2040-hal/src/async_utils.rs @@ -21,6 +21,13 @@ pub(crate) mod sealed { pub struct IrqWaker { waker: Mutex>>, } + + impl Default for IrqWaker { + fn default() -> Self { + Self::new() + } + } + impl IrqWaker { pub const fn new() -> Self { Self { diff --git a/rp2040-hal/src/multicore.rs b/rp2040-hal/src/multicore.rs index efc0da950..d1b018402 100644 --- a/rp2040-hal/src/multicore.rs +++ b/rp2040-hal/src/multicore.rs @@ -96,6 +96,12 @@ pub struct Stack { pub mem: [usize; SIZE], } +impl Default for Stack { + fn default() -> Self { + Self::new() + } +} + impl Stack { /// Construct a stack of length SIZE, initialized to 0 pub const fn new() -> Stack { diff --git a/rp2040-hal/src/sio.rs b/rp2040-hal/src/sio.rs index 6cc516b65..5a562d6df 100644 --- a/rp2040-hal/src/sio.rs +++ b/rp2040-hal/src/sio.rs @@ -626,6 +626,12 @@ pub struct LaneCtrl { pub shift: u8, } +impl Default for LaneCtrl { + fn default() -> Self { + Self::new() + } +} + impl LaneCtrl { /// Default configuration. Normal operation, unsigned, mask keeps all bits, no shift. pub const fn new() -> Self { diff --git a/rp2040-hal/src/vector_table.rs b/rp2040-hal/src/vector_table.rs index 8bc33a78e..432fea00d 100644 --- a/rp2040-hal/src/vector_table.rs +++ b/rp2040-hal/src/vector_table.rs @@ -30,6 +30,12 @@ pub struct VectorTable { table: [Vector; 48], } +impl Default for VectorTable { + fn default() -> Self { + Self::new() + } +} + impl VectorTable { /// Create a new vector table. All entries will point to 0 - you must call init() /// on this to copy the current vector table before setting it as active From 745c9dcef3f97e66f9eb99d497c1594a24fff342 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Sun, 3 Mar 2024 08:54:21 +0000 Subject: [PATCH 2/2] Remove redundant imports --- rp2040-hal/src/clocks/clock_sources.rs | 4 ---- rp2040-hal/src/pll.rs | 2 +- rp2040-hal/src/rtc/datetime.rs | 2 +- rp2040-hal/src/usb.rs | 2 +- rp2040-hal/src/xosc.rs | 1 - 5 files changed, 3 insertions(+), 8 deletions(-) diff --git a/rp2040-hal/src/clocks/clock_sources.rs b/rp2040-hal/src/clocks/clock_sources.rs index c399f5766..8189d757a 100644 --- a/rp2040-hal/src/clocks/clock_sources.rs +++ b/rp2040-hal/src/clocks/clock_sources.rs @@ -6,12 +6,8 @@ use crate::{ bank0::{Gpio20, Gpio22}, FunctionClock, Pin, PullNone, PullType, }, - pll::{Locked, PhaseLockedLoop}, rosc::{Enabled, RingOscillator}, - typelevel::Sealed, - xosc::{CrystalOscillator, Stable}, }; -use pac::{PLL_SYS, PLL_USB}; pub(crate) type PllSys = PhaseLockedLoop; impl Sealed for PllSys {} diff --git a/rp2040-hal/src/pll.rs b/rp2040-hal/src/pll.rs index dbff55a80..2255cd39b 100644 --- a/rp2040-hal/src/pll.rs +++ b/rp2040-hal/src/pll.rs @@ -2,7 +2,7 @@ // See [Chapter 2 Section 18](https://datasheets.raspberrypi.org/rp2040/rp2040_datasheet.pdf) for more details use core::{ - convert::{Infallible, TryInto}, + convert::Infallible, marker::PhantomData, ops::{Deref, Range, RangeInclusive}, }; diff --git a/rp2040-hal/src/rtc/datetime.rs b/rp2040-hal/src/rtc/datetime.rs index 6697e62ec..48f078098 100644 --- a/rp2040-hal/src/rtc/datetime.rs +++ b/rp2040-hal/src/rtc/datetime.rs @@ -34,7 +34,7 @@ pub struct DateTime { pub month: u8, /// 1..28,29,30,31 depending on month pub day: u8, - /// + /// The day of week pub day_of_week: DayOfWeek, /// 0..23 pub hour: u8, diff --git a/rp2040-hal/src/usb.rs b/rp2040-hal/src/usb.rs index 839f65daf..3f2f9f375 100644 --- a/rp2040-hal/src/usb.rs +++ b/rp2040-hal/src/usb.rs @@ -106,7 +106,7 @@ //! ``` use core::cell::RefCell; -use critical_section::{self, Mutex}; +use critical_section::Mutex; use usb_device::{ bus::{PollResult, UsbBus as UsbBusTrait}, diff --git a/rp2040-hal/src/xosc.rs b/rp2040-hal/src/xosc.rs index 2252a4e58..1c2ec68ac 100644 --- a/rp2040-hal/src/xosc.rs +++ b/rp2040-hal/src/xosc.rs @@ -1,7 +1,6 @@ //! Crystal Oscillator (XOSC) // See [Chapter 2 Section 16](https://datasheets.raspberrypi.org/rp2040/rp2040_datasheet.pdf) for more details -use core::convert::TryInto; use core::{convert::Infallible, ops::RangeInclusive}; use fugit::HertzU32;