aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2022-08-22 10:36:33 +0200
committerUlf Lilleengen <[email protected]>2022-08-22 16:37:35 +0200
commit3e155d2ec366379584bf7ba4a447109555aa0d77 (patch)
treee1a6a8340354ea67316697bf737bd08ec0ab7d00
parent5fddff849eea74fb240147432a1739ae1759cb6c (diff)
nRF documentation warning fixes
-rw-r--r--embassy-nrf/src/buffered_uarte.rs9
-rw-r--r--embassy-nrf/src/gpio.rs21
-rw-r--r--embassy-nrf/src/nvmc.rs10
-rw-r--r--embassy-nrf/src/ppi/mod.rs12
-rw-r--r--embassy-nrf/src/ppi/ppi.rs3
-rw-r--r--embassy-usb/src/builder.rs2
-rw-r--r--embassy-usb/src/control.rs3
-rw-r--r--embassy-usb/src/driver.rs6
8 files changed, 60 insertions, 6 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.
48pub struct State<'d, U: UarteInstance, T: TimerInstance>(StateStorage<StateInner<'d, U, T>>); 49pub struct State<'d, U: UarteInstance, T: TimerInstance>(StateStorage<StateInner<'d, U, T>>);
49impl<'d, U: UarteInstance, T: TimerInstance> State<'d, U, T> { 50impl<'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> {
75impl<'d, U: UarteInstance, T: TimerInstance> Unpin for BufferedUarte<'d, U, T> {} 77impl<'d, U: UarteInstance, T: TimerInstance> Unpin for BufferedUarte<'d, U, T> {}
76 78
77impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { 79impl<'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
3use core::convert::Infallible; 4use 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))]
28pub enum Pull { 29pub 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
39impl<'d, T: Pin> Input<'d, T> { 43impl<'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))]
68pub enum Level { 75pub 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
119impl<'d, T: Pin> Output<'d, T> { 129impl<'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].
377pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + sealed::Pin + Sized + 'static { 391pub 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
410pub struct AnyPin { 425pub struct AnyPin {
411 pin_port: u8, 426 pin_port: u8,
412} 427}
413 428
414impl AnyPin { 429impl 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
3use core::{ptr, slice}; 3use core::{ptr, slice};
4 4
@@ -10,13 +10,19 @@ use embedded_storage::nor_flash::{
10use crate::peripherals::NVMC; 10use crate::peripherals::NVMC;
11use crate::{pac, Peripheral}; 11use crate::{pac, Peripheral};
12 12
13/// Erase size of NVMC flash in bytes.
13pub const PAGE_SIZE: usize = 4096; 14pub const PAGE_SIZE: usize = 4096;
15
16/// Size of NVMC flash in bytes.
14pub const FLASH_SIZE: usize = crate::chip::FLASH_SIZE; 17pub 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))]
18pub enum Error { 22pub 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.
32pub struct Nvmc<'d> { 39pub struct Nvmc<'d> {
33 _p: PeripheralRef<'d, NVMC>, 40 _p: PeripheralRef<'d, NVMC>,
34} 41}
35 42
36impl<'d> Nvmc<'d> { 43impl<'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")]
27mod ppi; 27mod ppi;
28 28
29/// An instance of the Programmable peripheral interconnect on nRF devices.
29pub struct Ppi<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> { 30pub 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.
90pub trait Channel: sealed::Channel + Peripheral<P = Self> + Sized { 94pub 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.
95pub trait ConfigurableChannel: Channel + Into<AnyConfigurableChannel> { 100pub 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.
99pub trait StaticChannel: Channel + Into<AnyStaticChannel> { 106pub 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.
103pub trait Group: sealed::Group + Sized { 112pub 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.
199pub struct AnyGroup { 211pub 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
22impl<'d, C: StaticChannel> Ppi<'d, C, 0, 1> { 22impl<'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
34impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { 35impl<'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
48impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { 50impl<'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
diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs
index 1ca24cc08..6be88bc76 100644
--- a/embassy-usb/src/builder.rs
+++ b/embassy-usb/src/builder.rs
@@ -10,6 +10,7 @@ use crate::{Interface, STRING_INDEX_CUSTOM_START};
10#[derive(Debug, Copy, Clone)] 10#[derive(Debug, Copy, Clone)]
11#[cfg_attr(feature = "defmt", derive(defmt::Format))] 11#[cfg_attr(feature = "defmt", derive(defmt::Format))]
12#[non_exhaustive] 12#[non_exhaustive]
13/// Configuration used when creating [UsbDevice].
13pub struct Config<'a> { 14pub struct Config<'a> {
14 pub(crate) vendor_id: u16, 15 pub(crate) vendor_id: u16,
15 pub(crate) product_id: u16, 16 pub(crate) product_id: u16,
@@ -96,6 +97,7 @@ pub struct Config<'a> {
96} 97}
97 98
98impl<'a> Config<'a> { 99impl<'a> Config<'a> {
100 /// Create default configuration with the provided vid and pid values.
99 pub fn new(vid: u16, pid: u16) -> Self { 101 pub fn new(vid: u16, pid: u16) -> Self {
100 Self { 102 Self {
101 device_class: 0x00, 103 device_class: 0x00,
diff --git a/embassy-usb/src/control.rs b/embassy-usb/src/control.rs
index 12e5303c3..3e5749a01 100644
--- a/embassy-usb/src/control.rs
+++ b/embassy-usb/src/control.rs
@@ -1,3 +1,4 @@
1//! USB control data types.
1use core::mem; 2use core::mem;
2 3
3use super::types::*; 4use super::types::*;
@@ -8,7 +9,7 @@ use super::types::*;
8#[cfg_attr(feature = "defmt", derive(defmt::Format))] 9#[cfg_attr(feature = "defmt", derive(defmt::Format))]
9pub enum RequestType { 10pub enum RequestType {
10 /// Request is a USB standard request. Usually handled by 11 /// Request is a USB standard request. Usually handled by
11 /// [`UsbDevice`](crate::device::UsbDevice). 12 /// [`UsbDevice`](crate::UsbDevice).
12 Standard = 0, 13 Standard = 0,
13 /// Request is intended for a USB class. 14 /// Request is intended for a USB class.
14 Class = 1, 15 Class = 1,
diff --git a/embassy-usb/src/driver.rs b/embassy-usb/src/driver.rs
index 2a84ff9e7..7888f1639 100644
--- a/embassy-usb/src/driver.rs
+++ b/embassy-usb/src/driver.rs
@@ -12,7 +12,7 @@ pub trait Driver<'a> {
12 12
13 /// Allocates an endpoint and specified endpoint parameters. This method is called by the device 13 /// Allocates an endpoint and specified endpoint parameters. This method is called by the device
14 /// and class implementations to allocate endpoints, and can only be called before 14 /// and class implementations to allocate endpoints, and can only be called before
15 /// [`start`](UsbBus::start) is called. 15 /// [`start`](Self::start) is called.
16 /// 16 ///
17 /// # Arguments 17 /// # Arguments
18 /// 18 ///
@@ -95,7 +95,7 @@ pub trait Bus {
95 /// 95 ///
96 /// # Errors 96 /// # Errors
97 /// 97 ///
98 /// * [`Unsupported`](crate::UsbError::Unsupported) - This UsbBus implementation doesn't support 98 /// * [`Unsupported`](crate::driver::Unsupported) - This UsbBus implementation doesn't support
99 /// simulating a disconnect or it has not been enabled at creation time. 99 /// simulating a disconnect or it has not been enabled at creation time.
100 fn force_reset(&mut self) -> Result<(), Unsupported> { 100 fn force_reset(&mut self) -> Result<(), Unsupported> {
101 Err(Unsupported) 101 Err(Unsupported)
@@ -105,7 +105,7 @@ pub trait Bus {
105 /// 105 ///
106 /// # Errors 106 /// # Errors
107 /// 107 ///
108 /// * [`Unsupported`](crate::UsbError::Unsupported) - This UsbBus implementation doesn't support 108 /// * [`Unsupported`](crate::driver::Unsupported) - This UsbBus implementation doesn't support
109 /// remote wakeup or it has not been enabled at creation time. 109 /// remote wakeup or it has not been enabled at creation time.
110 fn remote_wakeup(&mut self) -> Self::RemoteWakeupFuture<'_>; 110 fn remote_wakeup(&mut self) -> Self::RemoteWakeupFuture<'_>;
111} 111}