mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-12-11 08:02:34 +00:00
Use inline const for initializing arrays. (#3567)
This commit is contained in:
parent
b9408f0510
commit
aaad8450e9
@ -26,13 +26,11 @@ pub struct State<const MTU: usize, const N_RX: usize, const N_TX: usize> {
|
||||
}
|
||||
|
||||
impl<const MTU: usize, const N_RX: usize, const N_TX: usize> State<MTU, N_RX, N_TX> {
|
||||
const NEW_PACKET: PacketBuf<MTU> = PacketBuf::new();
|
||||
|
||||
/// Create a new channel state.
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
rx: [Self::NEW_PACKET; N_RX],
|
||||
tx: [Self::NEW_PACKET; N_TX],
|
||||
rx: [const { PacketBuf::new() }; N_RX],
|
||||
tx: [const { PacketBuf::new() }; N_TX],
|
||||
inner: MaybeUninit::uninit(),
|
||||
}
|
||||
}
|
||||
|
@ -29,9 +29,8 @@ const PIN_COUNT: usize = 48;
|
||||
const PIN_COUNT: usize = 32;
|
||||
|
||||
#[allow(clippy::declare_interior_mutable_const)]
|
||||
const NEW_AW: AtomicWaker = AtomicWaker::new();
|
||||
static CHANNEL_WAKERS: [AtomicWaker; CHANNEL_COUNT] = [NEW_AW; CHANNEL_COUNT];
|
||||
static PORT_WAKERS: [AtomicWaker; PIN_COUNT] = [NEW_AW; PIN_COUNT];
|
||||
static CHANNEL_WAKERS: [AtomicWaker; CHANNEL_COUNT] = [const { AtomicWaker::new() }; CHANNEL_COUNT];
|
||||
static PORT_WAKERS: [AtomicWaker; PIN_COUNT] = [const { AtomicWaker::new() }; PIN_COUNT];
|
||||
|
||||
/// Polarity for listening to events for GPIOTE input channels.
|
||||
pub enum InputChannelPolarity {
|
||||
|
@ -123,11 +123,10 @@ struct RtcDriver {
|
||||
alarms: Mutex<[AlarmState; ALARM_COUNT]>,
|
||||
}
|
||||
|
||||
const ALARM_STATE_NEW: AlarmState = AlarmState::new();
|
||||
embassy_time_driver::time_driver_impl!(static DRIVER: RtcDriver = RtcDriver {
|
||||
period: AtomicU32::new(0),
|
||||
alarm_count: AtomicU8::new(0),
|
||||
alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [ALARM_STATE_NEW; ALARM_COUNT]),
|
||||
alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [const {AlarmState::new()}; ALARM_COUNT]),
|
||||
});
|
||||
|
||||
impl RtcDriver {
|
||||
|
@ -22,11 +22,10 @@ use crate::pac::usbd::vals;
|
||||
use crate::util::slice_in_ram;
|
||||
use crate::{interrupt, pac, Peripheral};
|
||||
|
||||
const NEW_AW: AtomicWaker = AtomicWaker::new();
|
||||
static BUS_WAKER: AtomicWaker = NEW_AW;
|
||||
static EP0_WAKER: AtomicWaker = NEW_AW;
|
||||
static EP_IN_WAKERS: [AtomicWaker; 8] = [NEW_AW; 8];
|
||||
static EP_OUT_WAKERS: [AtomicWaker; 8] = [NEW_AW; 8];
|
||||
static BUS_WAKER: AtomicWaker = AtomicWaker::new();
|
||||
static EP0_WAKER: AtomicWaker = AtomicWaker::new();
|
||||
static EP_IN_WAKERS: [AtomicWaker; 8] = [const { AtomicWaker::new() }; 8];
|
||||
static EP_OUT_WAKERS: [AtomicWaker; 8] = [const { AtomicWaker::new() }; 8];
|
||||
static READY_ENDPOINTS: AtomicU32 = AtomicU32::new(0);
|
||||
|
||||
/// Interrupt handler.
|
||||
|
@ -112,8 +112,7 @@ impl Watchdog {
|
||||
|
||||
let this = Self { _private: () };
|
||||
|
||||
const DUMMY_HANDLE: WatchdogHandle = WatchdogHandle { index: 0 };
|
||||
let mut handles = [DUMMY_HANDLE; N];
|
||||
let mut handles = [const { WatchdogHandle { index: 0 } }; N];
|
||||
for i in 0..N {
|
||||
handles[i] = WatchdogHandle { index: i as u8 };
|
||||
handles[i].pet();
|
||||
|
@ -52,14 +52,16 @@ impl PinInterrupt {
|
||||
}
|
||||
}
|
||||
|
||||
const NEW_PIN_INTERRUPT: PinInterrupt = PinInterrupt {
|
||||
assigned: false,
|
||||
waker: AtomicWaker::new(),
|
||||
at_fault: false,
|
||||
};
|
||||
const INTERUPT_COUNT: usize = 8;
|
||||
static PIN_INTERRUPTS: Mutex<RefCell<[PinInterrupt; INTERUPT_COUNT]>> =
|
||||
Mutex::new(RefCell::new([NEW_PIN_INTERRUPT; INTERUPT_COUNT]));
|
||||
static PIN_INTERRUPTS: Mutex<RefCell<[PinInterrupt; INTERUPT_COUNT]>> = Mutex::new(RefCell::new(
|
||||
[const {
|
||||
PinInterrupt {
|
||||
assigned: false,
|
||||
waker: AtomicWaker::new(),
|
||||
at_fault: false,
|
||||
}
|
||||
}; INTERUPT_COUNT],
|
||||
));
|
||||
|
||||
fn next_available_interrupt() -> Option<usize> {
|
||||
critical_section::with(|cs| {
|
||||
|
@ -212,8 +212,7 @@ impl<'a, C: Channel> Future for Transfer<'a, C> {
|
||||
pub(crate) const CHANNEL_COUNT: usize = 12;
|
||||
#[cfg(feature = "_rp235x")]
|
||||
pub(crate) const CHANNEL_COUNT: usize = 16;
|
||||
const NEW_AW: AtomicWaker = AtomicWaker::new();
|
||||
static CHANNEL_WAKERS: [AtomicWaker; CHANNEL_COUNT] = [NEW_AW; CHANNEL_COUNT];
|
||||
static CHANNEL_WAKERS: [AtomicWaker; CHANNEL_COUNT] = [const { AtomicWaker::new() }; CHANNEL_COUNT];
|
||||
|
||||
trait SealedChannel {}
|
||||
trait SealedWord {}
|
||||
|
@ -13,18 +13,16 @@ use crate::pac::common::{Reg, RW};
|
||||
use crate::pac::SIO;
|
||||
use crate::{interrupt, pac, peripherals, Peripheral, RegExt};
|
||||
|
||||
const NEW_AW: AtomicWaker = AtomicWaker::new();
|
||||
|
||||
#[cfg(any(feature = "rp2040", feature = "rp235xa"))]
|
||||
pub(crate) const BANK0_PIN_COUNT: usize = 30;
|
||||
#[cfg(feature = "rp235xb")]
|
||||
pub(crate) const BANK0_PIN_COUNT: usize = 48;
|
||||
|
||||
static BANK0_WAKERS: [AtomicWaker; BANK0_PIN_COUNT] = [NEW_AW; BANK0_PIN_COUNT];
|
||||
static BANK0_WAKERS: [AtomicWaker; BANK0_PIN_COUNT] = [const { AtomicWaker::new() }; BANK0_PIN_COUNT];
|
||||
#[cfg(feature = "qspi-as-gpio")]
|
||||
const QSPI_PIN_COUNT: usize = 6;
|
||||
#[cfg(feature = "qspi-as-gpio")]
|
||||
static QSPI_WAKERS: [AtomicWaker; QSPI_PIN_COUNT] = [NEW_AW; QSPI_PIN_COUNT];
|
||||
static QSPI_WAKERS: [AtomicWaker; QSPI_PIN_COUNT] = [const { AtomicWaker::new() }; QSPI_PIN_COUNT];
|
||||
|
||||
/// Represents a digital input or output level.
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
|
||||
|
@ -1270,9 +1270,7 @@ trait SealedInstance {
|
||||
|
||||
#[inline]
|
||||
fn wakers() -> &'static Wakers {
|
||||
const NEW_AW: AtomicWaker = AtomicWaker::new();
|
||||
static WAKERS: Wakers = Wakers([NEW_AW; 12]);
|
||||
|
||||
static WAKERS: Wakers = Wakers([const { AtomicWaker::new() }; 12]);
|
||||
&WAKERS
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,6 @@ struct AlarmState {
|
||||
unsafe impl Send for AlarmState {}
|
||||
|
||||
const ALARM_COUNT: usize = 4;
|
||||
const DUMMY_ALARM: AlarmState = AlarmState {
|
||||
timestamp: Cell::new(0),
|
||||
callback: Cell::new(None),
|
||||
};
|
||||
|
||||
struct TimerDriver {
|
||||
alarms: Mutex<CriticalSectionRawMutex, [AlarmState; ALARM_COUNT]>,
|
||||
@ -32,7 +28,10 @@ struct TimerDriver {
|
||||
}
|
||||
|
||||
embassy_time_driver::time_driver_impl!(static DRIVER: TimerDriver = TimerDriver{
|
||||
alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [DUMMY_ALARM; ALARM_COUNT]),
|
||||
alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [const{AlarmState {
|
||||
timestamp: Cell::new(0),
|
||||
callback: Cell::new(None),
|
||||
}}; ALARM_COUNT]),
|
||||
next_alarm: AtomicU8::new(0),
|
||||
});
|
||||
|
||||
|
@ -43,10 +43,9 @@ const EP_COUNT: usize = 16;
|
||||
const EP_MEMORY_SIZE: usize = 4096;
|
||||
const EP_MEMORY: *mut u8 = pac::USB_DPRAM.as_ptr() as *mut u8;
|
||||
|
||||
const NEW_AW: AtomicWaker = AtomicWaker::new();
|
||||
static BUS_WAKER: AtomicWaker = NEW_AW;
|
||||
static EP_IN_WAKERS: [AtomicWaker; EP_COUNT] = [NEW_AW; EP_COUNT];
|
||||
static EP_OUT_WAKERS: [AtomicWaker; EP_COUNT] = [NEW_AW; EP_COUNT];
|
||||
static BUS_WAKER: AtomicWaker = AtomicWaker::new();
|
||||
static EP_IN_WAKERS: [AtomicWaker; EP_COUNT] = [const { AtomicWaker::new() }; EP_COUNT];
|
||||
static EP_OUT_WAKERS: [AtomicWaker; EP_COUNT] = [const { AtomicWaker::new() }; EP_COUNT];
|
||||
|
||||
struct EndpointBuffer<T: Instance> {
|
||||
addr: u16,
|
||||
|
@ -42,11 +42,9 @@ pub struct PacketQueue<const TX: usize, const RX: usize> {
|
||||
impl<const TX: usize, const RX: usize> PacketQueue<TX, RX> {
|
||||
/// Create a new packet queue.
|
||||
pub const fn new() -> Self {
|
||||
const NEW_TDES: TDes = TDes::new();
|
||||
const NEW_RDES: RDes = RDes::new();
|
||||
Self {
|
||||
tx_desc: [NEW_TDES; TX],
|
||||
rx_desc: [NEW_RDES; RX],
|
||||
tx_desc: [const { TDes::new() }; TX],
|
||||
rx_desc: [const { RDes::new() }; RX],
|
||||
tx_buf: [Packet([0; TX_BUFFER_SIZE]); TX],
|
||||
rx_buf: [Packet([0; RX_BUFFER_SIZE]); RX],
|
||||
}
|
||||
|
@ -14,8 +14,7 @@ use crate::pac::EXTI;
|
||||
use crate::{interrupt, pac, peripherals, Peripheral};
|
||||
|
||||
const EXTI_COUNT: usize = 16;
|
||||
const NEW_AW: AtomicWaker = AtomicWaker::new();
|
||||
static EXTI_WAKERS: [AtomicWaker; EXTI_COUNT] = [NEW_AW; EXTI_COUNT];
|
||||
static EXTI_WAKERS: [AtomicWaker; EXTI_COUNT] = [const { AtomicWaker::new() }; EXTI_COUNT];
|
||||
|
||||
#[cfg(exti_w)]
|
||||
fn cpu_regs() -> pac::exti::Cpu {
|
||||
|
@ -229,11 +229,9 @@ struct State {
|
||||
|
||||
impl State {
|
||||
const fn new() -> Self {
|
||||
const WAKER: AtomicWaker = AtomicWaker::new();
|
||||
|
||||
Self {
|
||||
rx_wakers: [WAKER; 6],
|
||||
tx_wakers: [WAKER; 6],
|
||||
rx_wakers: [const { AtomicWaker::new() }; 6],
|
||||
tx_wakers: [const { AtomicWaker::new() }; 6],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -261,13 +261,10 @@ pub(crate) struct RtcDriver {
|
||||
rtc: Mutex<CriticalSectionRawMutex, Cell<Option<&'static Rtc>>>,
|
||||
}
|
||||
|
||||
#[allow(clippy::declare_interior_mutable_const)]
|
||||
const ALARM_STATE_NEW: AlarmState = AlarmState::new();
|
||||
|
||||
embassy_time_driver::time_driver_impl!(static DRIVER: RtcDriver = RtcDriver {
|
||||
period: AtomicU32::new(0),
|
||||
alarm_count: AtomicU8::new(0),
|
||||
alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [ALARM_STATE_NEW; ALARM_COUNT]),
|
||||
alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [const{AlarmState::new()}; ALARM_COUNT]),
|
||||
#[cfg(feature = "low-power")]
|
||||
rtc: Mutex::const_new(CriticalSectionRawMutex::new(), Cell::new(None)),
|
||||
});
|
||||
|
@ -59,10 +59,9 @@ struct State {
|
||||
|
||||
impl State {
|
||||
const fn new() -> Self {
|
||||
const NEW_AW: AtomicWaker = AtomicWaker::new();
|
||||
Self {
|
||||
up_waker: NEW_AW,
|
||||
cc_waker: [NEW_AW; 4],
|
||||
up_waker: AtomicWaker::new(),
|
||||
cc_waker: [const { AtomicWaker::new() }; 4],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -119,15 +119,12 @@ const USBRAM_ALIGN: usize = 2;
|
||||
#[cfg(any(usbram_32_2048, usbram_32_1024))]
|
||||
const USBRAM_ALIGN: usize = 4;
|
||||
|
||||
const NEW_AW: AtomicWaker = AtomicWaker::new();
|
||||
static BUS_WAKER: AtomicWaker = NEW_AW;
|
||||
static BUS_WAKER: AtomicWaker = AtomicWaker::new();
|
||||
static EP0_SETUP: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
const NEW_CTR_TRIGGERED: AtomicBool = AtomicBool::new(false);
|
||||
static CTR_TRIGGERED: [AtomicBool; EP_COUNT] = [NEW_CTR_TRIGGERED; EP_COUNT];
|
||||
|
||||
static EP_IN_WAKERS: [AtomicWaker; EP_COUNT] = [NEW_AW; EP_COUNT];
|
||||
static EP_OUT_WAKERS: [AtomicWaker; EP_COUNT] = [NEW_AW; EP_COUNT];
|
||||
static CTR_TRIGGERED: [AtomicBool; EP_COUNT] = [const { AtomicBool::new(false) }; EP_COUNT];
|
||||
static EP_IN_WAKERS: [AtomicWaker; EP_COUNT] = [const { AtomicWaker::new() }; EP_COUNT];
|
||||
static EP_OUT_WAKERS: [AtomicWaker; EP_COUNT] = [const { AtomicWaker::new() }; EP_COUNT];
|
||||
static IRQ_RESET: AtomicBool = AtomicBool::new(false);
|
||||
static IRQ_SUSPEND: AtomicBool = AtomicBool::new(false);
|
||||
static IRQ_RESUME: AtomicBool = AtomicBool::new(false);
|
||||
|
@ -43,7 +43,6 @@ struct TimeDriver {
|
||||
signaler: UninitCell<Signaler>,
|
||||
}
|
||||
|
||||
const ALARM_NEW: AlarmState = AlarmState::new();
|
||||
embassy_time_driver::time_driver_impl!(static DRIVER: TimeDriver = TimeDriver {
|
||||
alarm_count: AtomicU8::new(0),
|
||||
|
||||
@ -56,7 +55,8 @@ embassy_time_driver::time_driver_impl!(static DRIVER: TimeDriver = TimeDriver {
|
||||
impl TimeDriver {
|
||||
fn init(&self) {
|
||||
self.once.call_once(|| unsafe {
|
||||
self.alarms.write(CsMutex::new(RefCell::new([ALARM_NEW; ALARM_COUNT])));
|
||||
self.alarms
|
||||
.write(CsMutex::new(RefCell::new([const { AlarmState::new() }; ALARM_COUNT])));
|
||||
self.zero_instant.write(StdInstant::now());
|
||||
self.signaler.write(Signaler::new());
|
||||
|
||||
|
@ -40,7 +40,6 @@ struct TimeDriver {
|
||||
zero_instant: UninitCell<StdInstant>,
|
||||
}
|
||||
|
||||
const ALARM_NEW: AlarmState = AlarmState::new();
|
||||
embassy_time_driver::time_driver_impl!(static DRIVER: TimeDriver = TimeDriver {
|
||||
alarm_count: AtomicU8::new(0),
|
||||
once: Once::new(),
|
||||
@ -51,7 +50,8 @@ embassy_time_driver::time_driver_impl!(static DRIVER: TimeDriver = TimeDriver {
|
||||
impl TimeDriver {
|
||||
fn init(&self) {
|
||||
self.once.call_once(|| unsafe {
|
||||
self.alarms.write(Mutex::new([ALARM_NEW; ALARM_COUNT]));
|
||||
self.alarms
|
||||
.write(Mutex::new([const { AlarmState::new() }; ALARM_COUNT]));
|
||||
self.zero_instant.write(StdInstant::now());
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user