diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-04-17 11:10:44 (GMT) |
|---|---|---|
| committer | Michele Bini <michele.bini@gmail.com> | 2022-04-17 13:12:52 (GMT) |
| commit | 50b5b2ccb716a4a5c5b409962424a2441c9435e7 (patch) | |
| tree | 81b7ec7950a595cbefab6b4954171bf4b6d498bf /src/components/motor/MotorController.cpp | |
| parent | 94db51bba103c6b70475209c05a10911f4a005c7 (diff) | |
Switch MotorController and TimerController to FreeRTOS timers
Diffstat (limited to 'src/components/motor/MotorController.cpp')
| -rw-r--r-- | src/components/motor/MotorController.cpp | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index c794a02..4c44fc4 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -12,32 +12,33 @@ 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); + shortVibTimer = xTimerCreate("shortVibTm", 1, pdFALSE, nullptr, StopMotor); + longVibTimer = xTimerCreate("longVibTm", 1, 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)); + xTimerChangePeriod(motorController->longVibTimer, APP_TIMER_TICKS(1000), 0); 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(shortVibTimer, APP_TIMER_TICKS(motorDuration), 0) == pdPASS && xTimerStart(shortVibTimer, 0) == pdPASS) { + nrf_gpio_pin_clear(PinMap::Motor); + } } void MotorController::StartRinging() { - Ring(this); - app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this); + xTimerChangePeriod(longVibTimer, 1, 0); + xTimerStart(longVibTimer, 0); } void MotorController::StopRinging() { - app_timer_stop(longVibTimer); + xTimerStop(longVibTimer, 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); } |
