mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-08-05 18:21:54 +00:00
Add HAL SPI implementation
This commit is contained in:
70
include/sta/hal/spi.hpp
Normal file
70
include/sta/hal/spi.hpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* @brief Implementations for SpiInterface and SpiDevice using HAL.
|
||||
*
|
||||
* Define STA_HAL_SPI_ENABLE in <sta/config.hpp> to enable.
|
||||
* Requires STA_HAL_GPIO_ENABLE.
|
||||
*/
|
||||
#ifndef STA_HAL_SPI_HPP
|
||||
#define STA_HAL_SPI_HPP
|
||||
|
||||
#include <sta/config.hpp>
|
||||
#ifdef STA_HAL_SPI_ENABLE
|
||||
|
||||
#include <sta/spi_device.hpp>
|
||||
#include <sta/hal/gpio_pin.hpp>
|
||||
|
||||
#include <main.h>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Implementation of SpiInterface using HAL.
|
||||
*/
|
||||
class HalSpiInterface : public SpiInterface
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @param handle SPI handle
|
||||
* @param mutex Mutex object for managing access. Pass nullptr for no access control
|
||||
*/
|
||||
HalSpiInterface(SPI_HandleTypeDef * handle, Mutex * mutex = nullptr);
|
||||
|
||||
void transfer(uint8_t value) override;
|
||||
void transfer(const uint8_t * buffer, 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;
|
||||
|
||||
private:
|
||||
SPI_HandleTypeDef * handle_; /**< SPI handle */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Implementation of SpiDevice using HAL.
|
||||
*/
|
||||
class HalSpiDevice : public SpiDevice
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @param intf SPI interface
|
||||
* @param csPin Device CS pin
|
||||
*/
|
||||
HalSpiDevice(SpiInterface * intf, HalGpioPin csPin);
|
||||
|
||||
void select() override;
|
||||
void deselect() override;
|
||||
|
||||
private:
|
||||
HalGpioPin csPin_; /**< Device CS pin */
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_HAL_SPI_ENABLE
|
||||
|
||||
#endif // STA_HAL_SPI_HPP
|
Reference in New Issue
Block a user