diff options
| author | Ulf Lilleengen <[email protected]> | 2023-12-08 20:42:52 +0100 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2023-12-08 22:37:39 +0100 |
| commit | 02b7a833d9855bd1db9665b8e9f311f0db93c156 (patch) | |
| tree | f77d928981fb308289b6a43e43417f1e832b8119 | |
| parent | c94a9b8d75ef938aaeb3df18c1eaeb996d655ba0 (diff) | |
docs: document all public apis of embedded-hal-internal
* Make some fields and functions non-public where possible.
* Enable doc warnings for missing public API docs.
| -rw-r--r-- | embassy-hal-internal/src/atomic_ring_buffer.rs | 14 | ||||
| -rw-r--r-- | embassy-hal-internal/src/drop.rs | 7 | ||||
| -rw-r--r-- | embassy-hal-internal/src/lib.rs | 1 | ||||
| -rw-r--r-- | embassy-hal-internal/src/macros.rs | 5 | ||||
| -rw-r--r-- | embassy-hal-internal/src/peripheral.rs | 1 | ||||
| -rw-r--r-- | embassy-hal-internal/src/ratio.rs | 1 |
6 files changed, 27 insertions, 2 deletions
diff --git a/embassy-hal-internal/src/atomic_ring_buffer.rs b/embassy-hal-internal/src/atomic_ring_buffer.rs index ea84925c4..b4f2cec28 100644 --- a/embassy-hal-internal/src/atomic_ring_buffer.rs +++ b/embassy-hal-internal/src/atomic_ring_buffer.rs | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | //! Atomic reusable ringbuffer. | ||
| 1 | use core::slice; | 2 | use core::slice; |
| 2 | use core::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; | 3 | use core::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; |
| 3 | 4 | ||
| @@ -14,8 +15,9 @@ use core::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; | |||
| 14 | /// One concurrent writer and one concurrent reader are supported, even at | 15 | /// One concurrent writer and one concurrent reader are supported, even at |
| 15 | /// different execution priorities (like main and irq). | 16 | /// different execution priorities (like main and irq). |
| 16 | pub struct RingBuffer { | 17 | pub struct RingBuffer { |
| 18 | #[doc(hidden)] | ||
| 17 | pub buf: AtomicPtr<u8>, | 19 | pub buf: AtomicPtr<u8>, |
| 18 | pub len: AtomicUsize, | 20 | len: AtomicUsize, |
| 19 | 21 | ||
| 20 | // start and end wrap at len*2, not at len. | 22 | // start and end wrap at len*2, not at len. |
| 21 | // This allows distinguishing "full" and "empty". | 23 | // This allows distinguishing "full" and "empty". |
| @@ -24,11 +26,16 @@ pub struct RingBuffer { | |||
| 24 | // | 26 | // |
| 25 | // This avoids having to consider the ringbuffer "full" at len-1 instead of len. | 27 | // This avoids having to consider the ringbuffer "full" at len-1 instead of len. |
| 26 | // The usual solution is adding a "full" flag, but that can't be made atomic | 28 | // The usual solution is adding a "full" flag, but that can't be made atomic |
| 29 | #[doc(hidden)] | ||
| 27 | pub start: AtomicUsize, | 30 | pub start: AtomicUsize, |
| 31 | #[doc(hidden)] | ||
| 28 | pub end: AtomicUsize, | 32 | pub end: AtomicUsize, |
| 29 | } | 33 | } |
| 30 | 34 | ||
| 35 | /// A type which can only read from a ring buffer. | ||
| 31 | pub struct Reader<'a>(&'a RingBuffer); | 36 | pub struct Reader<'a>(&'a RingBuffer); |
| 37 | |||
| 38 | /// A type which can only write to a ring buffer. | ||
| 32 | pub struct Writer<'a>(&'a RingBuffer); | 39 | pub struct Writer<'a>(&'a RingBuffer); |
| 33 | 40 | ||
| 34 | impl RingBuffer { | 41 | impl RingBuffer { |
| @@ -89,10 +96,12 @@ impl RingBuffer { | |||
| 89 | Writer(self) | 96 | Writer(self) |
| 90 | } | 97 | } |
| 91 | 98 | ||
| 99 | /// Return length of buffer. | ||
| 92 | pub fn len(&self) -> usize { | 100 | pub fn len(&self) -> usize { |
| 93 | self.len.load(Ordering::Relaxed) | 101 | self.len.load(Ordering::Relaxed) |
| 94 | } | 102 | } |
| 95 | 103 | ||
| 104 | /// Check if buffer is full. | ||
| 96 | pub fn is_full(&self) -> bool { | 105 | pub fn is_full(&self) -> bool { |
| 97 | let len = self.len.load(Ordering::Relaxed); | 106 | let len = self.len.load(Ordering::Relaxed); |
| 98 | let start = self.start.load(Ordering::Relaxed); | 107 | let start = self.start.load(Ordering::Relaxed); |
| @@ -101,6 +110,7 @@ impl RingBuffer { | |||
| 101 | self.wrap(start + len) == end | 110 | self.wrap(start + len) == end |
| 102 | } | 111 | } |
| 103 | 112 | ||
| 113 | /// Check if buffer is empty. | ||
| 104 | pub fn is_empty(&self) -> bool { | 114 | pub fn is_empty(&self) -> bool { |
| 105 | let start = self.start.load(Ordering::Relaxed); | 115 | let start = self.start.load(Ordering::Relaxed); |
| 106 | let end = self.end.load(Ordering::Relaxed); | 116 | let end = self.end.load(Ordering::Relaxed); |
| @@ -238,6 +248,7 @@ impl<'a> Writer<'a> { | |||
| 238 | [(unsafe { buf.add(end) }, n0), (buf, n1)] | 248 | [(unsafe { buf.add(end) }, n0), (buf, n1)] |
| 239 | } | 249 | } |
| 240 | 250 | ||
| 251 | /// Mark n bytes as written and advance the write index. | ||
| 241 | pub fn push_done(&mut self, n: usize) { | 252 | pub fn push_done(&mut self, n: usize) { |
| 242 | trace!(" ringbuf: push {:?}", n); | 253 | trace!(" ringbuf: push {:?}", n); |
| 243 | let end = self.0.end.load(Ordering::Relaxed); | 254 | let end = self.0.end.load(Ordering::Relaxed); |
| @@ -323,6 +334,7 @@ impl<'a> Reader<'a> { | |||
| 323 | (unsafe { buf.add(start) }, n) | 334 | (unsafe { buf.add(start) }, n) |
| 324 | } | 335 | } |
| 325 | 336 | ||
| 337 | /// Mark n bytes as read and allow advance the read index. | ||
| 326 | pub fn pop_done(&mut self, n: usize) { | 338 | pub fn pop_done(&mut self, n: usize) { |
| 327 | trace!(" ringbuf: pop {:?}", n); | 339 | trace!(" ringbuf: pop {:?}", n); |
| 328 | 340 | ||
diff --git a/embassy-hal-internal/src/drop.rs b/embassy-hal-internal/src/drop.rs index 7cd16aaec..8383fcc16 100644 --- a/embassy-hal-internal/src/drop.rs +++ b/embassy-hal-internal/src/drop.rs | |||
| @@ -1,16 +1,20 @@ | |||
| 1 | //! Types for controlling when drop is invoked. | ||
| 1 | use core::mem; | 2 | use core::mem; |
| 2 | use core::mem::MaybeUninit; | 3 | use core::mem::MaybeUninit; |
| 3 | 4 | ||
| 4 | #[must_use = "to delay the drop handler invokation to the end of the scope"] | 5 | /// A type to delay the drop handler invocation. |
| 6 | #[must_use = "to delay the drop handler invocation to the end of the scope"] | ||
| 5 | pub struct OnDrop<F: FnOnce()> { | 7 | pub struct OnDrop<F: FnOnce()> { |
| 6 | f: MaybeUninit<F>, | 8 | f: MaybeUninit<F>, |
| 7 | } | 9 | } |
| 8 | 10 | ||
| 9 | impl<F: FnOnce()> OnDrop<F> { | 11 | impl<F: FnOnce()> OnDrop<F> { |
| 12 | /// Create a new instance. | ||
| 10 | pub fn new(f: F) -> Self { | 13 | pub fn new(f: F) -> Self { |
| 11 | Self { f: MaybeUninit::new(f) } | 14 | Self { f: MaybeUninit::new(f) } |
| 12 | } | 15 | } |
| 13 | 16 | ||
| 17 | /// Prevent drop handler from running. | ||
| 14 | pub fn defuse(self) { | 18 | pub fn defuse(self) { |
| 15 | mem::forget(self) | 19 | mem::forget(self) |
| 16 | } | 20 | } |
| @@ -34,6 +38,7 @@ pub struct DropBomb { | |||
| 34 | } | 38 | } |
| 35 | 39 | ||
| 36 | impl DropBomb { | 40 | impl DropBomb { |
| 41 | /// Create a new instance. | ||
| 37 | pub fn new() -> Self { | 42 | pub fn new() -> Self { |
| 38 | Self { _private: () } | 43 | Self { _private: () } |
| 39 | } | 44 | } |
diff --git a/embassy-hal-internal/src/lib.rs b/embassy-hal-internal/src/lib.rs index f3d59e588..89f20e993 100644 --- a/embassy-hal-internal/src/lib.rs +++ b/embassy-hal-internal/src/lib.rs | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![allow(clippy::new_without_default)] | 2 | #![allow(clippy::new_without_default)] |
| 3 | #![doc = include_str!("../README.md")] | 3 | #![doc = include_str!("../README.md")] |
| 4 | #![warn(missing_docs)] | ||
| 4 | 5 | ||
| 5 | // This mod MUST go first, so that the others see its macros. | 6 | // This mod MUST go first, so that the others see its macros. |
| 6 | pub(crate) mod fmt; | 7 | pub(crate) mod fmt; |
diff --git a/embassy-hal-internal/src/macros.rs b/embassy-hal-internal/src/macros.rs index 97df38954..07cd89487 100644 --- a/embassy-hal-internal/src/macros.rs +++ b/embassy-hal-internal/src/macros.rs | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | /// Types for the peripheral singletons. | ||
| 1 | #[macro_export] | 2 | #[macro_export] |
| 2 | macro_rules! peripherals_definition { | 3 | macro_rules! peripherals_definition { |
| 3 | ($($(#[$cfg:meta])? $name:ident),*$(,)?) => { | 4 | ($($(#[$cfg:meta])? $name:ident),*$(,)?) => { |
| @@ -29,6 +30,7 @@ macro_rules! peripherals_definition { | |||
| 29 | }; | 30 | }; |
| 30 | } | 31 | } |
| 31 | 32 | ||
| 33 | /// Define the peripherals struct. | ||
| 32 | #[macro_export] | 34 | #[macro_export] |
| 33 | macro_rules! peripherals_struct { | 35 | macro_rules! peripherals_struct { |
| 34 | ($($(#[$cfg:meta])? $name:ident),*$(,)?) => { | 36 | ($($(#[$cfg:meta])? $name:ident),*$(,)?) => { |
| @@ -87,6 +89,7 @@ macro_rules! peripherals_struct { | |||
| 87 | }; | 89 | }; |
| 88 | } | 90 | } |
| 89 | 91 | ||
| 92 | /// Defining peripheral type. | ||
| 90 | #[macro_export] | 93 | #[macro_export] |
| 91 | macro_rules! peripherals { | 94 | macro_rules! peripherals { |
| 92 | ($($(#[$cfg:meta])? $name:ident),*$(,)?) => { | 95 | ($($(#[$cfg:meta])? $name:ident),*$(,)?) => { |
| @@ -105,6 +108,7 @@ macro_rules! peripherals { | |||
| 105 | }; | 108 | }; |
| 106 | } | 109 | } |
| 107 | 110 | ||
| 111 | /// Convenience converting into reference. | ||
| 108 | #[macro_export] | 112 | #[macro_export] |
| 109 | macro_rules! into_ref { | 113 | macro_rules! into_ref { |
| 110 | ($($name:ident),*) => { | 114 | ($($name:ident),*) => { |
| @@ -114,6 +118,7 @@ macro_rules! into_ref { | |||
| 114 | } | 118 | } |
| 115 | } | 119 | } |
| 116 | 120 | ||
| 121 | /// Implement the peripheral trait. | ||
| 117 | #[macro_export] | 122 | #[macro_export] |
| 118 | macro_rules! impl_peripheral { | 123 | macro_rules! impl_peripheral { |
| 119 | ($type:ident) => { | 124 | ($type:ident) => { |
diff --git a/embassy-hal-internal/src/peripheral.rs b/embassy-hal-internal/src/peripheral.rs index 38b4c452e..16d49edfb 100644 --- a/embassy-hal-internal/src/peripheral.rs +++ b/embassy-hal-internal/src/peripheral.rs | |||
| @@ -20,6 +20,7 @@ pub struct PeripheralRef<'a, T> { | |||
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | impl<'a, T> PeripheralRef<'a, T> { | 22 | impl<'a, T> PeripheralRef<'a, T> { |
| 23 | /// Create a new reference to a peripheral. | ||
| 23 | #[inline] | 24 | #[inline] |
| 24 | pub fn new(inner: T) -> Self { | 25 | pub fn new(inner: T) -> Self { |
| 25 | Self { | 26 | Self { |
diff --git a/embassy-hal-internal/src/ratio.rs b/embassy-hal-internal/src/ratio.rs index 9a8808a33..91dcfd47c 100644 --- a/embassy-hal-internal/src/ratio.rs +++ b/embassy-hal-internal/src/ratio.rs | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | //! Types for dealing with rational numbers. | ||
| 1 | use core::ops::{Add, Div, Mul}; | 2 | use core::ops::{Add, Div, Mul}; |
| 2 | 3 | ||
| 3 | use num_traits::{CheckedAdd, CheckedDiv, CheckedMul}; | 4 | use num_traits::{CheckedAdd, CheckedDiv, CheckedMul}; |
