From e7d246a2e78410013421c43f669da7c31d99fcf4 Mon Sep 17 00:00:00 2001 From: Henrik Stickann <4376396-Mithradir@users.noreply.gitlab.com> Date: Sun, 24 Apr 2022 13:43:15 +0200 Subject: [PATCH] Add HAL clock helpers --- include/sta/hal/clocks.hpp | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 include/sta/hal/clocks.hpp diff --git a/include/sta/hal/clocks.hpp b/include/sta/hal/clocks.hpp new file mode 100644 index 0000000..d29a23a --- /dev/null +++ b/include/sta/hal/clocks.hpp @@ -0,0 +1,60 @@ +/** + * @brief Helper macros for HAL clock queries. + */ +#ifndef STA_HAL_CLOCKS_HPP +#define STA_HAL_CLOCKS_HPP + +#include +#include + + +/** + * @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