#include <register_device.h>
Public Member Functions | |
constexpr | RegisterDevice (Initiator &initiator, Address address, endian register_address_order, endian data_order, RegisterAddressSize register_address_size) |
constexpr | RegisterDevice (Initiator &initiator, Address address, endian order, RegisterAddressSize register_address_size) |
Status | WriteRegisters (uint32_t register_address, ConstByteSpan register_data, ByteSpan buffer, chrono::SystemClock::duration timeout) |
Status | WriteRegisters8 (uint32_t register_address, span< const uint8_t > register_data, ByteSpan buffer, chrono::SystemClock::duration timeout) |
Status | WriteRegisters16 (uint32_t register_address, span< const uint16_t > register_data, ByteSpan buffer, chrono::SystemClock::duration timeout) |
Status | WriteRegisters32 (uint32_t register_address, span< const uint32_t > register_data, ByteSpan buffer, chrono::SystemClock::duration timeout) |
Status | ReadRegisters (uint32_t register_address, ByteSpan return_data, chrono::SystemClock::duration timeout) |
Status | ReadRegisters8 (uint32_t register_address, span< uint8_t > return_data, chrono::SystemClock::duration timeout) |
Status | ReadRegisters16 (uint32_t register_address, span< uint16_t > return_data, chrono::SystemClock::duration timeout) |
Status | ReadRegisters32 (uint32_t register_address, span< uint32_t > return_data, chrono::SystemClock::duration timeout) |
Status | WriteRegister (uint32_t register_address, std::byte register_data, chrono::SystemClock::duration timeout) |
Status | WriteRegister8 (uint32_t register_address, uint8_t register_data, chrono::SystemClock::duration timeout) |
Status | WriteRegister16 (uint32_t register_address, uint16_t register_data, chrono::SystemClock::duration timeout) |
Status | WriteRegister32 (uint32_t register_address, uint32_t register_data, chrono::SystemClock::duration timeout) |
Result< std::byte > | ReadRegister (uint32_t register_address, chrono::SystemClock::duration timeout) |
Result< uint8_t > | ReadRegister8 (uint32_t register_address, chrono::SystemClock::duration timeout) |
Result< uint16_t > | ReadRegister16 (uint32_t register_address, chrono::SystemClock::duration timeout) |
Result< uint32_t > | ReadRegister32 (uint32_t register_address, chrono::SystemClock::duration timeout) |
![]() | |
constexpr | Device (Initiator &initiator, Address device_address) |
Device (const Device &)=delete | |
Device (Device &&)=default | |
Status | TransferFor (span< const Message > messages, chrono::SystemClock::duration timeout) |
Wraps pw::i2c::Initiator::TransferFor . | |
Status | WriteReadFor (ConstByteSpan tx_buffer, ByteSpan rx_buffer, chrono::SystemClock::duration timeout) |
Wraps pw::i2c::Initiator::WriteReadFor . | |
Status | WriteReadFor (const void *tx_buffer, size_t tx_size_bytes, void *rx_buffer, size_t rx_size_bytes, chrono::SystemClock::duration timeout) |
Status | WriteFor (ConstByteSpan tx_buffer, chrono::SystemClock::duration timeout) |
Wraps pw::i2c::Initiator::WriteFor . | |
Status | WriteFor (const void *tx_buffer, size_t tx_size_bytes, chrono::SystemClock::duration timeout) |
Status | ReadFor (ByteSpan rx_buffer, chrono::SystemClock::duration timeout) |
Wraps pw::i2c::Initiator::ReadFor . | |
Status | ReadFor (void *rx_buffer, size_t rx_size_bytes, chrono::SystemClock::duration timeout) |
Status | ProbeFor (chrono::SystemClock::duration timeout) |
Wraps pw::i2c::Initiator::ProbeDeviceFor . | |
The common interface for I2C register devices. Contains methods to help read and write the device's registers.
|
inlineconstexpr |
This constructor specifies the endianness of the register address and data separately. If your register address and data have the same endianness and you'd like to specify them both with a single argument, see the other pw::i2c::RegisterDevice
constructor.
[in] | initiator | A pw::i2c::Initiator instance for the bus that the device is on. |
[in] | address | The address of the I2C device. |
[in] | register_address_order | The endianness of the register address. |
[in] | data_order | The endianness of the data. |
[in] | register_address_size | The size of the register address. |
|
inlineconstexpr |
This constructor specifies the endianness of the register address and data with a single argument. If your register address and data have different endianness, use the other pw::i2c::RegisterDevice
constructor.
[in] | initiator | A pw::i2c::Initiator instance for the bus that the device is on. |
[in] | address | The address of the I2C device. |
[in] | order | The endianness of both the register address and register data. |
[in] | register_address_size | The size of the register address. |
|
inline |
Sends a register address to read from and then reads from that address.
register_address
and the return data use the endianness that was provided when this pw::i2c::RegisterDevice
instance was constructed.
[in] | register_address | The register address to read. |
[in] | timeout | The maximum duration to block waiting for both exclusive bus access and the completion of the I2C transaction. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: Returns the register data. * * DEADLINE_EXCEEDED: Unable to acquire exclusive bus access and * complete the transaction in time. * * FAILED_PRECONDITION: The interface is not initialized or enabled. * * INTERNAL: An issue occurred while building the return data. * * INVALID_ARGUMENT: ``register_address`` is larger than the 10-bit * address space. * * UNAVAILABLE: The device took too long to respond to the NACK. * *
|
inline |
Variant of pw::i2c::RegisterDevice::ReadRegister()
that returns exactly 16 bits.
|
inline |
Variant of pw::i2c::RegisterDevice::ReadRegister()
that returns exactly 32 bits.
|
inline |
Variant of pw::i2c::RegisterDevice::ReadRegister()
that returns exactly 8 bits.
Status pw::i2c::RegisterDevice::ReadRegisters | ( | uint32_t | register_address, |
ByteSpan | return_data, | ||
chrono::SystemClock::duration | timeout | ||
) |
Reads data from multiple contiguous registers starting from a specific offset or register. This method is byte-addressable.
register_address
and return_data
use the endianness that was provided when this pw::i2c::RegisterDevice
instance was constructed.
return_data
is a correct size for your device.[in] | register_address | The register address to begin reading at. |
[out] | return_data | The area to read the data into. The amount of data that will be read is equal to the size of this span. Endianness is taken into account if this span is 2 or 4 bytes. |
[in] | timeout | The maximum duration to block waiting for both exclusive bus access and the completion of the I2C transaction. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The bulk read was successful. * * DEADLINE_EXCEEDED: Unable to acquire exclusive bus access and * complete the transaction in time. * * FAILED_PRECONDITION: The interface is not initialized or enabled. * * INTERNAL: An issue occurred while building ``return_data``. * * INVALID_ARGUMENT: ``register_address`` is larger than the 10-bit * address space. * * UNAVAILABLE: The device took too long to respond to the NACK. * *
|
inline |
Variant of pw::i2c::RegisterDevice::ReadRegisters()
that requires return_data
to be exactly 16 bits.
|
inline |
Variant of pw::i2c::RegisterDevice::ReadRegisters()
that requires return_data
to be exactly 32 bits.
|
inline |
Variant of pw::i2c::RegisterDevice::ReadRegisters()
that requires return_data
to be exactly 8 bits.
|
inline |
Sends a register address to write to and then writes to that address.
register_address
and register_data
use the endianness that was provided when this pw::i2c::RegisterDevice
instance was constructed.
register_data
is a correct size for your device.[in] | register_address | The register address to write to. |
[in] | register_data | The data that should be written at the address. The maximum allowed size is 4 bytes. |
[in] | timeout | The maximum duration to block waiting for both exclusive bus access and the completion of the I2C transaction. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The write was successful. * * DEADLINE_EXCEEDED: Unable to acquire exclusive bus access * and complete the transaction in time. * * FAILED_PRECONDITION: The interface is not initialized or enabled. * * INTERNAL: An issue occurred while writing the data. * * INVALID_ARGUMENT: ``register_address`` is larger than the 10-bit * address space. * * UNAVAILABLE: The device took too long to respond to the NACK. * *
|
inline |
Variant of pw::i2c::RegisterDevice::WriteRegister()
that writes exactly 16 bits.
|
inline |
Variant of pw::i2c::RegisterDevice::WriteRegister()
that writes exactly 32 bits.
|
inline |
Variant of pw::i2c::RegisterDevice::WriteRegister()
that writes exactly 8 bits.
|
inline |
Writes data to multiple contiguous registers starting at a specific register. This method is byte-addressable.
register_address
and register_data
use the endianness that was provided when this pw::i2c::RegisterDevice
instance was constructed.
register_data
is a correct size for your device.[in] | register_address | The register address to begin writing at. |
[in] | register_data | The data to write. Endianness is taken into account if the data is 2 or 4 bytes. |
[in] | buffer | A buffer for constructing the write data. The size of this buffer must be at least as large as the size of register_address plus the size of register_data . |
[in] | timeout | The maximum duration to block waiting for both exclusive bus access and the completion of the I2C transaction. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The bulk write was successful. * * DEADLINE_EXCEEDED: Unable to acquire exclusive bus access and * complete the transaction in time. * * FAILED_PRECONDITION: The interface is not initialized or enabled. * * INTERNAL: An issue occurred while building ``register_data``. * * INVALID_ARGUMENT: ``register_address`` is larger than the 10-bit * address space. * * OUT_OF_RANGE: The size of ``buffer`` is less than the size * of ``register_address`` plus the size of ``register_data``. * * UNAVAILABLE: The device took too long to respond to the NACK. * *
|
inline |
Variant of pw::i2c::RegisterDevice::WriteRegisters()
that requires register_data
to be exactly 16 bits.
|
inline |
Variant of pw::i2c::RegisterDevice::WriteRegisters()
that requires register_data
to be exactly 32 bits.
|
inline |
Variant of pw::i2c::RegisterDevice::WriteRegisters()
that requires register_data
to be exactly 8 bits.