Rename SPI classes

This commit is contained in:
Henrik Stickann
2023-02-02 22:23:44 +01:00
parent 59585b2ae5
commit fdf5b4890d
10 changed files with 630 additions and 615 deletions

View File

@@ -1,16 +1,10 @@
/**
* @file
* @brief Implementations for SpiInterface and SpiDevice using STM32 HAL.
* @brief SPI bus implementation using STM32 HAL.
*/
#ifndef STA_CORE_STM32_SPI_HPP
#define STA_CORE_STM32_SPI_HPP
/**
* @defgroup stm32SPI SPI
* @ingroup stm32
* @brief STM32 SPI module.
*/
// Only enable module on STM32 platform w/ HAL SPI module enabled
#include <sta/config.hpp>
@@ -24,102 +18,120 @@
# endif // HAL_SPI_MODULE_ENABLED
#endif // STA_PLATFORM_STM32
#if defined(STA_STM32_SPI_ENABLED) || defined(DOXYGEN)
#include <sta/spi/device.hpp>
#include <sta/spi/interface.hpp>
#include <sta/spi/spi.hpp>
#include <sta/stm32/clocks.hpp>
#include <sta/stm32/gpio_pin.hpp>
/**
* @defgroup sta_core_stm32_spi SPI
* @ingroup sta_core_stm32
* @brief STM32 %SPI module.
*/
namespace sta
{
/**
* @ingroup stm32SPI
* @{
*/
/**
* @addtogroup sta_core_stm32_spi
* @{
*/
/**
* @brief Get peripheral clock frequency.
*
* @return Clock frequency
*/
using STM32SpiPCLKFreqFn = uint32_t (*)();
/**
* @brief STM32 HAL implementation of the `SPI` interface class.
*/
class STM32SPI : public SPI
{
public:
struct Info
{
SPI_HandleTypeDef * handle; /**< STM32 HAL handle */
uint32_t pclkFreq; /**< Peripheral clock frequency used by interface */
};
/**
* @brief Info related to STM SPI interface.
*/
struct STM32SpiInterfaceInfo
{
SPI_HandleTypeDef * handle; /**< Interface handle */
STM32SpiPCLKFreqFn getPCLKFreq; /**< Getter for peripheral clock used by interface */
};
public:
/**
* @param handle STM32 HAL handle
* @param pclkFreq Peripheral clock frequency used by %SPI interface
* @param mutex Mutex object for managing access. Pass nullptr for no access control
*/
STM32SPI(SPI_HandleTypeDef * handle, uint32_t pclkFreq, Mutex * mutex = nullptr);
/**
* @param info Interface info
* @param mutex Mutex object for managing access. Pass nullptr for no access control
*/
STM32SPI(const Info & info, Mutex * mutex = nullptr);
void transfer(uint8_t value) override;
void transfer16(uint16_t value) override;
void transfer(const uint8_t * buffer, size_t size) override;
void transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size) override;
void receive(uint8_t * buffer, size_t size) override;
void fill(uint8_t value, size_t count) override;
private:
SPI_HandleTypeDef * handle_; /**< STM32 HAL handle */
};
/**
* @brief Implementation of SpiInterface interface using STM32 HAL.
*/
class STM32SpiInterface : public SpiInterface
{
public:
/**
* @param info SPI interface info
* @param mutex Mutex object for managing access. Pass nullptr for no access control
*/
STM32SpiInterface(const STM32SpiInterfaceInfo & info, Mutex * mutex = nullptr);
/**
* @brief STM32 HAL implementation of the `SPIDevice` class.
*/
class STM32SPIDevice : public SPIDevice
{
public:
/**
* @param intf %SPI interface
* @param csPin Device CS pin
*/
STM32SPIDevice(STM32SPI * intf, STM32GpioPin csPin);
void transfer(uint8_t value) override;
void transfer16(uint16_t value) override;
void transfer(const uint8_t * buffer, size_t size) override;
void transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size) override;
void receive(uint8_t * buffer, size_t size) override;
void fill(uint8_t value, size_t count) override;
const SpiSettings & settings() const override;
private:
STM32SpiInterfaceInfo info_; /**< SPI interface info */
};
private:
STM32GpioPin csPin_; /**< Device CS pin */
};
/**
* @brief Implementation of SpiDevice interface using STM32 HAL.
*/
class STM32SpiDevice : public SpiDevice
{
public:
/**
* @param intf SPI interface
* @param csPin Device CS pin
*/
STM32SpiDevice(STM32SpiInterface * intf, STM32GpioPin csPin);
private:
STM32GpioPin csPin_; /**< Device CS pin */
};
/** @} */
/** @} */
} // namespace sta
/**
* @brief Get SPI interface info struct for STM32 HAL handle.
* @brief Get bus info for STM32 %SPI interface via HAL handle.
*
* Requires STA_STM32_<handle>_PCLK_IDX to be defined for the MCU.
* MCU mappings are found in `core` -> sta/mcu/.hpp files.
* MCU mappings are found in the sta/stm32/mcu/.hpp files.
*
* Check the MCUs Reference Manual RCC register documentation to see which
* peripheral clock is used.
*
* @param handle SPI interface handle
* @param handle STM32 HAL %SPI handle
*
* @ingroup halSPI
* @ingroup sta_core_stm32_spi
*/
#define STA_STM32_SPI_INFO(handle) sta::STM32SpiInterfaceInfo{&handle, STA_STM32_GET_HANDLE_PCLK_FREQ_FN(handle)}
#define STA_STM32_SPI_INFO(handle) sta::STM32SPI::Info{&handle, STA_STM32_GET_HANDLE_PCLK_FREQ_FN(handle)()}
/**
* @brief Get bus info for STM32 %SPI interface via index.
*
* Requires STA_STM32_SPI_<n>_PCLK_IDX to be defined for the MCU.
* MCU mappings are found in the sta/stm32/mcu/.hpp files.
*
* Check the MCUs Reference Manual RCC register documentation to see which
* peripheral clock is used.
*
* @param n STM32 %SPI interface index
*
* @ingroup sta_core_stm32_spi
*/
#define STA_STM32_SPI_INFO_N(n) sta::STM32SPI::Info{&handle, STA_STM32_GET_SPI_PCLK_FREQ_FN(n)()}
#endif // STA_STM32_SPI_ENABLED