Do not compile GFX and older fonts anymore.
Refactor SystemTask in its own class. Refactor Screen to be able to close current screen and open a new one. Re-enable sleep/wake up and propagate button event to Screens.
This commit is contained in:
parent
2bdff7ed2b
commit
02772b996f
|
@ -156,17 +156,15 @@ list(APPEND SOURCE_FILES
|
|||
Logging/NrfLogger.cpp
|
||||
BlinkApp/BlinkApp.cpp
|
||||
DisplayApp/DisplayApp.cpp
|
||||
DisplayApp/Fonts/lcdfont70.c
|
||||
DisplayApp/Fonts/lcdfont14.c
|
||||
DisplayApp/Screens/Screen.cpp
|
||||
DisplayApp/Screens/Clock.cpp
|
||||
DisplayApp/Screens/Message.cpp
|
||||
# DisplayApp/Screens/Message.cpp
|
||||
DisplayApp/Screens/Tile.cpp
|
||||
DisplayApp/Screens/Tab.cpp
|
||||
# DisplayApp/Screens/Tab.cpp
|
||||
main.cpp
|
||||
drivers/St7789.cpp
|
||||
drivers/SpiMaster.cpp
|
||||
Components/Gfx/Gfx.cpp
|
||||
# Components/Gfx/Gfx.cpp
|
||||
BLE/BleManager.c
|
||||
Components/Battery/BatteryController.cpp
|
||||
Components/Ble/BleController.cpp
|
||||
|
@ -180,6 +178,8 @@ list(APPEND SOURCE_FILES
|
|||
DisplayApp/LittleVgl.cpp
|
||||
DisplayApp/Fonts/jetbrains_mono_extrabold_compressed.c
|
||||
DisplayApp/Fonts/jetbrains_mono_bold_20.c
|
||||
|
||||
SystemTask/SystemTask.cpp
|
||||
)
|
||||
|
||||
set(INCLUDE_FILES
|
||||
|
@ -187,16 +187,13 @@ set(INCLUDE_FILES
|
|||
Logging/NrfLogger.h
|
||||
BlinkApp/BlinkApp.h
|
||||
DisplayApp/DisplayApp.h
|
||||
DisplayApp/Fonts/lcdfont70.h
|
||||
DisplayApp/Fonts/lcdfont14.h
|
||||
DisplayApp/Screens/Screen.h
|
||||
DisplayApp/Screens/Clock.h
|
||||
DisplayApp/Screens/Message.h
|
||||
# DisplayApp/Screens/Message.h
|
||||
DisplayApp/Screens/Tile.h
|
||||
DisplayApp/Screens/Tab.h
|
||||
# DisplayApp/Screens/Tab.h
|
||||
drivers/St7789.h
|
||||
drivers/SpiMaster.h
|
||||
Components/Gfx/Gfx.h
|
||||
BLE/BleManager.h
|
||||
Components/Battery/BatteryController.h
|
||||
Components/Ble/BleController.h
|
||||
|
@ -214,6 +211,8 @@ set(INCLUDE_FILES
|
|||
libs/date/includes/date/tz_private.h
|
||||
|
||||
DisplayApp/LittleVgl.h
|
||||
|
||||
SystemTask/SystemTask.h
|
||||
)
|
||||
|
||||
include_directories(
|
||||
|
|
|
@ -13,25 +13,26 @@
|
|||
#include <string>
|
||||
#include <lvgl/lvgl.h>
|
||||
#include <DisplayApp/Screens/Tile.h>
|
||||
#include <DisplayApp/Screens/Tab.h>
|
||||
#include "../SystemTask/SystemTask.h"
|
||||
//#include <DisplayApp/Screens/Tab.h>
|
||||
|
||||
using namespace Pinetime::Applications;
|
||||
|
||||
DisplayApp::DisplayApp(Pinetime::Drivers::St7789& lcd,
|
||||
Pinetime::Components::Gfx& gfx,
|
||||
Pinetime::Components::LittleVgl& lvgl,
|
||||
Pinetime::Drivers::Cst816S& touchPanel,
|
||||
Controllers::Battery &batteryController,
|
||||
Controllers::Ble &bleController,
|
||||
Controllers::DateTime &dateTimeController) :
|
||||
Controllers::DateTime &dateTimeController,
|
||||
Pinetime::System::SystemTask& systemTask) :
|
||||
lcd{lcd},
|
||||
gfx{gfx},
|
||||
lvgl{lvgl},
|
||||
touchPanel{touchPanel},
|
||||
batteryController{batteryController},
|
||||
bleController{bleController},
|
||||
dateTimeController{dateTimeController},
|
||||
currentScreen{new Screens::Clock(this, gfx, dateTimeController) } {
|
||||
currentScreen{new Screens::Clock(this, dateTimeController) },
|
||||
systemTask{systemTask} {
|
||||
msgQueue = xQueueCreate(queueSize, itemSize);
|
||||
}
|
||||
|
||||
|
@ -48,7 +49,7 @@ void DisplayApp::Process(void *instance) {
|
|||
while (1) {
|
||||
|
||||
app->Refresh();
|
||||
lv_task_handler();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,36 +115,28 @@ void DisplayApp::Refresh() {
|
|||
OnTouchEvent();
|
||||
break;
|
||||
case Messages::ButtonPushed:
|
||||
currentScreen->OnButtonPushed();
|
||||
if(!currentScreen->OnButtonPushed()) {
|
||||
systemTask.PushMessage(System::SystemTask::Messages::GoToSleep);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool first = true;
|
||||
|
||||
void DisplayApp::RunningState() {
|
||||
// clockScreen.SetCurrentDateTime(dateTimeController.CurrentDateTime());
|
||||
|
||||
if(currentScreen != nullptr) {
|
||||
currentScreen->Refresh(first);
|
||||
if(currentScreen->GetNextScreen() != Screens::Screen::NextScreen::None) {
|
||||
switch(currentScreen->GetNextScreen()) {
|
||||
case Screens::Screen::NextScreen::Clock:
|
||||
currentScreen.reset(nullptr);
|
||||
currentScreen.reset(new Screens::Clock(this, gfx, dateTimeController));
|
||||
break;
|
||||
case Screens::Screen::NextScreen::Menu:
|
||||
currentScreen.reset(nullptr);
|
||||
currentScreen.reset(new Screens::Tile(this, gfx));
|
||||
break;
|
||||
case Screens::Screen::NextScreen::App:
|
||||
currentScreen.reset(nullptr);
|
||||
currentScreen.reset(new Screens::Message(this, gfx));
|
||||
break;
|
||||
}
|
||||
if(!currentScreen->Refresh(true)) {
|
||||
currentScreen.reset(nullptr);
|
||||
switch(nextApp) {
|
||||
case Apps::None:
|
||||
case Apps::Launcher: currentScreen.reset(new Screens::Tile(this)); break;
|
||||
case Apps::Clock: currentScreen.reset(new Screens::Clock(this, dateTimeController)); break;
|
||||
// case Apps::Test: currentScreen.reset(new Screens::Message(this)); break;
|
||||
}
|
||||
first = false;
|
||||
nextApp = Apps::None;
|
||||
}
|
||||
lv_task_handler();
|
||||
}
|
||||
|
||||
void DisplayApp::IdleState() {
|
||||
|
@ -169,3 +162,7 @@ void DisplayApp::OnTouchEvent() {
|
|||
// pointColor+=10;
|
||||
// }
|
||||
}
|
||||
|
||||
void DisplayApp::StartApp(DisplayApp::Apps app) {
|
||||
nextApp = app;
|
||||
}
|
||||
|
|
|
@ -14,35 +14,37 @@
|
|||
#include "LittleVgl.h"
|
||||
#include <date/date.h>
|
||||
#include <DisplayApp/Screens/Clock.h>
|
||||
#include <DisplayApp/Screens/Message.h>
|
||||
//#include <DisplayApp/Screens/Message.h>
|
||||
|
||||
extern const FONT_INFO lCD_70ptFontInfo;
|
||||
|
||||
namespace Pinetime {
|
||||
namespace System {
|
||||
class SystemTask;
|
||||
};
|
||||
namespace Applications {
|
||||
class DisplayApp {
|
||||
public:
|
||||
enum class States {Idle, Running};
|
||||
enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent, SwitchScreen,ButtonPushed} ;
|
||||
DisplayApp(Pinetime::Drivers::St7789& lcd,
|
||||
Pinetime::Components::Gfx& gfx,
|
||||
Pinetime::Components::LittleVgl& lvgl,
|
||||
Pinetime::Drivers::Cst816S&,
|
||||
Controllers::Battery &batteryController,
|
||||
Controllers::Ble &bleController,
|
||||
Controllers::DateTime& dateTimeController);
|
||||
Controllers::DateTime& dateTimeController,
|
||||
Pinetime::System::SystemTask& systemTask);
|
||||
void Start();
|
||||
void PushMessage(Messages msg);
|
||||
|
||||
enum class Apps {None, Launcher, Clock, Test};
|
||||
void StartApp(Apps app);
|
||||
|
||||
private:
|
||||
TaskHandle_t taskHandle;
|
||||
static void Process(void* instance);
|
||||
void InitHw();
|
||||
Pinetime::Drivers::St7789& lcd;
|
||||
Pinetime::Components::Gfx& gfx;
|
||||
Pinetime::Components::LittleVgl lvgl;
|
||||
const FONT_INFO largeFont {lCD_70ptFontInfo.height, lCD_70ptFontInfo.startChar, lCD_70ptFontInfo.endChar, lCD_70ptFontInfo.spacePixels, lCD_70ptFontInfo.charInfo, lCD_70ptFontInfo.data};
|
||||
const FONT_INFO smallFont {lCD_14ptFontInfo.height, lCD_14ptFontInfo.startChar, lCD_14ptFontInfo.endChar, lCD_14ptFontInfo.spacePixels, lCD_14ptFontInfo.charInfo, lCD_14ptFontInfo.data};
|
||||
void Refresh();
|
||||
|
||||
States state = States::Running;
|
||||
|
@ -66,6 +68,9 @@ namespace Pinetime {
|
|||
static constexpr uint8_t pinLcdBacklight3 = 23;
|
||||
|
||||
bool isClock = true;
|
||||
|
||||
Pinetime::System::SystemTask& systemTask;
|
||||
Apps nextApp = Apps::None;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) {
|
|||
screen->OnObjectEvent(obj, event);
|
||||
}
|
||||
|
||||
Clock::Clock(DisplayApp* app, Pinetime::Components::Gfx &gfx, Controllers::DateTime& dateTimeController) : Screen(app, gfx), currentDateTime{{}}, version {{}}, dateTimeController{dateTimeController} {
|
||||
Clock::Clock(DisplayApp* app, Controllers::DateTime& dateTimeController) : Screen(app), currentDateTime{{}}, version {{}}, dateTimeController{dateTimeController} {
|
||||
displayedChar[0] = 0;
|
||||
displayedChar[1] = 0;
|
||||
displayedChar[2] = 0;
|
||||
|
@ -65,7 +65,7 @@ Clock::~Clock() {
|
|||
lv_obj_clean(lv_scr_act());
|
||||
}
|
||||
|
||||
void Clock::Refresh(bool fullRefresh) {
|
||||
bool Clock::Refresh(bool fullRefresh) {
|
||||
if(fullRefresh) {
|
||||
auto currentDateTime = dateTimeController.CurrentDateTime();
|
||||
}
|
||||
|
@ -145,6 +145,7 @@ void Clock::Refresh(bool fullRefresh) {
|
|||
lv_label_set_text(label_version, versionStr);
|
||||
}
|
||||
|
||||
return running;
|
||||
}
|
||||
|
||||
const char *Clock::MonthToString(Pinetime::Controllers::DateTime::Months month) {
|
||||
|
@ -185,9 +186,14 @@ char const *Clock::MonthsString[] = {
|
|||
void Clock::OnObjectEvent(lv_obj_t *obj, lv_event_t event) {
|
||||
if(obj == backgroundLabel) {
|
||||
if (event == LV_EVENT_CLICKED) {
|
||||
nextScreen = NextScreen::Menu;
|
||||
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Clock::OnButtonPushed() {
|
||||
return Screen::OnButtonPushed();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -35,9 +35,11 @@ namespace Pinetime {
|
|||
class Clock : public Screen{
|
||||
public:
|
||||
enum class BleConnectionStates{ NotConnected, Connected};
|
||||
Clock(DisplayApp* app, Components::Gfx& gfx, Controllers::DateTime& dateTimeController);
|
||||
Clock(DisplayApp* app, Controllers::DateTime& dateTimeController);
|
||||
~Clock() override;
|
||||
void Refresh(bool fullRefresh) override;
|
||||
|
||||
bool Refresh(bool fullRefresh) override;
|
||||
bool OnButtonPushed() override;
|
||||
|
||||
void SetBatteryPercentRemaining(uint8_t percent) { batteryPercentRemaining = percent; }
|
||||
void SetBleConnectionState(BleConnectionStates state) { bleState = state; }
|
||||
|
@ -52,9 +54,6 @@ namespace Pinetime {
|
|||
|
||||
char displayedChar[5];
|
||||
|
||||
const FONT_INFO largeFont {lCD_70ptFontInfo.height, lCD_70ptFontInfo.startChar, lCD_70ptFontInfo.endChar, lCD_70ptFontInfo.spacePixels, lCD_70ptFontInfo.charInfo, lCD_70ptFontInfo.data};
|
||||
const FONT_INFO smallFont {lCD_14ptFontInfo.height, lCD_14ptFontInfo.startChar, lCD_14ptFontInfo.endChar, lCD_14ptFontInfo.spacePixels, lCD_14ptFontInfo.charInfo, lCD_14ptFontInfo.data};
|
||||
|
||||
uint16_t currentYear = 1970;
|
||||
Pinetime::Controllers::DateTime::Months currentMonth = Pinetime::Controllers::DateTime::Months::Unknown;
|
||||
Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
|
||||
|
@ -77,6 +76,8 @@ namespace Pinetime {
|
|||
|
||||
Controllers::DateTime& dateTimeController;
|
||||
|
||||
bool running = true;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,16 +9,18 @@ namespace Pinetime {
|
|||
class Screen {
|
||||
public:
|
||||
enum class NextScreen {None, Clock, Menu, App};
|
||||
Screen(DisplayApp* app, Components::Gfx& gfx) : app{app}, gfx{gfx} {}
|
||||
|
||||
Screen(DisplayApp* app) : app{app} {}
|
||||
virtual ~Screen() = default;
|
||||
virtual void Refresh(bool fullRefresh) = 0;
|
||||
NextScreen GetNextScreen() {return nextScreen;}
|
||||
virtual void OnButtonPushed() {};
|
||||
|
||||
// Return false if the app can be closed, true if it must continue to run
|
||||
virtual bool Refresh(bool fullRefresh) = 0;
|
||||
|
||||
// Return false if the button hasn't been handled by the app, true if it has been handled
|
||||
virtual bool OnButtonPushed() { return false; }
|
||||
|
||||
protected:
|
||||
DisplayApp* app;
|
||||
Components::Gfx& gfx;
|
||||
NextScreen nextScreen = NextScreen::None;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,8 +22,7 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) {
|
|||
|
||||
static const char * btnm_map1[] = {"App1", "App2", "App3", "\n", "App4", "App5", "App11", ""};
|
||||
|
||||
Tile::Tile(DisplayApp* app, Pinetime::Components::Gfx &gfx) : Screen(app, gfx) {
|
||||
|
||||
Tile::Tile(DisplayApp* app) : Screen(app) {
|
||||
static lv_point_t valid_pos[] = {{0,0}, {LV_COORD_MIN, LV_COORD_MIN}};
|
||||
tileview = lv_tileview_create(lv_scr_act(), NULL);
|
||||
lv_tileview_set_valid_positions(tileview, valid_pos, 1);
|
||||
|
@ -38,11 +37,16 @@ Tile::Tile(DisplayApp* app, Pinetime::Components::Gfx &gfx) : Screen(app, gfx) {
|
|||
lv_btnm_set_map(btnm1, btnm_map1);
|
||||
lv_obj_set_size(btnm1, LV_HOR_RES, LV_VER_RES);
|
||||
|
||||
labelStyle = const_cast<lv_style_t *>(lv_label_get_style(btnm1, LV_BTNM_STYLE_BTN_REL));
|
||||
labelStyle->text.font = &jetbrains_mono_bold_20;
|
||||
labelStyle->body.grad_color = labelStyle->body.main_color;
|
||||
lv_btnm_set_style(btnm1, LV_BTNM_STYLE_BTN_REL, labelStyle);
|
||||
lv_btnm_set_style(btnm1, LV_BTNM_STYLE_BTN_PR, labelStyle);
|
||||
labelRelStyle = const_cast<lv_style_t *>(lv_label_get_style(btnm1, LV_BTNM_STYLE_BTN_REL));
|
||||
labelRelStyle->text.font = &jetbrains_mono_bold_20;
|
||||
labelRelStyle->body.grad_color = labelRelStyle->body.main_color;
|
||||
lv_btnm_set_style(btnm1, LV_BTNM_STYLE_BTN_REL, labelRelStyle);
|
||||
|
||||
labelPrStyle = const_cast<lv_style_t *>(lv_label_get_style(btnm1, LV_BTNM_STYLE_BTN_PR));
|
||||
labelPrStyle->text.font = &jetbrains_mono_bold_20;
|
||||
labelPrStyle->body.grad_color = labelPrStyle->body.shadow.color;
|
||||
// lv_btnm_set_style(btnm1, LV_BTNM_STYLE_BTN_PR, labelPrStyle);
|
||||
//TODO better style handling
|
||||
|
||||
lv_obj_align(btnm1, tile1, LV_ALIGN_CENTER, 0, 0);
|
||||
btnm1->user_data = this;
|
||||
|
@ -100,17 +104,28 @@ Tile::~Tile() {
|
|||
lv_obj_clean(lv_scr_act());
|
||||
}
|
||||
|
||||
void Tile::Refresh(bool fullRefresh) {
|
||||
|
||||
bool Tile::Refresh(bool fullRefresh) {
|
||||
return running;
|
||||
}
|
||||
|
||||
void Tile::OnObjectEvent(lv_obj_t *obj, lv_event_t event) {
|
||||
auto* tile = static_cast<Tile*>(obj->user_data);
|
||||
if(event == LV_EVENT_CLICKED) {
|
||||
NRF_LOG_INFO("Clicked");
|
||||
nextScreen = Screen::NextScreen::App;
|
||||
|
||||
tile->StartApp();
|
||||
clickCount++;
|
||||
}
|
||||
else if(event == LV_EVENT_VALUE_CHANGED) {
|
||||
NRF_LOG_INFO("Toggled");
|
||||
}
|
||||
}
|
||||
|
||||
bool Tile::OnButtonPushed() {
|
||||
app->StartApp(DisplayApp::Apps::Clock);
|
||||
running = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Tile::StartApp() {
|
||||
app->StartApp(DisplayApp::Apps::Clock);
|
||||
running = false;
|
||||
}
|
||||
|
|
|
@ -15,18 +15,18 @@ namespace Pinetime {
|
|||
namespace Screens {
|
||||
class Tile : public Screen {
|
||||
public:
|
||||
explicit Tile(DisplayApp* app, Components::Gfx& gfx);
|
||||
explicit Tile(DisplayApp* app);
|
||||
~Tile() override;
|
||||
void Refresh(bool fullRefresh) override;
|
||||
|
||||
bool Refresh(bool fullRefresh) override;
|
||||
bool OnButtonPushed() override;
|
||||
|
||||
void OnObjectEvent(lv_obj_t* obj, lv_event_t event);
|
||||
|
||||
void OnButtonPushed() override {nextScreen = NextScreen::Clock;}
|
||||
|
||||
private:
|
||||
const FONT_INFO largeFont {lCD_70ptFontInfo.height, lCD_70ptFontInfo.startChar, lCD_70ptFontInfo.endChar, lCD_70ptFontInfo.spacePixels, lCD_70ptFontInfo.charInfo, lCD_70ptFontInfo.data};
|
||||
const FONT_INFO smallFont {lCD_14ptFontInfo.height, lCD_14ptFontInfo.startChar, lCD_14ptFontInfo.endChar, lCD_14ptFontInfo.spacePixels, lCD_14ptFontInfo.charInfo, lCD_14ptFontInfo.data};
|
||||
|
||||
lv_style_t* labelStyle;
|
||||
lv_style_t* labelRelStyle;
|
||||
lv_style_t* labelPrStyle;
|
||||
lv_obj_t * label1;
|
||||
lv_obj_t * label2;
|
||||
lv_obj_t * label3;
|
||||
|
@ -50,6 +50,8 @@ namespace Pinetime {
|
|||
|
||||
uint32_t clickCount = 0 ;
|
||||
uint32_t previousClickCount = 0;
|
||||
void StartApp();
|
||||
bool running = true;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
115
src/SystemTask/SystemTask.cpp
Normal file
115
src/SystemTask/SystemTask.cpp
Normal file
|
@ -0,0 +1,115 @@
|
|||
#include <libraries/log/nrf_log.h>
|
||||
#include <libraries/gpiote/app_gpiote.h>
|
||||
#include <drivers/Cst816s.h>
|
||||
#include <DisplayApp/LittleVgl.h>
|
||||
#include <hal/nrf_rtc.h>
|
||||
#include "SystemTask.h"
|
||||
#include "../main.h"
|
||||
using namespace Pinetime::System;
|
||||
|
||||
SystemTask::SystemTask(Pinetime::Drivers::SpiMaster &spi, Pinetime::Drivers::St7789 &lcd,
|
||||
Pinetime::Drivers::Cst816S &touchPanel, Pinetime::Components::LittleVgl &lvgl,
|
||||
Pinetime::Controllers::Battery &batteryController, Pinetime::Controllers::Ble &bleController,
|
||||
Pinetime::Controllers::DateTime& dateTimeController) :
|
||||
spi{spi}, lcd{lcd}, touchPanel{touchPanel}, lvgl{lvgl}, batteryController{batteryController}, bleController{bleController}, dateTimeController{dateTimeController} {
|
||||
systemTaksMsgQueue = xQueueCreate(10, 1);
|
||||
}
|
||||
|
||||
void SystemTask::Start() {
|
||||
if (pdPASS != xTaskCreate(SystemTask::Process, "MAIN", 256, this, 0, &taskHandle))
|
||||
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
|
||||
}
|
||||
|
||||
void SystemTask::Process(void *instance) {
|
||||
auto *app = static_cast<SystemTask *>(instance);
|
||||
NRF_LOG_INFO("SystemTask task started!");
|
||||
app->Work();
|
||||
}
|
||||
|
||||
void SystemTask::Work() {
|
||||
APP_GPIOTE_INIT(2);
|
||||
bool erase_bonds=false;
|
||||
// nrf_sdh_freertos_init(ble_manager_start_advertising, &erase_bonds);
|
||||
|
||||
spi.Init();
|
||||
lcd.Init();
|
||||
touchPanel.Init();
|
||||
batteryController.Init();
|
||||
|
||||
displayApp.reset(new Pinetime::Applications::DisplayApp(lcd, lvgl, touchPanel, batteryController, bleController, dateTimeController, *this));
|
||||
displayApp->Start();
|
||||
|
||||
batteryController.Update();
|
||||
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::UpdateBatteryLevel);
|
||||
|
||||
nrf_gpio_cfg_sense_input(pinButton, (nrf_gpio_pin_pull_t)GPIO_PIN_CNF_PULL_Pulldown, (nrf_gpio_pin_sense_t)GPIO_PIN_CNF_SENSE_High);
|
||||
nrf_gpio_cfg_output(15);
|
||||
nrf_gpio_pin_set(15);
|
||||
|
||||
nrfx_gpiote_in_config_t pinConfig;
|
||||
pinConfig.skip_gpio_setup = true;
|
||||
pinConfig.hi_accuracy = false;
|
||||
pinConfig.is_watcher = false;
|
||||
pinConfig.sense = (nrf_gpiote_polarity_t)NRF_GPIOTE_POLARITY_HITOLO;
|
||||
pinConfig.pull = (nrf_gpio_pin_pull_t)GPIO_PIN_CNF_PULL_Pulldown;
|
||||
|
||||
nrfx_gpiote_in_init(pinButton, &pinConfig, nrfx_gpiote_evt_handler);
|
||||
|
||||
nrf_gpio_cfg_sense_input(pinTouchIrq, (nrf_gpio_pin_pull_t)GPIO_PIN_CNF_PULL_Pullup, (nrf_gpio_pin_sense_t)GPIO_PIN_CNF_SENSE_Low);
|
||||
|
||||
pinConfig.skip_gpio_setup = true;
|
||||
pinConfig.hi_accuracy = false;
|
||||
pinConfig.is_watcher = false;
|
||||
pinConfig.sense = (nrf_gpiote_polarity_t)NRF_GPIOTE_POLARITY_HITOLO;
|
||||
pinConfig.pull = (nrf_gpio_pin_pull_t)GPIO_PIN_CNF_PULL_Pullup;
|
||||
|
||||
nrfx_gpiote_in_init(pinTouchIrq, &pinConfig, nrfx_gpiote_evt_handler);
|
||||
|
||||
|
||||
while(true) {
|
||||
uint8_t msg;
|
||||
if (xQueueReceive(systemTaksMsgQueue, &msg, isSleeping?3600000 : 1000)) {
|
||||
Messages message = static_cast<Messages >(msg);
|
||||
switch(message) {
|
||||
case Messages::GoToRunning: isSleeping = false; break;
|
||||
case Messages::GoToSleep:
|
||||
NRF_LOG_INFO("[SystemTask] Going to sleep");
|
||||
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::GoToSleep);
|
||||
isSleeping = true; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG);
|
||||
dateTimeController.UpdateTime(systick_counter);
|
||||
}
|
||||
}
|
||||
|
||||
void SystemTask::OnButtonPushed() {
|
||||
|
||||
if(!isSleeping) {
|
||||
NRF_LOG_INFO("[SystemTask] Button pushed");
|
||||
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::ButtonPushed);
|
||||
}
|
||||
else {
|
||||
NRF_LOG_INFO("[SystemTask] Button pushed, waking up");
|
||||
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::GoToRunning);
|
||||
isSleeping = false;
|
||||
batteryController.Update();
|
||||
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::UpdateBatteryLevel);
|
||||
}
|
||||
}
|
||||
|
||||
void SystemTask::OnTouchEvent() {
|
||||
NRF_LOG_INFO("[SystemTask] Touch event");
|
||||
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::TouchEvent);
|
||||
}
|
||||
|
||||
void SystemTask::PushMessage(SystemTask::Messages msg) {
|
||||
BaseType_t xHigherPriorityTaskWoken;
|
||||
xHigherPriorityTaskWoken = pdFALSE;
|
||||
xQueueSendFromISR(systemTaksMsgQueue, &msg, &xHigherPriorityTaskWoken);
|
||||
if (xHigherPriorityTaskWoken) {
|
||||
/* Actual macro used here is port specific. */
|
||||
// TODO : should I do something here?
|
||||
}
|
||||
}
|
60
src/SystemTask/SystemTask.h
Normal file
60
src/SystemTask/SystemTask.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
#pragma once
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
#include <memory>
|
||||
#include <drivers/SpiMaster.h>
|
||||
#include <drivers/St7789.h>
|
||||
#include <Components/Battery/BatteryController.h>
|
||||
#include <DisplayApp/DisplayApp.h>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace System {
|
||||
class SystemTask {
|
||||
public:
|
||||
enum class Messages {GoToSleep, GoToRunning};
|
||||
|
||||
SystemTask(Pinetime::Drivers::SpiMaster& spi,
|
||||
Pinetime::Drivers::St7789& lcd,
|
||||
Pinetime::Drivers::Cst816S& touchPanel,
|
||||
Pinetime::Components::LittleVgl& lvgl,
|
||||
Pinetime::Controllers::Battery& batteryController,
|
||||
Pinetime::Controllers::Ble& bleController,
|
||||
Pinetime::Controllers::DateTime& dateTimeController);
|
||||
|
||||
|
||||
void Start();
|
||||
void PushMessage(Messages msg);
|
||||
|
||||
void OnButtonPushed();
|
||||
void OnTouchEvent();
|
||||
private:
|
||||
TaskHandle_t taskHandle;
|
||||
|
||||
Pinetime::Drivers::SpiMaster& spi;
|
||||
Pinetime::Drivers::St7789& lcd;
|
||||
Pinetime::Drivers::Cst816S& touchPanel;
|
||||
Pinetime::Components::LittleVgl& lvgl;
|
||||
Pinetime::Controllers::Battery& batteryController;
|
||||
std::unique_ptr<Pinetime::Applications::DisplayApp> displayApp;
|
||||
Pinetime::Controllers::Ble& bleController;
|
||||
Pinetime::Controllers::DateTime& dateTimeController;
|
||||
QueueHandle_t systemTaksMsgQueue;
|
||||
bool isSleeping = false;
|
||||
|
||||
|
||||
static constexpr uint8_t pinSpiSck = 2;
|
||||
static constexpr uint8_t pinSpiMosi = 3;
|
||||
static constexpr uint8_t pinSpiMiso = 4;
|
||||
static constexpr uint8_t pinSpiCsn = 25;
|
||||
static constexpr uint8_t pinLcdDataCommand = 18;
|
||||
static constexpr uint8_t pinButton = 13;
|
||||
static constexpr uint8_t pinTouchIrq = 28;
|
||||
|
||||
static void Process(void* instance);
|
||||
void Work();
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
}
|
|
@ -123,7 +123,7 @@ typedef int16_t lv_coord_t;
|
|||
*==================*/
|
||||
|
||||
/*1: Enable the Animations */
|
||||
#define LV_USE_ANIMATION 0
|
||||
#define LV_USE_ANIMATION 1
|
||||
#if LV_USE_ANIMATION
|
||||
|
||||
/*Declare the type of the user data of animations (can be e.g. `void *`, `int`, `struct`)*/
|
||||
|
@ -563,7 +563,7 @@ typedef void * lv_obj_user_data_t;
|
|||
#define LV_USE_TILEVIEW 1
|
||||
#if LV_USE_TILEVIEW
|
||||
/*Time of slide animation [ms] (0: no animation)*/
|
||||
# define LV_TILEVIEW_DEF_ANIM_TIME 0
|
||||
# define LV_TILEVIEW_DEF_ANIM_TIME 300
|
||||
#endif
|
||||
|
||||
/*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/
|
||||
|
|
146
src/main.cpp
146
src/main.cpp
|
@ -18,10 +18,10 @@
|
|||
#include "../drivers/Cst816s.h"
|
||||
#include <drivers/St7789.h>
|
||||
#include <drivers/SpiMaster.h>
|
||||
#include <Components/Gfx/Gfx.h>
|
||||
|
||||
#include <lvgl/lvgl.h>
|
||||
#include <DisplayApp/LittleVgl.h>
|
||||
#include <SystemTask/SystemTask.h>
|
||||
|
||||
#if NRF_LOG_ENABLED
|
||||
#include "Logging/NrfLogger.h"
|
||||
|
@ -33,8 +33,6 @@ Pinetime::Logging::DummyLogger logger;
|
|||
|
||||
std::unique_ptr<Pinetime::Drivers::SpiMaster> spi;
|
||||
std::unique_ptr<Pinetime::Drivers::St7789> lcd;
|
||||
Pinetime::Drivers::St7789* ptrLcd;
|
||||
std::unique_ptr<Pinetime::Components::Gfx> gfx;
|
||||
std::unique_ptr<Pinetime::Components::LittleVgl> lvgl;
|
||||
std::unique_ptr<Pinetime::Drivers::Cst816S> touchPanel;
|
||||
|
||||
|
@ -45,27 +43,19 @@ static constexpr uint8_t pinSpiCsn = 25;
|
|||
static constexpr uint8_t pinLcdDataCommand = 18;
|
||||
|
||||
|
||||
std::unique_ptr<Pinetime::Applications::DisplayApp> displayApp;
|
||||
TaskHandle_t systemThread;
|
||||
bool isSleeping = false;
|
||||
TimerHandle_t debounceTimer;
|
||||
Pinetime::Controllers::Battery batteryController;
|
||||
Pinetime::Controllers::Ble bleController;
|
||||
Pinetime::Controllers::DateTime dateTimeController;
|
||||
|
||||
|
||||
void ble_manager_set_ble_connection_callback(void (*connection)());
|
||||
void ble_manager_set_ble_disconnection_callback(void (*disconnection)());
|
||||
static constexpr uint8_t pinButton = 13;
|
||||
static constexpr uint8_t pinTouchIrq = 28;
|
||||
QueueHandle_t systemTaksMsgQueue;
|
||||
enum class SystemTaskMessages {GoToSleep, GoToRunning};
|
||||
void SystemTask_PushMessage(SystemTaskMessages message);
|
||||
std::unique_ptr<Pinetime::System::SystemTask> systemTask;
|
||||
|
||||
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
|
||||
if(pin == pinTouchIrq) {
|
||||
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::TouchEvent);
|
||||
if(!isSleeping) return;
|
||||
systemTask->OnTouchEvent();
|
||||
return ;
|
||||
}
|
||||
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
|
@ -73,7 +63,6 @@ void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action
|
|||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
|
||||
extern "C" {
|
||||
void vApplicationIdleHook(void) {
|
||||
lv_tick_inc(1);
|
||||
|
@ -82,118 +71,17 @@ extern "C" {
|
|||
|
||||
void DebounceTimerCallback(TimerHandle_t xTimer) {
|
||||
xTimerStop(xTimer, 0);
|
||||
/*if(isSleeping) {
|
||||
SystemTask_PushMessage(SystemTaskMessages::GoToRunning);
|
||||
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::GoToRunning);
|
||||
isSleeping = false;
|
||||
batteryController.Update();
|
||||
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::UpdateBatteryLevel);
|
||||
}
|
||||
else {
|
||||
SystemTask_PushMessage(SystemTaskMessages::GoToSleep);
|
||||
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::GoToSleep);
|
||||
isSleeping = true;
|
||||
}*/
|
||||
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::ButtonPushed);
|
||||
}
|
||||
|
||||
void SystemTask_PushMessage(SystemTaskMessages message) {
|
||||
BaseType_t xHigherPriorityTaskWoken;
|
||||
xHigherPriorityTaskWoken = pdFALSE;
|
||||
xQueueSendFromISR(systemTaksMsgQueue, &message, &xHigherPriorityTaskWoken);
|
||||
if (xHigherPriorityTaskWoken) {
|
||||
/* Actual macro used here is port specific. */
|
||||
// TODO : should I do something here?
|
||||
}
|
||||
}
|
||||
|
||||
// TODO The whole SystemTask should go in its own class
|
||||
// BUT... it has to work with pure C callback (nrfx_gpiote_evt_handler) and i've still not found
|
||||
// a good design for that (the callback does not allow to pass a pointer to an instance...)
|
||||
void SystemTask(void *) {
|
||||
APP_GPIOTE_INIT(2);
|
||||
bool erase_bonds=false;
|
||||
// nrf_sdh_freertos_init(ble_manager_start_advertising, &erase_bonds);
|
||||
|
||||
spi.reset(new Pinetime::Drivers::SpiMaster {Pinetime::Drivers::SpiMaster::SpiModule::SPI0, {
|
||||
Pinetime::Drivers::SpiMaster::BitOrder::Msb_Lsb,
|
||||
Pinetime::Drivers::SpiMaster::Modes::Mode3,
|
||||
Pinetime::Drivers::SpiMaster::Frequencies::Freq8Mhz,
|
||||
pinSpiSck,
|
||||
pinSpiMosi,
|
||||
pinSpiMiso,
|
||||
pinSpiCsn
|
||||
}});
|
||||
|
||||
lcd.reset(new Pinetime::Drivers::St7789(*spi, pinLcdDataCommand));
|
||||
gfx.reset(new Pinetime::Components::Gfx(*lcd));
|
||||
touchPanel.reset(new Pinetime::Drivers::Cst816S());
|
||||
|
||||
lvgl.reset(new Pinetime::Components::LittleVgl(*lcd, *touchPanel));
|
||||
ptrLcd = lcd.get();
|
||||
|
||||
spi->Init();
|
||||
lcd->Init();
|
||||
touchPanel->Init();
|
||||
batteryController.Init();
|
||||
|
||||
displayApp.reset(new Pinetime::Applications::DisplayApp(*lcd, *gfx, *lvgl, *touchPanel, batteryController, bleController, dateTimeController));
|
||||
displayApp->Start();
|
||||
|
||||
batteryController.Update();
|
||||
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::UpdateBatteryLevel);
|
||||
|
||||
debounceTimer = xTimerCreate ("debounceTimer", 200, pdFALSE, (void *) 0, DebounceTimerCallback);
|
||||
|
||||
nrf_gpio_cfg_sense_input(pinButton, (nrf_gpio_pin_pull_t)GPIO_PIN_CNF_PULL_Pulldown, (nrf_gpio_pin_sense_t)GPIO_PIN_CNF_SENSE_High);
|
||||
nrf_gpio_cfg_output(15);
|
||||
nrf_gpio_pin_set(15);
|
||||
|
||||
nrfx_gpiote_in_config_t pinConfig;
|
||||
pinConfig.skip_gpio_setup = true;
|
||||
pinConfig.hi_accuracy = false;
|
||||
pinConfig.is_watcher = false;
|
||||
pinConfig.sense = (nrf_gpiote_polarity_t)NRF_GPIOTE_POLARITY_HITOLO;
|
||||
pinConfig.pull = (nrf_gpio_pin_pull_t)GPIO_PIN_CNF_PULL_Pulldown;
|
||||
|
||||
nrfx_gpiote_in_init(pinButton, &pinConfig, nrfx_gpiote_evt_handler);
|
||||
|
||||
nrf_gpio_cfg_sense_input(pinTouchIrq, (nrf_gpio_pin_pull_t)GPIO_PIN_CNF_PULL_Pullup, (nrf_gpio_pin_sense_t)GPIO_PIN_CNF_SENSE_Low);
|
||||
|
||||
pinConfig.skip_gpio_setup = true;
|
||||
pinConfig.hi_accuracy = false;
|
||||
pinConfig.is_watcher = false;
|
||||
pinConfig.sense = (nrf_gpiote_polarity_t)NRF_GPIOTE_POLARITY_HITOLO;
|
||||
pinConfig.pull = (nrf_gpio_pin_pull_t)GPIO_PIN_CNF_PULL_Pullup;
|
||||
|
||||
nrfx_gpiote_in_init(pinTouchIrq, &pinConfig, nrfx_gpiote_evt_handler);
|
||||
|
||||
systemTaksMsgQueue = xQueueCreate(10, 1);
|
||||
bool systemTaskSleeping = false;
|
||||
|
||||
while(true) {
|
||||
uint8_t msg;
|
||||
if (xQueueReceive(systemTaksMsgQueue, &msg, systemTaskSleeping?3600000 : 1000)) {
|
||||
SystemTaskMessages message = static_cast<SystemTaskMessages >(msg);
|
||||
switch(message) {
|
||||
case SystemTaskMessages::GoToRunning: systemTaskSleeping = false; break;
|
||||
case SystemTaskMessages::GoToSleep: systemTaskSleeping = true; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG);
|
||||
dateTimeController.UpdateTime(systick_counter);
|
||||
}
|
||||
systemTask->OnButtonPushed();
|
||||
}
|
||||
|
||||
void OnBleConnection() {
|
||||
bleController.Connect();
|
||||
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::UpdateBleConnection);
|
||||
// TODO Notify system/Display app
|
||||
}
|
||||
|
||||
void OnBleDisconnection() {
|
||||
bleController.Disconnect();
|
||||
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::UpdateBleConnection);
|
||||
// TODO Notify system/Display app
|
||||
}
|
||||
|
||||
void OnNewTime(current_time_char_t* currentTime) {
|
||||
|
@ -224,12 +112,28 @@ void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void) {
|
|||
NRF_SPIM0->EVENTS_STOPPED = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
logger.Init();
|
||||
nrf_drv_clock_init();
|
||||
|
||||
if (pdPASS != xTaskCreate(SystemTask, "MAIN", 256, nullptr, 0, &systemThread))
|
||||
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
|
||||
spi.reset(new Pinetime::Drivers::SpiMaster {Pinetime::Drivers::SpiMaster::SpiModule::SPI0, {
|
||||
Pinetime::Drivers::SpiMaster::BitOrder::Msb_Lsb,
|
||||
Pinetime::Drivers::SpiMaster::Modes::Mode3,
|
||||
Pinetime::Drivers::SpiMaster::Frequencies::Freq8Mhz,
|
||||
pinSpiSck,
|
||||
pinSpiMosi,
|
||||
pinSpiMiso,
|
||||
pinSpiCsn
|
||||
}});
|
||||
lcd.reset(new Pinetime::Drivers::St7789(*spi, pinLcdDataCommand));
|
||||
touchPanel.reset(new Pinetime::Drivers::Cst816S());
|
||||
lvgl.reset(new Pinetime::Components::LittleVgl(*lcd, *touchPanel));
|
||||
debounceTimer = xTimerCreate ("debounceTimer", 200, pdFALSE, (void *) 0, DebounceTimerCallback);
|
||||
|
||||
systemTask.reset(new Pinetime::System::SystemTask(*spi, *lcd, *touchPanel, *lvgl, batteryController, bleController, dateTimeController));
|
||||
systemTask->Start();
|
||||
|
||||
/*
|
||||
ble_manager_init();
|
||||
ble_manager_set_new_time_callback(OnNewTime);
|
||||
|
|
7
src/main.h
Normal file
7
src/main.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <timers.h>
|
||||
|
||||
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action);
|
||||
void DebounceTimerCallback(TimerHandle_t xTimer);
|
Loading…
Reference in a new issue