diff options
| author | Frostie314159 <[email protected]> | 2024-03-31 20:48:05 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-03-31 20:48:05 +0200 |
| commit | 67c9cc2c4b886e6962ecdd6eff8794b14c1accdc (patch) | |
| tree | f176ab269949d26f48e04c950cebc5489bae8c56 /embassy-hal-internal/src | |
| parent | a2f9aa592ec61beb247065003016515f0d423c13 (diff) | |
| parent | 6634cc90bcd3eb25b64712688920f383584b2964 (diff) | |
Merge branch 'embassy-rs:main' into ticker_send_sync
Diffstat (limited to 'embassy-hal-internal/src')
| -rw-r--r-- | embassy-hal-internal/src/atomic_ring_buffer.rs | 33 | ||||
| -rw-r--r-- | embassy-hal-internal/src/fmt.rs | 3 | ||||
| -rw-r--r-- | embassy-hal-internal/src/interrupt.rs | 8 | ||||
| -rw-r--r-- | embassy-hal-internal/src/peripheral.rs | 11 |
4 files changed, 36 insertions, 19 deletions
diff --git a/embassy-hal-internal/src/atomic_ring_buffer.rs b/embassy-hal-internal/src/atomic_ring_buffer.rs index b4f2cec28..34ceac852 100644 --- a/embassy-hal-internal/src/atomic_ring_buffer.rs +++ b/embassy-hal-internal/src/atomic_ring_buffer.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | //! Atomic reusable ringbuffer. | 1 | //! Atomic reusable ringbuffer. |
| 2 | use core::slice; | ||
| 3 | use core::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; | 2 | use core::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; |
| 3 | use core::{ptr, slice}; | ||
| 4 | 4 | ||
| 5 | /// Atomic reusable ringbuffer | 5 | /// Atomic reusable ringbuffer |
| 6 | /// | 6 | /// |
| @@ -73,6 +73,7 @@ impl RingBuffer { | |||
| 73 | pub unsafe fn deinit(&self) { | 73 | pub unsafe fn deinit(&self) { |
| 74 | // Ordering: it's OK to use `Relaxed` because this is not called | 74 | // Ordering: it's OK to use `Relaxed` because this is not called |
| 75 | // concurrently with other methods. | 75 | // concurrently with other methods. |
| 76 | self.buf.store(ptr::null_mut(), Ordering::Relaxed); | ||
| 76 | self.len.store(0, Ordering::Relaxed); | 77 | self.len.store(0, Ordering::Relaxed); |
| 77 | self.start.store(0, Ordering::Relaxed); | 78 | self.start.store(0, Ordering::Relaxed); |
| 78 | self.end.store(0, Ordering::Relaxed); | 79 | self.end.store(0, Ordering::Relaxed); |
| @@ -82,20 +83,46 @@ impl RingBuffer { | |||
| 82 | /// | 83 | /// |
| 83 | /// # Safety | 84 | /// # Safety |
| 84 | /// | 85 | /// |
| 85 | /// Only one reader can exist at a time. | 86 | /// - Only one reader can exist at a time. |
| 87 | /// - Ringbuffer must be initialized. | ||
| 86 | pub unsafe fn reader(&self) -> Reader<'_> { | 88 | pub unsafe fn reader(&self) -> Reader<'_> { |
| 87 | Reader(self) | 89 | Reader(self) |
| 88 | } | 90 | } |
| 89 | 91 | ||
| 92 | /// Try creating a reader, fails if not initialized. | ||
| 93 | /// | ||
| 94 | /// # Safety | ||
| 95 | /// | ||
| 96 | /// Only one reader can exist at a time. | ||
| 97 | pub unsafe fn try_reader(&self) -> Option<Reader<'_>> { | ||
| 98 | if self.buf.load(Ordering::Relaxed).is_null() { | ||
| 99 | return None; | ||
| 100 | } | ||
| 101 | Some(Reader(self)) | ||
| 102 | } | ||
| 103 | |||
| 90 | /// Create a writer. | 104 | /// Create a writer. |
| 91 | /// | 105 | /// |
| 92 | /// # Safety | 106 | /// # Safety |
| 93 | /// | 107 | /// |
| 94 | /// Only one writer can exist at a time. | 108 | /// - Only one writer can exist at a time. |
| 109 | /// - Ringbuffer must be initialized. | ||
| 95 | pub unsafe fn writer(&self) -> Writer<'_> { | 110 | pub unsafe fn writer(&self) -> Writer<'_> { |
| 96 | Writer(self) | 111 | Writer(self) |
| 97 | } | 112 | } |
| 98 | 113 | ||
| 114 | /// Try creating a writer, fails if not initialized. | ||
| 115 | /// | ||
| 116 | /// # Safety | ||
| 117 | /// | ||
| 118 | /// Only one writer can exist at a time. | ||
| 119 | pub unsafe fn try_writer(&self) -> Option<Writer<'_>> { | ||
| 120 | if self.buf.load(Ordering::Relaxed).is_null() { | ||
| 121 | return None; | ||
| 122 | } | ||
| 123 | Some(Writer(self)) | ||
| 124 | } | ||
| 125 | |||
| 99 | /// Return length of buffer. | 126 | /// Return length of buffer. |
| 100 | pub fn len(&self) -> usize { | 127 | pub fn len(&self) -> usize { |
| 101 | self.len.load(Ordering::Relaxed) | 128 | self.len.load(Ordering::Relaxed) |
diff --git a/embassy-hal-internal/src/fmt.rs b/embassy-hal-internal/src/fmt.rs index 78e583c1c..2ac42c557 100644 --- a/embassy-hal-internal/src/fmt.rs +++ b/embassy-hal-internal/src/fmt.rs | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | #![allow(unused_macros)] | 2 | #![allow(unused)] |
| 3 | 3 | ||
| 4 | use core::fmt::{Debug, Display, LowerHex}; | 4 | use core::fmt::{Debug, Display, LowerHex}; |
| 5 | 5 | ||
| @@ -229,7 +229,6 @@ impl<T, E> Try for Result<T, E> { | |||
| 229 | } | 229 | } |
| 230 | } | 230 | } |
| 231 | 231 | ||
| 232 | #[allow(unused)] | ||
| 233 | pub(crate) struct Bytes<'a>(pub &'a [u8]); | 232 | pub(crate) struct Bytes<'a>(pub &'a [u8]); |
| 234 | 233 | ||
| 235 | impl<'a> Debug for Bytes<'a> { | 234 | impl<'a> Debug for Bytes<'a> { |
diff --git a/embassy-hal-internal/src/interrupt.rs b/embassy-hal-internal/src/interrupt.rs index 19dabcf6f..5e64dce9d 100644 --- a/embassy-hal-internal/src/interrupt.rs +++ b/embassy-hal-internal/src/interrupt.rs | |||
| @@ -30,14 +30,12 @@ macro_rules! interrupt_mod { | |||
| 30 | pub mod typelevel { | 30 | pub mod typelevel { |
| 31 | use super::InterruptExt; | 31 | use super::InterruptExt; |
| 32 | 32 | ||
| 33 | mod sealed { | 33 | trait SealedInterrupt {} |
| 34 | pub trait Interrupt {} | ||
| 35 | } | ||
| 36 | 34 | ||
| 37 | /// Type-level interrupt. | 35 | /// Type-level interrupt. |
| 38 | /// | 36 | /// |
| 39 | /// This trait is implemented for all typelevel interrupt types in this module. | 37 | /// This trait is implemented for all typelevel interrupt types in this module. |
| 40 | pub trait Interrupt: sealed::Interrupt { | 38 | pub trait Interrupt: SealedInterrupt { |
| 41 | 39 | ||
| 42 | /// Interrupt enum variant. | 40 | /// Interrupt enum variant. |
| 43 | /// | 41 | /// |
| @@ -105,7 +103,7 @@ macro_rules! interrupt_mod { | |||
| 105 | #[doc=stringify!($irqs)] | 103 | #[doc=stringify!($irqs)] |
| 106 | #[doc=" typelevel interrupt."] | 104 | #[doc=" typelevel interrupt."] |
| 107 | pub enum $irqs {} | 105 | pub enum $irqs {} |
| 108 | impl sealed::Interrupt for $irqs{} | 106 | impl SealedInterrupt for $irqs{} |
| 109 | impl Interrupt for $irqs { | 107 | impl Interrupt for $irqs { |
| 110 | const IRQ: super::Interrupt = super::Interrupt::$irqs; | 108 | const IRQ: super::Interrupt = super::Interrupt::$irqs; |
| 111 | } | 109 | } |
diff --git a/embassy-hal-internal/src/peripheral.rs b/embassy-hal-internal/src/peripheral.rs index 16d49edfb..f03f41507 100644 --- a/embassy-hal-internal/src/peripheral.rs +++ b/embassy-hal-internal/src/peripheral.rs | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | use core::ops::{Deref, DerefMut}; | 2 | use core::ops::Deref; |
| 3 | 3 | ||
| 4 | /// An exclusive reference to a peripheral. | 4 | /// An exclusive reference to a peripheral. |
| 5 | /// | 5 | /// |
| @@ -86,13 +86,6 @@ impl<'a, T> Deref for PeripheralRef<'a, T> { | |||
| 86 | } | 86 | } |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | impl<'a, T> DerefMut for PeripheralRef<'a, T> { | ||
| 90 | #[inline] | ||
| 91 | fn deref_mut(&mut self) -> &mut Self::Target { | ||
| 92 | &mut self.inner | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 96 | /// Trait for any type that can be used as a peripheral of type `P`. | 89 | /// Trait for any type that can be used as a peripheral of type `P`. |
| 97 | /// | 90 | /// |
| 98 | /// This is used in driver constructors, to allow passing either owned peripherals (e.g. `TWISPI0`), | 91 | /// This is used in driver constructors, to allow passing either owned peripherals (e.g. `TWISPI0`), |
| @@ -162,7 +155,7 @@ pub trait Peripheral: Sized { | |||
| 162 | } | 155 | } |
| 163 | } | 156 | } |
| 164 | 157 | ||
| 165 | impl<'b, T: DerefMut> Peripheral for T | 158 | impl<'b, T: Deref> Peripheral for T |
| 166 | where | 159 | where |
| 167 | T::Target: Peripheral, | 160 | T::Target: Peripheral, |
| 168 | { | 161 | { |
