semf
semf::Stm32SpiSlave Class Reference

SpiSlaveHardware implementation for STM32. More...

#include <stm32spislave.h>

Inheritance diagram for semf::Stm32SpiSlave:
Inheritance graph
Collaboration diagram for semf::Stm32SpiSlave:
Collaboration graph

Public Types

enum class  ErrorCode : uint8_t {
  Init_HalError = 0 , Init_HalBusy , Init_HalTimeout , Deinit_HalError ,
  Deinit_HalBusy , Deinit_HalTimeout , SystemIsrError_Isr , SetFormatHardware_BitsNotSupported ,
  StopWriteHardware_HalError , StopWriteHardware_HalBusy , StopWriteHardware_HalTimeout , StopReadHardware_HalError ,
  StopReadHardware_HalBusy , StopReadHardware_HalTimeout , WriteHardware_HalError , WriteHardware_HalBusy ,
  WriteHardware_HalTimeout , ReadHardware_HalError , ReadHardware_HalBusy , ReadHardware_HalTimeout ,
  WriteReadHardware_HalError , WriteReadHardware_HalBusy , WriteReadHardware_HalTimeout
}
 
- Public Types inherited from semf::SpiSlaveHardware
enum class  ErrorCode : uint8_t {
  Write_IsBusy = 0 , Write_DataIsNullptr , Write_DataSizeIsZero , Read_IsBusy ,
  Read_BufferIsNullptr , Read_BufferSizeIsZero , SetFormat_IsBusy , StopWrite_IsNotWriting ,
  StopRead_IsNotReading , WriteRead_IsBusy , WriteRead_WriteDataIsNullptr , WriteRead_ReadBufferIsNullptr ,
  WriteRead_SizeIsZero
}
 Error IDs for this class. Error ID identify a unique error() / onError call (excluding transferring). More...
 
- Public Types inherited from semf::Spi
enum class  TransmissionMode : uint8_t { Mode0 , Mode1 , Mode2 , Mode3 }
 
enum class  WireMode : uint8_t { FullDuplexWires , HalfDuplexWires , WriteOnlyWires , ReadOnlyWires }
 
- 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

 Stm32SpiSlave (SPI_HandleTypeDef &hwHandle)
 Constructor. More...
 
 Stm32SpiSlave (const Stm32SpiSlave &other)=delete
 
virtual ~Stm32SpiSlave ()=default
 
void init () override
 
void deinit () override
 
- Public Member Functions inherited from semf::SpiSlaveHardware
virtual ~SpiSlaveHardware ()=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 stopRead () override
 
void stopWrite () override
 
void setFrame (Frame frame) override
 Sets the selected usage of start and stop condition. More...
 
void writeRead (const uint8_t writeData[], uint8_t readBuffer[], size_t size) override
 For writing and reading data parallel through the communication hardware 1) For interrupt or one shot dma mode, dataAvailable signal will be fired after successful read/write. 2) For cyclic dma mode, do not use this function. More...
 
void setFormat (uint8_t bits, TransmissionMode transmission, WireMode wire) override
 Sets the format for the spi slave device. More...
 
- Public Member Functions inherited from semf::Spi
virtual ~Spi ()=default
 
virtual void writeRead (const uint8_t writeData[], uint8_t readBuffer[], size_t size)=0
 For writing and reading data parallel through the communication hardware 1) For interrupt or one shot dma mode, dataAvailable signal will be fired after successful read/write. 2) For cyclic dma mode, do not use this function. More...
 
virtual void setFormat (uint8_t bits, TransmissionMode transmission, WireMode wire)=0
 Sets the format for the spi slave device. More...
 
- 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 (SPI_HandleTypeDef &hwHandle)
 Handles the global receive complete callback. More...
 
static void systemIsrWritten (SPI_HandleTypeDef &hwHandle)
 Handles the global transmit complete callback. More...
 
static void systemIsrWrittenAndRead (SPI_HandleTypeDef &hwHandle)
 Handles the global receive transmit complete callback. More...
 
static void systemIsrError (SPI_HandleTypeDef &hwHandle)
 Handles the global error callback. More...
 
static void systemIsrAbort (SPI_HandleTypeDef &hwHandle)
 Handles the global abort callback. More...
 

Protected Member Functions

void writeHardware (const uint8_t data[], size_t dataSize) override
 Accesses the spi hardware in order to write dataSize bytes of data. More...
 
void readHardware (uint8_t buffer[], size_t bufferSize) override
 Accesses the spi hardware in order to read bufferSize bytes and stores them in buffer. More...
 
void writeReadHardware (const uint8_t writeData[], uint8_t readBuffer[], size_t size) override
 Accesses the spi hardware in order to perform a full duplex read/write. More...
 
void stopReadHardware () override
 
void stopWriteHardware () override
 
void onReadWritten ()
 
void onReadWrittenHardware ()
 
void onAbortedHardware ()
 
void setFormatHardware (uint8_t bits, TransmissionMode transmission, WireMode wire) override
 Configures the hardware for insuring the given configuration. More...
 
- Protected Member Functions inherited from semf::SpiSlaveHardware
void onError (Error thrown)
 Error routine, emits the error signal. More...
 
void onDataAvailable ()
 
void onDataWritten ()
 
void setBusy (bool busy)
 Sets the flag m_isBusy. More...
 
virtual void writeHardware (const uint8_t data[], size_t dataSize)=0
 Accesses the spi hardware in order to write dataSize bytes of data. More...
 
virtual void readHardware (uint8_t buffer[], size_t bufferSize)=0
 Accesses the spi hardware in order to read bufferSize bytes and stores them in buffer. More...
 
virtual void writeReadHardware (const uint8_t writeData[], uint8_t readBuffer[], size_t size)=0
 Accesses the spi hardware in order to perform a full duplex read/write. More...
 
virtual void stopReadHardware ()=0
 
virtual void stopWriteHardware ()=0
 
virtual void setFormatHardware (uint8_t bits, TransmissionMode transmission, WireMode wire)=0
 Configures the hardware for insuring the given configuration. More...
 
void setWireMode (WireMode mode)
 Sets the wire mode. More...
 
void setTransmissionMode (TransmissionMode mode)
 Sets the transmission mode. More...
 

Additional Inherited Members

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

Detailed Description

SpiSlaveHardware implementation for STM32.

Definition at line 24 of file stm32spislave.h.

Member Enumeration Documentation

◆ ErrorCode

enum class semf::Stm32SpiSlave::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 
SystemIsrError_Isr 
SetFormatHardware_BitsNotSupported 
StopWriteHardware_HalError 
StopWriteHardware_HalBusy 
StopWriteHardware_HalTimeout 
StopReadHardware_HalError 
StopReadHardware_HalBusy 
StopReadHardware_HalTimeout 
WriteHardware_HalError 
WriteHardware_HalBusy 
WriteHardware_HalTimeout 
ReadHardware_HalError 
ReadHardware_HalBusy 
ReadHardware_HalTimeout 
WriteReadHardware_HalError 
WriteReadHardware_HalBusy 
WriteReadHardware_HalTimeout 

Definition at line 28 of file stm32spislave.h.

Constructor & Destructor Documentation

◆ Stm32SpiSlave() [1/2]

semf::Stm32SpiSlave::Stm32SpiSlave ( SPI_HandleTypeDef &  hwHandle)
explicit

Constructor.

Parameters
hwHandleNative hardware handle.

Definition at line 18 of file stm32spislave.cpp.

Here is the call graph for this function:

◆ Stm32SpiSlave() [2/2]

semf::Stm32SpiSlave::Stm32SpiSlave ( const Stm32SpiSlave other)
explicitdelete

◆ ~Stm32SpiSlave()

virtual semf::Stm32SpiSlave::~Stm32SpiSlave ( )
virtualdefault

Member Function Documentation

◆ deinit()

void semf::Stm32SpiSlave::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 49 of file stm32spislave.cpp.

Here is the call graph for this function:

◆ init()

void semf::Stm32SpiSlave::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 stm32spislave.cpp.

Here is the call graph for this function:

◆ onAbortedHardware()

void semf::Stm32SpiSlave::onAbortedHardware ( )
protected

Handles the abort ISR.

Definition at line 272 of file stm32spislave.cpp.

Here is the call graph for this function:

◆ onReadWritten()

void semf::Stm32SpiSlave::onReadWritten ( )
protected

Emits the signal dataAvailable and resets the busy flag.

Definition at line 250 of file stm32spislave.cpp.

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

◆ onReadWrittenHardware()

void semf::Stm32SpiSlave::onReadWrittenHardware ( )
protected

Handles the read written ISR.

Definition at line 257 of file stm32spislave.cpp.

Here is the call graph for this function:

◆ readHardware()

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

Accesses the spi hardware in order to read bufferSize bytes and stores them in buffer.

Parameters
bufferBuffer location.
bufferSizeSize of the buffer.
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::SpiSlaveHardware.

Definition at line 144 of file stm32spislave.cpp.

Here is the call graph for this function:

◆ setFormatHardware()

void semf::Stm32SpiSlave::setFormatHardware ( uint8_t  bits,
TransmissionMode  transmission,
WireMode  wire 
)
overrideprotectedvirtual

Configures the hardware for insuring the given configuration.

Parameters
bitsNumber of bits per frame.
transmissionTransmission mode (polarity and phase setting).
wireWire transmission setting.

Implements semf::SpiSlaveHardware.

Definition at line 278 of file stm32spislave.cpp.

Here is the call graph for this function:

◆ stopReadHardware()

void semf::Stm32SpiSlave::stopReadHardware ( )
overrideprotectedvirtual

Stops the hardware to read.

Exceptions
StopReadHardware_HalErrorIf the ST-HAL returns a hal error.
StopReadHardware_HalBusyIf the ST-HAL returns a hal busy.
StopReadHardware_HalTimeoutIf the ST-HAL returns a hal timeout.

Implements semf::SpiSlaveHardware.

Definition at line 198 of file stm32spislave.cpp.

Here is the call graph for this function:

◆ stopWriteHardware()

void semf::Stm32SpiSlave::stopWriteHardware ( )
overrideprotectedvirtual

Stop the hardware to write.

Exceptions
StopWriteHardware_HalErrorIf the ST-HAL returns a hal error.
StopWriteHardware_HalBusyIf the ST-HAL returns a hal busy.
StopWriteHardware_HalTimeoutIf the ST-HAL returns a hal timeout.

Implements semf::SpiSlaveHardware.

Definition at line 224 of file stm32spislave.cpp.

Here is the call graph for this function:

◆ systemIsrAbort()

void semf::Stm32SpiSlave::systemIsrAbort ( SPI_HandleTypeDef &  hwHandle)
static

Handles the global abort callback.

Parameters
hwHandleThe handle causing the callback.

Definition at line 110 of file stm32spislave.cpp.

Here is the caller graph for this function:

◆ systemIsrError()

void semf::Stm32SpiSlave::systemIsrError ( SPI_HandleTypeDef &  hwHandle)
static

Handles the global error callback.

Parameters
hwHandleThe handle causing the callback.

Definition at line 101 of file stm32spislave.cpp.

Here is the caller graph for this function:

◆ systemIsrRead()

void semf::Stm32SpiSlave::systemIsrRead ( SPI_HandleTypeDef &  hwHandle)
static

Handles the global receive complete callback.

Parameters
hwHandleThe handle causing the callback.

Definition at line 74 of file stm32spislave.cpp.

Here is the caller graph for this function:

◆ systemIsrWritten()

void semf::Stm32SpiSlave::systemIsrWritten ( SPI_HandleTypeDef &  hwHandle)
static

Handles the global transmit complete callback.

Parameters
hwHandleThe handle causing the callback.

Definition at line 83 of file stm32spislave.cpp.

Here is the caller graph for this function:

◆ systemIsrWrittenAndRead()

void semf::Stm32SpiSlave::systemIsrWrittenAndRead ( SPI_HandleTypeDef &  hwHandle)
static

Handles the global receive transmit complete callback.

Parameters
hwHandleThe handle causing the callback.

Definition at line 92 of file stm32spislave.cpp.

Here is the caller graph for this function:

◆ writeHardware()

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

Accesses the spi hardware in order to write dataSize bytes of data.

Parameters
dataData location.
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::SpiSlaveHardware.

Definition at line 119 of file stm32spislave.cpp.

Here is the call graph for this function:

◆ writeReadHardware()

void semf::Stm32SpiSlave::writeReadHardware ( const uint8_t  writeData[],
uint8_t  readBuffer[],
size_t  size 
)
overrideprotectedvirtual

Accesses the spi hardware in order to perform a full duplex read/write.

Parameters
writeDataData to write.
readBufferBuffer to read.
sizeSize of both buffers.
Exceptions
WriteReadHardware_HalErrorIf the ST-HAL returns a hal error.
WriteReadHardware_HalBusyIf the ST-HAL returns a hal busy.
WriteReadHardware_HalTimeoutIf the ST-HAL returns a hal timeout.

Implements semf::SpiSlaveHardware.

Definition at line 169 of file stm32spislave.cpp.

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