summaryrefslogtreecommitdiff
path: root/src/components/motor/MotorController.cpp
diff options
context:
space:
mode:
authorjlukanc <27705324+jlukanc1@users.noreply.github.com>2021-01-16 03:11:53 (GMT)
committerjlukanc <27705324+jlukanc1@users.noreply.github.com>2021-01-16 03:11:53 (GMT)
commitfbb77baa3b6e487f4c68e08770499cb893c4e035 (patch)
tree54b0606373dc4b281071ea49643744848c54c1ed /src/components/motor/MotorController.cpp
parent50ae0ae5e073ac48652e6c26549f9b19655e8da3 (diff)
add non-blocking motor controller
Diffstat (limited to 'src/components/motor/MotorController.cpp')
-rw-r--r--src/components/motor/MotorController.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp
new file mode 100644
index 0000000..1885f7b
--- /dev/null
+++ b/src/components/motor/MotorController.cpp
@@ -0,0 +1,40 @@
+#include "MotorController.h"
+#include <hal/nrf_gpio.h>
+#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