mirror of
https://github.com/embassy-rs/embassy.git
synced 2025-09-27 12:20:37 +00:00
cyw43: make State::new a const fn
This commit is contained in:
parent
659c616f9f
commit
db83d7275e
@ -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<EventMask>,
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user