diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-06-06 17:47:43 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-06 17:47:43 +0200 |
| commit | 35dcf8c8607483c104711c9398d47d57147f4389 (patch) | |
| tree | b2c17823827af9233dff152d918fb829cc939ad8 /src/components/motor | |
| parent | f95147cf0ed759a6ae30ac8d7cfdf7eba23a3ee9 (diff) | |
Switch to freertos timers (#1095)
* Use FreeRTOS timer for AlarmController
* Use FreeRTOS timer for MotorController
* Remove app_timer component from compilation as we now solely use
FreeROTS timer
* Simplify variable and text names for AlarmController and MotorController timers
* Call ScheduleAlarm directly from StopAlerting, for recurring timers
Co-authored-by: Riku Isokoski <riksu9000@gmail.com>
Co-authored-by: NeroBurner <pyro4hell@gmail.com>
Diffstat (limited to 'src/components/motor')
| -rw-r--r-- | src/components/motor/MotorController.cpp | 26 | ||||
| -rw-r--r-- | src/components/motor/MotorController.h | 8 |
2 files changed, 17 insertions, 17 deletions
diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index c794a02c..90e41d20 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -1,43 +1,39 @@ #include "components/motor/MotorController.h" #include <hal/nrf_gpio.h> #include "systemtask/SystemTask.h" -#include "app_timer.h" #include "drivers/PinMap.h" -APP_TIMER_DEF(shortVibTimer); -APP_TIMER_DEF(longVibTimer); - using namespace Pinetime::Controllers; void MotorController::Init() { nrf_gpio_cfg_output(PinMap::Motor); nrf_gpio_pin_set(PinMap::Motor); - app_timer_init(); - app_timer_create(&shortVibTimer, APP_TIMER_MODE_SINGLE_SHOT, StopMotor); - app_timer_create(&longVibTimer, APP_TIMER_MODE_REPEATED, Ring); + shortVib = xTimerCreate("shortVib", 1, pdFALSE, nullptr, StopMotor); + longVib = xTimerCreate("longVib", pdMS_TO_TICKS(1000), pdTRUE, this, Ring); } -void MotorController::Ring(void* p_context) { - auto* motorController = static_cast<MotorController*>(p_context); +void MotorController::Ring(TimerHandle_t xTimer) { + auto* motorController = static_cast<MotorController*>(pvTimerGetTimerID(xTimer)); motorController->RunForDuration(50); } void MotorController::RunForDuration(uint8_t motorDuration) { - nrf_gpio_pin_clear(PinMap::Motor); - app_timer_start(shortVibTimer, APP_TIMER_TICKS(motorDuration), nullptr); + if (xTimerChangePeriod(shortVib, pdMS_TO_TICKS(motorDuration), 0) == pdPASS && xTimerStart(shortVib, 0) == pdPASS) { + nrf_gpio_pin_clear(PinMap::Motor); + } } void MotorController::StartRinging() { - Ring(this); - app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this); + RunForDuration(50); + xTimerStart(longVib, 0); } void MotorController::StopRinging() { - app_timer_stop(longVibTimer); + xTimerStop(longVib, 0); nrf_gpio_pin_set(PinMap::Motor); } -void MotorController::StopMotor(void* p_context) { +void MotorController::StopMotor(TimerHandle_t xTimer) { nrf_gpio_pin_set(PinMap::Motor); } diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index b5a592b1..6dea6d1f 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -1,5 +1,7 @@ #pragma once +#include <FreeRTOS.h> +#include <timers.h> #include <cstdint> namespace Pinetime { @@ -15,8 +17,10 @@ namespace Pinetime { void StopRinging(); private: - static void Ring(void* p_context); - static void StopMotor(void* p_context); + static void Ring(TimerHandle_t xTimer); + static void StopMotor(TimerHandle_t xTimer); + TimerHandle_t shortVib; + TimerHandle_t longVib; }; } } |
