|
idfxx 1.0.0
Modern C++23 components for ESP-IDF
|
I2C master bus controller with thread-safe device access. More...
Classes | |
| struct | config |
| I2C master bus configuration. More... | |
Public Member Functions | |
| master_bus (enum port port, const struct config &config) | |
| Creates a new I2C master bus. | |
| master_bus (enum port port, gpio sda, gpio scl, freq::hertz frequency) | |
| Creates a new I2C master bus with default settings. | |
| ~master_bus () | |
| master_bus (const master_bus &)=delete | |
| master_bus & | operator= (const master_bus &)=delete |
| master_bus (master_bus &&other) noexcept | |
| master_bus & | operator= (master_bus &&other) noexcept |
| void | lock () const |
| Acquires exclusive access to the bus. | |
| bool | try_lock () const noexcept |
| Tries to acquire exclusive access without blocking. | |
| void | unlock () const |
| Releases exclusive access to the bus. | |
| i2c_master_bus_handle_t | handle () const |
| Returns the underlying ESP-IDF bus handle. | |
| enum port | port () const |
| Returns the I2C port. | |
| freq::hertz | frequency () const |
| Returns the bus clock frequency in Hz. | |
| std::vector< uint8_t > | scan_devices () const |
| Scans for devices on the bus. | |
| template<typename Rep , typename Period > | |
| std::vector< uint8_t > | scan_devices (const std::chrono::duration< Rep, Period > &timeout) const |
| Scans for devices on the bus. | |
| void | probe (uint16_t address) const |
| Probes for a device at the specified address. | |
| template<typename Rep , typename Period > | |
| void | probe (uint16_t address, const std::chrono::duration< Rep, Period > &timeout) const |
| Probes for a device at the specified address. | |
| result< void > | try_probe (uint16_t address) const |
| Probes for a device at the specified address. | |
| template<typename Rep , typename Period > | |
| result< void > | try_probe (uint16_t address, const std::chrono::duration< Rep, Period > &timeout) const |
| Probes for a device at the specified address. | |
Static Public Member Functions | |
| static result< master_bus > | make (enum port port, const struct config &config) |
| Creates a new I2C master bus. | |
| static result< master_bus > | make (enum port port, gpio sda, gpio scl, freq::hertz frequency) |
| Creates a new I2C master bus with default settings. | |
I2C master bus controller with thread-safe device access.
Represents an I2C bus operating in master mode. Satisfies the Lockable named requirement for use with std::lock_guard and std::unique_lock.
This type is non-copyable and move-only. Result-returning methods on a moved-from object return errc::invalid_state. Simple accessors return default/null values. The Lockable methods (lock/try_lock/unlock) silently no-op on a moved-from object.
Definition at line 110 of file master.hpp.
Creates a new I2C master bus.
| port | I2C port number. |
| config | Bus configuration. |
| std::system_error | on failure. |
|
explicit |
Creates a new I2C master bus with default settings.
| port | I2C port number. |
| sda | GPIO pin for the SDA line. |
| scl | GPIO pin for the SCL line. |
| frequency | Clock frequency in Hz. |
| std::system_error | on failure. |
| idfxx::i2c::master_bus::~master_bus | ( | ) |
|
delete |
|
noexcept |
|
inline |
Returns the bus clock frequency in Hz.
Definition at line 246 of file master.hpp.
|
inline |
Returns the underlying ESP-IDF bus handle.
Definition at line 240 of file master.hpp.
|
inline |
Acquires exclusive access to the bus.
Definition at line 216 of file master.hpp.
|
static |
Creates a new I2C master bus.
| port | I2C port number. |
| config | Bus configuration. |
|
static |
Creates a new I2C master bus with default settings.
| port | I2C port number. |
| sda | GPIO pin for the SDA line. |
| scl | GPIO pin for the SCL line. |
| frequency | Clock frequency in Hz. |
|
delete |
|
noexcept |
Returns the I2C port.
Definition at line 243 of file master.hpp.
Probes for a device at the specified address.
| address | Device address. |
| std::system_error | if the device does not acknowledge or on error. |
Definition at line 280 of file master.hpp.
References idfxx::i2c::DEFAULT_TIMEOUT, and probe().
Referenced by probe().
|
inline |
Probes for a device at the specified address.
| address | Device address. |
| timeout | Maximum time to wait for response. |
| std::system_error | if the device does not acknowledge or on error. |
Definition at line 292 of file master.hpp.
References idfxx::timeout, and idfxx::unwrap().
|
inline |
Scans for devices on the bus.
Probes addresses 0x08-0x77 and returns those that acknowledge.
Definition at line 255 of file master.hpp.
References idfxx::i2c::DEFAULT_TIMEOUT, and scan_devices().
Referenced by scan_devices().
|
inline |
Scans for devices on the bus.
Probes addresses 0x08-0x77 and returns those that acknowledge.
| timeout | Maximum time to wait for each probe. |
Definition at line 267 of file master.hpp.
References idfxx::timeout.
|
inlinenoexcept |
Tries to acquire exclusive access without blocking.
Definition at line 224 of file master.hpp.
Probes for a device at the specified address.
| address | Device address. |
Definition at line 304 of file master.hpp.
References idfxx::i2c::DEFAULT_TIMEOUT, and try_probe().
Referenced by idfxx::i2c::master_device::probe(), and try_probe().
|
inline |
Probes for a device at the specified address.
| address | Device address. |
| timeout | Maximum time to wait for response. |
Definition at line 315 of file master.hpp.
References idfxx::timeout.
|
inline |
Releases exclusive access to the bus.
Definition at line 232 of file master.hpp.