From fbb77baa3b6e487f4c68e08770499cb893c4e035 Mon Sep 17 00:00:00 2001 From: jlukanc <27705324+jlukanc1@users.noreply.github.com> Date: Fri, 15 Jan 2021 22:11:53 -0500 Subject: add non-blocking motor controller --- src/components/motor/MotorController.cpp | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/components/motor/MotorController.cpp (limited to 'src/components/motor/MotorController.cpp') diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp new file mode 100644 index 00000000..1885f7bd --- /dev/null +++ b/src/components/motor/MotorController.cpp @@ -0,0 +1,40 @@ +#include "MotorController.h" +#include +#include "systemtask/SystemTask.h" +#include "app_timer.h" +#include "nrf_drv_clock.h" + +APP_TIMER_DEF(vibTimer); + +using namespace Pinetime::Controllers; + +static void lfclk_request(void) //get the low freq. clock +{ + nrf_drv_clock_init(); + nrf_drv_clock_lfclk_request(NULL); +} + +void vibrateTimer(void * p_context) +{ + nrf_gpio_pin_set(pinMotor); +} + +static void create_timers() +{ + //create timer, single shot, re-armable + app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrateTimer); +} + +void MotorController::Init() { + nrf_gpio_cfg_output(pinMotor); // set the motor pin as an output + nrf_gpio_pin_set(pinMotor); + lfclk_request(); //get lfclock ready + app_timer_init(); //start app timers to make calls + create_timers(); +} + +void MotorController::SetDuration(uint8_t motorDuration) { + nrf_gpio_pin_clear(pinMotor); + //start timer for motorDuration miliseconds + app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL); //timers trigger at end of duration? +} \ No newline at end of file -- cgit v1.2.3 From bf7d77bd341de7360d7e4331ee088dc7a72620fc Mon Sep 17 00:00:00 2001 From: jlukanc <27705324+jlukanc1@users.noreply.github.com> Date: Sat, 23 Jan 2021 15:15:42 -0500 Subject: remove unneeded defines --- src/components/motor/MotorController.cpp | 1 - src/components/motor/MotorController.h | 39 +------------------------------- 2 files changed, 1 insertion(+), 39 deletions(-) (limited to 'src/components/motor/MotorController.cpp') diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index 1885f7bd..738e6d33 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -4,7 +4,6 @@ #include "app_timer.h" #include "nrf_drv_clock.h" -APP_TIMER_DEF(vibTimer); using namespace Pinetime::Controllers; diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index 63bc9580..01fe9304 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -10,45 +10,8 @@ namespace Pinetime { public: void Init(); void SetDuration(uint8_t motorDuration); - #ifndef NRF_CLOCK_ENABLED - #define NRF_CLOCK_ENABLED 1 - #endif - #ifndef CLOCK_CONFIG_LF_SRC - #define CLOCK_CONFIG_LF_SRC 1 - #endif - - #ifndef CLOCK_CONFIG_IRQ_PRIORITY - #define CLOCK_CONFIG_IRQ_PRIORITY 6 - #endif - - #define APP_TIMER_ENABLED 1 - #define APP_TIMER_CONFIG_RTC_FREQUENCY 15 //2048hz - #define APP_TIMER_CONFIG_IRQ_PRIORITY 6 - - #ifndef APP_TIMER_CONFIG_OP_QUEUE_SIZE - #define APP_TIMER_CONFIG_OP_QUEUE_SIZE 10 - #endif - - #ifndef APP_TIMER_CONFIG_USE_SCHEDULER - #define APP_TIMER_CONFIG_USE_SCHEDULER 0 - #endif - - #ifndef APP_TIMER_KEEPS_RTC_ACTIVE - #define APP_TIMER_KEEPS_RTC_ACTIVE 0 - #endif - - #ifndef APP_TIMER_SAFE_WINDOW_MS - #define APP_TIMER_SAFE_WINDOW_MS 300000 - #endif - - #ifndef APP_TIMER_WITH_PROFILER - #define APP_TIMER_WITH_PROFILER 0 - #endif - - #ifndef APP_TIMER_CONFIG_SWI_NUMBER - #define APP_TIMER_CONFIG_SWI_NUMBER 0 - #endif + APP_TIMER_DEF(vibTimer); private: -- cgit v1.2.3 From f27e63290639ca257e88298b60429d72271c4954 Mon Sep 17 00:00:00 2001 From: jlukanc <27705324+jlukanc1@users.noreply.github.com> Date: Mon, 25 Jan 2021 12:44:58 -0500 Subject: move app timer def --- src/components/motor/MotorController.cpp | 3 ++- src/components/motor/MotorController.h | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/components/motor/MotorController.cpp') diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index 738e6d33..51a01b4c 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -4,6 +4,7 @@ #include "app_timer.h" #include "nrf_drv_clock.h" +APP_TIMER_DEF(vibTimer); using namespace Pinetime::Controllers; @@ -36,4 +37,4 @@ void MotorController::SetDuration(uint8_t motorDuration) { nrf_gpio_pin_clear(pinMotor); //start timer for motorDuration miliseconds app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL); //timers trigger at end of duration? -} \ No newline at end of file +} diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index 01fe9304..52ab558c 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -1,6 +1,7 @@ #pragma once #include +#include "app_timer.h" namespace Pinetime { namespace Controllers { @@ -11,10 +12,8 @@ namespace Pinetime { void Init(); void SetDuration(uint8_t motorDuration); - APP_TIMER_DEF(vibTimer); - private: - + app_timer_id_t vibTimer; }; } -} \ No newline at end of file +} -- cgit v1.2.3 From 7ab153cd7690db8a43bde1af792edecc5e0f8d5d Mon Sep 17 00:00:00 2001 From: petter <39340152+petterhs@users.noreply.github.com> Date: Fri, 5 Feb 2021 17:06:56 +0100 Subject: refactor MotorController --- src/components/motor/MotorController.cpp | 33 +++++++++----------------------- src/components/motor/MotorController.h | 1 + 2 files changed, 10 insertions(+), 24 deletions(-) (limited to 'src/components/motor/MotorController.cpp') diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index 51a01b4c..7f53fbf7 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -2,39 +2,24 @@ #include #include "systemtask/SystemTask.h" #include "app_timer.h" -#include "nrf_drv_clock.h" APP_TIMER_DEF(vibTimer); using namespace Pinetime::Controllers; -static void lfclk_request(void) //get the low freq. clock -{ - nrf_drv_clock_init(); - nrf_drv_clock_lfclk_request(NULL); -} - -void vibrateTimer(void * p_context) -{ - nrf_gpio_pin_set(pinMotor); -} - -static void create_timers() -{ - //create timer, single shot, re-armable - app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrateTimer); -} - void MotorController::Init() { - nrf_gpio_cfg_output(pinMotor); // set the motor pin as an output + nrf_gpio_cfg_output(pinMotor); nrf_gpio_pin_set(pinMotor); - lfclk_request(); //get lfclock ready - app_timer_init(); //start app timers to make calls - create_timers(); + app_timer_init(); + app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate); } void MotorController::SetDuration(uint8_t motorDuration) { nrf_gpio_pin_clear(pinMotor); - //start timer for motorDuration miliseconds - app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL); //timers trigger at end of duration? + /* Start timer for motorDuration miliseconds and timer triggers vibrate() when it finishes*/ + app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL); } + +void MotorController::vibrate(void * p_context) { + nrf_gpio_pin_set(pinMotor); +} \ No newline at end of file diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index 9ce91c52..bdc20c0c 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -13,6 +13,7 @@ namespace Pinetime { void SetDuration(uint8_t motorDuration); private: + static void vibrate(void * p_context); }; } } -- cgit v1.2.3