2021-06-04 16:01:38 +02:00
|
|
|
#ifndef FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_
|
|
|
|
#define FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_
|
|
|
|
|
2021-06-04 16:34:38 +02:00
|
|
|
#include "spiDefinitions.h"
|
2021-06-10 21:31:21 +02:00
|
|
|
#include "mspInit.h"
|
2021-06-04 16:34:38 +02:00
|
|
|
|
2021-06-04 16:01:38 +02:00
|
|
|
#include "fsfw/devicehandlers/CookieIF.h"
|
|
|
|
|
2021-06-04 16:34:38 +02:00
|
|
|
#include "stm32h743xx.h"
|
|
|
|
|
2021-06-10 21:31:21 +02:00
|
|
|
/**
|
|
|
|
* @brief SPI cookie implementation for the STM32H7 device family
|
|
|
|
* @details
|
|
|
|
* This cookie contains and caches device specific information to be used by the
|
|
|
|
* SPI communication interface
|
|
|
|
* @author R. Mueller
|
|
|
|
*/
|
2021-06-04 16:01:38 +02:00
|
|
|
class SpiCookie: public CookieIF {
|
2021-06-10 21:31:21 +02:00
|
|
|
friend class SpiComIF;
|
2021-06-04 16:01:38 +02:00
|
|
|
public:
|
2021-06-10 21:31:21 +02:00
|
|
|
/**
|
|
|
|
* Allows construction of a SPI cookie for a connected SPI device
|
|
|
|
* @param deviceAddress
|
|
|
|
* @param spiIdx SPI bus, e.g. SPI1 or SPI2
|
|
|
|
* @param transferMode
|
|
|
|
* @param mspCfg This is the MSP configuration. The user is expected to supply
|
|
|
|
* a valid MSP configuration. See mspInit.h for functions
|
|
|
|
* to create one.
|
|
|
|
* @param spiSpeed
|
|
|
|
* @param spiMode
|
|
|
|
* @param chipSelectGpioPin GPIO port. Don't use a number here, use the 16 bit type
|
|
|
|
* definitions supplied in the MCU header file! (e.g. GPIO_PIN_X)
|
|
|
|
* @param chipSelectGpioPort GPIO port (e.g. GPIOA)
|
|
|
|
* @param maxRecvSize Maximum expected receive size. Chose as small as possible.
|
|
|
|
*/
|
|
|
|
SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode,
|
|
|
|
spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode,
|
2021-06-04 17:13:14 +02:00
|
|
|
uint16_t chipSelectGpioPin, GPIO_TypeDef* chipSelectGpioPort, size_t maxRecvSize);
|
|
|
|
|
|
|
|
uint16_t getChipSelectGpioPin() const;
|
|
|
|
GPIO_TypeDef* getChipSelectGpioPort();
|
|
|
|
address_t getDeviceAddress() const;
|
|
|
|
spi::SpiBus getSpiIdx() const;
|
|
|
|
spi::SpiModes getSpiMode() const;
|
2021-06-10 21:31:21 +02:00
|
|
|
spi::TransferModes getTransferMode() const;
|
2021-06-04 17:13:14 +02:00
|
|
|
uint32_t getSpiSpeed() const;
|
|
|
|
size_t getMaxRecvSize() const;
|
2021-06-10 12:05:49 +02:00
|
|
|
SPI_HandleTypeDef& getSpiHandle();
|
2021-06-04 17:13:14 +02:00
|
|
|
|
2021-06-04 16:01:38 +02:00
|
|
|
private:
|
2021-06-04 16:34:38 +02:00
|
|
|
address_t deviceAddress;
|
2021-06-10 12:05:49 +02:00
|
|
|
SPI_HandleTypeDef spiHandle = {};
|
2021-06-04 16:34:38 +02:00
|
|
|
spi::SpiBus spiIdx;
|
|
|
|
uint32_t spiSpeed;
|
|
|
|
spi::SpiModes spiMode;
|
2021-06-10 21:31:21 +02:00
|
|
|
spi::TransferModes transferMode;
|
2021-06-11 10:37:48 +02:00
|
|
|
volatile spi::TransferStates transferState = spi::TransferStates::IDLE;
|
2021-06-04 16:34:38 +02:00
|
|
|
uint16_t chipSelectGpioPin;
|
|
|
|
GPIO_TypeDef* chipSelectGpioPort;
|
2021-06-10 21:31:21 +02:00
|
|
|
// The MSP configuration is cached here. Be careful when using this, it is automatically
|
|
|
|
// deleted by the SPI communication interface if it is not required anymore!
|
|
|
|
spi::MspCfgBase* mspCfg = nullptr;
|
2021-06-04 17:13:14 +02:00
|
|
|
const size_t maxRecvSize;
|
2021-06-10 21:31:21 +02:00
|
|
|
|
|
|
|
// Only the SpiComIF is allowed to use this to prevent dangling pointers issues
|
|
|
|
spi::MspCfgBase* getMspCfg();
|
|
|
|
void deleteMspCfg();
|
2021-06-11 10:37:48 +02:00
|
|
|
|
|
|
|
void setTransferState(spi::TransferStates transferState);
|
|
|
|
spi::TransferStates getTransferState() const;
|
2021-06-04 16:01:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_ */
|