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

Overview

Structure to hold all mockable callbacks for the Responder. Test fixtures can use this to set up and verify interactions. The generic ResponderTest fixture will own an instance of this struct and pass it to the NativeResponderTest constructor.

Inheritance diagram for pw::i2c::test::ResponderEventsForTest:
pw::i2c::ResponderEvents

Public Member Functions

bool OnStartRead () override
 
bool OnStartWrite () override
 
bool OnWrite (ConstByteSpan data) override
 
Result< ConstByteSpanOnRead () override
 
bool OnStop () override
 
void SetOnStartReadCb (pw::Function< bool()> &&cb)
 
void SetOnStartWriteCb (pw::Function< bool()> &&cb)
 
void SetOnWriteCb (pw::Function< bool(ConstByteSpan)> &&cb)
 
void SetOnReadCb (pw::Function< Result< ConstByteSpan >()> &&cb)
 
void SetOnStopCb (pw::Function< bool()> &&cb)
 
virtual bool OnStartRead ()
 
virtual bool OnStartWrite ()
 
virtual bool OnWrite (ConstByteSpan data)
 
virtual Result< ConstByteSpanOnRead ()
 
virtual bool OnStop ()
 

Member Function Documentation

◆ OnRead()

Result< ConstByteSpan > pw::i2c::test::ResponderEventsForTest::OnRead ( )
inlineoverridevirtual

Called when data is needed from the bus.

The responder implementation is responsible for handling hardware that doesn't support a hardware cache. In those cases follow-up interrupts for reading the next byte should consume the next byte from the original span until all the bytes have been consumed. At which point this function will be called again.

Returns
A Result containing ConstByteSpan on success or one of the following error codes on failure:
  • OK along with a byte span used to send to the initiator. An ACK will be sent for each valid byte.
  • Any error status to NACK.

Reimplemented from pw::i2c::ResponderEvents.

◆ OnStartRead()

bool pw::i2c::test::ResponderEventsForTest::OnStartRead ( )
inlineoverridevirtual

Called when a read start condition is seen.

Returns
  • true to send an ACK
  • false to NACK

Reimplemented from pw::i2c::ResponderEvents.

◆ OnStartWrite()

bool pw::i2c::test::ResponderEventsForTest::OnStartWrite ( )
inlineoverridevirtual

Called when a write start condition is seen.

Returns
  • true to send an ACK
  • false to NACK

Reimplemented from pw::i2c::ResponderEvents.

◆ OnStop()

bool pw::i2c::test::ResponderEventsForTest::OnStop ( )
inlineoverridevirtual

Called when the stop condition is received.

Returns
  • true to send an ACK
  • false to NACK

Reimplemented from pw::i2c::ResponderEvents.

◆ OnWrite()

bool pw::i2c::test::ResponderEventsForTest::OnWrite ( ConstByteSpan  data)
inlineoverridevirtual

Called when data is available on the bus.

Depending on the IC, some buses have hardware caches so they will call this function once with a few bytes while others will call this once per byte. Either way, the write is not considered complete until the stop condition is called.

  • data The data written to the responder
    Returns
    • true to send an ACK
    • false to NACK

Reimplemented from pw::i2c::ResponderEvents.


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