Pigweed
 
Loading...
Searching...
No Matches
pw::i2c::LinuxInitiator Class Referencefinal

#include <initiator.h>

Inheritance diagram for pw::i2c::LinuxInitiator:
pw::i2c::Initiator

Public Member Functions

 LinuxInitiator (int fd)
 
 LinuxInitiator (const LinuxInitiator &)=delete
 
LinuxInitiatoroperator= (const LinuxInitiator &)=delete
 
- Public Member Functions inherited from pw::i2c::Initiator
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)
 

Static Public Member Functions

static Result< int > OpenI2cBus (const char *bus_path)
 

Private Member Functions

Status DoWriteReadFor (Address device_address, ConstByteSpan tx_buffer, ByteSpan rx_buffer, chrono::SystemClock::duration timeout) override
 

Additional Inherited Members

- Public Types inherited from pw::i2c::Initiator
enum class  Feature : int { kStandard = 0 , kTenBit = (1 << 0) , kNoStart = (1 << 1) }
 Defined set of supported i2c features.
 

Detailed Description

Initiator interface implementation using the Linux userspace i2c-dev driver.

Takes exclusive control of an I2C bus device (ex. "/dev/i2c-0"). The user is responsible to open the device node prior to creating the initiator. The file descriptor is closed when the initiator object is destroyed.

The bus device must support the full I2C functionality. Users of the class are encouraged to use the OpenI2cBus helper to ensure the bus is valid.

Access to the bus is guarded by an internal mutex, so this initiator can be safely used from multiple threads.

Constructor & Destructor Documentation

◆ LinuxInitiator()

pw::i2c::LinuxInitiator::LinuxInitiator ( int  fd)

Construct an instantiator using an open file descriptor. The file descriptor is closed during destruction.

Parameters
[in]fdValid file descriptor for an I2C device node.

Member Function Documentation

◆ DoWriteReadFor()

Status pw::i2c::LinuxInitiator::DoWriteReadFor ( Address  device_address,
ConstByteSpan  tx_buffer,
ByteSpan  rx_buffer,
chrono::SystemClock::duration  timeout 
)
overrideprivatevirtual

Implement pw::i2c::Initiator with the following additional requriements:

  • Asserts that device_address is a 7-bit address.
  • At least one of tx_buffer or rx_buffer must be not empty. Otherwise, returns InvalidArgument.
Note
The timeout is used both for getting an exclusive lock on the initiator and for getting exclusive use of a multi-controller bus. If the timeout is zero or negative, the transaction will only execute if there is no contention at either level.

Reimplemented from pw::i2c::Initiator.

◆ OpenI2cBus()

static Result< int > pw::i2c::LinuxInitiator::OpenI2cBus ( const char *  bus_path)
static

Open an I2C bus and validate that full I2C functionality is supported.

Parameters
[in]bus_pathPath to the I2C bus device node.
Return values
OKThe device node was opened successfully.
InvalidArgumentFailed to open the device node or to validate I2C functionality.
Returns
The open file descriptor on success.

The documentation for this class was generated from the following file: