API referencestd/embedded

std/embedded/chip/esp_capture

Public declarations, types, methods, and source contracts for std/embedded/chip/esp_capture.

On this page

Library guide · API index and notation

This page is generated from the bundled library in this checkout. Signatures and adjacent source comments are reproduced below; the linked guide explains usage, storage, failures, and platform support.

import "std/embedded/chip/esp_capture"

Names used in signatures

Unqualified names denote this package’s types (including other source files in the same package), language built-ins, or generic parameters such as T. Qualified names use the import aliases below. These aliases belong to the library source; import a dependency yourself to use its alias in your program.

Alias Package Source file
hal std/embedded/hal esp_capture.dodo
mmio core/mmio esp_capture.dodo

CLOCK_HZ

Constant · Source

The capture timer’s clock: the MCPWM function clock, the 160 MHz PLL output undivided (PCR PWM_CLK_CONF, MCPWM CLK_CFG).

pub const CLOCK_HZ: u32 = 160_000_000

WINDOW_MAX_US

Constant · Source

The longest window, within the capture timer’s 26.8-second wrap.

pub const WINDOW_MAX_US: u32 = 25_000_000

MAX_CYCLES

Constant · Source

Rising edges after which a measurement ends whatever the window.

pub const MAX_CYCLES: u32 = 16384

READ_TRIES

Constant · Source

Tries a poll makes at a consistent reading before it takes an inconsistent one.

pub const READ_TRIES: u32 = 64

window_ticks

Function · Source

The window in capture timer ticks.

pub fn window_ticks(clock_hz: u32, window_us: u32) -> u32

window_ticks_checked

Function · Source

The window in ticks; InvalidInput for 0 or above WINDOW_MAX_US.

pub fn window_ticks_checked(clock_hz: u32, window_us: u32) -> u32!hal.Error

ticks_between

Function · Source

The ticks from earlier to later on the wrapping capture timer.

pub fn ticks_between(later: u32, earlier: u32) -> u32

Tracker

Struct · Source

The measurement arithmetic, apart from the registers: readings in, a hal.PulseCapture out. Times are capture timer ticks, which wrap.

pub struct Tracker {
    // Private implementation fields omitted.
}

Tracker.new

Function · Source

pub fn new(clock_hz: u32, window_us: u32) -> Tracker

Tracker.update

Function · Source

One consistent reading: count rising edges since the counter last restarted, the latest of them at rise, the latest falling edge at fall, the time now, the line’s level now, and whether the counter wrapped. True with capture set when a measurement ended; the caller then restarts the counter and calls restart. Overrun if the counter wrapped: the caller restarts as well.

pub fn update(&mut self, count: u32, rise: u32, fall: u32, now: u32, level: bool, wrapped: bool, capture: &mut hal.PulseCapture) -> bool!hal.Error

Tracker.restart

Function · Source

Begin the next measurement from a reading taken right after the counter restarted: count rising edges since (usually 0), the latest rising edge at rise (before the restart if count is 0).

pub fn restart(&mut self, count: u32, rise: u32, now: u32, level: bool)

Tracker.needs_restart

Function · Source

Whether a measurement ended and restart is due.

pub fn needs_restart(&self) -> bool

PwmCapture

Struct · Source

A PWM input on one pin; see the package comment. Implements hal.PwmInput.

pub struct PwmCapture: hal.PwmInput {
    // Private implementation fields omitted.
}

PwmCapture.start

Function · Source

Start measuring the pin the chip package routed to PWM0_CAP0, PWM0_CAP1, and PCNT0_SIG_CH0, in windows of window_us. InvalidInput for a window of 0 or above WINDOW_MAX_US. SAFETY: the caller owns the MCPWM’s capture unit and PCNT unit 0, both clocked and out of reset, and routed the signals.

pub unsafe fn start(pin: u32, window_us: u32) -> PwmCapture!hal.Error

Requires an unsafe context. Follow the source safety preconditions and the linked guide before calling this API.

PwmCapture.poll_capture

Function · Source

Without waiting: true with capture set to a measurement that finished since the last call; see hal.PwmInput and the package comment. Overrun if the counter wrapped because polls came more than 32767 rising edges apart; the next measurement has then begun.

pub fn poll_capture(&mut self, capture: &mut hal.PulseCapture) -> bool!hal.Error

PwmCapture.pin

Function · Source

The pin measured.

pub fn pin(&self) -> u32

PwmCapture.window_us

Function · Source

The window, in microseconds.

pub fn window_us(&self) -> u32

PwmCapture.resolution_ps

Function · Source

The time one capture timer tick stands for, in picoseconds: 6250.

pub fn resolution_ps(&self) -> u32

PwmCapture.stop

Function · Source

Stop the capture unit and the counter. Returns the pin.

pub fn stop(self) -> u32

Search every guide, reference page, and API declaration.