Class Client

Inheritance Relationships

Base Types

Derived Types

Class Documentation

class Client : public TWI::EndPoint, public CycleTimer

Base abstract definition for a TWI client.

See also

EndPoint, Host This class implements the basic state machine to interface a TWI bus as a client. It is design to be controlled by a upper layer object (a controller). The interface notifies the controller of bus events (start, address, etc) via the signals and the controller shall use the API of this class to react accordingly.

Subclassed by ArchAVR_TWI::_Client, ArchXT_TWI::_Client

Public Types

enum State

Values:

enumerator State_Disabled

Client disabled.

enumerator State_Idle

Client idle.

enumerator State_Start

Receiving a Start condition.

enumerator State_AddressRx

Receving a Address/RW byte.

enumerator State_AddressRAck

Pending/transmitting a ACK/NACK for a read request.

enumerator State_AddressWAck

Pending/transmitting a ACK/NACK for a Write request.

enumerator State_DataTx

Read request ACKed, in TX mode, pending/transmitting data.

enumerator State_DataTxAck

Data sent, receiving ACK bit from the host.

enumerator State_DataRx

Write request ACKed, in RX mode, pending/receiving data.

enumerator State_DataRxAck

Data received, pending/sending ACK bit.

enumerator State_Count

Total number of states.

Public Functions

Client()

Construct a client interface.

void init(CycleManager &cycle_manager)

Initialisation of the interface, must be called before any operation.

inline State state() const

Getter for the state of the client.

void set_enabled(bool enabled)

Enable/disable the interface.

inline bool enabled() const

Returns true if the client is enabled, false if disabled.

void reset()

Reset the interface to the Idle state. No-op if the interface is disabled.

bool active() const

Returns whether the interface is currently active, i.e. participating in bus traffic. For a client, it means it has positively acknowledged the address byte.

bool clock_hold() const

Returns whether the client is currently holding the clock line.

unsigned char rw() const

Returns the direction of the current request, depending on the latest RW bit received.

Returns:

1 for a Read Request, 0 for a Write Request

inline bool ack() const

Returns the latest state of the ACK bit, either sent by this client, or received by the host, after an address or a data byte.

Returns:

true for ACK, false for NACK

bool set_ack(bool ack)

Set the ack reply, after either an address or a data byte has been received.

Parameters:

ack – true for ACK, false for NACK

Returns:

true if the call was ‘legal’ i.e. the host was waiting for a ACK, false otherwise

bool start_data_tx(uint8_t data)

Start transmitting a data byte, in response to a Read Request.

Parameters:

data – byte to be transmitted

Returns:

true if the call was ‘legal’, false otherwise

bool start_data_rx()

Start receiving a data byte, in response to a Write Request.

Returns:

true if the call was ‘legal’, false otherwise

inline Signal &signal()

Getter for the client signal.

virtual cycle_count_t next(cycle_count_t when) override

Callback from the cycle loop.

Note

there’s no guarantee the method will be called exactly on the required ‘when’ cycle. The only guarantee is “called ‘when’ <= ‘current cycle’”, the implementations must account for this.

Note

The next ‘when’ can be in the ‘past’ (i.e. <= ‘current cycle’). In this case, the timer will be called again within the same cycle with the given next ‘when’. The only constraint is that it must be greater than the previous ‘when’. If it’s negative or zero, the timer is removed from the queue.

Parameters:

when – current ‘when’ cycle, at which the timer was scheduled

Returns:

the next ‘when’ the timer requires to be called at.

Protected Functions

virtual void clock_level_changed(bool level) override
virtual void data_level_changed(bool level) override