From dd2983821ed23ef8d9c9059357abf11e7bc96a12 Mon Sep 17 00:00:00 2001 From: Henrik Stickann <4376396-Mithradir@users.noreply.gitlab.com> Date: Fri, 20 Jan 2023 01:52:18 +0100 Subject: [PATCH] Change module enable logic --- include/sta/stm32/can.hpp | 24 ++++++++++++------------ include/sta/stm32/clocks.hpp | 5 +++++ include/sta/stm32/delay.hpp | 13 +++---------- include/sta/stm32/gpio_pin.hpp | 14 +++++++++++--- include/sta/stm32/hal.hpp | 1 + include/sta/stm32/spi.hpp | 29 ++++++++++++----------------- include/sta/stm32/uart.hpp | 23 +++++++++++------------ src/stm32/can.cpp | 4 ++-- src/stm32/delay.cpp | 8 ++++++-- src/stm32/gpio_pin.cpp | 4 ++-- src/stm32/spi.cpp | 12 +++--------- src/stm32/uart.cpp | 4 ++-- 12 files changed, 70 insertions(+), 71 deletions(-) diff --git a/include/sta/stm32/can.hpp b/include/sta/stm32/can.hpp index f440ece..1af57c4 100644 --- a/include/sta/stm32/can.hpp +++ b/include/sta/stm32/can.hpp @@ -14,14 +14,6 @@ */ #ifdef DOXYGEN -/** - * @def STA_STM32_CAN_ENABLE - * @brief Enable module. - * - * @ingroup stm32BuildConfig - */ -# define STA_STM32_CAN_ENABLE - /** * @def STA_STM32_CAN_GLOBAL * @brief Create global CanBus object using this CAN instance. @@ -32,12 +24,20 @@ #endif // DOXYGEN + +// Only enable module on STM32 platform w/ HAL CAN module enabled #include -#ifdef STA_STM32_CAN_ENABLE +#ifdef STA_PLATFORM_STM32 +# include +# ifdef HAL_CAN_MODULE_ENABLED +# define STA_STM32_CAN_ENABLED +# endif // HAL_CAN_MODULE_ENABLED +#endif // STA_PLATFORM_STM32 -#include -#include +#ifdef STA_STM32_CAN_ENABLED + +#include namespace sta @@ -124,6 +124,6 @@ namespace sta } // namespace sta -#endif // STA_STM32_CAN_ENABLE +#endif // STA_STM32_CAN_ENABLED #endif // STA_CORE_STM32_CAN_HPP diff --git a/include/sta/stm32/clocks.hpp b/include/sta/stm32/clocks.hpp index 4828ae7..29a9b4f 100644 --- a/include/sta/stm32/clocks.hpp +++ b/include/sta/stm32/clocks.hpp @@ -23,7 +23,10 @@ * @{ */ + +// Only enable module on STM32 platform #include +#ifdef STA_PLATFORM_STM32 #include @@ -96,4 +99,6 @@ /** @} */ +#endif // STA_PLATFORM_STM32 + #endif // STA_CORE_STM32_CLOCKS_HPP diff --git a/include/sta/stm32/delay.hpp b/include/sta/stm32/delay.hpp index a9400dc..94cbe90 100644 --- a/include/sta/stm32/delay.hpp +++ b/include/sta/stm32/delay.hpp @@ -12,14 +12,6 @@ */ #ifdef DOXYGEN -/** - * @def STA_STM32_DELAY_ENABLE - * @brief Enable module. - * - * @ingroup stm32BuildConfig - */ -# define STA_STM32_DELAY_ENABLE - /** * @def STA_STM32_DELAY_US_TIM * @brief 1 MHz TIM instance used by sta::delayUs. @@ -33,8 +25,9 @@ #endif // DOXYGEN +// Only enable module on STM32 platform #include -#ifdef STA_STM32_DELAY_ENABLE +#ifdef STA_PLATFORM_STM32 #include @@ -63,6 +56,6 @@ namespace sta } // namespace sta -#endif // STA_STM32_DELAY_ENABLE +#endif // STA_PLATFORM_STM32 #endif // STA_CORE_STM32_DELAY_HPP diff --git a/include/sta/stm32/gpio_pin.hpp b/include/sta/stm32/gpio_pin.hpp index 8ed6910..c69f6ed 100644 --- a/include/sta/stm32/gpio_pin.hpp +++ b/include/sta/stm32/gpio_pin.hpp @@ -22,12 +22,20 @@ #endif // DOXYGEN +// Only enable module on STM32 platform w/ HAL GPIO module enabled #include -#ifdef STA_STM32_GPIO_ENABLE +#ifdef STA_PLATFORM_STM32 +# include +# ifdef HAL_GPIO_MODULE_ENABLED +# define STA_STM32_GPIO_ENABLED +# endif // HAL_GPIO_MODULE_ENABLED +#endif // STA_PLATFORM_STM32 + + +#ifdef STA_STM32_GPIO_ENABLED #include -#include namespace sta @@ -103,6 +111,6 @@ namespace sta #define STA_STM32_GPIO_PIN(label) sta::STM32GpioPin{label##_GPIO_Port, label##_Pin} -#endif // STA_STM32_GPIO_ENABLE +#endif // STA_STM32_GPIO_ENABLED #endif // STA_CORE_STM32_GPIO_PIN_HPP diff --git a/include/sta/stm32/hal.hpp b/include/sta/stm32/hal.hpp index fb3dedd..b6b5b4b 100644 --- a/include/sta/stm32/hal.hpp +++ b/include/sta/stm32/hal.hpp @@ -1,6 +1,7 @@ #ifndef STA_CORE_STM32_HAL_HPP #define STA_CORE_STM32_HAL_HPP + // Include STM32 HAL headers #include diff --git a/include/sta/stm32/spi.hpp b/include/sta/stm32/spi.hpp index dbb1a2a..595cbf0 100644 --- a/include/sta/stm32/spi.hpp +++ b/include/sta/stm32/spi.hpp @@ -11,26 +11,21 @@ * @brief STM32 SPI module. */ -#ifdef DOXYGEN -/** - * @def STA_STM32_SPI_ENABLE - * @brief Enable module. - * - * Requires **STM_GPIO** module. - * - * @ingroup stm32BuildConfig - */ -# define STA_STM32_SPI_ENABLE -#endif // DOXYGEN - +// Only enable module on STM32 platform w/ HAL SPI module enabled #include -#ifdef STA_STM32_SPI_ENABLE +#ifdef STA_PLATFORM_STM32 +# include +# ifndef HAL_GPIO_MODULE_ENABLED +# error "STM32 GPIO module required!" +# endif // !HAL_GPIO_MODULE_ENABLED +# ifdef HAL_SPI_MODULE_ENABLED +# define STA_STM32_SPI_ENABLED +# endif // HAL_SPI_MODULE_ENABLED +#endif // STA_PLATFORM_STM32 -#ifndef STA_STM32_GPIO_ENABLE -#error "STM32 GPIO module required" -#endif // !STA_STM32_GPIO_ENABLE +#ifdef STA_STM32_SPI_ENABLED #include #include @@ -128,6 +123,6 @@ namespace sta #define STA_STM32_SPI_INFO(handle) sta::STM32SpiInterfaceInfo{&handle, STA_STM32_GET_HANDLE_PCLK_FREQ_FN(handle)} -#endif // STA_STM32_SPI_ENABLE +#endif // STA_STM32_SPI_ENABLED #endif // STA_CORE_STM32_SPI_HPP diff --git a/include/sta/stm32/uart.hpp b/include/sta/stm32/uart.hpp index 18fd891..45ab782 100644 --- a/include/sta/stm32/uart.hpp +++ b/include/sta/stm32/uart.hpp @@ -12,14 +12,6 @@ */ #ifdef DOXYGEN -/** - * @def STA_STM32_UART_ENABLE - * @brief Enable module. - * - * @ingroup stm32BuildConfig - */ -# define STA_STM32_UART_ENABLE - /** * @def STA_STM32_UART_DEBUG_SERIAL * @brief Create global sta::DebugSerial object using this HAL UART instance. @@ -30,13 +22,20 @@ #endif // DOXYGEN +// Only enable module on STM32 platform w/ HAL UART module enabled #include -#ifdef STA_STM32_UART_ENABLE +#ifdef STA_PLATFORM_STM32 +# include +# ifdef HAL_UART_MODULE_ENABLED +# define STA_STM32_UART_ENABLED +# endif // HAL_UART_MODULE_ENABLED +#endif // STA_PLATFORM_STM32 + + +#ifdef STA_STM32_UART_ENABLED #include -#include - namespace sta { @@ -61,6 +60,6 @@ namespace sta } // namespace sta -#endif // STA_STM32_UART_ENABLE +#endif // STA_STM32_UART_ENABLED #endif // STA_CORE_STM32_UART_HPP diff --git a/src/stm32/can.cpp b/src/stm32/can.cpp index ec83936..0e0379c 100644 --- a/src/stm32/can.cpp +++ b/src/stm32/can.cpp @@ -1,5 +1,5 @@ #include -#ifdef STA_STM32_CAN_ENABLE +#ifdef STA_STM32_CAN_ENABLED #include #include @@ -207,4 +207,4 @@ extern "C" #endif // STA_STM32_CAN_GLOBAL -#endif // STA_STM32_CAN_ENABLE +#endif // STA_STM32_CAN_ENABLED diff --git a/src/stm32/delay.cpp b/src/stm32/delay.cpp index 684cf8f..d9c58fc 100644 --- a/src/stm32/delay.cpp +++ b/src/stm32/delay.cpp @@ -1,5 +1,5 @@ #include -#ifdef STA_STM32_DELAY_ENABLE +#ifdef STA_PLATFORM_STM32 #include #include @@ -19,6 +19,10 @@ namespace sta #ifdef STA_STM32_DELAY_US_TIM +#ifndef HAL_TIM_MODULE_ENABLED +# error "STM32 HAL TIM module not enabled!" +#endif // HAL_TIM_MODULE_ENABLED + #include namespace sta @@ -68,4 +72,4 @@ namespace sta #endif // STA_STM32_DELAY_US_TIM -#endif // STA_STM32_DELAY_ENABLE +#endif // STA_PLATFORM_STM32 diff --git a/src/stm32/gpio_pin.cpp b/src/stm32/gpio_pin.cpp index 11f841e..20e3208 100644 --- a/src/stm32/gpio_pin.cpp +++ b/src/stm32/gpio_pin.cpp @@ -1,5 +1,5 @@ #include -#ifdef STA_STM32_GPIO_ENABLE +#ifdef STA_STM32_GPIO_ENABLED #include #include @@ -80,4 +80,4 @@ namespace sta } // namespace sta -#endif // STA_STM32_GPIO_ENABLE +#endif // STA_STM32_GPIO_ENABLED diff --git a/src/stm32/spi.cpp b/src/stm32/spi.cpp index 90243aa..955be2c 100644 --- a/src/stm32/spi.cpp +++ b/src/stm32/spi.cpp @@ -1,5 +1,5 @@ #include -#ifdef STA_STM32_SPI_ENABLE +#ifdef STA_STM32_SPI_ENABLED #include #include @@ -10,13 +10,7 @@ # define STA_STM32_SPI_REVERSE_BIT_ORDER SpiBitOrder::MSB #elif STA_MCU_BIG_ENDIAN # define STA_STM32_SPI_REVERSE_BIT_ORDER SpiBitOrder::LSB -#else // !STA_MCU_LITTLE_ENDIAN && !STA_MCU_BIG_ENDIAN -# ifdef STA_STM32_SPI_REVERSE_BIT_ORDER -# warning "Internal STA_STM32_SPI_REVERSE_BIT_ORDER macro manually defined! Better now what you are doing!!!" -# else // !STA_STM32_SPI_REVERSE_BIT_ORDER -# error "Unknown endian-ness. Define STA_MCU_LITTLE_ENDIAN or STA_MCU_BIG_ENDIAN in " -# endif // !STA_STM32_SPI_REVERSE_BIT_ORDER -#endif // !STA_MCU_LITTLE_ENDIAN && !STA_MCU_BIG_ENDIAN +#endif namespace sta @@ -178,4 +172,4 @@ namespace sta } // namespace sta -#endif // STA_HAL_SPI_ENABLE +#endif // STA_STM32_SPI_ENABLED diff --git a/src/stm32/uart.cpp b/src/stm32/uart.cpp index 3a99564..d530c7c 100644 --- a/src/stm32/uart.cpp +++ b/src/stm32/uart.cpp @@ -1,5 +1,5 @@ #include -#ifdef STA_STM32_UART_ENABLE +#ifdef STA_STM32_UART_ENABLED #include @@ -40,4 +40,4 @@ namespace sta #endif // STA_STM32_UART_DEBUG_SERIAL -#endif // STA_STM32_UART_ENABLE +#endif // STA_STM32_UART_ENABLED