2020-02-23 07:44:39 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <FreeRTOS.h>
|
|
|
|
#include <task.h>
|
|
|
|
#include <memory>
|
|
|
|
#include <drivers/SpiMaster.h>
|
|
|
|
#include <drivers/St7789.h>
|
|
|
|
#include <Components/Battery/BatteryController.h>
|
|
|
|
#include <DisplayApp/DisplayApp.h>
|
2020-02-23 15:09:11 -05:00
|
|
|
#include <drivers/Watchdog.h>
|
2020-05-07 13:53:51 -04:00
|
|
|
#include <drivers/SpiNorFlash.h>
|
2020-07-02 15:38:52 -04:00
|
|
|
#include "SystemMonitor.h"
|
2020-07-20 16:28:21 -04:00
|
|
|
#include "Components/Ble/NimbleController.h"
|
|
|
|
#include "timers.h"
|
2020-02-23 07:44:39 -05:00
|
|
|
|
|
|
|
namespace Pinetime {
|
|
|
|
namespace System {
|
|
|
|
class SystemTask {
|
|
|
|
public:
|
2020-05-02 08:16:57 -04:00
|
|
|
enum class Messages {GoToSleep, GoToRunning, OnNewTime, OnNewNotification, BleConnected,
|
2020-08-22 11:59:59 -04:00
|
|
|
BleFirmwareUpdateStarted, BleFirmwareUpdateFinished, OnTouchEvent, OnButtonEvent, OnDisplayTaskSleeping
|
2020-03-25 16:23:40 -04:00
|
|
|
};
|
2020-02-23 07:44:39 -05:00
|
|
|
|
2020-05-07 13:53:51 -04:00
|
|
|
SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd,
|
2020-07-19 14:30:44 -04:00
|
|
|
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
|
|
|
|
Drivers::TwiMaster& twiMaster, Drivers::Cst816S &touchPanel,
|
2020-03-28 14:05:28 -04:00
|
|
|
Components::LittleVgl &lvgl,
|
|
|
|
Controllers::Battery &batteryController, Controllers::Ble &bleController,
|
|
|
|
Controllers::DateTime &dateTimeController,
|
|
|
|
Pinetime::Controllers::NotificationManager& manager);
|
2020-02-23 07:44:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
void Start();
|
|
|
|
void PushMessage(Messages msg);
|
|
|
|
|
|
|
|
void OnButtonPushed();
|
|
|
|
void OnTouchEvent();
|
2020-06-01 14:40:11 -04:00
|
|
|
|
|
|
|
void OnIdle();
|
|
|
|
|
2020-07-11 16:37:28 -04:00
|
|
|
Pinetime::Controllers::NimbleController& nimble() {return nimbleController;};
|
|
|
|
|
2020-02-23 07:44:39 -05:00
|
|
|
private:
|
|
|
|
TaskHandle_t taskHandle;
|
|
|
|
|
|
|
|
Pinetime::Drivers::SpiMaster& spi;
|
|
|
|
Pinetime::Drivers::St7789& lcd;
|
2020-05-07 13:53:51 -04:00
|
|
|
Pinetime::Drivers::SpiNorFlash& spiNorFlash;
|
2020-07-19 14:30:44 -04:00
|
|
|
Pinetime::Drivers::TwiMaster& twiMaster;
|
2020-02-23 07:44:39 -05:00
|
|
|
Pinetime::Drivers::Cst816S& touchPanel;
|
|
|
|
Pinetime::Components::LittleVgl& lvgl;
|
|
|
|
Pinetime::Controllers::Battery& batteryController;
|
|
|
|
std::unique_ptr<Pinetime::Applications::DisplayApp> displayApp;
|
|
|
|
Pinetime::Controllers::Ble& bleController;
|
|
|
|
Pinetime::Controllers::DateTime& dateTimeController;
|
|
|
|
QueueHandle_t systemTaksMsgQueue;
|
|
|
|
bool isSleeping = false;
|
2020-02-23 15:09:11 -05:00
|
|
|
Pinetime::Drivers::Watchdog watchdog;
|
2020-03-22 07:03:17 -04:00
|
|
|
Pinetime::Drivers::WatchdogView watchdogView;
|
2020-03-28 14:05:28 -04:00
|
|
|
Pinetime::Controllers::NotificationManager& notificationManager;
|
2020-04-19 15:26:09 -04:00
|
|
|
Pinetime::Controllers::NimbleController nimbleController;
|
2020-02-23 07:44:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
static constexpr uint8_t pinSpiSck = 2;
|
|
|
|
static constexpr uint8_t pinSpiMosi = 3;
|
|
|
|
static constexpr uint8_t pinSpiMiso = 4;
|
|
|
|
static constexpr uint8_t pinSpiCsn = 25;
|
|
|
|
static constexpr uint8_t pinLcdDataCommand = 18;
|
|
|
|
static constexpr uint8_t pinButton = 13;
|
|
|
|
static constexpr uint8_t pinTouchIrq = 28;
|
|
|
|
|
|
|
|
static void Process(void* instance);
|
|
|
|
void Work();
|
2020-07-04 12:10:30 -04:00
|
|
|
void ReloadIdleTimer() const;
|
2020-05-01 15:58:31 -04:00
|
|
|
bool isBleDiscoveryTimerRunning = false;
|
|
|
|
uint8_t bleDiscoveryTimer = 0;
|
2020-06-07 14:05:04 -04:00
|
|
|
static constexpr uint32_t idleTime = 15000;
|
2020-06-01 14:40:11 -04:00
|
|
|
TimerHandle_t idleTimer;
|
|
|
|
bool doNotGoToSleep = false;
|
2020-02-23 07:44:39 -05:00
|
|
|
|
2020-06-01 14:40:11 -04:00
|
|
|
void GoToRunning();
|
2020-07-02 15:38:52 -04:00
|
|
|
|
|
|
|
#if configUSE_TRACE_FACILITY == 1
|
|
|
|
SystemMonitor<FreeRtosMonitor> monitor;
|
|
|
|
#else
|
|
|
|
SystemMonitor<DummyMonitor> monitor;
|
|
|
|
#endif
|
2020-02-23 07:44:39 -05:00
|
|
|
};
|
|
|
|
}
|
2020-07-11 16:37:28 -04:00
|
|
|
}
|