refactor tree, add ecad, mcad
This commit is contained in:
@@ -27,8 +27,8 @@
|
||||
|
||||
namespace BSP {
|
||||
|
||||
using Common::ReturnCode;
|
||||
using Common::Schedule::NextTime;
|
||||
using BSP::ReturnCode;
|
||||
using BSP::Schedule::NextTime;
|
||||
|
||||
ButtonManager *ButtonManager::m_instance = nullptr;
|
||||
|
||||
@@ -67,8 +67,8 @@ ReturnCode ButtonManager::init()
|
||||
|
||||
NextTime ButtonManager::execute()
|
||||
{
|
||||
Common::time_t systime;
|
||||
Common::time_t endtime = 0;
|
||||
BSP::time_t systime;
|
||||
BSP::time_t endtime = 0;
|
||||
BSP::SystemTimer::get_time(systime);
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ void ButtonManager::remove_callback(Button btn)
|
||||
void ButtonManager::irq()
|
||||
{
|
||||
uint32_t idr = GPIOA->IDR;
|
||||
static Common::time_t systime;
|
||||
static BSP::time_t systime;
|
||||
|
||||
// TODO: is this call too expensive for an interrupt handler?
|
||||
BSP::SystemTimer::get_time(systime);
|
||||
|
||||
@@ -29,13 +29,13 @@
|
||||
|
||||
namespace BSP {
|
||||
|
||||
class ButtonManager : public Common::Schedule::Task {
|
||||
class ButtonManager : public BSP::Schedule::Task {
|
||||
public:
|
||||
ButtonManager(Common::Schedule::TaskScheduler &scheduler,
|
||||
ButtonManager(BSP::Schedule::TaskScheduler &scheduler,
|
||||
uint8_t up_gpio_idx,
|
||||
uint8_t mid_gpio_idx,
|
||||
uint8_t down_gpio_idx,
|
||||
Common::time_t debounce_time)
|
||||
BSP::time_t debounce_time)
|
||||
: m_scheduler(scheduler)
|
||||
, m_buttons
|
||||
{
|
||||
@@ -66,9 +66,9 @@ public:
|
||||
|
||||
using ChangeCallback = std::function<void(ButtonState)>;
|
||||
|
||||
Common::Schedule::NextTime execute() override;
|
||||
BSP::Schedule::NextTime execute() override;
|
||||
|
||||
Common::ReturnCode init();
|
||||
BSP::ReturnCode init();
|
||||
void set_callback(Button btn, ChangeCallback callback);
|
||||
void remove_callback(Button btn);
|
||||
|
||||
@@ -79,7 +79,7 @@ private:
|
||||
struct button_state {
|
||||
|
||||
button_state(uint8_t gpio_index,
|
||||
Common::time_t debounce_time,
|
||||
BSP::time_t debounce_time,
|
||||
ChangeCallback callback)
|
||||
: m_gpio_idx(gpio_index)
|
||||
, m_debounce_time(debounce_time)
|
||||
@@ -88,15 +88,15 @@ private:
|
||||
, m_callback(callback)
|
||||
{}
|
||||
uint8_t const m_gpio_idx;
|
||||
Common::time_t const m_debounce_time;
|
||||
BSP::time_t const m_debounce_time;
|
||||
|
||||
ButtonState m_prev_call_state; /*<! The last state the button was in when it the callback was called */
|
||||
ButtonState m_state; /*<! The state the button was in during the last iteration */
|
||||
Common::time_t m_state_change_ts; /*<! The system time when the button entered its current state */
|
||||
BSP::time_t m_state_change_ts; /*<! The system time when the button entered its current state */
|
||||
ChangeCallback m_callback; /*<! The callback to call when the button has changed states (post-debounce) */
|
||||
};
|
||||
|
||||
Common::Schedule::TaskScheduler &m_scheduler;
|
||||
BSP::Schedule::TaskScheduler &m_scheduler;
|
||||
button_state m_buttons[Button::Count];
|
||||
|
||||
static void nop_callback(ButtonState) {};
|
||||
|
||||
@@ -24,11 +24,11 @@
|
||||
|
||||
// TODO: Basically all of the error checking
|
||||
|
||||
using Common::Schedule::Task;
|
||||
using Common::Schedule::NextTime;
|
||||
using Common::ReturnCode;
|
||||
using BSP::Schedule::Task;
|
||||
using BSP::Schedule::NextTime;
|
||||
using BSP::ReturnCode;
|
||||
|
||||
ScreenManager::ScreenManager(Common::Schedule::TaskScheduler &scheduler,
|
||||
ScreenManager::ScreenManager(BSP::Schedule::TaskScheduler &scheduler,
|
||||
BSP::DisplayDriver &display,
|
||||
BSP::ButtonManager &buttons)
|
||||
: m_scheduler(scheduler)
|
||||
|
||||
@@ -31,21 +31,21 @@
|
||||
#include "Application/ButtonManager.h"
|
||||
#include "Application/Screens/Screen.h"
|
||||
|
||||
class ScreenManager : public Common::Schedule::Task {
|
||||
class ScreenManager : public BSP::Schedule::Task {
|
||||
public:
|
||||
|
||||
ScreenManager(Common::Schedule::TaskScheduler &scheduler,
|
||||
ScreenManager(BSP::Schedule::TaskScheduler &scheduler,
|
||||
BSP::DisplayDriver &display,
|
||||
BSP::ButtonManager &buttons);
|
||||
|
||||
Common::ReturnCode init();
|
||||
Common::ReturnCode set_root_screen(Screen &screen);
|
||||
BSP::ReturnCode init();
|
||||
BSP::ReturnCode set_root_screen(Screen &screen);
|
||||
|
||||
Common::Schedule::NextTime execute() override;
|
||||
BSP::Schedule::NextTime execute() override;
|
||||
|
||||
Common::ReturnCode pop_screen();
|
||||
Common::ReturnCode push_screen(Screen &screen);
|
||||
Common::ReturnCode set_screen(Screen &screen);
|
||||
BSP::ReturnCode pop_screen();
|
||||
BSP::ReturnCode push_screen(Screen &screen);
|
||||
BSP::ReturnCode set_screen(Screen &screen);
|
||||
|
||||
private:
|
||||
|
||||
@@ -58,7 +58,7 @@ private:
|
||||
|
||||
static constexpr std::size_t MAX_SCREEN_STACK = 5;
|
||||
|
||||
Common::Schedule::TaskScheduler &m_scheduler;
|
||||
BSP::Schedule::TaskScheduler &m_scheduler;
|
||||
|
||||
std::array<Screen *, MAX_SCREEN_STACK> m_screen_stack;
|
||||
std::size_t m_screen_stack_depth;
|
||||
|
||||
191
firmware/Application/Screens/AnalogTimeScreen.cpp
Normal file
191
firmware/Application/Screens/AnalogTimeScreen.cpp
Normal file
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
* 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 <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include "Application/Screens/AnalogTimeScreen.h"
|
||||
#include "Application/SystemFonts.h"
|
||||
#include "Bsp/Drivers/RtcDriver.h"
|
||||
#include "Bsp/SystemTime.h"
|
||||
#include "Bsp/Drivers/LowPower.h"
|
||||
|
||||
using BSP::ReturnCode;
|
||||
using BSP::Time;
|
||||
using BSP::Schedule::NextTime;
|
||||
using Color = BSP::DisplayDriver::Color;
|
||||
|
||||
// TODO: remove all calls to std::cos and std::sin?
|
||||
|
||||
AnalogTimeScreen::AnalogTimeScreen(BSP::DisplayDriver &driver,
|
||||
ScreenManager &manager,
|
||||
Screen &menu_screen)
|
||||
: m_driver(driver)
|
||||
, m_last_time()
|
||||
, m_manager(manager)
|
||||
, m_menu_screen(menu_screen)
|
||||
, m_display_seconds(true)
|
||||
{}
|
||||
|
||||
ReturnCode AnalogTimeScreen::init()
|
||||
{
|
||||
return ReturnCode::OK;
|
||||
}
|
||||
|
||||
void AnalogTimeScreen::draw_ticks() {
|
||||
|
||||
// After profiling, using lookup tables is 6-10% faster than using std::sin & std::cos.
|
||||
static constexpr float sin_tbl[8] = {
|
||||
0.0,
|
||||
0.10452539173303049,
|
||||
0.20790564888802265,
|
||||
0.30900818248165035,
|
||||
0.4067253572759511,
|
||||
0.4999866265466325,
|
||||
0.5877702605258084,
|
||||
0.6691145400274635,
|
||||
};
|
||||
|
||||
static constexpr float cos_tbl[8] = {
|
||||
1.0,
|
||||
0.9945222181947755,
|
||||
0.9781488849661131,
|
||||
0.9510593794077146,
|
||||
0.9135504823209005,
|
||||
0.8660331248136633,
|
||||
0.8090278863187741,
|
||||
0.7431592913526923,
|
||||
};
|
||||
|
||||
const uint32_t y_center = m_driver.get_height() / 2;
|
||||
const uint32_t x_center = m_driver.get_width() / 2;
|
||||
const uint32_t radius = std::min(m_driver.get_width(), m_driver.get_height()) / 2;
|
||||
|
||||
// This only works for square screens, but saves a a bunch of float math and calls to trig functions
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
const uint32_t len = (i % 5 == 0) ? 10 : 5;
|
||||
const uint32_t width = (i % 5 == 0) ? 3 : 1;
|
||||
const uint32_t end1_offset = sin_tbl[i] * radius;
|
||||
const uint32_t end2_offset = cos_tbl[i] * radius;
|
||||
const uint32_t start1_offset = sin_tbl[i] * (radius - len);
|
||||
const uint32_t start2_offset = cos_tbl[i] * (radius - len);
|
||||
|
||||
m_driver.draw_line(x_center + start1_offset, y_center + start2_offset,
|
||||
x_center + end1_offset, y_center + end2_offset,
|
||||
Color::BLACK, width);
|
||||
m_driver.draw_line(x_center - start1_offset, y_center + start2_offset,
|
||||
x_center - end1_offset, y_center + end2_offset,
|
||||
Color::BLACK, width);
|
||||
m_driver.draw_line(x_center + start1_offset, y_center - start2_offset,
|
||||
x_center + end1_offset, y_center - end2_offset,
|
||||
Color::BLACK, width);
|
||||
m_driver.draw_line(x_center - start1_offset, y_center - start2_offset,
|
||||
x_center - end1_offset, y_center - end2_offset,
|
||||
Color::BLACK, width);
|
||||
|
||||
m_driver.draw_line(x_center + start2_offset, y_center + start1_offset,
|
||||
x_center + end2_offset, y_center + end1_offset,
|
||||
Color::BLACK, width);
|
||||
m_driver.draw_line(x_center - start2_offset, y_center + start1_offset,
|
||||
x_center - end2_offset, y_center + end1_offset,
|
||||
Color::BLACK, width);
|
||||
m_driver.draw_line(x_center + start2_offset, y_center - start1_offset,
|
||||
x_center + end2_offset, y_center - end1_offset,
|
||||
Color::BLACK, width);
|
||||
m_driver.draw_line(x_center - start2_offset, y_center - start1_offset,
|
||||
x_center - end2_offset, y_center - end1_offset,
|
||||
Color::BLACK, width);
|
||||
}
|
||||
}
|
||||
|
||||
void AnalogTimeScreen::draw_hand(uint32_t ticks, uint32_t len, int32_t width, Color color) {
|
||||
|
||||
const uint32_t y_center = m_driver.get_height() / 2;
|
||||
const uint32_t x_center = m_driver.get_width() / 2;
|
||||
|
||||
uint32_t x_end = x_center + std::sin(ticks * TURNS_PER_TICK) * len;
|
||||
uint32_t y_end = y_center - std::cos(ticks * TURNS_PER_TICK) * len;
|
||||
|
||||
m_driver.draw_line(x_center, y_center, x_end, y_end, color, width);
|
||||
}
|
||||
|
||||
void AnalogTimeScreen::display_time()
|
||||
{
|
||||
BSP::WallClockTime time;
|
||||
BSP::RtcDriver::get_time(time);
|
||||
|
||||
m_driver.clear(Color::WHITE);
|
||||
|
||||
draw_ticks();
|
||||
|
||||
const uint32_t seconds_len = std::min(m_driver.get_width(), m_driver.get_height()) * 9 / 20;
|
||||
const uint32_t minutes_len = std::min(m_driver.get_width(), m_driver.get_height()) * 17 / 40;
|
||||
const uint32_t hours_len = std::min(m_driver.get_width(), m_driver.get_height()) * 6 / 20;
|
||||
|
||||
draw_hand(time.get_hours_12() * 5, hours_len, 3, Color::BLACK);
|
||||
draw_hand(time.get_minutes(), minutes_len, 3, Color::BLACK);
|
||||
|
||||
if (m_display_seconds) {
|
||||
draw_hand(time.get_seconds(), seconds_len, 2, Color::RED);
|
||||
}
|
||||
|
||||
m_last_time = time;
|
||||
m_driver.refresh();
|
||||
}
|
||||
|
||||
NextTime AnalogTimeScreen::execute()
|
||||
{
|
||||
display_time();
|
||||
|
||||
BSP::time_t now;
|
||||
BSP::SystemTimer::get_time(now);
|
||||
if (m_display_seconds) {
|
||||
return NextTime::in(Time::seconds(1));
|
||||
} else {
|
||||
|
||||
BSP::WallClockTime wall_time;
|
||||
BSP::RtcDriver::get_time(wall_time);
|
||||
return NextTime::in(Time::seconds(61 - wall_time.get_seconds()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AnalogTimeScreen::enable() {
|
||||
m_last_time = {};
|
||||
display_time();
|
||||
}
|
||||
|
||||
void AnalogTimeScreen::disable() {
|
||||
}
|
||||
|
||||
void AnalogTimeScreen::notify_up_button() {
|
||||
/* TODO: This should open a menu first */
|
||||
m_manager.push_screen(m_menu_screen);
|
||||
}
|
||||
|
||||
void AnalogTimeScreen::notify_middle_button() {
|
||||
|
||||
}
|
||||
|
||||
void AnalogTimeScreen::notify_down_button() {
|
||||
|
||||
}
|
||||
61
firmware/Application/Screens/AnalogTimeScreen.h
Normal file
61
firmware/Application/Screens/AnalogTimeScreen.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Bsp/macros.h"
|
||||
|
||||
#include "Application/ScreenManager.h"
|
||||
#include "Application/Screens/Screen.h"
|
||||
|
||||
class AnalogTimeScreen : public Screen {
|
||||
public:
|
||||
|
||||
AnalogTimeScreen(BSP::DisplayDriver &display,
|
||||
ScreenManager &m_manager,
|
||||
Screen &m_menu_screen);
|
||||
|
||||
BSP::ReturnCode init();
|
||||
BSP::Schedule::NextTime execute() override;
|
||||
|
||||
void enable() override;
|
||||
void disable() override;
|
||||
|
||||
void notify_up_button() override;
|
||||
void notify_middle_button() override;
|
||||
void notify_down_button() override;
|
||||
|
||||
private:
|
||||
|
||||
static constexpr float TURNS_PER_TICK = 2 * 3.1415 / 60;
|
||||
|
||||
void draw_hand(uint32_t ticks, uint32_t len, int32_t width, BSP::DisplayDriver::Color color);
|
||||
void draw_ticks();
|
||||
void display_time();
|
||||
|
||||
BSP::DisplayDriver &m_driver;
|
||||
BSP::WallClockTime m_last_time;
|
||||
|
||||
ScreenManager &m_manager;
|
||||
Screen &m_menu_screen;
|
||||
|
||||
const bool m_display_seconds;
|
||||
};
|
||||
@@ -19,18 +19,18 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "Application/Screens/DisplayTimeScreen.h"
|
||||
#include "Application/Screens/BigDigitalTimeScreen.h"
|
||||
#include "Application/SystemFonts.h"
|
||||
#include "Bsp/Drivers/RtcDriver.h"
|
||||
#include "Bsp/SystemTime.h"
|
||||
#include "Bsp/Drivers/LowPower.h"
|
||||
|
||||
using Common::ReturnCode;
|
||||
using Common::Time;
|
||||
using Common::Schedule::NextTime;
|
||||
using BSP::ReturnCode;
|
||||
using BSP::Time;
|
||||
using BSP::Schedule::NextTime;
|
||||
using Color = BSP::DisplayDriver::Color;
|
||||
|
||||
DisplayTimeScreen::DisplayTimeScreen(BSP::DisplayDriver &driver,
|
||||
BigDigitalTimeScreen::BigDigitalTimeScreen(BSP::DisplayDriver &driver,
|
||||
ScreenManager &manager,
|
||||
Screen &menu_screen)
|
||||
: m_driver(driver)
|
||||
@@ -48,14 +48,12 @@ static char get_char_for_digit(uint8_t bcd_digit)
|
||||
return bcd_digit + '0';
|
||||
}
|
||||
|
||||
ReturnCode DisplayTimeScreen::init()
|
||||
ReturnCode BigDigitalTimeScreen::init()
|
||||
{
|
||||
SET(RCC->CFGR, RCC_CFGR_SW_HSI);
|
||||
|
||||
return ReturnCode::OK;
|
||||
}
|
||||
|
||||
void DisplayTimeScreen::display_number(uint32_t *x, uint32_t y, uint32_t tens, uint32_t ones, const struct font &f)
|
||||
void BigDigitalTimeScreen::display_number(uint32_t *x, uint32_t y, uint32_t tens, uint32_t ones, const struct font &f)
|
||||
{
|
||||
char time_str[3] = { 0 };
|
||||
|
||||
@@ -63,12 +61,12 @@ void DisplayTimeScreen::display_number(uint32_t *x, uint32_t y, uint32_t tens, u
|
||||
time_str[1] = get_char_for_digit(ones);
|
||||
time_str[2] = '\0';
|
||||
|
||||
m_driver.string_at(x, y, time_str, &f, Color::WHITE);
|
||||
m_driver.string_at(x, y, time_str, &f, Color::BLACK);
|
||||
}
|
||||
|
||||
void DisplayTimeScreen::display_time()
|
||||
void BigDigitalTimeScreen::display_time()
|
||||
{
|
||||
Common::WallClockTime time;
|
||||
BSP::WallClockTime time;
|
||||
BSP::RtcDriver::get_time(time);
|
||||
const struct font &font = font_large_digits;
|
||||
const uint32_t y_space = (m_driver.get_height() - (2 * font.height)) / 3;
|
||||
@@ -76,7 +74,7 @@ void DisplayTimeScreen::display_time()
|
||||
|
||||
uint32_t x = 0;
|
||||
|
||||
m_driver.clear(Color::BLACK);
|
||||
m_driver.clear(Color::WHITE);
|
||||
|
||||
x = x_space;
|
||||
display_number(&x, y_space,
|
||||
@@ -90,40 +88,40 @@ void DisplayTimeScreen::display_time()
|
||||
m_driver.refresh();
|
||||
}
|
||||
|
||||
NextTime DisplayTimeScreen::execute()
|
||||
NextTime BigDigitalTimeScreen::execute()
|
||||
{
|
||||
display_time();
|
||||
|
||||
Common::time_t now;
|
||||
BSP::time_t now;
|
||||
BSP::SystemTimer::get_time(now);
|
||||
if (m_display_seconds) {
|
||||
return NextTime::in(Time::seconds(1));
|
||||
} else {
|
||||
|
||||
Common::WallClockTime wall_time;
|
||||
BSP::WallClockTime wall_time;
|
||||
BSP::RtcDriver::get_time(wall_time);
|
||||
return NextTime::in(Time::seconds(61 - wall_time.get_seconds()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DisplayTimeScreen::enable() {
|
||||
void BigDigitalTimeScreen::enable() {
|
||||
m_last_time = {};
|
||||
display_time();
|
||||
}
|
||||
|
||||
void DisplayTimeScreen::disable() {
|
||||
void BigDigitalTimeScreen::disable() {
|
||||
}
|
||||
|
||||
void DisplayTimeScreen::notify_up_button() {
|
||||
void BigDigitalTimeScreen::notify_up_button() {
|
||||
/* TODO: This should open a menu first */
|
||||
m_manager.push_screen(m_menu_screen);
|
||||
}
|
||||
|
||||
void DisplayTimeScreen::notify_middle_button() {
|
||||
void BigDigitalTimeScreen::notify_middle_button() {
|
||||
|
||||
}
|
||||
|
||||
void DisplayTimeScreen::notify_down_button() {
|
||||
void BigDigitalTimeScreen::notify_down_button() {
|
||||
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
@@ -26,15 +26,15 @@
|
||||
#include "Application/ScreenManager.h"
|
||||
#include "Application/Screens/Screen.h"
|
||||
|
||||
class DisplayTimeScreen : public Screen {
|
||||
class BigDigitalTimeScreen : public Screen {
|
||||
public:
|
||||
|
||||
DisplayTimeScreen(BSP::DisplayDriver &display,
|
||||
ScreenManager &m_manager,
|
||||
Screen &m_menu_screen);
|
||||
BigDigitalTimeScreen(BSP::DisplayDriver &display,
|
||||
ScreenManager &m_manager,
|
||||
Screen &m_menu_screen);
|
||||
|
||||
Common::ReturnCode init();
|
||||
Common::Schedule::NextTime execute() override;
|
||||
BSP::ReturnCode init();
|
||||
BSP::Schedule::NextTime execute() override;
|
||||
|
||||
void enable() override;
|
||||
void disable() override;
|
||||
@@ -49,7 +49,7 @@ private:
|
||||
void display_number(uint32_t *x, uint32_t y, uint32_t tens, uint32_t ones, const font &f);
|
||||
|
||||
BSP::DisplayDriver &m_driver;
|
||||
Common::WallClockTime m_last_time;
|
||||
BSP::WallClockTime m_last_time;
|
||||
|
||||
ScreenManager &m_manager;
|
||||
Screen &m_menu_screen;
|
||||
@@ -39,8 +39,8 @@ public:
|
||||
, m_manager(manager)
|
||||
{}
|
||||
|
||||
Common::ReturnCode init() {
|
||||
return Common::ReturnCode::OK;
|
||||
BSP::ReturnCode init() {
|
||||
return BSP::ReturnCode::OK;
|
||||
}
|
||||
|
||||
void render() {
|
||||
@@ -58,9 +58,9 @@ public:
|
||||
m_driver.refresh();
|
||||
}
|
||||
|
||||
Common::Schedule::NextTime execute() override {
|
||||
BSP::Schedule::NextTime execute() override {
|
||||
render();
|
||||
return Common::Schedule::NextTime::never();
|
||||
return BSP::Schedule::NextTime::never();
|
||||
}
|
||||
|
||||
void enable() override {
|
||||
|
||||
@@ -124,12 +124,12 @@ public:
|
||||
m_driver.refresh();
|
||||
}
|
||||
|
||||
Common::ReturnCode init() {
|
||||
return Common::ReturnCode::OK;
|
||||
BSP::ReturnCode init() {
|
||||
return BSP::ReturnCode::OK;
|
||||
}
|
||||
|
||||
Common::Schedule::NextTime execute() override {
|
||||
return Common::Schedule::NextTime::never();
|
||||
BSP::Schedule::NextTime execute() override {
|
||||
return BSP::Schedule::NextTime::never();
|
||||
}
|
||||
|
||||
void enable() override {
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "Bsp/ReturnCode.h"
|
||||
#include "Bsp/Task.h"
|
||||
|
||||
class Screen : public Common::Schedule::Task {
|
||||
class Screen : public BSP::Schedule::Task {
|
||||
public:
|
||||
|
||||
virtual void enable() = 0;
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
#include "Bsp/SystemTime.h"
|
||||
#include "Bsp/Drivers/RtcDriver.h"
|
||||
|
||||
using Common::ReturnCode;
|
||||
using Common::Time;
|
||||
using Common::Schedule::NextTime;
|
||||
using BSP::ReturnCode;
|
||||
using BSP::Time;
|
||||
using BSP::Schedule::NextTime;
|
||||
|
||||
SetDateScreen::SetDateScreen(BSP::DisplayDriver &display,
|
||||
ScreenManager &manager)
|
||||
|
||||
@@ -36,8 +36,8 @@ public:
|
||||
SetDateScreen(BSP::DisplayDriver &display,
|
||||
ScreenManager &m_manager);
|
||||
|
||||
Common::ReturnCode init();
|
||||
Common::Schedule::NextTime execute() override;
|
||||
BSP::ReturnCode init();
|
||||
BSP::Schedule::NextTime execute() override;
|
||||
|
||||
void enable() override;
|
||||
void disable() override;
|
||||
@@ -70,7 +70,7 @@ private:
|
||||
|
||||
SetState m_state;
|
||||
bool m_is_acked = false;
|
||||
Common::WallClockTime m_time;
|
||||
BSP::WallClockTime m_time;
|
||||
const struct font &m_font;
|
||||
const uint32_t m_row_spacing;
|
||||
const uint32_t m_row_0_y;
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
#include "Bsp/SystemTime.h"
|
||||
#include "Bsp/Drivers/RtcDriver.h"
|
||||
|
||||
using Common::ReturnCode;
|
||||
using Common::Time;
|
||||
using Common::Schedule::NextTime;
|
||||
using BSP::ReturnCode;
|
||||
using BSP::Time;
|
||||
using BSP::Schedule::NextTime;
|
||||
|
||||
SetTimeScreen::SetTimeScreen(BSP::DisplayDriver &display,
|
||||
ScreenManager &manager)
|
||||
|
||||
@@ -36,8 +36,8 @@ public:
|
||||
SetTimeScreen(BSP::DisplayDriver &display,
|
||||
ScreenManager &m_manager);
|
||||
|
||||
Common::ReturnCode init();
|
||||
Common::Schedule::NextTime execute() override;
|
||||
BSP::ReturnCode init();
|
||||
BSP::Schedule::NextTime execute() override;
|
||||
|
||||
void enable() override;
|
||||
void disable() override;
|
||||
@@ -70,7 +70,7 @@ private:
|
||||
|
||||
SetState m_state;
|
||||
bool m_is_acked = false;
|
||||
Common::WallClockTime m_time;
|
||||
BSP::WallClockTime m_time;
|
||||
const struct font &m_font;
|
||||
const uint32_t m_row_spacing;
|
||||
const uint32_t m_row_0_y;
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
#include "Application/ButtonManager.h"
|
||||
|
||||
#include "Application/ScreenManager.h"
|
||||
#include "Application/Screens/DisplayTimeScreen.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"
|
||||
@@ -39,13 +40,13 @@
|
||||
// TODO: Don't include this here.
|
||||
#include "stm32l0xx.h"
|
||||
|
||||
using Common::Time;
|
||||
using BSP::Time;
|
||||
|
||||
static Common::Schedule::LowPowerTaskScheduler<5> g_sched;
|
||||
static BSP::Schedule::LowPowerTaskScheduler<5> g_sched;
|
||||
static BSP::SpiDriver g_spi(g_sched);
|
||||
static BSP::DisplayDriver g_display(g_sched, g_spi);
|
||||
static BSP::LptimPwm g_lptim_pwm(LPTIM1);
|
||||
static BSP::ButtonManager g_btn_manager(g_sched, 2, 1, 0, Time::millis(1));
|
||||
static BSP::ButtonManager g_btn_manager(g_sched, 0, 1, 2, Time::millis(1));
|
||||
|
||||
static ScreenManager g_screen_manager(g_sched, g_display, g_btn_manager);
|
||||
static SetTimeScreen g_set_time_screen(g_display, g_screen_manager);
|
||||
@@ -72,7 +73,7 @@ static MenuScreen g_main_menu_screen(g_display,
|
||||
std::initializer_list<MenuScreenItem>({MenuScreenItem("Apps", g_settings_menu_screen),
|
||||
MenuScreenItem("Settings", g_settings_menu_screen)}));
|
||||
|
||||
static DisplayTimeScreen g_display_time_screen(g_display, g_screen_manager, g_main_menu_screen);
|
||||
static AnalogTimeScreen g_display_time_screen(g_display, g_screen_manager, g_main_menu_screen);
|
||||
|
||||
extern "C" void __cxa_pure_virtual() { while(1) {} }
|
||||
|
||||
@@ -121,7 +122,45 @@ void SystemInit()
|
||||
|
||||
/*!< Reset HSEBYP bit (disable HSE bypass) */
|
||||
CLR(RCC->CR,
|
||||
RCC_CR_HSEBYP);
|
||||
RCC_CR_HSEBYP)
|
||||
;
|
||||
|
||||
/* (1) Test if PLL is used as System clock */
|
||||
/* (2) Select HSI as system clock */
|
||||
/* (3) Wait for HSI switched */
|
||||
/* (4) Disable the PLL */
|
||||
/* (5) Wait until PLLRDY is cleared */
|
||||
/* (6) Set latency to 1 wait state */
|
||||
/* (7) Set the PLL multiplier to 24 and divider by 3 */
|
||||
/* (8) Enable the PLL */
|
||||
/* (9) Wait until PLLRDY is set */
|
||||
/* (10) Select PLL as system clock */
|
||||
/* (11) Wait until the PLL is switched on */
|
||||
|
||||
// SET(RCC->CR, RCC_CR_HSION);
|
||||
// while((RCC->CR & RCC_CR_HSIRDY) != 0) {}
|
||||
|
||||
// if ((RCC->CFGR & RCC_CFGR_SWS) == RCC_CFGR_SWS_PLL) /* (1) */
|
||||
// {
|
||||
// RCC->CFGR = (RCC->CFGR & (uint32_t) (~RCC_CFGR_SW)) | RCC_CFGR_SW_HSI; /* (2) */
|
||||
// while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_HSI) /* (3) */
|
||||
// { /* For robust implementation, add here time-out management */ }
|
||||
// }
|
||||
|
||||
// RCC->CR &= (uint32_t)(~RCC_CR_PLLON);/* (4) */
|
||||
// while((RCC->CR & RCC_CR_PLLRDY) != 0) /* (5) */
|
||||
// { /* For robust implementation, add here time-out management */ }
|
||||
|
||||
// FLASH->ACR |= FLASH_ACR_LATENCY; /* (6) */
|
||||
// RCC->CFGR = RCC->CFGR & ((~(RCC_CFGR_PLLMUL| RCC_CFGR_PLLDIV )) | (RCC_CFGR_PLLMUL24 | RCC_CFGR_PLLDIV2)); /* (7) */
|
||||
// RCC->CR |= RCC_CR_PLLON; /* (8) */
|
||||
|
||||
// while ((RCC->CR & RCC_CR_PLLRDY) == 0) /* (9) */
|
||||
// { /* For robust implementation, add here time-out management */ }
|
||||
// RCC->CFGR |= (uint32_t) (RCC_CFGR_SW_PLL); /* (10) */
|
||||
|
||||
// while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL) /* (11) */
|
||||
// { /* For robust implementation, add here time-out management */ }
|
||||
|
||||
/*!< Reset
|
||||
* PLLSRC (HSI16 is the PLL source),
|
||||
@@ -129,7 +168,7 @@ void SystemInit()
|
||||
* Don't touch PLLDIV[1:0], since 0 is undefined
|
||||
*/
|
||||
CLR(RCC->CFGR,
|
||||
RCC_CFGR_PLLSRC | RCC_CFGR_PLLMUL | RCC_CFGR_PLLDIV);
|
||||
RCC_CFGR_PLLSRC | RCC_CFGR_PLLMUL | RCC_CFGR_PLLDIV);
|
||||
|
||||
/*!< Disable all interrupts */
|
||||
RCC->CIER = 0x00000000;
|
||||
@@ -170,7 +209,7 @@ static void _init(void)
|
||||
g_screen_manager.set_root_screen(g_display_time_screen);
|
||||
|
||||
// Enqueue each of the tasks
|
||||
Common::Schedule::NextTime asap = Common::Schedule::NextTime::asap();
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user