From 0d02d57cbbbc3c295d1ddc433304ff1edcf24e64 Mon Sep 17 00:00:00 2001 From: dvdb97 Date: Sun, 16 Jul 2023 12:02:45 +0200 Subject: [PATCH] Small fixes for smt32 support --- include/sta/bus/uart/uart.hpp | 2 +- include/sta/config.hpp | 4 ++-- include/sta/devices/stm32/bus/spi.hpp | 13 +++++-------- include/sta/devices/stm32/bus/uart.hpp | 2 +- include/sta/devices/stm32/can.hpp | 2 +- include/sta/devices/stm32/gpio_pin.hpp | 2 ++ src/bus/uart/uart.cpp | 4 ++-- src/devices/stm32/bus/spi.cpp | 10 ++++------ src/devices/stm32/bus/uart.cpp | 6 +++--- src/devices/stm32/can.cpp | 2 +- src/devices/stm32/delay.cpp | 2 +- src/devices/stm32/gpio_pin.cpp | 7 ++++++- 12 files changed, 29 insertions(+), 27 deletions(-) diff --git a/include/sta/bus/uart/uart.hpp b/include/sta/bus/uart/uart.hpp index aee3232..21bff52 100644 --- a/include/sta/bus/uart/uart.hpp +++ b/include/sta/bus/uart/uart.hpp @@ -9,7 +9,7 @@ namespace sta class UART : public Interface { public: - UART(Mutex * mutex=nullptr); + UART(UARTSettings & settings, Mutex * mutex=nullptr); /** * @brief Get %UART interface settings. diff --git a/include/sta/config.hpp b/include/sta/config.hpp index 3b22342..b9d1958 100644 --- a/include/sta/config.hpp +++ b/include/sta/config.hpp @@ -1,11 +1,11 @@ #ifndef STA_CONFIG_HPP #define STA_CONFIG_HPP -#include +#include #define STA_DEBUGGING_ENABLED #define STA_PRINTF_USE_STDLIB -#define STA_ASSERT_FORCE +// #define STA_ASSERT_FORCE #endif // STA_CONFIG_HPP \ No newline at end of file diff --git a/include/sta/devices/stm32/bus/spi.hpp b/include/sta/devices/stm32/bus/spi.hpp index 385e1e9..9ed1ee0 100644 --- a/include/sta/devices/stm32/bus/spi.hpp +++ b/include/sta/devices/stm32/bus/spi.hpp @@ -21,11 +21,11 @@ #if defined(STA_STM32_SPI_ENABLED) || defined(DOXYGEN) -#include -#include +#include +#include -#include -#include +#include +#include /** @@ -92,10 +92,7 @@ namespace sta * @param intf %SPI interface * @param csPin Device CS pin */ - STM32SPIDevice(STM32SPI * intf, STM32GpioPin csPin); - - private: - STM32GpioPin csPin_; /**< Device CS pin */ + STM32SPIDevice(STM32SPI * intf, STM32GpioPin * csPin); }; diff --git a/include/sta/devices/stm32/bus/uart.hpp b/include/sta/devices/stm32/bus/uart.hpp index f50477d..1f70911 100644 --- a/include/sta/devices/stm32/bus/uart.hpp +++ b/include/sta/devices/stm32/bus/uart.hpp @@ -41,7 +41,7 @@ namespace sta /** * @param handle STM32 HAL handle */ - STM32UART(UART_HandleTypeDef * handle, Mutex * mutex); + STM32UART(UART_HandleTypeDef * handle, UARTSettings & settings, Mutex * mutex); void transfer(uint8_t value) override; void transfer16(uint16_t value) override; diff --git a/include/sta/devices/stm32/can.hpp b/include/sta/devices/stm32/can.hpp index 8eb5d70..95a96c5 100644 --- a/include/sta/devices/stm32/can.hpp +++ b/include/sta/devices/stm32/can.hpp @@ -28,7 +28,7 @@ #if defined(STA_STM32_CAN_ENABLED) || defined(DOXYGEN) -#include +#include namespace sta diff --git a/include/sta/devices/stm32/gpio_pin.hpp b/include/sta/devices/stm32/gpio_pin.hpp index ee87f2d..205b297 100644 --- a/include/sta/devices/stm32/gpio_pin.hpp +++ b/include/sta/devices/stm32/gpio_pin.hpp @@ -50,6 +50,8 @@ namespace sta void setState(GpioPinState state) override; + GpioPinState getState() override; + /** * @brief Get GPIO port for pin. * diff --git a/src/bus/uart/uart.cpp b/src/bus/uart/uart.cpp index d2e2767..1b86d1e 100644 --- a/src/bus/uart/uart.cpp +++ b/src/bus/uart/uart.cpp @@ -2,8 +2,8 @@ namespace sta { - UART::UART(Mutex * mutex) - : Interface{mutex} + UART::UART(UARTSettings & settings, Mutex * mutex) + : Interface{mutex}, settings_{settings} { } diff --git a/src/devices/stm32/bus/spi.cpp b/src/devices/stm32/bus/spi.cpp index 7cfa8b5..becfaac 100644 --- a/src/devices/stm32/bus/spi.cpp +++ b/src/devices/stm32/bus/spi.cpp @@ -1,7 +1,7 @@ #include #ifdef STA_STM32_SPI_ENABLED -#include +#include #include #include @@ -66,7 +66,7 @@ namespace sta } - STM32SPI::STM32SPI(SPI_HandleTypeDef * handle, uint32_t pclkFreq, Mutex * mutex = nullptr) + STM32SPI::STM32SPI(SPI_HandleTypeDef * handle, uint32_t pclkFreq, Mutex * mutex) : SPI(getSPISettings(handle, pclkFreq), mutex), handle_{handle} { STA_ASSERT(handle != nullptr); @@ -157,10 +157,8 @@ namespace sta } } - - - STM32SPIDevice::STM32SPIDevice(STM32SPI * intf, STM32GpioPin csPin) - : SPIDevice(intf, &csPin_), csPin_{csPin} + STM32SPIDevice::STM32SPIDevice(STM32SPI * intf, STM32GpioPin * csPin) + : SPIDevice(intf, csPin) {} } // namespace sta diff --git a/src/devices/stm32/bus/uart.cpp b/src/devices/stm32/bus/uart.cpp index 2d36ef3..699e9eb 100644 --- a/src/devices/stm32/bus/uart.cpp +++ b/src/devices/stm32/bus/uart.cpp @@ -1,13 +1,13 @@ #include #ifdef STA_STM32_UART_ENABLED -#include +#include #include namespace sta { - STM32UART::STM32UART(UART_HandleTypeDef * handle, Mutex * mutex) - : UART{mutex}, handle_{handle} + STM32UART::STM32UART(UART_HandleTypeDef * handle, UARTSettings & settings, Mutex * mutex) + : UART{settings, mutex}, handle_{handle} { STA_ASSERT(handle != nullptr); } diff --git a/src/devices/stm32/can.cpp b/src/devices/stm32/can.cpp index 1355b0e..0c485ea 100644 --- a/src/devices/stm32/can.cpp +++ b/src/devices/stm32/can.cpp @@ -1,7 +1,7 @@ #include #ifdef STA_STM32_CAN_ENABLED -#include +#include #include diff --git a/src/devices/stm32/delay.cpp b/src/devices/stm32/delay.cpp index a9d4c51..a7bfd3c 100644 --- a/src/devices/stm32/delay.cpp +++ b/src/devices/stm32/delay.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include diff --git a/src/devices/stm32/gpio_pin.cpp b/src/devices/stm32/gpio_pin.cpp index 9318605..416d3ab 100644 --- a/src/devices/stm32/gpio_pin.cpp +++ b/src/devices/stm32/gpio_pin.cpp @@ -1,7 +1,7 @@ #include #ifdef STA_STM32_GPIO_ENABLED -#include +#include #include @@ -18,6 +18,11 @@ namespace sta HAL_GPIO_WritePin(port_, pin_, (state == GpioPinState::GPIO_LOW) ? GPIO_PIN_RESET : GPIO_PIN_SET); } + GpioPinState STM32GpioPin::getState() + { + return HAL_GPIO_ReadPin(port_, pin_) == GPIO_PIN_RESET ? GpioPinState::GPIO_LOW : GpioPinState::GPIO_HIGH; + } + GPIO_TypeDef * STM32GpioPin::getPort() const { return port_;