semf
semf::Stm32I2cMaster Class Reference

I2cMasterHardware implementation for STM32. More...

#include <stm32i2cmaster.h>

Inheritance diagram for semf::Stm32I2cMaster:
Inheritance graph
Collaboration diagram for semf::Stm32I2cMaster:
Collaboration graph

Public Types

enum class  ErrorCode : uint8_t {
  Init_HalError = 0 , Init_HalBusy , Init_HalTimeout , Deinit_HalError ,
  Deinit_HalBusy , Deinit_HalTimeout , StopWrite_HalError , StopWrite_HalBusy ,
  StopWrite_HalTimeout , StopRead_HalError , StopRead_HalBusy , StopRead_HalTimeout ,
  SetFrequency_IsBusy , IsrError_HalError , ReadHardware_HalError , ReadHardware_HalBusy ,
  ReadHardware_HalTimeout , WriteHardware_HalError , WriteHardware_HalBusy , WriteHardware_HalTimeout
}
 
- 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

 Stm32I2cMaster (I2C_HandleTypeDef &hwHandle)
 Constructor. More...
 
 Stm32I2cMaster (const Stm32I2cMaster &other)=delete
 
virtual ~Stm32I2cMaster ()=default
 
void init () override
 
void deinit () override
 
void stopWrite () override
 
void stopRead () override
 
void setFrequency (uint32_t hz) override
 Sets the speed (I2C baud rate). More...
 
void checkAddress (uint8_t address) override
 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 isrRead (I2C_HandleTypeDef &i2c)
 Interrupt service routine for i2c object receive. More...
 
void isrWritten (I2C_HandleTypeDef &i2c)
 Interrupt service routine for i2c object transmit. More...
 
void isrError (I2C_HandleTypeDef &i2c)
 Interrupt service routine for i2c object error. More...
 
void isrAbort (I2C_HandleTypeDef &i2c)
 Interrupt service routine for i2c object abort. More...
 
- 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...
 
- Public Member Functions inherited from semf::LinkedQueue< T >::Node
virtual ~Node ()=default
 
T * next () const
 Returns a pointer to the next element in a queue. More...
 
void setNext (T *next)
 Sets a pointer to the next element in a list. More...
 
bool isInQueue (LinkedQueue &queue)
 Returns if a node is part of this LinkedQueue. More...
 

Static Public Member Functions

static LinkedQueue< Stm32I2cMaster > * queue ()
 Get the list with all i2c. More...
 
static void systemIsrRead (I2C_HandleTypeDef &i2c)
 System-wide interrupt service routine for i2c receive. More...
 
static void systemIsrWritten (I2C_HandleTypeDef &i2c)
 System-wide interrupt service routine for i2c transmit. More...
 
static void systemIsrError (I2C_HandleTypeDef &i2c)
 System-wide interrupt service routine for i2c error. More...
 
static void systemIsrAbort (I2C_HandleTypeDef &i2c)
 System-wide interrupt service routine for process canceling. More...
 

Protected Member Functions

I2C_HandleTypeDef * hardwareHandle ()
 Returns the hardware handle. More...
 
virtual uint32_t hardwareFrame (CommunicationHardware::Frame frame) const
 Converts the frame information from semf to STM. More...
 
void readHardware (uint8_t buffer[], size_t bufferSize) override
 Hardware will read data. After finished read operation, onDataAvailable() function will be called. More...
 
void writeHardware (const uint8_t data[], size_t dataSize) override
 Hardware will write data. After finished write operation, onDataWritten() 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< Errorerror
 

Detailed Description

I2cMasterHardware implementation for STM32.

Definition at line 24 of file stm32i2cmaster.h.

Member Enumeration Documentation

◆ ErrorCode

enum class semf::Stm32I2cMaster::ErrorCode : uint8_t
strong

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

Enumerator
Init_HalError 
Init_HalBusy 
Init_HalTimeout 
Deinit_HalError 
Deinit_HalBusy 
Deinit_HalTimeout 
StopWrite_HalError 
StopWrite_HalBusy 
StopWrite_HalTimeout 
StopRead_HalError 
StopRead_HalBusy 
StopRead_HalTimeout 
SetFrequency_IsBusy 
IsrError_HalError 
ReadHardware_HalError 
ReadHardware_HalBusy 
ReadHardware_HalTimeout 
WriteHardware_HalError 
WriteHardware_HalBusy 
WriteHardware_HalTimeout 

Definition at line 28 of file stm32i2cmaster.h.

Constructor & Destructor Documentation

◆ Stm32I2cMaster() [1/2]

semf::Stm32I2cMaster::Stm32I2cMaster ( I2C_HandleTypeDef &  hwHandle)
explicit

Constructor.

Parameters
hwHandlei2c hardware interface

Definition at line 18 of file stm32i2cmaster.cpp.

Here is the call graph for this function:

◆ Stm32I2cMaster() [2/2]

semf::Stm32I2cMaster::Stm32I2cMaster ( const Stm32I2cMaster other)
explicitdelete

◆ ~Stm32I2cMaster()

virtual semf::Stm32I2cMaster::~Stm32I2cMaster ( )
virtualdefault

Member Function Documentation

◆ checkAddress()

void semf::Stm32I2cMaster::checkAddress ( uint8_t  address)
overridevirtual

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.

Implements semf::I2cMasterHardware.

Definition at line 149 of file stm32i2cmaster.cpp.

Here is the call graph for this function:

◆ deinit()

void semf::Stm32I2cMaster::deinit ( )
overridevirtual

Deinitializes the hardware

Exceptions
Deinit_HalErrorIf the ST-HAL returns a hal error.
Deinit_HalBusyIf the ST-HAL returns a hal busy.
Deinit_HalTimeoutIf the ST-HAL returns a hal timeout.

Implements semf::CommunicationHardware.

Definition at line 50 of file stm32i2cmaster.cpp.

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

◆ hardwareFrame()

uint32_t semf::Stm32I2cMaster::hardwareFrame ( CommunicationHardware::Frame  frame) const
protectedvirtual

Converts the frame information from semf to STM.

Parameters
frameFrame information.
Returns
STM frame information.

Definition at line 230 of file stm32i2cmaster.cpp.

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

◆ hardwareHandle()

I2C_HandleTypeDef * semf::Stm32I2cMaster::hardwareHandle ( )
protected

Returns the hardware handle.

Returns
hardware handle.

Definition at line 225 of file stm32i2cmaster.cpp.

◆ init()

void semf::Stm32I2cMaster::init ( )
overridevirtual

Initializes the hardware.

Exceptions
Init_HalErrorIf the ST-HAL returns a hal error.
Init_HalBusyIf the ST-HAL returns a hal busy.
Init_HalTimeoutIf the ST-HAL returns a hal timeout.

Implements semf::CommunicationHardware.

Definition at line 25 of file stm32i2cmaster.cpp.

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

◆ isrAbort()

void semf::Stm32I2cMaster::isrAbort ( I2C_HandleTypeDef &  i2c)

Interrupt service routine for i2c object abort.

Parameters
i2cHardware handler.

Definition at line 215 of file stm32i2cmaster.cpp.

Here is the call graph for this function:

◆ isrError()

void semf::Stm32I2cMaster::isrError ( I2C_HandleTypeDef &  i2c)

Interrupt service routine for i2c object error.

Parameters
i2cHardware handler.
Exceptions
IsrError_HalErrorIf an unexpected error occures.

Definition at line 206 of file stm32i2cmaster.cpp.

Here is the call graph for this function:

◆ isrRead()

void semf::Stm32I2cMaster::isrRead ( I2C_HandleTypeDef &  i2c)

Interrupt service routine for i2c object receive.

Parameters
i2cHardware handler.

Definition at line 188 of file stm32i2cmaster.cpp.

Here is the call graph for this function:

◆ isrWritten()

void semf::Stm32I2cMaster::isrWritten ( I2C_HandleTypeDef &  i2c)

Interrupt service routine for i2c object transmit.

Parameters
i2cHardware handler.

Definition at line 197 of file stm32i2cmaster.cpp.

Here is the call graph for this function:

◆ queue()

LinkedQueue< Stm32I2cMaster > * semf::Stm32I2cMaster::queue ( )
static

Get the list with all i2c.

Returns
The list with all i2c.

Definition at line 158 of file stm32i2cmaster.cpp.

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

◆ readHardware()

void semf::Stm32I2cMaster::readHardware ( uint8_t  buffer[],
size_t  bufferSize 
)
overrideprotectedvirtual

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

Parameters
bufferBuffer to store received data in.
bufferSizeSize of data.
Exceptions
ReadHardware_HalErrorIf the ST-HAL returns a hal error.
ReadHardware_HalBusyIf the ST-HAL returns a hal timeout.
ReadHardware_HalTimeoutIf the ST-HAL returns a hal busy.

Implements semf::I2cMasterHardware.

Definition at line 256 of file stm32i2cmaster.cpp.

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

◆ setFrequency()

void semf::Stm32I2cMaster::setFrequency ( uint32_t  hz)
overridevirtual

Sets the speed (I2C baud rate).

Parameters
hzFrequency in hz.
Exceptions
SetFrequency_IsBusyIf this is busy.

Implements semf::I2c.

Definition at line 135 of file stm32i2cmaster.cpp.

Here is the call graph for this function:

◆ stopRead()

void semf::Stm32I2cMaster::stopRead ( )
overridevirtual

Stops the read process as fast as possible without destroying anything. The readStopped Signal gets emitted if the call was successful.

Exceptions
StopRead_HalErrorIf the ST-HAL returns a hal error.
StopRead_HalBusyIf the ST-HAL returns a hal busy.
StopRead_HalTimeoutIf the ST-HAL returns a hal timeout.

Implements semf::app::Communication.

Definition at line 105 of file stm32i2cmaster.cpp.

Here is the call graph for this function:

◆ stopWrite()

void semf::Stm32I2cMaster::stopWrite ( )
overridevirtual

Stops the write process as fast as possible without destroying anything. The writeStopped Signal gets emitted if the call was successful.

Exceptions
StopWrite_HalErrorIf the ST-HAL returns a hal error.
StopWrite_HalBusyIf the ST-HAL returns a hal busy.
StopWrite_HalTimeoutIf the ST-HAL returns a hal timeout.

Implements semf::app::Communication.

Definition at line 75 of file stm32i2cmaster.cpp.

Here is the call graph for this function:

◆ systemIsrAbort()

void semf::Stm32I2cMaster::systemIsrAbort ( I2C_HandleTypeDef &  i2c)
static

System-wide interrupt service routine for process canceling.

Parameters
i2cHardware handler.

Definition at line 182 of file stm32i2cmaster.cpp.

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

◆ systemIsrError()

void semf::Stm32I2cMaster::systemIsrError ( I2C_HandleTypeDef &  i2c)
static

System-wide interrupt service routine for i2c error.

Parameters
i2cHardware handler.

Definition at line 176 of file stm32i2cmaster.cpp.

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

◆ systemIsrRead()

void semf::Stm32I2cMaster::systemIsrRead ( I2C_HandleTypeDef &  i2c)
static

System-wide interrupt service routine for i2c receive.

Parameters
i2cHardware handler.

Definition at line 164 of file stm32i2cmaster.cpp.

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

◆ systemIsrWritten()

void semf::Stm32I2cMaster::systemIsrWritten ( I2C_HandleTypeDef &  i2c)
static

System-wide interrupt service routine for i2c transmit.

Parameters
i2cHardware handler.

Definition at line 170 of file stm32i2cmaster.cpp.

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

◆ writeHardware()

void semf::Stm32I2cMaster::writeHardware ( const uint8_t  data[],
size_t  dataSize 
)
overrideprotectedvirtual

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

Parameters
dataArray of data to write.
dataSizeSize of data.
Exceptions
WriteHardware_HalErrorIf the ST-HAL returns a hal error.
WriteHardware_HalBusyIf the ST-HAL returns a hal timeout.
WriteHardware_HalTimeoutIf the ST-HAL returns a hal busy.

Implements semf::I2cMasterHardware.

Definition at line 291 of file stm32i2cmaster.cpp.

Here is the call graph for this function: