From c8941003bbfb5624cc41434f1c803d237fdcfac8 Mon Sep 17 00:00:00 2001 From: Thomas Klaehn Date: Sun, 26 Apr 2020 08:57:43 +0200 Subject: [PATCH] Add button application --- src/application/button/main.cc | 71 ++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/application/button/main.cc diff --git a/src/application/button/main.cc b/src/application/button/main.cc new file mode 100644 index 0000000..c275b06 --- /dev/null +++ b/src/application/button/main.cc @@ -0,0 +1,71 @@ +#include + +#include "virtual_timer/VirtualTimerDistributor.h" + +#include "platform/cm4/InterruptHandler.h" +#include "platform/cm4/InterruptGuardian.h" +#include "platform/cm4/SystemTick.h" + +#include "platform/nrf52/gpio.h" +#include "platform/nrf52/gpiote.h" +#include "platform/nrf52/InterruptHandler.h" +#include "platform/nrf52/InterruptGuardian.h" + +#include "gpio_interface.h" +#include "delay.h" + +using namespace pinetime::platform; +using namespace pinetime::virtual_timer; + +// IRQs +nrf52::InterruptGuardian nrf52::InterruptGuardian::instance; +cm4::InterruptGuardian cm4::InterruptGuardian::instance; + +// GPIO events +nrf52::Gpiote gpiote; + +// Timer +cm4::SystemTick system_tick; +VirtualTimerDistributor virtual_timer_distributor(system_tick.instance()); +pinetime::Delay delay; + + +enum { + PIN_NUMBER_BUTTON_1 = 13, + PIN_NUMBER_BUTTON_2 = 14, + PIN_NUMBER_BUTTON_3 = 15, + PIN_NUMBER_BUTTON_4 = 16, + PIN_NUMBER_LED_1 = 17, + PIN_NUMBER_LED_2 = 18, + PIN_NUMBER_LED_3 = 19, + PIN_NUMBER_LED_4 = 20 +}; + +// LEDs +nrf52::Gpio led_1(PIN_NUMBER_LED_1); +nrf52::Gpio led_2(PIN_NUMBER_LED_2); +nrf52::Gpio led_3(PIN_NUMBER_LED_3); +nrf52::Gpio led_4(PIN_NUMBER_LED_4); +std::array leds = {&led_1, &led_2, &led_3, &led_4}; + +// Buttons +nrf52::Gpio button_1(PIN_NUMBER_BUTTON_1); +nrf52::Gpio button_2(PIN_NUMBER_BUTTON_2); +nrf52::Gpio button_3(PIN_NUMBER_BUTTON_3); +nrf52::Gpio button_4(PIN_NUMBER_BUTTON_4); + +int main(void) +{ + button_1.set_direction(pinetime::interfaces::GpioInterface::direction::IN, true); + cm4::InterruptGuardian::enable_interrupts(); + while(true) { + for(auto it = leds.begin(); it != leds.end(); ++it) { + uint32_t b1 = button_1.get(); + if(b1) { + nrf52::Gpio * led = *it; + led->toggle(); + } + } + } + return 0; +}