Re-implement sleep/wakeup for touch panel, display, NOR Flash, SPI and TWI.

This commit is contained in:
JF 2020-08-22 17:59:59 +02:00
parent ecbbeb6283
commit f7e40b1b58
11 changed files with 80 additions and 24 deletions

View file

@ -95,14 +95,10 @@ void DisplayApp::Refresh() {
vTaskDelay(100);
}
lcd.DisplayOff();
lcd.Sleep();
touchPanel.Sleep();
systemTask.PushMessage(System::SystemTask::Messages::OnDisplayTaskSleeping);
state = States::Idle;
break;
case Messages::GoToRunning:
lcd.Wakeup();
touchPanel.Wakeup();
lcd.DisplayOn();
brightnessController.Restore();
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();
if(info.action == 2) {// 2 = contact
if(!currentScreen->OnTouchEvent(info.x, info.y)) {

View file

@ -145,6 +145,14 @@ void SystemTask::Work() {
case Messages::OnButtonEvent:
ReloadIdleTimer();
break;
case Messages::OnDisplayTaskSleeping:
spiNorFlash.Sleep();
lcd.Sleep();
touchPanel.Sleep();
spi.Sleep();
twiMaster.Sleep();
break;
default: break;
}
}
@ -185,6 +193,13 @@ void SystemTask::OnButtonPushed() {
void SystemTask::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::UpdateBatteryLevel);
}

View file

@ -18,7 +18,7 @@ namespace Pinetime {
class SystemTask {
public:
enum class Messages {GoToSleep, GoToRunning, OnNewTime, OnNewNotification, BleConnected,
BleFirmwareUpdateStarted, BleFirmwareUpdateFinished, OnTouchEvent, OnButtonEvent
BleFirmwareUpdateStarted, BleFirmwareUpdateFinished, OnTouchEvent, OnButtonEvent, OnDisplayTaskSleeping
};
SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd,

View file

@ -2,7 +2,6 @@
#include <task.h>
#include <nrfx_log.h>
#include <legacy/nrf_drv_gpiote.h>
#include "Cst816s.h"
using namespace Pinetime::Drivers;
@ -96,12 +95,16 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() {
}
void Cst816S::Sleep() {
// TODO re enable sleep mode
//twiMaster.Sleep();
nrf_gpio_cfg_default(6);
nrf_gpio_cfg_default(7);
nrf_gpio_pin_clear(pinReset);
vTaskDelay(5);
nrf_gpio_pin_set(pinReset);
vTaskDelay(50);
static constexpr uint8_t sleepValue = 0x03;
twiMaster.Write(twiAddress, 0xA5, &sleepValue, 1);
NRF_LOG_INFO("[TOUCHPANEL] Sleep");
}
void Cst816S::Wakeup() {
Init();
NRF_LOG_INFO("[TOUCHPANEL] Wakeup");
}

View file

@ -1,4 +1,5 @@
#include <hal/nrf_gpio.h>
#include <nrfx_log.h>
#include "Spi.h"
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() {
// TODO sleep spi
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() {
@ -27,8 +32,10 @@ bool Spi::Init() {
return true;
}
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);
void Spi::Wakeup() {
nrf_gpio_cfg_output(pinCsn);
nrf_gpio_pin_set(pinCsn);
NRF_LOG_INFO("[SPI] Wakeup")
}

View file

@ -4,6 +4,7 @@
#include "SpiMaster.h"
#include <algorithm>
#include <task.h>
#include <nrfx_log.h>
using namespace Pinetime::Drivers;
@ -231,10 +232,13 @@ void SpiMaster::Sleep() {
nrf_gpio_cfg_default(params.pinSCK);
nrf_gpio_cfg_default(params.pinMOSI);
nrf_gpio_cfg_default(params.pinMISO);
NRF_LOG_INFO("[SPIMASTER] sleep")
}
void SpiMaster::Wakeup() {
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) {

View file

@ -11,8 +11,8 @@ SpiNorFlash::SpiNorFlash(Spi& spi) : spi{spi} {
}
void SpiNorFlash::Init() {
auto id = ReadIdentificaion();
NRF_LOG_INFO("[SPI FLASH] Manufacturer : %d, Memory type : %d, memory density : %d", id.manufacturer, id.type, id.density);
device_id = ReadIdentificaion();
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() {
@ -20,11 +20,25 @@ void SpiNorFlash::Uninit() {
}
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() {
// 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() {

View file

@ -48,11 +48,13 @@ namespace Pinetime {
SectorErase = 0x20,
ReadSecurityRegister = 0x2B,
ReadIdentification = 0x9F,
ReleaseFromDeepPowerDown = 0xAB,
DeepPowerDown = 0xB9
};
static constexpr uint16_t pageSize = 256;
Spi& spi;
Identification device_id;
};
}
}

View file

@ -1,5 +1,6 @@
#include <hal/nrf_gpio.h>
#include <libraries/delay/nrf_delay.h>
#include <nrfx_log.h>
#include "St7789.h"
#include "Spi.h"
@ -174,12 +175,10 @@ void St7789::HardwareReset() {
void St7789::Sleep() {
SleepIn();
nrf_gpio_cfg_default(pinDataCommand);
// spi.Sleep(); // TODO sleep SPI
NRF_LOG_INFO("[LCD] Sleep");
}
void St7789::Wakeup() {
// spi.Wakeup(); // TODO wake up SPI
nrf_gpio_cfg_output(pinDataCommand);
// TODO why do we need to reset the controller?
HardwareReset();
@ -193,4 +192,5 @@ void St7789::Wakeup() {
NormalModeOn();
VerticalScrollStartAddress(verticalScrollingStartAddress);
DisplayOn();
NRF_LOG_INFO("[LCD] Wakeup")
}

View file

@ -137,4 +137,16 @@ void TwiMaster::Write(uint8_t deviceAddress, const uint8_t *data, size_t size, b
uint32_t error = twiBaseAddress->ERRORSRC;
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");
}

View file

@ -22,6 +22,9 @@ namespace Pinetime {
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 Sleep();
void Wakeup();
private:
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);