mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-08-05 18:21:54 +00:00
Implement changes to SPI interfaces
This commit is contained in:
@@ -23,6 +23,23 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Get peripheral clock frequency.
|
||||
*
|
||||
* @return Clock frequency
|
||||
*/
|
||||
using HalSpiPCLKFreqFn = uint32_t (*)();
|
||||
|
||||
/**
|
||||
* @brief Info related to HAL SPI interface.
|
||||
*/
|
||||
struct HalSpiInterfaceInfo
|
||||
{
|
||||
SPI_HandleTypeDef * handle; /**< Interface handle */
|
||||
HalSpiPCLKFreqFn getPCLKFreq; /**< Getter for peripheral clock used by interface */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Implementation of `SpiInterface` interface using HAL.
|
||||
*/
|
||||
@@ -30,24 +47,23 @@ namespace sta
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @param handle SPI handle
|
||||
* @param info SPI interface info
|
||||
* @param mutex Mutex object for managing access. Pass nullptr for no access control
|
||||
*/
|
||||
HalSpiInterface(SPI_HandleTypeDef * handle, Mutex * mutex = nullptr);
|
||||
HalSpiInterface(const HalSpiInterfaceInfo & 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 transfer16(uint16_t value) override;
|
||||
|
||||
void fill(uint8_t value, size_t count) override;
|
||||
void fill32(uint32_t value, size_t count) 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:
|
||||
SPI_HandleTypeDef * handle_; /**< SPI handle */
|
||||
HalSpiInterfaceInfo info_; /**< SPI interface info */
|
||||
};
|
||||
|
||||
|
||||
@@ -72,6 +88,38 @@ namespace sta
|
||||
} // namespace sta
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get function returning PCLK frequency.
|
||||
*
|
||||
* @param n Index of peripheral clock
|
||||
*/
|
||||
#define STA_HAL_GET_PCLK_FREQ_FN(n) HAL_RCC_GetPCLK ## n ## Freq
|
||||
|
||||
/**
|
||||
* @brief Get SPI interface info struct.
|
||||
*
|
||||
* Check the MCUs Reference Manual RCC register documentation to see which
|
||||
* peripheral clock is used.
|
||||
*
|
||||
* @param n Index of SPI interface (e.g. 2 for SPI2)
|
||||
* @param pclk Index of peripheral clock used by SPI interface
|
||||
*/
|
||||
#define STA_HAL_SPI_INFO_MANUAL(n, pclk) sta::HalSpiInterfaceInfo{&hspi ## n, STA_HAL_GET_PCLK_FREQ_FN(pclk)}
|
||||
|
||||
/**
|
||||
* @brief Get SPI interface info struct.
|
||||
*
|
||||
* Requires STA_HAL_SPI_n_PCLK_IDX set to idx of PCLK used by the interface.
|
||||
*
|
||||
* Check the MCUs Reference Manual RCC register documentation to see which
|
||||
* peripheral clock is used.
|
||||
*
|
||||
* @param n Index of SPI interface (e.g. 2 for SPI2)
|
||||
*/
|
||||
#define STA_HAL_SPI_INFO(n) STA_HAL_SPI_INFO_MANUAL(n, STA_HAL_SPI_ ## n ## _PCLK_IDX)
|
||||
|
||||
|
||||
#endif // STA_HAL_SPI_ENABLE
|
||||
|
||||
#endif // STA_HAL_SPI_HPP
|
||||
|
Reference in New Issue
Block a user