/* * Copyright (C) 2019 Max Regan * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "Bsp/LowPowerTaskScheduler.h" #include "Bsp/Drivers/RtcDriver.h" #include "Bsp/Drivers/DisplayDriver.h" #include "Bsp/Drivers/SpiDriver.h" #include "Bsp/Drivers/LptimPwm.h" #include "Application/ButtonManager.h" #include "Application/ScreenManager.h" #include "Application/Screens/AnalogTimeScreen.h" #include "Application/Screens/BigDigitalTimeScreen.h" #include "Application/Screens/DebugScreen.h" #include "Application/Screens/MenuScreen.h" #include "Application/Screens/SetTimeScreen.h" #include "Application/Screens/SetDateScreen.h" #include "Application/Screens/StopwatchScreen.h" #include "Bsp/macros.h" #include "Mcu.h" using namespace BSP; // GPIOs static GpioDriver g_gpioa(GPIOA); static GpioPin g_dbg0(g_gpioa, 3); static GpioPin g_dbg1(g_gpioa, 6); static GpioPin g_tx(g_gpioa, 9); static GpioPin g_rx(g_gpioa, 10); static GpioPin g_btn_down(g_gpioa, 0); static GpioPin g_btn_mid(g_gpioa, 1); static GpioPin g_btn_up(g_gpioa, 2); static GpioPin g_nss(g_gpioa, 4); static GpioPin g_sck(g_gpioa, 5); static GpioPin g_mosi(g_gpioa, 12); static GpioPin g_extcomm(g_gpioa, 7); // Scheduler and Tasks static Schedule::LowPowerTaskScheduler<5> g_sched; static SpiDriver g_spi(g_sched, g_nss); static DisplayDriver g_display(g_sched, g_spi); static LptimPwm g_lptim_pwm(LPTIM1); static ButtonManager g_btn_mgr( g_sched, g_btn_up, g_btn_mid, g_btn_down, Time::millis(200)); // Screens- contexts for the display static ScreenManager g_screen_mgr(g_sched, g_display, g_btn_mgr); static SetTimeScreen g_set_time_screen(g_display, g_screen_mgr); static SetTimeScreen g_set_date_screen(g_display, g_screen_mgr); static StopwatchScreen g_stopwatch_screen(g_display, g_screen_mgr); static MenuScreen g_set_face_screen(g_display, g_screen_mgr, "Face", std::initializer_list()); static MenuScreen g_settings_menu_screen(g_display, g_screen_mgr, "Settings", std::initializer_list( { MenuScreenItem("Set Time", g_set_time_screen), MenuScreenItem("Set Date", g_set_date_screen), MenuScreenItem("Set Face", g_set_face_screen) })); static MenuScreen g_apps_menu_screen(g_display, g_screen_mgr, "Apps", std::initializer_list({MenuScreenItem("Stopwatch", g_stopwatch_screen)})); static MenuScreen g_main_menu_screen(g_display, g_screen_mgr, "Main Menu", std::initializer_list( { MenuScreenItem("Apps", g_apps_menu_screen), MenuScreenItem("Settings", g_settings_menu_screen) })); static AnalogTimeScreen g_analog_time_screen(g_display, g_screen_mgr, g_main_menu_screen); static BigDigitalTimeScreen g_digital_time_screen(g_display, g_screen_mgr, g_main_menu_screen); [[noreturn]] void main() { // Set up the system clock RtcDriver::init(); SystemTimer::set_timer(RtcDriver::get_system_timer()); LowPower::init(); // Initialize the tasks g_lptim_pwm.init(); g_spi.init(); g_btn_mgr.init(); g_display.init(); g_screen_mgr.init(); g_screen_mgr.set_root_screen(g_analog_time_screen); g_set_face_screen.add_item(MenuScreenItem("Analog", []() { g_screen_mgr.set_root_screen(g_analog_time_screen); })); g_set_face_screen.add_item(MenuScreenItem("Digital", []() { g_screen_mgr.set_root_screen(g_digital_time_screen); })); // Enqueue each of the tasks Schedule::NextTime asap = Schedule::NextTime::asap(); g_sched.add_task(g_spi, asap); g_sched.add_task(g_btn_mgr, asap); g_sched.add_task(g_display, asap); g_sched.add_task(g_screen_mgr, asap); // And we're off! This will never return g_sched.run(); }