semf
semf::I2cMasterHardware Class Referenceabstract

For using the I2C in master mode. More...

#include <i2cmasterhardware.h>

Inheritance diagram for semf::I2cMasterHardware:
Inheritance graph
Collaboration diagram for semf::I2cMasterHardware:
Collaboration graph

Public Types

enum class  ErrorCode : uint8_t {
  Write_IsBusy = 0 , Write_DataIsNullptr , Write_DataSizeIsZero , Read_IsBusy ,
  Read_BufferIsNullptr , Read_BufferSizeIsZero , SetAddress_IsBusy
}
 Error codes for this class. Error ID identify a unique error() / onError call (excluding transferring). More...
 
- Public Types inherited from semf::CommunicationHardware
enum class  Type { SynchronousMaster = 1 , SynchronousSlave , Asynchronous }
 
enum class  Frame : uint8_t { First = 0x01 , Next = 0x08 , Last = 0x10 , FirstAndLast = 0x11 }
 

Public Member Functions

virtual ~I2cMasterHardware ()=default
 
virtual void checkAddress (uint8_t address)=0
 Checks if the given address is available on the bus. Emits address found if successful (ACK). error signal will be emitted, if no slave answers (NACK). More...
 
void write (const uint8_t data[], size_t dataSize) override
 For writing data, dataWritten signal will be emitted after successful write. More...
 
void read (uint8_t buffer[], size_t bufferSize) override
 For reading data, dataAvailable signal will be emitted after successful read. More...
 
bool isBusyReading () const override
 Communication hardware is busy reading at the moment. More...
 
bool isBusyWriting () const override
 Communication hardware is busy writing at the moment. More...
 
uint8_t address () const override
 Returns the I2C slave device address. More...
 
void setAddress (uint8_t address) override
 
void setFrame (CommunicationHardware::Frame frame) override
 Sets the selected usage of start and stop condition. More...
 
- Public Member Functions inherited from semf::I2c
virtual ~I2c ()=default
 
virtual void setFrequency (uint32_t hz)=0
 Sets the speed (I2C baud rate). More...
 
virtual uint8_t address () const =0
 Returns the I2C slave device address. More...
 
virtual void setAddress (uint8_t address)=0
 
- Public Member Functions inherited from semf::CommunicationHardwareSynchronousMaster
virtual ~CommunicationHardwareSynchronousMaster ()=default
 
Type type () const override
 Returns the hardware type. More...
 
- Public Member Functions inherited from semf::CommunicationHardware
virtual ~CommunicationHardware ()=default
 
virtual void init ()=0
 
virtual void deinit ()=0
 
virtual Type type () const =0
 Returns the hardware type. More...
 
virtual void setFrame (Frame frame)=0
 Sets the selected usage of start and stop condition. More...
 
- Public Member Functions inherited from semf::app::Communication
virtual ~Communication ()=default
 
virtual void write (const uint8_t data[], size_t dataSize)=0
 For writing data, dataWritten signal will be emitted after successful write. More...
 
virtual void read (uint8_t buffer[], size_t bufferSize)=0
 For reading data, dataAvailable signal will be emitted after successful read. More...
 
virtual void stopRead ()=0
 
virtual void stopWrite ()=0
 
virtual bool isBusyReading () const =0
 Communication hardware is busy reading at the moment. More...
 
virtual bool isBusyWriting () const =0
 Communication hardware is busy writing at the moment. More...
 

Public Attributes

semf::Signal addressFound
 
- Public Attributes inherited from semf::app::Communication
Signal dataWritten
 
Signal dataAvailable
 
Signal writeStopped
 
Signal readStopped
 
Signal< Errorerror
 

Protected Member Functions

void setBusy (bool isBusy)
 Sets the busy flag. More...
 
CommunicationHardware::Frame frame () const
 Returns the actual frame mode setting. More...
 
virtual void writeHardware (const uint8_t data[], size_t dataSize)=0
 Hardware will write data. After finished write operation, onDataWritten() function will be called. More...
 
virtual void readHardware (uint8_t buffer[], size_t bufferSize)=0
 Hardware will read data. After finished read operation, onDataAvailable() function will be called. More...
 
virtual void setFrequencyHardware (uint32_t hz)=0
 Configures the frequency of the bus. More...
 
void onDataWritten ()
 
void onDataAvailable ()
 
void onError (Error thrown)
 Is called if an error occurred by hardware read or write access. Will emit error signal. More...
 

Detailed Description

For using the I2C in master mode.

Definition at line 21 of file i2cmasterhardware.h.

Member Enumeration Documentation

◆ ErrorCode

enum class semf::I2cMasterHardware::ErrorCode : uint8_t
strong

Error codes for this class. Error ID identify a unique error() / onError call (excluding transferring).

Enumerator
Write_IsBusy 
Write_DataIsNullptr 
Write_DataSizeIsZero 
Read_IsBusy 
Read_BufferIsNullptr 
Read_BufferSizeIsZero 
SetAddress_IsBusy 

Definition at line 27 of file i2cmasterhardware.h.

Constructor & Destructor Documentation

◆ ~I2cMasterHardware()

virtual semf::I2cMasterHardware::~I2cMasterHardware ( )
virtualdefault

Member Function Documentation

◆ address()

uint8_t semf::I2cMasterHardware::address ( ) const
overridevirtual

Returns the I2C slave device address.

Returns
Device address.

Implements semf::I2c.

Definition at line 77 of file i2cmasterhardware.cpp.

Here is the caller graph for this function:

◆ checkAddress()

virtual void semf::I2cMasterHardware::checkAddress ( uint8_t  address)
pure virtual

Checks if the given address is available on the bus. Emits address found if successful (ACK). error signal will be emitted, if no slave answers (NACK).

Parameters
address7 bit I2C slave address.

Implemented in semf::Stm32I2cMaster.

◆ frame()

CommunicationHardware::Frame semf::I2cMasterHardware::frame ( ) const
protected

Returns the actual frame mode setting.

Returns
Frame mode for setting start and stop condition.

Definition at line 120 of file i2cmasterhardware.cpp.

Here is the caller graph for this function:

◆ isBusyReading()

bool semf::I2cMasterHardware::isBusyReading ( ) const
overridevirtual

Communication hardware is busy reading at the moment.

Returns
State of the communication hardware.

Implements semf::app::Communication.

Definition at line 67 of file i2cmasterhardware.cpp.

Here is the caller graph for this function:

◆ isBusyWriting()

bool semf::I2cMasterHardware::isBusyWriting ( ) const
overridevirtual

Communication hardware is busy writing at the moment.

Returns
State of the communication hardware.

Implements semf::app::Communication.

Definition at line 72 of file i2cmasterhardware.cpp.

Here is the caller graph for this function:

◆ onDataAvailable()

void semf::I2cMasterHardware::onDataAvailable ( )
protected

Is called after data is available in the hardware. Will emit dataAvailable signal.

Definition at line 132 of file i2cmasterhardware.cpp.

Here is the caller graph for this function:

◆ onDataWritten()

void semf::I2cMasterHardware::onDataWritten ( )
protected

Is called after data are written by the hardware. Will emit dataWritten signal.

Definition at line 125 of file i2cmasterhardware.cpp.

Here is the caller graph for this function:

◆ onError()

void semf::I2cMasterHardware::onError ( Error  thrown)
protected

Is called if an error occurred by hardware read or write access. Will emit error signal.

Parameters
thrownA thrown error object.

Definition at line 139 of file i2cmasterhardware.cpp.

Here is the caller graph for this function:

◆ read()

void semf::I2cMasterHardware::read ( uint8_t  buffer[],
size_t  bufferSize 
)
overridevirtual

For reading data, dataAvailable signal will be emitted after successful read.

Parameters
bufferBuffer to store received bytes in.
bufferSizeSize of receive buffer.
Exceptions
Read_IsBusyIf this is busy.
Read_BufferIsNullptrIf buffer is nullptr.
Read_BufferSizeIsZeroIf bufferSize is zero.

Implements semf::app::Communication.

Definition at line 41 of file i2cmasterhardware.cpp.

Here is the call graph for this function:

◆ readHardware()

virtual void semf::I2cMasterHardware::readHardware ( uint8_t  buffer[],
size_t  bufferSize 
)
protectedpure virtual

Hardware will read data. After finished read operation, onDataAvailable() function will be called.

Parameters
bufferBuffer to store received data in.
bufferSizeSize of data.

Implemented in semf::SoftI2cMaster, and semf::Stm32I2cMaster.

Here is the caller graph for this function:

◆ setAddress()

void semf::I2cMasterHardware::setAddress ( uint8_t  address)
overridevirtual

Note
Sets the address of the i2c. When this function is called by a master it specifies the address of the slave for further I/O operations. When this function is called by a slave it sets the main address of its own.
Parameters
addressDevice address (0x00 - 0x80)
Exceptions
SetAddress_IsBusyIf this is busy.

Implements semf::I2c.

Definition at line 82 of file i2cmasterhardware.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setBusy()

void semf::I2cMasterHardware::setBusy ( bool  isBusy)
protected

Sets the busy flag.

Note
in the functions write(), read() busy is set to true. In onDataAvailable(), onDataWritten() and onError() is busy reseted to false.
Parameters
isBusytrue for busy, false for idle.

Definition at line 115 of file i2cmasterhardware.cpp.

Here is the caller graph for this function:

◆ setFrame()

void semf::I2cMasterHardware::setFrame ( CommunicationHardware::Frame  frame)
overridevirtual

Sets the selected usage of start and stop condition.

Parameters
frameframe mode

Implements semf::CommunicationHardware.

Definition at line 94 of file i2cmasterhardware.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setFrequencyHardware()

virtual void semf::I2cMasterHardware::setFrequencyHardware ( uint32_t  hz)
protectedpure virtual

Configures the frequency of the bus.

Parameters
hzFrequency in hertz.
Here is the caller graph for this function:

◆ write()

void semf::I2cMasterHardware::write ( const uint8_t  data[],
size_t  dataSize 
)
overridevirtual

For writing data, dataWritten signal will be emitted after successful write.

Parameters
dataArray, containing data to write.
dataSizeSize of write data.
Exceptions
Write_IsBusyIf this is busy.
Write_DataIsNullptrIf data is nullptr
Write_DataSizeIsZeroIf dataSize is zero.

Implements semf::app::Communication.

Definition at line 15 of file i2cmasterhardware.cpp.

Here is the call graph for this function:

◆ writeHardware()

virtual void semf::I2cMasterHardware::writeHardware ( const uint8_t  data[],
size_t  dataSize 
)
protectedpure virtual

Hardware will write data. After finished write operation, onDataWritten() function will be called.

Parameters
dataArray of data to write.
dataSizeSize of data.

Implemented in semf::Stm32I2cMaster, and semf::SoftI2cMaster.

Here is the caller graph for this function:

Member Data Documentation

◆ addressFound

semf::Signal semf::I2cMasterHardware::addressFound

Gets emitted after calling checkAddress successfully.

Definition at line 75 of file i2cmasterhardware.h.