semf
semf::Stm32I2cSlave Class Reference

I2cSlaveHardware implementation for STM32. More...

#include <stm32i2cslave.h>

Inheritance diagram for semf::Stm32I2cSlave:
Inheritance graph
Collaboration diagram for semf::Stm32I2cSlave:
Collaboration graph

Public Types

enum class  ErrorCode : uint8_t {
  Init_HalError = 0 , Init_HalBusy , Init_HalTimeout , Deinit_HalError ,
  Deinit_HalBusy , Deinit_HalTimeout , SystemIsrListen_EnableListenHalError , SystemIsrListen_EnableListenHalBusy ,
  SystemIsrListen_EnableListenHalTimeout , SetFrequency_IsBusy , SystemIsrError_HalError , ReadHardware_HalError ,
  ReadHardware_HalBusy , ReadHardware_HalTimeout , WriteHardware_HalError , WriteHardware_HalBusy ,
  WriteHardware_HalTimeout , StartListeningHardware_HalError , StartListeningHardware_HalBusy , StartListeningHardware_HalTimeout ,
  StopListeningHardware_HalError , StopListeningHardware_HalBusy , StopListeningHardware_HalTimeout
}
 
- Public Types inherited from semf::I2cSlaveHardware
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...
 
- 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

 Stm32I2cSlave (I2C_HandleTypeDef &hwHandle)
 Constructor. More...
 
 Stm32I2cSlave (const Stm32I2cSlave &other)=delete
 
virtual ~Stm32I2cSlave ()=default
 
void init () override
 
void deinit () override
 
void stopRead () override
 
void stopWrite () override
 
void setFrequency (uint32_t hz) override
 Sets the speed (I2C baud rate). More...
 
- Public Member Functions inherited from semf::I2cSlaveHardware
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...
 
- 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::CommunicationHardwareSynchronousSlave
virtual ~CommunicationHardwareSynchronousSlave ()=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 void systemIsrRead (I2C_HandleTypeDef &hwHandle)
 System-wide isr for data reception on an I2C-bus. More...
 
static void systemIsrWritten (I2C_HandleTypeDef &hwHandle)
 System-wide isr for data transmission on an I2C-bus. More...
 
static void systemIsrListen (I2C_HandleTypeDef &hwHandle)
 System-wide isr for end of listening on an I2C-bus. More...
 
static void systemIsrError (I2C_HandleTypeDef &hwHandle)
 
static void systemIsrAddressing (I2C_HandleTypeDef &hwHandle, uint8_t direction, uint16_t addrMatchCode)
 

Protected Member Functions

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...
 
void startListeningHardware () override
 
void stopListeningHardware () override
 
void setAddressHardware (uint8_t address) override
 Sets the address of the i2c hardware. More...
 
virtual uint32_t hardwareFrame (CommunicationHardware::Frame frame) const
 Converts the frame information from semf to STM. More...
 
I2C_HandleTypeDef * hardwareHandle ()
 Returns the hardware Handle. More...
 
- Protected Member Functions inherited from semf::I2cSlaveHardware
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...
 

Additional Inherited Members

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

Detailed Description

I2cSlaveHardware implementation for STM32.

Definition at line 23 of file stm32i2cslave.h.

Member Enumeration Documentation

◆ ErrorCode

enum class semf::Stm32I2cSlave::ErrorCode : uint8_t
strong

Error IDs 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 
SystemIsrListen_EnableListenHalError 
SystemIsrListen_EnableListenHalBusy 
SystemIsrListen_EnableListenHalTimeout 
SetFrequency_IsBusy 
SystemIsrError_HalError 
ReadHardware_HalError 
ReadHardware_HalBusy 
ReadHardware_HalTimeout 
WriteHardware_HalError 
WriteHardware_HalBusy 
WriteHardware_HalTimeout 
StartListeningHardware_HalError 
StartListeningHardware_HalBusy 
StartListeningHardware_HalTimeout 
StopListeningHardware_HalError 
StopListeningHardware_HalBusy 
StopListeningHardware_HalTimeout 

Definition at line 27 of file stm32i2cslave.h.

Constructor & Destructor Documentation

◆ Stm32I2cSlave() [1/2]

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

Constructor.

Parameters
hwHandleHardware handle.

Definition at line 17 of file stm32i2cslave.cpp.

◆ Stm32I2cSlave() [2/2]

semf::Stm32I2cSlave::Stm32I2cSlave ( const Stm32I2cSlave other)
explicitdelete

◆ ~Stm32I2cSlave()

virtual semf::Stm32I2cSlave::~Stm32I2cSlave ( )
virtualdefault

Member Function Documentation

◆ deinit()

void semf::Stm32I2cSlave::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 47 of file stm32i2cslave.cpp.

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

◆ hardwareFrame()

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

Converts the frame information from semf to STM.

Parameters
frameFrame information.
Returns
STM frame information.

Definition at line 276 of file stm32i2cslave.cpp.

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

◆ hardwareHandle()

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

Returns the hardware Handle.

Returns
Pointer to hardware handle.

Definition at line 296 of file stm32i2cslave.cpp.

◆ init()

void semf::Stm32I2cSlave::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 23 of file stm32i2cslave.cpp.

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

◆ readHardware()

void semf::Stm32I2cSlave::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 busy.
ReadHardware_HalTimeoutIf the ST-HAL returns a hal timeout.

Implements semf::I2cSlaveHardware.

Definition at line 167 of file stm32i2cslave.cpp.

Here is the call graph for this function:

◆ setAddressHardware()

void semf::Stm32I2cSlave::setAddressHardware ( uint8_t  address)
overrideprotectedvirtual

Sets the address of the i2c hardware.

Parameters
addressAddress of the slave.

Implements semf::I2cSlaveHardware.

Definition at line 269 of file stm32i2cslave.cpp.

Here is the call graph for this function:

◆ setFrequency()

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

Sets the speed (I2C baud rate).

Parameters
hzFrequency in hz.
Exceptions
SetFrequency_IsBusyIf this is busy.

Reimplemented from semf::I2cSlaveHardware.

Definition at line 81 of file stm32i2cslave.cpp.

Here is the call graph for this function:

◆ startListeningHardware()

void semf::Stm32I2cSlave::startListeningHardware ( )
overrideprotectedvirtual

Hardware will react on getting addressed.

Exceptions
StartListeningHardware_HalErrorIf the ST-HAL returns a hal error.
StartListeningHardware_HalBusyIf the ST-HAL returns a hal busy.
StartListeningHardware_HalTimeoutIf the ST-HAL returns a hal timeout.

Implements semf::I2cSlaveHardware.

Definition at line 219 of file stm32i2cslave.cpp.

Here is the call graph for this function:

◆ stopListeningHardware()

void semf::Stm32I2cSlave::stopListeningHardware ( )
overrideprotectedvirtual

Hardware will ignore getting addressed.

Exceptions
StopListeningHardware_HalErrorIf the ST-HAL returns a hal error.
StopListeningHardware_HalBusyIf the ST-HAL returns a hal busy.
StopListeningHardware_HalTimeoutIf the ST-HAL returns a hal timeout.

Implements semf::I2cSlaveHardware.

Definition at line 244 of file stm32i2cslave.cpp.

Here is the call graph for this function:

◆ stopRead()

void semf::Stm32I2cSlave::stopRead ( )
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 71 of file stm32i2cslave.cpp.

◆ stopWrite()

void semf::Stm32I2cSlave::stopWrite ( )
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 76 of file stm32i2cslave.cpp.

◆ systemIsrAddressing()

void semf::Stm32I2cSlave::systemIsrAddressing ( I2C_HandleTypeDef &  hwHandle,
uint8_t  direction,
uint16_t  addrMatchCode 
)
static

Definition at line 153 of file stm32i2cslave.cpp.

Here is the caller graph for this function:

◆ systemIsrError()

void semf::Stm32I2cSlave::systemIsrError ( I2C_HandleTypeDef &  hwHandle)
static

Definition at line 144 of file stm32i2cslave.cpp.

Here is the caller graph for this function:

◆ systemIsrListen()

void semf::Stm32I2cSlave::systemIsrListen ( I2C_HandleTypeDef &  hwHandle)
static

System-wide isr for end of listening on an I2C-bus.

Parameters
hwHandleNative handle.
Exceptions
SystemIsrListen_EnableListenHalErrorIf the ST-HAL returns a hal error.
SystemIsrListen_EnableListenHalBusyIf the ST-HAL returns a hal busy.
SystemIsrListen_EnableListenHalTimeoutIf the ST-HAL returns a hal timeout.

Definition at line 114 of file stm32i2cslave.cpp.

Here is the caller graph for this function:

◆ systemIsrRead()

void semf::Stm32I2cSlave::systemIsrRead ( I2C_HandleTypeDef &  hwHandle)
static

System-wide isr for data reception on an I2C-bus.

Parameters
hwHandleNative handle.

Definition at line 92 of file stm32i2cslave.cpp.

Here is the caller graph for this function:

◆ systemIsrWritten()

void semf::Stm32I2cSlave::systemIsrWritten ( I2C_HandleTypeDef &  hwHandle)
static

System-wide isr for data transmission on an I2C-bus.

Parameters
hwHandleNative handle.

Definition at line 103 of file stm32i2cslave.cpp.

Here is the caller graph for this function:

◆ writeHardware()

void semf::Stm32I2cSlave::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 busy.
WriteHardware_HalTimeoutIf the ST-HAL returns a hal timeout.

Implements semf::I2cSlaveHardware.

Definition at line 193 of file stm32i2cslave.cpp.

Here is the call graph for this function: