The common, base driver interface for initiating thread-safe transactions with devices on an I2C bus. Other documentation may call this style of interface an I2C "master", "central", or "controller".
More...
|
constexpr | Initiator () |
|
constexpr | Initiator (Feature supported_features) |
|
Status | WriteReadFor (Address device_address, ConstByteSpan tx_buffer, ByteSpan rx_buffer, chrono::SystemClock::duration timeout) |
|
Status | TransferFor (span< const Message > messages, chrono::SystemClock::duration timeout) |
|
Status | WriteReadFor (Address device_address, const void *tx_buffer, size_t tx_size_bytes, void *rx_buffer, size_t rx_size_bytes, chrono::SystemClock::duration timeout) |
|
Status | WriteFor (Address device_address, ConstByteSpan tx_buffer, chrono::SystemClock::duration timeout) |
|
Status | WriteFor (Address device_address, const void *tx_buffer, size_t tx_size_bytes, chrono::SystemClock::duration timeout) |
|
Status | ReadFor (Address device_address, ByteSpan rx_buffer, chrono::SystemClock::duration timeout) |
|
Status | ReadFor (Address device_address, void *rx_buffer, size_t rx_size_bytes, chrono::SystemClock::duration timeout) |
|
Status | ProbeDeviceFor (Address device_address, chrono::SystemClock::duration timeout) |
|
The common, base driver interface for initiating thread-safe transactions with devices on an I2C bus. Other documentation may call this style of interface an I2C "master", "central", or "controller".
pw::i2c::Initiator
isn't required to support 10-bit addressing. If only 7-bit addressing is supported, pw::i2c::Initiator
fails a runtime assertion if given a Message with the kTenBitAddress flag, or when given an address that is out of 7-bit address range.
The implementer of TransferFor() (or DoWriteReadFor()) is responsible for ensuring thread safety and enabling functionality such as initialization, configuration, enabling and disabling, unsticking SDA, and detecting device address registration collisions.
- Note
pw::i2c::Initiator
uses internal synchronization, so it's safe to initiate transactions from multiple threads. Each call to this class will be executed in a single bus transaction using repeated starts.
Furthermore, devices may require specific sequences of transactions, and application logic must provide the synchronization to execute these sequences correctly.
Performs multiple arbitrary reads and writes to an I2C device as one atomic transaction. Each part of the transaction is referred to as a "message".
For a series of 0...N messages, the signal on the bus for the atomic transaction of two messages should look like this:
START + #0.I2C_ADDRESS + #0.WRITE/READ(0/1) + #0.BYTES +
START + #1.I2C_ADDRESS + #1.WRITE/READ(0/1) + #1.BYTES +
...
START + #N.I2C_ADDRESS + #N.WRITE/READ(0/1) + #N.BYTES + STOP
- Parameters
-
[in] | messages | An array of pw::i2c::Message objects to transmit as one i2c bus transaction. |
For each Message msg in messages:
If msg.GetAddress().IsTenBit() is true:
- The implementation should transmit that message using the 10-bit addressing scheme defined in the i2c spec.
- The implementation should CHECK or return an error if 10-bit addressing is unsupported.
If msg.GetAddress().IsWriteContinuation() is true:
- The implementation should transmit this message without a start condition or address.
- The implementation should CHECK or return an error if the hardware or initiator does not support this feature.
- Parameters
-
[in] | timeout | The maximum duration to block waiting for both exclusive bus access and the completion of the bus transaction. |
- Precondition
- The provided addresses of each message must be supported by the initiator, Don't use a 10-bit address if the initiator only supports 7-bit addresses. This method fails a runtime assertion if this precondition isn't met.
- Returns
embed:rst:leading-asterisk
*
* .. pw-status-codes::
*
* OK: The transaction succeeded.
*
* INVALID_ARGUMENT: The arguments can never be valid. For example,
* a WriteContinuation without a preceding Write message.
*
* DEADLINE_EXCEEDED: Was unable to acquire exclusive initiator access
* and complete the I2C transaction in time.
*
* UNAVAILABLE: A NACK condition occurred, meaning the addressed device
* didn't respond or was unable to process the request.
*
* FAILED_PRECONDITION: The interface isn't initialized or enabled.
*
* UNIMPLEMENTED: The interface doesn't support the necessary i2c
* features or combination of i2c messages.
*
*