Improve doxygen comments

This commit is contained in:
Henrik Stickann 2022-04-24 13:43:44 +02:00
parent e7d246a2e7
commit a24aa1c5c6
10 changed files with 77 additions and 52 deletions

View File

@ -1,7 +1,8 @@
/** /**
* @brief Atomic mutex implementation. * @brief Atomic mutex implementation.
* *
* Define **STA_ATOMIC_ENABLE** to enable module. * Configuration:
* STA_ATOMIC_ENABLE: Enable module
*/ */
#ifndef STA_ATOMIC_MUTEX_HPP #ifndef STA_ATOMIC_MUTEX_HPP
#define STA_ATOMIC_MUTEX_HPP #define STA_ATOMIC_MUTEX_HPP

View File

@ -1,7 +1,8 @@
/** /**
* @brief Atomic signal implementation. * @brief Atomic signal implementation.
* *
* Define **STA_ATOMIC_ENABLE** to enable module. * Configuration:
* STA_ATOMIC_ENABLE: Enable module
*/ */
#ifndef STA_ATOMIC_SIGNAL_HPP #ifndef STA_ATOMIC_SIGNAL_HPP
#define STA_ATOMIC_SIGNAL_HPP #define STA_ATOMIC_SIGNAL_HPP

View File

@ -1,7 +1,8 @@
/** /**
* @brief Wrapper for HAL GPIO pins. * @brief Wrapper for HAL GPIO pins.
* *
* Define **STA_HAL_GPIO_ENABLE** in `<sta/config.hpp>` to enable module. * Configuration:
* STA_HAL_GPIO_ENABLE: Enable module
*/ */
#ifndef STA_HAL_GPIO_PIN_HPP #ifndef STA_HAL_GPIO_PIN_HPP
#define STA_HAL_GPIO_PIN_HPP #define STA_HAL_GPIO_PIN_HPP
@ -10,8 +11,7 @@
#ifdef STA_HAL_GPIO_ENABLE #ifdef STA_HAL_GPIO_ENABLE
#include <sta/gpio_pin.hpp> #include <sta/gpio_pin.hpp>
#include <sta/hal.hpp>
#include <main.h>
namespace sta namespace sta

View File

@ -1,9 +1,10 @@
/** /**
* @brief Implementations for `SpiInterface` and `SpiDevice` using HAL. * @brief Implementations for `SpiInterface` and `SpiDevice` using HAL.
* *
* Define **STA_HAL_SPI_ENABLE** in `<sta/config.hpp>` to enable module. * Configuration:
* STA_HAL_SPI_ENABLE: Enable module
* *
* Requires **STA_HAL_GPIO_ENABLE**. * Requires **HAL_GPIO** module.
*/ */
#ifndef STA_HAL_SPI_HPP #ifndef STA_HAL_SPI_HPP
#define STA_HAL_SPI_HPP #define STA_HAL_SPI_HPP
@ -15,11 +16,11 @@
#error "HAL GPIO required" #error "HAL GPIO required"
#endif // !STA_HAL_GPIO_ENABLE #endif // !STA_HAL_GPIO_ENABLE
#include <sta/hal.hpp>
#include <sta/spi_device.hpp> #include <sta/spi_device.hpp>
#include <sta/hal/clocks.hpp>
#include <sta/hal/gpio_pin.hpp> #include <sta/hal/gpio_pin.hpp>
#include <main.h>
namespace sta namespace sta
{ {
@ -88,36 +89,18 @@ namespace sta
} // 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 * Requires STA_HAL_<handle>_PCLK_IDX to be defined for the MCU.
*/ * MCU mappings are found in `core` -> sta/mcu/.hpp files.
#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 * Check the MCUs Reference Manual RCC register documentation to see which
* peripheral clock is used. * peripheral clock is used.
* *
* @param n Index of SPI interface (e.g. 2 for SPI2) * @param handle SPI interface handle
* @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)} #define STA_HAL_SPI_INFO(handle) sta::HalSpiInterfaceInfo{&handle, STA_HAL_GET_HANDLE_PCLK_FREQ_FN(handle)}
/**
* @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_ENABLE

View File

@ -1,10 +1,9 @@
/** /**
* @brief Implementation of UART using HAL. * @brief Implementation of UART using HAL.
* *
* Define **STA_HAL_UART_ENABLE** in `<sta/config.hpp>` to enable module. * Configuration:
* * STA_HAL_UART_ENABLE: Enable module
* To use a HAL UART instance (e.g. UART1) for `<sta/debug_serial.hpp>` define: * STA_HAL_UART_DEBUG_SERIAL: Create global `sta::DebugSerial` object using this UART instance
* #define STA_HAL_UART_DEBUG_SERIAL huart1
*/ */
#ifndef STA_HAL_UART_HPP #ifndef STA_HAL_UART_HPP
#define STA_HAL_UART_HPP #define STA_HAL_UART_HPP
@ -12,10 +11,9 @@
#include <sta/config.hpp> #include <sta/config.hpp>
#ifdef STA_HAL_UART_ENABLE #ifdef STA_HAL_UART_ENABLE
#include <sta/hal.hpp>
#include <sta/uart.hpp> #include <sta/uart.hpp>
#include <main.h>
namespace sta namespace sta
{ {

View File

@ -6,8 +6,8 @@
#include <sta/spi_interface.hpp> #include <sta/spi_interface.hpp>
#include <stdint.h> #include <cstdint>
#include <stddef.h> #include <cstddef>
namespace sta namespace sta

View File

@ -7,8 +7,8 @@
#include <sta/mutex.hpp> #include <sta/mutex.hpp>
#include <sta/spi_settings.hpp> #include <sta/spi_settings.hpp>
#include <stdint.h> #include <cstdint>
#include <stddef.h> #include <cstddef>
namespace sta namespace sta

View File

@ -1,3 +1,6 @@
/**
* @brief SPI setting types.
*/
#ifndef STA_SPI_SETTINGS_HPP #ifndef STA_SPI_SETTINGS_HPP
#define STA_SPI_SETTINGS_HPP #define STA_SPI_SETTINGS_HPP
@ -6,18 +9,27 @@
namespace sta namespace sta
{ {
/**
* @brief SPI clock polarity.
*/
enum class SpiClkPolarity enum class SpiClkPolarity
{ {
LOW, LOW,
HIGH HIGH
}; };
/**
* @brief SPI clock phase.
*/
enum class SpiClkPhase enum class SpiClkPhase
{ {
EDGE_1, EDGE_1,
EDGE_2 EDGE_2
}; };
/**
* @brief SPI clock mode.
*/
enum class SpiMode enum class SpiMode
{ {
MODE_0, MODE_0,
@ -26,18 +38,27 @@ namespace sta
MODE_3 MODE_3
}; };
/**
* @brief SPI data size.
*/
enum class SpiDataSize enum class SpiDataSize
{ {
SIZE_8, SIZE_8,
SIZE_16 SIZE_16
}; };
/**
* @brief SPI bit order.
*/
enum class SpiBitOrder enum class SpiBitOrder
{ {
MSB, MSB,
LSB LSB
}; };
/**
* @brief Spi baud rate prescaler.
*/
enum class SpiBaudRatePrescaler enum class SpiBaudRatePrescaler
{ {
DIV_2, DIV_2,
@ -51,17 +72,39 @@ namespace sta
}; };
/**
* @brief SPI settings.
*/
struct SpiSettings struct SpiSettings
{ {
SpiMode mode; SpiMode mode; /**< SPI clock mode */
SpiDataSize dataSize; SpiDataSize dataSize; /**< SPI data size */
SpiBitOrder bitOrder; SpiBitOrder bitOrder; /**< SPI bit order */
uint32_t clkSpeed; 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); 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); 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); SpiMode getSpiMode(SpiClkPolarity polarity, SpiClkPhase phase);
} // namespace sta } // namespace sta

View File

@ -4,8 +4,8 @@
#ifndef STA_UART_HPP #ifndef STA_UART_HPP
#define STA_UART_HPP #define STA_UART_HPP
#include <stddef.h> #include <cstddef>
#include <stdint.h> #include <cstdint>
namespace sta namespace sta

View File

@ -1,10 +1,9 @@
#include <sta/uart.hpp> #include <sta/uart.hpp>
//#include <cstdio> #include <sta/printf.hpp>
#include <cstring> #include <cstring>
// Include last so macros don't mess with other headers
#include <printf.h>
namespace sta namespace sta
@ -143,7 +142,7 @@ namespace sta
void UART::printDec(uintmax_t num, const char * fmt) void UART::printDec(uintmax_t num, const char * fmt)
{ {
char buffer[64]; char buffer[64];
sprintf(buffer, fmt, num); snprintf(buffer, sizeof(buffer), fmt, num);
print(buffer); print(buffer);
} }