Re-implement sleep/wakeup for touch panel, display, NOR Flash, SPI and TWI.
This commit is contained in:
parent
ecbbeb6283
commit
f7e40b1b58
|
@ -95,14 +95,10 @@ void DisplayApp::Refresh() {
|
||||||
vTaskDelay(100);
|
vTaskDelay(100);
|
||||||
}
|
}
|
||||||
lcd.DisplayOff();
|
lcd.DisplayOff();
|
||||||
lcd.Sleep();
|
systemTask.PushMessage(System::SystemTask::Messages::OnDisplayTaskSleeping);
|
||||||
touchPanel.Sleep();
|
|
||||||
state = States::Idle;
|
state = States::Idle;
|
||||||
break;
|
break;
|
||||||
case Messages::GoToRunning:
|
case Messages::GoToRunning:
|
||||||
lcd.Wakeup();
|
|
||||||
touchPanel.Wakeup();
|
|
||||||
|
|
||||||
lcd.DisplayOn();
|
lcd.DisplayOn();
|
||||||
brightnessController.Restore();
|
brightnessController.Restore();
|
||||||
state = States::Running;
|
state = States::Running;
|
||||||
|
@ -173,7 +169,7 @@ void DisplayApp::Refresh() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(touchMode == TouchModes::Polling) {
|
if(state != States::Idle && touchMode == TouchModes::Polling) {
|
||||||
auto info = touchPanel.GetTouchInfo();
|
auto info = touchPanel.GetTouchInfo();
|
||||||
if(info.action == 2) {// 2 = contact
|
if(info.action == 2) {// 2 = contact
|
||||||
if(!currentScreen->OnTouchEvent(info.x, info.y)) {
|
if(!currentScreen->OnTouchEvent(info.x, info.y)) {
|
||||||
|
|
|
@ -145,6 +145,14 @@ void SystemTask::Work() {
|
||||||
case Messages::OnButtonEvent:
|
case Messages::OnButtonEvent:
|
||||||
ReloadIdleTimer();
|
ReloadIdleTimer();
|
||||||
break;
|
break;
|
||||||
|
case Messages::OnDisplayTaskSleeping:
|
||||||
|
spiNorFlash.Sleep();
|
||||||
|
lcd.Sleep();
|
||||||
|
touchPanel.Sleep();
|
||||||
|
|
||||||
|
spi.Sleep();
|
||||||
|
twiMaster.Sleep();
|
||||||
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,6 +193,13 @@ void SystemTask::OnButtonPushed() {
|
||||||
|
|
||||||
void SystemTask::GoToRunning() {
|
void SystemTask::GoToRunning() {
|
||||||
PushMessage(Messages::GoToRunning);
|
PushMessage(Messages::GoToRunning);
|
||||||
|
spi.Wakeup();
|
||||||
|
twiMaster.Wakeup();
|
||||||
|
|
||||||
|
spiNorFlash.Wakeup();
|
||||||
|
lcd.Wakeup();
|
||||||
|
touchPanel.Wakeup();
|
||||||
|
|
||||||
displayApp->PushMessage(Applications::DisplayApp::Messages::GoToRunning);
|
displayApp->PushMessage(Applications::DisplayApp::Messages::GoToRunning);
|
||||||
displayApp->PushMessage(Applications::DisplayApp::Messages::UpdateBatteryLevel);
|
displayApp->PushMessage(Applications::DisplayApp::Messages::UpdateBatteryLevel);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace Pinetime {
|
||||||
class SystemTask {
|
class SystemTask {
|
||||||
public:
|
public:
|
||||||
enum class Messages {GoToSleep, GoToRunning, OnNewTime, OnNewNotification, BleConnected,
|
enum class Messages {GoToSleep, GoToRunning, OnNewTime, OnNewNotification, BleConnected,
|
||||||
BleFirmwareUpdateStarted, BleFirmwareUpdateFinished, OnTouchEvent, OnButtonEvent
|
BleFirmwareUpdateStarted, BleFirmwareUpdateFinished, OnTouchEvent, OnButtonEvent, OnDisplayTaskSleeping
|
||||||
};
|
};
|
||||||
|
|
||||||
SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd,
|
SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd,
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#include <task.h>
|
#include <task.h>
|
||||||
#include <nrfx_log.h>
|
#include <nrfx_log.h>
|
||||||
#include <legacy/nrf_drv_gpiote.h>
|
#include <legacy/nrf_drv_gpiote.h>
|
||||||
|
|
||||||
#include "Cst816s.h"
|
#include "Cst816s.h"
|
||||||
using namespace Pinetime::Drivers;
|
using namespace Pinetime::Drivers;
|
||||||
|
|
||||||
|
@ -96,12 +95,16 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cst816S::Sleep() {
|
void Cst816S::Sleep() {
|
||||||
// TODO re enable sleep mode
|
nrf_gpio_pin_clear(pinReset);
|
||||||
//twiMaster.Sleep();
|
vTaskDelay(5);
|
||||||
nrf_gpio_cfg_default(6);
|
nrf_gpio_pin_set(pinReset);
|
||||||
nrf_gpio_cfg_default(7);
|
vTaskDelay(50);
|
||||||
|
static constexpr uint8_t sleepValue = 0x03;
|
||||||
|
twiMaster.Write(twiAddress, 0xA5, &sleepValue, 1);
|
||||||
|
NRF_LOG_INFO("[TOUCHPANEL] Sleep");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cst816S::Wakeup() {
|
void Cst816S::Wakeup() {
|
||||||
Init();
|
Init();
|
||||||
|
NRF_LOG_INFO("[TOUCHPANEL] Wakeup");
|
||||||
}
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
#include <hal/nrf_gpio.h>
|
#include <hal/nrf_gpio.h>
|
||||||
|
#include <nrfx_log.h>
|
||||||
#include "Spi.h"
|
#include "Spi.h"
|
||||||
|
|
||||||
using namespace Pinetime::Drivers;
|
using namespace Pinetime::Drivers;
|
||||||
|
@ -18,8 +19,12 @@ bool Spi::Read(uint8_t* cmd, size_t cmdSize, uint8_t *data, size_t dataSize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Spi::Sleep() {
|
void Spi::Sleep() {
|
||||||
// TODO sleep spi
|
|
||||||
nrf_gpio_cfg_default(pinCsn);
|
nrf_gpio_cfg_default(pinCsn);
|
||||||
|
NRF_LOG_INFO("[SPI] Sleep")
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Spi::WriteCmdAndBuffer(const uint8_t *cmd, size_t cmdSize, const uint8_t *data, size_t dataSize) {
|
||||||
|
return spiMaster.WriteCmdAndBuffer(pinCsn, cmd, cmdSize, data, dataSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Spi::Init() {
|
bool Spi::Init() {
|
||||||
|
@ -27,8 +32,10 @@ bool Spi::Init() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Spi::WriteCmdAndBuffer(const uint8_t *cmd, size_t cmdSize, const uint8_t *data, size_t dataSize) {
|
void Spi::Wakeup() {
|
||||||
return spiMaster.WriteCmdAndBuffer(pinCsn, cmd, cmdSize, data, dataSize);
|
nrf_gpio_cfg_output(pinCsn);
|
||||||
|
nrf_gpio_pin_set(pinCsn);
|
||||||
|
NRF_LOG_INFO("[SPI] Wakeup")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "SpiMaster.h"
|
#include "SpiMaster.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <task.h>
|
#include <task.h>
|
||||||
|
#include <nrfx_log.h>
|
||||||
|
|
||||||
using namespace Pinetime::Drivers;
|
using namespace Pinetime::Drivers;
|
||||||
|
|
||||||
|
@ -231,10 +232,13 @@ void SpiMaster::Sleep() {
|
||||||
nrf_gpio_cfg_default(params.pinSCK);
|
nrf_gpio_cfg_default(params.pinSCK);
|
||||||
nrf_gpio_cfg_default(params.pinMOSI);
|
nrf_gpio_cfg_default(params.pinMOSI);
|
||||||
nrf_gpio_cfg_default(params.pinMISO);
|
nrf_gpio_cfg_default(params.pinMISO);
|
||||||
|
|
||||||
|
NRF_LOG_INFO("[SPIMASTER] sleep")
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpiMaster::Wakeup() {
|
void SpiMaster::Wakeup() {
|
||||||
Init();
|
Init();
|
||||||
|
NRF_LOG_INFO("[SPIMASTER] Wakeup");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpiMaster::WriteCmdAndBuffer(uint8_t pinCsn, const uint8_t *cmd, size_t cmdSize, const uint8_t *data, size_t dataSize) {
|
bool SpiMaster::WriteCmdAndBuffer(uint8_t pinCsn, const uint8_t *cmd, size_t cmdSize, const uint8_t *data, size_t dataSize) {
|
||||||
|
|
|
@ -11,8 +11,8 @@ SpiNorFlash::SpiNorFlash(Spi& spi) : spi{spi} {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpiNorFlash::Init() {
|
void SpiNorFlash::Init() {
|
||||||
auto id = ReadIdentificaion();
|
device_id = ReadIdentificaion();
|
||||||
NRF_LOG_INFO("[SPI FLASH] Manufacturer : %d, Memory type : %d, memory density : %d", id.manufacturer, id.type, id.density);
|
NRF_LOG_INFO("[SPI FLASH] Manufacturer : %d, Memory type : %d, memory density : %d", device_id.manufacturer, device_id.type, device_id.density);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpiNorFlash::Uninit() {
|
void SpiNorFlash::Uninit() {
|
||||||
|
@ -20,11 +20,25 @@ void SpiNorFlash::Uninit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpiNorFlash::Sleep() {
|
void SpiNorFlash::Sleep() {
|
||||||
|
auto cmd = static_cast<uint8_t>(Commands::DeepPowerDown);
|
||||||
|
spi.Write(&cmd, sizeof(uint8_t));
|
||||||
|
NRF_LOG_INFO("[FLASH] Sleep")
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpiNorFlash::Wakeup() {
|
void SpiNorFlash::Wakeup() {
|
||||||
|
// send Commands::ReleaseFromDeepPowerDown then 3 dummy bytes before reading Device ID
|
||||||
|
static constexpr uint8_t cmdSize = 4;
|
||||||
|
uint8_t cmd[cmdSize] = {static_cast<uint8_t>(Commands::ReleaseFromDeepPowerDown), 0x01, 0x02, 0x03};
|
||||||
|
uint8_t id = 0;
|
||||||
|
spi.Read(reinterpret_cast<uint8_t *>(&cmd), cmdSize, &id, 1);
|
||||||
|
auto devId = device_id = ReadIdentificaion();
|
||||||
|
if(devId.type != device_id.type) {
|
||||||
|
NRF_LOG_INFO("[SpiNorFlash] ID on Wakeup: Failed");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
NRF_LOG_INFO("[SpiNorFlash] ID on Wakeup: %d", id);
|
||||||
|
}
|
||||||
|
NRF_LOG_INFO("[FLASH] Wakeup")
|
||||||
}
|
}
|
||||||
|
|
||||||
SpiNorFlash::Identification SpiNorFlash::ReadIdentificaion() {
|
SpiNorFlash::Identification SpiNorFlash::ReadIdentificaion() {
|
||||||
|
|
|
@ -48,11 +48,13 @@ namespace Pinetime {
|
||||||
SectorErase = 0x20,
|
SectorErase = 0x20,
|
||||||
ReadSecurityRegister = 0x2B,
|
ReadSecurityRegister = 0x2B,
|
||||||
ReadIdentification = 0x9F,
|
ReadIdentification = 0x9F,
|
||||||
|
ReleaseFromDeepPowerDown = 0xAB,
|
||||||
|
DeepPowerDown = 0xB9
|
||||||
};
|
};
|
||||||
static constexpr uint16_t pageSize = 256;
|
static constexpr uint16_t pageSize = 256;
|
||||||
|
|
||||||
Spi& spi;
|
Spi& spi;
|
||||||
|
Identification device_id;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <hal/nrf_gpio.h>
|
#include <hal/nrf_gpio.h>
|
||||||
#include <libraries/delay/nrf_delay.h>
|
#include <libraries/delay/nrf_delay.h>
|
||||||
|
#include <nrfx_log.h>
|
||||||
#include "St7789.h"
|
#include "St7789.h"
|
||||||
#include "Spi.h"
|
#include "Spi.h"
|
||||||
|
|
||||||
|
@ -174,12 +175,10 @@ void St7789::HardwareReset() {
|
||||||
void St7789::Sleep() {
|
void St7789::Sleep() {
|
||||||
SleepIn();
|
SleepIn();
|
||||||
nrf_gpio_cfg_default(pinDataCommand);
|
nrf_gpio_cfg_default(pinDataCommand);
|
||||||
// spi.Sleep(); // TODO sleep SPI
|
NRF_LOG_INFO("[LCD] Sleep");
|
||||||
}
|
}
|
||||||
|
|
||||||
void St7789::Wakeup() {
|
void St7789::Wakeup() {
|
||||||
// spi.Wakeup(); // TODO wake up SPI
|
|
||||||
|
|
||||||
nrf_gpio_cfg_output(pinDataCommand);
|
nrf_gpio_cfg_output(pinDataCommand);
|
||||||
// TODO why do we need to reset the controller?
|
// TODO why do we need to reset the controller?
|
||||||
HardwareReset();
|
HardwareReset();
|
||||||
|
@ -193,4 +192,5 @@ void St7789::Wakeup() {
|
||||||
NormalModeOn();
|
NormalModeOn();
|
||||||
VerticalScrollStartAddress(verticalScrollingStartAddress);
|
VerticalScrollStartAddress(verticalScrollingStartAddress);
|
||||||
DisplayOn();
|
DisplayOn();
|
||||||
|
NRF_LOG_INFO("[LCD] Wakeup")
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,3 +138,15 @@ void TwiMaster::Write(uint8_t deviceAddress, const uint8_t *data, size_t size, b
|
||||||
twiBaseAddress->ERRORSRC = error;
|
twiBaseAddress->ERRORSRC = error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TwiMaster::Sleep() {
|
||||||
|
nrf_gpio_cfg_default(6);
|
||||||
|
nrf_gpio_cfg_default(7);
|
||||||
|
twiBaseAddress->ENABLE = 0;
|
||||||
|
NRF_LOG_INFO("[TWIMASTER] Sleep");
|
||||||
|
}
|
||||||
|
|
||||||
|
void TwiMaster::Wakeup() {
|
||||||
|
Init();
|
||||||
|
NRF_LOG_INFO("[TWIMASTER] Wakeup");
|
||||||
|
}
|
||||||
|
|
|
@ -22,6 +22,9 @@ namespace Pinetime {
|
||||||
void Read(uint8_t deviceAddress, uint8_t registerAddress, uint8_t* buffer, size_t size);
|
void Read(uint8_t deviceAddress, uint8_t registerAddress, uint8_t* buffer, size_t size);
|
||||||
void Write(uint8_t deviceAddress, uint8_t registerAddress, const uint8_t* data, size_t size);
|
void Write(uint8_t deviceAddress, uint8_t registerAddress, const uint8_t* data, size_t size);
|
||||||
|
|
||||||
|
void Sleep();
|
||||||
|
void Wakeup();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Read(uint8_t deviceAddress, uint8_t* buffer, size_t size, bool stop);
|
void Read(uint8_t deviceAddress, uint8_t* buffer, size_t size, bool stop);
|
||||||
void Write(uint8_t deviceAddress, const uint8_t* data, size_t size, bool stop);
|
void Write(uint8_t deviceAddress, const uint8_t* data, size_t size, bool stop);
|
||||||
|
|
Loading…
Reference in a new issue