From a97faf8e9e84053d6db37549cc4211866cb3b89f Mon Sep 17 00:00:00 2001 From: JF Date: Sat, 8 Feb 2020 18:01:02 +0100 Subject: First quick'n'dirty integration of LittleVGL. Needs some cleaning. --- src/drivers/SpiMaster.cpp | 31 +++++++++++++++---------------- src/drivers/SpiMaster.h | 7 +++++-- 2 files changed, 20 insertions(+), 18 deletions(-) (limited to 'src/drivers') diff --git a/src/drivers/SpiMaster.cpp b/src/drivers/SpiMaster.cpp index 4a875b9e..71986054 100644 --- a/src/drivers/SpiMaster.cpp +++ b/src/drivers/SpiMaster.cpp @@ -1,7 +1,10 @@ +#include #include #include #include "SpiMaster.h" #include +#include + using namespace Pinetime::Drivers; SpiMaster::SpiMaster(const SpiMaster::SpiModule spi, const SpiMaster::Parameters ¶ms) : @@ -96,7 +99,7 @@ void SpiMaster::DisableWorkaroundForFtpan58(NRF_SPIM_Type *spim, uint32_t ppi_ch spim->INTENSET = (1<<19); } -void SpiMaster::OnEndEvent(BufferProvider& provider) { +void SpiMaster::OnEndEvent() { if(!busy) return; auto s = currentBufferSize; @@ -110,24 +113,20 @@ void SpiMaster::OnEndEvent(BufferProvider& provider) { } else { uint8_t* buffer = nullptr; size_t size = 0; - if(provider.GetNextBuffer(&buffer, size)) { - currentBufferAddr = (uint32_t) buffer; - currentBufferSize = size; - auto s = currentBufferSize; - auto currentSize = std::min((size_t)255, s); - PrepareTx(currentBufferAddr, currentSize); - currentBufferAddr += currentSize; - currentBufferSize -= currentSize; - - spiBaseAddress->TASKS_START = 1; - } else { - busy = false; - nrf_gpio_pin_set(pinCsn); + busy = false; + + + if(taskToNotify != nullptr) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + vTaskNotifyGiveFromISR(taskToNotify, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); } + + nrf_gpio_pin_set(pinCsn); } } -void SpiMaster::OnStartedEvent(BufferProvider& provider) { +void SpiMaster::OnStartedEvent() { if(!busy) return; } @@ -143,7 +142,7 @@ void SpiMaster::PrepareTx(const volatile uint32_t bufferAddress, const volatile bool SpiMaster::Write(const uint8_t *data, size_t size) { if(data == nullptr) return false; - + taskToNotify = xTaskGetCurrentTaskHandle(); while(busy) { asm("nop"); } diff --git a/src/drivers/SpiMaster.h b/src/drivers/SpiMaster.h index 60013242..82042bdf 100644 --- a/src/drivers/SpiMaster.h +++ b/src/drivers/SpiMaster.h @@ -1,8 +1,10 @@ #pragma once +#include #include #include #include #include +#include #include "BufferProvider.h" namespace Pinetime { @@ -27,8 +29,8 @@ namespace Pinetime { bool Init(); bool Write(const uint8_t* data, size_t size); - void OnStartedEvent(BufferProvider& provider); - void OnEndEvent(BufferProvider& provider); + void OnStartedEvent(); + void OnEndEvent(); void Sleep(); void Wakeup(); @@ -47,6 +49,7 @@ namespace Pinetime { volatile bool busy = false; volatile uint32_t currentBufferAddr = 0; volatile size_t currentBufferSize = 0; + volatile TaskHandle_t taskToNotify; }; } } -- cgit v1.2.3-70-g09d2 From 52539a5ff1b6f52c65b032ef1668d43d4df2dc24 Mon Sep 17 00:00:00 2001 From: JF Date: Wed, 12 Feb 2020 19:57:04 +0100 Subject: Log Touchpanel data (position + gesture!) --- src/DisplayApp/DisplayApp.cpp | 9 ++----- src/drivers/Cst816s.cpp | 57 ++++++++++++++++++++++++++++++++----------- src/drivers/Cst816s.h | 12 +++++++++ src/main.cpp | 2 +- 4 files changed, 58 insertions(+), 22 deletions(-) (limited to 'src/drivers') diff --git a/src/DisplayApp/DisplayApp.cpp b/src/DisplayApp/DisplayApp.cpp index d29027fb..365855ed 100644 --- a/src/DisplayApp/DisplayApp.cpp +++ b/src/DisplayApp/DisplayApp.cpp @@ -48,11 +48,7 @@ void DisplayApp::Process(void *instance) { while (1) { app->Refresh(); - - auto before = nrf_rtc_counter_get(portNRF_RTC_REG); lv_task_handler(); - auto after = nrf_rtc_counter_get(portNRF_RTC_REG); - NRF_LOG_INFO("duration : %d", (after-before)); } } @@ -77,10 +73,10 @@ void DisplayApp::Refresh() { break; case States::Running: RunningState(); - queueTimeout = 1; + queueTimeout = 1000; break; } -/* + Messages msg; if (xQueueReceive(msgQueue, &msg, queueTimeout)) { switch (msg) { @@ -119,7 +115,6 @@ void DisplayApp::Refresh() { break; } } - */ } bool first = true; diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index 67700f53..b1af12d4 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -50,29 +50,58 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() { nrfx_twi_rx(&twi, address, touchData, 63); auto nbTouchPoints = touchData[2] & 0x0f; - uint8_t i = 0; +// uint8_t i = 0; +// NRF_LOG_INFO("#########################") + for(int i = 0; i < 1; i++) { uint8_t pointId = (touchData[touchIdIndex + (touchStep * i)]) >> 4; if(nbTouchPoints == 0 && pointId == lastTouchId) return info; // We fetch only the first touch point (the controller seems to handle only one anyway...) info.isTouch = true; - auto xHigh = touchData[touchXHighIndex + (touchStep * i)] & 0x0f; - auto xLow = touchData[touchXLowIndex + (touchStep * i)]; - uint16_t x = (xHigh << 8) | xLow; - auto yHigh = touchData[touchYHighIndex + (touchStep * i)] & 0x0f; - auto yLow = touchData[touchYLowIndex + (touchStep * i)]; - uint16_t y = (yHigh << 8) | yLow; + auto xHigh = touchData[touchXHighIndex + (touchStep * i)] & 0x0f; + auto xLow = touchData[touchXLowIndex + (touchStep * i)]; + uint16_t x = (xHigh << 8) | xLow; + + auto yHigh = touchData[touchYHighIndex + (touchStep * i)] & 0x0f; + auto yLow = touchData[touchYLowIndex + (touchStep * i)]; + uint16_t y = (yHigh << 8) | yLow; + + auto action = touchData[touchEventIndex + (touchStep * i)] >> 6; /* 0 = Down, 1 = Up, 2 = contact*/ + auto finger = touchData[touchIdIndex + (touchStep * i)] >> 4; + auto pressure = touchData[touchXYIndex + (touchStep * i)]; + auto area = touchData[touchMiscIndex + (touchStep * i)] >> 4; + + info.x = x; + info.y = y; + info.action = action; + info.gesture = static_cast(touchData[gestureIndex]); + + NRF_LOG_INFO("---------------") + NRF_LOG_INFO("ID : %d", pointId); + NRF_LOG_INFO("NB : %d", nbTouchPoints); + NRF_LOG_INFO("X/Y :%d / %d", info.x, info.y); + NRF_LOG_INFO("Action : %d", action); + NRF_LOG_INFO("Finger : %d", finger); + NRF_LOG_INFO("Pressure : %d", pressure); + NRF_LOG_INFO("area : %d", area); + NRF_LOG_INFO("Touch : %s", info.isTouch?"Yes" : "No"); + switch(info.gesture) {// gesture + case Gestures::None: NRF_LOG_INFO("Gesture : None"); break; + case Gestures::SlideDown: NRF_LOG_INFO("Gesture : Slide Down"); break; + case Gestures::SlideUp: NRF_LOG_INFO("Gesture : Slide Up"); break; + case Gestures::SlideLeft: NRF_LOG_INFO("Gesture : Slide Left"); break; + case Gestures::SlideRight: NRF_LOG_INFO("Gesture : Slide Right"); break; + case Gestures::SingleTap: NRF_LOG_INFO("Gesture : Single click"); break; + case Gestures::DoubleTap: NRF_LOG_INFO("Gesture : Double click"); break; + case Gestures::LongPress: NRF_LOG_INFO("Gesture : Long press"); break; + default : NRF_LOG_INFO("Unknown"); break; + } + + } - auto action = touchData[touchEventIndex + (touchStep * i)] >> 6; /* 0 = Down, 1 = Up, 2 = contact*/ - auto finger = touchData[touchIdIndex + (touchStep * i)] >> 4; - auto pressure = touchData[touchXYIndex + (touchStep * i)]; - auto area = touchData[touchMiscIndex + (touchStep * i)] >> 4; - info.x = x; - info.y = y; - info.action = action; return info; } diff --git a/src/drivers/Cst816s.h b/src/drivers/Cst816s.h index 0adb448b..93b05df1 100644 --- a/src/drivers/Cst816s.h +++ b/src/drivers/Cst816s.h @@ -6,6 +6,16 @@ namespace Pinetime { namespace Drivers { class Cst816S { public : + enum class Gestures : uint8_t { + None = 0x00, + SlideDown = 0x01, + SlideUp = 0x02, + SlideLeft = 0x03, + SlideRight = 0x04, + SingleTap = 0x05, + DoubleTap = 0x0B, + LongPress = 0x0C + }; struct TouchInfos { uint16_t x; uint16_t y; @@ -13,6 +23,7 @@ namespace Pinetime { uint8_t finger; uint8_t pressure; uint8_t area; + Gestures gesture; bool isTouch = false; }; @@ -36,6 +47,7 @@ namespace Pinetime { static constexpr uint8_t touchYLowIndex = 6; static constexpr uint8_t touchIdIndex = 5; static constexpr uint8_t touchStep = 6; + static constexpr uint8_t gestureIndex = 1; uint8_t touchData[63]; diff --git a/src/main.cpp b/src/main.cpp index d655ad33..0d374c6b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -171,7 +171,7 @@ void SystemTask(void *) { while(true) { uint8_t msg; - if (xQueueReceive(systemTaksMsgQueue, &msg, systemTaskSleeping?3600000 : 10)) { + if (xQueueReceive(systemTaksMsgQueue, &msg, systemTaskSleeping?3600000 : 1000)) { SystemTaskMessages message = static_cast(msg); switch(message) { case SystemTaskMessages::GoToRunning: systemTaskSleeping = false; break; -- cgit v1.2.3-70-g09d2 From 167a0ffc873a2442af43d0347efd00f84932b8cc Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 16 Feb 2020 18:32:36 +0100 Subject: Add touch panel port to lvgl. PoC of user interaction with 3 screen (clock, menu and app). --- src/CMakeLists.txt | 17 ++++ src/Components/DateTime/DateTimeController.cpp | 2 +- src/DisplayApp/DisplayApp.cpp | 46 +++++++--- src/DisplayApp/DisplayApp.h | 8 +- src/DisplayApp/LittleVgl.cpp | 38 +++++++- src/DisplayApp/LittleVgl.h | 12 ++- src/DisplayApp/Screens/Clock.cpp | 57 ++++++++++-- src/DisplayApp/Screens/Clock.h | 11 ++- src/DisplayApp/Screens/Message.cpp | 77 +++++++++++++--- src/DisplayApp/Screens/Message.h | 12 ++- src/DisplayApp/Screens/Screen.h | 9 +- src/DisplayApp/Screens/Tab.cpp | 67 ++++++++++++++ src/DisplayApp/Screens/Tab.h | 28 ++++++ src/DisplayApp/Screens/Tile.cpp | 118 +++++++++++++++++++++++++ src/DisplayApp/Screens/Tile.h | 56 ++++++++++++ src/drivers/Cst816s.cpp | 40 ++++----- src/libs/lv_conf.h | 2 +- src/main.cpp | 8 +- 18 files changed, 540 insertions(+), 68 deletions(-) create mode 100644 src/DisplayApp/Screens/Tab.cpp create mode 100644 src/DisplayApp/Screens/Tab.h create mode 100644 src/DisplayApp/Screens/Tile.cpp create mode 100644 src/DisplayApp/Screens/Tile.h (limited to 'src/drivers') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0b220423..a5971f27 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -137,6 +137,19 @@ set(LVGL_SRC libs/lvgl/src/lv_themes/lv_theme_night.h libs/lvgl/src/lv_themes/lv_theme_night.c + libs/lvgl/src/lv_objx/lv_list.c + libs/lvgl/src/lv_objx/lv_list.h + libs/lvgl/src/lv_objx/lv_tileview.c + libs/lvgl/src/lv_objx/lv_tileview.h + libs/lvgl/src/lv_objx/lv_tabview.c + libs/lvgl/src/lv_objx/lv_tabview.h + libs/lvgl/src/lv_objx/lv_btnm.c + libs/lvgl/src/lv_objx/lv_btnm.h + libs/lvgl/src/lv_objx/lv_page.c + libs/lvgl/src/lv_objx/lv_page.h + libs/lvgl/src/lv_objx/lv_img.c + libs/lvgl/src/lv_objx/lv_img.h + ) list(APPEND SOURCE_FILES @@ -148,6 +161,8 @@ list(APPEND SOURCE_FILES DisplayApp/Screens/Screen.cpp DisplayApp/Screens/Clock.cpp DisplayApp/Screens/Message.cpp + DisplayApp/Screens/Tile.cpp + DisplayApp/Screens/Tab.cpp main.cpp drivers/St7789.cpp drivers/SpiMaster.cpp @@ -177,6 +192,8 @@ set(INCLUDE_FILES DisplayApp/Screens/Screen.h DisplayApp/Screens/Clock.h DisplayApp/Screens/Message.h + DisplayApp/Screens/Tile.h + DisplayApp/Screens/Tab.h drivers/St7789.h drivers/SpiMaster.h Components/Gfx/Gfx.h diff --git a/src/Components/DateTime/DateTimeController.cpp b/src/Components/DateTime/DateTimeController.cpp index 81d45416..ed6d70fb 100644 --- a/src/Components/DateTime/DateTimeController.cpp +++ b/src/Components/DateTime/DateTimeController.cpp @@ -49,7 +49,7 @@ void DateTime::UpdateTime(uint32_t systickCounter) { previousSystickCounter = 0xffffff - (rest - systickCounter); } - currentDateTime += std::chrono::milliseconds (systickDelta*10); + currentDateTime += std::chrono::seconds (correctedDelta); auto dp = date::floor(currentDateTime); auto time = date::make_time(currentDateTime-dp); diff --git a/src/DisplayApp/DisplayApp.cpp b/src/DisplayApp/DisplayApp.cpp index 365855ed..959c84a0 100644 --- a/src/DisplayApp/DisplayApp.cpp +++ b/src/DisplayApp/DisplayApp.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include using namespace Pinetime::Applications; @@ -29,14 +31,12 @@ DisplayApp::DisplayApp(Pinetime::Drivers::St7789& lcd, batteryController{batteryController}, bleController{bleController}, dateTimeController{dateTimeController}, - clockScreen{gfx}, - messageScreen{gfx}{ + currentScreen{new Screens::Tile(this, gfx) } { msgQueue = xQueueCreate(queueSize, itemSize); - currentScreen = &clockScreen; } void DisplayApp::Start() { - if (pdPASS != xTaskCreate(DisplayApp::Process, "DisplayApp", 1024, this, 0, &taskHandle)) + if (pdPASS != xTaskCreate(DisplayApp::Process, "DisplayApp", 512, this, 0, &taskHandle)) APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); } @@ -73,7 +73,7 @@ void DisplayApp::Refresh() { break; case States::Running: RunningState(); - queueTimeout = 1000; + queueTimeout = 20; break; } @@ -104,15 +104,17 @@ void DisplayApp::Refresh() { case Messages::UpdateDateTime: break; case Messages::UpdateBleConnection: - clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected : Screens::Clock::BleConnectionStates::NotConnected); +// clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected : Screens::Clock::BleConnectionStates::NotConnected); break; case Messages::UpdateBatteryLevel: - clockScreen.SetBatteryPercentRemaining(batteryController.PercentRemaining()); +// clockScreen.SetBatteryPercentRemaining(batteryController.PercentRemaining()); break; case Messages::TouchEvent: if(state != States::Running) break; OnTouchEvent(); break; + case Messages::ButtonPushed: + currentScreen->OnButtonPushed(); } } } @@ -120,10 +122,26 @@ void DisplayApp::Refresh() { bool first = true; void DisplayApp::RunningState() { - clockScreen.SetCurrentDateTime(dateTimeController.CurrentDateTime()); +// 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; + } + } first = false; } } @@ -144,10 +162,10 @@ void DisplayApp::PushMessage(DisplayApp::Messages msg) { static uint16_t pointColor = 0x07e0; void DisplayApp::OnTouchEvent() { - auto info = touchPanel.GetTouchInfo(); - - if(info.isTouch) { - gfx.FillRectangle(info.x-10, info.y-10, 20,20, pointColor); - pointColor+=10; - } +// auto info = touchPanel.GetTouchInfo(); +// +// if(info.isTouch) { +// gfx.FillRectangle(info.x-10, info.y-10, 20,20, pointColor); +// pointColor+=10; +// } } diff --git a/src/DisplayApp/DisplayApp.h b/src/DisplayApp/DisplayApp.h index 8cd26ce8..f8101536 100644 --- a/src/DisplayApp/DisplayApp.h +++ b/src/DisplayApp/DisplayApp.h @@ -23,7 +23,7 @@ namespace Pinetime { class DisplayApp { public: enum class States {Idle, Running}; - enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent} ; + 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, @@ -60,12 +60,12 @@ namespace Pinetime { Pinetime::Drivers::Cst816S& touchPanel; void OnTouchEvent(); - Screens::Clock clockScreen; - Screens::Message messageScreen; - Screens::Screen* currentScreen = nullptr; + std::unique_ptr currentScreen; static constexpr uint8_t pinLcdBacklight1 = 14; static constexpr uint8_t pinLcdBacklight2 = 22; static constexpr uint8_t pinLcdBacklight3 = 23; + + bool isClock = true; }; } } diff --git a/src/DisplayApp/LittleVgl.cpp b/src/DisplayApp/LittleVgl.cpp index 7830953a..50744acc 100644 --- a/src/DisplayApp/LittleVgl.cpp +++ b/src/DisplayApp/LittleVgl.cpp @@ -17,8 +17,18 @@ static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_colo lvgl->FlushDisplay(area, color_p); } -LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd) : lcd{lcd} { +bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) { + auto* lvgl = static_cast(indev_drv->user_data); + return lvgl->GetTouchPadInfo(data); +} + +LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Drivers::Cst816S& touchPanel) : lcd{lcd}, touchPanel{touchPanel} { lv_init(); + InitDisplay(); + InitTouchpad(); +} + +void LittleVgl::InitDisplay() { lv_theme_t* theme = lv_theme_night_init(10, NULL); lv_theme_set_current(theme); @@ -39,8 +49,16 @@ LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd) : lcd{lcd} { /*Finally register the driver*/ lv_disp_drv_register(&disp_drv); +} +void LittleVgl::InitTouchpad() { + lv_indev_drv_t indev_drv; + lv_indev_drv_init(&indev_drv); + indev_drv.type = LV_INDEV_TYPE_POINTER; + indev_drv.read_cb = touchpad_read; + indev_drv.user_data = this; + lv_indev_drv_register(&indev_drv); } void LittleVgl::FlushDisplay(const lv_area_t *area, lv_color_t *color_p) { @@ -57,3 +75,21 @@ void LittleVgl::FlushDisplay(const lv_area_t *area, lv_color_t *color_p) { * Inform the graphics library that you are ready with the flushing*/ lv_disp_flush_ready(&disp_drv); } + +bool LittleVgl::GetTouchPadInfo(lv_indev_data_t *ptr) { + auto info = touchPanel.GetTouchInfo(); + + if((previousClick.x != info.x || previousClick.y != info.y) && + (info.gesture == Drivers::Cst816S::Gestures::SingleTap)) { + ptr->state = LV_INDEV_STATE_PR; + previousClick.x = ptr->point.x; + previousClick.y = ptr->point.y; + } + else { + ptr->state = LV_INDEV_STATE_REL; + } + + ptr->point.x = info.x; + ptr->point.y = info.y; + return false; +} diff --git a/src/DisplayApp/LittleVgl.h b/src/DisplayApp/LittleVgl.h index cff1c3b1..ef104969 100644 --- a/src/DisplayApp/LittleVgl.h +++ b/src/DisplayApp/LittleVgl.h @@ -2,26 +2,36 @@ #include #include +#include static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p); +static bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); namespace Pinetime { namespace Components { class LittleVgl { public: - LittleVgl(Pinetime::Drivers::St7789& lcd); + LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Drivers::Cst816S& touchPanel); void FlushDisplay(const lv_area_t * area, lv_color_t * color_p); + bool GetTouchPadInfo(lv_indev_data_t *ptr); private: + void InitDisplay(); + void InitTouchpad(); + Pinetime::Drivers::St7789& lcd; + Pinetime::Drivers::Cst816S& touchPanel; + lv_disp_buf_t disp_buf_2; lv_color_t buf2_1[LV_HOR_RES_MAX * 2]; lv_color_t buf2_2[LV_HOR_RES_MAX * 2]; lv_disp_drv_t disp_drv; + lv_point_t previousClick; + }; } diff --git a/src/DisplayApp/Screens/Clock.cpp b/src/DisplayApp/Screens/Clock.cpp index a413476a..8513d3ed 100644 --- a/src/DisplayApp/Screens/Clock.cpp +++ b/src/DisplayApp/Screens/Clock.cpp @@ -4,12 +4,24 @@ #include #include #include "Clock.h" +#include "../DisplayApp.h" using namespace Pinetime::Applications::Screens; extern lv_font_t jetbrains_mono_extrabold_compressedextrabold_compressed; extern lv_font_t jetbrains_mono_bold_20; -Clock::Clock(Pinetime::Components::Gfx &gfx) : Screen(gfx), currentDateTime{{}}, version {{}} { +static void event_handler(lv_obj_t * obj, lv_event_t event) { + Clock* screen = static_cast(obj->user_data); + screen->OnObjectEvent(obj, event); +} + +Clock::Clock(DisplayApp* app, Pinetime::Components::Gfx &gfx, Controllers::DateTime& dateTimeController) : Screen(app, gfx), currentDateTime{{}}, version {{}}, dateTimeController{dateTimeController} { + displayedChar[0] = 0; + displayedChar[1] = 0; + displayedChar[2] = 0; + displayedChar[3] = 0; + displayedChar[4] = 0; + label_battery = lv_label_create(lv_scr_act(), NULL); lv_obj_align(label_battery, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -80, 0); @@ -38,11 +50,24 @@ Clock::Clock(Pinetime::Components::Gfx &gfx) : Screen(gfx), currentDateTime{{}}, lv_label_set_style(label_version, LV_LABEL_STYLE_MAIN, labelStyle); lv_obj_align(label_version, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 100); + backgroundLabel = lv_label_create(lv_scr_act(), NULL); + backgroundLabel->user_data = this; + lv_label_set_style(backgroundLabel, LV_LABEL_STYLE_MAIN, labelStyle); + lv_obj_set_click(backgroundLabel, true); + lv_obj_set_event_cb(backgroundLabel, event_handler); + lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP); + lv_obj_set_size(backgroundLabel, 240, 240); + lv_obj_set_pos(backgroundLabel, 0, 0); + lv_label_set_text(backgroundLabel, ""); +} + +Clock::~Clock() { + lv_obj_clean(lv_scr_act()); } void Clock::Refresh(bool fullRefresh) { if(fullRefresh) { - auto dummy = currentDateTime.Get(); + auto currentDateTime = dateTimeController.CurrentDateTime(); } if (fullRefresh || batteryPercentRemaining.IsUpdated()) { @@ -62,6 +87,8 @@ void Clock::Refresh(bool fullRefresh) { // TODO color } + currentDateTime = dateTimeController.CurrentDateTime(); + if(fullRefresh || currentDateTime.IsUpdated()) { auto newDateTime = currentDateTime.Get(); @@ -86,10 +113,17 @@ void Clock::Refresh(bool fullRefresh) { char timeStr[6]; sprintf(timeStr, "%c%c:%c%c", hoursChar[0],hoursChar[1],minutesChar[0], minutesChar[1]); - lv_label_set_text(label_time, timeStr); + + if(hoursChar[0] != displayedChar[0] || hoursChar[1] != displayedChar[1] || minutesChar[0] != displayedChar[2] || minutesChar[1] != displayedChar[3]) { + displayedChar[0] = hoursChar[0]; + displayedChar[1] = hoursChar[1]; + displayedChar[2] = minutesChar[0]; + displayedChar[3] = minutesChar[1]; + + lv_label_set_text(label_time, timeStr); + } if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { - gfx.FillRectangle(0,180, 240, 15, 0x0000); char dateStr[22]; sprintf(dateStr, "%s %d %s %d", DayOfWeekToString(dayOfWeek), day, MonthToString(month), year); lv_label_set_text(label_date, dateStr); @@ -103,9 +137,10 @@ void Clock::Refresh(bool fullRefresh) { } if(fullRefresh || version.IsUpdated()) { - char version[20]; - sprintf(version, "VERSION: %d.%d.%d", Version::Major(), Version::Minor(), Version::Patch()); - lv_label_set_text(label_version, version); + auto dummy = version.Get(); + char versionStr[20]; + sprintf(versionStr, "VERSION: %d.%d.%d", Version::Major(), Version::Minor(), Version::Patch()); + lv_label_set_text(label_version, versionStr); } } @@ -145,4 +180,12 @@ char const *Clock::MonthsString[] = { "DEC" }; +void Clock::OnObjectEvent(lv_obj_t *obj, lv_event_t event) { + if(obj == backgroundLabel) { + if (event == LV_EVENT_CLICKED) { + nextScreen = NextScreen::Menu; + } + } +} + diff --git a/src/DisplayApp/Screens/Clock.h b/src/DisplayApp/Screens/Clock.h index f5328535..d6e5a288 100644 --- a/src/DisplayApp/Screens/Clock.h +++ b/src/DisplayApp/Screens/Clock.h @@ -21,7 +21,7 @@ namespace Pinetime { explicit DirtyValue(T v) { value = v; } explicit DirtyValue(T& v) { value = v; } bool IsUpdated() const { return isUpdated; } - T& Get() { return value; this->isUpdated = false;} + T& Get() { this->isUpdated = false; return value; } DirtyValue& operator=(const T& other) { this->value = other; @@ -35,19 +35,23 @@ namespace Pinetime { class Clock : public Screen{ public: enum class BleConnectionStates{ NotConnected, Connected}; - Clock(Components::Gfx& gfx); + Clock(DisplayApp* app, Components::Gfx& gfx, Controllers::DateTime& dateTimeController); + ~Clock() override; void Refresh(bool fullRefresh) override; void SetBatteryPercentRemaining(uint8_t percent) { batteryPercentRemaining = percent; } void SetBleConnectionState(BleConnectionStates state) { bleState = state; } void SetCurrentDateTime(const std::chrono::time_point& tp) { currentDateTime = tp;} + void OnObjectEvent(lv_obj_t *pObj, lv_event_t i); private: static const char* MonthToString(Pinetime::Controllers::DateTime::Months month); static const char* DayOfWeekToString(Pinetime::Controllers::DateTime::Days dayOfWeek); static char const *DaysString[]; static char const *MonthsString[]; + 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}; @@ -69,6 +73,9 @@ namespace Pinetime { lv_obj_t* label_time; lv_obj_t* label_date; lv_obj_t* label_version; + lv_obj_t* backgroundLabel; + + Controllers::DateTime& dateTimeController; }; } diff --git a/src/DisplayApp/Screens/Message.cpp b/src/DisplayApp/Screens/Message.cpp index 8ffad413..c9e0938f 100644 --- a/src/DisplayApp/Screens/Message.cpp +++ b/src/DisplayApp/Screens/Message.cpp @@ -5,24 +5,77 @@ #include #include #include +#include #include "Message.h" +#include + using namespace Pinetime::Applications::Screens; -extern lv_font_t jetbrains_mono_extrabold_compressedextrabold_compressed; +extern lv_font_t jetbrains_mono_bold_20; + +static void event_handler(lv_obj_t * obj, lv_event_t event) { + Message* screen = static_cast(obj->user_data); + screen->OnObjectEvent(obj, event); +} + +Message::Message(DisplayApp* app, Pinetime::Components::Gfx &gfx) : Screen(app, gfx) { + + backgroundLabel = lv_label_create(lv_scr_act(), NULL); + backgroundLabel->user_data = this; + + labelStyle = const_cast(lv_label_get_style(backgroundLabel, LV_LABEL_STYLE_MAIN)); + labelStyle->text.font = &jetbrains_mono_bold_20; + + lv_label_set_style(backgroundLabel, LV_LABEL_STYLE_MAIN, labelStyle); + lv_obj_set_click(backgroundLabel, true); + lv_obj_set_event_cb(backgroundLabel, event_handler); + lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP); + lv_obj_set_size(backgroundLabel, 240, 240); + lv_obj_set_pos(backgroundLabel, 0, 0); + lv_label_set_text(backgroundLabel, ""); +// lv_obj_align(backgroundLabel, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); + + button = lv_btn_create(lv_scr_act(), NULL); + lv_obj_set_event_cb(button, event_handler); + lv_obj_align(button, NULL, LV_ALIGN_CENTER, 0, -40); + button->user_data = this; + + label = lv_label_create(button, NULL); + lv_label_set_style(label, LV_LABEL_STYLE_MAIN, labelStyle); + lv_label_set_text(label, "Hello!"); + + labelClick = lv_label_create(lv_scr_act(), NULL); + lv_label_set_style(labelClick, LV_LABEL_STYLE_MAIN, labelStyle); + lv_obj_align(labelClick, button, LV_ALIGN_OUT_BOTTOM_MID, 0, 30); + lv_label_set_text(labelClick, "0"); +} + +Message::~Message() { + lv_obj_clean(lv_scr_act()); +} -lv_obj_t * label; -int x = 0; void Message::Refresh(bool fullRefresh) { - if(fullRefresh) { - label = lv_label_create(lv_scr_act(), NULL); /*Add a label to the button*/ - labelStyle = const_cast(lv_label_get_style(label, LV_LABEL_STYLE_MAIN)); - labelStyle->text.font = &jetbrains_mono_extrabold_compressedextrabold_compressed; - lv_label_set_style(label, LV_LABEL_STYLE_MAIN, labelStyle); - lv_label_set_text(label, "01:23"); /*Set the labels text*/ - } else { - lv_obj_set_pos(label, 0, x++); - if(x > 200) x = 0; + if(previousClickCount != clickCount) { + lv_label_set_text_fmt(labelClick, "%d", clickCount); + previousClickCount = clickCount; } +} +void Message::OnObjectEvent(lv_obj_t *obj, lv_event_t event) { + if(obj == backgroundLabel) { + if(event == LV_EVENT_CLICKED) { + app->PushMessage(DisplayApp::Messages::SwitchScreen); + NRF_LOG_INFO("SCREEN"); + } + return ; + } + + if(event == LV_EVENT_CLICKED) { + NRF_LOG_INFO("Clicked"); + clickCount++; + } + else if(event == LV_EVENT_VALUE_CHANGED) { + NRF_LOG_INFO("Toggled"); + } } diff --git a/src/DisplayApp/Screens/Message.h b/src/DisplayApp/Screens/Message.h index 419c2e62..2f1da942 100644 --- a/src/DisplayApp/Screens/Message.h +++ b/src/DisplayApp/Screens/Message.h @@ -15,14 +15,24 @@ namespace Pinetime { namespace Screens { class Message : public Screen{ public: - Message(Components::Gfx& gfx) : Screen(gfx) {} + explicit Message(DisplayApp* app, Components::Gfx& gfx); + ~Message() override; void Refresh(bool fullRefresh) override; + void OnObjectEvent(lv_obj_t* obj, lv_event_t event); + void OnButtonPushed() override { nextScreen = Screen::NextScreen::Menu; } 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_obj_t * label; + lv_obj_t* backgroundLabel; + lv_obj_t * button; + lv_obj_t * labelClick; + + uint32_t clickCount = 0 ; + uint32_t previousClickCount = 0; }; } } diff --git a/src/DisplayApp/Screens/Screen.h b/src/DisplayApp/Screens/Screen.h index 5e2fa43e..57b8ea2a 100644 --- a/src/DisplayApp/Screens/Screen.h +++ b/src/DisplayApp/Screens/Screen.h @@ -4,14 +4,21 @@ namespace Pinetime { namespace Applications { + class DisplayApp; namespace Screens { class Screen { public: - Screen(Components::Gfx& gfx) : gfx{gfx} {} + enum class NextScreen {None, Clock, Menu, App}; + Screen(DisplayApp* app, Components::Gfx& gfx) : app{app}, gfx{gfx} {} + virtual ~Screen() = default; virtual void Refresh(bool fullRefresh) = 0; + NextScreen GetNextScreen() {return nextScreen;} + virtual void OnButtonPushed() {}; protected: + DisplayApp* app; Components::Gfx& gfx; + NextScreen nextScreen = NextScreen::None; }; } } diff --git a/src/DisplayApp/Screens/Tab.cpp b/src/DisplayApp/Screens/Tab.cpp new file mode 100644 index 00000000..adc32578 --- /dev/null +++ b/src/DisplayApp/Screens/Tab.cpp @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "Tab.h" +#include + + +using namespace Pinetime::Applications::Screens; + +extern lv_font_t jetbrains_mono_bold_20; + +//static void event_handler(lv_obj_t * obj, lv_event_t event) { +// Tile* screen = static_cast(obj->user_data); +// screen->OnObjectEvent(obj, event); +//} + +Tab::Tab(DisplayApp* app, Pinetime::Components::Gfx &gfx) : Screen(app, gfx) { +/*Create a Tab view object*/ + lv_obj_t *tabview; + tabview = lv_tabview_create(lv_scr_act(), NULL); + + /*Add 3 tabs (the tabs are page (lv_page) and can be scrolled*/ + lv_obj_t *tab1 = lv_tabview_add_tab(tabview, "Tab 1"); + lv_obj_t *tab2 = lv_tabview_add_tab(tabview, "Tab 2"); + lv_obj_t *tab3 = lv_tabview_add_tab(tabview, "Tab 3"); + + + /*Add content to the tabs*/ + lv_obj_t * label = lv_label_create(tab1, NULL); + lv_label_set_text(label, "This the first tab\n\n" + "If the content\n" + "of a tab\n" + "become too long\n" + "the it \n" + "automatically\n" + "become\n" + "scrollable."); + + label = lv_label_create(tab2, NULL); + lv_label_set_text(label, "Second tab"); + + label = lv_label_create(tab3, NULL); + lv_label_set_text(label, "Third tab"); + +} + +Tab::~Tab() { + lv_obj_clean(lv_scr_act()); +} + +void Tab::Refresh(bool fullRefresh) { + +} + +void Tab::OnObjectEvent(lv_obj_t *obj, lv_event_t event) { + if(event == LV_EVENT_CLICKED) { + NRF_LOG_INFO("Clicked"); + } + else if(event == LV_EVENT_VALUE_CHANGED) { + NRF_LOG_INFO("Toggled"); + } +} diff --git a/src/DisplayApp/Screens/Tab.h b/src/DisplayApp/Screens/Tab.h new file mode 100644 index 00000000..1af956f4 --- /dev/null +++ b/src/DisplayApp/Screens/Tab.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include "Screen.h" +#include +#include "../Fonts/lcdfont14.h" +#include "../Fonts/lcdfont70.h" +#include "../../Version.h" +#include + +namespace Pinetime { + namespace Applications { + namespace Screens { + class Tab : public Screen { + public: + explicit Tab(DisplayApp* app, Components::Gfx& gfx); + ~Tab() override; + void Refresh(bool fullRefresh) override; + void OnObjectEvent(lv_obj_t* obj, lv_event_t event); + + private: + + }; + } + } +} diff --git a/src/DisplayApp/Screens/Tile.cpp b/src/DisplayApp/Screens/Tile.cpp new file mode 100644 index 00000000..d89562c7 --- /dev/null +++ b/src/DisplayApp/Screens/Tile.cpp @@ -0,0 +1,118 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "Tile.h" +#include +#include + + +using namespace Pinetime::Applications::Screens; + +extern lv_font_t jetbrains_mono_bold_20; + +static void event_handler(lv_obj_t * obj, lv_event_t event) { + Tile* screen = static_cast(obj->user_data); + screen->OnObjectEvent(obj, event); +} + +//static const char * btnm_map1[] = {"App1", "App2", "App3", "\n", "App4", "App5", "App11", ""}; +//static const char * btnm_map2[] = {"App6", "App7", "App8", "\n", "App9", "App10", "App22",""}; +static const char * btnm_map1[] = {"App1", ""}; + +Tile::Tile(DisplayApp* app, Pinetime::Components::Gfx &gfx) : Screen(app, gfx) { + + 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); + lv_tileview_set_edge_flash(tileview, false); + + tile1 = lv_obj_create(tileview, NULL); + lv_obj_set_pos(tile1, 0, 0); + lv_obj_set_size(tile1, LV_HOR_RES, LV_VER_RES); + lv_tileview_add_element(tileview, tile1); + + btnm1 = lv_btnm_create(tile1, NULL); + lv_btnm_set_map(btnm1, btnm_map1); + lv_obj_set_size(btnm1, LV_HOR_RES, LV_VER_RES); + + labelStyle = const_cast(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); + + lv_obj_align(btnm1, tile1, LV_ALIGN_CENTER, 0, 0); + btnm1->user_data = this; + lv_obj_set_event_cb(btnm1, event_handler); +/* + tile2 = lv_obj_create(tileview, NULL); + lv_obj_set_pos(tile2, 0, LV_VER_RES); + lv_obj_set_size(tile2, LV_HOR_RES, LV_VER_RES); + lv_tileview_add_element(tileview, tile2); + + btnm2 = lv_btnm_create(tileview, NULL); + lv_btnm_set_map(btnm2, btnm_map2); + lv_obj_align(btnm2, tile2, LV_ALIGN_CENTER, 0, 0); +*/ +/* + tile1 = lv_obj_create(tileview, NULL); + lv_obj_set_pos(tile1, 0, 0); + lv_obj_set_size(tile1, LV_HOR_RES, LV_VER_RES); + lv_tileview_add_element(tileview, tile1); + + btn1 = lv_btn_create(tile1, NULL); + lv_obj_align(btn1, tile1, LV_ALIGN_CENTER, 0, 0); + + label1 = lv_label_create(btn1, NULL); + lv_label_set_text(label1, "Button1"); +*/ +/* + tile2 = lv_obj_create(tileview, NULL); + lv_obj_set_pos(tile2, 0, LV_VER_RES); + lv_obj_set_size(tile2, LV_HOR_RES, LV_VER_RES); + lv_tileview_add_element(tileview, tile2); + + btn2 = lv_btn_create(tile2, NULL); + lv_obj_align(btn2, tile2, LV_ALIGN_CENTER, 0, 0); + + + label2 = lv_label_create(btn2, NULL); + lv_label_set_text(label2, "Button2"); + + tile3 = lv_obj_create(tileview, NULL); + lv_obj_set_pos(tile3, 0, LV_VER_RES*2); + lv_obj_set_size(tile3, LV_HOR_RES, LV_VER_RES); + lv_tileview_add_element(tileview, tile3); + + btn3 = lv_btn_create(tile3, NULL); + lv_obj_align(btn3, tile3, LV_ALIGN_CENTER, 0, 0); + + + label3 = lv_label_create(btn3, NULL); + lv_label_set_text(label3, "Button3"); +*/ +} + +Tile::~Tile() { + lv_obj_clean(lv_scr_act()); +} + +void Tile::Refresh(bool fullRefresh) { + +} + +void Tile::OnObjectEvent(lv_obj_t *obj, lv_event_t event) { + if(event == LV_EVENT_CLICKED) { + NRF_LOG_INFO("Clicked"); + nextScreen = Screen::NextScreen::App; + clickCount++; + } + else if(event == LV_EVENT_VALUE_CHANGED) { + NRF_LOG_INFO("Toggled"); + } +} diff --git a/src/DisplayApp/Screens/Tile.h b/src/DisplayApp/Screens/Tile.h new file mode 100644 index 00000000..c9de2c5c --- /dev/null +++ b/src/DisplayApp/Screens/Tile.h @@ -0,0 +1,56 @@ +#pragma once + +#include +#include +#include +#include "Screen.h" +#include +#include "../Fonts/lcdfont14.h" +#include "../Fonts/lcdfont70.h" +#include "../../Version.h" +#include + +namespace Pinetime { + namespace Applications { + namespace Screens { + class Tile : public Screen { + public: + explicit Tile(DisplayApp* app, Components::Gfx& gfx); + ~Tile() override; + void Refresh(bool fullRefresh) 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_obj_t * label1; + lv_obj_t * label2; + lv_obj_t * label3; + + lv_obj_t* backgroundLabel; + lv_obj_t * button; + lv_obj_t * labelClick; + + lv_obj_t *tileview; + lv_obj_t * tile1; + lv_obj_t * tile2; + lv_obj_t * list; + lv_obj_t * list_btn; + lv_obj_t * tile3; + lv_obj_t * btn1; + lv_obj_t * btn2; + lv_obj_t * btn3; + + lv_obj_t * btnm1; + lv_obj_t * btnm2; + + uint32_t clickCount = 0 ; + uint32_t previousClickCount = 0; + }; + } + } +} diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index b1af12d4..61bce94c 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -78,26 +78,26 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() { info.action = action; info.gesture = static_cast(touchData[gestureIndex]); - NRF_LOG_INFO("---------------") - NRF_LOG_INFO("ID : %d", pointId); - NRF_LOG_INFO("NB : %d", nbTouchPoints); - NRF_LOG_INFO("X/Y :%d / %d", info.x, info.y); - NRF_LOG_INFO("Action : %d", action); - NRF_LOG_INFO("Finger : %d", finger); - NRF_LOG_INFO("Pressure : %d", pressure); - NRF_LOG_INFO("area : %d", area); - NRF_LOG_INFO("Touch : %s", info.isTouch?"Yes" : "No"); - switch(info.gesture) {// gesture - case Gestures::None: NRF_LOG_INFO("Gesture : None"); break; - case Gestures::SlideDown: NRF_LOG_INFO("Gesture : Slide Down"); break; - case Gestures::SlideUp: NRF_LOG_INFO("Gesture : Slide Up"); break; - case Gestures::SlideLeft: NRF_LOG_INFO("Gesture : Slide Left"); break; - case Gestures::SlideRight: NRF_LOG_INFO("Gesture : Slide Right"); break; - case Gestures::SingleTap: NRF_LOG_INFO("Gesture : Single click"); break; - case Gestures::DoubleTap: NRF_LOG_INFO("Gesture : Double click"); break; - case Gestures::LongPress: NRF_LOG_INFO("Gesture : Long press"); break; - default : NRF_LOG_INFO("Unknown"); break; - } +// NRF_LOG_INFO("---------------") +// NRF_LOG_INFO("ID : %d", pointId); +// NRF_LOG_INFO("NB : %d", nbTouchPoints); +// NRF_LOG_INFO("X/Y :%d / %d", info.x, info.y); +// NRF_LOG_INFO("Action : %d", action); +// NRF_LOG_INFO("Finger : %d", finger); +// NRF_LOG_INFO("Pressure : %d", pressure); +// NRF_LOG_INFO("area : %d", area); +// NRF_LOG_INFO("Touch : %s", info.isTouch?"Yes" : "No"); +// switch(info.gesture) {// gesture +// case Gestures::None: NRF_LOG_INFO("Gesture : None"); break; +// case Gestures::SlideDown: NRF_LOG_INFO("Gesture : Slide Down"); break; +// case Gestures::SlideUp: NRF_LOG_INFO("Gesture : Slide Up"); break; +// case Gestures::SlideLeft: NRF_LOG_INFO("Gesture : Slide Left"); break; +// case Gestures::SlideRight: NRF_LOG_INFO("Gesture : Slide Right"); break; +// case Gestures::SingleTap: NRF_LOG_INFO("Gesture : Single click"); break; +// case Gestures::DoubleTap: NRF_LOG_INFO("Gesture : Double click"); break; +// case Gestures::LongPress: NRF_LOG_INFO("Gesture : Long press"); break; +// default : NRF_LOG_INFO("Unknown"); break; +// } } diff --git a/src/libs/lv_conf.h b/src/libs/lv_conf.h index 603339ee..8d7a6f7e 100644 --- a/src/libs/lv_conf.h +++ b/src/libs/lv_conf.h @@ -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 300 +# define LV_TILEVIEW_DEF_ANIM_TIME 0 #endif /*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/ diff --git a/src/main.cpp b/src/main.cpp index 0d374c6b..2a272677 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -82,7 +82,7 @@ extern "C" { void DebounceTimerCallback(TimerHandle_t xTimer) { xTimerStop(xTimer, 0); - if(isSleeping) { + /*if(isSleeping) { SystemTask_PushMessage(SystemTaskMessages::GoToRunning); displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::GoToRunning); isSleeping = false; @@ -93,7 +93,8 @@ void DebounceTimerCallback(TimerHandle_t xTimer) { 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) { @@ -126,8 +127,9 @@ void SystemTask(void *) { lcd.reset(new Pinetime::Drivers::St7789(*spi, pinLcdDataCommand)); gfx.reset(new Pinetime::Components::Gfx(*lcd)); - lvgl.reset(new Pinetime::Components::LittleVgl(*lcd)); touchPanel.reset(new Pinetime::Drivers::Cst816S()); + + lvgl.reset(new Pinetime::Components::LittleVgl(*lcd, *touchPanel)); ptrLcd = lcd.get(); spi->Init(); -- cgit v1.2.3-70-g09d2 From 0aa1803ea22b119401bcd2e4d9d5278e8386f151 Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 23 Feb 2020 21:09:11 +0100 Subject: Enable watchdog, and issue a WDT reset when the button is pushed for more than 7s. --- src/CMakeLists.txt | 4 +-- src/SystemTask/SystemTask.cpp | 8 +++++- src/SystemTask/SystemTask.h | 2 ++ src/drivers/Watchdog.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++ src/drivers/Watchdog.h | 17 ++++++++++++ src/libs/lvgl | 2 +- 6 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 src/drivers/Watchdog.cpp create mode 100644 src/drivers/Watchdog.h (limited to 'src/drivers') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3fb4dd6e..6b5c5741 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -160,11 +160,10 @@ list(APPEND SOURCE_FILES DisplayApp/Screens/Clock.cpp DisplayApp/Screens/Message.cpp DisplayApp/Screens/Tile.cpp -# DisplayApp/Screens/Tab.cpp main.cpp drivers/St7789.cpp drivers/SpiMaster.cpp -# Components/Gfx/Gfx.cpp + drivers/Watchdog.cpp BLE/BleManager.c Components/Battery/BatteryController.cpp Components/Ble/BleController.cpp @@ -194,6 +193,7 @@ set(INCLUDE_FILES # DisplayApp/Screens/Tab.h drivers/St7789.h drivers/SpiMaster.h + drivers/Watchdog.h BLE/BleManager.h Components/Battery/BatteryController.h Components/Ble/BleController.h diff --git a/src/SystemTask/SystemTask.cpp b/src/SystemTask/SystemTask.cpp index 91822fa2..e15846da 100644 --- a/src/SystemTask/SystemTask.cpp +++ b/src/SystemTask/SystemTask.cpp @@ -29,6 +29,9 @@ void SystemTask::Process(void *instance) { } void SystemTask::Work() { + watchdog.Setup(7); + watchdog.Start(); + NRF_LOG_INFO("Last reset reason : %s", Pinetime::Drivers::Watchdog::ResetReasonToString(watchdog.ResetReason())); APP_GPIOTE_INIT(2); bool erase_bonds=false; nrf_sdh_freertos_init(ble_manager_start_advertising, &erase_bonds); @@ -70,7 +73,7 @@ void SystemTask::Work() { while(true) { uint8_t msg; - if (xQueueReceive(systemTaksMsgQueue, &msg, isSleeping?3600000 : 1000)) { + if (xQueueReceive(systemTaksMsgQueue, &msg, isSleeping?2500 : 1000)) { Messages message = static_cast(msg); switch(message) { case Messages::GoToRunning: isSleeping = false; break; @@ -83,6 +86,9 @@ void SystemTask::Work() { } uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG); dateTimeController.UpdateTime(systick_counter); + + if(!nrf_gpio_pin_read(pinButton)) + watchdog.Kick(); } } diff --git a/src/SystemTask/SystemTask.h b/src/SystemTask/SystemTask.h index cb913545..f5ba2d75 100644 --- a/src/SystemTask/SystemTask.h +++ b/src/SystemTask/SystemTask.h @@ -7,6 +7,7 @@ #include #include #include +#include namespace Pinetime { namespace System { @@ -41,6 +42,7 @@ namespace Pinetime { Pinetime::Controllers::DateTime& dateTimeController; QueueHandle_t systemTaksMsgQueue; bool isSleeping = false; + Pinetime::Drivers::Watchdog watchdog; static constexpr uint8_t pinSpiSck = 2; diff --git a/src/drivers/Watchdog.cpp b/src/drivers/Watchdog.cpp new file mode 100644 index 00000000..b0dc12e5 --- /dev/null +++ b/src/drivers/Watchdog.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include "Watchdog.h" +using namespace Pinetime::Drivers; + + +void Watchdog::Setup(uint8_t timeoutSeconds) { + NRF_WDT->CONFIG &= ~(WDT_CONFIG_SLEEP_Msk << WDT_CONFIG_SLEEP_Pos); + NRF_WDT->CONFIG |= (WDT_CONFIG_HALT_Run << WDT_CONFIG_SLEEP_Pos); + + NRF_WDT->CONFIG &= ~(WDT_CONFIG_HALT_Msk << WDT_CONFIG_HALT_Pos); + NRF_WDT->CONFIG |= (WDT_CONFIG_HALT_Pause << WDT_CONFIG_HALT_Pos); + + /* timeout (s) = (CRV + 1) / 32768 */ + // JF : 7500 = 7.5s + uint32_t crv = (((timeoutSeconds*1000u) << 15u) / 1000) - 1; + NRF_WDT->CRV = crv; + + /* Enable reload requests */ + NRF_WDT->RREN = (WDT_RREN_RR0_Enabled << WDT_RREN_RR0_Pos); +} + +void Watchdog::Start() { + NRF_WDT->TASKS_START = 1; +} + +void Watchdog::Kick() { + NRF_WDT->RR[0] = WDT_RR_RR_Reload; +} + +Watchdog::ResetReasons Watchdog::ResetReason() { + uint32_t resetReason; + sd_power_reset_reason_get(&resetReason); + sd_power_reset_reason_clr(0xFFFFFFFF); + if(resetReason & 0x01) return ResetReasons::ResetPin; + if((resetReason >> 1) & 0x01) return ResetReasons::Watchdog; + if((resetReason >> 2) & 0x01) return ResetReasons::SoftReset; + if((resetReason >> 3) & 0x01) return ResetReasons::CpuLockup; + if((resetReason >> 16) & 0x01) return ResetReasons::SystemOff; + if((resetReason >> 17) & 0x01) return ResetReasons::LpComp; + if((resetReason >> 18) & 0x01) return ResetReasons::DebugInterface; + if((resetReason >> 19) & 0x01) return ResetReasons::NFC; + return ResetReasons::HardReset; +} + +const char *Watchdog::ResetReasonToString(Watchdog::ResetReasons reason) { + switch(reason) { + case ResetReasons::ResetPin: return "Reset pin"; + case ResetReasons::Watchdog: return "Watchdog"; + case ResetReasons::DebugInterface: return "Debug interface"; + case ResetReasons::LpComp: return "LPCOMP"; + case ResetReasons::SystemOff: return "System OFF"; + case ResetReasons::CpuLockup: return "CPU Lock-up"; + case ResetReasons::SoftReset: return "Soft reset"; + case ResetReasons::NFC: return "NFC"; + case ResetReasons::HardReset: return "Hard reset"; + default: return "Unknown"; + } +} diff --git a/src/drivers/Watchdog.h b/src/drivers/Watchdog.h new file mode 100644 index 00000000..da192d9e --- /dev/null +++ b/src/drivers/Watchdog.h @@ -0,0 +1,17 @@ +#pragma once + +namespace Pinetime { + namespace Drivers { + class Watchdog { + public: + enum class ResetReasons { ResetPin, Watchdog, SoftReset, CpuLockup, SystemOff, LpComp, DebugInterface, NFC, HardReset }; + void Setup(uint8_t timeoutSeconds); + void Start(); + void Kick(); + + ResetReasons ResetReason(); + static const char* ResetReasonToString(ResetReasons reason); + + }; + } +} diff --git a/src/libs/lvgl b/src/libs/lvgl index 10b9c9b2..ee95d1c9 160000 --- a/src/libs/lvgl +++ b/src/libs/lvgl @@ -1 +1 @@ -Subproject commit 10b9c9b2f5344e7b2f5cc00a19ed86ed56ae9866 +Subproject commit ee95d1c9cf74899585f9165458911f2d54ca7500 -- cgit v1.2.3-70-g09d2 From 6f1857c50397aa26d1b16ded6bbb4e6952f3762e Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 1 Mar 2020 21:00:59 +0100 Subject: Add debugPins module that provides functions to set and clear debug GPIOs. Disable logging once again. --- CMakeLists.txt | 9 +++++++++ src/CMakeLists.txt | 2 ++ src/drivers/DebugPins.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++ src/drivers/DebugPins.h | 25 ++++++++++++++++++++++++ src/sdk_config.h | 6 +++--- 5 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 src/drivers/DebugPins.cpp create mode 100644 src/drivers/DebugPins.h (limited to 'src/drivers') diff --git a/CMakeLists.txt b/CMakeLists.txt index a874a9e7..3e36bff4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,10 @@ if(USE_OPENOCD) endif() endif() +if(DEFINED USE_DEBUG_PINS AND USE_DEBUG_PINS) + add_definitions(-DUSE_DEBUG_PINS) +endif() + message("BUILD CONFIGURATION") message("-------------------") message(" * Version : " ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) @@ -53,6 +57,11 @@ elseif(USE_GDB_CLIENT) elseif(USE_OPENOCD) message(" * Programmer/debugger : OpenOCD Client") endif() +if(USE_DEBUG_PINS) + message(" * Debug pins : Enabled") +else() + message(" * Debug pins : Disabled") +endif() set(VERSION_EDIT_WARNING "// Do not edit this file, it is automatically generated by CMAKE!") configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/Version.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/Version.h) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ac19cf09..86ef8869 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -178,6 +178,7 @@ list(APPEND SOURCE_FILES drivers/St7789.cpp drivers/SpiMaster.cpp drivers/Watchdog.cpp + drivers/DebugPins.cpp BLE/BleManager.c Components/Battery/BatteryController.cpp Components/Ble/BleController.cpp @@ -211,6 +212,7 @@ set(INCLUDE_FILES drivers/St7789.h drivers/SpiMaster.h drivers/Watchdog.h + drivers/DebugPins.h BLE/BleManager.h Components/Battery/BatteryController.h Components/Ble/BleController.h diff --git a/src/drivers/DebugPins.cpp b/src/drivers/DebugPins.cpp new file mode 100644 index 00000000..5a12fd86 --- /dev/null +++ b/src/drivers/DebugPins.cpp @@ -0,0 +1,49 @@ +#include +#include "DebugPins.h" + +#ifdef USE_DEBUG_PINS +void debugpins_init() { + nrf_gpio_cfg_output(DebugPin0); + nrf_gpio_pin_clear(DebugPin0); + + nrf_gpio_cfg_output(DebugPin1); + nrf_gpio_pin_clear(DebugPin1); + + nrf_gpio_cfg_output(DebugPin2); + nrf_gpio_pin_clear(DebugPin2); + + nrf_gpio_cfg_output(DebugPin3); + nrf_gpio_pin_clear(DebugPin3); + + nrf_gpio_cfg_output(DebugPin4); + nrf_gpio_pin_clear(DebugPin4); +} +void debugpins_set(debugpins_pins pin) { + nrf_gpio_pin_set((uint32_t)(pin)); +} + +void debugpins_clear(debugpins_pins pin) { + nrf_gpio_pin_clear((uint32_t)(pin)); +} + +void debugpins_pulse(debugpins_pins pin) { + nrf_gpio_pin_set((uint32_t)(pin)); + nrf_gpio_pin_clear((uint32_t)(pin)); +} +#else +void debugpins_init() { + +} +void debugpins_set(debugpins_pins pin) { + +} + +void debugpins_clear(debugpins_pins pin) { + +} + +void debugpins_pulse(debugpins_pins pin) { + +} + +#endif \ No newline at end of file diff --git a/src/drivers/DebugPins.h b/src/drivers/DebugPins.h new file mode 100644 index 00000000..cb20bac5 --- /dev/null +++ b/src/drivers/DebugPins.h @@ -0,0 +1,25 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +typedef enum { + DebugPin0 = 27, + DebugPin1 = 29, + DebugPin2 = 20, + DebugPin3 = 17, + DebugPin4 = 11, +} debugpins_pins; + +void debugpins_init(); +void debugpins_set(debugpins_pins pin); +void debugpins_clear(debugpins_pins pin); +void debugpins_pulse(debugpins_pins pin); + +#ifdef __cplusplus +} +#endif + diff --git a/src/sdk_config.h b/src/sdk_config.h index d1570718..bf0d7bf6 100644 --- a/src/sdk_config.h +++ b/src/sdk_config.h @@ -8452,15 +8452,15 @@ // NRF_LOG_ENABLED - nrf_log - Logger //========================================================== #ifndef NRF_LOG_ENABLED -#define NRF_LOG_ENABLED 1 +#define NRF_LOG_ENABLED 0 #endif #ifndef NRF_LOG_BACKEND_RTT_ENABLED -#define NRF_LOG_BACKEND_RTT_ENABLED 1 +#define NRF_LOG_BACKEND_RTT_ENABLED 0 #endif #ifndef NRF_LOG_BACKEND_SERIAL_USES_RTT -#define NRF_LOG_BACKEND_SERIAL_USES_RTT 1 +#define NRF_LOG_BACKEND_SERIAL_USES_RTT 0s #endif // Log message pool - Configuration of log message pool -- cgit v1.2.3-70-g09d2