2021-07-15 19:23:12 +02:00
|
|
|
#include "fsfw/hal/stm32h7/spi/SpiCookie.h"
|
2021-07-13 19:19:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode,
|
|
|
|
spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode,
|
|
|
|
uint16_t chipSelectGpioPin, GPIO_TypeDef* chipSelectGpioPort, size_t maxRecvSize):
|
|
|
|
deviceAddress(deviceAddress), spiIdx(spiIdx), spiSpeed(spiSpeed), spiMode(spiMode),
|
|
|
|
transferMode(transferMode), chipSelectGpioPin(chipSelectGpioPin),
|
|
|
|
chipSelectGpioPort(chipSelectGpioPort), mspCfg(mspCfg), maxRecvSize(maxRecvSize) {
|
|
|
|
spiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
|
|
|
|
spiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
|
|
spiHandle.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
|
|
spiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
|
|
spiHandle.Init.CRCPolynomial = 7;
|
|
|
|
spiHandle.Init.CRCLength = SPI_CRC_LENGTH_8BIT;
|
|
|
|
spiHandle.Init.NSS = SPI_NSS_SOFT;
|
|
|
|
spiHandle.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
|
|
|
|
spiHandle.Init.Direction = SPI_DIRECTION_2LINES;
|
|
|
|
// Recommended setting to avoid glitches
|
|
|
|
spiHandle.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_ENABLE;
|
|
|
|
spiHandle.Init.Mode = SPI_MODE_MASTER;
|
|
|
|
spi::assignSpiMode(spiMode, spiHandle);
|
|
|
|
spiHandle.Init.BaudRatePrescaler = spi::getPrescaler(HAL_RCC_GetHCLKFreq(), spiSpeed);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t SpiCookie::getChipSelectGpioPin() const {
|
|
|
|
return chipSelectGpioPin;
|
|
|
|
}
|
|
|
|
|
|
|
|
GPIO_TypeDef* SpiCookie::getChipSelectGpioPort() {
|
|
|
|
return chipSelectGpioPort;
|
|
|
|
}
|
|
|
|
|
|
|
|
address_t SpiCookie::getDeviceAddress() const {
|
|
|
|
return deviceAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
spi::SpiBus SpiCookie::getSpiIdx() const {
|
|
|
|
return spiIdx;
|
|
|
|
}
|
|
|
|
|
|
|
|
spi::SpiModes SpiCookie::getSpiMode() const {
|
|
|
|
return spiMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SpiCookie::getSpiSpeed() const {
|
|
|
|
return spiSpeed;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t SpiCookie::getMaxRecvSize() const {
|
|
|
|
return maxRecvSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
SPI_HandleTypeDef& SpiCookie::getSpiHandle() {
|
|
|
|
return spiHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
spi::MspCfgBase* SpiCookie::getMspCfg() {
|
|
|
|
return mspCfg;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpiCookie::deleteMspCfg() {
|
|
|
|
if(mspCfg != nullptr) {
|
|
|
|
delete mspCfg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
spi::TransferModes SpiCookie::getTransferMode() const {
|
|
|
|
return transferMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpiCookie::setTransferState(spi::TransferStates transferState) {
|
|
|
|
this->transferState = transferState;
|
|
|
|
}
|
|
|
|
|
|
|
|
spi::TransferStates SpiCookie::getTransferState() const {
|
|
|
|
return this->transferState;
|
|
|
|
}
|