diff --git a/cyw43/src/events.rs b/cyw43/src/events.rs index 44bfa98e9..2a78b38c3 100644 --- a/cyw43/src/events.rs +++ b/cyw43/src/events.rs @@ -296,10 +296,10 @@ pub struct Events { } impl Events { - pub fn new() -> Self { + pub const fn new() -> Self { Self { queue: EventQueue::new(), - mask: SharedEventMask::default(), + mask: SharedEventMask::new(), } } } @@ -333,7 +333,6 @@ impl Message { } } -#[derive(Default)] struct EventMask { mask: [u32; Self::WORD_COUNT], } @@ -341,6 +340,12 @@ struct EventMask { impl EventMask { const WORD_COUNT: usize = ((Event::LAST as u32 + (u32::BITS - 1)) / u32::BITS) as usize; + const fn new() -> Self { + Self { + mask: [0; Self::WORD_COUNT], + } + } + fn enable(&mut self, event: Event) { let n = event as u32; let word = n / u32::BITS; @@ -366,13 +371,17 @@ impl EventMask { } } -#[derive(Default)] - pub struct SharedEventMask { mask: RefCell, } impl SharedEventMask { + pub const fn new() -> Self { + Self { + mask: RefCell::new(EventMask::new()), + } + } + pub fn enable(&self, events: &[Event]) { let mut mask = self.mask.borrow_mut(); for event in events { @@ -398,3 +407,9 @@ impl SharedEventMask { mask.is_enabled(event) } } + +impl Default for SharedEventMask { + fn default() -> Self { + Self::new() + } +} diff --git a/cyw43/src/ioctl.rs b/cyw43/src/ioctl.rs index af8bb695b..35135e296 100644 --- a/cyw43/src/ioctl.rs +++ b/cyw43/src/ioctl.rs @@ -33,8 +33,8 @@ struct Wakers { runner: WakerRegistration, } -impl Default for Wakers { - fn default() -> Self { +impl Wakers { + const fn new() -> Self { Self { control: WakerRegistration::new(), runner: WakerRegistration::new(), @@ -48,10 +48,10 @@ pub struct IoctlState { } impl IoctlState { - pub fn new() -> Self { + pub const fn new() -> Self { Self { state: Cell::new(IoctlStateInner::Done { resp_len: 0 }), - wakers: Default::default(), + wakers: RefCell::new(Wakers::new()), } } diff --git a/cyw43/src/lib.rs b/cyw43/src/lib.rs index aab13d8b8..16b436e66 100644 --- a/cyw43/src/lib.rs +++ b/cyw43/src/lib.rs @@ -124,7 +124,7 @@ struct NetState { impl State { /// Create new driver state holder. - pub fn new() -> Self { + pub const fn new() -> Self { Self { ioctl_state: IoctlState::new(), net: NetState {