diff --git a/hepa-uv/core/tasks.cpp b/hepa-uv/core/tasks.cpp index 79b97994c..656b53e9d 100644 --- a/hepa-uv/core/tasks.cpp +++ b/hepa-uv/core/tasks.cpp @@ -36,8 +36,8 @@ void hepauv_tasks::start_tasks( can_task::start_reader(can_bus); // TODO: including led_hardware for testing, this should be a AssesorClient - auto& hepa_task = - hepa_task_builder.start(5, "hepa_fan", gpio_drive_pins, hepa_hardware, queues); + auto& hepa_task = hepa_task_builder.start(5, "hepa_fan", gpio_drive_pins, + hepa_hardware, queues); auto& uv_task = uv_task_builder.start(5, "uv_ballast", gpio_drive_pins, queues); auto& led_control_task = diff --git a/hepa-uv/firmware/hardware.c b/hepa-uv/firmware/hardware.c deleted file mode 100644 index afe84d074..000000000 --- a/hepa-uv/firmware/hardware.c +++ /dev/null @@ -1,114 +0,0 @@ -#include "hepa-uv/firmware/hardware.h" -#include "hepa-uv/firmware/utility_gpio.h" -#include "common/firmware/errors.h" - -#include "platform_specific_hal_conf.h" -#include "system_stm32g4xx.h" - -TIM_HandleTypeDef htim3; - -TIM_OC_InitTypeDef htim3_sConfigOC = {0}; - - -// void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_pwm) { -// if(htim_pwm->Instance == TIM3) { -// __HAL_RCC_TIM3_CLK_ENABLE(); -// } -// } - -// void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim) { -// GPIO_InitTypeDef GPIO_InitStruct = {0}; -// if (htim->Instance == TIM3) { -// __HAL_RCC_GPIOA_CLK_ENABLE(); -// /**TIM3 GPIO Configuration -// PA6 ------> TIM3_CH1 -// */ -// GPIO_InitStruct.Pin = HEPA_PWM_PIN; -// GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; -// GPIO_InitStruct.Pull = GPIO_NOPULL; -// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; -// GPIO_InitStruct.Alternate = GPIO_AF2_TIM3; -// HAL_GPIO_Init(HEPA_PWM_PORT, &GPIO_InitStruct); -// } -// } - -/** - * @brief TIM3 Initialization Function for HEPA_PWM - * @param None - * @retval None - */ -static void MX_TIM3_Init(void) { - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; - - htim3.State = HAL_TIM_STATE_RESET; - htim3.Instance = TIM3; - htim3.Init.Prescaler = 64 - 1; - htim3.Init.CounterMode = TIM_COUNTERMODE_UP; - htim3.Init.Period = 40 - 1; - htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim3.Init.RepetitionCounter = 0; - htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if (HAL_TIM_Base_Init(&htim3) != HAL_OK) { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK) { - Error_Handler(); - } - if (HAL_TIM_PWM_Init(&htim3) != HAL_OK) { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != - HAL_OK) { - Error_Handler(); - } - htim3_sConfigOC.OCMode = TIM_OCMODE_PWM1; - // 0% duty cycle - htim3_sConfigOC.Pulse = 0; - htim3_sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; - htim3_sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; - htim3_sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; - htim3_sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET; - htim3_sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET; - if (HAL_TIM_PWM_ConfigChannel(&htim3, &htim3_sConfigOC, TIM_CHANNEL_1) != - HAL_OK) { - Error_Handler(); - } - sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; - sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; - sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF; - sBreakDeadTimeConfig.DeadTime = 0; - sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE; - sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH; - sBreakDeadTimeConfig.BreakFilter = 0; - sBreakDeadTimeConfig.BreakAFMode = TIM_BREAK_AFMODE_INPUT; - sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE; - sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH; - sBreakDeadTimeConfig.Break2Filter = 0; - sBreakDeadTimeConfig.Break2AFMode = TIM_BREAK_AFMODE_INPUT; - sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE; - if (HAL_TIMEx_ConfigBreakDeadTime(&htim3, &sBreakDeadTimeConfig) != - HAL_OK) { - Error_Handler(); - } - // HAL_TIM_MspPostInit(&htim3); -} - -void hepa_fan_hw_update_pwm(uint32_t duty_cycle) { - // update hepa fan speed - htim3.Instance->CCR1 = duty_cycle; -} - -void initialize_hardware() { - MX_TIM3_Init(); - - // Set the hepa fan speed to 0 - hepa_fan_hw_update_pwm(0); - - // Activate the channels - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); -} diff --git a/hepa-uv/firmware/hepa_control_hardware.cpp b/hepa-uv/firmware/hepa_control_hardware.cpp index 27a77b4d1..5347c172b 100644 --- a/hepa-uv/firmware/hepa_control_hardware.cpp +++ b/hepa-uv/firmware/hepa_control_hardware.cpp @@ -1,9 +1,9 @@ #include "hepa-uv/firmware/hepa_control_hardware.hpp" -#include "hepa-uv/firmware/hardware.h" -using namespace hepa_control_hardware; +#include "hepa-uv/firmware/hepauv_hardware.h" +using namespace hepa_control_hardware; void HepaControlHardware::set_hepa_fan_speed(uint32_t duty_cycle) { - hepa_fan_hw_update_pwm(duty_cycle); + set_hepa_fan_pwm(duty_cycle); } \ No newline at end of file diff --git a/hepa-uv/firmware/led_control_task/led_control_hardware.cpp b/hepa-uv/firmware/led_control_task/led_control_hardware.cpp index a7f42fb7a..7a5ad9ca6 100644 --- a/hepa-uv/firmware/led_control_task/led_control_hardware.cpp +++ b/hepa-uv/firmware/led_control_task/led_control_hardware.cpp @@ -6,9 +6,7 @@ using namespace led_control_hardware; // NOLINTNEXTLINE(readability-convert-member-functions-to-static) -auto LEDControlHardware::initialize() -> void { - initialize_hepauv_hardware(); -} +auto LEDControlHardware::initialize() -> void { initialize_hepauv_hardware(); } void LEDControlHardware::set_button_led_power(uint8_t button, uint32_t r, uint32_t g, uint32_t b, diff --git a/hepa-uv/firmware/main_rev1.cpp b/hepa-uv/firmware/main_rev1.cpp index 22c181df5..a1fa8396d 100644 --- a/hepa-uv/firmware/main_rev1.cpp +++ b/hepa-uv/firmware/main_rev1.cpp @@ -22,9 +22,9 @@ #include "common/firmware/utility_gpio.h" #include "hepa-uv/core/messages.hpp" #include "hepa-uv/core/tasks.hpp" -#include "hepa-uv/firmware/led_control_hardware.hpp" #include "hepa-uv/firmware/hepa_control_hardware.hpp" #include "hepa-uv/firmware/hepauv_hardware.h" +#include "hepa-uv/firmware/led_control_hardware.hpp" #include "hepa-uv/firmware/utility_gpio.h" static auto iWatchdog = iwdg::IndependentWatchDog{}; @@ -131,7 +131,8 @@ auto main() -> int { canbus.start(can_bit_timings); - hepauv_tasks::start_tasks(canbus, gpio_drive_pins, hepa_hardware, led_hardware); + hepauv_tasks::start_tasks(canbus, gpio_drive_pins, hepa_hardware, + led_hardware); iWatchdog.start(6); diff --git a/include/hepa-uv/core/hepa_task.hpp b/include/hepa-uv/core/hepa_task.hpp index 326395cb4..a3c235284 100644 --- a/include/hepa-uv/core/hepa_task.hpp +++ b/include/hepa-uv/core/hepa_task.hpp @@ -6,8 +6,8 @@ #include "common/core/message_queue.hpp" #include "common/firmware/gpio.hpp" #include "hepa-uv/core/constants.h" -#include "hepa-uv/core/messages.hpp" #include "hepa-uv/core/led_control_task.hpp" +#include "hepa-uv/core/messages.hpp" #include "hepa-uv/firmware/gpio_drive_hardware.hpp" #include "hepa-uv/firmware/hepa_control_hardware.hpp" @@ -18,10 +18,13 @@ using TaskMessage = interrupt_task_messages::TaskMessage; template class HepaMessageHandler { public: - explicit HepaMessageHandler(gpio_drive_hardware::GpioDrivePins &drive_pins, - hepa_control_hardware::HepaControlHardware &hepa_hardware, - LEDControlClient &led_control_client) - : drive_pins{drive_pins}, hepa_hardware{hepa_hardware}, led_control_client{led_control_client} { + explicit HepaMessageHandler( + gpio_drive_hardware::GpioDrivePins &drive_pins, + hepa_control_hardware::HepaControlHardware &hepa_hardware, + LEDControlClient &led_control_client) + : drive_pins{drive_pins}, + hepa_hardware{hepa_hardware}, + led_control_client{led_control_client} { // get current state hepa_push_button = gpio::is_set(drive_pins.hepa_push_button); // turn off the HEPA fan @@ -93,10 +96,12 @@ class HepaTask { * Task entry point. */ template - [[noreturn]] void operator()(gpio_drive_hardware::GpioDrivePins *drive_pins, - hepa_control_hardware::HepaControlHardware *hepa_hardware, - LEDControlClient *led_control_client) { - auto handler = HepaMessageHandler{*drive_pins, *hepa_hardware, *led_control_client}; + [[noreturn]] void operator()( + gpio_drive_hardware::GpioDrivePins *drive_pins, + hepa_control_hardware::HepaControlHardware *hepa_hardware, + LEDControlClient *led_control_client) { + auto handler = HepaMessageHandler{*drive_pins, *hepa_hardware, + *led_control_client}; TaskMessage message{}; for (;;) { if (queue.try_read(&message, queue.max_delay)) { diff --git a/include/hepa-uv/core/interfaces.hpp b/include/hepa-uv/core/interfaces.hpp index ddaace920..a161325ef 100644 --- a/include/hepa-uv/core/interfaces.hpp +++ b/include/hepa-uv/core/interfaces.hpp @@ -17,7 +17,7 @@ class LEDControlInterface { uint32_t b, uint32_t w) -> void = 0; }; -} // led_control namespace +} // namespace led_control namespace hepa_control { @@ -27,9 +27,10 @@ class HepaControlInterface { HepaControlInterface(const HepaControlInterface&) = delete; HepaControlInterface(HepaControlInterface&&) = delete; auto operator=(HepaControlInterface&&) -> HepaControlInterface& = delete; - auto operator=(const HepaControlInterface&) -> HepaControlInterface& = delete; + auto operator=(const HepaControlInterface&) + -> HepaControlInterface& = delete; virtual ~HepaControlInterface() = default; virtual void set_hepa_fan_speed(uint32_t duty_cycle); -}; -} // hepa_control namespace \ No newline at end of file +}; +} // namespace hepa_control \ No newline at end of file diff --git a/include/hepa-uv/core/led_control_task.hpp b/include/hepa-uv/core/led_control_task.hpp index 19e9a12ce..3f47f9f0b 100644 --- a/include/hepa-uv/core/led_control_task.hpp +++ b/include/hepa-uv/core/led_control_task.hpp @@ -4,8 +4,8 @@ #include "common/core/message_queue.hpp" #include "hepa-uv/core/constants.h" -#include "hepa-uv/core/messages.hpp" #include "hepa-uv/core/interfaces.hpp" +#include "hepa-uv/core/messages.hpp" namespace led_control_task { diff --git a/include/hepa-uv/core/tasks.hpp b/include/hepa-uv/core/tasks.hpp index 16830dc7e..7272c5b47 100644 --- a/include/hepa-uv/core/tasks.hpp +++ b/include/hepa-uv/core/tasks.hpp @@ -5,8 +5,8 @@ #include "hepa-uv/core/led_control_task.hpp" #include "hepa-uv/core/uv_task.hpp" #include "hepa-uv/firmware/gpio_drive_hardware.hpp" -#include "hepa-uv/firmware/led_control_hardware.hpp" #include "hepa-uv/firmware/hepa_control_hardware.hpp" +#include "hepa-uv/firmware/led_control_hardware.hpp" namespace hepauv_tasks { diff --git a/include/hepa-uv/firmware/hardware.h b/include/hepa-uv/firmware/hardware.h deleted file mode 100644 index 2ec4e6214..000000000 --- a/include/hepa-uv/firmware/hardware.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include - -#include "hepa-uv/core/constants.h" - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -void hepa_fan_hw_update_pwm(uint32_t duty_cycle); -void initialize_hardware(); - -#ifdef __cplusplus -} // extern "C" -#endif // __cplusplus diff --git a/include/hepa-uv/firmware/hepa_control_hardware.hpp b/include/hepa-uv/firmware/hepa_control_hardware.hpp index 809060d04..3fdeddc6a 100644 --- a/include/hepa-uv/firmware/hepa_control_hardware.hpp +++ b/include/hepa-uv/firmware/hepa_control_hardware.hpp @@ -19,4 +19,4 @@ class HepaControlHardware : public HepaControlInterface { void set_hepa_fan_speed(uint32_t duty_cycle); }; -} // namespace led_control_hardware \ No newline at end of file +} // namespace hepa_control_hardware \ No newline at end of file