diff --git a/include/sta/atomic/mutex.hpp b/include/sta/atomic/mutex.hpp index dcab789..a41b89f 100644 --- a/include/sta/atomic/mutex.hpp +++ b/include/sta/atomic/mutex.hpp @@ -1,7 +1,8 @@ /** * @brief Atomic mutex implementation. * - * Define **STA_ATOMIC_ENABLE** to enable module. + * Configuration: + * STA_ATOMIC_ENABLE: Enable module */ #ifndef STA_ATOMIC_MUTEX_HPP #define STA_ATOMIC_MUTEX_HPP diff --git a/include/sta/atomic/signal.hpp b/include/sta/atomic/signal.hpp index 4ca8cfc..b84f030 100644 --- a/include/sta/atomic/signal.hpp +++ b/include/sta/atomic/signal.hpp @@ -1,7 +1,8 @@ /** * @brief Atomic signal implementation. * - * Define **STA_ATOMIC_ENABLE** to enable module. + * Configuration: + * STA_ATOMIC_ENABLE: Enable module */ #ifndef STA_ATOMIC_SIGNAL_HPP #define STA_ATOMIC_SIGNAL_HPP diff --git a/include/sta/hal/gpio_pin.hpp b/include/sta/hal/gpio_pin.hpp index d4cdf9b..08b7f9c 100644 --- a/include/sta/hal/gpio_pin.hpp +++ b/include/sta/hal/gpio_pin.hpp @@ -1,7 +1,8 @@ /** * @brief Wrapper for HAL GPIO pins. * - * Define **STA_HAL_GPIO_ENABLE** in `` to enable module. + * Configuration: + * STA_HAL_GPIO_ENABLE: Enable module */ #ifndef STA_HAL_GPIO_PIN_HPP #define STA_HAL_GPIO_PIN_HPP @@ -10,8 +11,7 @@ #ifdef STA_HAL_GPIO_ENABLE #include - -#include +#include namespace sta diff --git a/include/sta/hal/spi.hpp b/include/sta/hal/spi.hpp index 7034368..b992513 100644 --- a/include/sta/hal/spi.hpp +++ b/include/sta/hal/spi.hpp @@ -1,9 +1,10 @@ /** * @brief Implementations for `SpiInterface` and `SpiDevice` using HAL. * - * Define **STA_HAL_SPI_ENABLE** in `` to enable module. + * Configuration: + * STA_HAL_SPI_ENABLE: Enable module * - * Requires **STA_HAL_GPIO_ENABLE**. + * Requires **HAL_GPIO** module. */ #ifndef STA_HAL_SPI_HPP #define STA_HAL_SPI_HPP @@ -15,11 +16,11 @@ #error "HAL GPIO required" #endif // !STA_HAL_GPIO_ENABLE +#include #include +#include #include -#include - namespace sta { @@ -88,36 +89,18 @@ namespace sta } // namespace sta - /** - * @brief Get function returning PCLK frequency. + * @brief Get SPI interface info struct for HAL handle. * - * @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. + * Requires STA_HAL__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 n Index of SPI interface (e.g. 2 for SPI2) - * @param pclk Index of peripheral clock used by SPI interface + * @param handle SPI interface handle */ -#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) +#define STA_HAL_SPI_INFO(handle) sta::HalSpiInterfaceInfo{&handle, STA_HAL_GET_HANDLE_PCLK_FREQ_FN(handle)} #endif // STA_HAL_SPI_ENABLE diff --git a/include/sta/hal/uart.hpp b/include/sta/hal/uart.hpp index c12c5dc..398a00e 100644 --- a/include/sta/hal/uart.hpp +++ b/include/sta/hal/uart.hpp @@ -1,10 +1,9 @@ /** * @brief Implementation of UART using HAL. * - * Define **STA_HAL_UART_ENABLE** in `` to enable module. - * - * To use a HAL UART instance (e.g. UART1) for `` define: - * #define STA_HAL_UART_DEBUG_SERIAL huart1 + * Configuration: + * STA_HAL_UART_ENABLE: Enable module + * STA_HAL_UART_DEBUG_SERIAL: Create global `sta::DebugSerial` object using this UART instance */ #ifndef STA_HAL_UART_HPP #define STA_HAL_UART_HPP @@ -12,10 +11,9 @@ #include #ifdef STA_HAL_UART_ENABLE +#include #include -#include - namespace sta { diff --git a/include/sta/spi_device.hpp b/include/sta/spi_device.hpp index 7e02f47..44253cc 100644 --- a/include/sta/spi_device.hpp +++ b/include/sta/spi_device.hpp @@ -6,8 +6,8 @@ #include -#include -#include +#include +#include namespace sta diff --git a/include/sta/spi_interface.hpp b/include/sta/spi_interface.hpp index 3c05e12..4d6ef17 100644 --- a/include/sta/spi_interface.hpp +++ b/include/sta/spi_interface.hpp @@ -7,8 +7,8 @@ #include #include -#include -#include +#include +#include namespace sta diff --git a/include/sta/spi_settings.hpp b/include/sta/spi_settings.hpp index d88a428..decec26 100644 --- a/include/sta/spi_settings.hpp +++ b/include/sta/spi_settings.hpp @@ -1,3 +1,6 @@ +/** + * @brief SPI setting types. + */ #ifndef STA_SPI_SETTINGS_HPP #define STA_SPI_SETTINGS_HPP @@ -6,18 +9,27 @@ namespace sta { + /** + * @brief SPI clock polarity. + */ enum class SpiClkPolarity { LOW, HIGH }; + /** + * @brief SPI clock phase. + */ enum class SpiClkPhase { EDGE_1, EDGE_2 }; + /** + * @brief SPI clock mode. + */ enum class SpiMode { MODE_0, @@ -26,18 +38,27 @@ namespace sta MODE_3 }; + /** + * @brief SPI data size. + */ enum class SpiDataSize { SIZE_8, SIZE_16 }; + /** + * @brief SPI bit order. + */ enum class SpiBitOrder { MSB, LSB }; + /** + * @brief Spi baud rate prescaler. + */ enum class SpiBaudRatePrescaler { DIV_2, @@ -51,17 +72,39 @@ namespace sta }; + /** + * @brief SPI settings. + */ struct SpiSettings { - SpiMode mode; - SpiDataSize dataSize; - SpiBitOrder bitOrder; - uint32_t clkSpeed; + SpiMode mode; /**< SPI clock mode */ + SpiDataSize dataSize; /**< SPI data size */ + SpiBitOrder bitOrder; /**< SPI bit order */ + uint32_t clkSpeed; /**< SPI clock speed */ }; + /** + * @brief Get SPI clock polarity from clock mode. + * + * @param mode SPI clock mode + * @return SPI clock polarity + */ SpiClkPolarity getSpiClkPolarity(SpiMode mode); + /** + * @brief Get SPI clock phase from clock mode. + * + * @param mode SPI clock mode + * @return SPI clock phase + */ SpiClkPhase getSpiClkPhase(SpiMode mode); + /** + * @brief Get SPI clock mode from clock phase and polarity. + * + * @param polarity SPI clock polarity + * @param phase SPI clock phase + * @return SPI clock mode + */ SpiMode getSpiMode(SpiClkPolarity polarity, SpiClkPhase phase); } // namespace sta diff --git a/include/sta/uart.hpp b/include/sta/uart.hpp index b849ea3..a287bd7 100644 --- a/include/sta/uart.hpp +++ b/include/sta/uart.hpp @@ -4,8 +4,8 @@ #ifndef STA_UART_HPP #define STA_UART_HPP -#include -#include +#include +#include namespace sta diff --git a/src/uart.cpp b/src/uart.cpp index 12bc743..5b5c7bb 100644 --- a/src/uart.cpp +++ b/src/uart.cpp @@ -1,10 +1,9 @@ #include -//#include +#include + #include -// Include last so macros don't mess with other headers -#include namespace sta @@ -143,7 +142,7 @@ namespace sta void UART::printDec(uintmax_t num, const char * fmt) { char buffer[64]; - sprintf(buffer, fmt, num); + snprintf(buffer, sizeof(buffer), fmt, num); print(buffer); }