|
idfxx 1.0.0
Modern C++23 components for ESP-IDF
|
A device on a SPI master bus. More...
Classes | |
| struct | config |
| SPI device configuration. More... | |
Public Member Functions | |
| master_device (master_bus &bus, const struct config &config) | |
| Creates a new SPI device on the specified bus. | |
| ~master_device () | |
| master_device (const master_device &)=delete | |
| master_device & | operator= (const master_device &)=delete |
| master_device (master_device &&other) noexcept | |
| master_device & | operator= (master_device &&other) noexcept |
| master_bus & | bus () const |
| Returns the parent bus. | |
| spi_device_handle_t | idf_handle () const |
| Returns the underlying ESP-IDF device handle. | |
| freq::hertz | frequency () const |
| Returns the actual clock frequency in use. | |
| void | transmit (std::span< const uint8_t > tx_data) |
| Transmits data to the device. | |
| void | receive (std::span< uint8_t > rx_data) |
| Receives data from the device into the provided buffer. | |
| std::vector< uint8_t > | receive (size_t size) |
| Receives data from the device. | |
| void | transfer (std::span< const uint8_t > tx_data, std::span< uint8_t > rx_data) |
| Performs a full-duplex transfer. | |
| result< void > | try_transmit (std::span< const uint8_t > tx_data) |
| Transmits data to the device. | |
| result< void > | try_receive (std::span< uint8_t > rx_data) |
| Receives data from the device into the provided buffer. | |
| result< std::vector< uint8_t > > | try_receive (size_t size) |
| Receives data from the device. | |
| result< void > | try_transfer (std::span< const uint8_t > tx_data, std::span< uint8_t > rx_data) |
| Performs a full-duplex transfer. | |
| void | transmit (const transaction &trans) |
| Executes a full-control transaction. | |
| result< void > | try_transmit (const transaction &trans) |
| Executes a full-control transaction. | |
| void | polling_transmit (std::span< const uint8_t > tx_data) |
| Transmits data using polling (busy-wait). | |
| void | polling_receive (std::span< uint8_t > rx_data) |
| Receives data using polling (busy-wait). | |
| std::vector< uint8_t > | polling_receive (size_t size) |
| Receives data using polling (busy-wait). | |
| void | polling_transfer (std::span< const uint8_t > tx_data, std::span< uint8_t > rx_data) |
| Performs a full-duplex transfer using polling (busy-wait). | |
| void | polling_transmit (const transaction &trans) |
| Executes a full-control transaction using polling (busy-wait). | |
| result< void > | try_polling_transmit (std::span< const uint8_t > tx_data) |
| Transmits data using polling (busy-wait). | |
| result< void > | try_polling_receive (std::span< uint8_t > rx_data) |
| Receives data using polling (busy-wait). | |
| result< std::vector< uint8_t > > | try_polling_receive (size_t size) |
| Receives data using polling (busy-wait). | |
| result< void > | try_polling_transfer (std::span< const uint8_t > tx_data, std::span< uint8_t > rx_data) |
| Performs a full-duplex transfer using polling (busy-wait). | |
| result< void > | try_polling_transmit (const transaction &trans) |
| Executes a full-control transaction using polling (busy-wait). | |
| idfxx::future< void > | queue_trans (const transaction &trans) |
| Queues a transaction for asynchronous execution. | |
| template<typename Rep , typename Period > | |
| idfxx::future< void > | queue_trans (const transaction &trans, const std::chrono::duration< Rep, Period > &timeout) |
| Queues a transaction for asynchronous execution with timeout. | |
| result< idfxx::future< void > > | try_queue_trans (const transaction &trans) |
| Queues a transaction for asynchronous execution. | |
| template<typename Rep , typename Period > | |
| result< idfxx::future< void > > | try_queue_trans (const transaction &trans, const std::chrono::duration< Rep, Period > &timeout) |
| Queues a transaction for asynchronous execution with timeout. | |
| void | lock () const |
| Acquires exclusive access to the SPI bus for this device. | |
| bool | try_lock () const noexcept |
| Tries to acquire exclusive bus access without blocking. | |
| void | unlock () const |
| Releases exclusive bus access. | |
Static Public Member Functions | |
| static result< master_device > | make (master_bus &bus, const struct config &config) |
| Creates a new SPI device on the specified bus. | |
A device on a SPI master bus.
Represents a device attached to a SPI bus. Provides byte-oriented transmit/receive helpers, a full-control transaction API, a polling (busy-wait) variant for low-latency transfers, and an asynchronous queue API for overlapping transfers with other work.
The blocking APIs are thread-safe and may be called concurrently from multiple tasks. The polling APIs are NOT thread-safe — acquire exclusive bus access via lock() (or a std::lock_guard) before calling them.
Satisfies the Lockable named requirement, so it can be used directly with std::lock_guard and similar standard RAII wrappers.
This type is non-copyable and move-only. The caller must ensure the parent master_bus outlives this device.
Definition at line 332 of file master.hpp.
|
explicit |
Creates a new SPI device on the specified bus.
Does not take ownership of bus. The caller must ensure that this device does not outlive the bus.
| bus | The parent SPI master bus. |
| config | Device configuration. |
| std::system_error | on failure. |
| idfxx::spi::master_device::~master_device | ( | ) |
|
delete |
|
noexcept |
|
inline |
Returns the parent bus.
Definition at line 422 of file master.hpp.
| freq::hertz idfxx::spi::master_device::frequency | ( | ) | const |
Returns the actual clock frequency in use.
The requested config::clock_speed may not always be exactly achievable; this returns the closest frequency the hardware is running at.
|
inline |
Returns the underlying ESP-IDF device handle.
Definition at line 428 of file master.hpp.
| void idfxx::spi::master_device::lock | ( | ) | const |
Acquires exclusive access to the SPI bus for this device.
While the bus is acquired, transactions to all other devices on the same bus are deferred. Blocks indefinitely.
|
static |
Creates a new SPI device on the specified bus.
Does not take ownership of bus. The caller must ensure that this device does not outlive the bus.
| bus | The parent SPI master bus. |
| config | Device configuration. |
|
delete |
|
noexcept |
Receives data using polling (busy-wait).
| size | Number of bytes to receive. |
| std::system_error | on failure. |
Definition at line 607 of file master.hpp.
References try_polling_receive(), and idfxx::unwrap().
Receives data using polling (busy-wait).
| rx_data | Buffer to receive into. |
| std::system_error | on failure. |
Definition at line 594 of file master.hpp.
References try_polling_receive(), and idfxx::unwrap().
|
inline |
Performs a full-duplex transfer using polling (busy-wait).
| tx_data | Data to transmit. |
| rx_data | Buffer for received data (must be same size as tx_data). |
| std::system_error | on failure. |
Definition at line 619 of file master.hpp.
References try_polling_transfer(), and idfxx::unwrap().
|
inline |
Executes a full-control transaction using polling (busy-wait).
| trans | Transaction descriptor (lengths in bits). |
| std::system_error | on failure. |
Definition at line 632 of file master.hpp.
References try_polling_transmit(), and idfxx::unwrap().
Transmits data using polling (busy-wait).
| tx_data | Data to transmit. |
| std::system_error | on failure. |
Definition at line 583 of file master.hpp.
References try_polling_transmit(), and idfxx::unwrap().
|
inline |
Queues a transaction for asynchronous execution.
Submits trans to the device and returns a future that signals completion. Blocks indefinitely if the device's transaction queue is full; the queue depth is set by config::queue_size.
| trans | Transaction descriptor. |
| std::system_error | on failure. |
Definition at line 718 of file master.hpp.
References try_queue_trans(), and idfxx::unwrap().
|
inline |
Queues a transaction for asynchronous execution with timeout.
| Rep | Duration arithmetic type. |
| Period | Duration period type. |
| trans | Transaction descriptor. |
| timeout | Maximum time to wait for space in the transaction queue. |
| std::system_error | on failure or timeout. |
Definition at line 735 of file master.hpp.
References idfxx::timeout, try_queue_trans(), and idfxx::unwrap().
Receives data from the device.
| size | Number of bytes to receive. |
| std::system_error | on failure. |
Definition at line 485 of file master.hpp.
References try_receive(), and idfxx::unwrap().
Receives data from the device into the provided buffer.
| rx_data | Buffer to receive into. |
| std::system_error | on failure. |
Definition at line 469 of file master.hpp.
References try_receive(), and idfxx::unwrap().
|
inline |
Performs a full-duplex transfer.
| tx_data | Data to transmit. |
| rx_data | Buffer for received data (must be same size as tx_data). |
| std::system_error | on failure. |
Definition at line 502 of file master.hpp.
References try_transfer(), and idfxx::unwrap().
|
inline |
Executes a full-control transaction.
| trans | Transaction descriptor (lengths in bits). |
| std::system_error | on failure. |
Definition at line 557 of file master.hpp.
References try_transmit(), and idfxx::unwrap().
Transmits data to the device.
| tx_data | Data to transmit. |
| std::system_error | on failure. |
Definition at line 459 of file master.hpp.
References try_transmit(), and idfxx::unwrap().
|
noexcept |
Tries to acquire exclusive bus access without blocking.
Receives data using polling (busy-wait).
| size | Number of bytes to receive. |
Receives data using polling (busy-wait).
| rx_data | Buffer to receive into. |
Referenced by polling_receive(), and polling_receive().
| result< void > idfxx::spi::master_device::try_polling_transfer | ( | std::span< const uint8_t > | tx_data, |
| std::span< uint8_t > | rx_data | ||
| ) |
Performs a full-duplex transfer using polling (busy-wait).
| tx_data | Data to transmit. |
| rx_data | Buffer for received data (must be same size as tx_data). |
Referenced by polling_transfer().
| result< void > idfxx::spi::master_device::try_polling_transmit | ( | const transaction & | trans | ) |
Executes a full-control transaction using polling (busy-wait).
| trans | Transaction descriptor (lengths in bits). |
| result< void > idfxx::spi::master_device::try_polling_transmit | ( | std::span< const uint8_t > | tx_data | ) |
Transmits data using polling (busy-wait).
| tx_data | Data to transmit. |
Referenced by polling_transmit(), and polling_transmit().
| result< idfxx::future< void > > idfxx::spi::master_device::try_queue_trans | ( | const transaction & | trans | ) |
Queues a transaction for asynchronous execution.
Submits trans to the device and returns a future that signals completion. Blocks indefinitely if the device's transaction queue is full; the queue depth is set by config::queue_size.
| trans | Transaction descriptor. |
Referenced by queue_trans(), and queue_trans().
|
inline |
Queues a transaction for asynchronous execution with timeout.
| Rep | Duration arithmetic type. |
| Period | Duration period type. |
| trans | Transaction descriptor. |
| timeout | Maximum time to wait for space in the transaction queue. |
Definition at line 771 of file master.hpp.
References idfxx::timeout.
Receives data from the device.
| size | Number of bytes to receive. |
| result< void > idfxx::spi::master_device::try_transfer | ( | std::span< const uint8_t > | tx_data, |
| std::span< uint8_t > | rx_data | ||
| ) |
Performs a full-duplex transfer.
| tx_data | Data to transmit. |
| rx_data | Buffer for received data (must be same size as tx_data). |
Referenced by transfer().
| result< void > idfxx::spi::master_device::try_transmit | ( | const transaction & | trans | ) |
Executes a full-control transaction.
| trans | Transaction descriptor (lengths in bits). |
Transmits data to the device.
| tx_data | Data to transmit. |
Referenced by transmit(), and transmit().
| void idfxx::spi::master_device::unlock | ( | ) | const |
Releases exclusive bus access.