From 3555593c31d2e89c31df7978dd0de4d98117f2fd Mon Sep 17 00:00:00 2001 From: Thomas Klaehn Date: Thu, 9 Apr 2020 09:36:47 +0200 Subject: [PATCH] Add Sys_Tick example application --- .vscode/tasks.json | 26 ++++++++---------- src/application/sys_tick/main.cc | 47 ++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 src/application/sys_tick/main.cc diff --git a/.vscode/tasks.json b/.vscode/tasks.json index a1d2299..772f3d9 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,21 +1,25 @@ { - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format "version": "2.0.0", "options": { "env": { - "PLATFORM": "nrf52", - // "PLATFORM": "posix", "APPLICATION": "blinky", // "APPLICATION": "spi", // "APPLICATION": "st7789_lcd", + // "APPLICATION": "sys_tick", + "${BUILD_CMD}": "eval docker run --env PLATFORM=${PLATFORM} --env APPLICATION=${APPLICATION} -t --rm -v '${workspaceFolder}':/work --user $(id -u):$(id -g) arm-none-eabi.buildenv", }, }, + "presentation": { + "focus": true, + "reveal": "always", + "panel": "shared", + "clear": true, + }, "tasks": [ { "label": "all", "type":"shell", - "command": "make all -j8", + "command": "${BUILD_CMD} make all -j8", "problemMatcher": { "base": "$gcc", "owner": "gcc", @@ -49,7 +53,7 @@ { "label": "clean", "type":"shell", - "command": "make clean -j8", + "command": "${BUILD_CMD} make clean -j8", "problemMatcher": { "base": "$gcc", "owner": "gcc", @@ -66,7 +70,7 @@ { "label": "distclean", "type":"shell", - "command": "make distclean", + "command": "${BUILD_CMD} make distclean", "problemMatcher": { "base": "$gcc", "owner": "gcc", @@ -97,11 +101,5 @@ "isDefault": true } } - ], - "presentation": { - "focus": true, - "reveal": "always", - "panel": "shared", - "clear": true, - } + ] } diff --git a/src/application/sys_tick/main.cc b/src/application/sys_tick/main.cc new file mode 100644 index 0000000..10e47d8 --- /dev/null +++ b/src/application/sys_tick/main.cc @@ -0,0 +1,47 @@ +#include + +extern "C" { + #include "nrf52.h" +} + +#include "platform/nrf52/gpio.h" +#include "platform/nrf52/InterruptHandler.h" +#include "platform/nrf52/InterruptGuardian.h" +#include "platform/cm4/SystemTick.h" + +using namespace pinetime::platform::nrf52; + +enum { + PIN_NUMBER_LED_1 = 17, + PIN_NUMBER_LED_2 = 18, + PIN_NUMBER_LED_3 = 19, + PIN_NUMBER_LED_4 = 20 +}; + +Gpio led_1(PIN_NUMBER_LED_1); +Gpio led_2(PIN_NUMBER_LED_2); +Gpio led_3(PIN_NUMBER_LED_3); +Gpio led_4(PIN_NUMBER_LED_4); + +std::array leds = {&led_1, &led_2, &led_3, &led_4}; + +InterruptGuardian InterruptGuardian::instance; + +pinetime::platform::cm4::SystemTick ticker; + +int main(void) +{ + ticker.enable(); + uint32_t last_tick = 0; + while(true) { + for(auto it = std::begin(leds); it != std::end(leds); ++it) { + uint32_t tick = ticker.tick() / 1000; + if(tick != last_tick) { + Gpio * tmp = *it; + tmp->toggle(); + } + last_tick = tick; + } + } + return 0; +}