diff options
| author | Davide Della Giustina <[email protected]> | 2023-02-28 17:39:02 +0000 |
|---|---|---|
| committer | Davide Della Giustina <[email protected]> | 2023-02-28 17:39:02 +0000 |
| commit | 485bb76e467aaa2522907bcb1bad538b4374d672 (patch) | |
| tree | 13ad8edbb054ce1beb9fd00f02753f888651810c | |
| parent | c1e93c0904706a7497046ba25d82fcfda6576734 (diff) | |
Implemented suggestions from @Dirbaio
| -rw-r--r-- | embassy-stm32/src/eth/mod.rs | 43 | ||||
| -rw-r--r-- | embassy-stm32/src/lib.rs | 8 |
2 files changed, 11 insertions, 40 deletions
diff --git a/embassy-stm32/src/eth/mod.rs b/embassy-stm32/src/eth/mod.rs index 04c74e605..89d2c5a3d 100644 --- a/embassy-stm32/src/eth/mod.rs +++ b/embassy-stm32/src/eth/mod.rs | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | mod _version; | 5 | mod _version; |
| 6 | pub mod generic_smi; | 6 | pub mod generic_smi; |
| 7 | 7 | ||
| 8 | use core::mem::MaybeUninit; | ||
| 8 | use core::task::Context; | 9 | use core::task::Context; |
| 9 | 10 | ||
| 10 | use embassy_net_driver::{Capabilities, LinkState}; | 11 | use embassy_net_driver::{Capabilities, LinkState}; |
| @@ -30,43 +31,19 @@ pub struct PacketQueue<const TX: usize, const RX: usize> { | |||
| 30 | 31 | ||
| 31 | impl<const TX: usize, const RX: usize> PacketQueue<TX, RX> { | 32 | impl<const TX: usize, const RX: usize> PacketQueue<TX, RX> { |
| 32 | pub const fn new() -> Self { | 33 | pub const fn new() -> Self { |
| 33 | #[cfg(feature = "nightly")] | 34 | const NEW_TDES: TDes = TDes::new(); |
| 34 | { | 35 | const NEW_RDES: RDes = RDes::new(); |
| 35 | let mut this = core::mem::MaybeUninit::uninit(); | 36 | Self { |
| 36 | unsafe { | 37 | tx_desc: [NEW_TDES; TX], |
| 37 | Self::init(&mut this); | 38 | rx_desc: [NEW_RDES; RX], |
| 38 | this.assume_init() | 39 | tx_buf: [Packet([0; TX_BUFFER_SIZE]); TX], |
| 39 | } | 40 | rx_buf: [Packet([0; RX_BUFFER_SIZE]); RX], |
| 40 | } | ||
| 41 | #[cfg(not(feature = "nightly"))] | ||
| 42 | { | ||
| 43 | const NEW_TDES: TDes = TDes::new(); | ||
| 44 | const NEW_RDES: RDes = RDes::new(); | ||
| 45 | Self { | ||
| 46 | tx_desc: [NEW_TDES; TX], | ||
| 47 | rx_desc: [NEW_RDES; RX], | ||
| 48 | tx_buf: [Packet([0; TX_BUFFER_SIZE]); TX], | ||
| 49 | rx_buf: [Packet([0; RX_BUFFER_SIZE]); RX], | ||
| 50 | } | ||
| 51 | } | 41 | } |
| 52 | } | 42 | } |
| 53 | 43 | ||
| 54 | // Allow to initialize a Self without requiring it to go on the stack | 44 | // Allow to initialize a Self without requiring it to go on the stack |
| 55 | #[cfg(feature = "nightly")] | 45 | pub unsafe fn init(this: &mut MaybeUninit<Self>) { |
| 56 | pub const unsafe fn init(this: &mut core::mem::MaybeUninit<Self>) { | 46 | this.as_mut_ptr().write_bytes(0u8, core::mem::size_of::<Self>()); |
| 57 | let this: &mut Self = unsafe { this.assume_init_mut() }; | ||
| 58 | let mut i = 0; | ||
| 59 | while i < TX { | ||
| 60 | this.tx_desc[i] = TDes::new(); | ||
| 61 | this.tx_buf[i] = Packet([0; TX_BUFFER_SIZE]); | ||
| 62 | i += 1; | ||
| 63 | } | ||
| 64 | i = 0; | ||
| 65 | while i < RX { | ||
| 66 | this.rx_desc[i] = RDes::new(); | ||
| 67 | this.rx_buf[i] = Packet([0; RX_BUFFER_SIZE]); | ||
| 68 | i += 1; | ||
| 69 | } | ||
| 70 | } | 47 | } |
| 71 | } | 48 | } |
| 72 | 49 | ||
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 7c0b2d516..eeaa04f67 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs | |||
| @@ -1,13 +1,7 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![cfg_attr( | 2 | #![cfg_attr( |
| 3 | feature = "nightly", | 3 | feature = "nightly", |
| 4 | feature( | 4 | feature(type_alias_impl_trait, async_fn_in_trait, impl_trait_projections) |
| 5 | type_alias_impl_trait, | ||
| 6 | async_fn_in_trait, | ||
| 7 | impl_trait_projections, | ||
| 8 | const_mut_refs, | ||
| 9 | const_maybe_uninit_assume_init | ||
| 10 | ) | ||
| 11 | )] | 5 | )] |
| 12 | #![cfg_attr(feature = "nightly", allow(incomplete_features))] | 6 | #![cfg_attr(feature = "nightly", allow(incomplete_features))] |
| 13 | 7 | ||
