Merge branch 'develop' into HEAD
This commit is contained in:
@@ -27,6 +27,19 @@
|
||||
|
||||
using namespace Pinetime::System;
|
||||
|
||||
namespace {
|
||||
static inline bool in_isr(void) {
|
||||
return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
void DimTimerCallback(TimerHandle_t xTimer) {
|
||||
|
||||
NRF_LOG_INFO("DimTimerCallback");
|
||||
auto sysTask = static_cast<SystemTask*>(pvTimerGetTimerID(xTimer));
|
||||
sysTask->OnDim();
|
||||
}
|
||||
|
||||
void IdleTimerCallback(TimerHandle_t xTimer) {
|
||||
|
||||
NRF_LOG_INFO("IdleTimerCallback");
|
||||
@@ -42,10 +55,19 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
|
||||
Components::LittleVgl& lvgl,
|
||||
Controllers::Battery& batteryController,
|
||||
Controllers::Ble& bleController,
|
||||
Controllers::DateTime& dateTimeController,
|
||||
Controllers::TimerController& timerController,
|
||||
Drivers::Watchdog& watchdog,
|
||||
Pinetime::Controllers::NotificationManager& notificationManager,
|
||||
Pinetime::Controllers::MotorController& motorController,
|
||||
Pinetime::Drivers::Hrs3300& heartRateSensor,
|
||||
Pinetime::Controllers::MotionController& motionController,
|
||||
Pinetime::Drivers::Bma421& motionSensor,
|
||||
Controllers::Settings& settingsController)
|
||||
Controllers::Settings& settingsController,
|
||||
Pinetime::Controllers::HeartRateController& heartRateController,
|
||||
Pinetime::Applications::DisplayApp& displayApp,
|
||||
Pinetime::Applications::HeartRateTask& heartRateApp,
|
||||
Pinetime::Controllers::FS& fs)
|
||||
: spi {spi},
|
||||
lcd {lcd},
|
||||
spiNorFlash {spiNorFlash},
|
||||
@@ -53,20 +75,26 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
|
||||
touchPanel {touchPanel},
|
||||
lvgl {lvgl},
|
||||
batteryController {batteryController},
|
||||
heartRateController {*this},
|
||||
bleController {bleController},
|
||||
dateTimeController {*this},
|
||||
watchdog {},
|
||||
watchdogView {watchdog},
|
||||
dateTimeController {dateTimeController},
|
||||
timerController {timerController},
|
||||
watchdog {watchdog},
|
||||
notificationManager{notificationManager},
|
||||
motorController {motorController},
|
||||
heartRateSensor {heartRateSensor},
|
||||
motionSensor {motionSensor},
|
||||
settingsController {settingsController},
|
||||
heartRateController{heartRateController},
|
||||
motionController{motionController},
|
||||
displayApp{displayApp},
|
||||
heartRateApp(heartRateApp),
|
||||
fs{fs},
|
||||
nimbleController(*this, bleController, dateTimeController, notificationManager, batteryController, spiNorFlash, heartRateController) {
|
||||
systemTasksMsgQueue = xQueueCreate(10, 1);
|
||||
|
||||
}
|
||||
|
||||
void SystemTask::Start() {
|
||||
systemTasksMsgQueue = xQueueCreate(10, 1);
|
||||
if (pdPASS != xTaskCreate(SystemTask::Process, "MAIN", 350, this, 0, &taskHandle))
|
||||
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
|
||||
}
|
||||
@@ -83,48 +111,43 @@ void SystemTask::Work() {
|
||||
NRF_LOG_INFO("Last reset reason : %s", Pinetime::Drivers::Watchdog::ResetReasonToString(watchdog.ResetReason()));
|
||||
APP_GPIOTE_INIT(2);
|
||||
|
||||
app_timer_init();
|
||||
|
||||
spi.Init();
|
||||
spiNorFlash.Init();
|
||||
spiNorFlash.Wakeup();
|
||||
|
||||
fs.Init();
|
||||
|
||||
nimbleController.Init();
|
||||
nimbleController.StartAdvertising();
|
||||
brightnessController.Init();
|
||||
lcd.Init();
|
||||
|
||||
twiMaster.Init();
|
||||
touchPanel.Init();
|
||||
dateTimeController.Register(this);
|
||||
batteryController.Init();
|
||||
motorController.Init();
|
||||
motionSensor.SoftReset();
|
||||
timerController.Register(this);
|
||||
timerController.Init();
|
||||
|
||||
// Reset the TWI device because the motion sensor chip most probably crashed it...
|
||||
twiMaster.Sleep();
|
||||
twiMaster.Init();
|
||||
|
||||
motionSensor.Init();
|
||||
motionController.Init(motionSensor.DeviceType());
|
||||
settingsController.Init();
|
||||
|
||||
displayApp = std::make_unique<Pinetime::Applications::DisplayApp>(lcd,
|
||||
lvgl,
|
||||
touchPanel,
|
||||
batteryController,
|
||||
bleController,
|
||||
dateTimeController,
|
||||
watchdogView,
|
||||
*this,
|
||||
notificationManager,
|
||||
heartRateController,
|
||||
settingsController,
|
||||
motorController,
|
||||
motionController);
|
||||
displayApp->Start();
|
||||
displayApp.Register(this);
|
||||
displayApp.Start();
|
||||
|
||||
displayApp->PushMessage(Pinetime::Applications::Display::Messages::UpdateBatteryLevel);
|
||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::UpdateBatteryLevel);
|
||||
|
||||
heartRateSensor.Init();
|
||||
heartRateSensor.Disable();
|
||||
heartRateApp = std::make_unique<Pinetime::Applications::HeartRateTask>(heartRateSensor, heartRateController);
|
||||
heartRateApp->Start();
|
||||
heartRateApp.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);
|
||||
@@ -149,8 +172,22 @@ void SystemTask::Work() {
|
||||
|
||||
nrfx_gpiote_in_init(pinTouchIrq, &pinConfig, nrfx_gpiote_evt_handler);
|
||||
|
||||
idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut()), pdFALSE, this, IdleTimerCallback);
|
||||
xTimerStart(idleTimer, 0);
|
||||
pinConfig.sense = NRF_GPIOTE_POLARITY_TOGGLE;
|
||||
pinConfig.pull = NRF_GPIO_PIN_NOPULL;
|
||||
pinConfig.is_watcher = false;
|
||||
pinConfig.hi_accuracy = false;
|
||||
pinConfig.skip_gpio_setup = true;
|
||||
nrfx_gpiote_in_init(pinPowerPresentIrq, &pinConfig, nrfx_gpiote_evt_handler);
|
||||
|
||||
if (nrf_gpio_pin_read(pinPowerPresentIrq)) {
|
||||
nrf_gpio_cfg_sense_input(pinPowerPresentIrq, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW);
|
||||
} else {
|
||||
nrf_gpio_cfg_sense_input(pinPowerPresentIrq, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH);
|
||||
}
|
||||
|
||||
idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(2000), pdFALSE, this, IdleTimerCallback);
|
||||
dimTimer = xTimerCreate("dimTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), pdFALSE, this, DimTimerCallback);
|
||||
xTimerStart(dimTimer, 0);
|
||||
|
||||
// Suppress endless loop diagnostic
|
||||
#pragma clang diagnostic push
|
||||
@@ -161,53 +198,55 @@ void SystemTask::Work() {
|
||||
uint8_t msg;
|
||||
if (xQueueReceive(systemTasksMsgQueue, &msg, 100)) {
|
||||
|
||||
// call the battery controller or use the MSG in DisplayApp to get the battery status ???
|
||||
// it is necessary to validate which is the most efficient
|
||||
batteryController.Update();
|
||||
// displayApp->PushMessage(Pinetime::Applications::Display::Messages::UpdateBatteryLevel);
|
||||
// analyze a more efficient way to do this refreshment
|
||||
// this and the UpdateMotion(); can be called on a timer to be independent of the main process ???
|
||||
// the battery does not emit events when changing charge levels, so we piggyback
|
||||
// on any system event to read and update the current values
|
||||
|
||||
Messages message = static_cast<Messages>(msg);
|
||||
switch (message) {
|
||||
case Messages::EnableSleeping:
|
||||
doNotGoToSleep = false;
|
||||
// Make sure that exiting an app doesn't enable sleeping,
|
||||
// if the exiting was caused by a firmware update
|
||||
if (!bleController.IsFirmwareUpdating()) {
|
||||
doNotGoToSleep = false;
|
||||
}
|
||||
break;
|
||||
case Messages::DisableSleeping:
|
||||
doNotGoToSleep = true;
|
||||
break;
|
||||
case Messages::UpdateTimeOut:
|
||||
xTimerChangePeriod(idleTimer, pdMS_TO_TICKS(settingsController.GetScreenTimeOut()), 0);
|
||||
xTimerChangePeriod(dimTimer, pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), 0);
|
||||
break;
|
||||
case Messages::GoToRunning:
|
||||
spi.Wakeup();
|
||||
twiMaster.Wakeup();
|
||||
|
||||
// Double Tap needs the touch screen to be in normal mode
|
||||
if (settingsController.getWakeUpMode() != Pinetime::Controllers::Settings::WakeUpMode::DoubleTap) {
|
||||
if (!settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) {
|
||||
touchPanel.Wakeup();
|
||||
}
|
||||
|
||||
nimbleController.StartAdvertising();
|
||||
xTimerStart(idleTimer, 0);
|
||||
xTimerStart(dimTimer, 0);
|
||||
spiNorFlash.Wakeup();
|
||||
lcd.Wakeup();
|
||||
|
||||
displayApp->PushMessage(Pinetime::Applications::Display::Messages::GoToRunning);
|
||||
displayApp->PushMessage(Pinetime::Applications::Display::Messages::UpdateBatteryLevel);
|
||||
heartRateApp->PushMessage(Pinetime::Applications::HeartRateTask::Messages::WakeUp);
|
||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::GoToRunning);
|
||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::UpdateBatteryLevel);
|
||||
heartRateApp.PushMessage(Pinetime::Applications::HeartRateTask::Messages::WakeUp);
|
||||
|
||||
isSleeping = false;
|
||||
isWakingUp = false;
|
||||
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.getWakeUpMode() == Pinetime::Controllers::Settings::WakeUpMode::DoubleTap) or
|
||||
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) or
|
||||
(touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap and
|
||||
settingsController.getWakeUpMode() == Pinetime::Controllers::Settings::WakeUpMode::SingleTap))) {
|
||||
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap)))) {
|
||||
GoToRunning();
|
||||
}
|
||||
} break;
|
||||
@@ -215,22 +254,30 @@ void SystemTask::Work() {
|
||||
isGoingToSleep = true;
|
||||
NRF_LOG_INFO("[systemtask] Going to sleep");
|
||||
xTimerStop(idleTimer, 0);
|
||||
displayApp->PushMessage(Pinetime::Applications::Display::Messages::GoToSleep);
|
||||
heartRateApp->PushMessage(Pinetime::Applications::HeartRateTask::Messages::GoToSleep);
|
||||
xTimerStop(dimTimer, 0);
|
||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::GoToSleep);
|
||||
heartRateApp.PushMessage(Pinetime::Applications::HeartRateTask::Messages::GoToSleep);
|
||||
break;
|
||||
case Messages::OnNewTime:
|
||||
ReloadIdleTimer();
|
||||
displayApp->PushMessage(Pinetime::Applications::Display::Messages::UpdateDateTime);
|
||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::UpdateDateTime);
|
||||
break;
|
||||
case Messages::OnNewNotification:
|
||||
if (isSleeping && !isWakingUp)
|
||||
if (isSleeping && !isWakingUp) {
|
||||
GoToRunning();
|
||||
}
|
||||
if (notificationManager.GetLastNotification().category == Controllers::NotificationManager::Categories::IncomingCall) {
|
||||
motorController.startRunning(500);
|
||||
} else {
|
||||
motorController.runForDuration(35);
|
||||
}
|
||||
displayApp->PushMessage(Pinetime::Applications::Display::Messages::NewNotification);
|
||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::NewNotification);
|
||||
case Messages::OnTimerDone:
|
||||
if (isSleeping && !isWakingUp) {
|
||||
GoToRunning();
|
||||
}
|
||||
motorController.runForDuration(35);
|
||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TimerDone);
|
||||
break;
|
||||
case Messages::BleConnected:
|
||||
ReloadIdleTimer();
|
||||
@@ -241,19 +288,22 @@ void SystemTask::Work() {
|
||||
doNotGoToSleep = true;
|
||||
if (isSleeping && !isWakingUp)
|
||||
GoToRunning();
|
||||
displayApp->PushMessage(Pinetime::Applications::Display::Messages::BleFirmwareUpdateStarted);
|
||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::BleFirmwareUpdateStarted);
|
||||
break;
|
||||
case Messages::BleFirmwareUpdateFinished:
|
||||
doNotGoToSleep = false;
|
||||
xTimerStart(idleTimer, 0);
|
||||
if (bleController.State() == Pinetime::Controllers::Ble::FirmwareUpdateStates::Validated)
|
||||
if (bleController.State() == Pinetime::Controllers::Ble::FirmwareUpdateStates::Validated) {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
doNotGoToSleep = false;
|
||||
xTimerStart(dimTimer, 0);
|
||||
break;
|
||||
case Messages::OnTouchEvent:
|
||||
ReloadIdleTimer();
|
||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
|
||||
break;
|
||||
case Messages::OnButtonEvent:
|
||||
ReloadIdleTimer();
|
||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::ButtonPushed);
|
||||
break;
|
||||
case Messages::OnDisplayTaskSleeping:
|
||||
if (BootloaderVersion::IsValid()) {
|
||||
@@ -265,7 +315,7 @@ void SystemTask::Work() {
|
||||
spi.Sleep();
|
||||
|
||||
// Double Tap needs the touch screen to be in normal mode
|
||||
if (settingsController.getWakeUpMode() != Pinetime::Controllers::Settings::WakeUpMode::DoubleTap) {
|
||||
if (!settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) {
|
||||
touchPanel.Sleep();
|
||||
}
|
||||
twiMaster.Sleep();
|
||||
@@ -278,6 +328,11 @@ void SystemTask::Work() {
|
||||
// Remember we'll have to reset the counter next time we're awake
|
||||
stepCounterMustBeReset = true;
|
||||
break;
|
||||
case Messages::OnChargingEvent:
|
||||
motorController.SetDuration(15);
|
||||
// Battery level is updated on every message - there's no need to do anything
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -294,6 +349,11 @@ void SystemTask::Work() {
|
||||
}
|
||||
}
|
||||
|
||||
if (xTaskGetTickCount() - batteryNotificationTick > batteryNotificationPeriod) {
|
||||
nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining());
|
||||
batteryNotificationTick = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
monitor.Process();
|
||||
uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG);
|
||||
dateTimeController.UpdateTime(systick_counter);
|
||||
@@ -307,7 +367,7 @@ void SystemTask::UpdateMotion() {
|
||||
if (isGoingToSleep or isWakingUp)
|
||||
return;
|
||||
|
||||
if (isSleeping && settingsController.getWakeUpMode() != Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist)
|
||||
if (isSleeping && !settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist))
|
||||
return;
|
||||
|
||||
if (isSleeping)
|
||||
@@ -335,7 +395,6 @@ void SystemTask::OnButtonPushed() {
|
||||
if (!isSleeping) {
|
||||
NRF_LOG_INFO("[systemtask] Button pushed");
|
||||
PushMessage(Messages::OnButtonEvent);
|
||||
displayApp->PushMessage(Pinetime::Applications::Display::Messages::ButtonPushed);
|
||||
} else {
|
||||
if (!isWakingUp) {
|
||||
NRF_LOG_INFO("[systemtask] Button pushed, waking up");
|
||||
@@ -356,28 +415,42 @@ void SystemTask::OnTouchEvent() {
|
||||
return;
|
||||
if (!isSleeping) {
|
||||
PushMessage(Messages::OnTouchEvent);
|
||||
displayApp->PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
|
||||
} else if (!isWakingUp) {
|
||||
if (settingsController.getWakeUpMode() == Pinetime::Controllers::Settings::WakeUpMode::None or
|
||||
settingsController.getWakeUpMode() == Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist)
|
||||
return;
|
||||
PushMessage(Messages::TouchWakeUp);
|
||||
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap) or
|
||||
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) {
|
||||
PushMessage(Messages::TouchWakeUp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SystemTask::PushMessage(SystemTask::Messages msg) {
|
||||
void SystemTask::PushMessage(System::Messages msg) {
|
||||
if (msg == Messages::GoToSleep) {
|
||||
isGoingToSleep = true;
|
||||
}
|
||||
BaseType_t xHigherPriorityTaskWoken;
|
||||
xHigherPriorityTaskWoken = pdFALSE;
|
||||
xQueueSendFromISR(systemTasksMsgQueue, &msg, &xHigherPriorityTaskWoken);
|
||||
if (xHigherPriorityTaskWoken) {
|
||||
/* Actual macro used here is port specific. */
|
||||
// TODO: should I do something here?
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void SystemTask::OnDim() {
|
||||
if (doNotGoToSleep)
|
||||
return;
|
||||
NRF_LOG_INFO("Dim timeout -> Dim screen")
|
||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::DimScreen);
|
||||
xTimerStart(idleTimer, 0);
|
||||
isDimmed = true;
|
||||
}
|
||||
|
||||
void SystemTask::OnIdle() {
|
||||
if (doNotGoToSleep)
|
||||
return;
|
||||
@@ -385,8 +458,13 @@ void SystemTask::OnIdle() {
|
||||
PushMessage(Messages::GoToSleep);
|
||||
}
|
||||
|
||||
void SystemTask::ReloadIdleTimer() const {
|
||||
void SystemTask::ReloadIdleTimer() {
|
||||
if (isSleeping || isGoingToSleep)
|
||||
return;
|
||||
xTimerReset(idleTimer, 0);
|
||||
if (isDimmed) {
|
||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::RestoreBrightness);
|
||||
isDimmed = false;
|
||||
}
|
||||
xTimerReset(dimTimer, 0);
|
||||
xTimerStop(idleTimer, 0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user