/* * 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 BSP::Time; // GPIOs static BSP::GpioDriver g_gpioa(GPIOA); static BSP::GpioPin g_dbg0(g_gpioa, 3); static BSP::GpioPin g_dbg1(g_gpioa, 6); static BSP::GpioPin g_tx(g_gpioa, 9); static BSP::GpioPin g_rx(g_gpioa, 10); static BSP::GpioPin g_btn_down(g_gpioa, 0); static BSP::GpioPin g_btn_mid(g_gpioa, 1); static BSP::GpioPin g_btn_up(g_gpioa, 2); static BSP::GpioPin g_nss(g_gpioa, 4); static BSP::GpioPin g_sck(g_gpioa, 5); static BSP::GpioPin g_mosi(g_gpioa, 12); static BSP::GpioPin g_extcomm(g_gpioa, 7); // Scheduler and Tasks static BSP::Schedule::LowPowerTaskScheduler<5> g_sched; static BSP::SpiDriver g_spi(g_sched, g_nss); static BSP::DisplayDriver g_display(g_sched, g_spi); static BSP::LptimPwm g_lptim_pwm(LPTIM1); static BSP::ButtonManager g_btn_manager( g_sched, g_btn_up, g_btn_mid, g_btn_down, Time::millis(200)); // Screens- contexts for the display static ScreenManager g_screen_manager(g_sched, g_display, g_btn_manager); static SetTimeScreen g_set_time_screen(g_display, g_screen_manager); static SetTimeScreen g_set_date_screen(g_display, g_screen_manager); static StopwatchScreen g_stopwatch_screen(g_display, g_screen_manager); static MenuScreen g_set_face_screen(g_display, g_screen_manager, "Face", std::initializer_list()); static MenuScreen g_settings_menu_screen(g_display, g_screen_manager, "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_manager, "Apps", std::initializer_list({MenuScreenItem("Stopwatch", g_stopwatch_screen)})); static MenuScreen g_main_menu_screen(g_display, g_screen_manager, "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_manager, g_main_menu_screen); static BigDigitalTimeScreen g_digital_time_screen(g_display, g_screen_manager, g_main_menu_screen); [[noreturn]] void main() { // Set up the system clock BSP::RtcDriver::init(); BSP::SystemTimer::set_timer(BSP::RtcDriver::get_system_timer()); BSP::LowPower::init(); // Initialize the tasks g_lptim_pwm.init(); g_spi.init(); g_btn_manager.init(); g_display.init(); g_screen_manager.init(); g_screen_manager.set_root_screen(g_analog_time_screen); g_set_face_screen.add_item(MenuScreenItem("Analog", []() { g_screen_manager.set_root_screen(g_analog_time_screen); })); g_set_face_screen.add_item(MenuScreenItem("Digital", []() { g_screen_manager.set_root_screen(g_digital_time_screen); })); // Enqueue each of the tasks BSP::Schedule::NextTime asap = BSP::Schedule::NextTime::asap(); g_sched.add_task(g_spi, asap); g_sched.add_task(g_btn_manager, asap); g_sched.add_task(g_display, asap); g_sched.add_task(g_screen_manager, asap); // And we're off! This will never return g_sched.run(); }