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

Overview

The Responder class provides an abstract interface for an I2C device operating in responder (target) mode. It handles callbacks for various I2C transaction events.

Inheritance diagram for pw::i2c::Responder:
pw::i2c::ZephyrResponder

Public Member Functions

constexpr Responder (Address address, ResponderEvents &events)
 
Status Enable ()
 
Status Disable ()
 

Protected Member Functions

virtual Status DoEnable ()=0
 Implementation of Enable()
 
virtual Status DoDisable ()=0
 Implementation of Disable()
 
bool OnStartRead ()
 
bool OnStartWrite ()
 
bool OnWrite (ConstByteSpan data)
 
Result< ConstByteSpanOnRead ()
 
bool OnStop ()
 
const Addressaddress () const
 

Member Function Documentation

◆ address()

const Address & pw::i2c::Responder::address ( ) const
inlineprotected
Returns
The address of this responder.

◆ Disable()

Status pw::i2c::Responder::Disable ( )
inline

Stop listening to the port

Returns
  • OK: if the responder is no longer listening.
  • An error status if the responder failed to disable.

◆ DoDisable()

virtual Status pw::i2c::Responder::DoDisable ( )
protectedpure virtual

Implementation of Disable()

Implemented in pw::i2c::ZephyrResponder.

◆ DoEnable()

virtual Status pw::i2c::Responder::DoEnable ( )
protectedpure virtual

Implementation of Enable()

Implemented in pw::i2c::ZephyrResponder.

◆ Enable()

Status pw::i2c::Responder::Enable ( )
inline

Start listening to the port

Returns
  • OK: The responder is now listening.
  • UNAVAILABLE: The I2C device is not set up or doesn't exist.
  • INTERNAL: The I2C device incurred an internal error.

◆ OnRead()

Result< ConstByteSpan > pw::i2c::Responder::OnRead ( )
inlineprotected

Called when the I2C initiator is attempting to read data from the responder. The responder should fill the provided buffer with data to be sent to the initiator. This function may be called multiple times within a single I2C read transaction.

Returns
A Result containing ConstByteSpan on success or one of the following error codes on failure:
  • OK: the span of bytes to be written to to the initiator.
  • An error code on failure when no data was read.

◆ OnStartRead()

bool pw::i2c::Responder::OnStartRead ( )
inlineprotected

Called when the I2C initiator initiates a read operation from this responder. This indicates that the initiator is expecting data from the responder. The responder should prepare for subsequent OnRead() calls.

Returns
  • true if the responder is ready to provide data.
  • false if the responder cannot handle the read operation.

◆ OnStartWrite()

bool pw::i2c::Responder::OnStartWrite ( )
inlineprotected

Called when the I2C initiator initiates a write operation to this responder. This indicates that the initiator is about to send data to the responder. The responder should prepare for subsequent OnWrite() calls.

Returns
  • true if the responder is ready to receive data.
  • false if the responder cannot handle the write operation.

◆ OnStop()

bool pw::i2c::Responder::OnStop ( )
inlineprotected

Called when the I2C initiator issues a STOP condition, signaling the end of the current transaction. This callback allows the responder to perform any necessary cleanup or state reset.

Returns
  • true on success to respond with ACK
  • false on failure to respond with NACK

◆ OnWrite()

bool pw::i2c::Responder::OnWrite ( ConstByteSpan  data)
inlineprotected

Called when the I2C initiator has written data to the responder. This function may be called multiple times within a single I2C write transaction if the initiator sends data in chunks.

Parameters
dataA span containing the data written by the initiator.
Returns
  • true if the data was processed successfully.
  • false if there was an issue processing the data.

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