semf
|
This class used two GPIOs (SCL and SDA) and a Timer and implements a software I2C Master interface. More...
#include <softi2cmaster.h>
Public Types | |
enum class | ErrorCode : uint8_t { StopConditionSetSda_NackError = 0 } |
Error IDs for this class. Error ID identify a unique error() / onError call (excluding transferring). More... | |
Public Types inherited from semf::I2cMasterHardware | |
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 | |
SoftI2cMaster (Gpio &scl, Gpio &sda, app::Timer &timer) | |
Constructor. More... | |
SoftI2cMaster (const SoftI2cMaster &other)=delete | |
virtual | ~SoftI2cMaster ()=default |
void | init () override |
void | deinit () override |
void | stopWrite () override |
void | stopRead () override |
Public Member Functions inherited from semf::I2cMasterHardware | |
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... | |
Protected Member Functions | |
void | writeHardware (const uint8_t data[], size_t size) override |
Hardware will write data. After finished write operation, onDataWritten() function will be called. More... | |
void | readHardware (uint8_t buffer[], size_t bufferSize) override |
Hardware will read data. After finished read operation, onDataAvailable() function will be called. More... | |
Protected Member Functions inherited from semf::I2cMasterHardware | |
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... | |
Additional Inherited Members | |
Public Attributes inherited from semf::I2cMasterHardware | |
semf::Signal | addressFound |
Public Attributes inherited from semf::app::Communication | |
Signal | dataWritten |
Signal | dataAvailable |
Signal | writeStopped |
Signal | readStopped |
Signal< Error > | error |
This class used two GPIOs (SCL and SDA) and a Timer and implements a software I2C Master interface.
If possible, use a hardware timer. The I2C frequency is half of the timer frequency.
Definition at line 29 of file softi2cmaster.h.
|
strong |
Error IDs for this class. Error ID identify a unique error() / onError call (excluding transferring).
Enumerator | |
---|---|
StopConditionSetSda_NackError |
Definition at line 35 of file softi2cmaster.h.
semf::SoftI2cMaster::SoftI2cMaster | ( | Gpio & | scl, |
Gpio & | sda, | ||
app::Timer & | timer | ||
) |
Constructor.
timer
frequency. scl | GPIO to use as SCL output. |
sda | GPIO to use as SDA output and input. |
timer | Ideally use a hardware timer to handle the I2C timing. |
Definition at line 15 of file softi2cmaster.cpp.
|
explicitdelete |
|
virtualdefault |
|
overridevirtual |
Deinitializes the hardware
Implements semf::CommunicationHardware.
Definition at line 41 of file softi2cmaster.cpp.
|
overridevirtual |
Initializes the hardware.
Implements semf::CommunicationHardware.
Definition at line 22 of file softi2cmaster.cpp.
|
overrideprotectedvirtual |
Hardware will read data. After finished read operation, onDataAvailable()
function will be called.
buffer | Buffer to store received data in. |
bufferSize | Size of data . |
Implements semf::I2cMasterHardware.
Definition at line 86 of file softi2cmaster.cpp.
|
overridevirtual |
Stops the read process as fast as possible without destroying anything. The readStopped
Signal gets emitted if the call was successful.
Implements semf::app::Communication.
Definition at line 56 of file softi2cmaster.cpp.
|
overridevirtual |
Stops the write process as fast as possible without destroying anything. The writeStopped
Signal gets emitted if the call was successful.
Implements semf::app::Communication.
Definition at line 49 of file softi2cmaster.cpp.
|
overrideprotectedvirtual |
Hardware will write data. After finished write operation, onDataWritten()
function will be called.
data | Array of data to write. |
dataSize | Size of data . |
Implements semf::I2cMasterHardware.
Definition at line 63 of file softi2cmaster.cpp.