grouping CS gpio definition

This commit is contained in:
Robin Müller 2021-10-27 17:31:04 +02:00
parent 3448a8c01b
commit d675621b73
2 changed files with 17 additions and 8 deletions

View File

@ -3,10 +3,10 @@
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):
size_t maxRecvSize, GpioPair csGpio):
deviceAddress(deviceAddress), spiIdx(spiIdx), spiSpeed(spiSpeed), spiMode(spiMode),
transferMode(transferMode), chipSelectGpioPin(chipSelectGpioPin),
chipSelectGpioPort(chipSelectGpioPort), mspCfg(mspCfg), maxRecvSize(maxRecvSize) {
transferMode(transferMode), csGpio(csGpio),
mspCfg(mspCfg), maxRecvSize(maxRecvSize) {
spiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
spiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
spiHandle.Init.TIMode = SPI_TIMODE_DISABLE;
@ -24,11 +24,11 @@ SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferM
}
uint16_t SpiCookie::getChipSelectGpioPin() const {
return chipSelectGpioPin;
return csGpio.second;
}
GPIO_TypeDef* SpiCookie::getChipSelectGpioPort() {
return chipSelectGpioPort;
return csGpio.first;
}
address_t SpiCookie::getDeviceAddress() const {

View File

@ -8,6 +8,8 @@
#include "stm32h743xx.h"
#include <utility>
/**
* @brief SPI cookie implementation for the STM32H7 device family
* @details
@ -18,6 +20,12 @@
class SpiCookie: public CookieIF {
friend class SpiComIF;
public:
/**
* Typedef for STM32 GPIO pair where the first entry is the port used (e.g. GPIOA)
* and the second entry is the pin number
*/
using GpioPair = std::pair<GPIO_TypeDef*, uint16_t>;
/**
* Allows construction of a SPI cookie for a connected SPI device
* @param deviceAddress
@ -32,10 +40,11 @@ public:
* 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.
* @param csGpio Optional CS GPIO definition.
*/
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);
size_t maxRecvSize, GpioPair csGpio = GpioPair(nullptr, 0));
uint16_t getChipSelectGpioPin() const;
GPIO_TypeDef* getChipSelectGpioPort();
@ -55,8 +64,8 @@ private:
spi::SpiModes spiMode;
spi::TransferModes transferMode;
volatile spi::TransferStates transferState = spi::TransferStates::IDLE;
uint16_t chipSelectGpioPin;
GPIO_TypeDef* chipSelectGpioPort;
GpioPair csGpio;
// 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;