semf
|
For using the I2C in master mode. More...
#include <i2cmasterhardware.h>
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< 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 | 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... | |
For using the I2C in master mode.
Definition at line 21 of file i2cmasterhardware.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 |
Definition at line 27 of file i2cmasterhardware.h.
|
virtualdefault |
|
overridevirtual |
Returns the I2C slave device address.
Implements semf::I2c.
Definition at line 77 of file i2cmasterhardware.cpp.
|
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).
address | 7 bit I2C slave address. |
Implemented in semf::Stm32I2cMaster.
|
protected |
Returns the actual frame mode setting.
Definition at line 120 of file i2cmasterhardware.cpp.
|
overridevirtual |
Communication hardware is busy reading at the moment.
Implements semf::app::Communication.
Definition at line 67 of file i2cmasterhardware.cpp.
|
overridevirtual |
Communication hardware is busy writing at the moment.
Implements semf::app::Communication.
Definition at line 72 of file i2cmasterhardware.cpp.
|
protected |
Is called after data is available in the hardware. Will emit dataAvailable
signal.
Definition at line 132 of file i2cmasterhardware.cpp.
|
protected |
Is called after data are written by the hardware. Will emit dataWritten
signal.
Definition at line 125 of file i2cmasterhardware.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 139 of file i2cmasterhardware.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. |
Implements semf::app::Communication.
Definition at line 41 of file i2cmasterhardware.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::SoftI2cMaster, and semf::Stm32I2cMaster.
|
overridevirtual |
address | Device address (0x00 - 0x80) |
SetAddress_IsBusy | If this is busy. |
Implements semf::I2c.
Definition at line 82 of file i2cmasterhardware.cpp.
|
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 115 of file i2cmasterhardware.cpp.
|
overridevirtual |
Sets the selected usage of start and stop condition.
frame | frame mode |
Implements semf::CommunicationHardware.
Definition at line 94 of file i2cmasterhardware.cpp.
|
protectedpure virtual |
Configures the frequency of the bus.
hz | Frequency in hertz. |
|
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. |
Implements semf::app::Communication.
Definition at line 15 of file i2cmasterhardware.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::Stm32I2cMaster, and semf::SoftI2cMaster.
semf::Signal semf::I2cMasterHardware::addressFound |
Gets emitted after calling checkAddress
successfully.
Definition at line 75 of file i2cmasterhardware.h.