From 67e7d88a5be5dfc1aae536e587dd0cbeba0475e4 Mon Sep 17 00:00:00 2001 From: dario Date: Thu, 18 Apr 2024 00:01:14 +0200 Subject: [PATCH 1/3] Added easier GPIO pin API --- include/sta/gpio_pin.hpp | 18 ++++++++++++++++++ src/gpio_pin.cpp | 20 ++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/gpio_pin.cpp diff --git a/include/sta/gpio_pin.hpp b/include/sta/gpio_pin.hpp index 9a26f4c..3ab32be 100644 --- a/include/sta/gpio_pin.hpp +++ b/include/sta/gpio_pin.hpp @@ -38,6 +38,24 @@ namespace sta */ virtual void setState(GpioPinState state) = 0; + /** + * @brief Set the GPIO pin to high. + * + */ + void setHigh(); + + /** + * @brief Set the GPIO pin to low. + * + */ + void setLow(); + + /** + * @brief Set the GPIO pin to the opposite of the current state. + * + */ + void toggle(); + /** * @brief Get pin input state. * diff --git a/src/gpio_pin.cpp b/src/gpio_pin.cpp new file mode 100644 index 0000000..aafd52e --- /dev/null +++ b/src/gpio_pin.cpp @@ -0,0 +1,20 @@ +#include + + +namespace sta +{ + void GpioPin::setHigh() + { + setState(GpioPinState::GPIO_HIGH); + } + + void GpioPin::setLow() + { + setState(GpioPinState::GPIO_LOW); + } + + void GpioPin::toggle() + { + setState(getState() == GpioPinState::GPIO_HIGH ? GpioPinState::GPIO_LOW : GpioPinState::GPIO_HIGH); + } +} // namespace sta From 78479d528c99d5fb1965dd5864acb1eed4f02f07 Mon Sep 17 00:00:00 2001 From: CarlWachter Date: Tue, 30 Apr 2024 13:41:57 +0200 Subject: [PATCH 2/3] CAN via Interrupt --- src/devices/stm32/can.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/devices/stm32/can.cpp b/src/devices/stm32/can.cpp index 7a5cd59..31bde0d 100644 --- a/src/devices/stm32/can.cpp +++ b/src/devices/stm32/can.cpp @@ -203,16 +203,16 @@ namespace sta } // namespace sta -#ifdef STA_STM32_CAN_GLOBAL +#ifdef STA_STM32_CAN_HANDLE #include namespace sta { - STM32CanController CanBus(&STA_STM32_CAN_GLOBAL); + STM32CanController CanBus(&STA_STM32_CAN_HANDLE); STA_WEAK - void CanBus_RxPendingCallback() + void CanBus_RxPendingCallback(uint32_t fifo) {} } // namespace sta @@ -221,17 +221,17 @@ extern "C" { void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) { - if (hcan == &STA_STM32_CAN_GLOBAL) + if (hcan == &STA_STM32_CAN_HANDLE) { - sta::CanBus_RxPendingCallback(); + sta::CanBus_RxPendingCallback(CAN_RX_FIFO0); } } void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan) { - if (hcan == &STA_STM32_CAN_GLOBAL) + if (hcan == &STA_STM32_CAN_HANDLE) { - sta::CanBus_RxPendingCallback(); + sta::CanBus_RxPendingCallback(CAN_RX_FIFO1); } } } From 61b738e2fc634c3525a74b1bc128a718707e2221 Mon Sep 17 00:00:00 2001 From: CarlWachter Date: Tue, 30 Apr 2024 15:25:06 +0200 Subject: [PATCH 3/3] Fix: Actually applying the configs for the CAN Filter --- src/devices/stm32/can.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/devices/stm32/can.cpp b/src/devices/stm32/can.cpp index 31bde0d..47e9c97 100644 --- a/src/devices/stm32/can.cpp +++ b/src/devices/stm32/can.cpp @@ -166,6 +166,7 @@ namespace sta config->FilterScale = CAN_FILTERSCALE_32BIT; config->FilterActivation = CAN_FILTER_DISABLE; config->SlaveStartFilterBank = MAX_FILTER_COUNT; + HAL_CAN_ConfigFilter(handle_, config); } }