![]() |
Arduino Core for STM32
1.0
|
This class is for handling SPI periphery, but is more optimized for speed same as arduino SPI class. More...
#include <HardwareSPI.h>
Public Member Functions | |
HardwareSPI_O (SPI_HandleTypeDef &hspi) | |
Constructor. More... | |
SPI_Status | beginTransaction (SPISettings settings) override |
Enables SPI periphery and sets some settings. More... | |
uint16_t | transfer (uint16_t data, bool lastByte=false) override |
SPI transfer is based on a simultaneous send and receive data. More... | |
uint16_t | transfer16 (uint16_t data, bool lastByte=false) override |
SPI transfer is based on a simultaneous send and receive data. More... | |
uint32_t | transfer32 (uint32_t data, bool lastByte=false) override |
SPI transfer is based on a simultaneous send and receive data. More... | |
bool | write (uint16_t data, bool lastByte=false) override |
Sends data using SPI periphery. More... | |
bool | write16 (uint16_t data, bool lastByte=false) override |
Sends data using SPI periphery. More... | |
bool | write32 (uint32_t data, bool lastByte=false) override |
Sends data using SPI periphery. More... | |
uint16_t | receive (bool lastByte=false) override |
Receives data from SPI periphery. More... | |
uint16_t | receive16 (bool lastByte=false) override |
Receives data from SPI periphery. More... | |
uint32_t | receive32 (bool lastByte=false) override |
Receives data from SPI periphery. More... | |
bool | transferBytes (const uint8_t *out, uint8_t *in, uint32_t size, bool lastByte=false) override |
Transfers data using SPI periphery in blocking mode, it is sending and receiving data simultaneously. More... | |
bool | writeBytes (const uint8_t *data, uint32_t size, bool lastByte=false) override |
Sends data using SPI periphery in blocking mode. More... | |
bool | receiveBytes (uint8_t *data, uint32_t size, bool lastByte=false) override |
Receives data from SPI periphery in blocking mode. More... | |
bool | transfer (void *buf, uint16_t count, bool lastByte=false) override |
SPI transfer is based on a simultaneous send and receive data. More... | |
SPI_Status | endTransaction () override |
Disables SPI periphery and checks or sends CRC if enabled. More... | |
![]() | |
HardwareSPI (SPI_HandleTypeDef &hspi) | |
Constructor. More... | |
~HardwareSPI () | |
Destructor. More... | |
bool | begin (SPI_InitTypeDef &initStruct) |
Initialize SPI periphery and it's pins. More... | |
bool | begin () |
Initialize SPI periphery and it's pins. More... | |
bool | end () |
Deinitialization and disabling SPI periphery, it can be used for "sleep mode". More... | |
bool | isSending () |
Checks if data are sending or transferring right now using DMA or IT and if periphery is busy. More... | |
bool | isReceiving () |
Checks if data are receiving or transferring right now using DMA or IT and if periphery is busy. More... | |
bool | isTransfering () |
Checks if data are transferring right now using DMA or IT and if periphery is busy. More... | |
bool | isTransacting () |
Checks if data are sending, receiving, transferring right now using DMA or IT and if periphery is busy. More... | |
bool | instanceExists (void) |
Checks if SPI instance exists. More... | |
bool | connectDMAtoRx (DMA_HandleTypeDef &DMA_handle) |
Use this method to connect DMA channel to SPI Rx programmatically. More... | |
bool | connectDMAtoTx (DMA_HandleTypeDef &DMA_handle) |
Use this method to connect DMA channel to SPI Tx programmatically. More... | |
bool | disconnectDMAfromRx () |
Disconnects DMA channel from SPI Rx. More... | |
bool | disconnectDMAfromTx () |
Disconnects DMA channel from SPI Tx. More... | |
bool | isDMAconnectedToRx (void) |
Checks if DMA channel is connected to SPI Rx and can be used for data receiving/transferring. More... | |
bool | isDMAconnectedToTx (void) |
Checks if DMA channel is connected to SPI Tx and can be used for data writing/transferring. More... | |
uint32_t | getSPIClockFreq (void) |
Gets periphery SPI Clock Frequency in Hz. More... | |
bool | setMode (uint32_t mode) |
Sets Master or Slave mode. More... | |
uint32_t | getMode () |
Gets, if periphery mode is Master or Slave. More... | |
bool | setHwCS (bool HardwareCS, bool OutputCS=true) |
Sets if Chip Select pin is handled by hardware or by software (calling digitalWrite()). More... | |
bool | isHwCS () |
Gets, if Chip Select is handled by hardware. More... | |
bool | isHwOutputCS () |
Gets, if Chip Select handled by hardware is set to output mode. More... | |
bool | setBitOrder (uint8_t bitOrder) |
Sets bit order to LSB or MSB. More... | |
uint8_t | getBitOrder () |
Gets, if bit order is set to LSB or MSB. More... | |
bool | setDataMode (uint8_t dataMode) |
Sets data mode. More... | |
uint8_t | getDataMode () |
Gets, what data mode is set. More... | |
bool | setFrequency (uint32_t freq) |
Calculates SPI clock divider from frequency and sets it. More... | |
uint32_t | getFrequency () |
Calculates SPI frequency from APB frequency and Clock Divider. More... | |
bool | setClockDivider (uint32_t clockDiv) |
Sets SPI clock divider. More... | |
uint32_t | getClockDivider () |
Gets clock divider. More... | |
bool | setDataBits (uint16_t bits) |
Sets SPI data width in bits. More... | |
uint16_t | getDataBits () |
Gets set data width in bits. More... | |
bool | enableTImode (bool enable) |
Enables or disabled TI mode. More... | |
bool | isTImodeEnabled () |
Gets if TI mode is enabled. More... | |
bool | enableCRC (bool enable) |
Enables CRC. More... | |
bool | isCRCenabled () |
Gets if CRC is enabled. More... | |
bool | setCRClength (SPI_CRCLength length) |
Sets CRC length. More... | |
SPI_CRCLength | getCRClength () |
Gets CRC length. More... | |
bool | setCRCPolynomial (uint32_t polynomial) |
Sets CRC polynomial. More... | |
uint32_t | getCRCPolynomial () |
Gets CRC polynomial. More... | |
void | setTimeout (uint32_t Timeout) |
Sets timeout in milliseconds. More... | |
uint32_t | getTimeout () |
Gets timeout in milliseconds. More... | |
void | flushRX () |
Clears RX FIFO buffer. More... | |
bool | flush () |
Waits until DMA or IT (nonblocking transaction methods) are timed out and then aborts them. More... | |
virtual bool | writeBytesNonBlocking (const uint8_t *data, uint32_t size, bool lastByte=false) |
Sends data using SPI periphery using DMA or IT (interrupt) mode. More... | |
virtual bool | transferBytesNonBlocking (const uint8_t *out, uint8_t *in, uint32_t size, bool lastByte=false) |
Transfers data using SPI periphery using DMA or IT (interrupt) mode, it is sending and receiving data simultaneously. More... | |
virtual bool | receiveBytesNonBlocking (uint8_t *data, uint32_t size, bool lastByte=false) |
Receives data from SPI periphery in non-blocking mode using DMA or IT (interrupt) mode. More... | |
bool | isFullDuplex () |
Check, if full duplex mode is enabled for this periphery. More... | |
bool | isRxEnabled () |
Checks, if SPI periphery can receive data. More... | |
bool | isTxEnabled () |
Checks, if SPI periphery can transmit data. More... | |
operator bool () const | |
Checks if SPI instance exists. More... | |
bool | available () |
Checks if any data are available in RX FIFO buffer. More... | |
bool | hasError (void) |
Checks if instance has error. More... | |
SPI_ErrorCode | getError (void) |
Gets error, that happens during begin, end or transaction. More... | |
void | clearError (uint32_t clearMask=0xFFFFFFFFUL) |
Gets error, that happens during begin, end or transaction. More... | |
virtual SPI_Status | lastTransactionStatus () |
Checks last transaction status. More... | |
void | setWriteDoneCallback (void(*WriteDoneCallback_)()) |
Sets callback function, that will be called when all data using writeBytesNonBlocking() method were send. More... | |
void | setTransferDoneCallback (void(*TransferDoneCallback_)()) |
Sets callback function, that will be called when all data using transferBytesNonBlocking() method were transfered. More... | |
void | setReceiveDoneCallback (void(*ReceiveDoneCallback_)()) |
Sets callback function, that will be called when all data using receiveBytesNonBlocking() method were received. More... | |
void | setWriteHalfCallback (void(*WriteHalfCallback_)()) |
Sets callback function, that will be called when half of data using writeBytesNonBlocking() method were send. More... | |
void | setTransferHalfCallback (void(*TransferHalfCallback_)()) |
Sets callback function, that will be called when half of data using transferBytesNonBlocking() method were transfered. More... | |
void | setReceiveHalfCallback (void(*ReceiveHalfCallback_)()) |
Sets callback function, that will be called when half of data using receiveBytesNonBlocking() method were received. More... | |
void | setErrorCallback (void(*ErrorCallback_)(SPI_ErrorCode)) |
Sets callback function, that will be called when an error has occurred. More... | |
SPI_HandleTypeDef & | getHAL_SPI_Struct () |
Returns SPI structure, that is used for handling SPI. More... | |
Additional Inherited Members | |
![]() | |
static void | handleWriteDoneCallback (SPI_TypeDef *instance) |
Handles WriteDone callback function. More... | |
static void | handleTransferDoneCallback (SPI_TypeDef *instance) |
Handles TransferDone callback function. More... | |
static void | handleReceiveDoneCallback (SPI_TypeDef *instance) |
Handles ReceiveDone callback function. More... | |
static void | handleWriteHalfCallback (SPI_TypeDef *instance) |
Handles WriteHalf callback function. More... | |
static void | handleTransferHalfCallback (SPI_TypeDef *instance) |
Handles TransferHalf callback function. More... | |
static void | handleReceiveHalfCallback (SPI_TypeDef *instance) |
Handles ReceiveHalf callback function. More... | |
static void | handleErrorCallback (SPI_TypeDef *instance) |
Handles Error callback function. More... | |
static uint32_t | getSPIIndex (SPI_TypeDef *instance) |
Gets SPI instance index. More... | |
static HardwareSPI ** | getSPIInstances () |
Gets array of all created SPI instances (just from this class, not SPI structure). More... | |
static uint8_t | getAvailableSPIsCount () |
Gets all available SPIs instances count. More... | |
![]() | |
void | clearCRCErrorFlag () |
Clears CRC error flag from interrupt register. More... | |
void | clearOVRErrorFlag () |
Clears OVR error flag from interrupt register. More... | |
void | clearMODFlag () |
Clears MOD flag from interrupt register. More... | |
void | clearFREFlag () |
Clears FRE flag from interrupt register. More... | |
void | addThisToInstArr () |
Writes new class instance to array of all timer instances. More... | |
void | removeThisFromInstArr () |
Removes this instance from instances array. More... | |
![]() | |
SPI_HandleTypeDef * | _hspi = NULL |
Pointer to SPI handle structure. More... | |
uint32_t | _startMillis = 0 |
Start time of transferring/receiving/sending data non-blocking. More... | |
uint32_t | timeout = 1000 |
Timeout interval in ms. More... | |
SPISettings | oldSettings |
Old SPI setting - to speed up begin transaction. More... | |
void(* | WriteDoneCallback )() = NULL |
void(* | TransferDoneCallback )() = NULL |
void(* | ReceiveDoneCallback )() = NULL |
void(* | WriteHalfCallback )() = NULL |
void(* | TransferHalfCallback )() = NULL |
void(* | ReceiveHalfCallback )() = NULL |
void(* | ErrorCallback )(SPI_ErrorCode) = NULL |
SPI_Status | transactionError = SPI_OK |
Last transaction status. More... | |
![]() | |
static HardwareSPI * | instances [] |
Array of all created SPI instances (just from this class, not SPI structure). More... | |
static uint8_t | availableSPIsCount = sizeof(instances)/sizeof(*instances) |
Available SPI instances count. More... | |
This class is for handling SPI periphery, but is more optimized for speed same as arduino SPI class.
This class is optimized for speed, but may not work with all MCUs. If this happens, use HardwareSPI class.
Method group | Description |
---|---|
Initializers | Methods for initializing or de-initializing SPI periphery. |
State checking methods | Methods for checking current state. |
Setting methods | Methods for change periphery settings. |
Optimized transaction initializers | Methods for initializing transaction and flushing buffers. |
Optimized transaction methods | Methods for data transaction. |
Callback methods | Methods for event handling. |
Advanced methods | Advanced methods to extend this library when needed. |
|
inline |
Constructor.