diff options
| author | Ulf Lilleengen <[email protected]> | 2022-08-22 10:36:33 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2022-08-22 16:37:35 +0200 |
| commit | 3e155d2ec366379584bf7ba4a447109555aa0d77 (patch) | |
| tree | e1a6a8340354ea67316697bf737bd08ec0ab7d00 /embassy-nrf | |
| parent | 5fddff849eea74fb240147432a1739ae1759cb6c (diff) | |
nRF documentation warning fixes
Diffstat (limited to 'embassy-nrf')
| -rw-r--r-- | embassy-nrf/src/buffered_uarte.rs | 9 | ||||
| -rw-r--r-- | embassy-nrf/src/gpio.rs | 21 | ||||
| -rw-r--r-- | embassy-nrf/src/nvmc.rs | 10 | ||||
| -rw-r--r-- | embassy-nrf/src/ppi/mod.rs | 12 | ||||
| -rw-r--r-- | embassy-nrf/src/ppi/ppi.rs | 3 |
5 files changed, 53 insertions, 2 deletions
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index 21ff1d73b..08dfcbcf9 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs | |||
| @@ -45,8 +45,10 @@ enum TxState { | |||
| 45 | Transmitting(usize), | 45 | Transmitting(usize), |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | /// A type for storing the state of the UARTE peripheral that can be stored in a static. | ||
| 48 | pub struct State<'d, U: UarteInstance, T: TimerInstance>(StateStorage<StateInner<'d, U, T>>); | 49 | pub struct State<'d, U: UarteInstance, T: TimerInstance>(StateStorage<StateInner<'d, U, T>>); |
| 49 | impl<'d, U: UarteInstance, T: TimerInstance> State<'d, U, T> { | 50 | impl<'d, U: UarteInstance, T: TimerInstance> State<'d, U, T> { |
| 51 | /// Create an instance for storing UARTE peripheral state. | ||
| 50 | pub fn new() -> Self { | 52 | pub fn new() -> Self { |
| 51 | Self(StateStorage::new()) | 53 | Self(StateStorage::new()) |
| 52 | } | 54 | } |
| @@ -75,6 +77,12 @@ pub struct BufferedUarte<'d, U: UarteInstance, T: TimerInstance> { | |||
| 75 | impl<'d, U: UarteInstance, T: TimerInstance> Unpin for BufferedUarte<'d, U, T> {} | 77 | impl<'d, U: UarteInstance, T: TimerInstance> Unpin for BufferedUarte<'d, U, T> {} |
| 76 | 78 | ||
| 77 | impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { | 79 | impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { |
| 80 | /// Create a new instance of a BufferedUarte. | ||
| 81 | /// | ||
| 82 | /// See the [module documentation](crate::buffered_uarte) for more details about the intended use. | ||
| 83 | /// | ||
| 84 | /// The BufferedUarte uses the provided state to store the buffers and peripheral state. The timer and ppi channels are used to 'emulate' idle line detection so that read operations | ||
| 85 | /// can return early if there is no data to receive. | ||
| 78 | pub fn new( | 86 | pub fn new( |
| 79 | state: &'d mut State<'d, U, T>, | 87 | state: &'d mut State<'d, U, T>, |
| 80 | peri: impl Peripheral<P = U> + 'd, | 88 | peri: impl Peripheral<P = U> + 'd, |
| @@ -178,6 +186,7 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { | |||
| 178 | } | 186 | } |
| 179 | } | 187 | } |
| 180 | 188 | ||
| 189 | /// Adjust the baud rate to the provided value. | ||
| 181 | pub fn set_baudrate(&mut self, baudrate: Baudrate) { | 190 | pub fn set_baudrate(&mut self, baudrate: Baudrate) { |
| 182 | self.inner.with(|state| { | 191 | self.inner.with(|state| { |
| 183 | let r = U::regs(); | 192 | let r = U::regs(); |
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs index a61ff6aa5..924629908 100644 --- a/embassy-nrf/src/gpio.rs +++ b/embassy-nrf/src/gpio.rs | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | //! General purpose input/output for nRF. | ||
| 1 | #![macro_use] | 2 | #![macro_use] |
| 2 | 3 | ||
| 3 | use core::convert::Infallible; | 4 | use core::convert::Infallible; |
| @@ -26,8 +27,11 @@ pub enum Port { | |||
| 26 | #[derive(Debug, Eq, PartialEq)] | 27 | #[derive(Debug, Eq, PartialEq)] |
| 27 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 28 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 28 | pub enum Pull { | 29 | pub enum Pull { |
| 30 | /// No pull. | ||
| 29 | None, | 31 | None, |
| 32 | /// Internal pull-up resistor. | ||
| 30 | Up, | 33 | Up, |
| 34 | /// Internal pull-down resistor. | ||
| 31 | Down, | 35 | Down, |
| 32 | } | 36 | } |
| 33 | 37 | ||
| @@ -37,6 +41,7 @@ pub struct Input<'d, T: Pin> { | |||
| 37 | } | 41 | } |
| 38 | 42 | ||
| 39 | impl<'d, T: Pin> Input<'d, T> { | 43 | impl<'d, T: Pin> Input<'d, T> { |
| 44 | /// Create GPIO input driver for a [Pin] with the provided [Pull] configuration. | ||
| 40 | #[inline] | 45 | #[inline] |
| 41 | pub fn new(pin: impl Peripheral<P = T> + 'd, pull: Pull) -> Self { | 46 | pub fn new(pin: impl Peripheral<P = T> + 'd, pull: Pull) -> Self { |
| 42 | let mut pin = Flex::new(pin); | 47 | let mut pin = Flex::new(pin); |
| @@ -45,11 +50,13 @@ impl<'d, T: Pin> Input<'d, T> { | |||
| 45 | Self { pin } | 50 | Self { pin } |
| 46 | } | 51 | } |
| 47 | 52 | ||
| 53 | /// Test if current pin level is high. | ||
| 48 | #[inline] | 54 | #[inline] |
| 49 | pub fn is_high(&self) -> bool { | 55 | pub fn is_high(&self) -> bool { |
| 50 | self.pin.is_high() | 56 | self.pin.is_high() |
| 51 | } | 57 | } |
| 52 | 58 | ||
| 59 | /// Test if current pin level is low. | ||
| 53 | #[inline] | 60 | #[inline] |
| 54 | pub fn is_low(&self) -> bool { | 61 | pub fn is_low(&self) -> bool { |
| 55 | self.pin.is_low() | 62 | self.pin.is_low() |
| @@ -66,7 +73,9 @@ impl<'d, T: Pin> Input<'d, T> { | |||
| 66 | #[derive(Debug, Eq, PartialEq)] | 73 | #[derive(Debug, Eq, PartialEq)] |
| 67 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 74 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 68 | pub enum Level { | 75 | pub enum Level { |
| 76 | /// Logical low. | ||
| 69 | Low, | 77 | Low, |
| 78 | /// Logical high. | ||
| 70 | High, | 79 | High, |
| 71 | } | 80 | } |
| 72 | 81 | ||
| @@ -88,6 +97,7 @@ impl Into<bool> for Level { | |||
| 88 | } | 97 | } |
| 89 | } | 98 | } |
| 90 | 99 | ||
| 100 | /// Drive strength settings for an output pin. | ||
| 91 | // These numbers match DRIVE_A exactly so hopefully the compiler will unify them. | 101 | // These numbers match DRIVE_A exactly so hopefully the compiler will unify them. |
| 92 | #[derive(Clone, Copy, Debug, PartialEq)] | 102 | #[derive(Clone, Copy, Debug, PartialEq)] |
| 93 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 103 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| @@ -117,6 +127,7 @@ pub struct Output<'d, T: Pin> { | |||
| 117 | } | 127 | } |
| 118 | 128 | ||
| 119 | impl<'d, T: Pin> Output<'d, T> { | 129 | impl<'d, T: Pin> Output<'d, T> { |
| 130 | /// Create GPIO output driver for a [Pin] with the provided [Level] and [OutputDriver] configuration. | ||
| 120 | #[inline] | 131 | #[inline] |
| 121 | pub fn new(pin: impl Peripheral<P = T> + 'd, initial_output: Level, drive: OutputDrive) -> Self { | 132 | pub fn new(pin: impl Peripheral<P = T> + 'd, initial_output: Level, drive: OutputDrive) -> Self { |
| 122 | let mut pin = Flex::new(pin); | 133 | let mut pin = Flex::new(pin); |
| @@ -264,11 +275,13 @@ impl<'d, T: Pin> Flex<'d, T> { | |||
| 264 | self.pin.conf().reset(); | 275 | self.pin.conf().reset(); |
| 265 | } | 276 | } |
| 266 | 277 | ||
| 278 | /// Test if current pin level is high. | ||
| 267 | #[inline] | 279 | #[inline] |
| 268 | pub fn is_high(&self) -> bool { | 280 | pub fn is_high(&self) -> bool { |
| 269 | !self.is_low() | 281 | !self.is_low() |
| 270 | } | 282 | } |
| 271 | 283 | ||
| 284 | /// Test if current pin level is low. | ||
| 272 | #[inline] | 285 | #[inline] |
| 273 | pub fn is_low(&self) -> bool { | 286 | pub fn is_low(&self) -> bool { |
| 274 | self.pin.block().in_.read().bits() & (1 << self.pin.pin()) == 0 | 287 | self.pin.block().in_.read().bits() & (1 << self.pin.pin()) == 0 |
| @@ -374,6 +387,7 @@ pub(crate) mod sealed { | |||
| 374 | } | 387 | } |
| 375 | } | 388 | } |
| 376 | 389 | ||
| 390 | /// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin]. | ||
| 377 | pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + sealed::Pin + Sized + 'static { | 391 | pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + sealed::Pin + Sized + 'static { |
| 378 | /// Number of the pin within the port (0..31) | 392 | /// Number of the pin within the port (0..31) |
| 379 | #[inline] | 393 | #[inline] |
| @@ -392,6 +406,7 @@ pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + sealed::Pin + Sized + 'stat | |||
| 392 | } | 406 | } |
| 393 | } | 407 | } |
| 394 | 408 | ||
| 409 | /// Peripheral port register value | ||
| 395 | #[inline] | 410 | #[inline] |
| 396 | fn psel_bits(&self) -> u32 { | 411 | fn psel_bits(&self) -> u32 { |
| 397 | self.pin_port() as u32 | 412 | self.pin_port() as u32 |
| @@ -406,12 +421,16 @@ pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + sealed::Pin + Sized + 'stat | |||
| 406 | } | 421 | } |
| 407 | } | 422 | } |
| 408 | 423 | ||
| 409 | // Type-erased GPIO pin | 424 | /// Type-erased GPIO pin |
| 410 | pub struct AnyPin { | 425 | pub struct AnyPin { |
| 411 | pin_port: u8, | 426 | pin_port: u8, |
| 412 | } | 427 | } |
| 413 | 428 | ||
| 414 | impl AnyPin { | 429 | impl AnyPin { |
| 430 | /// Create an [AnyPin] for a specific pin. | ||
| 431 | /// | ||
| 432 | /// # Safety | ||
| 433 | /// - `pin_port` should not in use by another driver. | ||
| 415 | #[inline] | 434 | #[inline] |
| 416 | pub unsafe fn steal(pin_port: u8) -> Self { | 435 | pub unsafe fn steal(pin_port: u8) -> Self { |
| 417 | Self { pin_port } | 436 | Self { pin_port } |
diff --git a/embassy-nrf/src/nvmc.rs b/embassy-nrf/src/nvmc.rs index cd6100339..6f66f7a78 100644 --- a/embassy-nrf/src/nvmc.rs +++ b/embassy-nrf/src/nvmc.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | //! Nvmcerature sensor interface. | 1 | //! Non-Volatile Memory Controller (NVMC) module. |
| 2 | 2 | ||
| 3 | use core::{ptr, slice}; | 3 | use core::{ptr, slice}; |
| 4 | 4 | ||
| @@ -10,13 +10,19 @@ use embedded_storage::nor_flash::{ | |||
| 10 | use crate::peripherals::NVMC; | 10 | use crate::peripherals::NVMC; |
| 11 | use crate::{pac, Peripheral}; | 11 | use crate::{pac, Peripheral}; |
| 12 | 12 | ||
| 13 | /// Erase size of NVMC flash in bytes. | ||
| 13 | pub const PAGE_SIZE: usize = 4096; | 14 | pub const PAGE_SIZE: usize = 4096; |
| 15 | |||
| 16 | /// Size of NVMC flash in bytes. | ||
| 14 | pub const FLASH_SIZE: usize = crate::chip::FLASH_SIZE; | 17 | pub const FLASH_SIZE: usize = crate::chip::FLASH_SIZE; |
| 15 | 18 | ||
| 19 | /// Error type for NVMC operations. | ||
| 16 | #[derive(Debug, Copy, Clone, PartialEq, Eq)] | 20 | #[derive(Debug, Copy, Clone, PartialEq, Eq)] |
| 17 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 21 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 18 | pub enum Error { | 22 | pub enum Error { |
| 23 | /// Opration using a location not in flash. | ||
| 19 | OutOfBounds, | 24 | OutOfBounds, |
| 25 | /// Unaligned operation or using unaligned buffers. | ||
| 20 | Unaligned, | 26 | Unaligned, |
| 21 | } | 27 | } |
| 22 | 28 | ||
| @@ -29,11 +35,13 @@ impl NorFlashError for Error { | |||
| 29 | } | 35 | } |
| 30 | } | 36 | } |
| 31 | 37 | ||
| 38 | /// Non-Volatile Memory Controller (NVMC) that implements the `embedded-storage` traits. | ||
| 32 | pub struct Nvmc<'d> { | 39 | pub struct Nvmc<'d> { |
| 33 | _p: PeripheralRef<'d, NVMC>, | 40 | _p: PeripheralRef<'d, NVMC>, |
| 34 | } | 41 | } |
| 35 | 42 | ||
| 36 | impl<'d> Nvmc<'d> { | 43 | impl<'d> Nvmc<'d> { |
| 44 | /// Create Nvmc driver. | ||
| 37 | pub fn new(_p: impl Peripheral<P = NVMC> + 'd) -> Self { | 45 | pub fn new(_p: impl Peripheral<P = NVMC> + 'd) -> Self { |
| 38 | into_ref!(_p); | 46 | into_ref!(_p); |
| 39 | Self { _p } | 47 | Self { _p } |
diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs index 23ab011bc..1fdd35717 100644 --- a/embassy-nrf/src/ppi/mod.rs +++ b/embassy-nrf/src/ppi/mod.rs | |||
| @@ -26,6 +26,7 @@ mod dppi; | |||
| 26 | #[cfg(feature = "_ppi")] | 26 | #[cfg(feature = "_ppi")] |
| 27 | mod ppi; | 27 | mod ppi; |
| 28 | 28 | ||
| 29 | /// An instance of the Programmable peripheral interconnect on nRF devices. | ||
| 29 | pub struct Ppi<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> { | 30 | pub struct Ppi<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> { |
| 30 | ch: PeripheralRef<'d, C>, | 31 | ch: PeripheralRef<'d, C>, |
| 31 | #[cfg(feature = "_dppi")] | 32 | #[cfg(feature = "_dppi")] |
| @@ -48,6 +49,7 @@ impl Task { | |||
| 48 | Self(unsafe { NonNull::new_unchecked(reg as *const _ as *mut _) }) | 49 | Self(unsafe { NonNull::new_unchecked(reg as *const _ as *mut _) }) |
| 49 | } | 50 | } |
| 50 | 51 | ||
| 52 | /// Address off subscription register for this task. | ||
| 51 | pub fn subscribe_reg(&self) -> *mut u32 { | 53 | pub fn subscribe_reg(&self) -> *mut u32 { |
| 52 | unsafe { self.0.as_ptr().add(REGISTER_DPPI_CONFIG_OFFSET) } | 54 | unsafe { self.0.as_ptr().add(REGISTER_DPPI_CONFIG_OFFSET) } |
| 53 | } | 55 | } |
| @@ -69,6 +71,7 @@ impl Event { | |||
| 69 | Self(unsafe { NonNull::new_unchecked(reg as *const _ as *mut _) }) | 71 | Self(unsafe { NonNull::new_unchecked(reg as *const _ as *mut _) }) |
| 70 | } | 72 | } |
| 71 | 73 | ||
| 74 | /// Address of publish register for this event. | ||
| 72 | pub fn publish_reg(&self) -> *mut u32 { | 75 | pub fn publish_reg(&self) -> *mut u32 { |
| 73 | unsafe { self.0.as_ptr().add(REGISTER_DPPI_CONFIG_OFFSET) } | 76 | unsafe { self.0.as_ptr().add(REGISTER_DPPI_CONFIG_OFFSET) } |
| 74 | } | 77 | } |
| @@ -87,21 +90,29 @@ pub(crate) mod sealed { | |||
| 87 | pub trait Group {} | 90 | pub trait Group {} |
| 88 | } | 91 | } |
| 89 | 92 | ||
| 93 | /// Interface for PPI channels. | ||
| 90 | pub trait Channel: sealed::Channel + Peripheral<P = Self> + Sized { | 94 | pub trait Channel: sealed::Channel + Peripheral<P = Self> + Sized { |
| 91 | /// Returns the number of the channel | 95 | /// Returns the number of the channel |
| 92 | fn number(&self) -> usize; | 96 | fn number(&self) -> usize; |
| 93 | } | 97 | } |
| 94 | 98 | ||
| 99 | /// Interface for PPI channels that can be configured. | ||
| 95 | pub trait ConfigurableChannel: Channel + Into<AnyConfigurableChannel> { | 100 | pub trait ConfigurableChannel: Channel + Into<AnyConfigurableChannel> { |
| 101 | /// Convert into a type erased configurable channel. | ||
| 96 | fn degrade(self) -> AnyConfigurableChannel; | 102 | fn degrade(self) -> AnyConfigurableChannel; |
| 97 | } | 103 | } |
| 98 | 104 | ||
| 105 | /// Interface for PPI channels that cannot be configured. | ||
| 99 | pub trait StaticChannel: Channel + Into<AnyStaticChannel> { | 106 | pub trait StaticChannel: Channel + Into<AnyStaticChannel> { |
| 107 | /// Convert into a type erased static channel. | ||
| 100 | fn degrade(self) -> AnyStaticChannel; | 108 | fn degrade(self) -> AnyStaticChannel; |
| 101 | } | 109 | } |
| 102 | 110 | ||
| 111 | /// Interface for a group of PPI channels. | ||
| 103 | pub trait Group: sealed::Group + Sized { | 112 | pub trait Group: sealed::Group + Sized { |
| 113 | /// Returns the number of the group. | ||
| 104 | fn number(&self) -> usize; | 114 | fn number(&self) -> usize; |
| 115 | /// Convert into a type erased group. | ||
| 105 | fn degrade(self) -> AnyGroup { | 116 | fn degrade(self) -> AnyGroup { |
| 106 | AnyGroup { | 117 | AnyGroup { |
| 107 | number: self.number() as u8, | 118 | number: self.number() as u8, |
| @@ -196,6 +207,7 @@ macro_rules! impl_ppi_channel { | |||
| 196 | // ====================== | 207 | // ====================== |
| 197 | // groups | 208 | // groups |
| 198 | 209 | ||
| 210 | /// A type erased PPI group. | ||
| 199 | pub struct AnyGroup { | 211 | pub struct AnyGroup { |
| 200 | number: u8, | 212 | number: u8, |
| 201 | } | 213 | } |
diff --git a/embassy-nrf/src/ppi/ppi.rs b/embassy-nrf/src/ppi/ppi.rs index 450a290a2..19abc4e18 100644 --- a/embassy-nrf/src/ppi/ppi.rs +++ b/embassy-nrf/src/ppi/ppi.rs | |||
| @@ -20,6 +20,7 @@ fn regs() -> &'static pac::ppi::RegisterBlock { | |||
| 20 | 20 | ||
| 21 | #[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task | 21 | #[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task |
| 22 | impl<'d, C: StaticChannel> Ppi<'d, C, 0, 1> { | 22 | impl<'d, C: StaticChannel> Ppi<'d, C, 0, 1> { |
| 23 | /// Configure PPI channel to trigger `task`. | ||
| 23 | pub fn new_zero_to_one(ch: impl Peripheral<P = C> + 'd, task: Task) -> Self { | 24 | pub fn new_zero_to_one(ch: impl Peripheral<P = C> + 'd, task: Task) -> Self { |
| 24 | into_ref!(ch); | 25 | into_ref!(ch); |
| 25 | 26 | ||
| @@ -32,6 +33,7 @@ impl<'d, C: StaticChannel> Ppi<'d, C, 0, 1> { | |||
| 32 | } | 33 | } |
| 33 | 34 | ||
| 34 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { | 35 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { |
| 36 | /// Configure PPI channel to trigger `task` on `event`. | ||
| 35 | pub fn new_one_to_one(ch: impl Peripheral<P = C> + 'd, event: Event, task: Task) -> Self { | 37 | pub fn new_one_to_one(ch: impl Peripheral<P = C> + 'd, event: Event, task: Task) -> Self { |
| 36 | into_ref!(ch); | 38 | into_ref!(ch); |
| 37 | 39 | ||
| @@ -46,6 +48,7 @@ impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { | |||
| 46 | 48 | ||
| 47 | #[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task | 49 | #[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task |
| 48 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { | 50 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { |
| 51 | /// Configure PPI channel to trigger `task1` and `task2` on `event`. | ||
| 49 | pub fn new_one_to_two(ch: impl Peripheral<P = C> + 'd, event: Event, task1: Task, task2: Task) -> Self { | 52 | pub fn new_one_to_two(ch: impl Peripheral<P = C> + 'd, event: Event, task1: Task, task2: Task) -> Self { |
| 50 | into_ref!(ch); | 53 | into_ref!(ch); |
| 51 | 54 | ||
