Move STM32 implementations into sta-stm32-core repository

This commit is contained in:
Henrik Stickann 2022-05-09 21:14:05 +02:00
parent 7c0c05d296
commit 92e3dd474b
14 changed files with 0 additions and 902 deletions

View File

@ -1,81 +0,0 @@
/**
* @file
* @brief Helper macros for HAL clock queries.
*/
#ifndef STA_HAL_CLOCKS_HPP
#define STA_HAL_CLOCKS_HPP
/**
* @defgroup hal HAL
* @brief HAL base implementations.
*/
/**
* @defgroup halBuildConfig Build config
* @ingroup hal
* @brief Build configuration options.
*/
/**
* @defgroup halClocks Clocks
* @ingroup hal
* @brief HAL clock queries.
* @{
*/
#include <sta/config.hpp>
#include <sta/hal.hpp>
/**
* @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
// Internal helper for macro expansion
#define _STA_HAL_GET_PCLK_FREQ_FN(n) STA_HAL_GET_PCLK_FREQ_FN(n)
// Get instance to PCLK index map macro
#define _STA_PCLK_IDX_MAP(type, idx) STA_ ## type ## _ ## idx ## _PCLK_IDX
// Get HAL handle to PCLK index map macro
#define _STA_HAL_PCLK_IDX_MAP(handle) STA_HAL_ ## handle ## _PCLK_IDX
/**
* @brief Get function returning frequency of PCLK used by TIM.
*
* @param n TIM index
*/
#define STA_HAL_GET_TIM_PCLK_FREQ_FN(n) _STA_HAL_GET_PCLK_FREQ_FN(_STA_PCLK_IDX_MAP(TIM, n))
/**
* @brief Get function returning frequency of PCLK used by SPI interface.
*
* @param n SPI interface index
*/
#define STA_HAL_GET_SPI_PCLK_FREQ_FN(n) _STA_HAL_GET_PCLK_FREQ_FN(_STA_PCLK_IDX_MAP(SPI, n))
/**
* @brief Get function returning frequency of PCLK used by I2C interface.
*
* @param n I2C interface index
*/
#define STA_HAL_GET_I2C_PCLK_FREQ_FN(n) _STA_HAL_GET_PCLK_FREQ_FN(_STA_PCLK_IDX_MAP(I2C, n))
/**
* @brief Get function returning frequency of PCLK used by USART interface.
*
* @param n USART interface index
*/
#define STA_HAL_GET_USART_PCLK_FREQ_FN(n) _STA_HAL_GET_PCLK_FREQ_FN(_STA_PCLK_IDX_MAP(USART, n))
/**
* @brief Get function returning frequency of PCLK used by HAL instance.
*
* @param handle Instance handle
*/
#define STA_HAL_GET_HANDLE_PCLK_FREQ_FN(handle) _STA_HAL_GET_PCLK_FREQ_FN(_STA_HAL_PCLK_IDX_MAP(handle))
/** @} */
#endif // STA_HAL_CLOCKS_HPP

View File

@ -1,69 +0,0 @@
/**
* @file
* @brief Delay functions.
*/
#ifndef STA_HAL_DELAY_HPP
#define STA_HAL_DELAY_HPP
/**
* @defgroup halDelay Delay
* @ingroup hal
* @brief HAL Delay module
*/
#ifdef DOXYGEN
/**
* @def STA_HAL_DELAY_ENABLE
* @brief Enable module.
*
* @ingroup halBuildConfig
*/
# define STA_HAL_DELAY_ENABLE
/**
* @def STA_HAL_DELAY_US_TIM
* @brief 1 MHz TIM instance used by sta::delayUs.
*
* NOTE: TIM time base must be started before use of sta::delayUs by calling sta::initHAL.
* When using startup system task this is handled automatically.
*
* @ingroup halBuildConfig
*/
# define STA_HAL_DELAY_US_TIM
#endif // DOXYGEN
#include <sta/config.hpp>
#ifdef STA_HAL_DELAY_ENABLE
#include <cstdint>
namespace sta
{
/**
* @brief Millisecond delay.
*
* @param ms Milliseconds
*
* @ingroup halDelay
*/
void delayMs(uint32_t ms);
#ifdef STA_HAL_DELAY_US_TIM
/**
* @brief Microsecond delay.
*
* @param us Microseconds
*
* @ingroup halDelay
*/
void delayUs(uint32_t us);
#endif // STA_HAL_DELAY_US_TIM
} // namespace sta
#endif // STA_HAL_DELAY_TIM
#endif // STA_HAL_DELAY_HPP
/** @} */

View File

@ -1,68 +0,0 @@
/**
* @file
* @brief Wrapper for HAL GPIO pins.
*/
#ifndef STA_HAL_GPIO_PIN_HPP
#define STA_HAL_GPIO_PIN_HPP
/**
* @defgroup halGPIO GPIO
* @ingroup hal
* @brief HAL GPIO module
*/
#ifdef DOXYGEN
/**
* @def STA_HAL_GPIO_ENABLE
* @brief Enable module.
*
* @ingroup halBuildConfig
*/
# define STA_HAL_GPIO_ENABLE
#endif // DOXYGEN
#include <sta/config.hpp>
#ifdef STA_HAL_GPIO_ENABLE
#include <sta/intf/gpio_pin.hpp>
#include <sta/hal.hpp>
namespace sta
{
/**
* @brief Container for HAL GPIO Pin objects.
*
* @ingroup halGPIO
*/
class HalGpioPin : public GpioPin
{
public:
HalGpioPin(GPIO_TypeDef * port, uint16_t pin);
void setState(GpioPinState state) override;
GPIO_TypeDef * getPort() const;
uint16_t getPin() const;
uint8_t getIndex() const;
private:
GPIO_TypeDef * port_; /**< GPIO port */
uint16_t pin_; /**< GPIO pin */
};
}
/**
* @brief Create HalGpioPin object from pin label.
*
* @param label Pin label
*
* @ingroup halGPIO
*/
#define STA_HAL_GPIO_PIN(label) sta::HalGpioPin{label##_GPIO_Port, label##_Pin}
#endif // STA_HAL_GPIO_ENABLE
#endif // STA_HAL_GPIO_PIN_HPP

View File

@ -1,20 +0,0 @@
/**
* @file
* @brief Global HAL initialization.
*/
#ifndef STA_HAL_INIT_HPP
#define STA_HAL_INIT_HPP
namespace sta
{
/**
* @brief Initialize global HAL objects.
*
* @ingroup hal
*/
void initHAL();
} // namespace sta
#endif // STA_HAL_INIT_HPP

View File

@ -1,134 +0,0 @@
/**
* @file
* @brief Implementations for `SpiInterface` and `SpiDevice` using HAL.
*/
#ifndef STA_HAL_SPI_HPP
#define STA_HAL_SPI_HPP
/**
* @defgroup halSPI SPI
* @ingroup hal
* @brief HAL SPI module.
*/
#ifdef DOXYGEN
/**
* @def STA_HAL_SPI_ENABLE
* @brief Enable module.
*
* Requires **HAL_GPIO** module.
*
* @ingroup halBuildConfig
*/
# define STA_HAL_SPI_ENABLE
#endif // DOXYGEN
#include <sta/config.hpp>
#ifdef STA_HAL_SPI_ENABLE
#ifndef STA_HAL_GPIO_ENABLE
#error "HAL GPIO module required"
#endif // !STA_HAL_GPIO_ENABLE
#include <sta/hal.hpp>
#include <sta/hal/clocks.hpp>
#include <sta/hal/gpio_pin.hpp>
#include <sta/intf/spi_device.hpp>
namespace sta
{
/**
* @ingroup halSPI
* @{
*/
/**
* @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.
*/
class HalSpiInterface : public SpiInterface
{
public:
/**
* @param info SPI interface info
* @param mutex Mutex object for managing access. Pass nullptr for no access control
*/
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 receive(uint8_t * buffer, size_t size) override;
void fill(uint8_t value, size_t count) override;
const SpiSettings & settings() const override;
private:
HalSpiInterfaceInfo info_; /**< SPI interface info */
};
/**
* @brief Implementation of `SpiDevice` interface 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
/**
* @brief Get SPI interface info struct for HAL handle.
*
* Requires STA_HAL_<handle>_PCLK_IDX to be defined for the MCU.
* MCU mappings are found in `core` -> sta/mcu/.hpp files.
*
* Check the MCUs Reference Manual RCC register documentation to see which
* peripheral clock is used.
*
* @param handle SPI interface handle
*
* @ingroup halSPI
*/
#define STA_HAL_SPI_INFO(handle) sta::HalSpiInterfaceInfo{&handle, STA_HAL_GET_HANDLE_PCLK_FREQ_FN(handle)}
#endif // STA_HAL_SPI_ENABLE
#endif // STA_HAL_SPI_HPP

View File

@ -1,65 +0,0 @@
/**
* @file
* @brief Implementation of UART using HAL.
*/
#ifndef STA_HAL_UART_HPP
#define STA_HAL_UART_HPP
/**
* @defgroup halUART UART
* @ingroup hal
* @brief HAL UART module.
*/
#ifdef DOXYGEN
/**
* @def STA_HAL_UART_ENABLE
* @brief Enable module.
*
* @ingroup halBuildConfig
*/
# define STA_HAL_UART_ENABLE
/**
* @def STA_HAL_UART_DEBUG_SERIAL
* @brief Create global sta::DebugSerial object using this HAL UART instance.
*
* @ingroup halBuildConfig
*/
# define STA_HAL_UART_DEBUG_SERIAL
#endif // DOXYGEN
#include <sta/config.hpp>
#ifdef STA_HAL_UART_ENABLE
#include <sta/hal.hpp>
#include <sta/intf/uart.hpp>
namespace sta
{
/**
* @brief Implementation of UART interface using HAL.
*
* @ingroup halUART
*/
class HalUART : public UART
{
public:
/**
* @param handle UART handle
*/
HalUART(UART_HandleTypeDef * handle);
void write(const uint8_t * buffer, size_t size) override;
private:
UART_HandleTypeDef * handle_; /**< UART handle */
};
} // namespace sta
#endif // STA_HAL_UART_ENABLE
#endif // STA_HAL_UART_HPP

View File

@ -1,77 +0,0 @@
/**
* @brief Configuration for STM32F411xE family.
*/
#ifndef STA_MCU_STM32F411xE_HPP
#define STA_MCU_STM32F411xE_HPP
#ifndef STM32F411xE
# error "MCU config incompatible"
#endif // !STM32F411xE
#include <sta/mcu/stm32base.hpp>
// Peripheral clock mappings
//
// TIM to PCLK
#define STA_TIM_1_PCLK_IDX 2
#define STA_TIM_2_PCLK_IDX 1
#define STA_TIM_3_PCLK_IDX 1
#define STA_TIM_4_PCLK_IDX 1
#define STA_TIM_5_PCLK_IDX 1
#define STA_TIM_9_PCLK_IDX 2
#define STA_TIM_10_PCLK_IDX 2
#define STA_TIM_11_PCLK_IDX 2
// SPI to PCLK
#define STA_SPI_1_PCLK_IDX 2
#define STA_SPI_2_PCLK_IDX 1
#define STA_SPI_3_PCLK_IDX 1
#define STA_SPI_4_PCLK_IDX 2
#define STA_SPI_5_PCLK_IDX 2
// I2C to PCLK
#define STA_I2C_1_PCLK_IDX 1
#define STA_I2C_2_PCLK_IDX 1
#define STA_I2C_3_PCLK_IDX 1
// USART to PCLK
#define STA_USART_1_PCLK_IDX 2
#define STA_USART_2_PCLK_IDX 1
#define STA_USART_6_PCLK_IDX 2
// HAL handle mappings
//
#define STA_HAL_htim1_PCLK_IDX STA_TIM_1_PCLK_IDX
#define STA_HAL_htim2_PCLK_IDX STA_TIM_2_PCLK_IDX
#define STA_HAL_htim3_PCLK_IDX STA_TIM_3_PCLK_IDX
#define STA_HAL_htim4_PCLK_IDX STA_TIM_4_PCLK_IDX
#define STA_HAL_htim5_PCLK_IDX STA_TIM_5_PCLK_IDX
#define STA_HAL_htim9_PCLK_IDX STA_TIM_9_PCLK_IDX
#define STA_HAL_htim10_PCLK_IDX STA_TIM_10_PCLK_IDX
#define STA_HAL_htim11_PCLK_IDX STA_TIM_11_PCLK_IDX
// SPI to PCLK
#define STA_HAL_hspi1_PCLK_IDX STA_SPI_1_PCLK_IDX
#define STA_HAL_hspi2_PCLK_IDX STA_SPI_2_PCLK_IDX
#define STA_HAL_hspi3_PCLK_IDX STA_SPI_3_PCLK_IDX
#define STA_HAL_hspi4_PCLK_IDX STA_SPI_4_PCLK_IDX
#define STA_HAL_hspi5_PCLK_IDX STA_SPI_5_PCLK_IDX
// I2C to PCLK
#define STA_HAL_hi2c1_PCLK_IDX STA_I2C_1_PCLK_IDX
#define STA_HAL_hi2c2_PCLK_IDX STA_I2C_2_PCLK_IDX
#define STA_HAL_h12c3_PCLK_IDX STA_I2C_3_PCLK_IDX
// USART to PCLK
#define STA_HAL_husart1_PCLK_IDX STA_USART_1_PCLK_IDX
#define STA_HAL_husart2_PCLK_IDX STA_USART_2_PCLK_IDX
#define STA_HAL_husart6_PCLK_IDX STA_USART_6_PCLK_IDX
#endif // STA_MCU_STM32F411xE_HPP

View File

@ -1,16 +0,0 @@
/**
* @brief Configuration for STM32F413xx family.
*/
#ifndef STA_MCU_STM32F413xx_HPP
#define STA_MCU_STM32F413xx_HPP
#ifndef STM32F413xx
# error "MCU config incompatible"
#endif // !STM32F413xx
#include <sta/mcu/stm32base.hpp>
#endif // STA_MCU_STM32F413xx_HPP

View File

@ -1,12 +0,0 @@
/**
* @brief Common configuration for STM32 MCUs
*/
#ifndef STA_MCU_STM32_BASE_HPP
#define STA_MCU_STM32_BASE_HPP
// TODO: Are all STM32 MCUs little endian?
#define STA_MCU_LITTLE_ENDIAN
#endif // STA_MCU_STM32_BASE_HPP

View File

@ -1,65 +0,0 @@
#include <sta/hal/delay.hpp>
#ifdef STA_HAL_DELAY_ENABLE
#include <sta/assert.hpp>
#include <sta/hal.hpp>
#include <sta/lang.hpp>
#include <sta/hal/clocks.hpp>
namespace sta
{
void delayMs(uint32_t ms)
{
HAL_Delay(ms);
}
} // namespace sta
#ifdef STA_HAL_DELAY_US_TIM
#include <tim.h>
namespace sta
{
void delayUs(uint32_t us)
{
__HAL_TIM_SET_COUNTER(&STA_HAL_DELAY_US_TIM, 0);
while (__HAL_TIM_GET_COUNTER(&STA_HAL_DELAY_US_TIM) < us);
}
bool isValidDelayUsTIM()
{
// Get PCLK multiplier for TIM clock
uint32_t pclkMul = 1;
switch (STA_HAL_DELAY_US_TIM.Init.ClockDivision)
{
case TIM_CLOCKDIVISION_DIV1:
pclkMul = 1;
break;
case TIM_CLOCKDIVISION_DIV2:
pclkMul = 2;
break;
case TIM_CLOCKDIVISION_DIV4:
pclkMul = 4;
break;
default:
STA_ASSERT(false);
STA_UNREACHABLE();
}
// Calculate TIM clock frequency
uint32_t clkFreq = pclkMul * STA_HAL_GET_HANDLE_PCLK_FREQ_FN(STA_HAL_DELAY_US_TIM)();
// Calculate update frequency based on prescaler value
uint32_t updateFreq = clkFreq / STA_HAL_DELAY_US_TIM.Init.Prescaler;
// TIM must have at least microsecond precision (>= 1 MHz frequency)
return (updateFreq == 1000000);
}
} // namespace sta
#endif // STA_HAL_DELAY_US_TIM
#endif // STA_HAL_DELAY_ENABLE

View File

@ -1,37 +0,0 @@
#include <sta/hal/gpio_pin.hpp>
#ifdef STA_HAL_GPIO_ENABLE
#include <sta/assert.hpp>
namespace sta
{
HalGpioPin::HalGpioPin(GPIO_TypeDef * port, uint16_t pin)
: port_{port}, pin_{pin}
{
STA_ASSERT(port != nullptr);
}
void HalGpioPin::setState(GpioPinState state)
{
HAL_GPIO_WritePin(port_, pin_, (state == GpioPinState::LOW) ? GPIO_PIN_RESET : GPIO_PIN_SET);
}
GPIO_TypeDef * HalGpioPin::getPort() const
{
return port_;
}
uint16_t HalGpioPin::getPin() const
{
return pin_;
}
uint8_t HalGpioPin::getIndex() const
{
return GPIO_GET_INDEX(port_);
}
} // namespace sta
#endif // STA_HAL_GPIO_ENABLE

View File

@ -1,22 +0,0 @@
#include <sta/hal/init.hpp>
#include <sta/assert.hpp>
#ifdef STA_HAL_DELAY_US_TIM
#include <tim.h>
#endif // STA_HAL_DELAY_US_TIM
namespace sta
{
void initHAL()
{
#ifdef STA_HAL_DELAY_US_TIM
// Validate TIM used for delayUs
extern bool isValidDelayUsTIM();
STA_ASSERT(isValidDelayUsTIM());
// Start timer base
HAL_TIM_Base_Start(&STA_HAL_DELAY_US_TIM);
#endif // STA_HAL_DELAY_US_TIM
}
}

View File

@ -1,193 +0,0 @@
#include <sta/hal/spi.hpp>
#ifdef STA_HAL_SPI_ENABLE
#include <sta/assert.hpp>
#include <sta/endian.hpp>
#include <sta/lang.hpp>
#ifdef STA_MCU_LITTLE_ENDIAN
# define STA_HAL_SPI_REVERSE_BIT_ORDER SpiBitOrder::MSB
#elif STA_MCU_BIG_ENDIAN
# define STA_HAL_SPI_REVERSE_BIT_ORDER SpiBitOrder::LSB
#else // !STA_MCU_LITTLE_ENDIAN && !STA_MCU_BIG_ENDIAN
# ifdef STA_HAL_SPI_REVERSE_BIT_ORDER
# warning "Internal STA_HAL_SPI_REVERSE_BIT_ORDER macro manually defined! Better now what you are doing!!!"
# else // !STA_HAL_SPI_REVERSE_BIT_ORDER
# error "Unknown endian-ness. Define STA_MCU_LITTLE_ENDIAN or STA_MCU_BIG_ENDIAN in <sta/config.hpp>"
# endif // !STA_HAL_SPI_REVERSE_BIT_ORDER
#endif // !STA_MCU_LITTLE_ENDIAN && !STA_MCU_BIG_ENDIAN
namespace sta
{
static SpiSettings getHalSpiSettings(SPI_HandleTypeDef * handle, uint32_t pclkFreq)
{
SpiSettings settings;
settings.mode = getSpiMode(
(handle->Init.CLKPolarity == SPI_POLARITY_LOW) ? SpiClkPolarity::LOW : SpiClkPolarity::HIGH,
(handle->Init.CLKPhase == SPI_PHASE_1EDGE) ? SpiClkPhase::EDGE_1 : SpiClkPhase::EDGE_2
);
settings.dataSize = (handle->Init.DataSize == SPI_DATASIZE_8BIT) ? SpiDataSize::SIZE_8 : SpiDataSize::SIZE_16;
settings.bitOrder = (handle->Init.FirstBit == SPI_FIRSTBIT_MSB) ? SpiBitOrder::MSB : SpiBitOrder::LSB;
uint32_t prescaler = 1;
switch (handle->Init.BaudRatePrescaler)
{
case SPI_BAUDRATEPRESCALER_2:
prescaler = 2;
break;
case SPI_BAUDRATEPRESCALER_4:
prescaler = 4;
break;
case SPI_BAUDRATEPRESCALER_8:
prescaler = 8;
break;
case SPI_BAUDRATEPRESCALER_16:
prescaler = 16;
break;
case SPI_BAUDRATEPRESCALER_32:
prescaler = 32;
break;
case SPI_BAUDRATEPRESCALER_64:
prescaler = 64;
break;
case SPI_BAUDRATEPRESCALER_128:
prescaler = 128;
break;
case SPI_BAUDRATEPRESCALER_256:
prescaler = 256;
break;
default:
// Unreachable case
STA_ASSERT_MSG(false, "Case for SPI_BAUDRATEPRESCALER not handled");
STA_UNREACHABLE();
}
// SPI clock speed is based of PCLK
settings.clkSpeed = pclkFreq / prescaler;
return settings;
}
HalSpiInterface::HalSpiInterface(const HalSpiInterfaceInfo & info, Mutex * mutex /* = nullptr */)
: SpiInterface(mutex), info_{info}
{
STA_ASSERT(info.handle != nullptr);
STA_ASSERT(info.getPCLKFreq != nullptr);
}
void HalSpiInterface::transfer(uint8_t value)
{
if (settings().dataSize == SpiDataSize::SIZE_8)
{
HAL_SPI_Transmit(info_.handle, &value, 1, HAL_MAX_DELAY);
}
else
{
// Required since tx buffer is cast to uint16_t * internally
uint16_t dummy = value;
HAL_SPI_Transmit(info_.handle, reinterpret_cast<uint8_t *>(&dummy), 1, HAL_MAX_DELAY);
}
}
void HalSpiInterface::transfer16(uint16_t value)
{
static_assert(sizeof(value) == 2, "Unexpected uint16_t size");
uint16_t size = 1;
// Send as two bytes if data size is 8-bit
if (settings().dataSize == SpiDataSize::SIZE_8)
{
size = 2;
if (settings().bitOrder == STA_HAL_SPI_REVERSE_BIT_ORDER)
{
// Reverse byte order from internal representation
value = STA_UINT16_SWAP_BYTE_ORDER(value);
}
}
HAL_SPI_Transmit(info_.handle, reinterpret_cast<uint8_t *>(&value), size, HAL_MAX_DELAY);
}
void HalSpiInterface::transfer(const uint8_t * buffer, size_t size)
{
STA_ASSERT(buffer != nullptr);
STA_ASSERT(size != 0);
HAL_SPI_Transmit(info_.handle, const_cast<uint8_t *>(buffer), size, HAL_MAX_DELAY);
}
void HalSpiInterface::transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size)
{
STA_ASSERT(txBuffer != nullptr);
STA_ASSERT(rxBuffer != nullptr);
STA_ASSERT(size != 0);
HAL_SPI_TransmitReceive(info_.handle, const_cast<uint8_t *>(txBuffer), rxBuffer, size, HAL_MAX_DELAY);
}
void HalSpiInterface::receive(uint8_t * buffer, size_t size)
{
STA_ASSERT(buffer != nullptr);
HAL_SPI_Receive(info_.handle, buffer, size, HAL_MAX_DELAY);
}
void HalSpiInterface::fill(uint8_t value, size_t count)
{
STA_ASSERT(count != 0);
if (settings().dataSize == SpiDataSize::SIZE_8)
{
for (size_t i = 0; i < count; ++i)
{
HAL_SPI_Transmit(info_.handle, &value, 1, HAL_MAX_DELAY);
}
}
else
{
// Required since tx buffer is cast to uint16_t * internally
uint16_t dummy = value;
for (size_t i = 0; i < count; ++i)
{
HAL_SPI_Transmit(info_.handle, reinterpret_cast<uint8_t *>(&dummy), 1, HAL_MAX_DELAY);
}
}
}
const SpiSettings & HalSpiInterface::settings() const
{
// Cache settings
static SpiSettings settings = getHalSpiSettings(info_.handle, info_.getPCLKFreq());
return settings;
}
HalSpiDevice::HalSpiDevice(SpiInterface * intf, HalGpioPin csPin)
: SpiDevice(intf), csPin_{csPin}
{}
void HalSpiDevice::select()
{
csPin_.setState(GpioPinState::LOW);
}
void HalSpiDevice::deselect()
{
csPin_.setState(GpioPinState::HIGH);
}
} // namespace sta
#endif // STA_HAL_SPI_ENABLE

View File

@ -1,43 +0,0 @@
#include <sta/hal/uart.hpp>
#ifdef STA_HAL_UART_ENABLE
#include <sta/assert.hpp>
namespace sta
{
HalUART::HalUART(UART_HandleTypeDef * handle)
: handle_{handle}
{
STA_ASSERT(handle != nullptr);
}
void HalUART::write(const uint8_t * buffer, size_t size)
{
STA_ASSERT(buffer != nullptr);
HAL_UART_Transmit(handle_, const_cast<uint8_t *>(buffer), size, HAL_MAX_DELAY);
}
} // namespace sta
#ifdef STA_HAL_UART_DEBUG_SERIAL
// Get extern declaration for DebugSerial because const namespace level variables have internal linkage by default
#include <sta/debug_serial.hpp>
#include <usart.h>
namespace sta
{
HalUART gHalDebugSerial(&STA_HAL_UART_DEBUG_SERIAL);
// Used by <sta/debug.hpp>
PrintableUART DebugSerial(&gHalDebugSerial);
} // namespace sta
#endif // STA_HAL_UART_DEBUG_SERIAL
#endif // STA_HAL_UART_ENABLE