Skip to content

Commit

Permalink
Rename ADC free running configuration
Browse files Browse the repository at this point in the history
Also renaming the `read_most_recent()` method, for free running mode.
  • Loading branch information
jlpettersson committed Dec 20, 2023
1 parent 85474db commit 80eb039
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion rp2040-hal/examples/adc_fifo_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn main() -> ! {

// Configure free-running mode:
let mut adc_fifo = adc
.build_fifo()
.free_running()
// Set clock divider to target a sample rate of 1000 samples per second (1ksps).
// The value was calculated by `(48MHz / 1ksps) - 1 = 47999.0`.
// Please check the `clock_divider` method documentation for details.
Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal/examples/adc_fifo_irq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ mod app {
uart.write_full_blocking(b"ADC FIFO interrupt example\r\n");

let adc_fifo = adc
.build_fifo()
.free_running()
// Set clock divider to target a sample rate of 1000 samples per second (1ksps).
// The value was calculated by `(48MHz / 1ksps) - 1 = 47999.0`.
// Please check the `clock_divider` method documentation for details.
Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal/examples/adc_fifo_poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn main() -> ! {

// Configure free-running mode:
let mut adc_fifo = adc
.build_fifo()
.free_running()
// Set clock divider to target a sample rate of 1000 samples per second (1ksps).
// The value was calculated by `(48MHz / 1ksps) - 1 = 47999.0`.
// Please check the `clock_divider` method documentation for details.
Expand Down
18 changes: 9 additions & 9 deletions rp2040-hal/src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
//! let mut temperature_sensor = adc.take_temp_sensor().unwrap();
//!
//! // Configure & start capturing to the fifo:
//! let mut fifo = adc.build_fifo()
//! let mut fifo = adc.free_running()
//! .clock_divider(0, 0) // sample as fast as possible (500ksps. This is the default)
//! .set_channel(&mut temperature_sensor)
//! .start();
Expand Down Expand Up @@ -91,7 +91,7 @@
//! let mut temperature_sensor = adc.take_temp_sensor().unwrap();
//!
//! // Configure & start capturing to the fifo:
//! let mut fifo = adc.build_fifo()
//! let mut fifo = adc.free_running()
//! .clock_divider(0, 0) // sample as fast as possible (500ksps. This is the default)
//! .set_channel(&mut temperature_sensor)
//! .enable_dma()
Expand Down Expand Up @@ -292,7 +292,7 @@ impl Adc {
///
/// Capturing is started by calling [`AdcFifoBuilder::start`], which
/// returns an [`AdcFifo`] to read from.
pub fn build_fifo(&mut self) -> AdcFifoBuilder<'_, u16> {
pub fn free_running(&mut self) -> AdcFifoBuilder<'_, u16> {
AdcFifoBuilder {
adc: self,
marker: PhantomData,
Expand Down Expand Up @@ -357,7 +357,7 @@ where

/// Used to configure & build an [`AdcFifo`]
///
/// See [`Adc::build_fifo`] for details, as well as the `adc_fifo_*` [examples](https://github.com/rp-rs/rp-hal/tree/main/rp2040-hal/examples).
/// See [`Adc::free_running`] for details, as well as the `adc_fifo_*` [examples](https://github.com/rp-rs/rp-hal/tree/main/rp2040-hal/examples).
pub struct AdcFifoBuilder<'a, Word> {
adc: &'a mut Adc,
marker: PhantomData<Word>,
Expand Down Expand Up @@ -511,7 +511,7 @@ impl<'a, Word> AdcFifoBuilder<'a, Word> {

/// Represents the ADC fifo, when used in free running mode
///
/// Constructed by [`AdcFifoBuilder::start`], which is accessible through [`Adc::build_fifo`].
/// Constructed by [`AdcFifoBuilder::start`], which is accessible through [`Adc::free_running`].
///
pub struct AdcFifo<'a, Word> {
adc: &'a mut Adc,
Expand Down Expand Up @@ -567,26 +567,26 @@ impl<'a, Word> AdcFifo<'a, Word> {
/// Example:
/// ```ignore
/// // start continuously sampling values:
/// let mut fifo = adc.build_fifo().set_channel(&mut adc_pin).start();
/// let mut adc_free_running = adc.free_running().set_channel(&mut adc_pin).start();
///
/// loop {
/// do_something_timing_critical();
///
/// // read the most recent value:
/// if fifo.read_single() > THRESHOLD {
/// if adc_free_running.read_most_recent() > THRESHOLD {
/// led.set_high().unwrap();
/// } else {
/// led.set_low().unwrap();
/// }
/// }
///
/// // stop sampling, when it's no longer needed
/// fifo.stop();
/// adc_free_running.stop();
/// ```
///
/// Note that when round-robin sampling is used, there is no way
/// to tell from which channel this sample came.
pub fn read_single(&mut self) -> u16 {
pub fn read_most_recent(&mut self) -> u16 {
self.adc.read_single()
}

Expand Down

0 comments on commit 80eb039

Please sign in to comment.