C/C++ API Reference
Loading...
Searching...
No Matches
pw::i2c::Message Class Reference

Overview

A struct that represents I2C read and write messages.

Individual messages can be accumulated into a span and transmitted in one atomic i2c transaction using an Initiator implementation.

#include "pw_i2c/message.h"
constexpr auto kAddress = pw::i2c::Address::SevenBit<0x42>()
constexpr chrono::SystemClock::duration kTimeout =
std::chrono::duration_cast<chrono::SystemClock::duration>(100ms);
const std::array<std::byte, 2> tx_buffer = {std::byte{0xCD},
std::byte{0xEF}};
std::array<std::byte, 2> rx_buffer;
Vector<Message, 2> messages;
if (!tx_buffer.empty()) {
messages.push_back(Message::WriteMessage(kAddress, tx_buffer));
}
if (!rx_buffer.empty()) {
messages.push_back(Message::ReadMessage(kAddress, rx_buffer));
}
initiator.TransferFor(messages, kTimeout);
static constexpr Message ReadMessage(Address address, ByteSpan data)
Definition: message.h:108
static constexpr Message WriteMessage(Address address, ConstByteSpan data)
Definition: message.h:65

Public Member Functions

bool IsRead () const
 
bool IsTenBit () const
 
bool IsWriteContinuation () const
 
Address GetAddress () const
 
ByteSpan GetMutableData () const
 
ConstByteSpan GetData () const
 

Static Public Member Functions

static constexpr Message WriteMessage (Address address, ConstByteSpan data)
 
static constexpr Message WriteMessageContinuation (ConstByteSpan data)
 
static constexpr Message ReadMessage (Address address, ByteSpan data)
 

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