aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2022-06-23 12:59:18 +0200
committerUlf Lilleengen <[email protected]>2022-06-23 13:17:56 +0200
commitca59c1ff3570474dc819c2d759c69c3a186ca5bc (patch)
tree22f96a5a03cdb43366e8bedf954cad13566328ca /embassy-nrf
parent6d3a652026d222bb0191c77406e1f4145a64c5f9 (diff)
Add more API docs for embassy-cortex-m and embassy-nrf
Diffstat (limited to 'embassy-nrf')
-rw-r--r--embassy-nrf/src/buffered_uarte.rs2
-rw-r--r--embassy-nrf/src/gpio.rs2
-rw-r--r--embassy-nrf/src/lib.rs30
-rw-r--r--embassy-nrf/src/uarte.rs6
4 files changed, 33 insertions, 7 deletions
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs
index 34f20efe7..4fc78b95d 100644
--- a/embassy-nrf/src/buffered_uarte.rs
+++ b/embassy-nrf/src/buffered_uarte.rs
@@ -3,7 +3,7 @@
3//! WARNING!!! The functionality provided here is intended to be used only 3//! WARNING!!! The functionality provided here is intended to be used only
4//! in situations where hardware flow control are available i.e. CTS and RTS. 4//! in situations where hardware flow control are available i.e. CTS and RTS.
5//! This is a problem that should be addressed at a later stage and can be 5//! This is a problem that should be addressed at a later stage and can be
6//! fully explained at https://github.com/embassy-rs/embassy/issues/536. 6//! fully explained at <https://github.com/embassy-rs/embassy/issues/536>.
7//! 7//!
8//! Note that discarding a future from a read or write operation may lead to losing 8//! Note that discarding a future from a read or write operation may lead to losing
9//! data. For example, when using `futures_util::future::select` and completion occurs 9//! data. For example, when using `futures_util::future::select` and completion occurs
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs
index e68b8874a..0ba20b0b1 100644
--- a/embassy-nrf/src/gpio.rs
+++ b/embassy-nrf/src/gpio.rs
@@ -429,7 +429,7 @@ mod eh02 {
429 } 429 }
430 } 430 }
431 431
432 /// Implement [`InputPin`] for [`Flex`]; 432 /// Implement [`embedded_hal_02::digital::v2::InputPin`] for [`Flex`];
433 /// 433 ///
434 /// If the pin is not in input mode the result is unspecified. 434 /// If the pin is not in input mode the result is unspecified.
435 impl<'d, T: Pin> embedded_hal_02::digital::v2::InputPin for Flex<'d, T> { 435 impl<'d, T: Pin> embedded_hal_02::digital::v2::InputPin for Flex<'d, T> {
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs
index 1f1ffc99d..3699ad0fa 100644
--- a/embassy-nrf/src/lib.rs
+++ b/embassy-nrf/src/lib.rs
@@ -1,3 +1,11 @@
1//! # Embassy nRF HAL
2//!
3//! HALs implement safe, idiomatic Rust APIs to use the hardware capabilities, so raw register manipulation is not needed.
4//!
5//! The Embassy nRF HAL targets the Nordic Semiconductor nRF family of hardware. The HAL implements both blocking and async APIs
6//! for many peripherals. The benefit of using the async APIs is that the HAL takes care of waiting for peripherals to
7//! complete operations in low power mod and handling interrupts, so that applications can focus on more important matters.
8//!
1//! ## EasyDMA considerations 9//! ## EasyDMA considerations
2//! 10//!
3//! On nRF chips, peripherals can use the so called EasyDMA feature to offload the task of interacting 11//! On nRF chips, peripherals can use the so called EasyDMA feature to offload the task of interacting
@@ -23,8 +31,8 @@
23//! ``` 31//! ```
24//! 32//!
25//! Each peripheral struct which uses EasyDMA ([`Spim`](spim::Spim), [`Uarte`](uarte::Uarte), [`Twim`](twim::Twim)) has two variants of their mutating functions: 33//! Each peripheral struct which uses EasyDMA ([`Spim`](spim::Spim), [`Uarte`](uarte::Uarte), [`Twim`](twim::Twim)) has two variants of their mutating functions:
26//! - Functions with the suffix (e.g. [`write_from_ram`](Spim::write_from_ram), [`transfer_from_ram`](Spim::transfer_from_ram)) will return an error if the passed slice does not reside in RAM. 34//! - Functions with the suffix (e.g. [`write_from_ram`](spim::Spim::write_from_ram), [`transfer_from_ram`](spim::Spim::transfer_from_ram)) will return an error if the passed slice does not reside in RAM.
27//! - Functions without the suffix (e.g. [`write`](Spim::write), [`transfer`](Spim::transfer)) will check whether the data is in RAM and copy it into memory prior to transmission. 35//! - Functions without the suffix (e.g. [`write`](spim::Spim::write), [`transfer`](spim::Spim::transfer)) will check whether the data is in RAM and copy it into memory prior to transmission.
28//! 36//!
29//! Since copying incurs a overhead, you are given the option to choose from `_from_ram` variants which will 37//! Since copying incurs a overhead, you are given the option to choose from `_from_ram` variants which will
30//! fail and notify you, or the more convenient versions without the suffix which are potentially a little bit 38//! fail and notify you, or the more convenient versions without the suffix which are potentially a little bit
@@ -112,6 +120,7 @@ mod chip;
112pub use chip::EASY_DMA_SIZE; 120pub use chip::EASY_DMA_SIZE;
113 121
114pub mod interrupt { 122pub mod interrupt {
123 //! nRF interrupts for cortex-m devices.
115 pub use cortex_m::interrupt::{CriticalSection, Mutex}; 124 pub use cortex_m::interrupt::{CriticalSection, Mutex};
116 pub use embassy_cortex_m::interrupt::*; 125 pub use embassy_cortex_m::interrupt::*;
117 126
@@ -130,28 +139,44 @@ pub use embassy_hal_common::{unborrow, Unborrow};
130pub use embassy_macros::cortex_m_interrupt as interrupt; 139pub use embassy_macros::cortex_m_interrupt as interrupt;
131 140
132pub mod config { 141pub mod config {
142 //! Configuration options used when initializing the HAL.
143
144 /// High frequency clock source.
133 pub enum HfclkSource { 145 pub enum HfclkSource {
146 /// Internal source
134 Internal, 147 Internal,
148 /// External source from xtal.
135 ExternalXtal, 149 ExternalXtal,
136 } 150 }
137 151
152 /// Low frequency clock source
138 pub enum LfclkSource { 153 pub enum LfclkSource {
154 /// Internal RC oscillator
139 InternalRC, 155 InternalRC,
156 /// Synthesized from the high frequency clock source.
140 #[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160")))] 157 #[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160")))]
141 Synthesized, 158 Synthesized,
159 /// External source from xtal.
142 ExternalXtal, 160 ExternalXtal,
161 /// External source from xtal with low swing applied.
143 #[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160")))] 162 #[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160")))]
144 ExternalLowSwing, 163 ExternalLowSwing,
164 /// External source from xtal with full swing applied.
145 #[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160")))] 165 #[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160")))]
146 ExternalFullSwing, 166 ExternalFullSwing,
147 } 167 }
148 168
169 /// Configuration for peripherals. Default configuration should work on any nRF chip.
149 #[non_exhaustive] 170 #[non_exhaustive]
150 pub struct Config { 171 pub struct Config {
172 /// High frequency clock source.
151 pub hfclk_source: HfclkSource, 173 pub hfclk_source: HfclkSource,
174 /// Low frequency clock source.
152 pub lfclk_source: LfclkSource, 175 pub lfclk_source: LfclkSource,
176 /// GPIOTE interrupt priority. Should be lower priority than softdevice if used.
153 #[cfg(feature = "gpiote")] 177 #[cfg(feature = "gpiote")]
154 pub gpiote_interrupt_priority: crate::interrupt::Priority, 178 pub gpiote_interrupt_priority: crate::interrupt::Priority,
179 /// Time driver interrupt priority. Should be lower priority than softdevice if used.
155 #[cfg(feature = "_time-driver")] 180 #[cfg(feature = "_time-driver")]
156 pub time_interrupt_priority: crate::interrupt::Priority, 181 pub time_interrupt_priority: crate::interrupt::Priority,
157 } 182 }
@@ -173,6 +198,7 @@ pub mod config {
173 } 198 }
174} 199}
175 200
201/// Initialize peripherals with the provided configuration. This should only be called once at startup.
176pub fn init(config: config::Config) -> Peripherals { 202pub fn init(config: config::Config) -> Peripherals {
177 // Do this first, so that it panics if user is calling `init` a second time 203 // Do this first, so that it panics if user is calling `init` a second time
178 // before doing anything important. 204 // before doing anything important.
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs
index c129fb63a..f626c62a5 100644
--- a/embassy-nrf/src/uarte.rs
+++ b/embassy-nrf/src/uarte.rs
@@ -19,9 +19,9 @@ use core::task::Poll;
19 19
20use embassy_hal_common::drop::OnDrop; 20use embassy_hal_common::drop::OnDrop;
21use embassy_hal_common::unborrow; 21use embassy_hal_common::unborrow;
22use futures::future::poll_fn; 22use futures::future::poll_fn; // Re-export SVD variants to allow user to directly set values.
23// Re-export SVD variants to allow user to directly set values. 23pub use pac::uarte0::baudrate::BAUDRATE_A as Baudrate;
24pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; 24pub use pac::uarte0::config::PARITY_A as Parity;
25 25
26use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; 26use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE};
27use crate::gpio::sealed::Pin as _; 27use crate::gpio::sealed::Pin as _;