From fe64176e7b8a0a7a9df733701d08762b60c2511f Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Thu, 15 Jul 2021 14:11:27 +0300 Subject: [PATCH 01/31] New touch handler, with issues --- src/CMakeLists.txt | 4 + src/displayapp/DisplayApp.cpp | 124 +++++++++--------- src/displayapp/DisplayApp.h | 8 +- src/displayapp/LittleVgl.cpp | 9 +- src/displayapp/LittleVgl.h | 2 +- src/displayapp/Messages.h | 3 +- src/displayapp/screens/FirmwareValidation.cpp | 4 +- src/displayapp/screens/List.cpp | 2 +- src/displayapp/screens/Metronome.cpp | 3 - src/displayapp/screens/ScreenList.h | 2 +- src/displayapp/screens/StopWatch.cpp | 4 +- src/displayapp/screens/SystemInfo.cpp | 6 +- src/displayapp/screens/Tile.cpp | 10 +- src/displayapp/screens/Tile.h | 2 +- .../screens/settings/QuickSettings.cpp | 6 +- .../screens/settings/SettingDisplay.cpp | 4 +- src/drivers/Cst816s.cpp | 12 +- src/main.cpp | 11 +- src/systemtask/SystemTask.cpp | 1 - src/touchhandler/TouchHandler.cpp | 70 ++++++++++ src/touchhandler/TouchHandler.h | 45 +++++++ 21 files changed, 230 insertions(+), 102 deletions(-) create mode 100644 src/touchhandler/TouchHandler.cpp create mode 100644 src/touchhandler/TouchHandler.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 40e1f2a5..cbc8cadc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -495,6 +495,8 @@ list(APPEND SOURCE_FILES components/heartrate/Biquad.cpp components/heartrate/Ptagc.cpp components/heartrate/HeartRateController.cpp + + touchhandler/TouchHandler.cpp ) list(APPEND RECOVERY_SOURCE_FILES @@ -552,6 +554,7 @@ list(APPEND RECOVERY_SOURCE_FILES components/heartrate/Ptagc.cpp components/motor/MotorController.cpp components/fs/FS.cpp + touchhandler/TouchHandler.cpp ) list(APPEND RECOVERYLOADER_SOURCE_FILES @@ -660,6 +663,7 @@ set(INCLUDE_FILES components/heartrate/Ptagc.h components/heartrate/HeartRateController.h components/motor/MotorController.h + touchhandler/TouchHandler.h ) include_directories( diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 071af0c8..ca7e390f 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -66,7 +66,8 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd, Controllers::Settings& settingsController, Pinetime::Controllers::MotorController& motorController, Pinetime::Controllers::MotionController& motionController, - Pinetime::Controllers::TimerController& timerController) + Pinetime::Controllers::TimerController& timerController, + Pinetime::Controllers::TouchHandler& touchHandler) : lcd {lcd}, lvgl {lvgl}, touchPanel {touchPanel}, @@ -79,7 +80,8 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd, settingsController {settingsController}, motorController {motorController}, motionController {motionController}, - timerController {timerController} { + timerController {timerController}, + touchHandler {touchHandler} { } void DisplayApp::Start() { @@ -176,33 +178,6 @@ void DisplayApp::Refresh() { LoadApp(Apps::Timer, DisplayApp::FullRefreshDirections::Down); } break; - case Messages::TouchEvent: { - if (state != States::Running) - break; - auto gesture = OnTouchEvent(); - if (!currentScreen->OnTouchEvent(gesture)) { - if (currentApp == Apps::Clock) { - switch (gesture) { - case TouchEvents::SwipeUp: - LoadApp(Apps::Launcher, DisplayApp::FullRefreshDirections::Up); - break; - case TouchEvents::SwipeDown: - LoadApp(Apps::Notifications, DisplayApp::FullRefreshDirections::Down); - break; - case TouchEvents::SwipeRight: - LoadApp(Apps::QuickSettings, DisplayApp::FullRefreshDirections::RightAnim); - break; - case TouchEvents::DoubleTap: - PushMessageToSystemTask(System::Messages::GoToSleep); - break; - default: - break; - } - } else if (returnTouchEvent == gesture) { - LoadApp(returnToApp, returnDirection); - } - } - } break; case Messages::ButtonPushed: if (currentApp == Apps::Clock) { PushMessageToSystemTask(System::Messages::GoToSleep); @@ -223,18 +198,41 @@ void DisplayApp::Refresh() { } } - if(nextApp != Apps::None) { - LoadApp(nextApp, nextDirection); - nextApp = Apps::None; + auto gesture = GetGesture(); + if (gesture != TouchEvents::None) { + if (!currentScreen->OnTouchEvent(gesture)) { + if (currentApp == Apps::Clock) { + switch (gesture) { + case TouchEvents::SwipeUp: + LoadApp(Apps::Launcher, DisplayApp::FullRefreshDirections::Up); + break; + case TouchEvents::SwipeDown: + LoadApp(Apps::Notifications, DisplayApp::FullRefreshDirections::Down); + break; + case TouchEvents::SwipeRight: + LoadApp(Apps::QuickSettings, DisplayApp::FullRefreshDirections::RightAnim); + break; + case TouchEvents::DoubleTap: + PushMessageToSystemTask(System::Messages::GoToSleep); + break; + default: + break; + } + } else if (returnTouchEvent == gesture) { + LoadApp(returnToApp, returnDirection); + } + } else { + touchHandler.CancelTap(); + } } - if (state != States::Idle && touchMode == TouchModes::Polling) { - auto info = touchPanel.GetTouchInfo(); - if (info.action == 2) { // 2 = contact - if (!currentScreen->OnTouchEvent(info.x, info.y)) { - lvgl.SetNewTapEvent(info.x, info.y); - } - } + if (touchMode == TouchModes::Polling) { + currentScreen->OnTouchEvent(touchHandler.GetX(), touchHandler.GetY()); + } + + if (nextApp != Apps::None) { + LoadApp(nextApp, nextDirection); + nextApp = Apps::None; } } @@ -257,6 +255,7 @@ void DisplayApp::ReturnApp(Apps app, DisplayApp::FullRefreshDirections direction } void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) { + touchHandler.CancelTap(); currentScreen.reset(nullptr); SetFullRefresh(direction); @@ -395,31 +394,28 @@ void DisplayApp::PushMessage(Messages msg) { } } -TouchEvents DisplayApp::OnTouchEvent() { - auto info = touchPanel.GetTouchInfo(); - if (info.isTouch) { - switch (info.gesture) { - case Pinetime::Drivers::Cst816S::Gestures::SingleTap: - if (touchMode == TouchModes::Gestures) { - lvgl.SetNewTapEvent(info.x, info.y); - } - return TouchEvents::Tap; - case Pinetime::Drivers::Cst816S::Gestures::LongPress: - return TouchEvents::LongTap; - case Pinetime::Drivers::Cst816S::Gestures::DoubleTap: - return TouchEvents::DoubleTap; - case Pinetime::Drivers::Cst816S::Gestures::SlideRight: - return TouchEvents::SwipeRight; - case Pinetime::Drivers::Cst816S::Gestures::SlideLeft: - return TouchEvents::SwipeLeft; - case Pinetime::Drivers::Cst816S::Gestures::SlideDown: - return TouchEvents::SwipeDown; - case Pinetime::Drivers::Cst816S::Gestures::SlideUp: - return TouchEvents::SwipeUp; - case Pinetime::Drivers::Cst816S::Gestures::None: - default: - return TouchEvents::None; - } +TouchEvents DisplayApp::GetGesture() { + auto gesture = touchHandler.GestureGet(); + switch (gesture) { + /* + case Pinetime::Drivers::Cst816S::Gestures::SingleTap: + return TouchEvents::Tap; + */ + case Pinetime::Drivers::Cst816S::Gestures::LongPress: + return TouchEvents::LongTap; + case Pinetime::Drivers::Cst816S::Gestures::DoubleTap: + return TouchEvents::DoubleTap; + case Pinetime::Drivers::Cst816S::Gestures::SlideRight: + return TouchEvents::SwipeRight; + case Pinetime::Drivers::Cst816S::Gestures::SlideLeft: + return TouchEvents::SwipeLeft; + case Pinetime::Drivers::Cst816S::Gestures::SlideDown: + return TouchEvents::SwipeDown; + case Pinetime::Drivers::Cst816S::Gestures::SlideUp: + return TouchEvents::SwipeUp; + case Pinetime::Drivers::Cst816S::Gestures::None: + default: + return TouchEvents::None; } return TouchEvents::None; } diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index f4573ab7..74fc4456 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -14,6 +14,7 @@ #include "components/settings/Settings.h" #include "displayapp/screens/Screen.h" #include "components/timer/TimerController.h" +#include "touchhandler/TouchHandler.h" #include "Messages.h" namespace Pinetime { @@ -31,6 +32,7 @@ namespace Pinetime { class NotificationManager; class HeartRateController; class MotionController; + class TouchHandler; } namespace System { @@ -55,7 +57,8 @@ namespace Pinetime { Controllers::Settings& settingsController, Pinetime::Controllers::MotorController& motorController, Pinetime::Controllers::MotionController& motionController, - Pinetime::Controllers::TimerController& timerController); + Pinetime::Controllers::TimerController& timerController, + Pinetime::Controllers::TouchHandler& touchHandler); void Start(); void PushMessage(Display::Messages msg); @@ -81,6 +84,7 @@ namespace Pinetime { Pinetime::Controllers::MotorController& motorController; Pinetime::Controllers::MotionController& motionController; Pinetime::Controllers::TimerController& timerController; + Pinetime::Controllers::TouchHandler& touchHandler; Pinetime::Controllers::FirmwareValidator validator; Controllers::BrightnessController brightnessController; @@ -102,7 +106,7 @@ namespace Pinetime { TouchModes touchMode = TouchModes::Gestures; - TouchEvents OnTouchEvent(); + TouchEvents GetGesture(); void RunningState(); void IdleState(); static void Process(void* instance); diff --git a/src/displayapp/LittleVgl.cpp b/src/displayapp/LittleVgl.cpp index c069afa2..d0c6161e 100644 --- a/src/displayapp/LittleVgl.cpp +++ b/src/displayapp/LittleVgl.cpp @@ -166,18 +166,17 @@ void LittleVgl::FlushDisplay(const lv_area_t* area, lv_color_t* color_p) { lv_disp_flush_ready(&disp_drv); } -void LittleVgl::SetNewTapEvent(uint16_t x, uint16_t y) { +void LittleVgl::SetNewTapEvent(uint16_t x, uint16_t y, bool contact) { tap_x = x; tap_y = y; - tapped = true; + tapped = contact; } bool LittleVgl::GetTouchPadInfo(lv_indev_data_t* ptr) { + ptr->point.x = tap_x; + ptr->point.y = tap_y; if (tapped) { - ptr->point.x = tap_x; - ptr->point.y = tap_y; ptr->state = LV_INDEV_STATE_PR; - tapped = false; } else { ptr->state = LV_INDEV_STATE_REL; } diff --git a/src/displayapp/LittleVgl.h b/src/displayapp/LittleVgl.h index 41f934a7..8d1ed56f 100644 --- a/src/displayapp/LittleVgl.h +++ b/src/displayapp/LittleVgl.h @@ -24,7 +24,7 @@ namespace Pinetime { void FlushDisplay(const lv_area_t* area, lv_color_t* color_p); bool GetTouchPadInfo(lv_indev_data_t* ptr); void SetFullRefresh(FullRefreshDirections direction); - void SetNewTapEvent(uint16_t x, uint16_t y); + void SetNewTapEvent(uint16_t x, uint16_t y, bool contact); private: void InitDisplay(); diff --git a/src/displayapp/Messages.h b/src/displayapp/Messages.h index ce65f846..3b8bad27 100644 --- a/src/displayapp/Messages.h +++ b/src/displayapp/Messages.h @@ -8,7 +8,6 @@ namespace Pinetime { UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, - TouchEvent, ButtonPushed, NewNotification, TimerDone, @@ -17,4 +16,4 @@ namespace Pinetime { }; } } -} \ No newline at end of file +} diff --git a/src/displayapp/screens/FirmwareValidation.cpp b/src/displayapp/screens/FirmwareValidation.cpp index 1d05be8d..5bacb4e8 100644 --- a/src/displayapp/screens/FirmwareValidation.cpp +++ b/src/displayapp/screens/FirmwareValidation.cpp @@ -66,10 +66,10 @@ bool FirmwareValidation::Refresh() { } void FirmwareValidation::OnButtonEvent(lv_obj_t* object, lv_event_t event) { - if (object == buttonValidate && event == LV_EVENT_PRESSED) { + if (object == buttonValidate && event == LV_EVENT_CLICKED) { validator.Validate(); running = false; - } else if (object == buttonReset && event == LV_EVENT_PRESSED) { + } else if (object == buttonReset && event == LV_EVENT_CLICKED) { validator.Reset(); } } diff --git a/src/displayapp/screens/List.cpp b/src/displayapp/screens/List.cpp index b4f4d2cf..1f92634a 100644 --- a/src/displayapp/screens/List.cpp +++ b/src/displayapp/screens/List.cpp @@ -108,7 +108,7 @@ bool List::Refresh() { } void List::OnButtonEvent(lv_obj_t* object, lv_event_t event) { - if (event == LV_EVENT_RELEASED) { + if (event == LV_EVENT_CLICKED) { for (int i = 0; i < MAXLISTITEMS; i++) { if (apps[i] != Apps::None && object == itemApps[i]) { app->StartApp(apps[i], DisplayApp::FullRefreshDirections::Up); diff --git a/src/displayapp/screens/Metronome.cpp b/src/displayapp/screens/Metronome.cpp index 7bfbccb7..15916b62 100644 --- a/src/displayapp/screens/Metronome.cpp +++ b/src/displayapp/screens/Metronome.cpp @@ -83,12 +83,9 @@ Metronome::Metronome(DisplayApp* app, Controllers::MotorController& motorControl lv_obj_set_height(playPause, 39); playPauseLabel = lv_label_create(playPause, nullptr); lv_label_set_text(playPauseLabel, Symbols::play); - - app->SetTouchMode(DisplayApp::TouchModes::Polling); } Metronome::~Metronome() { - app->SetTouchMode(DisplayApp::TouchModes::Gestures); systemTask.PushMessage(System::Messages::EnableSleeping); lv_obj_clean(lv_scr_act()); } diff --git a/src/displayapp/screens/ScreenList.h b/src/displayapp/screens/ScreenList.h index ea66bfb2..50d66328 100644 --- a/src/displayapp/screens/ScreenList.h +++ b/src/displayapp/screens/ScreenList.h @@ -110,4 +110,4 @@ namespace Pinetime { }; } } -} \ No newline at end of file +} diff --git a/src/displayapp/screens/StopWatch.cpp b/src/displayapp/screens/StopWatch.cpp index f4db5d6e..e3db6299 100644 --- a/src/displayapp/screens/StopWatch.cpp +++ b/src/displayapp/screens/StopWatch.cpp @@ -161,7 +161,7 @@ bool StopWatch::Refresh() { } void StopWatch::playPauseBtnEventHandler(lv_event_t event) { - if (event != LV_EVENT_PRESSED) { + if (event != LV_EVENT_CLICKED) { return; } if (currentState == States::Init) { @@ -174,7 +174,7 @@ void StopWatch::playPauseBtnEventHandler(lv_event_t event) { } void StopWatch::stopLapBtnEventHandler(lv_event_t event) { - if (event != LV_EVENT_PRESSED) { + if (event != LV_EVENT_CLICKED) { return; } // If running, then this button is used to save laps diff --git a/src/displayapp/screens/SystemInfo.cpp b/src/displayapp/screens/SystemInfo.cpp index f5bf0cc9..47a49180 100644 --- a/src/displayapp/screens/SystemInfo.cpp +++ b/src/displayapp/screens/SystemInfo.cpp @@ -210,7 +210,7 @@ bool SystemInfo::sortById(const TaskStatus_t& lhs, const TaskStatus_t& rhs) { } std::unique_ptr SystemInfo::CreateScreen4() { - TaskStatus_t tasksStatus[7]; + TaskStatus_t tasksStatus[10]; lv_obj_t* infoTask = lv_table_create(lv_scr_act(), NULL); lv_table_set_col_cnt(infoTask, 3); lv_table_set_row_cnt(infoTask, 8); @@ -223,9 +223,9 @@ std::unique_ptr SystemInfo::CreateScreen4() { lv_table_set_cell_value(infoTask, 0, 2, "Free"); lv_table_set_col_width(infoTask, 2, 90); - auto nb = uxTaskGetSystemState(tasksStatus, 7, nullptr); + auto nb = uxTaskGetSystemState(tasksStatus, sizeof(tasksStatus) / sizeof(tasksStatus[0]), nullptr); std::sort(tasksStatus, tasksStatus + nb, sortById); - for (uint8_t i = 0; i < nb; i++) { + for (uint8_t i = 0; i < nb && i < 7; i++) { lv_table_set_cell_value(infoTask, i + 1, 0, std::to_string(tasksStatus[i].xTaskNumber).c_str()); lv_table_set_cell_value(infoTask, i + 1, 1, tasksStatus[i].pcTaskName); diff --git a/src/displayapp/screens/Tile.cpp b/src/displayapp/screens/Tile.cpp index 3eb127cc..5a40e915 100644 --- a/src/displayapp/screens/Tile.cpp +++ b/src/displayapp/screens/Tile.cpp @@ -12,9 +12,7 @@ namespace { static void event_handler(lv_obj_t* obj, lv_event_t event) { Tile* screen = static_cast(obj->user_data); - uint32_t* eventDataPtr = (uint32_t*) lv_event_get_data(); - uint32_t eventData = *eventDataPtr; - screen->OnObjectEvent(obj, event, eventData); + screen->OnObjectEvent(obj, event); } } @@ -124,9 +122,9 @@ bool Tile::Refresh() { return running; } -void Tile::OnObjectEvent(lv_obj_t* obj, lv_event_t event, uint32_t buttonId) { - if (event == LV_EVENT_VALUE_CHANGED) { - app->StartApp(apps[buttonId], DisplayApp::FullRefreshDirections::Up); +void Tile::OnObjectEvent(lv_obj_t* obj, lv_event_t event) { + if (event == LV_EVENT_CLICKED) { + app->StartApp(apps[lv_btnmatrix_get_active_btn(obj)], DisplayApp::FullRefreshDirections::Up); running = false; } } diff --git a/src/displayapp/screens/Tile.h b/src/displayapp/screens/Tile.h index 4ebd81cd..91ce9d01 100644 --- a/src/displayapp/screens/Tile.h +++ b/src/displayapp/screens/Tile.h @@ -32,7 +32,7 @@ namespace Pinetime { bool Refresh() override; void UpdateScreen(); - void OnObjectEvent(lv_obj_t* obj, lv_event_t event, uint32_t buttonId); + void OnObjectEvent(lv_obj_t* obj, lv_event_t event); private: Pinetime::Controllers::Battery& batteryController; diff --git a/src/displayapp/screens/settings/QuickSettings.cpp b/src/displayapp/screens/settings/QuickSettings.cpp index acc2a27a..2da5ca27 100644 --- a/src/displayapp/screens/settings/QuickSettings.cpp +++ b/src/displayapp/screens/settings/QuickSettings.cpp @@ -125,12 +125,12 @@ void QuickSettings::UpdateScreen() { } void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) { - if (object == btn2 && event == LV_EVENT_PRESSED) { + if (object == btn2 && event == LV_EVENT_CLICKED) { running = false; app->StartApp(Apps::FlashLight, DisplayApp::FullRefreshDirections::None); - } else if (object == btn1 && event == LV_EVENT_PRESSED) { + } else if (object == btn1 && event == LV_EVENT_CLICKED) { brightness.Step(); lv_label_set_text_static(btn1_lvl, brightness.GetIcon()); @@ -147,7 +147,7 @@ void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) { lv_label_set_text_static(btn3_lvl, Symbols::notificationsOff); } - } else if (object == btn4 && event == LV_EVENT_PRESSED) { + } else if (object == btn4 && event == LV_EVENT_CLICKED) { running = false; settingsController.SetSettingsMenu(0); app->StartApp(Apps::Settings, DisplayApp::FullRefreshDirections::Up); diff --git a/src/displayapp/screens/settings/SettingDisplay.cpp b/src/displayapp/screens/settings/SettingDisplay.cpp index 4954185d..aaf6a9f0 100644 --- a/src/displayapp/screens/settings/SettingDisplay.cpp +++ b/src/displayapp/screens/settings/SettingDisplay.cpp @@ -85,7 +85,7 @@ bool SettingDisplay::Refresh() { } void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) { - if (event == LV_EVENT_VALUE_CHANGED) { + if (event == LV_EVENT_CLICKED) { for (int i = 0; i < optionsTotal; i++) { if (object == cbOption[i]) { lv_checkbox_set_checked(cbOption[i], true); @@ -110,4 +110,4 @@ void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) { } } } -} \ No newline at end of file +} diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index fd9792b3..adb984e0 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -40,6 +40,16 @@ void Cst816S::Init() { */ static constexpr uint8_t motionMask = 0b00000101; twiMaster.Write(twiAddress, 0xEC, &motionMask, 1); + + /* + [7] EnTest - Interrupt pin to test, enable automatic periodic issued after a low pulse. + [6] EnTouch - When a touch is detected, a periodic pulsed Low. + [5] EnChange - Upon detecting a touch state changes, pulsed Low. + [4] EnMotion - When the detected gesture is pulsed Low. + [0] OnceWLP - Press gesture only issue a pulse signal is low. + */ + static constexpr uint8_t irqCtl = 0b01110000; + twiMaster.Write(twiAddress, 0xFA, &irqCtl, 1); } Cst816S::TouchInfos Cst816S::GetTouchInfo() { @@ -90,4 +100,4 @@ void Cst816S::Sleep() { void Cst816S::Wakeup() { Init(); NRF_LOG_INFO("[TOUCHPANEL] Wakeup"); -} \ No newline at end of file +} diff --git a/src/main.cpp b/src/main.cpp index ffbba5e7..f427db40 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,6 +43,7 @@ #include "drivers/TwiMaster.h" #include "drivers/Cst816s.h" #include "systemtask/SystemTask.h" +#include "touchhandler/TouchHandler.h" #if NRF_LOG_ENABLED #include "logging/NrfLogger.h" @@ -118,6 +119,7 @@ Pinetime::Drivers::WatchdogView watchdogView(watchdog); Pinetime::Controllers::NotificationManager notificationManager; Pinetime::Controllers::MotionController motionController; Pinetime::Controllers::TimerController timerController; +Pinetime::Controllers::TouchHandler touchHandler(touchPanel, lvgl); Pinetime::Controllers::FS fs {spiNorFlash}; Pinetime::Controllers::Settings settingsController {fs}; @@ -136,7 +138,8 @@ Pinetime::Applications::DisplayApp displayApp(lcd, settingsController, motorController, motionController, - timerController); + timerController, + touchHandler); Pinetime::System::SystemTask systemTask(spi, lcd, @@ -162,7 +165,7 @@ Pinetime::System::SystemTask systemTask(spi, void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { if (pin == pinTouchIrq) { - systemTask.OnTouchEvent(); + touchHandler.WakeUp(); return; } @@ -309,6 +312,10 @@ int main(void) { lvgl.Init(); systemTask.Start(); + + touchHandler.Register(&systemTask); + touchHandler.Start(); + nimble_port_init(); vTaskStartScheduler(); diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index d8b965b1..f6aee785 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -397,7 +397,6 @@ void SystemTask::OnTouchEvent() { return; if (!isSleeping) { PushMessage(Messages::OnTouchEvent); - displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent); } else if (!isWakingUp) { if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap) or settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) { diff --git a/src/touchhandler/TouchHandler.cpp b/src/touchhandler/TouchHandler.cpp new file mode 100644 index 00000000..a13d1af3 --- /dev/null +++ b/src/touchhandler/TouchHandler.cpp @@ -0,0 +1,70 @@ +#include "TouchHandler.h" + +using namespace Pinetime::Controllers; + +TouchHandler::TouchHandler(Drivers::Cst816S& touchPanel, Components::LittleVgl& lvgl) + : touchPanel {touchPanel}, + lvgl {lvgl} { +} + +void TouchHandler::CancelTap() { + isCancelled = true; + lvgl.SetNewTapEvent(-1, -1, false); +} + +Pinetime::Drivers::Cst816S::Gestures TouchHandler::GestureGet() { + auto returnGesture = gesture; + gesture = Drivers::Cst816S::Gestures::None; + return returnGesture; +} + +void TouchHandler::Start() { + if (pdPASS != xTaskCreate(TouchHandler::Process, "Touch", 80, this, 0, &taskHandle)) { + APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); + } +} + +void TouchHandler::Process(void* instance) { + auto* app = static_cast(instance); + app->Work(); +} + +void TouchHandler::Work() { + Pinetime::Drivers::Cst816S::TouchInfos info; + while (true) { + vTaskSuspend(taskHandle); + info = touchPanel.GetTouchInfo(); + if (systemTask->IsSleeping()) { + systemTask->PushMessage(System::Messages::TouchWakeUp); + } else { + x = info.x; + y = info.y; + if (info.action == 0) { + lvgl.SetNewTapEvent(info.x, info.y, true); + } else if (info.action == 1) { + lvgl.SetNewTapEvent(info.x, info.y, false); + prevGesture = Pinetime::Drivers::Cst816S::Gestures::None; + isCancelled = false; + } else if (info.action == 2) { + if (!isCancelled) { + lvgl.SetNewTapEvent(info.x, info.y, true); + } + if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) { + if (prevGesture != info.gesture) { + prevGesture = info.gesture; + gesture = info.gesture; + } + } + } + systemTask->OnTouchEvent(); + } + } +} + +void TouchHandler::Register(Pinetime::System::SystemTask* systemTask) { + this->systemTask = systemTask; +} + +void TouchHandler::WakeUp() { + vTaskResume(taskHandle); +} diff --git a/src/touchhandler/TouchHandler.h b/src/touchhandler/TouchHandler.h new file mode 100644 index 00000000..7999e00a --- /dev/null +++ b/src/touchhandler/TouchHandler.h @@ -0,0 +1,45 @@ +#pragma once +#include "drivers/Cst816s.h" +#include "systemtask/SystemTask.h" +#include +#include + +namespace Pinetime { + namespace Components { + class LittleVgl; + } + namespace Drivers { + class Cst816S; + } + namespace System { + class SystemTask; + } + namespace Controllers { + class TouchHandler { + public: + explicit TouchHandler(Drivers::Cst816S&, Components::LittleVgl&); + void CancelTap(); + void Register(Pinetime::System::SystemTask* systemTask); + void Start(); + void WakeUp(); + uint8_t GetX() const { + return x; + } + uint8_t GetY() const { + return y; + } + Drivers::Cst816S::Gestures GestureGet(); + private: + static void Process(void* instance); + void Work(); + Pinetime::System::SystemTask* systemTask = nullptr; + TaskHandle_t taskHandle; + Pinetime::Drivers::Cst816S& touchPanel; + Pinetime::Components::LittleVgl& lvgl; + Pinetime::Drivers::Cst816S::Gestures gesture; + Pinetime::Drivers::Cst816S::Gestures prevGesture; + bool isCancelled = false; + uint8_t x, y; + }; + } +} From 0d24d2b81e995d37bb7fb363df21a19b195107b8 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Thu, 15 Jul 2021 23:18:05 +0300 Subject: [PATCH 02/31] Quick fix --- src/drivers/Cst816s.cpp | 2 +- src/touchhandler/TouchHandler.cpp | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index adb984e0..127fe1ec 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -81,7 +81,7 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() { info.x = x; info.y = y; - info.action = action; + info.finger = nbTouchPoints; info.gesture = static_cast(touchData[gestureIndex]); return info; diff --git a/src/touchhandler/TouchHandler.cpp b/src/touchhandler/TouchHandler.cpp index a13d1af3..90b4d6da 100644 --- a/src/touchhandler/TouchHandler.cpp +++ b/src/touchhandler/TouchHandler.cpp @@ -39,13 +39,11 @@ void TouchHandler::Work() { } else { x = info.x; y = info.y; - if (info.action == 0) { - lvgl.SetNewTapEvent(info.x, info.y, true); - } else if (info.action == 1) { + if (info.finger == 0) { lvgl.SetNewTapEvent(info.x, info.y, false); prevGesture = Pinetime::Drivers::Cst816S::Gestures::None; isCancelled = false; - } else if (info.action == 2) { + } else if (info.finger == 1) { if (!isCancelled) { lvgl.SetNewTapEvent(info.x, info.y, true); } From 2a3e1263906d1145d6b539ff019362f0077d8097 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Fri, 16 Jul 2021 00:07:55 +0300 Subject: [PATCH 03/31] Fix most issues --- src/displayapp/DisplayApp.cpp | 11 ++--------- src/displayapp/DisplayApp.h | 4 ---- src/displayapp/LittleVgl.cpp | 2 +- src/displayapp/LittleVgl.h | 2 +- src/displayapp/screens/InfiniPaint.cpp | 3 --- src/displayapp/screens/Metronome.cpp | 2 +- src/displayapp/screens/Paddle.cpp | 4 ---- src/displayapp/screens/Screen.h | 1 + src/drivers/Cst816s.cpp | 26 +++++++++----------------- src/drivers/Cst816s.h | 26 ++++++++++++-------------- src/systemtask/SystemTask.cpp | 2 +- src/touchhandler/TouchHandler.cpp | 20 ++++++++++++-------- 12 files changed, 40 insertions(+), 63 deletions(-) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index ca7e390f..945f182a 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -226,9 +226,7 @@ void DisplayApp::Refresh() { } } - if (touchMode == TouchModes::Polling) { - currentScreen->OnTouchEvent(touchHandler.GetX(), touchHandler.GetY()); - } + currentScreen->OnTouchEvent(touchHandler.GetX(), touchHandler.GetY()); if (nextApp != Apps::None) { LoadApp(nextApp, nextDirection); @@ -367,6 +365,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) break; case Apps::Metronome: currentScreen = std::make_unique(this, motorController, *systemTask); + ReturnApp(Apps::Launcher, FullRefreshDirections::Down, TouchEvents::None); break; case Apps::Motion: currentScreen = std::make_unique(this, motionController); @@ -397,10 +396,8 @@ void DisplayApp::PushMessage(Messages msg) { TouchEvents DisplayApp::GetGesture() { auto gesture = touchHandler.GestureGet(); switch (gesture) { - /* case Pinetime::Drivers::Cst816S::Gestures::SingleTap: return TouchEvents::Tap; - */ case Pinetime::Drivers::Cst816S::Gestures::LongPress: return TouchEvents::LongTap; case Pinetime::Drivers::Cst816S::Gestures::DoubleTap: @@ -445,10 +442,6 @@ void DisplayApp::SetFullRefresh(DisplayApp::FullRefreshDirections direction) { } } -void DisplayApp::SetTouchMode(DisplayApp::TouchModes mode) { - touchMode = mode; -} - void DisplayApp::PushMessageToSystemTask(Pinetime::System::Messages message) { if(systemTask != nullptr) systemTask->PushMessage(message); diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index 74fc4456..96951d1c 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -43,7 +43,6 @@ namespace Pinetime { public: enum class States { Idle, Running }; enum class FullRefreshDirections { None, Up, Down, Left, Right, LeftAnim, RightAnim }; - enum class TouchModes { Gestures, Polling }; DisplayApp(Drivers::St7789& lcd, Components::LittleVgl& lvgl, @@ -65,7 +64,6 @@ namespace Pinetime { void StartApp(Apps app, DisplayApp::FullRefreshDirections direction); void SetFullRefresh(FullRefreshDirections direction); - void SetTouchMode(TouchModes mode); void Register(Pinetime::System::SystemTask* systemTask); @@ -104,8 +102,6 @@ namespace Pinetime { FullRefreshDirections returnDirection = FullRefreshDirections::None; TouchEvents returnTouchEvent = TouchEvents::None; - TouchModes touchMode = TouchModes::Gestures; - TouchEvents GetGesture(); void RunningState(); void IdleState(); diff --git a/src/displayapp/LittleVgl.cpp b/src/displayapp/LittleVgl.cpp index d0c6161e..b5669713 100644 --- a/src/displayapp/LittleVgl.cpp +++ b/src/displayapp/LittleVgl.cpp @@ -166,7 +166,7 @@ void LittleVgl::FlushDisplay(const lv_area_t* area, lv_color_t* color_p) { lv_disp_flush_ready(&disp_drv); } -void LittleVgl::SetNewTapEvent(uint16_t x, uint16_t y, bool contact) { +void LittleVgl::SetNewTouchPoint(uint16_t x, uint16_t y, bool contact) { tap_x = x; tap_y = y; tapped = contact; diff --git a/src/displayapp/LittleVgl.h b/src/displayapp/LittleVgl.h index 8d1ed56f..1f8a3d79 100644 --- a/src/displayapp/LittleVgl.h +++ b/src/displayapp/LittleVgl.h @@ -24,7 +24,7 @@ namespace Pinetime { void FlushDisplay(const lv_area_t* area, lv_color_t* color_p); bool GetTouchPadInfo(lv_indev_data_t* ptr); void SetFullRefresh(FullRefreshDirections direction); - void SetNewTapEvent(uint16_t x, uint16_t y, bool contact); + void SetNewTouchPoint(uint16_t x, uint16_t y, bool contact); private: void InitDisplay(); diff --git a/src/displayapp/screens/InfiniPaint.cpp b/src/displayapp/screens/InfiniPaint.cpp index 32240084..58bfa558 100644 --- a/src/displayapp/screens/InfiniPaint.cpp +++ b/src/displayapp/screens/InfiniPaint.cpp @@ -5,13 +5,10 @@ using namespace Pinetime::Applications::Screens; InfiniPaint::InfiniPaint(Pinetime::Applications::DisplayApp* app, Pinetime::Components::LittleVgl& lvgl) : Screen(app), lvgl {lvgl} { - app->SetTouchMode(DisplayApp::TouchModes::Polling); std::fill(b, b + bufferSize, selectColor); } InfiniPaint::~InfiniPaint() { - // Reset the touchmode - app->SetTouchMode(DisplayApp::TouchModes::Gestures); lv_obj_clean(lv_scr_act()); } diff --git a/src/displayapp/screens/Metronome.cpp b/src/displayapp/screens/Metronome.cpp index 15916b62..3e3f478e 100644 --- a/src/displayapp/screens/Metronome.cpp +++ b/src/displayapp/screens/Metronome.cpp @@ -91,7 +91,7 @@ Metronome::~Metronome() { } bool Metronome::OnTouchEvent(Pinetime::Applications::TouchEvents event) { - return true; + return false; } bool Metronome::Refresh() { diff --git a/src/displayapp/screens/Paddle.cpp b/src/displayapp/screens/Paddle.cpp index 5a939ac7..79e0c3d3 100644 --- a/src/displayapp/screens/Paddle.cpp +++ b/src/displayapp/screens/Paddle.cpp @@ -5,8 +5,6 @@ using namespace Pinetime::Applications::Screens; Paddle::Paddle(Pinetime::Applications::DisplayApp* app, Pinetime::Components::LittleVgl& lvgl) : Screen(app), lvgl {lvgl} { - app->SetTouchMode(DisplayApp::TouchModes::Polling); - background = lv_obj_create(lv_scr_act(), nullptr); lv_obj_set_size(background, LV_HOR_RES + 1, LV_VER_RES); lv_obj_set_pos(background, -1, 0); @@ -32,8 +30,6 @@ Paddle::Paddle(Pinetime::Applications::DisplayApp* app, Pinetime::Components::Li } Paddle::~Paddle() { - // Reset the touchmode - app->SetTouchMode(DisplayApp::TouchModes::Gestures); lv_obj_clean(lv_scr_act()); } diff --git a/src/displayapp/screens/Screen.h b/src/displayapp/screens/Screen.h index 8e49c9de..6567a20c 100644 --- a/src/displayapp/screens/Screen.h +++ b/src/displayapp/screens/Screen.h @@ -60,6 +60,7 @@ namespace Pinetime { } /** @return false if the event hasn't been handled by the app, true if it has been handled */ + // Returning true will cancel lvgl tap virtual bool OnTouchEvent(TouchEvents event) { return false; } diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index 127fe1ec..b8f8e45d 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -56,32 +56,24 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() { Cst816S::TouchInfos info; auto ret = twiMaster.Read(twiAddress, 0, touchData, sizeof(touchData)); - if (ret != TwiMaster::ErrorCodes::NoError) - return {}; + if (ret != TwiMaster::ErrorCodes::NoError) { + info.isValid = false; + return info; + } auto nbTouchPoints = touchData[2] & 0x0f; - uint8_t i = 0; - - uint8_t pointId = (touchData[touchIdIndex + (touchStep * i)]) >> 4; - if (nbTouchPoints == 0 && pointId == lastTouchId) - return info; - - info.isTouch = true; - - auto xHigh = touchData[touchXHighIndex + (touchStep * i)] & 0x0f; - auto xLow = touchData[touchXLowIndex + (touchStep * i)]; + auto xHigh = touchData[touchXHighIndex] & 0x0f; + auto xLow = touchData[touchXLowIndex]; uint16_t x = (xHigh << 8) | xLow; - auto yHigh = touchData[touchYHighIndex + (touchStep * i)] & 0x0f; - auto yLow = touchData[touchYLowIndex + (touchStep * i)]; + auto yHigh = touchData[touchYHighIndex] & 0x0f; + auto yLow = touchData[touchYLowIndex]; uint16_t y = (yHigh << 8) | yLow; - auto action = touchData[touchEventIndex + (touchStep * i)] >> 6; /* 0 = Down, 1 = Up, 2 = contact*/ - info.x = x; info.y = y; - info.finger = nbTouchPoints; + info.touching = (nbTouchPoints > 0); info.gesture = static_cast(touchData[gestureIndex]); return info; diff --git a/src/drivers/Cst816s.h b/src/drivers/Cst816s.h index 14c296ea..26bdf4e0 100644 --- a/src/drivers/Cst816s.h +++ b/src/drivers/Cst816s.h @@ -19,12 +19,9 @@ namespace Pinetime { struct TouchInfos { uint16_t x = 0; uint16_t y = 0; - uint8_t action = 0; - uint8_t finger = 0; - uint8_t pressure = 0; - uint8_t area = 0; Gestures gesture = Gestures::None; - bool isTouch = false; + bool touching = false; + bool isValid = false; }; Cst816S(TwiMaster& twiMaster, uint8_t twiAddress); @@ -41,23 +38,24 @@ namespace Pinetime { private: static constexpr uint8_t pinIrq = 28; static constexpr uint8_t pinReset = 10; - static constexpr uint8_t lastTouchId = 0x0f; + + // Unused/Unavailable commented out + static constexpr uint8_t gestureIndex = 1; static constexpr uint8_t touchPointNumIndex = 2; - static constexpr uint8_t touchMiscIndex = 8; - static constexpr uint8_t touchXYIndex = 7; - static constexpr uint8_t touchEventIndex = 3; + //static constexpr uint8_t touchEventIndex = 3; static constexpr uint8_t touchXHighIndex = 3; static constexpr uint8_t touchXLowIndex = 4; + //static constexpr uint8_t touchIdIndex = 5; static constexpr uint8_t touchYHighIndex = 5; static constexpr uint8_t touchYLowIndex = 6; - static constexpr uint8_t touchIdIndex = 5; - static constexpr uint8_t touchStep = 6; - static constexpr uint8_t gestureIndex = 1; + //static constexpr uint8_t touchStep = 6; + //static constexpr uint8_t touchXYIndex = 7; + //static constexpr uint8_t touchMiscIndex = 8; - uint8_t touchData[10]; + uint8_t touchData[7]; TwiMaster& twiMaster; uint8_t twiAddress; }; } -} \ No newline at end of file +} diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index f6aee785..7277fc93 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -231,7 +231,7 @@ void SystemTask::Work() { twiMaster.Wakeup(); auto touchInfo = touchPanel.GetTouchInfo(); twiMaster.Sleep(); - if (touchInfo.isTouch and ((touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and + if (touchInfo.isValid and ((touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) or (touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap and settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap)))) { diff --git a/src/touchhandler/TouchHandler.cpp b/src/touchhandler/TouchHandler.cpp index 90b4d6da..c6f8629f 100644 --- a/src/touchhandler/TouchHandler.cpp +++ b/src/touchhandler/TouchHandler.cpp @@ -9,7 +9,7 @@ TouchHandler::TouchHandler(Drivers::Cst816S& touchPanel, Components::LittleVgl& void TouchHandler::CancelTap() { isCancelled = true; - lvgl.SetNewTapEvent(-1, -1, false); + lvgl.SetNewTouchPoint(-1, -1, true); } Pinetime::Drivers::Cst816S::Gestures TouchHandler::GestureGet() { @@ -19,7 +19,7 @@ Pinetime::Drivers::Cst816S::Gestures TouchHandler::GestureGet() { } void TouchHandler::Start() { - if (pdPASS != xTaskCreate(TouchHandler::Process, "Touch", 80, this, 0, &taskHandle)) { + if (pdPASS != xTaskCreate(TouchHandler::Process, "Touch", 100, this, 0, &taskHandle)) { APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); } } @@ -39,13 +39,9 @@ void TouchHandler::Work() { } else { x = info.x; y = info.y; - if (info.finger == 0) { - lvgl.SetNewTapEvent(info.x, info.y, false); - prevGesture = Pinetime::Drivers::Cst816S::Gestures::None; - isCancelled = false; - } else if (info.finger == 1) { + if (info.touching) { if (!isCancelled) { - lvgl.SetNewTapEvent(info.x, info.y, true); + lvgl.SetNewTouchPoint(info.x, info.y, true); } if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) { if (prevGesture != info.gesture) { @@ -53,6 +49,14 @@ void TouchHandler::Work() { gesture = info.gesture; } } + } else { + if (isCancelled) { + lvgl.SetNewTouchPoint(-1, -1, false); + isCancelled = false; + } else { + lvgl.SetNewTouchPoint(info.x, info.y, false); + } + prevGesture = Pinetime::Drivers::Cst816S::Gestures::None; } systemTask->OnTouchEvent(); } From 93ccbf38e81b30165e49e897c01cac2eb54cc331 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Fri, 16 Jul 2021 01:49:20 +0300 Subject: [PATCH 04/31] Fix touch wakeup and code cleanup --- src/displayapp/LittleVgl.cpp | 21 ----------------- src/drivers/TwiMaster.cpp | 12 ++++++---- src/drivers/TwiMaster.h | 3 ++- src/main.cpp | 4 +++- src/systemtask/SystemTask.cpp | 38 +++++++++++++++---------------- src/systemtask/SystemTask.h | 13 +++++++---- src/touchhandler/TouchHandler.cpp | 5 ++-- 7 files changed, 43 insertions(+), 53 deletions(-) diff --git a/src/displayapp/LittleVgl.cpp b/src/displayapp/LittleVgl.cpp index b5669713..2bd5e57b 100644 --- a/src/displayapp/LittleVgl.cpp +++ b/src/displayapp/LittleVgl.cpp @@ -181,27 +181,6 @@ bool LittleVgl::GetTouchPadInfo(lv_indev_data_t* ptr) { ptr->state = LV_INDEV_STATE_REL; } return false; - /* - auto info = touchPanel.GetTouchInfo(); - - if((previousClick.x != info.x || previousClick.y != info.y) && - (info.gesture == Drivers::Cst816S::Gestures::SingleTap)) { - // TODO For an unknown reason, the first touch is taken twice into account. - // 'firstTouch' is a quite'n'dirty workaound until I find a better solution - if(firstTouch) ptr->state = LV_INDEV_STATE_REL; - else ptr->state = LV_INDEV_STATE_PR; - firstTouch = false; - previousClick.x = info.x; - previousClick.y = info.y; - } - else { - ptr->state = LV_INDEV_STATE_REL; - } - - ptr->point.x = info.x; - ptr->point.y = info.y; - return false; - */ } void LittleVgl::InitTheme() { diff --git a/src/drivers/TwiMaster.cpp b/src/drivers/TwiMaster.cpp index fc9edf81..456c3e64 100644 --- a/src/drivers/TwiMaster.cpp +++ b/src/drivers/TwiMaster.cpp @@ -12,9 +12,10 @@ TwiMaster::TwiMaster(const Modules module, const Parameters& params) : module {m } void TwiMaster::Init() { + sleeping = false; if(mutex == nullptr) mutex = xSemaphoreCreateBinary(); - + NRF_GPIO->PIN_CNF[params.pinScl] = ((uint32_t) GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | ((uint32_t) GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | ((uint32_t) GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) | ((uint32_t) GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) | @@ -176,11 +177,14 @@ void TwiMaster::Sleep() { nrf_gpio_cfg_default(6); nrf_gpio_cfg_default(7); NRF_LOG_INFO("[TWIMASTER] Sleep"); + sleeping = true; } void TwiMaster::Wakeup() { - Init(); - NRF_LOG_INFO("[TWIMASTER] Wakeup"); + if (sleeping) { + Init(); + NRF_LOG_INFO("[TWIMASTER] Wakeup"); + } } /* Sometimes, the TWIM device just freeze and never set the event EVENTS_LASTTX. @@ -206,4 +210,4 @@ void TwiMaster::FixHwFreezed() { // Re-enable I²C twiBaseAddress->ENABLE = twi_state; -} \ No newline at end of file +} diff --git a/src/drivers/TwiMaster.h b/src/drivers/TwiMaster.h index 6175b99b..5748ec65 100644 --- a/src/drivers/TwiMaster.h +++ b/src/drivers/TwiMaster.h @@ -39,6 +39,7 @@ namespace Pinetime { uint8_t internalBuffer[maxDataSize + registerSize]; uint32_t txStartedCycleCount = 0; static constexpr uint32_t HwFreezedDelay {161000}; + bool sleeping; }; } -} \ No newline at end of file +} diff --git a/src/main.cpp b/src/main.cpp index f427db40..b8d4b023 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -161,10 +161,12 @@ Pinetime::System::SystemTask systemTask(spi, heartRateController, displayApp, heartRateApp, - fs); + fs, + touchHandler); void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { if (pin == pinTouchIrq) { + twiMaster.Wakeup(); touchHandler.WakeUp(); return; } diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 7277fc93..93d19863 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -60,7 +60,8 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi, Pinetime::Controllers::HeartRateController& heartRateController, Pinetime::Applications::DisplayApp& displayApp, Pinetime::Applications::HeartRateTask& heartRateApp, - Pinetime::Controllers::FS& fs) + Pinetime::Controllers::FS& fs, + Pinetime::Controllers::TouchHandler& touchHandler) : spi {spi}, lcd {lcd}, spiNorFlash {spiNorFlash}, @@ -72,18 +73,18 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi, dateTimeController {dateTimeController}, timerController {timerController}, watchdog {watchdog}, - notificationManager{notificationManager}, + notificationManager {notificationManager}, motorController {motorController}, heartRateSensor {heartRateSensor}, motionSensor {motionSensor}, settingsController {settingsController}, - heartRateController{heartRateController}, - motionController{motionController}, - displayApp{displayApp}, + heartRateController {heartRateController}, + motionController {motionController}, + displayApp {displayApp}, heartRateApp(heartRateApp), - fs{fs}, + fs {fs}, + touchHandler {touchHandler}, nimbleController(*this, bleController, dateTimeController, notificationManager, batteryController, spiNorFlash, heartRateController) { - } void SystemTask::Start() { @@ -105,11 +106,11 @@ void SystemTask::Work() { APP_GPIOTE_INIT(2); app_timer_init(); - + spi.Init(); spiNorFlash.Init(); spiNorFlash.Wakeup(); - + fs.Init(); nimbleController.Init(); @@ -228,14 +229,14 @@ void SystemTask::Work() { isWakingUp = false; break; case Messages::TouchWakeUp: { - twiMaster.Wakeup(); - auto touchInfo = touchPanel.GetTouchInfo(); - twiMaster.Sleep(); - if (touchInfo.isValid and ((touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and - settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) or - (touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap and - settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap)))) { + auto gesture = touchHandler.GestureGet(); + if ((gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap && + settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) || + (gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap && + settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap))) { GoToRunning(); + } else { + twiMaster.Sleep(); } } break; case Messages::GoToSleep: @@ -311,7 +312,7 @@ void SystemTask::Work() { break; case Messages::OnChargingEvent: motorController.SetDuration(15); - // Battery level is updated on every message - there's no need to do anything + // Battery level is updated on every message - there's no need to do anything break; default: @@ -410,14 +411,13 @@ void SystemTask::PushMessage(System::Messages msg) { isGoingToSleep = true; } - if(in_isr()) { + if (in_isr()) { BaseType_t xHigherPriorityTaskWoken; xHigherPriorityTaskWoken = pdFALSE; xQueueSendFromISR(systemTasksMsgQueue, &msg, &xHigherPriorityTaskWoken); if (xHigherPriorityTaskWoken) { /* Actual macro used here is port specific. */ portYIELD_FROM_ISR(xHigherPriorityTaskWoken); - } } else { xQueueSend(systemTasksMsgQueue, &msg, portMAX_DELAY); diff --git a/src/systemtask/SystemTask.h b/src/systemtask/SystemTask.h index f8cf6370..a7ee73ad 100644 --- a/src/systemtask/SystemTask.h +++ b/src/systemtask/SystemTask.h @@ -17,6 +17,7 @@ #include "components/motor/MotorController.h" #include "components/timer/TimerController.h" #include "components/fs/FS.h" +#include "touchhandler/TouchHandler.h" #ifdef PINETIME_IS_RECOVERY #include "displayapp/DisplayAppRecovery.h" @@ -24,7 +25,7 @@ #else #include "components/settings/Settings.h" #include "displayapp/DisplayApp.h" - #include "displayapp/LittleVgl.h" + #include "displayapp/LittleVgl.h" #endif #include "drivers/Watchdog.h" @@ -39,6 +40,9 @@ namespace Pinetime { class TwiMaster; class Hrs3300; } + namespace Controllers { + class TouchHandler; + } namespace System { class SystemTask { public: @@ -62,7 +66,8 @@ namespace Pinetime { Pinetime::Controllers::HeartRateController& heartRateController, Pinetime::Applications::DisplayApp& displayApp, Pinetime::Applications::HeartRateTask& heartRateApp, - Pinetime::Controllers::FS& fs); + Pinetime::Controllers::FS& fs, + Pinetime::Controllers::TouchHandler& touchHandler); void Start(); void PushMessage(Messages msg); @@ -91,7 +96,6 @@ namespace Pinetime { Pinetime::Components::LittleVgl& lvgl; Pinetime::Controllers::Battery& batteryController; - Pinetime::Controllers::Ble& bleController; Pinetime::Controllers::DateTime& dateTimeController; Pinetime::Controllers::TimerController& timerController; @@ -106,13 +110,14 @@ namespace Pinetime { Pinetime::Drivers::Bma421& motionSensor; Pinetime::Controllers::Settings& settingsController; Pinetime::Controllers::HeartRateController& heartRateController; - + Controllers::BrightnessController brightnessController; Pinetime::Controllers::MotionController& motionController; Pinetime::Applications::DisplayApp& displayApp; Pinetime::Applications::HeartRateTask& heartRateApp; Pinetime::Controllers::FS& fs; + Pinetime::Controllers::TouchHandler& touchHandler; Pinetime::Controllers::NimbleController nimbleController; static constexpr uint8_t pinSpiSck = 2; diff --git a/src/touchhandler/TouchHandler.cpp b/src/touchhandler/TouchHandler.cpp index c6f8629f..86dc29f6 100644 --- a/src/touchhandler/TouchHandler.cpp +++ b/src/touchhandler/TouchHandler.cpp @@ -2,9 +2,7 @@ using namespace Pinetime::Controllers; -TouchHandler::TouchHandler(Drivers::Cst816S& touchPanel, Components::LittleVgl& lvgl) - : touchPanel {touchPanel}, - lvgl {lvgl} { +TouchHandler::TouchHandler(Drivers::Cst816S& touchPanel, Components::LittleVgl& lvgl) : touchPanel {touchPanel}, lvgl {lvgl} { } void TouchHandler::CancelTap() { @@ -35,6 +33,7 @@ void TouchHandler::Work() { vTaskSuspend(taskHandle); info = touchPanel.GetTouchInfo(); if (systemTask->IsSleeping()) { + gesture = info.gesture; systemTask->PushMessage(System::Messages::TouchWakeUp); } else { x = info.x; From baffa1594f9c1a03a95f0cc10955e3cf8bf880ce Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Fri, 16 Jul 2021 02:17:17 +0300 Subject: [PATCH 05/31] Fix gestures --- .../screens/settings/QuickSettings.cpp | 11 ---------- .../screens/settings/QuickSettings.h | 1 - src/touchhandler/TouchHandler.cpp | 20 ++++++++++++------- src/touchhandler/TouchHandler.h | 1 - 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/displayapp/screens/settings/QuickSettings.cpp b/src/displayapp/screens/settings/QuickSettings.cpp index 2da5ca27..076bea82 100644 --- a/src/displayapp/screens/settings/QuickSettings.cpp +++ b/src/displayapp/screens/settings/QuickSettings.cpp @@ -154,17 +154,6 @@ void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) { } } -bool QuickSettings::OnTouchEvent(Pinetime::Applications::TouchEvents event) { - switch (event) { - case Pinetime::Applications::TouchEvents::SwipeLeft: - running = false; - return false; - - default: - return true; - } -} - bool QuickSettings::Refresh() { return running; } diff --git a/src/displayapp/screens/settings/QuickSettings.h b/src/displayapp/screens/settings/QuickSettings.h index a14f46bf..e0fc0a87 100644 --- a/src/displayapp/screens/settings/QuickSettings.h +++ b/src/displayapp/screens/settings/QuickSettings.h @@ -29,7 +29,6 @@ namespace Pinetime { bool Refresh() override; - bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; void OnButtonEvent(lv_obj_t* object, lv_event_t event); void UpdateScreen(); diff --git a/src/touchhandler/TouchHandler.cpp b/src/touchhandler/TouchHandler.cpp index 86dc29f6..160b5e14 100644 --- a/src/touchhandler/TouchHandler.cpp +++ b/src/touchhandler/TouchHandler.cpp @@ -29,11 +29,23 @@ void TouchHandler::Process(void* instance) { void TouchHandler::Work() { Pinetime::Drivers::Cst816S::TouchInfos info; + Pinetime::Drivers::Cst816S::Gestures prevGesture = Pinetime::Drivers::Cst816S::Gestures::None; while (true) { vTaskSuspend(taskHandle); + info = touchPanel.GetTouchInfo(); + + if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) { + if (prevGesture != info.gesture) { + if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown || info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideLeft || + info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideUp || info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight) { + prevGesture = info.gesture; + } + gesture = info.gesture; + } + } + if (systemTask->IsSleeping()) { - gesture = info.gesture; systemTask->PushMessage(System::Messages::TouchWakeUp); } else { x = info.x; @@ -42,12 +54,6 @@ void TouchHandler::Work() { if (!isCancelled) { lvgl.SetNewTouchPoint(info.x, info.y, true); } - if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) { - if (prevGesture != info.gesture) { - prevGesture = info.gesture; - gesture = info.gesture; - } - } } else { if (isCancelled) { lvgl.SetNewTouchPoint(-1, -1, false); diff --git a/src/touchhandler/TouchHandler.h b/src/touchhandler/TouchHandler.h index 7999e00a..37ef5af2 100644 --- a/src/touchhandler/TouchHandler.h +++ b/src/touchhandler/TouchHandler.h @@ -37,7 +37,6 @@ namespace Pinetime { Pinetime::Drivers::Cst816S& touchPanel; Pinetime::Components::LittleVgl& lvgl; Pinetime::Drivers::Cst816S::Gestures gesture; - Pinetime::Drivers::Cst816S::Gestures prevGesture; bool isCancelled = false; uint8_t x, y; }; From 329482f87308c185e970b141bcbfe9c83b46c4da Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Fri, 16 Jul 2021 11:55:29 +0300 Subject: [PATCH 06/31] Fix remaining known issues --- src/displayapp/DisplayApp.cpp | 4 +++- src/displayapp/screens/Tile.cpp | 3 ++- src/touchhandler/TouchHandler.cpp | 9 ++++----- src/touchhandler/TouchHandler.h | 11 ++++++++--- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 945f182a..1ff8d51d 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -226,7 +226,9 @@ void DisplayApp::Refresh() { } } - currentScreen->OnTouchEvent(touchHandler.GetX(), touchHandler.GetY()); + if (touchHandler.IsTouching()) { + currentScreen->OnTouchEvent(touchHandler.GetX(), touchHandler.GetY()); + } if (nextApp != Apps::None) { LoadApp(nextApp, nextDirection); diff --git a/src/displayapp/screens/Tile.cpp b/src/displayapp/screens/Tile.cpp index 5a40e915..8eb5eb0a 100644 --- a/src/displayapp/screens/Tile.cpp +++ b/src/displayapp/screens/Tile.cpp @@ -91,6 +91,7 @@ Tile::Tile(uint8_t screenID, lv_obj_set_style_local_bg_color(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DISABLED, lv_color_hex(0x111111)); for (uint8_t i = 0; i < 6; i++) { + lv_btnmatrix_set_btn_ctrl(btnm1, i, LV_BTNMATRIX_CTRL_CLICK_TRIG); if (applications[i].application == Apps::None) { lv_btnmatrix_set_btn_ctrl(btnm1, i, LV_BTNMATRIX_CTRL_DISABLED); } @@ -123,7 +124,7 @@ bool Tile::Refresh() { } void Tile::OnObjectEvent(lv_obj_t* obj, lv_event_t event) { - if (event == LV_EVENT_CLICKED) { + if (event == LV_EVENT_VALUE_CHANGED) { app->StartApp(apps[lv_btnmatrix_get_active_btn(obj)], DisplayApp::FullRefreshDirections::Up); running = false; } diff --git a/src/touchhandler/TouchHandler.cpp b/src/touchhandler/TouchHandler.cpp index 160b5e14..0d0b8273 100644 --- a/src/touchhandler/TouchHandler.cpp +++ b/src/touchhandler/TouchHandler.cpp @@ -6,8 +6,10 @@ TouchHandler::TouchHandler(Drivers::Cst816S& touchPanel, Components::LittleVgl& } void TouchHandler::CancelTap() { - isCancelled = true; - lvgl.SetNewTouchPoint(-1, -1, true); + if (info.touching) { + isCancelled = true; + lvgl.SetNewTouchPoint(-1, -1, true); + } } Pinetime::Drivers::Cst816S::Gestures TouchHandler::GestureGet() { @@ -28,7 +30,6 @@ void TouchHandler::Process(void* instance) { } void TouchHandler::Work() { - Pinetime::Drivers::Cst816S::TouchInfos info; Pinetime::Drivers::Cst816S::Gestures prevGesture = Pinetime::Drivers::Cst816S::Gestures::None; while (true) { vTaskSuspend(taskHandle); @@ -48,8 +49,6 @@ void TouchHandler::Work() { if (systemTask->IsSleeping()) { systemTask->PushMessage(System::Messages::TouchWakeUp); } else { - x = info.x; - y = info.y; if (info.touching) { if (!isCancelled) { lvgl.SetNewTouchPoint(info.x, info.y, true); diff --git a/src/touchhandler/TouchHandler.h b/src/touchhandler/TouchHandler.h index 37ef5af2..6b8189f5 100644 --- a/src/touchhandler/TouchHandler.h +++ b/src/touchhandler/TouchHandler.h @@ -22,23 +22,28 @@ namespace Pinetime { void Register(Pinetime::System::SystemTask* systemTask); void Start(); void WakeUp(); + + bool IsTouching() const { + return info.touching; + } uint8_t GetX() const { - return x; + return info.x; } uint8_t GetY() const { - return y; + return info.y; } Drivers::Cst816S::Gestures GestureGet(); private: static void Process(void* instance); void Work(); + + Pinetime::Drivers::Cst816S::TouchInfos info; Pinetime::System::SystemTask* systemTask = nullptr; TaskHandle_t taskHandle; Pinetime::Drivers::Cst816S& touchPanel; Pinetime::Components::LittleVgl& lvgl; Pinetime::Drivers::Cst816S::Gestures gesture; bool isCancelled = false; - uint8_t x, y; }; } } From 3e42297bd86fa20daaf7f59f6bc0a69de6cf9e53 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Sun, 18 Jul 2021 12:32:46 +0300 Subject: [PATCH 07/31] Update --- src/drivers/Cst816s.h | 2 +- src/main.cpp | 3 --- src/systemtask/SystemTask.cpp | 3 +++ src/touchhandler/TouchHandler.cpp | 44 ++++++++++++++++--------------- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/drivers/Cst816s.h b/src/drivers/Cst816s.h index 26bdf4e0..d4c17bb8 100644 --- a/src/drivers/Cst816s.h +++ b/src/drivers/Cst816s.h @@ -21,7 +21,7 @@ namespace Pinetime { uint16_t y = 0; Gestures gesture = Gestures::None; bool touching = false; - bool isValid = false; + bool isValid = true; }; Cst816S(TwiMaster& twiMaster, uint8_t twiAddress); diff --git a/src/main.cpp b/src/main.cpp index b8d4b023..62e4446f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -315,9 +315,6 @@ int main(void) { systemTask.Start(); - touchHandler.Register(&systemTask); - touchHandler.Start(); - nimble_port_init(); vTaskStartScheduler(); diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 93d19863..252d3cc3 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -144,6 +144,9 @@ void SystemTask::Work() { heartRateSensor.Disable(); heartRateApp.Start(); + touchHandler.Register(this); + touchHandler.Start(); + 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); diff --git a/src/touchhandler/TouchHandler.cpp b/src/touchhandler/TouchHandler.cpp index 0d0b8273..187aa696 100644 --- a/src/touchhandler/TouchHandler.cpp +++ b/src/touchhandler/TouchHandler.cpp @@ -30,37 +30,39 @@ void TouchHandler::Process(void* instance) { } void TouchHandler::Work() { - Pinetime::Drivers::Cst816S::Gestures prevGesture = Pinetime::Drivers::Cst816S::Gestures::None; + bool slideReleased = true; while (true) { vTaskSuspend(taskHandle); info = touchPanel.GetTouchInfo(); - if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) { - if (prevGesture != info.gesture) { - if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown || info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideLeft || - info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideUp || info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight) { - prevGesture = info.gesture; + if (info.isValid) { + if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) { + if (slideReleased) { + if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown || + info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideLeft || + info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideUp || + info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight) { + slideReleased = false; + } + gesture = info.gesture; } - gesture = info.gesture; } - } - if (systemTask->IsSleeping()) { - systemTask->PushMessage(System::Messages::TouchWakeUp); - } else { - if (info.touching) { - if (!isCancelled) { - lvgl.SetNewTouchPoint(info.x, info.y, true); - } - } else { - if (isCancelled) { - lvgl.SetNewTouchPoint(-1, -1, false); - isCancelled = false; + if (!systemTask->IsSleeping()) { + if (info.touching) { + if (!isCancelled) { + lvgl.SetNewTouchPoint(info.x, info.y, true); + } } else { - lvgl.SetNewTouchPoint(info.x, info.y, false); + if (isCancelled) { + lvgl.SetNewTouchPoint(-1, -1, false); + isCancelled = false; + } else { + lvgl.SetNewTouchPoint(info.x, info.y, false); + } + slideReleased = true; } - prevGesture = Pinetime::Drivers::Cst816S::Gestures::None; } systemTask->OnTouchEvent(); } From dc2b5f0c6b387f674915d0dbe817b7ac2a821e07 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Mon, 19 Jul 2021 10:21:42 +0300 Subject: [PATCH 08/31] Restore Tile.cpp changes --- src/displayapp/screens/Tile.cpp | 8 +++++--- src/displayapp/screens/Tile.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/displayapp/screens/Tile.cpp b/src/displayapp/screens/Tile.cpp index 8eb5eb0a..853fa7ec 100644 --- a/src/displayapp/screens/Tile.cpp +++ b/src/displayapp/screens/Tile.cpp @@ -12,7 +12,9 @@ namespace { static void event_handler(lv_obj_t* obj, lv_event_t event) { Tile* screen = static_cast(obj->user_data); - screen->OnObjectEvent(obj, event); + uint32_t* eventDataPtr = (uint32_t*) lv_event_get_data(); + uint32_t eventData = *eventDataPtr; + screen->OnObjectEvent(obj, event, eventData); } } @@ -123,9 +125,9 @@ bool Tile::Refresh() { return running; } -void Tile::OnObjectEvent(lv_obj_t* obj, lv_event_t event) { +void Tile::OnObjectEvent(lv_obj_t* obj, lv_event_t event, uint32_t buttonId) { if (event == LV_EVENT_VALUE_CHANGED) { - app->StartApp(apps[lv_btnmatrix_get_active_btn(obj)], DisplayApp::FullRefreshDirections::Up); + app->StartApp(apps[buttonId], DisplayApp::FullRefreshDirections::Up); running = false; } } diff --git a/src/displayapp/screens/Tile.h b/src/displayapp/screens/Tile.h index 91ce9d01..4ebd81cd 100644 --- a/src/displayapp/screens/Tile.h +++ b/src/displayapp/screens/Tile.h @@ -32,7 +32,7 @@ namespace Pinetime { bool Refresh() override; void UpdateScreen(); - void OnObjectEvent(lv_obj_t* obj, lv_event_t event); + void OnObjectEvent(lv_obj_t* obj, lv_event_t event, uint32_t buttonId); private: Pinetime::Controllers::Battery& batteryController; From baa7e1bf12b58224e9461a5a605dcebabcf9504e Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Mon, 9 Aug 2021 17:45:24 +0300 Subject: [PATCH 09/31] Optimize twiMaster --- src/drivers/TwiMaster.cpp | 43 ++++++++++++++++++--------------------- src/drivers/TwiMaster.h | 4 +++- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/drivers/TwiMaster.cpp b/src/drivers/TwiMaster.cpp index fc9edf81..e4c03d5b 100644 --- a/src/drivers/TwiMaster.cpp +++ b/src/drivers/TwiMaster.cpp @@ -9,21 +9,25 @@ using namespace Pinetime::Drivers; // TODO use DMA/IRQ TwiMaster::TwiMaster(const Modules module, const Parameters& params) : module {module}, params {params} { + mutex = xSemaphoreCreateBinary(); +} + +void TwiMaster::ConfigurePins() const { + NRF_GPIO->PIN_CNF[params.pinScl] = + (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | + (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | + (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) | + (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos); + + NRF_GPIO->PIN_CNF[params.pinSda] = + (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | + (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | + (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) | + (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos); } void TwiMaster::Init() { - if(mutex == nullptr) - mutex = xSemaphoreCreateBinary(); - - NRF_GPIO->PIN_CNF[params.pinScl] = - ((uint32_t) GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | ((uint32_t) GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | - ((uint32_t) GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) | ((uint32_t) GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) | - ((uint32_t) GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos); - - NRF_GPIO->PIN_CNF[params.pinSda] = - ((uint32_t) GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | ((uint32_t) GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | - ((uint32_t) GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) | ((uint32_t) GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) | - ((uint32_t) GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos); + ConfigurePins(); switch (module) { case Modules::TWIM1: @@ -179,7 +183,8 @@ void TwiMaster::Sleep() { } void TwiMaster::Wakeup() { - Init(); + ConfigurePins(); + twiBaseAddress->ENABLE = (TWIM_ENABLE_ENABLE_Enabled << TWIM_ENABLE_ENABLE_Pos); NRF_LOG_INFO("[TWIMASTER] Wakeup"); } @@ -194,16 +199,8 @@ void TwiMaster::FixHwFreezed() { uint32_t twi_state = NRF_TWI1->ENABLE; twiBaseAddress->ENABLE = TWIM_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos; - NRF_GPIO->PIN_CNF[params.pinScl] = - ((uint32_t) GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | ((uint32_t) GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | - ((uint32_t) GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) | ((uint32_t) GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) | - ((uint32_t) GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos); - - NRF_GPIO->PIN_CNF[params.pinSda] = - ((uint32_t) GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | ((uint32_t) GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | - ((uint32_t) GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) | ((uint32_t) GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) | - ((uint32_t) GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos); + ConfigurePins(); // Re-enable I²C twiBaseAddress->ENABLE = twi_state; -} \ No newline at end of file +} diff --git a/src/drivers/TwiMaster.h b/src/drivers/TwiMaster.h index 6175b99b..b8d36d59 100644 --- a/src/drivers/TwiMaster.h +++ b/src/drivers/TwiMaster.h @@ -26,6 +26,8 @@ namespace Pinetime { void Sleep(); void Wakeup(); + void ConfigurePins() const; + private: ErrorCodes Read(uint8_t deviceAddress, uint8_t* buffer, size_t size, bool stop); ErrorCodes Write(uint8_t deviceAddress, const uint8_t* data, size_t size, bool stop); @@ -41,4 +43,4 @@ namespace Pinetime { static constexpr uint32_t HwFreezedDelay {161000}; }; } -} \ No newline at end of file +} From d35a54c060700e537d3e39723b7ee9b1d71b36d8 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Mon, 9 Aug 2021 21:49:35 +0300 Subject: [PATCH 10/31] Try to fix bootloop --- src/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index ffbba5e7..a18c3942 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include #include #include +#include // nimble #define min // workaround: nimble's min/max macros conflict with libstdc++ @@ -300,6 +301,14 @@ int main(void) { nrf_drv_clock_init(); + // Unblock i2c? + nrf_gpio_cfg_output(pinTwiScl); + for (uint8_t i = 0; i < 16; i++) { + nrf_gpio_pin_toggle(pinTwiScl); + nrf_delay_us(5); + } + nrf_gpio_cfg_default(pinTwiScl); + debounceTimer = xTimerCreate("debounceTimer", 200, pdFALSE, (void*) 0, DebounceTimerCallback); debounceChargeTimer = xTimerCreate("debounceTimerCharge", 200, pdFALSE, (void*) 0, DebounceTimerChargeCallback); From ff81a72533e479388d49334d0ec3e0635b6e7f40 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Mon, 9 Aug 2021 22:07:06 +0300 Subject: [PATCH 11/31] Better pin configuration --- src/main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a18c3942..39d8906c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -302,7 +302,12 @@ int main(void) { nrf_drv_clock_init(); // Unblock i2c? - nrf_gpio_cfg_output(pinTwiScl); + nrf_gpio_cfg(pinTwiScl, + NRF_GPIO_PIN_DIR_OUTPUT, + NRF_GPIO_PIN_INPUT_DISCONNECT, + NRF_GPIO_PIN_NOPULL, + NRF_GPIO_PIN_S0D1, + NRF_GPIO_PIN_NOSENSE); for (uint8_t i = 0; i < 16; i++) { nrf_gpio_pin_toggle(pinTwiScl); nrf_delay_us(5); From 5eb56d9a06652cb10358ecba051bbfe8ec2957a7 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Mon, 9 Aug 2021 22:11:35 +0300 Subject: [PATCH 12/31] Set pin before loop --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index 39d8906c..d301be67 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -308,6 +308,7 @@ int main(void) { NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0D1, NRF_GPIO_PIN_NOSENSE); + nrf_gpio_pin_set(pinTwiScl); for (uint8_t i = 0; i < 16; i++) { nrf_gpio_pin_toggle(pinTwiScl); nrf_delay_us(5); From 2194a339cf55772c944fc1302ca740805d931983 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Tue, 10 Aug 2021 11:26:43 +0300 Subject: [PATCH 13/31] Only enable the bus when needed --- src/drivers/TwiMaster.cpp | 6 ++++-- src/systemtask/SystemTask.cpp | 9 --------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/drivers/TwiMaster.cpp b/src/drivers/TwiMaster.cpp index e4c03d5b..34aac07f 100644 --- a/src/drivers/TwiMaster.cpp +++ b/src/drivers/TwiMaster.cpp @@ -72,8 +72,10 @@ void TwiMaster::Init() { TwiMaster::ErrorCodes TwiMaster::Read(uint8_t deviceAddress, uint8_t registerAddress, uint8_t* data, size_t size) { xSemaphoreTake(mutex, portMAX_DELAY); + Wakeup(); auto ret = Write(deviceAddress, ®isterAddress, 1, false); ret = Read(deviceAddress, data, size, true); + Sleep(); xSemaphoreGive(mutex); return ret; } @@ -81,9 +83,11 @@ TwiMaster::ErrorCodes TwiMaster::Read(uint8_t deviceAddress, uint8_t registerAdd TwiMaster::ErrorCodes TwiMaster::Write(uint8_t deviceAddress, uint8_t registerAddress, const uint8_t* data, size_t size) { ASSERT(size <= maxDataSize); xSemaphoreTake(mutex, portMAX_DELAY); + Wakeup(); internalBuffer[0] = registerAddress; std::memcpy(internalBuffer + 1, data, size); auto ret = Write(deviceAddress, internalBuffer, size + 1, true); + Sleep(); xSemaphoreGive(mutex); return ret; } @@ -179,13 +183,11 @@ void TwiMaster::Sleep() { } nrf_gpio_cfg_default(6); nrf_gpio_cfg_default(7); - NRF_LOG_INFO("[TWIMASTER] Sleep"); } void TwiMaster::Wakeup() { ConfigurePins(); twiBaseAddress->ENABLE = (TWIM_ENABLE_ENABLE_Enabled << TWIM_ENABLE_ENABLE_Pos); - NRF_LOG_INFO("[TWIMASTER] Wakeup"); } /* Sometimes, the TWIM device just freeze and never set the event EVENTS_LASTTX. diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 8915ce74..4316330f 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -219,7 +219,6 @@ void SystemTask::Work() { break; case Messages::GoToRunning: spi.Wakeup(); - twiMaster.Wakeup(); // Double Tap needs the touch screen to be in normal mode if (!settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) { @@ -240,9 +239,7 @@ void SystemTask::Work() { isDimmed = false; break; case Messages::TouchWakeUp: { - twiMaster.Wakeup(); auto touchInfo = touchPanel.GetTouchInfo(); - twiMaster.Sleep(); if (touchInfo.isTouch and ((touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) or (touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap and @@ -315,7 +312,6 @@ void SystemTask::Work() { if (!settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) { touchPanel.Sleep(); } - twiMaster.Sleep(); isSleeping = true; isGoingToSleep = false; @@ -367,17 +363,12 @@ void SystemTask::UpdateMotion() { if (isSleeping && !settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist)) return; - if (isSleeping) - twiMaster.Wakeup(); - if (stepCounterMustBeReset) { motionSensor.ResetStepCounter(); stepCounterMustBeReset = false; } auto motionValues = motionSensor.Process(); - if (isSleeping) - twiMaster.Sleep(); motionController.IsSensorOk(motionSensor.IsOk()); motionController.Update(motionValues.x, motionValues.y, motionValues.z, motionValues.steps); From 90ea1071d1df4bf80f2a7d62467aca44c8a63d75 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Tue, 10 Aug 2021 11:52:20 +0300 Subject: [PATCH 14/31] Explicitly disable pullup --- src/drivers/TwiMaster.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/drivers/TwiMaster.cpp b/src/drivers/TwiMaster.cpp index 34aac07f..52f93d85 100644 --- a/src/drivers/TwiMaster.cpp +++ b/src/drivers/TwiMaster.cpp @@ -16,12 +16,14 @@ void TwiMaster::ConfigurePins() const { NRF_GPIO->PIN_CNF[params.pinScl] = (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | + (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos); NRF_GPIO->PIN_CNF[params.pinSda] = (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | + (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos); } From 7e92577c14895f57f5adda27ad54adbbc4b7ffe9 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Tue, 10 Aug 2021 21:02:51 +0300 Subject: [PATCH 15/31] Revert "Merge branch 'unblock_i2c' into develop" This reverts commit 275a84b3238874d213271f4287e6c1c5bfcb4353, reversing changes made to 9fb37550886f09f6510e99a5b452262c53c3987c. --- src/main.cpp | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9a5b0cfe..62e4446f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,7 +5,6 @@ #include #include #include -#include // nimble #define min // workaround: nimble's min/max macros conflict with libstdc++ @@ -306,20 +305,6 @@ int main(void) { nrf_drv_clock_init(); - // Unblock i2c? - nrf_gpio_cfg(pinTwiScl, - NRF_GPIO_PIN_DIR_OUTPUT, - NRF_GPIO_PIN_INPUT_DISCONNECT, - NRF_GPIO_PIN_NOPULL, - NRF_GPIO_PIN_S0D1, - NRF_GPIO_PIN_NOSENSE); - nrf_gpio_pin_set(pinTwiScl); - for (uint8_t i = 0; i < 16; i++) { - nrf_gpio_pin_toggle(pinTwiScl); - nrf_delay_us(5); - } - nrf_gpio_cfg_default(pinTwiScl); - debounceTimer = xTimerCreate("debounceTimer", 200, pdFALSE, (void*) 0, DebounceTimerCallback); debounceChargeTimer = xTimerCreate("debounceTimerCharge", 200, pdFALSE, (void*) 0, DebounceTimerChargeCallback); From 8a694adb0979339664da0af6d51c480d26c5527b Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Tue, 10 Aug 2021 22:03:34 +0300 Subject: [PATCH 16/31] Rework TouchHandler into not a task --- src/drivers/TwiMaster.cpp | 12 ++--- src/drivers/TwiMaster.h | 3 +- src/main.cpp | 3 +- src/systemtask/SystemTask.cpp | 8 +-- src/touchhandler/TouchHandler.cpp | 86 +++++++++++++------------------ src/touchhandler/TouchHandler.h | 9 ++-- 6 files changed, 50 insertions(+), 71 deletions(-) diff --git a/src/drivers/TwiMaster.cpp b/src/drivers/TwiMaster.cpp index 456c3e64..fc9edf81 100644 --- a/src/drivers/TwiMaster.cpp +++ b/src/drivers/TwiMaster.cpp @@ -12,10 +12,9 @@ TwiMaster::TwiMaster(const Modules module, const Parameters& params) : module {m } void TwiMaster::Init() { - sleeping = false; if(mutex == nullptr) mutex = xSemaphoreCreateBinary(); - + NRF_GPIO->PIN_CNF[params.pinScl] = ((uint32_t) GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | ((uint32_t) GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | ((uint32_t) GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) | ((uint32_t) GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) | @@ -177,14 +176,11 @@ void TwiMaster::Sleep() { nrf_gpio_cfg_default(6); nrf_gpio_cfg_default(7); NRF_LOG_INFO("[TWIMASTER] Sleep"); - sleeping = true; } void TwiMaster::Wakeup() { - if (sleeping) { - Init(); - NRF_LOG_INFO("[TWIMASTER] Wakeup"); - } + Init(); + NRF_LOG_INFO("[TWIMASTER] Wakeup"); } /* Sometimes, the TWIM device just freeze and never set the event EVENTS_LASTTX. @@ -210,4 +206,4 @@ void TwiMaster::FixHwFreezed() { // Re-enable I²C twiBaseAddress->ENABLE = twi_state; -} +} \ No newline at end of file diff --git a/src/drivers/TwiMaster.h b/src/drivers/TwiMaster.h index 5748ec65..6175b99b 100644 --- a/src/drivers/TwiMaster.h +++ b/src/drivers/TwiMaster.h @@ -39,7 +39,6 @@ namespace Pinetime { uint8_t internalBuffer[maxDataSize + registerSize]; uint32_t txStartedCycleCount = 0; static constexpr uint32_t HwFreezedDelay {161000}; - bool sleeping; }; } -} +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 62e4446f..dffec28a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -166,8 +166,7 @@ Pinetime::System::SystemTask systemTask(spi, void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { if (pin == pinTouchIrq) { - twiMaster.Wakeup(); - touchHandler.WakeUp(); + systemTask.OnTouchEvent(); return; } diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 7ba7cf69..5f363130 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -150,9 +150,6 @@ void SystemTask::Work() { heartRateSensor.Disable(); heartRateApp.Start(); - touchHandler.Register(this); - touchHandler.Start(); - 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); @@ -244,6 +241,8 @@ void SystemTask::Work() { isDimmed = false; break; case Messages::TouchWakeUp: { + twiMaster.Wakeup(); + touchHandler.GetNewTouchInfo(); auto gesture = touchHandler.GestureGet(); if ((gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap && settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) || @@ -299,6 +298,9 @@ void SystemTask::Work() { xTimerStart(dimTimer, 0); break; case Messages::OnTouchEvent: + if (touchHandler.GetNewTouchInfo()) { + touchHandler.UpdateLvglTouchPoint(); + } ReloadIdleTimer(); break; case Messages::OnButtonEvent: diff --git a/src/touchhandler/TouchHandler.cpp b/src/touchhandler/TouchHandler.cpp index 187aa696..c1a3c0d0 100644 --- a/src/touchhandler/TouchHandler.cpp +++ b/src/touchhandler/TouchHandler.cpp @@ -18,61 +18,47 @@ Pinetime::Drivers::Cst816S::Gestures TouchHandler::GestureGet() { return returnGesture; } -void TouchHandler::Start() { - if (pdPASS != xTaskCreate(TouchHandler::Process, "Touch", 100, this, 0, &taskHandle)) { - APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); +bool TouchHandler::GetNewTouchInfo() { + info = touchPanel.GetTouchInfo(); + + if (!info.isValid) { + return false; } -} -void TouchHandler::Process(void* instance) { - auto* app = static_cast(instance); - app->Work(); -} - -void TouchHandler::Work() { - bool slideReleased = true; - while (true) { - vTaskSuspend(taskHandle); - - info = touchPanel.GetTouchInfo(); - - if (info.isValid) { - if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) { - if (slideReleased) { - if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown || - info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideLeft || - info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideUp || - info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight) { - slideReleased = false; - } - gesture = info.gesture; - } - } - - if (!systemTask->IsSleeping()) { + if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) { + if (slideReleased) { + if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown || + info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideLeft || + info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideUp || + info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight) { if (info.touching) { - if (!isCancelled) { - lvgl.SetNewTouchPoint(info.x, info.y, true); - } - } else { - if (isCancelled) { - lvgl.SetNewTouchPoint(-1, -1, false); - isCancelled = false; - } else { - lvgl.SetNewTouchPoint(info.x, info.y, false); - } - slideReleased = true; + gesture = info.gesture; + slideReleased = false; } + } else { + gesture = info.gesture; } - systemTask->OnTouchEvent(); + } + } + + if (!info.touching) { + slideReleased = true; + } + + return true; +} + +void TouchHandler::UpdateLvglTouchPoint() { + if (info.touching) { + if (!isCancelled) { + lvgl.SetNewTouchPoint(info.x, info.y, true); + } + } else { + if (isCancelled) { + lvgl.SetNewTouchPoint(-1, -1, false); + isCancelled = false; + } else { + lvgl.SetNewTouchPoint(info.x, info.y, false); } } } - -void TouchHandler::Register(Pinetime::System::SystemTask* systemTask) { - this->systemTask = systemTask; -} - -void TouchHandler::WakeUp() { - vTaskResume(taskHandle); -} diff --git a/src/touchhandler/TouchHandler.h b/src/touchhandler/TouchHandler.h index 6b8189f5..38cb36cb 100644 --- a/src/touchhandler/TouchHandler.h +++ b/src/touchhandler/TouchHandler.h @@ -19,9 +19,9 @@ namespace Pinetime { public: explicit TouchHandler(Drivers::Cst816S&, Components::LittleVgl&); void CancelTap(); + bool GetNewTouchInfo(); + void UpdateLvglTouchPoint(); void Register(Pinetime::System::SystemTask* systemTask); - void Start(); - void WakeUp(); bool IsTouching() const { return info.touching; @@ -34,16 +34,13 @@ namespace Pinetime { } Drivers::Cst816S::Gestures GestureGet(); private: - static void Process(void* instance); - void Work(); Pinetime::Drivers::Cst816S::TouchInfos info; - Pinetime::System::SystemTask* systemTask = nullptr; - TaskHandle_t taskHandle; Pinetime::Drivers::Cst816S& touchPanel; Pinetime::Components::LittleVgl& lvgl; Pinetime::Drivers::Cst816S::Gestures gesture; bool isCancelled = false; + bool slideReleased = true; }; } } From 6776776421bd73c8e8f927af3ffc45ce77fe0e0d Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Tue, 10 Aug 2021 22:18:21 +0300 Subject: [PATCH 17/31] Make diff smaller and revert some changes in DisplayApp --- src/displayapp/DisplayApp.cpp | 117 +++++++++++++++++----------------- src/displayapp/Messages.h | 1 + src/systemtask/SystemTask.cpp | 1 + 3 files changed, 62 insertions(+), 57 deletions(-) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index b4fc885b..e26a96f2 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -52,6 +52,28 @@ namespace { static inline bool in_isr(void) { return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0; } + + TouchEvents ConvertGesture(Pinetime::Drivers::Cst816S::Gestures gesture) { + switch (gesture) { + case Pinetime::Drivers::Cst816S::Gestures::SingleTap: + return TouchEvents::Tap; + case Pinetime::Drivers::Cst816S::Gestures::LongPress: + return TouchEvents::LongTap; + case Pinetime::Drivers::Cst816S::Gestures::DoubleTap: + return TouchEvents::DoubleTap; + case Pinetime::Drivers::Cst816S::Gestures::SlideRight: + return TouchEvents::SwipeRight; + case Pinetime::Drivers::Cst816S::Gestures::SlideLeft: + return TouchEvents::SwipeLeft; + case Pinetime::Drivers::Cst816S::Gestures::SlideDown: + return TouchEvents::SwipeDown; + case Pinetime::Drivers::Cst816S::Gestures::SlideUp: + return TouchEvents::SwipeUp; + case Pinetime::Drivers::Cst816S::Gestures::None: + default: + return TouchEvents::None; + } + } } DisplayApp::DisplayApp(Drivers::St7789& lcd, @@ -185,6 +207,41 @@ void DisplayApp::Refresh() { LoadApp(Apps::Timer, DisplayApp::FullRefreshDirections::Down); } break; + case Messages::TouchEvent: { + if (state != States::Running) { + break; + } + auto gesture = ConvertGesture(touchHandler.GestureGet()); + if (gesture == TouchEvents::None) { + break; + } + if (!currentScreen->OnTouchEvent(gesture)) { + if (currentApp == Apps::Clock) { + switch (gesture) { + case TouchEvents::SwipeUp: + LoadApp(Apps::Launcher, DisplayApp::FullRefreshDirections::Up); + break; + case TouchEvents::SwipeDown: + LoadApp(Apps::Notifications, DisplayApp::FullRefreshDirections::Down); + break; + case TouchEvents::SwipeRight: + LoadApp(Apps::QuickSettings, DisplayApp::FullRefreshDirections::RightAnim); + break; + case TouchEvents::DoubleTap: + PushMessageToSystemTask(System::Messages::GoToSleep); + break; + default: + break; + } + } else if (returnTouchEvent == gesture) { + LoadApp(returnToApp, returnDirection); + brightnessController.Set(settingsController.GetBrightness()); + brightnessController.Backup(); + } + } else { + touchHandler.CancelTap(); + } + } break; case Messages::ButtonPushed: if (currentApp == Apps::Clock) { PushMessageToSystemTask(System::Messages::GoToSleep); @@ -207,44 +264,14 @@ void DisplayApp::Refresh() { } } - auto gesture = GetGesture(); - if (gesture != TouchEvents::None) { - if (!currentScreen->OnTouchEvent(gesture)) { - if (currentApp == Apps::Clock) { - switch (gesture) { - case TouchEvents::SwipeUp: - LoadApp(Apps::Launcher, DisplayApp::FullRefreshDirections::Up); - break; - case TouchEvents::SwipeDown: - LoadApp(Apps::Notifications, DisplayApp::FullRefreshDirections::Down); - break; - case TouchEvents::SwipeRight: - LoadApp(Apps::QuickSettings, DisplayApp::FullRefreshDirections::RightAnim); - break; - case TouchEvents::DoubleTap: - PushMessageToSystemTask(System::Messages::GoToSleep); - break; - default: - break; - } - } else if (returnTouchEvent == gesture) { - LoadApp(returnToApp, returnDirection); - brightnessController.Set(settingsController.GetBrightness()); - brightnessController.Backup(); - } - } else { - touchHandler.CancelTap(); - } + if (nextApp != Apps::None) { + LoadApp(nextApp, nextDirection); + nextApp = Apps::None; } if (touchHandler.IsTouching()) { currentScreen->OnTouchEvent(touchHandler.GetX(), touchHandler.GetY()); } - - if (nextApp != Apps::None) { - LoadApp(nextApp, nextDirection); - nextApp = Apps::None; - } } void DisplayApp::RunningState() { @@ -407,30 +434,6 @@ void DisplayApp::PushMessage(Messages msg) { } } -TouchEvents DisplayApp::GetGesture() { - auto gesture = touchHandler.GestureGet(); - switch (gesture) { - case Pinetime::Drivers::Cst816S::Gestures::SingleTap: - return TouchEvents::Tap; - case Pinetime::Drivers::Cst816S::Gestures::LongPress: - return TouchEvents::LongTap; - case Pinetime::Drivers::Cst816S::Gestures::DoubleTap: - return TouchEvents::DoubleTap; - case Pinetime::Drivers::Cst816S::Gestures::SlideRight: - return TouchEvents::SwipeRight; - case Pinetime::Drivers::Cst816S::Gestures::SlideLeft: - return TouchEvents::SwipeLeft; - case Pinetime::Drivers::Cst816S::Gestures::SlideDown: - return TouchEvents::SwipeDown; - case Pinetime::Drivers::Cst816S::Gestures::SlideUp: - return TouchEvents::SwipeUp; - case Pinetime::Drivers::Cst816S::Gestures::None: - default: - return TouchEvents::None; - } - return TouchEvents::None; -} - void DisplayApp::SetFullRefresh(DisplayApp::FullRefreshDirections direction) { switch (direction) { case DisplayApp::FullRefreshDirections::Down: diff --git a/src/displayapp/Messages.h b/src/displayapp/Messages.h index 26480987..322505e6 100644 --- a/src/displayapp/Messages.h +++ b/src/displayapp/Messages.h @@ -8,6 +8,7 @@ namespace Pinetime { UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, + TouchEvent, ButtonPushed, NewNotification, TimerDone, diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 5f363130..3ee26c5f 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -302,6 +302,7 @@ void SystemTask::Work() { touchHandler.UpdateLvglTouchPoint(); } ReloadIdleTimer(); + displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent); break; case Messages::OnButtonEvent: ReloadIdleTimer(); From cd7ca458fa959ba6d60b2cf107b198e462315abd Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Tue, 10 Aug 2021 22:37:41 +0300 Subject: [PATCH 18/31] Remove leftover --- src/touchhandler/TouchHandler.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/touchhandler/TouchHandler.h b/src/touchhandler/TouchHandler.h index 38cb36cb..e2140cae 100644 --- a/src/touchhandler/TouchHandler.h +++ b/src/touchhandler/TouchHandler.h @@ -21,7 +21,6 @@ namespace Pinetime { void CancelTap(); bool GetNewTouchInfo(); void UpdateLvglTouchPoint(); - void Register(Pinetime::System::SystemTask* systemTask); bool IsTouching() const { return info.touching; From fe33c756b7326cbf0a6c70822b70cff4dc2e3401 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Wed, 11 Aug 2021 18:31:40 +0300 Subject: [PATCH 19/31] Fix longpress gesture --- src/touchhandler/TouchHandler.cpp | 9 +++++---- src/touchhandler/TouchHandler.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/touchhandler/TouchHandler.cpp b/src/touchhandler/TouchHandler.cpp index c1a3c0d0..735b311a 100644 --- a/src/touchhandler/TouchHandler.cpp +++ b/src/touchhandler/TouchHandler.cpp @@ -26,14 +26,15 @@ bool TouchHandler::GetNewTouchInfo() { } if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) { - if (slideReleased) { + if (gestureReleased) { if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown || info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideLeft || info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideUp || - info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight) { + info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight || + info.gesture == Pinetime::Drivers::Cst816S::Gestures::LongPress) { if (info.touching) { gesture = info.gesture; - slideReleased = false; + gestureReleased = false; } } else { gesture = info.gesture; @@ -42,7 +43,7 @@ bool TouchHandler::GetNewTouchInfo() { } if (!info.touching) { - slideReleased = true; + gestureReleased = true; } return true; diff --git a/src/touchhandler/TouchHandler.h b/src/touchhandler/TouchHandler.h index e2140cae..f5442939 100644 --- a/src/touchhandler/TouchHandler.h +++ b/src/touchhandler/TouchHandler.h @@ -39,7 +39,7 @@ namespace Pinetime { Pinetime::Components::LittleVgl& lvgl; Pinetime::Drivers::Cst816S::Gestures gesture; bool isCancelled = false; - bool slideReleased = true; + bool gestureReleased = true; }; } } From 1d341a7aeb16acb45f25b16590630efd655ecd30 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Thu, 12 Aug 2021 14:06:58 +0300 Subject: [PATCH 20/31] Don't reconfigure pins --- src/drivers/TwiMaster.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/drivers/TwiMaster.cpp b/src/drivers/TwiMaster.cpp index 52f93d85..429a6eb7 100644 --- a/src/drivers/TwiMaster.cpp +++ b/src/drivers/TwiMaster.cpp @@ -180,15 +180,10 @@ TwiMaster::ErrorCodes TwiMaster::Write(uint8_t deviceAddress, const uint8_t* dat } void TwiMaster::Sleep() { - while (twiBaseAddress->ENABLE != 0) { - twiBaseAddress->ENABLE = (TWIM_ENABLE_ENABLE_Disabled << TWIM_ENABLE_ENABLE_Pos); - } - nrf_gpio_cfg_default(6); - nrf_gpio_cfg_default(7); + twiBaseAddress->ENABLE = (TWIM_ENABLE_ENABLE_Disabled << TWIM_ENABLE_ENABLE_Pos); } void TwiMaster::Wakeup() { - ConfigurePins(); twiBaseAddress->ENABLE = (TWIM_ENABLE_ENABLE_Enabled << TWIM_ENABLE_ENABLE_Pos); } From e0d01411d7124abc5ad099360057ba683287c428 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Sun, 13 Jun 2021 12:47:12 +0300 Subject: [PATCH 21/31] Ui update --- doc/ui_guidelines.md | 14 ++++ src/displayapp/screens/FirmwareValidation.cpp | 4 +- src/displayapp/screens/List.cpp | 34 ++++------ src/displayapp/screens/Music.cpp | 68 +++++++++---------- src/displayapp/screens/Music.h | 3 +- src/displayapp/screens/Tile.cpp | 30 ++++---- src/displayapp/screens/WatchFaceAnalog.cpp | 4 +- src/displayapp/screens/WatchFaceDigital.cpp | 14 ++-- .../screens/settings/QuickSettings.cpp | 47 ++++++------- .../screens/settings/QuickSettings.h | 2 + 10 files changed, 113 insertions(+), 107 deletions(-) create mode 100644 doc/ui_guidelines.md diff --git a/doc/ui_guidelines.md b/doc/ui_guidelines.md new file mode 100644 index 00000000..9b05ce64 --- /dev/null +++ b/doc/ui_guidelines.md @@ -0,0 +1,14 @@ +# UI design guidelines + +- Align objects all the way to the edge or corner +- Buttons should generally be at least 50px high +- Buttons should generally be on the bottom edge +- Make interactable objects **big** +- Recommendations for inner padding, aka distance between buttons: + - When aligning 4 objects: 4px, e.g. Settings + - When aligning 3 objects: 6px, e.g. App list + - When aligning 2 objects: 10px, e.g. Quick settings +- When using a page indicator, leave 8px for it on the right side + - It is acceptable to leave 8px on the left side as well to center the content +- Top bar takes at least 20px + padding + - Top bar right icons move 8px to the left when using a page indicator diff --git a/src/displayapp/screens/FirmwareValidation.cpp b/src/displayapp/screens/FirmwareValidation.cpp index 1d05be8d..da9d04f2 100644 --- a/src/displayapp/screens/FirmwareValidation.cpp +++ b/src/displayapp/screens/FirmwareValidation.cpp @@ -38,8 +38,9 @@ FirmwareValidation::FirmwareValidation(Pinetime::Applications::DisplayApp* app, lv_label_set_text(labelIsValidated, "Please #00ff00 Validate# this version or\n#ff0000 Reset# to rollback to the previous version."); buttonValidate = lv_btn_create(lv_scr_act(), nullptr); - lv_obj_align(buttonValidate, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); buttonValidate->user_data = this; + lv_obj_set_height(buttonValidate, 50); + lv_obj_align(buttonValidate, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); lv_obj_set_event_cb(buttonValidate, ButtonEventHandler); lv_obj_set_style_local_bg_color(buttonValidate, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x009900)); @@ -48,6 +49,7 @@ FirmwareValidation::FirmwareValidation(Pinetime::Applications::DisplayApp* app, buttonReset = lv_btn_create(lv_scr_act(), nullptr); buttonReset->user_data = this; + lv_obj_set_height(buttonReset, 50); lv_obj_align(buttonReset, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); lv_obj_set_style_local_bg_color(buttonReset, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x990000)); lv_obj_set_event_cb(buttonReset, ButtonEventHandler); diff --git a/src/displayapp/screens/List.cpp b/src/displayapp/screens/List.cpp index b4f4d2cf..eb53820b 100644 --- a/src/displayapp/screens/List.cpp +++ b/src/displayapp/screens/List.cpp @@ -25,42 +25,38 @@ List::List(uint8_t screenID, settingsController.SetSettingsMenu(screenID); if (numScreens > 1) { - pageIndicatorBasePoints[0].x = 240 - 1; - pageIndicatorBasePoints[0].y = 6; - pageIndicatorBasePoints[1].x = 240 - 1; - pageIndicatorBasePoints[1].y = 240 - 6; + pageIndicatorBasePoints[0].x = LV_HOR_RES - 1; + pageIndicatorBasePoints[0].y = 0; + pageIndicatorBasePoints[1].x = LV_HOR_RES - 1; + pageIndicatorBasePoints[1].y = LV_VER_RES; pageIndicatorBase = lv_line_create(lv_scr_act(), NULL); lv_obj_set_style_local_line_width(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3); lv_obj_set_style_local_line_color(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); - lv_obj_set_style_local_line_rounded(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, true); lv_line_set_points(pageIndicatorBase, pageIndicatorBasePoints, 2); - uint16_t indicatorSize = 228 / numScreens; - uint16_t indicatorPos = indicatorSize * screenID; + const uint16_t indicatorSize = LV_VER_RES / numScreens; + const uint16_t indicatorPos = indicatorSize * screenID; - pageIndicatorPoints[0].x = 240 - 1; - pageIndicatorPoints[0].y = 6 + indicatorPos; - pageIndicatorPoints[1].x = 240 - 1; - pageIndicatorPoints[1].y = 6 + indicatorPos + indicatorSize; + pageIndicatorPoints[0].x = LV_HOR_RES - 1; + pageIndicatorPoints[0].y = indicatorPos; + pageIndicatorPoints[1].x = LV_HOR_RES - 1; + pageIndicatorPoints[1].y = indicatorPos + indicatorSize; pageIndicator = lv_line_create(lv_scr_act(), NULL); lv_obj_set_style_local_line_width(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3); lv_obj_set_style_local_line_color(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); - lv_obj_set_style_local_line_rounded(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, true); lv_line_set_points(pageIndicator, pageIndicatorPoints, 2); } lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); - // lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); - lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); - lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); + lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 4); lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); lv_obj_set_pos(container1, 0, 0); - lv_obj_set_width(container1, LV_HOR_RES - 15); + lv_obj_set_width(container1, LV_HOR_RES - 8); lv_obj_set_height(container1, LV_VER_RES); lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); @@ -73,11 +69,11 @@ List::List(uint8_t screenID, itemApps[i] = lv_btn_create(container1, nullptr); lv_obj_set_style_local_bg_opa(itemApps[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_20); - lv_obj_set_style_local_radius(itemApps[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 20); + lv_obj_set_style_local_radius(itemApps[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 57); lv_obj_set_style_local_bg_color(itemApps[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_AQUA); - lv_obj_set_width(itemApps[i], LV_HOR_RES - 25); - lv_obj_set_height(itemApps[i], 52); + lv_obj_set_width(itemApps[i], LV_HOR_RES - 8); + lv_obj_set_height(itemApps[i], 57); lv_obj_set_event_cb(itemApps[i], ButtonEventHandler); lv_btn_set_layout(itemApps[i], LV_LAYOUT_ROW_MID); itemApps[i]->user_data = this; diff --git a/src/displayapp/screens/Music.cpp b/src/displayapp/screens/Music.cpp index c8d5e4b0..99a1518e 100644 --- a/src/displayapp/screens/Music.cpp +++ b/src/displayapp/screens/Music.cpp @@ -50,60 +50,55 @@ inline void lv_img_set_src_arr(lv_obj_t* img, const lv_img_dsc_t* src_img) { Music::Music(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::MusicService& music) : Screen(app), musicService(music) { lv_obj_t* label; + lv_style_init(&btn_style); + lv_style_set_radius(&btn_style, LV_STATE_DEFAULT, 20); + lv_style_set_bg_color(&btn_style, LV_STATE_DEFAULT, LV_COLOR_AQUA); + lv_style_set_bg_opa(&btn_style, LV_STATE_DEFAULT, LV_OPA_20); + btnVolDown = lv_btn_create(lv_scr_act(), nullptr); btnVolDown->user_data = this; lv_obj_set_event_cb(btnVolDown, event_handler); - lv_obj_set_size(btnVolDown, 65, 75); - lv_obj_align(btnVolDown, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 15, -10); - lv_obj_set_style_local_radius(btnVolDown, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 20); - lv_obj_set_style_local_bg_color(btnVolDown, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_AQUA); - lv_obj_set_style_local_bg_opa(btnVolDown, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_20); + lv_obj_set_size(btnVolDown, 76, 76); + lv_obj_align(btnVolDown, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); + lv_obj_add_style(btnVolDown, LV_STATE_DEFAULT, &btn_style); label = lv_label_create(btnVolDown, nullptr); lv_label_set_text(label, Symbols::volumDown); - lv_obj_set_hidden(btnVolDown, !displayVolumeButtons); + lv_obj_set_hidden(btnVolDown, true); btnVolUp = lv_btn_create(lv_scr_act(), nullptr); btnVolUp->user_data = this; lv_obj_set_event_cb(btnVolUp, event_handler); - lv_obj_set_size(btnVolUp, 65, 75); - lv_obj_align(btnVolUp, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, -15, -10); - lv_obj_set_style_local_radius(btnVolUp, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 20); - lv_obj_set_style_local_bg_color(btnVolUp, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_AQUA); - lv_obj_set_style_local_bg_opa(btnVolUp, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_20); + lv_obj_set_size(btnVolUp, 76, 76); + lv_obj_align(btnVolUp, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); + lv_obj_add_style(btnVolUp, LV_STATE_DEFAULT, &btn_style); label = lv_label_create(btnVolUp, nullptr); lv_label_set_text(label, Symbols::volumUp); - lv_obj_set_hidden(btnVolUp, !displayVolumeButtons); + lv_obj_set_hidden(btnVolUp, true); btnPrev = lv_btn_create(lv_scr_act(), nullptr); btnPrev->user_data = this; lv_obj_set_event_cb(btnPrev, event_handler); - lv_obj_set_size(btnPrev, 65, 75); - lv_obj_align(btnPrev, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 15, -10); - lv_obj_set_style_local_radius(btnPrev, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 20); - lv_obj_set_style_local_bg_color(btnPrev, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_AQUA); - lv_obj_set_style_local_bg_opa(btnPrev, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_20); + lv_obj_set_size(btnPrev, 76, 76); + lv_obj_align(btnPrev, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); + lv_obj_add_style(btnPrev, LV_STATE_DEFAULT, &btn_style); label = lv_label_create(btnPrev, nullptr); lv_label_set_text(label, Symbols::stepBackward); btnNext = lv_btn_create(lv_scr_act(), nullptr); btnNext->user_data = this; lv_obj_set_event_cb(btnNext, event_handler); - lv_obj_set_size(btnNext, 65, 75); - lv_obj_align(btnNext, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, -15, -10); - lv_obj_set_style_local_radius(btnNext, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 20); - lv_obj_set_style_local_bg_color(btnNext, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_AQUA); - lv_obj_set_style_local_bg_opa(btnNext, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_20); + lv_obj_set_size(btnNext, 76, 76); + lv_obj_align(btnNext, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); + lv_obj_add_style(btnNext, LV_STATE_DEFAULT, &btn_style); label = lv_label_create(btnNext, nullptr); lv_label_set_text(label, Symbols::stepForward); btnPlayPause = lv_btn_create(lv_scr_act(), nullptr); btnPlayPause->user_data = this; lv_obj_set_event_cb(btnPlayPause, event_handler); - lv_obj_set_size(btnPlayPause, 65, 75); - lv_obj_align(btnPlayPause, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, -10); - lv_obj_set_style_local_radius(btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 20); - lv_obj_set_style_local_bg_color(btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_AQUA); - lv_obj_set_style_local_bg_opa(btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_20); + lv_obj_set_size(btnPlayPause, 76, 76); + lv_obj_align(btnPlayPause, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, 0); + lv_obj_add_style(btnPlayPause, LV_STATE_DEFAULT, &btn_style); txtPlayPause = lv_label_create(btnPlayPause, nullptr); lv_label_set_text(txtPlayPause, Symbols::play); @@ -147,6 +142,7 @@ Music::Music(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Mus } Music::~Music() { + lv_style_reset(&btn_style); lv_obj_clean(lv_scr_act()); } @@ -272,21 +268,19 @@ void Music::OnObjectEvent(lv_obj_t* obj, lv_event_t event) { bool Music::OnTouchEvent(Pinetime::Applications::TouchEvents event) { switch (event) { case TouchEvents::SwipeUp: { - displayVolumeButtons = true; - lv_obj_set_hidden(btnVolDown, !displayVolumeButtons); - lv_obj_set_hidden(btnVolUp, !displayVolumeButtons); + lv_obj_set_hidden(btnVolDown, false); + lv_obj_set_hidden(btnVolUp, false); - lv_obj_set_hidden(btnNext, displayVolumeButtons); - lv_obj_set_hidden(btnPrev, displayVolumeButtons); + lv_obj_set_hidden(btnNext, true); + lv_obj_set_hidden(btnPrev, true); return true; } case TouchEvents::SwipeDown: { - displayVolumeButtons = false; - lv_obj_set_hidden(btnNext, displayVolumeButtons); - lv_obj_set_hidden(btnPrev, displayVolumeButtons); + lv_obj_set_hidden(btnNext, false); + lv_obj_set_hidden(btnPrev, false); - lv_obj_set_hidden(btnVolDown, !displayVolumeButtons); - lv_obj_set_hidden(btnVolUp, !displayVolumeButtons); + lv_obj_set_hidden(btnVolDown, true); + lv_obj_set_hidden(btnVolUp, true); return true; } case TouchEvents::SwipeLeft: { diff --git a/src/displayapp/screens/Music.h b/src/displayapp/screens/Music.h index ef8f1fec..00d3ad92 100644 --- a/src/displayapp/screens/Music.h +++ b/src/displayapp/screens/Music.h @@ -57,10 +57,11 @@ namespace Pinetime { lv_obj_t* imgDiscAnim; lv_obj_t* txtTrackDuration; + lv_style_t btn_style; + /** For the spinning disc animation */ bool frameB; - bool displayVolumeButtons = false; Pinetime::Controllers::MusicService& musicService; std::string artist; diff --git a/src/displayapp/screens/Tile.cpp b/src/displayapp/screens/Tile.cpp index d5d6cb80..a64320e6 100644 --- a/src/displayapp/screens/Tile.cpp +++ b/src/displayapp/screens/Tile.cpp @@ -35,37 +35,35 @@ Tile::Tile(uint8_t screenID, label_time = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_fmt(label_time, "%02i:%02i", dateTimeController.Hours(), dateTimeController.Minutes()); lv_label_set_align(label_time, LV_LABEL_ALIGN_CENTER); - lv_obj_align(label_time, nullptr, LV_ALIGN_IN_TOP_LEFT, 15, 6); + lv_obj_align(label_time, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); // Battery batteryIcon = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining())); - lv_obj_align(batteryIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, -15, 6); + lv_obj_align(batteryIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, -8, 0); if (numScreens > 1) { - pageIndicatorBasePoints[0].x = 240 - 1; - pageIndicatorBasePoints[0].y = 6; - pageIndicatorBasePoints[1].x = 240 - 1; - pageIndicatorBasePoints[1].y = 240 - 6; + pageIndicatorBasePoints[0].x = LV_HOR_RES - 1; + pageIndicatorBasePoints[0].y = 0; + pageIndicatorBasePoints[1].x = LV_HOR_RES - 1; + pageIndicatorBasePoints[1].y = LV_VER_RES; pageIndicatorBase = lv_line_create(lv_scr_act(), nullptr); lv_obj_set_style_local_line_width(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3); lv_obj_set_style_local_line_color(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); - lv_obj_set_style_local_line_rounded(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, true); lv_line_set_points(pageIndicatorBase, pageIndicatorBasePoints, 2); - uint16_t indicatorSize = 228 / numScreens; - uint16_t indicatorPos = indicatorSize * screenID; + const uint16_t indicatorSize = LV_VER_RES / numScreens; + const uint16_t indicatorPos = indicatorSize * screenID; - pageIndicatorPoints[0].x = 240 - 1; - pageIndicatorPoints[0].y = 6 + indicatorPos; - pageIndicatorPoints[1].x = 240 - 1; - pageIndicatorPoints[1].y = 6 + indicatorPos + indicatorSize; + pageIndicatorPoints[0].x = LV_HOR_RES - 1; + pageIndicatorPoints[0].y = indicatorPos; + pageIndicatorPoints[1].x = LV_HOR_RES - 1; + pageIndicatorPoints[1].y = indicatorPos + indicatorSize; pageIndicator = lv_line_create(lv_scr_act(), nullptr); lv_obj_set_style_local_line_width(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3); lv_obj_set_style_local_line_color(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); - lv_obj_set_style_local_line_rounded(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, true); lv_line_set_points(pageIndicator, pageIndicatorPoints, 2); } @@ -85,7 +83,7 @@ Tile::Tile(uint8_t screenID, btnm1 = lv_btnmatrix_create(lv_scr_act(), nullptr); lv_btnmatrix_set_map(btnm1, btnmMap); - lv_obj_set_size(btnm1, LV_HOR_RES - 10, LV_VER_RES - 60); + lv_obj_set_size(btnm1, LV_HOR_RES - 16, LV_VER_RES - 60); lv_obj_align(btnm1, NULL, LV_ALIGN_CENTER, 0, 10); lv_obj_set_style_local_radius(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DEFAULT, 20); @@ -93,6 +91,8 @@ Tile::Tile(uint8_t screenID, lv_obj_set_style_local_bg_color(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DEFAULT, LV_COLOR_AQUA); lv_obj_set_style_local_bg_opa(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DISABLED, LV_OPA_20); lv_obj_set_style_local_bg_color(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DISABLED, lv_color_hex(0x111111)); + lv_obj_set_style_local_pad_all(btnm1, LV_BTNMATRIX_PART_BG, LV_STATE_DEFAULT, 0); + lv_obj_set_style_local_pad_inner(btnm1, LV_BTNMATRIX_PART_BG, LV_STATE_DEFAULT, 6); for (uint8_t i = 0; i < 6; i++) { if (applications[i].application == Apps::None) { diff --git a/src/displayapp/screens/WatchFaceAnalog.cpp b/src/displayapp/screens/WatchFaceAnalog.cpp index 621929b8..1410fc28 100644 --- a/src/displayapp/screens/WatchFaceAnalog.cpp +++ b/src/displayapp/screens/WatchFaceAnalog.cpp @@ -67,12 +67,12 @@ WatchFaceAnalog::WatchFaceAnalog(Pinetime::Applications::DisplayApp* app, batteryIcon = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text(batteryIcon, Symbols::batteryHalf); - lv_obj_align(batteryIcon, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, -8, -4); + lv_obj_align(batteryIcon, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 0); notificationIcon = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FF00)); lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(false)); - lv_obj_align(notificationIcon, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 8, -4); + lv_obj_align(notificationIcon, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); // Date - Day / Week day diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index 7a240f1f..2b902b3b 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -35,7 +35,7 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, batteryIcon = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text(batteryIcon, Symbols::batteryFull); - lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -5, 2); + lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0); batteryPlug = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(batteryPlug, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFF0000)); @@ -50,7 +50,7 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, notificationIcon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FF00)); lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(false)); - lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 10, 0); + lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); label_date = lv_label_create(lv_scr_act(), nullptr); lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60); @@ -75,7 +75,7 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, heartbeatIcon = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text(heartbeatIcon, Symbols::heartBeat); lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B)); - lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 5, -2); + lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); heartbeatValue = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(heartbeatValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B)); @@ -85,7 +85,7 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, stepValue = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FFE7)); lv_label_set_text(stepValue, "0"); - lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -5, -2); + lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); stepIcon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(stepIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FFE7)); @@ -110,7 +110,7 @@ bool WatchFaceDigital::Refresh() { if (bleState.IsUpdated()) { lv_label_set_text(bleIcon, BleIcon::GetIcon(bleState.Get())); } - lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -5, 5); + lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0); lv_obj_align(batteryPlug, batteryIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0); lv_obj_align(bleIcon, batteryPlug, LV_ALIGN_OUT_LEFT_MID, -5, 0); @@ -208,7 +208,7 @@ bool WatchFaceDigital::Refresh() { lv_label_set_text_static(heartbeatValue, ""); } - lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 5, -2); + lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); lv_obj_align(heartbeatValue, heartbeatIcon, LV_ALIGN_OUT_RIGHT_MID, 5, 0); } @@ -216,7 +216,7 @@ bool WatchFaceDigital::Refresh() { motionSensorOk = motionController.IsSensorOk(); if (stepCount.IsUpdated() || motionSensorOk.IsUpdated()) { lv_label_set_text_fmt(stepValue, "%lu", stepCount.Get()); - lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -5, -2); + lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0); } diff --git a/src/displayapp/screens/settings/QuickSettings.cpp b/src/displayapp/screens/settings/QuickSettings.cpp index 0421d103..2d76d2dd 100644 --- a/src/displayapp/screens/settings/QuickSettings.cpp +++ b/src/displayapp/screens/settings/QuickSettings.cpp @@ -30,27 +30,29 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app, motorController {motorController}, settingsController {settingsController} { + // This is the distance (padding) between all objects on this screen. + const int innerDistance = 10; + // Time label_time = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_fmt(label_time, "%02i:%02i", dateTimeController.Hours(), dateTimeController.Minutes()); lv_label_set_align(label_time, LV_LABEL_ALIGN_CENTER); - lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 15, 4); + lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 0); batteryIcon = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining())); - lv_obj_align(batteryIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, -15, 4); + lv_obj_align(batteryIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); - lv_obj_t* lbl_btn; + lv_style_init(&btn_style); + lv_style_set_radius(&btn_style, LV_STATE_DEFAULT, (LV_VER_RES - 20 - 2 * innerDistance) / 8); + lv_style_set_bg_color(&btn_style, LV_STATE_DEFAULT, lv_color_hex(0x111111)); btn1 = lv_btn_create(lv_scr_act(), nullptr); btn1->user_data = this; lv_obj_set_event_cb(btn1, ButtonEventHandler); - lv_obj_align(btn1, nullptr, LV_ALIGN_CENTER, -50, -30); - lv_obj_set_style_local_radius(btn1, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 20); - lv_obj_set_style_local_bg_color(btn1, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); - lv_obj_set_style_local_bg_grad_dir(btn1, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_GRAD_DIR_NONE); - - lv_btn_set_fit2(btn1, LV_FIT_TIGHT, LV_FIT_TIGHT); + lv_obj_add_style(btn1, LV_BTN_PART_MAIN, &btn_style); + lv_obj_set_size(btn1, (LV_HOR_RES - innerDistance) / 2, (LV_VER_RES - 20 - 2 * innerDistance) / 2); + lv_obj_align(btn1, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 20 + innerDistance); btn1_lvl = lv_label_create(btn1, nullptr); lv_obj_set_style_local_text_font(btn1_lvl, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48); @@ -59,12 +61,11 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app, btn2 = lv_btn_create(lv_scr_act(), nullptr); btn2->user_data = this; lv_obj_set_event_cb(btn2, ButtonEventHandler); - lv_obj_align(btn2, nullptr, LV_ALIGN_CENTER, 50, -30); - lv_obj_set_style_local_radius(btn2, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 20); - lv_obj_set_style_local_bg_color(btn2, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); - lv_obj_set_style_local_bg_grad_dir(btn2, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_GRAD_DIR_NONE); - lv_btn_set_fit2(btn2, LV_FIT_TIGHT, LV_FIT_TIGHT); + lv_obj_add_style(btn2, LV_BTN_PART_MAIN, &btn_style); + lv_obj_set_size(btn2, (LV_HOR_RES - innerDistance) / 2, (LV_VER_RES - 20 - 2 * innerDistance) / 2); + lv_obj_align(btn2, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 20 + innerDistance); + lv_obj_t* lbl_btn; lbl_btn = lv_label_create(btn2, nullptr); lv_obj_set_style_local_text_font(lbl_btn, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48); lv_label_set_text_static(lbl_btn, Symbols::highlight); @@ -72,14 +73,11 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app, btn3 = lv_btn_create(lv_scr_act(), nullptr); btn3->user_data = this; lv_obj_set_event_cb(btn3, ButtonEventHandler); - lv_obj_align(btn3, nullptr, LV_ALIGN_CENTER, -50, 60); lv_btn_set_checkable(btn3, true); - lv_obj_set_style_local_radius(btn3, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 20); - lv_obj_set_style_local_bg_color(btn3, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); - lv_obj_set_style_local_bg_grad_dir(btn3, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_GRAD_DIR_NONE); + lv_obj_add_style(btn3, LV_BTN_PART_MAIN, &btn_style); lv_obj_set_style_local_bg_color(btn3, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_GREEN); - lv_obj_set_style_local_bg_grad_dir(btn1, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_GRAD_DIR_NONE); - lv_btn_set_fit2(btn3, LV_FIT_TIGHT, LV_FIT_TIGHT); + lv_obj_set_size(btn3, (LV_HOR_RES - innerDistance) / 2, (LV_VER_RES - 20 - 2 * innerDistance) / 2); + lv_obj_align(btn3, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); btn3_lvl = lv_label_create(btn3, nullptr); lv_obj_set_style_local_text_font(btn3_lvl, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48); @@ -94,11 +92,9 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app, btn4 = lv_btn_create(lv_scr_act(), nullptr); btn4->user_data = this; lv_obj_set_event_cb(btn4, ButtonEventHandler); - lv_obj_align(btn4, nullptr, LV_ALIGN_CENTER, 50, 60); - lv_obj_set_style_local_radius(btn4, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 20); - lv_obj_set_style_local_bg_color(btn4, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); - lv_obj_set_style_local_bg_grad_dir(btn4, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_GRAD_DIR_NONE); - lv_btn_set_fit2(btn4, LV_FIT_TIGHT, LV_FIT_TIGHT); + lv_obj_add_style(btn4, LV_BTN_PART_MAIN, &btn_style); + lv_obj_set_size(btn4, (LV_HOR_RES - innerDistance) / 2, (LV_VER_RES - 20 - 2 * innerDistance) / 2); + lv_obj_align(btn4, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); lbl_btn = lv_label_create(btn4, nullptr); lv_obj_set_style_local_text_font(lbl_btn, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48); @@ -114,6 +110,7 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app, } QuickSettings::~QuickSettings() { + lv_style_reset(&btn_style); lv_task_del(taskUpdate); lv_obj_clean(lv_scr_act()); settingsController.SaveSettings(); diff --git a/src/displayapp/screens/settings/QuickSettings.h b/src/displayapp/screens/settings/QuickSettings.h index e0fc0a87..2eefe1a7 100644 --- a/src/displayapp/screens/settings/QuickSettings.h +++ b/src/displayapp/screens/settings/QuickSettings.h @@ -44,6 +44,8 @@ namespace Pinetime { lv_obj_t* batteryIcon; lv_obj_t* label_time; + lv_style_t btn_style; + lv_obj_t* btn1; lv_obj_t* btn1_lvl; lv_obj_t* btn2; From fc6458a35c2260fe152fe84bcd06174cec6d3b92 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Sun, 13 Jun 2021 17:21:03 +0300 Subject: [PATCH 22/31] Add image with example layouts --- doc/ui/example.png | Bin 0 -> 10642 bytes doc/ui_guidelines.md | 2 ++ 2 files changed, 2 insertions(+) create mode 100644 doc/ui/example.png diff --git a/doc/ui/example.png b/doc/ui/example.png new file mode 100644 index 0000000000000000000000000000000000000000..2f6cb789212631bdf4378085a401272b40ab6ca3 GIT binary patch literal 10642 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 Date: Sat, 24 Jul 2021 21:46:55 +0300 Subject: [PATCH 23/31] Adjust previously missed scrollbar and firmware validation buttons --- src/displayapp/screens/FirmwareValidation.cpp | 4 ++-- src/displayapp/screens/Label.cpp | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/displayapp/screens/FirmwareValidation.cpp b/src/displayapp/screens/FirmwareValidation.cpp index da9d04f2..233ebd5b 100644 --- a/src/displayapp/screens/FirmwareValidation.cpp +++ b/src/displayapp/screens/FirmwareValidation.cpp @@ -39,7 +39,7 @@ FirmwareValidation::FirmwareValidation(Pinetime::Applications::DisplayApp* app, buttonValidate = lv_btn_create(lv_scr_act(), nullptr); buttonValidate->user_data = this; - lv_obj_set_height(buttonValidate, 50); + lv_obj_set_size(buttonValidate, 115, 50); lv_obj_align(buttonValidate, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); lv_obj_set_event_cb(buttonValidate, ButtonEventHandler); lv_obj_set_style_local_bg_color(buttonValidate, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x009900)); @@ -49,7 +49,7 @@ FirmwareValidation::FirmwareValidation(Pinetime::Applications::DisplayApp* app, buttonReset = lv_btn_create(lv_scr_act(), nullptr); buttonReset->user_data = this; - lv_obj_set_height(buttonReset, 50); + lv_obj_set_size(buttonReset, 115, 50); lv_obj_align(buttonReset, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); lv_obj_set_style_local_bg_color(buttonReset, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x990000)); lv_obj_set_event_cb(buttonReset, ButtonEventHandler); diff --git a/src/displayapp/screens/Label.cpp b/src/displayapp/screens/Label.cpp index 0132dbd2..f724fd48 100644 --- a/src/displayapp/screens/Label.cpp +++ b/src/displayapp/screens/Label.cpp @@ -6,10 +6,10 @@ Label::Label(uint8_t screenID, uint8_t numScreens, Pinetime::Applications::Displ : Screen(app), labelText {labelText} { if (numScreens > 1) { - pageIndicatorBasePoints[0].x = 240 - 1; - pageIndicatorBasePoints[0].y = 6; - pageIndicatorBasePoints[1].x = 240 - 1; - pageIndicatorBasePoints[1].y = 240 - 6; + pageIndicatorBasePoints[0].x = LV_HOR_RES - 1; + pageIndicatorBasePoints[0].y = 0; + pageIndicatorBasePoints[1].x = LV_HOR_RES - 1; + pageIndicatorBasePoints[1].y = LV_VER_RES; pageIndicatorBase = lv_line_create(lv_scr_act(), NULL); lv_obj_set_style_local_line_width(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3); @@ -17,13 +17,13 @@ Label::Label(uint8_t screenID, uint8_t numScreens, Pinetime::Applications::Displ lv_obj_set_style_local_line_rounded(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, true); lv_line_set_points(pageIndicatorBase, pageIndicatorBasePoints, 2); - uint16_t indicatorSize = 228 / numScreens; + uint16_t indicatorSize = LV_VER_RES / numScreens; uint16_t indicatorPos = indicatorSize * screenID; - pageIndicatorPoints[0].x = 240 - 1; - pageIndicatorPoints[0].y = (6 + indicatorPos); - pageIndicatorPoints[1].x = 240 - 1; - pageIndicatorPoints[1].y = (6 + indicatorPos) + indicatorSize; + pageIndicatorPoints[0].x = LV_HOR_RES - 1; + pageIndicatorPoints[0].y = indicatorPos; + pageIndicatorPoints[1].x = LV_HOR_RES - 1; + pageIndicatorPoints[1].y = indicatorPos + indicatorSize; pageIndicator = lv_line_create(lv_scr_act(), NULL); lv_obj_set_style_local_line_width(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3); From bc829053718f925662ca1dcdc9856426dabef573 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Thu, 29 Jul 2021 21:25:03 +0300 Subject: [PATCH 24/31] Clean up using variables --- .../screens/settings/QuickSettings.cpp | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/displayapp/screens/settings/QuickSettings.cpp b/src/displayapp/screens/settings/QuickSettings.cpp index 2d76d2dd..54e2f3e2 100644 --- a/src/displayapp/screens/settings/QuickSettings.cpp +++ b/src/displayapp/screens/settings/QuickSettings.cpp @@ -31,7 +31,7 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app, settingsController {settingsController} { // This is the distance (padding) between all objects on this screen. - const int innerDistance = 10; + static constexpr uint8_t innerDistance = 10; // Time label_time = lv_label_create(lv_scr_act(), nullptr); @@ -43,16 +43,22 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app, lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining())); lv_obj_align(batteryIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); + static constexpr uint8_t barHeight = 20 + innerDistance; + static constexpr uint8_t buttonHeight = (LV_VER_RES_MAX - barHeight - innerDistance) / 2; + static constexpr uint8_t buttonWidth = (LV_HOR_RES_MAX - innerDistance) / 2; // wide buttons + //static constexpr uint8_t buttonWidth = buttonHeight; // square buttons + static constexpr uint8_t buttonXOffset = (LV_HOR_RES_MAX - buttonWidth * 2 - innerDistance) / 2; + lv_style_init(&btn_style); - lv_style_set_radius(&btn_style, LV_STATE_DEFAULT, (LV_VER_RES - 20 - 2 * innerDistance) / 8); + lv_style_set_radius(&btn_style, LV_STATE_DEFAULT, buttonHeight / 4); lv_style_set_bg_color(&btn_style, LV_STATE_DEFAULT, lv_color_hex(0x111111)); btn1 = lv_btn_create(lv_scr_act(), nullptr); btn1->user_data = this; lv_obj_set_event_cb(btn1, ButtonEventHandler); lv_obj_add_style(btn1, LV_BTN_PART_MAIN, &btn_style); - lv_obj_set_size(btn1, (LV_HOR_RES - innerDistance) / 2, (LV_VER_RES - 20 - 2 * innerDistance) / 2); - lv_obj_align(btn1, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 20 + innerDistance); + lv_obj_set_size(btn1, buttonWidth, buttonHeight); + lv_obj_align(btn1, nullptr, LV_ALIGN_IN_TOP_LEFT, buttonXOffset, barHeight); btn1_lvl = lv_label_create(btn1, nullptr); lv_obj_set_style_local_text_font(btn1_lvl, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48); @@ -62,8 +68,8 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app, btn2->user_data = this; lv_obj_set_event_cb(btn2, ButtonEventHandler); lv_obj_add_style(btn2, LV_BTN_PART_MAIN, &btn_style); - lv_obj_set_size(btn2, (LV_HOR_RES - innerDistance) / 2, (LV_VER_RES - 20 - 2 * innerDistance) / 2); - lv_obj_align(btn2, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 20 + innerDistance); + lv_obj_set_size(btn2, buttonWidth, buttonHeight); + lv_obj_align(btn2, nullptr, LV_ALIGN_IN_TOP_RIGHT, - buttonXOffset, barHeight); lv_obj_t* lbl_btn; lbl_btn = lv_label_create(btn2, nullptr); @@ -76,8 +82,8 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app, lv_btn_set_checkable(btn3, true); lv_obj_add_style(btn3, LV_BTN_PART_MAIN, &btn_style); lv_obj_set_style_local_bg_color(btn3, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_GREEN); - lv_obj_set_size(btn3, (LV_HOR_RES - innerDistance) / 2, (LV_VER_RES - 20 - 2 * innerDistance) / 2); - lv_obj_align(btn3, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); + lv_obj_set_size(btn3, buttonWidth, buttonHeight); + lv_obj_align(btn3, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, buttonXOffset, 0); btn3_lvl = lv_label_create(btn3, nullptr); lv_obj_set_style_local_text_font(btn3_lvl, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48); @@ -93,8 +99,8 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app, btn4->user_data = this; lv_obj_set_event_cb(btn4, ButtonEventHandler); lv_obj_add_style(btn4, LV_BTN_PART_MAIN, &btn_style); - lv_obj_set_size(btn4, (LV_HOR_RES - innerDistance) / 2, (LV_VER_RES - 20 - 2 * innerDistance) / 2); - lv_obj_align(btn4, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); + lv_obj_set_size(btn4, buttonWidth, buttonHeight); + lv_obj_align(btn4, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, - buttonXOffset, 0); lbl_btn = lv_label_create(btn4, nullptr); lv_obj_set_style_local_text_font(lbl_btn, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48); From ee44b6ff4998d6f4d0672c05c1f65c0a9692dc0d Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Thu, 29 Jul 2021 21:49:06 +0300 Subject: [PATCH 25/31] Adjust inner padding in applist --- src/displayapp/screens/Tile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/screens/Tile.cpp b/src/displayapp/screens/Tile.cpp index a64320e6..777b5bb7 100644 --- a/src/displayapp/screens/Tile.cpp +++ b/src/displayapp/screens/Tile.cpp @@ -92,7 +92,7 @@ Tile::Tile(uint8_t screenID, lv_obj_set_style_local_bg_opa(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DISABLED, LV_OPA_20); lv_obj_set_style_local_bg_color(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DISABLED, lv_color_hex(0x111111)); lv_obj_set_style_local_pad_all(btnm1, LV_BTNMATRIX_PART_BG, LV_STATE_DEFAULT, 0); - lv_obj_set_style_local_pad_inner(btnm1, LV_BTNMATRIX_PART_BG, LV_STATE_DEFAULT, 6); + lv_obj_set_style_local_pad_inner(btnm1, LV_BTNMATRIX_PART_BG, LV_STATE_DEFAULT, 10); for (uint8_t i = 0; i < 6; i++) { if (applications[i].application == Apps::None) { From 81a36dc31ed22237e3cc06c8f4ba2a5cbcf07f8e Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Mon, 16 Aug 2021 18:26:10 +0300 Subject: [PATCH 26/31] Simplify parameters and cleanup --- src/drivers/TwiMaster.cpp | 43 +++++++++------------------------------ src/drivers/TwiMaster.h | 19 +++++++---------- src/main.cpp | 5 ++--- 3 files changed, 19 insertions(+), 48 deletions(-) diff --git a/src/drivers/TwiMaster.cpp b/src/drivers/TwiMaster.cpp index 429a6eb7..f17d7168 100644 --- a/src/drivers/TwiMaster.cpp +++ b/src/drivers/TwiMaster.cpp @@ -8,19 +8,20 @@ using namespace Pinetime::Drivers; // TODO use shortcut to automatically send STOP when receive LastTX, for example // TODO use DMA/IRQ -TwiMaster::TwiMaster(const Modules module, const Parameters& params) : module {module}, params {params} { +TwiMaster::TwiMaster(NRF_TWIM_Type* module, uint32_t frequency, uint8_t pinSda, uint8_t pinScl) + : module {module}, frequency {frequency}, pinSda {pinSda}, pinScl {pinScl} { mutex = xSemaphoreCreateBinary(); } void TwiMaster::ConfigurePins() const { - NRF_GPIO->PIN_CNF[params.pinScl] = + NRF_GPIO->PIN_CNF[pinScl] = (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos); - NRF_GPIO->PIN_CNF[params.pinSda] = + NRF_GPIO->PIN_CNF[pinSda] = (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) | @@ -31,28 +32,12 @@ void TwiMaster::ConfigurePins() const { void TwiMaster::Init() { ConfigurePins(); - switch (module) { - case Modules::TWIM1: - twiBaseAddress = NRF_TWIM1; - break; - default: - return; - } + twiBaseAddress = module; - switch (static_cast(params.frequency)) { - case Frequencies::Khz100: - twiBaseAddress->FREQUENCY = TWIM_FREQUENCY_FREQUENCY_K100; - break; - case Frequencies::Khz250: - twiBaseAddress->FREQUENCY = TWIM_FREQUENCY_FREQUENCY_K250; - break; - case Frequencies::Khz400: - twiBaseAddress->FREQUENCY = TWIM_FREQUENCY_FREQUENCY_K400; - break; - } + twiBaseAddress->FREQUENCY = frequency; - twiBaseAddress->PSEL.SCL = params.pinScl; - twiBaseAddress->PSEL.SDA = params.pinSda; + twiBaseAddress->PSEL.SCL = pinScl; + twiBaseAddress->PSEL.SDA = pinSda; twiBaseAddress->EVENTS_LASTRX = 0; twiBaseAddress->EVENTS_STOPPED = 0; twiBaseAddress->EVENTS_LASTTX = 0; @@ -63,12 +48,6 @@ void TwiMaster::Init() { twiBaseAddress->ENABLE = (TWIM_ENABLE_ENABLE_Enabled << TWIM_ENABLE_ENABLE_Pos); - /* // IRQ - NVIC_ClearPendingIRQ(_IRQn); - NVIC_SetPriority(_IRQn, 2); - NVIC_EnableIRQ(_IRQn); - */ - xSemaphoreGive(mutex); } @@ -194,12 +173,10 @@ void TwiMaster::Wakeup() { * */ void TwiMaster::FixHwFreezed() { NRF_LOG_INFO("I2C device frozen, reinitializing it!"); - // Disable I²C + uint32_t twi_state = NRF_TWI1->ENABLE; - twiBaseAddress->ENABLE = TWIM_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos; - ConfigurePins(); + Sleep(); - // Re-enable I²C twiBaseAddress->ENABLE = twi_state; } diff --git a/src/drivers/TwiMaster.h b/src/drivers/TwiMaster.h index b8d36d59..30ac6c5f 100644 --- a/src/drivers/TwiMaster.h +++ b/src/drivers/TwiMaster.h @@ -8,16 +8,9 @@ namespace Pinetime { namespace Drivers { class TwiMaster { public: - enum class Modules { TWIM1 }; - enum class Frequencies { Khz100, Khz250, Khz400 }; enum class ErrorCodes { NoError, TransactionFailed }; - struct Parameters { - uint32_t frequency; - uint8_t pinSda; - uint8_t pinScl; - }; - TwiMaster(const Modules module, const Parameters& params); + TwiMaster(NRF_TWIM_Type* module, uint32_t frequency, uint8_t pinSda, uint8_t pinScl); void Init(); ErrorCodes Read(uint8_t deviceAddress, uint8_t registerAddress, uint8_t* buffer, size_t size); @@ -26,16 +19,18 @@ namespace Pinetime { void Sleep(); void Wakeup(); - void ConfigurePins() const; - private: ErrorCodes Read(uint8_t deviceAddress, uint8_t* buffer, size_t size, bool stop); ErrorCodes Write(uint8_t deviceAddress, const uint8_t* data, size_t size, bool stop); void FixHwFreezed(); + void ConfigurePins() const; + NRF_TWIM_Type* twiBaseAddress; SemaphoreHandle_t mutex = nullptr; - const Modules module; - const Parameters params; + NRF_TWIM_Type* module; + uint32_t frequency; + uint8_t pinSda; + uint8_t pinScl; static constexpr uint8_t maxDataSize {16}; static constexpr uint8_t registerSize {1}; uint8_t internalBuffer[maxDataSize + registerSize]; diff --git a/src/main.cpp b/src/main.cpp index ffbba5e7..4e94ab19 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -81,9 +81,8 @@ Pinetime::Drivers::SpiNorFlash spiNorFlash {flashSpi}; // The TWI device should work @ up to 400Khz but there is a HW bug which prevent it from // respecting correct timings. According to erratas heet, this magic value makes it run // at ~390Khz with correct timings. -static constexpr uint32_t MaxTwiFrequencyWithoutHardwareBug {0x06200000}; -Pinetime::Drivers::TwiMaster twiMaster {Pinetime::Drivers::TwiMaster::Modules::TWIM1, - Pinetime::Drivers::TwiMaster::Parameters {MaxTwiFrequencyWithoutHardwareBug, pinTwiSda, pinTwiScl}}; +//static constexpr uint32_t MaxTwiFrequencyWithoutHardwareBug {0x06200000}; +Pinetime::Drivers::TwiMaster twiMaster {NRF_TWIM1, TWI_FREQUENCY_FREQUENCY_K250, pinTwiSda, pinTwiScl}; Pinetime::Drivers::Cst816S touchPanel {twiMaster, touchPanelTwiAddress}; #ifdef PINETIME_IS_RECOVERY static constexpr bool isFactory = true; From b91100573e474d6bf4aa324b982d190d035dd232 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Wed, 18 Aug 2021 19:20:25 +0300 Subject: [PATCH 27/31] Fix music app buttons --- src/displayapp/screens/Music.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/screens/Music.cpp b/src/displayapp/screens/Music.cpp index 99a1518e..257e9aea 100644 --- a/src/displayapp/screens/Music.cpp +++ b/src/displayapp/screens/Music.cpp @@ -292,7 +292,7 @@ bool Music::OnTouchEvent(Pinetime::Applications::TouchEvents event) { return true; } default: { - return true; + return false; } } } From df8ea7fe523bb9ec0ac3e24f0b1bebe5743d90cc Mon Sep 17 00:00:00 2001 From: hubmartin Date: Mon, 16 Aug 2021 16:42:42 +0200 Subject: [PATCH 28/31] Add memory print usage --- src/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 40e1f2a5..f72f50c9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -839,7 +839,7 @@ target_compile_options(${EXECUTABLE_NAME} PUBLIC set_target_properties(${EXECUTABLE_NAME} PROPERTIES SUFFIX ".out" - LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections --specs=nano.specs -lc -lnosys -lm -Wl,-Map=${EXECUTABLE_FILE_NAME}.map" + LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections -Wl,--print-memory-usage --specs=nano.specs -lc -lnosys -lm -Wl,-Map=${EXECUTABLE_FILE_NAME}.map" ) add_custom_command(TARGET ${EXECUTABLE_NAME} @@ -869,7 +869,7 @@ target_compile_options(${EXECUTABLE_MCUBOOT_NAME} PUBLIC set_target_properties(${EXECUTABLE_MCUBOOT_NAME} PROPERTIES SUFFIX ".out" - LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT_MCUBOOT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections --specs=nano.specs -lc -lnosys -lm -Wl,-Map=${EXECUTABLE_MCUBOOT_FILE_NAME}.map" + LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT_MCUBOOT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections -Wl,--print-memory-usage --specs=nano.specs -lc -lnosys -lm -Wl,-Map=${EXECUTABLE_MCUBOOT_FILE_NAME}.map" ) add_custom_command(TARGET ${EXECUTABLE_MCUBOOT_NAME} @@ -906,7 +906,7 @@ target_compile_options(${EXECUTABLE_RECOVERY_NAME} PUBLIC set_target_properties(${EXECUTABLE_RECOVERY_NAME} PROPERTIES SUFFIX ".out" - LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections --specs=nano.specs -lc -lnosys -lm -Wl,-Map=${EXECUTABLE_RECOVERY_FILE_NAME}.map" + LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections -Wl,--print-memory-usage --specs=nano.specs -lc -lnosys -lm -Wl,-Map=${EXECUTABLE_RECOVERY_FILE_NAME}.map" ) add_custom_command(TARGET ${EXECUTABLE_RECOVERY_NAME} @@ -936,7 +936,7 @@ target_compile_options(${EXECUTABLE_RECOVERY_MCUBOOT_NAME} PUBLIC set_target_properties(${EXECUTABLE_RECOVERY_MCUBOOT_NAME} PROPERTIES SUFFIX ".out" - LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections --specs=nano.specs -lc -lnosys -lm -Wl,-Map=${EXECUTABLE_GRAPHICS_FILE_NAME}.map" + LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections -Wl,--print-memory-usage --specs=nano.specs -lc -lnosys -lm -Wl,-Map=${EXECUTABLE_GRAPHICS_FILE_NAME}.map" ) add_custom_command(TARGET ${EXECUTABLE_RECOVERY_MCUBOOT_NAME} @@ -977,7 +977,7 @@ add_dependencies(${EXECUTABLE_RECOVERYLOADER_NAME} ${EXECUTABLE_RECOVERY_MCUBOOT set_target_properties(${EXECUTABLE_RECOVERYLOADER_NAME} PROPERTIES SUFFIX ".out" - LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections --specs=nano.specs -lc -lnosys -lm -Wl,-Map=${EXECUTABLE_RECOVERYLOADER_FILE_NAME}.map" + LINK_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections -Wl,--print-memory-usage --specs=nano.specs -lc -lnosys -lm -Wl,-Map=${EXECUTABLE_RECOVERYLOADER_FILE_NAME}.map" ) add_custom_command(TARGET ${EXECUTABLE_RECOVERYLOADER_NAME} @@ -1010,7 +1010,7 @@ add_dependencies(${EXECUTABLE_MCUBOOT_RECOVERYLOADER_NAME} ${EXECUTABLE_RECOVERY set_target_properties(${EXECUTABLE_MCUBOOT_RECOVERYLOADER_NAME} PROPERTIES SUFFIX ".out" - LINK_FLAGS "-mthumb -mabi=aapcs -std=gnu++98 -std=c99 -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT_MCUBOOT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections --specs=nano.specs -lc -lnosys -lm -Wl,-Map=${EXECUTABLE_MCUBOOT_RECOVERYLOADER_FILE_NAME}.map" + LINK_FLAGS "-mthumb -mabi=aapcs -std=gnu++98 -std=c99 -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT_MCUBOOT} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections -Wl,--print-memory-usage --specs=nano.specs -lc -lnosys -lm -Wl,-Map=${EXECUTABLE_MCUBOOT_RECOVERYLOADER_FILE_NAME}.map" ) add_custom_command(TARGET ${EXECUTABLE_MCUBOOT_RECOVERYLOADER_NAME} From 40392d7b9199c87de9784cacb1dee5476e5a5b6f Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Wed, 18 Aug 2021 21:40:27 +0300 Subject: [PATCH 29/31] Use highest frequency and move mutex creation to Init --- src/drivers/TwiMaster.cpp | 5 ++++- src/main.cpp | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/drivers/TwiMaster.cpp b/src/drivers/TwiMaster.cpp index f17d7168..76009278 100644 --- a/src/drivers/TwiMaster.cpp +++ b/src/drivers/TwiMaster.cpp @@ -10,7 +10,6 @@ using namespace Pinetime::Drivers; TwiMaster::TwiMaster(NRF_TWIM_Type* module, uint32_t frequency, uint8_t pinSda, uint8_t pinScl) : module {module}, frequency {frequency}, pinSda {pinSda}, pinScl {pinScl} { - mutex = xSemaphoreCreateBinary(); } void TwiMaster::ConfigurePins() const { @@ -30,6 +29,10 @@ void TwiMaster::ConfigurePins() const { } void TwiMaster::Init() { + if (mutex == nullptr) { + mutex = xSemaphoreCreateBinary(); + } + ConfigurePins(); twiBaseAddress = module; diff --git a/src/main.cpp b/src/main.cpp index 4e94ab19..524035fc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -81,8 +81,8 @@ Pinetime::Drivers::SpiNorFlash spiNorFlash {flashSpi}; // The TWI device should work @ up to 400Khz but there is a HW bug which prevent it from // respecting correct timings. According to erratas heet, this magic value makes it run // at ~390Khz with correct timings. -//static constexpr uint32_t MaxTwiFrequencyWithoutHardwareBug {0x06200000}; -Pinetime::Drivers::TwiMaster twiMaster {NRF_TWIM1, TWI_FREQUENCY_FREQUENCY_K250, pinTwiSda, pinTwiScl}; +static constexpr uint32_t MaxTwiFrequencyWithoutHardwareBug {0x06200000}; +Pinetime::Drivers::TwiMaster twiMaster {NRF_TWIM1, MaxTwiFrequencyWithoutHardwareBug, pinTwiSda, pinTwiScl}; Pinetime::Drivers::Cst816S touchPanel {twiMaster, touchPanelTwiAddress}; #ifdef PINETIME_IS_RECOVERY static constexpr bool isFactory = true; From 0313277ae604bb46987cdfbef123b7edfeb8ab9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sat, 28 Aug 2021 15:10:14 +0200 Subject: [PATCH 30/31] Fix touchinfo typo in SystemTask. --- src/systemtask/SystemTask.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 08e21999..03bf6706 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -241,7 +241,7 @@ void SystemTask::Work() { break; case Messages::TouchWakeUp: { auto touchInfo = touchPanel.GetTouchInfo(); - if (touchInfo.isTouch and ((touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and + if (touchInfo.touching and ((touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) or (touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap and settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap)))) { From fab49f8557ef8ff38fe4f607e33b18fb5a1aeb9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sat, 28 Aug 2021 15:23:13 +0200 Subject: [PATCH 31/31] Fix recovery firmware since last changes in DisplayApp. --- src/displayapp/DisplayAppRecovery.cpp | 4 +++- src/displayapp/DisplayAppRecovery.h | 6 +++++- src/displayapp/DummyLittleVgl.h | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/displayapp/DisplayAppRecovery.cpp b/src/displayapp/DisplayAppRecovery.cpp index fd517b11..17612ef0 100644 --- a/src/displayapp/DisplayAppRecovery.cpp +++ b/src/displayapp/DisplayAppRecovery.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "displayapp/icons/infinitime/infinitime-nb.c" using namespace Pinetime::Applications; @@ -19,7 +20,8 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd, Controllers::Settings& settingsController, Pinetime::Controllers::MotorController& motorController, Pinetime::Controllers::MotionController& motionController, - Pinetime::Controllers::TimerController& timerController) + Pinetime::Controllers::TimerController& timerController, + Pinetime::Controllers::TouchHandler& touchHandler) : lcd {lcd}, bleController {bleController} { } diff --git a/src/displayapp/DisplayAppRecovery.h b/src/displayapp/DisplayAppRecovery.h index 638c0071..8b2bc7f5 100644 --- a/src/displayapp/DisplayAppRecovery.h +++ b/src/displayapp/DisplayAppRecovery.h @@ -29,6 +29,9 @@ namespace Pinetime { namespace System { class SystemTask; }; + namespace Controllers { + class TouchHandler; + } namespace Applications { class DisplayApp { public: @@ -44,7 +47,8 @@ namespace Pinetime { Controllers::Settings& settingsController, Pinetime::Controllers::MotorController& motorController, Pinetime::Controllers::MotionController& motionController, - Pinetime::Controllers::TimerController& timerController); + Pinetime::Controllers::TimerController& timerController, + Pinetime::Controllers::TouchHandler& touchHandler); void Start(); void PushMessage(Pinetime::Applications::Display::Messages msg); void Register(Pinetime::System::SystemTask* systemTask); diff --git a/src/displayapp/DummyLittleVgl.h b/src/displayapp/DummyLittleVgl.h index 016165b8..1db51343 100644 --- a/src/displayapp/DummyLittleVgl.h +++ b/src/displayapp/DummyLittleVgl.h @@ -32,6 +32,9 @@ namespace Pinetime { } void SetNewTapEvent(uint16_t x, uint16_t y) { } + void SetNewTouchPoint(uint16_t x, uint16_t y, bool contact) { + + } }; } }