![]() |
semf
|
This class can be used for using the I2C bus as a slave. Call startListening()
for receiving I/O-requests from the master. You can handle them by connecting the signals readExpected
and writeExpected
and performing the I/O-calls accordingly.
More...
#include <i2cslavehardware.h>
Public Types | |
enum class | ErrorCode : uint8_t { Write_IsBusy = 0 , Write_DataIsNullptr , Write_DataSizeIsZero , Read_IsBusy , Read_BufferIsNullptr , Read_BufferSizeIsZero , SetAddress_IsBusy , SetFrequency_IsBusy , StartListening_IsBusy , StopListening_IsBusy } |
Error codes for this class. Error ID identify a unique error() / onError call (excluding transferring). More... | |
![]() | |
enum class | Type { SynchronousMaster = 1 , SynchronousSlave , Asynchronous } |
enum class | Frame : uint8_t { First = 0x01 , Next = 0x08 , Last = 0x10 , FirstAndLast = 0x11 } |
Public Member Functions | |
virtual | ~I2cSlaveHardware ()=default |
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... | |
void | setFrame (CommunicationHardware::Frame frame) override |
Sets the selected usage of start and stop condition. More... | |
uint8_t | address () const override |
Returns the I2C slave device address. More... | |
void | setAddress (uint8_t address) override |
Sets the address of the slave. More... | |
void | setFrequency (uint32_t hz) override |
Sets the speed (I2C baud rate). More... | |
void | startListening () |
Starts to react on getting addressed. More... | |
void | stopListening () |
Quits reacting on getting addressed. More... | |
bool | isListening () const |
Returns the listening flag. More... | |
![]() | |
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 |
![]() | |
virtual | ~CommunicationHardwareSynchronousSlave ()=default |
Type | type () const override |
Returns the hardware type. More... | |
![]() | |
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... | |
![]() | |
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 | |
Signal | readExpected |
Signal | writeExpected |
![]() | |
Signal | dataWritten |
Signal | dataAvailable |
Signal | writeStopped |
Signal | readStopped |
Signal< Error > | error |
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 | startListeningHardware ()=0 |
virtual void | stopListeningHardware ()=0 |
virtual void | setAddressHardware (uint8_t address)=0 |
Sets the address of the i2c hardware. More... | |
void | setListening (bool listening) |
Sets the listening flag. More... | |
virtual void | setFrequencyHardware (uint32_t hz)=0 |
Configures the frequency of the bus. More... | |
void | onDataWritten () |
Is called after data are written by the hardware. Will emit dataWritten signal. More... | |
void | onDataAvailable () |
Is called after data is available in the hardware. Will emit dataAvailable signal. More... | |
void | onError (Error thrown) |
Is called if an error occurred by hardware read or write access. Will emit error signal. More... | |
This class can be used for using the I2C bus as a slave. Call startListening()
for receiving I/O-requests from the master. You can handle them by connecting the signals readExpected
and writeExpected
and performing the I/O-calls accordingly.
Definition at line 22 of file i2cslavehardware.h.
|
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 | |
SetFrequency_IsBusy | |
StartListening_IsBusy | |
StopListening_IsBusy |
Definition at line 28 of file i2cslavehardware.h.
|
virtualdefault |
|
overridevirtual |
Returns the I2C slave device address.
Implements semf::I2c.
Definition at line 106 of file i2cslavehardware.cpp.
|
protected |
Returns the actual frame mode setting.
Definition at line 170 of file i2cslavehardware.cpp.
|
overridevirtual |
Communication hardware is busy reading at the moment.
Implements semf::app::Communication.
Definition at line 75 of file i2cslavehardware.cpp.
|
overridevirtual |
Communication hardware is busy writing at the moment.
Implements semf::app::Communication.
Definition at line 80 of file i2cslavehardware.cpp.
bool semf::I2cSlaveHardware::isListening | ( | ) | const |
Returns the listening flag.
Definition at line 160 of file i2cslavehardware.cpp.
|
protected |
Is called after data is available in the hardware. Will emit dataAvailable
signal.
Definition at line 187 of file i2cslavehardware.cpp.
|
protected |
Is called after data are written by the hardware. Will emit dataWritten
signal.
Definition at line 180 of file i2cslavehardware.cpp.
|
protected |
Is called if an error occurred by hardware read or write access. Will emit error
signal.
thrown | A thrown error object. |
Definition at line 194 of file i2cslavehardware.cpp.
|
overridevirtual |
For reading data, dataAvailable
signal will be emitted after successful read.
buffer | Buffer to store received bytes in. |
bufferSize | Size of receive buffer. |
Read_IsBusy | If this is busy. |
Read_BufferIsNullptr | If buffer is nullptr. |
Read_BufferSizeIsZero | If bufferSize is zero. |
startListening
before calling this function. If write
gets called from idle-state the behavior is unspecified! Implements semf::app::Communication.
Definition at line 45 of file i2cslavehardware.cpp.
|
protectedpure virtual |
Hardware will read data. After finished read operation, onDataAvailable()
function will be called.
buffer | Buffer to store received data in. |
bufferSize | Size of data . |
Implemented in semf::Stm32I2cSlave.
|
overridevirtual |
Sets the address of the slave.
address | new address of the slave. |
SetAddress_IsBusy | If this is busy. |
Implements semf::I2c.
Definition at line 111 of file i2cslavehardware.cpp.
|
protectedpure virtual |
Sets the address of the i2c hardware.
address | Address of the slave. |
Implemented in semf::Stm32I2cSlave.
|
protected |
Sets the busy flag.
write()
, read()
busy is set to true
. In onDataAvailable()
, onDataWritten()
and onError()
is busy reseted to false
. isBusy | true for busy, false for idle. |
Definition at line 165 of file i2cslavehardware.cpp.
|
overridevirtual |
Sets the selected usage of start and stop condition.
frame | frame mode |
Implements semf::CommunicationHardware.
Definition at line 85 of file i2cslavehardware.cpp.
|
overridevirtual |
Sets the speed (I2C baud rate).
hz | Frequency in hz. |
SetFrequency_IsBusy | If this is busy. |
Implements semf::I2c.
Reimplemented in semf::Stm32I2cSlave.
Definition at line 124 of file i2cslavehardware.cpp.
|
protectedpure virtual |
Configures the frequency of the bus.
hz | Frequency in hertz. |
|
protected |
Sets the listening flag.
listening | The new listening flag. |
Definition at line 175 of file i2cslavehardware.cpp.
void semf::I2cSlaveHardware::startListening | ( | ) |
Starts to react on getting addressed.
StartListening_IsBusy | If this is busy. |
Definition at line 136 of file i2cslavehardware.cpp.
|
protectedpure virtual |
Hardware will react on getting addressed.
Implemented in semf::Stm32I2cSlave.
void semf::I2cSlaveHardware::stopListening | ( | ) |
Quits reacting on getting addressed.
StopListening_IsBusy | If this is listening. |
Definition at line 148 of file i2cslavehardware.cpp.
|
protectedpure virtual |
Hardware will ignore getting addressed.
Implemented in semf::Stm32I2cSlave.
|
overridevirtual |
For writing data, dataWritten
signal will be emitted after successful write.
data | Array, containing data to write. |
dataSize | Size of write data. |
Write_IsBusy | If this is busy. |
Write_DataIsNullptr | If data is nullptr. |
Write_DataSizeIsZero | If dataSize is zero. |
startListening
before calling this function. If write
gets called from idle-state the behavior is unspecified! Implements semf::app::Communication.
Definition at line 15 of file i2cslavehardware.cpp.
|
protectedpure virtual |
Hardware will write data. After finished write operation, onDataWritten()
function will be called.
data | Array of data to write. |
dataSize | Size of data . |
Implemented in semf::Stm32I2cSlave.
Signal semf::I2cSlaveHardware::readExpected |
Gets emitted if the master requests to write.
Definition at line 92 of file i2cslavehardware.h.
Signal semf::I2cSlaveHardware::writeExpected |
Gets emitted if the master requests to read.
Definition at line 94 of file i2cslavehardware.h.