In development. It changes without notice.
Topic
GPIO & Buses
GPIO, I2C, SPI, UART, PWM, I2S and ADC, the USB pads, the die's temperature, and the lock of the crypto hardware.
A function whose name ends in FromIsr is for an interrupt; the others are for a task.
- See also
- I2C Bus, Serial Transport
Files | |
| file | src/ |
| One-shot ADC sampling implementation. | |
| file | src/ |
| One-shot ADC sampling facade. | |
| file | src/ |
| Mutual exclusion between the hardware crypto engines and audio streaming. | |
| file | src/ |
| The hardware-crypto lock's rules, with no RTOS in them. | |
| file | src/ |
| Digital GPIO configuration, level, and interrupt implementation. | |
| file | src/ |
| Digital GPIO configuration, level, and interrupt facade. | |
| file | src/ |
| I2C master-bus implementation. | |
| file | src/ |
| I2C master-bus facade. | |
| file | src/ |
| I2S standard-mode audio implementation. | |
| file | src/ |
| I2S standard-mode (Philips) audio facade. | |
| file | src/ |
| PWM (LEDC) output implementation. | |
| file | src/ |
| PWM (LEDC) output facade. | |
| file | src/ |
| The SoC's SHA-256 engine as a PBKDF2 chain drives it. | |
| file | src/ |
| SPI master bus and device implementation. | |
| file | src/ |
| SPI master bus and device facade. | |
| file | src/ |
| Internal die-temperature sensor implementation. | |
| file | src/ |
| Internal die-temperature sensor facade. | |
| file | src/ |
| UART port facade. | |
| file | src/ |
| Whether this build can isolate the SoC's USB PHY pads before a deep sleep. | |
Macros | |
| #define | KLEIDOS_ |
Typedefs | |
| using | kleidos:: |
| Host builds only: what a take by the lock's own holder does instead of stopping. | |
| using | kleidos:: |
| Called by a crypto caller about to block on the audio side's hold. | |
| using | kleidos:: |
| GPIO pin number (-1 = unassigned). | |
| using | kleidos:: |
| GPIO interrupt callback; runs in ISR context. | |
| using | kleidos:: |
| Level-wake callback; runs in ISR context, gets its pin. | |
Functions | |
| bool | kleidos:: |
| Configure a pin for ADC sampling. | |
| int | kleidos:: |
| Read a raw ADC count from a configured pin. | |
| int | kleidos:: |
| Read calibrated millivolts from a configured pin. | |
| void | kleidos:: |
| Release ADC resources. | |
| bool | kleidos:: |
| True while any crypto caller is blocked on the lock. | |
| void | kleidos:: |
| Install the hook a crypto caller calls before it blocks on the audio side's hold. | |
| Stats | kleidos:: |
| Read the lock's counters (crypto takes and waits, audio holds, refusals and yields, the longest yield, overruns and re-entries). | |
| void | kleidos:: |
| Zero the counters; the lock itself is untouched. | |
| void | kleidos:: |
| Host builds only: install what a ScopedLock taken by the task that already holds the lock does. | |
| bool | kleidos:: |
| Initialize the I2C master bus. | |
| void | kleidos:: |
| Tear down the bus. | |
| bool | kleidos:: |
| True when the I2C bus is initialized. | |
| bool | kleidos:: |
| Probe for a device on the bus by sending its address. | |
| bool | kleidos:: |
| Read bytes from an I2C device. | |
| bool | kleidos:: |
| Write bytes to an I2C device. | |
| bool | kleidos:: |
| Write two buffers to an I2C device as one transaction. | |
| bool | kleidos:: |
| Give one device a bus clock of its own. | |
| bool | kleidos:: |
| Write then repeated-start read in a single transaction. | |
| Counters | kleidos:: |
| Return the transfer and error counts since boot. | |
| uint32_t | kleidos:: |
| Return the currently configured default transaction timeout. | |
| constexpr uint32_t | kleidos:: |
DMA buffers config asks for, its 0 resolved to ESP-IDF's default. | |
| constexpr uint32_t | kleidos:: |
Frames per DMA buffer config asks for, its 0 resolved to ESP-IDF's default. | |
| constexpr uint64_t | kleidos:: |
| Frames the whole ring holds. | |
| constexpr uint32_t | kleidos:: |
| How long the whole ring plays, in milliseconds, rounded up. | |
| constexpr bool | kleidos:: |
| Whether two configurations open channels of the same shape. | |
| bool | kleidos:: |
| Open the I2S peripheral in standard (Philips) mode. | |
| void | kleidos:: |
| Close the channels: stop them and keep them allocated. | |
| Stats | kleidos:: |
| Read the overflow counters and the ring in use. | |
| bool | kleidos:: |
| Stop the open channels without releasing them. | |
| bool | kleidos:: |
| Restart the channels pause stopped. | |
| bool | kleidos:: |
| True when the I2S peripheral is initialized. | |
| bool | kleidos:: |
| Write interleaved PCM samples to the codec. | |
| bool | kleidos:: |
| Read interleaved PCM samples from the codec ADC/ | |
| bool | kleidos:: |
| Configure a PWM channel. | |
| bool | kleidos:: |
| Set the raw duty value for a channel. | |
| bool | kleidos:: |
| Change a timer's frequency, keeping its clock, its resolution and the raw duty of every channel on it. | |
| bool | kleidos:: |
| Set the duty as a percentage (0-100) for a channel. | |
| bool | kleidos:: |
| Stop PWM output and park the pin at idle level. | |
| ClockSource | kleidos:: |
| Read back the clock a PWM timer counts. | |
| const char * | kleidos:: |
| Name of a timer clock source, as the console prints it. | |
| uint32_t | kleidos:: |
| Read back the frequency a PWM timer runs at. | |
| uint32_t | kleidos:: |
| Return the maximum raw duty value for a given resolution. | |
| bool | kleidos:: |
| Take the SHA engine for one derivation and set it to SHA-256. | |
| void | kleidos:: |
| Give the engine back (its lock and its clock). | |
| bool | kleidos:: |
Hash block as the first block of a message and return the state the engine holds, in engine order. | |
| void | kleidos:: |
| Overwrite what the engine still holds of the last derivation: zeros to the state (SHA_H) and to all 16 text words (SHA_TEXT). | |
| bool | kleidos:: |
| Initialize an SPI bus with shared-line pins. | |
| bool | kleidos:: |
| Free a previously initialized SPI bus. | |
| bool | kleidos:: |
| Report whether a host's shared bus is currently initialized. | |
| Device | kleidos:: |
| Attach a device to an initialized SPI bus. | |
| bool | kleidos:: |
| Perform a full- or half-duplex SPI transfer. | |
| bool | kleidos:: |
Half-duplex read of rxSize bytes preceded by dummyBits idle clocks. | |
| bool | kleidos:: |
| Queue a write-only transfer for interrupt-driven DMA (non-blocking). | |
| bool | kleidos:: |
Acquire exclusive use of the bus for device until releaseBus. | |
| void | kleidos:: |
| Release a bus previously taken with acquireBus. | |
| bool | kleidos:: |
| Block until the next queued transaction completes and reclaim it. | |
| bool | kleidos:: |
| Read the SoC internal die temperature in degrees Celsius. | |
| bool | kleidos:: |
| Install the UART driver and configure the port. | |
| void | kleidos:: |
| Delete the driver and release the port (no-op when idle). | |
| bool | kleidos:: |
| True when a port is installed and ready. | |
| int | kleidos:: |
| Non-blocking read of pending RX bytes. | |
| int | kleidos:: |
| Queue bytes for transmission. | |
| void | kleidos:: |
| Drop all pending RX bytes from the driver ring buffer. | |
| void | kleidos:: |
| Block until the TX FIFO drains, bounded by a timeout. | |
Variables | |
| constexpr uint32_t | kleidos:: |
| Longest a crypto caller may wait for the audio side, in milliseconds. | |
| constexpr uint32_t | kleidos:: |
| How long the audio side sleeps, in milliseconds, before it looks again while a crypto caller waits. | |
| constexpr uint32_t | kleidos:: |
| ESP-IDF's DMA buffer count, used when Config:: | |
| constexpr uint32_t | kleidos:: |
| ESP-IDF's frames per DMA buffer, used when Config:: | |
| constexpr Kind | kleidos:: |
| This build's engine. | |
| constexpr size_t | kleidos:: |
| Words in a SHA-256 state, and in each half of a message block. | |
| constexpr size_t | kleidos:: |
| Bytes in one SHA-256 message block. | |
| constexpr uint32_t | kleidos:: |
Configuration | |
| bool | kleidos:: |
| Apply a full pin configuration. | |
| bool | kleidos:: |
True when pin is a usable GPIO number. | |
| bool | kleidos:: |
| Configure a pin as digital input. | |
| bool | kleidos:: |
| Configure a pin as digital output. | |
| bool | kleidos:: |
| Reset a pin to its default GPIO state. | |
| bool | kleidos:: |
| Change a pin's direction, keeping its pulls, interrupt and input routing. | |
Deep-sleep hold | |
| bool | kleidos:: |
| Latch a pad's current output level so it survives resets and deep sleep. | |
| bool | kleidos:: |
| Release a hold previously latched by holdEnable. | |
| bool | kleidos:: |
True when this facade latched pin and nothing has released it. | |
Level access | |
| bool | kleidos:: |
| Drive an output pin high or low. | |
| bool | kleidos:: |
| Read the current pin level. | |
Diagnostics | |
| bool | kleidos:: |
| Read a pad's live routing and electrical state. | |
Interrupts | |
| bool | kleidos:: |
| Register an ISR for a GPIO pin. | |
| void | kleidos:: |
| Remove a previously registered ISR for a GPIO pin. | |
Light sleep | |
| void | kleidos:: |
| Give up this facade's output claim on a pad a driver is about to take. | |
| void | kleidos:: |
| Drop whatever output claim a driver left on a pad it is done with. | |
| void | kleidos:: |
| Keep a pad's configuration while the chip light-sleeps. | |
| bool | kleidos:: |
| Attach the handler a level wake calls, with the pin's interrupt off. | |
| bool | kleidos:: |
| Arm a pin to raise its interrupt at a level, and to wake a light sleep. | |
| void | kleidos:: |
| Undo armLevelWake, leaving the pin with no wake and no interrupt. | |
Macro Definition Documentation
KLEIDOS_ SLEEP_ HAS_ USB_ PHY_ PADS #
1 where this build can isolate the SoC's USB PHY pads before a deep sleep (an ESP32-S3 target), 0 where there is no such pad to isolate. Every site that tests it also spells defined( ESP_PLATFORM ), which is redundant (the macro is 0 without it) and there so that a check of the build can see that a reader of an ESP_
Typedef Documentation
ContentionHook #
Called by a crypto caller about to block on the audio side's hold.
Runs on the crypto caller's task, outside any lock. It must not block (the speaker driver posts a wake item with no wait), and it may run more than once for one wait.
Enumeration Type Documentation
Attenuation #
BitsPerSample #
ClockSource #
The clock a PWM timer counts, as the hardware reports it.
Direction #
Pin data direction.
Host #
InterruptTrigger #
Kind #
Pull #
SlotMode #
Function Documentation
acquire() #
Take the SHA engine for one derivation and set it to SHA-256.
Blocks on ESP-IDF's SHA/AES lock, which every user of the engine holds: its clock enable resets the engine and is not reference counted.
- Returns
- True (the ESP32-S3 lock is a blocking take).
acquireBus() #
Acquire exclusive use of the bus for device until releaseBus.
Required around a run of queueTransmit calls that use keepCsActive, so the chip-select line stays asserted across the whole run. Blocks other devices on a shared bus for the duration.
- Parameters
-
Name Direction Meaning device in, out Device handle from addDevice().
- Return values
-
Value Meaning true Bus acquired. false No device or the driver reported an error.
addDevice() #
armLevelWake() #
Arm a pin to raise its interrupt at a level, and to wake a light sleep.
On a build with automatic light sleep the pin is also armed as a light-sleep wake source; on every other build it only raises the interrupt, which is what ends an idle wait there.
- Parameters
-
Name Direction Meaning pin in GPIO pin number with a handler from attachWakeHandler. wakeHigh in True to fire while the pin reads high, false while low.
- Return values
-
Value Meaning true Armed. false Invalid pin, no handler attached, the driver refused the configuration, or this is the native build.
attachIsr() #
Register an ISR for a GPIO pin.
- Parameters
-
Name Direction Meaning pin in GPIO pin number. trigger in Edge or level condition that fires the interrupt. handler in Callback to invoke from ISR context.
- Return values
-
Value Meaning true ISR registered successfully. false Driver refused the registration (invalid pin, handler, or trigger).
- Note
handlerruns in ISR context and must only call ISR-safe APIs (the*FromIsrfacade helpers, task notifications, etc.). It must not block, allocate, log through a non-DRAM logger, or take a mutex.
attachWakeHandler() #
Attach the handler a level wake calls, with the pin's interrupt off.
The pin's interrupt stays disabled until armLevelWake. When an armed pin fires, the interrupt disables itself before handler runs, so a level that stays asserted raises it once.
- Parameters
-
Name Direction Meaning pin in GPIO pin number, configured as an input by its owner. handler in Callback in ISR context (IRAM); gets pin.
- Return values
-
Value Meaning true Attached. false Invalid pin or handler, the ISR service is unavailable, or this is the native build.
awaitQueued() #
Block until the next queued transaction completes and reclaim it.
Reaps one in-flight transaction queued by queueTransmit in FIFO order. The returned slot (and its staging buffer) may be reused for the next chunk.
- Parameters
-
Name Direction Meaning device in, out Device handle from addDevice(). completed out Set to the transaction that finished (may be null on error).
- Return values
-
Value Meaning true A transaction completed and is returned via completed.false No device, nothing in flight, or the driver reported an error.
begin() [1/3] #
Initialize the I2C master bus.
The bus is reset once it exists (nine clocks and a STOP), so a chip that a reset of the SoC caught in the middle of a transfer lets go of SDA before the first transfer.
- Parameters
-
Name Direction Meaning config in Bus pins, frequency, and timeout settings.
- Return values
-
Value Meaning true Bus initialized and ready for transactions. false Driver reported an initialization error.
begin() [2/3] #
Open the I2S peripheral in standard (Philips) mode.
The first call allocates a TX channel when doutPin >= 0 and an RX channel when dinPin >= 0, with the ring config asks for, and leaves them running. A later call reopens the channels already allocated, stopped first if they run, with config's pins, rate, width and slots; the transmit ring is filled with silence before it restarts.
- Parameters
-
Name Direction Meaning config in Port, pins, sample rate, bit-width, slot mode and ring.
- Return values
-
Value Meaning true The requested channels are open and running. false The driver reported an error, or channels of another shape (sameShape) are allocated: they are never deleted to make room.
begin() [3/3] #
Install the UART driver and configure the port.
While the port is open, on a build with power management, the chip neither light-sleeps (ESP_ the UART receives nothing while it sleeps) nor drops its APB clock (ESP_ the line rate is derived from it, and the idle floor would halve it). end() lets go of both.
- Parameters
-
Name Direction Meaning config in Pins, line rate, peripheral number, and RX ring size.
- Return values
-
Value Meaning true Port installed and ready for reads/writes. false Driver error, or the facade is already holding a port (one client at a time; call end() first).
busInitialized() #
Report whether a host's shared bus is currently initialized.
Read-only diagnostic: a debug console can confirm the display/
- Parameters
-
Name Direction Meaning host in Host peripheral to query.
- Return values
-
Value Meaning true The bus for hostis initialized.false The bus for hostis not initialized.
clockSourceName() #
Name of a timer clock source, as the console prints it.
- Parameters
-
Name Direction Meaning source in Source.
- Returns
- "APB", "XTAL", "RC_FAST", "REF_TICK" or "unknown".
configure() [1/2] #
Apply a full pin configuration.
- Parameters
-
Name Direction Meaning config in Pin direction, pull, and interrupt descriptor.
- Return values
-
Value Meaning true Configuration applied successfully. false Configuration error reported by the driver.
configure() [2/2] #
Configure a PWM channel.
With automatic light sleep built the timer runs from the internal fast RC oscillator, the one clock that keeps running through a light sleep, and the channel is kept alive through it (frequency times 2^bits up to the oscillator's rate: about 8 MHz on the classic ESP32, 17.5 MHz on the ESP32-S3). Otherwise, without the idle floor the driver picks the timer's clock; with it the timer runs from a clock that does not follow the APB bus: the crystal on the ESP32-S3; on the classic ESP32, whose LEDC has no crystal input, REF_TICK when it can make the rate at the resolution asked (frequency times 2^bits up to 1 MHz), the internal fast RC oscillator otherwise.
- Parameters
-
Name Direction Meaning config in Channel, timer, frequency, resolution, and polarity settings.
- Return values
-
Value Meaning true PWM channel configured successfully. false Driver reported a configuration error.
configureInput() #
Configure a pin as digital input.
- Parameters
-
Name Direction Meaning pin in GPIO pin number to configure. pull in Internal pull-resistor selection. interrupt in Edge or level interrupt trigger.
- Return values
-
Value Meaning true Pin configured as input. false Configuration error reported by the driver.
configureOutput() #
Configure a pin as digital output.
The level is written before the driver is enabled, so the pin goes straight from what it was to initialHigh: no edge to the level it was last set to.
- Parameters
-
Name Direction Meaning pin in GPIO pin number to configure. initialHigh in Initial level; true drives the pin high on configure. openDrain in True to use open-drain mode.
- Return values
-
Value Meaning true Pin configured as output. false Configuration error reported by the driver.
configurePin() #
Configure a pin for ADC sampling.
- Parameters
-
Name Direction Meaning config in Pin and attenuation settings.
- Return values
-
Value Meaning true Pin configured for ADC sampling. false Driver reported a configuration error.
counters() #
Return the transfer and error counts since boot.
- Returns
- Both counts; zero on the native host build.
cryptoWaiting() #
True while any crypto caller is blocked on the lock.
The audio side reads it between blocks: when it turns true, the player yields within kAudioYieldBudgetMs.
- Return values
-
Value Meaning true A crypto caller is waiting. false None is.
defaultTimeoutMs() #
Return the currently configured default transaction timeout.
- Returns
- Default timeout in milliseconds.
detachIsr() #
Remove a previously registered ISR for a GPIO pin.
- Parameters
-
Name Direction Meaning pin in GPIO pin number.
- Note
- Must be called from task context (not from the ISR it unregisters); the GPIO ISR service treats handler removal as a deferred operation that requires the scheduler to be running.
disarmLevelWake() #
Undo armLevelWake, leaving the pin with no wake and no interrupt.
- Parameters
-
Name Direction Meaning pin in GPIO pin number.
end() [1/2] #
end() [2/2] #
Delete the driver and release the port (no-op when idle).
Also returns both pads to hi-Z inputs (no pulls) so a peripheral whose power rail is later cut is not backfed through a still-driven TX line, and releases the clock holds begin() took.
firstBlockState() #
Hash block as the first block of a message and return the state the engine holds, in engine order.
Our own register sequence: the 16 text words, START, a bounded wait, the eight state words.
- Parameters
-
Name Direction Meaning block in One :: kBlockBytes-byte block (an HMAC pad block). stateOut out Receives ::kStateWords words; wiped on a refusal.
- Return values
-
Value Meaning true stateOutholds the state.false The engine stayed busy past :: kBusyPollLimit polls, or the state read back all zero.
flushOutput() #
Block until the TX FIFO drains, bounded by a timeout.
- Parameters
-
Name Direction Meaning timeoutMs in Maximum time to wait for the drain, in milliseconds.
freeBus() #
Free a previously initialized SPI bus.
- Parameters
-
Name Direction Meaning host in Host peripheral to release.
- Return values
-
Value Meaning true Bus was initialized and has been released. false Bus was not initialized for host.
handOver() #
Give up this facade's output claim on a pad a driver is about to take.
Since ESP-IDF 6.1, configuring a pad as an output records a claim on it, and a driver (SPI, I2C) that then routes the pad reports a conflict when it finds the claim. A board parks a chip select or a bus pad from here before the driver that owns it comes up; the SPI and I2C facades call this for every pad they hand to ESP-IDF so that hand-over is not reported as a conflict. Only the record of the claim goes: the pad keeps its level and direction.
- Parameters
-
Name Direction Meaning pin in GPIO pin number; a negative or invalid one is ignored.
holdDisable() #
Release a hold previously latched by holdEnable.
- Parameters
-
Name Direction Meaning pin in GPIO pin number.
- Return values
-
Value Meaning true Hold released (or the pad was not held). false Invalid pin or the driver reported an error.
holdEnable() #
Latch a pad's current output level so it survives resets and deep sleep.
Wraps gpio_hold_en. Once held, the pad freezes at its present drive level and ignores further direction/
- Parameters
-
Name Direction Meaning pin in GPIO pin number. Must be a hold-capable pad and already driven to the intended level before this call.
- Return values
-
Value Meaning true Hold latched. false Invalid pin or the driver rejected the hold.
initializeBus() #
Initialize an SPI bus with shared-line pins.
- Parameters
-
Name Direction Meaning config in Host, clock, MISO/MOSI pins, and DMA settings.
- Return values
-
Value Meaning true Bus initialized successfully. false Bus was already initialized or the driver reported an error.
isHeld() #
True when this facade latched pin and nothing has released it.
A hold is otherwise write-only: ESP-IDF exposes no way to read back RTC_ or the digital hold, so the facade remembers what it latched. That makes the answer trustworthy for every deliberate hold in the firmware, which all go through holdEnable, and blind to one latched by a raw ESP-IDF call or left over from a previous boot. kleidos::
Declared only where KLEIDOS_ is 1 (platform/ usb_
- Parameters
-
Name Direction Meaning pin in GPIO pin number.
- Return values
-
Value Meaning true holdEnable latched this pin since boot and no holdDisable or resetPin released it. false Not held by this facade, or an invalid pin.
isValid() #
True when pin is a usable GPIO number.
- Parameters
-
Name Direction Meaning pin in GPIO pin number to validate.
- Return values
-
Value Meaning true pinis a valid GPIO number on the target.false pinis reserved, out of range, or otherwise unusable.
keepThroughLightSleep() #
Keep a pad's configuration while the chip light-sleeps.
On a build with automatic light sleep where ESP-IDF isolates every pad for the length of a sleep (its light-sleep GPIO reset workaround, the ESP32-S3 default), exempts pin so it keeps driving, reading and pulling as it does awake: a chip select stays deasserted, a reset line high, a power enable on, a key readable. Every pad a platform facade configures goes through here; pads nothing configured stay isolated. A no-op on every other build.
- Parameters
-
Name Direction Meaning pin in GPIO pin number; a negative or invalid one is ignored.
level() #
maxDuty() #
Return the maximum raw duty value for a given resolution.
- Parameters
-
Name Direction Meaning resolutionBits in Duty resolution in bits (e.g., 8 for 0-255).
- Returns
- Maximum duty count ((1 << resolutionBits) - 1).
pause() #
Stop the open channels without releasing them.
Stops their bit clock and DMA, and with them ESP-IDF's power-management lock a running channel holds: a running I2S channel keeps the APB clock at 80 MHz, which on a board built with the CPU idle floor keeps the cores off the floor for as long as it runs. Unlike end it keeps the channels allocated and configured, so resume restarts them without a new begin. No-op on channels already stopped, and before begin.
- Return values
-
Value Meaning true Every open channel is stopped. false A channel refused to stop (or the native build).
probe() #
Probe for a device on the bus by sending its address.
- Parameters
-
Name Direction Meaning address in 7-bit I2C device address. timeoutMs in Timeout in ms; 0 uses the default.
- Return values
-
Value Meaning true Device acknowledged the probe. false NACK, timeout, or bus error.
queueTransmit() #
Queue a write-only transfer for interrupt-driven DMA (non-blocking).
Hands transaction to the SPI driver's interrupt queue and returns immediately, leaving the CPU free to do other work (e.g. pack the next chunk) while the DMA runs. Completion is reaped with awaitQueued. The device must have been created with DeviceConfig::
Both transaction and txData must remain valid and untouched until the matching awaitQueued call returns this transaction.
When keepCsActive is true the chip-select line is held asserted after this transfer completes, so a sequence of chunks streams as one continuous CS frame (required by some panel controllers, e.g. ST7789V2, which desync their GRAM column pointer on a CS edge mid-RAMWR). The caller must bracket such a run with acquireBus / releaseBus and clear keepCsActive on the final chunk so CS deasserts normally.
- Parameters
-
Name Direction Meaning device in, out Device handle from addDevice(). transaction in, out Caller-owned slot, reused across frames. txData in DMA-capable bytes to transmit (must be non-null). txSize in Number of bytes to transmit (must be non-zero). keepCsActive in Hold CS asserted after this transfer (continuous run).
- Return values
-
Value Meaning true The transaction was queued. false Bad arguments, no device, or the driver rejected the queue.
read() [1/3] #
Read bytes from an I2C device.
- Parameters
-
Name Direction Meaning address in 7-bit device address. data out Destination buffer. length in Number of bytes to read. timeoutMs in Timeout in ms; 0 uses the default.
- Return values
-
Value Meaning true Read completed successfully. false NACK, timeout, or bus error.
read() [2/3] #
Read interleaved PCM samples from the codec ADC/
Same semantics as write(). Requires the config to have provided dinPin >= 0.
- Parameters
-
Name Direction Meaning data out Destination buffer for interleaved PCM samples. length in Buffer size in bytes. bytesRead out Set to the number of bytes actually received. timeoutMs in Maximum time to block in milliseconds.
- Return values
-
Value Meaning true Read succeeded or a short read fit within timeoutMs.false Backend reported a hard error (e.g. not initialized, no RX channel configured, null buffer, or non-recoverable I/O fault).
read() [3/3] #
Non-blocking read of pending RX bytes.
- Parameters
-
Name Direction Meaning buffer out Destination buffer. maxLen in Capacity of bufferin bytes.
- Returns
- Number of bytes read (0 when nothing is pending), or -1 when the port is not ready or the arguments are invalid.
readCelsius() #
Read the SoC internal die temperature in degrees Celsius.
Performs a self-contained install → enable → read → disable → uninstall cycle, leaving the sensor driver uninstalled on return. Safe to call from the UI task; does not touch any peripheral other than the temperature sensor.
- Parameters
-
Name Direction Meaning celsius out Receives the temperature in °C on success; untouched on failure.
- Return values
-
Value Meaning true A sample was read and written to celsius.false No internal sensor on this SoC (e.g. classic ESP32), the native build, or a driver error.
readMilliVolts() #
Read calibrated millivolts from a configured pin.
- Parameters
-
Name Direction Meaning pin in GPIO pin number.
- Returns
- Millivolts, or -1 on error, uncalibrated pin, or native build.
readPadState() #
Read a pad's live routing and electrical state.
For diagnostics: it answers who drives a pin now (a peripheral signal or the plain GPIO level), which a configuration call can change behind the owner's back. Reads only; changes nothing.
- Parameters
-
Name Direction Meaning pin in GPIO pin number. out out The pad's state; untouched on failure.
- Return values
-
Value Meaning true outholds the pad's state.false Invalid pin, or no hardware (native build).
readRaw() #
Read a raw ADC count from a configured pin.
- Parameters
-
Name Direction Meaning pin in GPIO pin number.
- Returns
- Raw ADC count, or -1 on error or on the native build.
readWithDummy() #
Half-duplex read of rxSize bytes preceded by dummyBits idle clocks.
A read-only transaction (no write phase) for panels that return data on the shared data line — either a dedicated MISO pin or a 3-wire panel whose SDA (MOSI) line turns around after the command. Because the transaction has no write phase, the SPI hardware can insert dummyBits dummy clocks before the read (ESP-IDF forbids dummy bits only when a transaction has both a read and a write phase). During the dummy clocks the Host does not latch data but the Device keeps shifting — this compensates for the panel's read setup time and, for ST7789, skips the one dummy clock that precedes every multi-parameter read (RDDID/
The caller drives D/C and holds chip-select: bracket a preceding command write (via transmit with keepCsActive) and this read inside one acquireBus / releaseBus span so both phases form a single CS frame (SPI_
- Parameters
-
Name Direction Meaning device in, out Device handle from addDevice() (half-duplex config). rxData out Buffer receiving rxSizebytes.rxSize in Number of bytes to read (must be non-zero). dummyBits in Idle clocks to insert before the read (0 for none). keepCsActive in Hold CS asserted after this read (rarely needed; normally the read is the final phase of the frame).
- Return values
-
Value Meaning true Read completed successfully. false Bad arguments, no device, or the driver reported a transfer error.
ready() [1/3] #
True when the I2C bus is initialized.
- Return values
-
Value Meaning true Bus is initialized and ready for transactions. false Bus has not been initialized (no successful begin()call).
ready() [2/3] #
True when the I2S peripheral is initialized.
- Return values
-
Value Meaning true Peripheral was successfully initialized by begin().false Peripheral is uninitialized.
ready() [3/3] #
releaseBus() #
Release a bus previously taken with acquireBus.
- Parameters
-
Name Direction Meaning device in, out Device handle from addDevice().
resetPin() #
Reset a pin to its default GPIO state.
Detaches any peripheral signal (LEDC, SPI, matrix) previously routed to the pad and releases any deep-sleep hold. Use before reclaiming a pin for direct GPIO control.
- Parameters
-
Name Direction Meaning pin in GPIO pin number.
- Return values
-
Value Meaning true Pin reset successfully. false Driver reported an error resetting the pin.
resume() #
Restart the channels pause stopped.
begin leaves the channels running; this is only needed after pause. The transmit channel restarts on silence: the samples a pause left queued are overwritten, not sent. No-op on channels already running, and before begin.
- Return values
-
Value Meaning true Every open channel runs. false A channel refused to start (or the native build).
ringDescCount() #
DMA buffers config asks for, its 0 resolved to ESP-IDF's default.
- Parameters
-
Name Direction Meaning config in The configuration.
- Returns
- The buffer count.
ringFrameCount() #
Frames per DMA buffer config asks for, its 0 resolved to ESP-IDF's default.
- Parameters
-
Name Direction Meaning config in The configuration.
- Returns
- The frame count.
ringFrames() #
Frames the whole ring holds.
Computed in 64 bits, so no pair of 32-bit counts wraps.
- Parameters
-
Name Direction Meaning config in The configuration.
- Returns
- Buffers times frames per buffer.
ringMs() #
How long the whole ring plays, in milliseconds, rounded up.
What a sample written now waits before it reaches the pin, at most, and the silence a stream must end with so that a pause discards only silence.
- Parameters
-
Name Direction Meaning config in The configuration.
- Returns
- The ring's length in milliseconds,
UINT32_MAXfor a length that does not fit; 0 when the sample rate is 0.
sameShape() #
Whether two configurations open channels of the same shape.
The shape is what a channel is allocated with and cannot change without a delete: the port, which directions exist (transmit, receive) and the ring. Pins, rate, width and slots can change on a closed channel.
- Parameters
-
Name Direction Meaning a in One configuration. b in The other.
- Return values
-
Value Meaning true begin may reopen channels allocated for awithb.false It must refuse.
scrub() #
Overwrite what the engine still holds of the last derivation: zeros to the state (SHA_H) and to all 16 text words (SHA_TEXT).
After a chain the state holds its last U and the text its last inner digest; the salt and the count are public, so either is a PIN-guess oracle. Every driver calls this before release, on every exit.
setContentionHook() #
Install the hook a crypto caller calls before it blocks on the audio side's hold.
The speaker driver posts a wake item from it, so a task blocked between sounds (the hang) reacts at once instead of polling. The hook must not block, and may run more than once for one wait. A waiter that read the hook just before it was replaced or removed may still call it once after this returns, so whatever the hook touches (the speaker's queue) must outlive the hook, never be deleted as it is removed.
- Parameters
-
Name Direction Meaning hook in The hook, or nullptrto remove it.
setDeviceFrequency() #
Give one device a bus clock of its own.
Every device is clocked at the bus's Config::address uses the new rate.
- Parameters
-
Name Direction Meaning address in 7-bit device address. frequencyHz in Its clock in Hz.
- Return values
-
Value Meaning true The rate is recorded (and applies from the next transfer). false Invalid address or rate, or no room left to record one.
setDirection() #
Change a pin's direction, keeping its pulls, interrupt and input routing.
Lighter than configure, which rewrites the whole pad. A pad whose input feeds a peripheral through the GPIO matrix (an SPI MISO) keeps feeding it in either direction, so a pad two owners share — driven as an output by one, read as an input by the other — is switched here around each owner's use.
- Warning
- An output direction makes the pad a plain GPIO output: any peripheral output signal routed to it (an SPI device's hardware chip-select) is disconnected. Never point this, configure or configureOutput at a pin a peripheral drives; use readPadState to see which one does.
- Parameters
-
Name Direction Meaning pin in GPIO pin number. direction in New direction (push-pull when an output).
- Return values
-
Value Meaning true Direction applied. false Invalid pin or the driver reported an error.
setDuty() #
Set the raw duty value for a channel.
- Parameters
-
Name Direction Meaning channel in LEDC channel index. duty in Raw duty count (0..maxDuty(resolutionBits)).
- Return values
-
Value Meaning true Driver accepted the new duty value. false Driver reported an error updating the duty.
setDutyPercent() #
Set the duty as a percentage (0-100) for a channel.
- Parameters
-
Name Direction Meaning channel in LEDC channel index. percent in Duty cycle percentage (0 = off, 100 = full on).
- Return values
-
Value Meaning true Driver accepted the new duty percentage. false Driver reported an error updating the duty.
setFrequency() #
Change a timer's frequency, keeping its clock, its resolution and the raw duty of every channel on it.
One register update (ESP-IDF's ledc_set_freq), so a sound that steps its pitch does not run configure again on every step. The raw duty counts stay, so each channel keeps its duty fraction at the new frequency: a buzzer note keeps its volume through a glide. Raw duty goes through setDuty, at the resolution the channel was configured with (10 bits for the buzzer: the low volumes need 1 to 3 %, which whole percents cannot say).
- Parameters
-
Name Direction Meaning timer in LEDC timer index; a channel must have been configured on it. frequencyHz in New frequency in Hz. Frequency times 2^bits must stay within the timer's clock (about 8 MHz for RC_FAST on the classic ESP32); the driver refuses a rate it cannot make.
- Return values
-
Value Meaning true The timer runs at frequencyHz.false No channel is configured on timer,frequencyHzis 0, or the driver refused the rate; the timer keeps its frequency.
setLevel() #
Drive an output pin high or low.
- Parameters
-
Name Direction Meaning pin in GPIO pin number. high in True to drive high, false to drive low.
- Return values
-
Value Meaning true Driver accepted the new level. false Driver reported an error setting the level.
setReentryHandlerForTest() #
Host builds only: install what a ScopedLock taken by the task that already holds the lock does.
The device stops the firmware there. The host stops the test program the same way by default (a log line, then std::abort), so a nested take fails whichever native suite runs into it, not only one that reads Stats::
- Parameters
-
Name Direction Meaning handler in Called instead of stopping, or nullptrfor the default.
stats() [1/2] #
Read the lock's counters (crypto takes and waits, audio holds, refusals and yields, the longest yield, overruns and re-entries).
- Returns
- A snapshot of the counters.
stats() [2/2] #
Read the overflow counters and the ring in use.
Safe from any task; the counters are raised by the driver's interrupt. The ring is read without a lock: it is written by the first begin and only ever rewritten with the same counts (sameShape), so only a read that races that first begin can report a stale one.
- Returns
- The counters since boot; zeros on the native build.
stop() #
Stop PWM output and park the pin at idle level.
- Parameters
-
Name Direction Meaning channel in LEDC channel index. idleHigh in True to park the pin high, false to park low.
- Return values
-
Value Meaning true PWM output stopped and pin parked at the requested level. false Driver reported an error stopping the channel.
takeBack() #
Drop whatever output claim a driver left on a pad it is done with.
For a driver that keeps its claim when it lets a pad go: ESP-IDF's SD SPI host configures its chip select as an output and never withdraws that claim, so its own release and the next bring-up each report a conflict on the pad. Called right before such a driver releases the pad. Only the record of the claim goes: the pad keeps its level and direction.
- Parameters
-
Name Direction Meaning pin in GPIO pin number; a negative or invalid one is ignored.
timerClockSource() #
Read back the clock a PWM timer counts.
Read from the LEDC registers, not from what configure asked for, so it shows the source the hardware actually uses.
- Parameters
-
Name Direction Meaning timer in LEDC timer index.
- Returns
- The source; ClockSource::
Unknown on the native build.
timerFrequencyHz() #
Read back the frequency a PWM timer runs at.
Computed from the timer's divider and its source as the source runs at the moment of the call. A caller is a running task, so an APB source reads its busy rate here; the rate it falls to while the cores idle is the reason to read timerClockSource beside it.
- Parameters
-
Name Direction Meaning timer in LEDC timer index.
- Returns
- Frequency in Hz; 0 for a timer no configured channel uses. On the native build, the frequency last configured or set.
transmit() #
Perform a full- or half-duplex SPI transfer.
- Parameters
-
Name Direction Meaning device in, out Device handle from addDevice(). txData in Bytes to transmit (may be nullptr for read-only). txSize in Number of bytes to transmit. rxData out Buffer to receive bytes (may be nullptr for write-only). rxSize in Number of bytes to receive. keepCsActive in Hold CS asserted after this transfer so a run of polling chunks streams as one continuous CS frame. Bracket such a run with acquireBus / releaseBus and clear it on the final chunk.
- Return values
-
Value Meaning true Transfer completed successfully. false Driver reported a transfer error.
write() [1/3] #
Write bytes to an I2C device.
- Parameters
-
Name Direction Meaning address in 7-bit device address. data in Source buffer. length in Number of bytes to write. timeoutMs in Timeout in ms; 0 uses the default.
- Return values
-
Value Meaning true Write completed successfully. false NACK, timeout, or bus error.
write() [2/3] #
Write interleaved PCM samples to the codec.
Blocks until all bytes are queued or timeoutMs elapses; bytesWritten reports the actual count. Returns false on error; a short write (timeout) still returns true with bytesWritten < length. A channel stopped by pause takes no samples until resume.
- Parameters
-
Name Direction Meaning data in Pointer to interleaved PCM sample data. length in Number of bytes to write. bytesWritten out Set to the number of bytes actually queued. timeoutMs in Maximum time to block in milliseconds.
- Return values
-
Value Meaning true Write succeeded or a short write fit within timeoutMs.false Backend reported a hard error (e.g. not initialized, no TX channel configured, null buffer, or non-recoverable I/O fault).
write() [3/3] #
Queue bytes for transmission.
- Parameters
-
Name Direction Meaning data in Source buffer. len in Number of bytes to send.
- Returns
- Number of bytes queued, or -1 when the port is not ready or the arguments are invalid.
writeParts() #
Write two buffers to an I2C device as one transaction.
One START, the address, head then body, one STOP: what a register write is (the register address, then its data) without copying the data behind the address first, so its length has no bound but the timeout.
- Parameters
-
Name Direction Meaning address in 7-bit device address. head in First bytes on the wire (a register address). headLength in Number of bytes in head.body in Bytes that follow. bodyLength in Number of bytes in body.timeoutMs in Timeout in ms; 0 uses the default.
- Return values
-
Value Meaning true Write completed successfully. false NACK, timeout, or bus error.
writeRead() #
Write then repeated-start read in a single transaction.
- Parameters
-
Name Direction Meaning address in 7-bit device address. writeData in Source buffer for the write phase. writeLength in Number of bytes to write. readData out Destination buffer for the read phase. readLength in Number of bytes to read. timeoutMs in Timeout in ms; 0 uses the default.
- Return values
-
Value Meaning true Transaction completed successfully. false NACK, timeout, or bus error.
Variable Documentation
kAudioBackoffMs #
How long the audio side sleeps, in milliseconds, before it looks again while a crypto caller waits.
Sleeping rather than retrying the mutex is what keeps it from taking the lock back from a waiter of lower priority that has been woken but has not run yet.
kAudioYieldBudgetMs #
Longest a crypto caller may wait for the audio side, in milliseconds.
The audio side's yield: the block being written (8 ms) and the close of the stream (the amplifier's gate write, whose shutdown cuts the sound, the codec's mute and the channel's pause), with room for the player to be preempted while it does so. A longer yield is counted in Stats::
kBusyPollLimit #
Most times a wait reads the engine's busy flag before it calls the engine hung. A compression takes about a microsecond; the limit is some milliseconds of polling.