COSA
An Object-Oriented Platform for Arduino Programming
TWI::Slave Class Referenceabstract

#include <TWI.hh>

Inheritance diagram for TWI::Slave:
Inheritance graph
Collaboration diagram for TWI::Slave:
Collaboration graph

Public Member Functions

 Slave (uint8_t addr)
 
void read_buf (void *buf, size_t size)
 
void write_buf (void *buf, size_t size)
 
void begin ()
 
virtual void on_completion (uint8_t type, int count)
 
virtual void on_request (void *buf, size_t size)=0
 
bool is_async () const
 
void sync_request ()
 
void async_request ()
 

Protected Member Functions

virtual void on_event (uint8_t type, uint16_t value)
 

Protected Attributes

uint8_t m_addr
 
bool m_async
 

Static Protected Attributes

static const uint8_t WRITE_IX = 0
 
static const uint8_t READ_IX = 1
 

Friends

class TWI
 
void TWI_vect (void)
 

Detailed Description

Slave device abstraction. Should set up buffers for request and response and handle incoming requests. See also USI/TWI.hh for definition for ATtiny devices.

Definition at line 129 of file TWI.hh.

Constructor & Destructor Documentation

TWI::Slave::Slave ( uint8_t  addr)
inline

Construct slave with given address.

Parameters
[in]addrslave address.

Definition at line 135 of file TWI.hh.

Member Function Documentation

void TWI::Driver::async_request ( )
inlineinherited

Set asynchronous request mode.

Definition at line 94 of file TWI.hh.

void TWI::Slave::begin ( )

Start TWI bus logic for the slave device.

Definition at line 290 of file TWI.cpp.

bool TWI::Driver::is_async ( ) const
inlineinherited

Return true(1) if the request is asyncrhonous otherwise false(0).

Definition at line 78 of file TWI.hh.

virtual void TWI::Slave::on_completion ( uint8_t  type,
int  count 
)
inlinevirtual

Service completion callback when a read/write has been completed.

Parameters
[in]typeevent code.
[in]countnumber of bytes in request.

Reimplemented from TWI::Driver.

Definition at line 163 of file TWI.hh.

void TWI::Slave::on_event ( uint8_t  type,
uint16_t  value 
)
protectedvirtual

Filter Event::WRITE_COMPLETED_TYPE(size) and calls on_request() with given write block as argument. The device is marked as ready when the request has been completed and a possible result block is available.

Parameters
[in]typethe event type.
[in]valuethe event value.

Reimplemented from Event::Handler.

Definition at line 302 of file TWI.cpp.

virtual void TWI::Slave::on_request ( void *  buf,
size_t  size 
)
pure virtual

Service request callback when a write has been completed, i.e., an argument block as been written. Must be defined by sub-class. Must handle write-read and write-write sequences. The device will become ready after the completion of the function.

Parameters
[in]bufbuffer pointer.
[in]sizeof buffer.

Implemented in VLCD::Slave.

void TWI::Slave::read_buf ( void *  buf,
size_t  size 
)

Set read (result) buffer. Must be called before starting TWI.

Parameters
[in]bufbuffer pointer.
[in]sizeof buffer.

Definition at line 319 of file TWI.cpp.

void TWI::Driver::sync_request ( )
inlineinherited

Set synchronous request mode.

Definition at line 86 of file TWI.hh.

void TWI::Slave::write_buf ( void *  buf,
size_t  size 
)

Set write (argument) buffer. Must be called before starting TWI.

Parameters
[in]bufbuffer pointer.
[in]sizeof buffer.

Definition at line 312 of file TWI.cpp.

Friends And Related Function Documentation

friend class TWI
friend

Allow access.

Definition at line 198 of file TWI.hh.

void TWI_vect ( void  )
friend

Member Data Documentation

uint8_t TWI::Driver::m_addr
protectedinherited

Device bus address.

Definition at line 114 of file TWI.hh.

bool TWI::Driver::m_async
protectedinherited

Asynchronious mode.

Definition at line 117 of file TWI.hh.

const uint8_t TWI::Slave::READ_IX = 1
staticprotected

Definition at line 184 of file TWI.hh.

const uint8_t TWI::Slave::WRITE_IX = 0
staticprotected

Internal index in io-vector for read/write buffers.

Definition at line 183 of file TWI.hh.


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