mirror of
https://github.com/InfiniTimeOrg/InfiniTime.git
synced 2024-10-22 15:11:51 +02:00
Merge branch 'main' into improve-alarm-preview
This commit is contained in:
commit
c12dbe5c8b
|
@ -75,6 +75,7 @@
|
|||
#define configUSE_TIME_SLICING 0
|
||||
#define configUSE_NEWLIB_REENTRANT 0
|
||||
#define configENABLE_BACKWARD_COMPATIBILITY 1
|
||||
#define configUSE_TASK_NOTIFICATIONS 0
|
||||
|
||||
/* Hook function related definitions. */
|
||||
#define configUSE_IDLE_HOOK 0
|
||||
|
|
|
@ -125,6 +125,7 @@ void DisplayApp::Start(System::BootErrors error) {
|
|||
bootError = error;
|
||||
|
||||
lvgl.Init();
|
||||
motorController.Init();
|
||||
|
||||
if (error == System::BootErrors::TouchController) {
|
||||
LoadNewScreen(Apps::Error, DisplayApp::FullRefreshDirections::None);
|
||||
|
@ -142,9 +143,6 @@ void DisplayApp::Process(void* instance) {
|
|||
NRF_LOG_INFO("displayapp task started!");
|
||||
app->InitHw();
|
||||
|
||||
// Send a dummy notification to unlock the lvgl display driver for the first iteration
|
||||
xTaskNotifyGive(xTaskGetCurrentTaskHandle());
|
||||
|
||||
while (true) {
|
||||
app->Refresh();
|
||||
}
|
||||
|
@ -153,7 +151,6 @@ void DisplayApp::Process(void* instance) {
|
|||
void DisplayApp::InitHw() {
|
||||
brightnessController.Init();
|
||||
ApplyBrightness();
|
||||
motorController.Init();
|
||||
lcd.Init();
|
||||
}
|
||||
|
||||
|
|
|
@ -38,9 +38,6 @@ void DisplayApp::Process(void* instance) {
|
|||
auto* app = static_cast<DisplayApp*>(instance);
|
||||
NRF_LOG_INFO("displayapp task started!");
|
||||
|
||||
// Send a dummy notification to unlock the lvgl display driver for the first iteration
|
||||
xTaskNotifyGive(xTaskGetCurrentTaskHandle());
|
||||
|
||||
app->InitHw();
|
||||
while (true) {
|
||||
app->Refresh();
|
||||
|
@ -94,7 +91,6 @@ void DisplayApp::DisplayLogo(uint16_t color) {
|
|||
Pinetime::Tools::RleDecoder rleDecoder(infinitime_nb, sizeof(infinitime_nb), color, colorBlack);
|
||||
for (int i = 0; i < displayWidth; i++) {
|
||||
rleDecoder.DecodeNext(displayBuffer, displayWidth * bytesPerPixel);
|
||||
ulTaskNotifyTake(pdTRUE, 500);
|
||||
lcd.DrawBuffer(0, i, displayWidth, 1, reinterpret_cast<const uint8_t*>(displayBuffer), displayWidth * bytesPerPixel);
|
||||
}
|
||||
}
|
||||
|
@ -103,7 +99,6 @@ void DisplayApp::DisplayOtaProgress(uint8_t percent, uint16_t color) {
|
|||
const uint8_t barHeight = 20;
|
||||
std::fill(displayBuffer, displayBuffer + (displayWidth * bytesPerPixel), color);
|
||||
for (int i = 0; i < barHeight; i++) {
|
||||
ulTaskNotifyTake(pdTRUE, 500);
|
||||
uint16_t barWidth = std::min(static_cast<float>(percent) * 2.4f, static_cast<float>(displayWidth));
|
||||
lcd.DrawBuffer(0, displayWidth - barHeight + i, barWidth, 1, reinterpret_cast<const uint8_t*>(displayBuffer), barWidth * bytesPerPixel);
|
||||
}
|
||||
|
|
|
@ -152,10 +152,6 @@ void LittleVgl::SetFullRefresh(FullRefreshDirections direction) {
|
|||
void LittleVgl::FlushDisplay(const lv_area_t* area, lv_color_t* color_p) {
|
||||
uint16_t y1, y2, width, height = 0;
|
||||
|
||||
ulTaskNotifyTake(pdTRUE, 200);
|
||||
// Notification is still needed (even if there is a mutex on SPI) because of the DataCommand pin
|
||||
// which cannot be set/clear during a transfer.
|
||||
|
||||
if ((scrollDirection == LittleVgl::FullRefreshDirections::Down) && (area->y2 == visibleNbLines - 1)) {
|
||||
writeOffset = ((writeOffset + totalNbLines) - visibleNbLines) % totalNbLines;
|
||||
} else if ((scrollDirection == FullRefreshDirections::Up) && (area->y1 == 0)) {
|
||||
|
@ -219,7 +215,6 @@ void LittleVgl::FlushDisplay(const lv_area_t* area, lv_color_t* color_p) {
|
|||
|
||||
if (height > 0) {
|
||||
lcd.DrawBuffer(area->x1, y1, width, height, reinterpret_cast<const uint8_t*>(color_p), width * height * 2);
|
||||
ulTaskNotifyTake(pdTRUE, 100);
|
||||
}
|
||||
|
||||
uint16_t pixOffset = width * height;
|
||||
|
|
|
@ -126,13 +126,6 @@ Bma421::Values Bma421::Process() {
|
|||
uint32_t steps = 0;
|
||||
bma423_step_counter_output(&steps, &bma);
|
||||
|
||||
int32_t temperature;
|
||||
bma4_get_temperature(&temperature, BMA4_DEG, &bma);
|
||||
temperature = temperature / 1000;
|
||||
|
||||
uint8_t activity = 0;
|
||||
bma423_activity_output(&activity, &bma);
|
||||
|
||||
// X and Y axis are swapped because of the way the sensor is mounted in the PineTime
|
||||
return {steps, data.y, data.x, data.z};
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ Spi::Spi(SpiMaster& spiMaster, uint8_t pinCsn) : spiMaster {spiMaster}, pinCsn {
|
|||
nrf_gpio_pin_set(pinCsn);
|
||||
}
|
||||
|
||||
bool Spi::Write(const uint8_t* data, size_t size) {
|
||||
return spiMaster.Write(pinCsn, data, size);
|
||||
bool Spi::Write(const uint8_t* data, size_t size, const std::function<void()>& preTransactionHook) {
|
||||
return spiMaster.Write(pinCsn, data, size, preTransactionHook);
|
||||
}
|
||||
|
||||
bool Spi::Read(uint8_t* cmd, size_t cmdSize, uint8_t* data, size_t dataSize) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include "drivers/SpiMaster.h"
|
||||
|
||||
namespace Pinetime {
|
||||
|
@ -14,7 +15,7 @@ namespace Pinetime {
|
|||
Spi& operator=(Spi&&) = delete;
|
||||
|
||||
bool Init();
|
||||
bool Write(const uint8_t* data, size_t size);
|
||||
bool Write(const uint8_t* data, size_t size, const std::function<void()>& preTransactionHook);
|
||||
bool Read(uint8_t* cmd, size_t cmdSize, uint8_t* data, size_t dataSize);
|
||||
bool WriteCmdAndBuffer(const uint8_t* cmd, size_t cmdSize, const uint8_t* data, size_t dataSize);
|
||||
void Sleep();
|
||||
|
|
|
@ -94,32 +94,45 @@ bool SpiMaster::Init() {
|
|||
return true;
|
||||
}
|
||||
|
||||
void SpiMaster::SetupWorkaroundForFtpan58(NRF_SPIM_Type* spim, uint32_t ppi_channel, uint32_t gpiote_channel) {
|
||||
// Create an event when SCK toggles.
|
||||
NRF_GPIOTE->CONFIG[gpiote_channel] = (GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos) | (spim->PSEL.SCK << GPIOTE_CONFIG_PSEL_Pos) |
|
||||
(GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos);
|
||||
void SpiMaster::SetupWorkaroundForErratum58() {
|
||||
nrfx_gpiote_pin_t pin = spiBaseAddress->PSEL.SCK;
|
||||
nrfx_gpiote_in_config_t gpioteCfg = {.sense = NRF_GPIOTE_POLARITY_TOGGLE,
|
||||
.pull = NRF_GPIO_PIN_NOPULL,
|
||||
.is_watcher = false,
|
||||
.hi_accuracy = true,
|
||||
.skip_gpio_setup = true};
|
||||
if (!workaroundActive) {
|
||||
// Create an event when SCK toggles.
|
||||
APP_ERROR_CHECK(nrfx_gpiote_in_init(pin, &gpioteCfg, NULL));
|
||||
nrfx_gpiote_in_event_enable(pin, false);
|
||||
|
||||
// Stop the spim instance when SCK toggles.
|
||||
nrf_ppi_channel_endpoint_setup(workaroundPpi, nrfx_gpiote_in_event_addr_get(pin), spiBaseAddress->TASKS_STOP);
|
||||
nrf_ppi_channel_enable(workaroundPpi);
|
||||
}
|
||||
|
||||
// Stop the spim instance when SCK toggles.
|
||||
NRF_PPI->CH[ppi_channel].EEP = (uint32_t) &NRF_GPIOTE->EVENTS_IN[gpiote_channel];
|
||||
NRF_PPI->CH[ppi_channel].TEP = (uint32_t) &spim->TASKS_STOP;
|
||||
NRF_PPI->CHENSET = 1U << ppi_channel;
|
||||
spiBaseAddress->EVENTS_END = 0;
|
||||
|
||||
// Disable IRQ
|
||||
spim->INTENCLR = (1 << 6);
|
||||
spim->INTENCLR = (1 << 1);
|
||||
spim->INTENCLR = (1 << 19);
|
||||
spiBaseAddress->INTENCLR = (1 << 6);
|
||||
spiBaseAddress->INTENCLR = (1 << 1);
|
||||
spiBaseAddress->INTENCLR = (1 << 19);
|
||||
workaroundActive = true;
|
||||
}
|
||||
|
||||
void SpiMaster::DisableWorkaroundForFtpan58(NRF_SPIM_Type* spim, uint32_t ppi_channel, uint32_t gpiote_channel) {
|
||||
NRF_GPIOTE->CONFIG[gpiote_channel] = 0;
|
||||
NRF_PPI->CH[ppi_channel].EEP = 0;
|
||||
NRF_PPI->CH[ppi_channel].TEP = 0;
|
||||
NRF_PPI->CHENSET = ppi_channel;
|
||||
void SpiMaster::DisableWorkaroundForErratum58() {
|
||||
nrfx_gpiote_pin_t pin = spiBaseAddress->PSEL.SCK;
|
||||
if (workaroundActive) {
|
||||
nrfx_gpiote_in_uninit(pin);
|
||||
nrf_ppi_channel_disable(workaroundPpi);
|
||||
}
|
||||
spiBaseAddress->EVENTS_END = 0;
|
||||
spim->INTENSET = (1 << 6);
|
||||
spim->INTENSET = (1 << 1);
|
||||
spim->INTENSET = (1 << 19);
|
||||
|
||||
// Enable IRQ
|
||||
spiBaseAddress->INTENSET = (1 << 6);
|
||||
spiBaseAddress->INTENSET = (1 << 1);
|
||||
spiBaseAddress->INTENSET = (1 << 19);
|
||||
workaroundActive = false;
|
||||
}
|
||||
|
||||
void SpiMaster::OnEndEvent() {
|
||||
|
@ -136,17 +149,11 @@ void SpiMaster::OnEndEvent() {
|
|||
|
||||
spiBaseAddress->TASKS_START = 1;
|
||||
} else {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
if (taskToNotify != nullptr) {
|
||||
vTaskNotifyGiveFromISR(taskToNotify, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
nrf_gpio_pin_set(this->pinCsn);
|
||||
currentBufferAddr = 0;
|
||||
BaseType_t xHigherPriorityTaskWoken2 = pdFALSE;
|
||||
xSemaphoreGiveFromISR(mutex, &xHigherPriorityTaskWoken2);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken | xHigherPriorityTaskWoken2);
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
xSemaphoreGiveFromISR(mutex, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,21 +180,23 @@ void SpiMaster::PrepareRx(const uint32_t bufferAddress, const size_t size) {
|
|||
spiBaseAddress->EVENTS_END = 0;
|
||||
}
|
||||
|
||||
bool SpiMaster::Write(uint8_t pinCsn, const uint8_t* data, size_t size) {
|
||||
bool SpiMaster::Write(uint8_t pinCsn, const uint8_t* data, size_t size, const std::function<void()>& preTransactionHook) {
|
||||
if (data == nullptr)
|
||||
return false;
|
||||
auto ok = xSemaphoreTake(mutex, portMAX_DELAY);
|
||||
ASSERT(ok == true);
|
||||
taskToNotify = xTaskGetCurrentTaskHandle();
|
||||
|
||||
this->pinCsn = pinCsn;
|
||||
|
||||
if (size == 1) {
|
||||
SetupWorkaroundForFtpan58(spiBaseAddress, 0, 0);
|
||||
SetupWorkaroundForErratum58();
|
||||
} else {
|
||||
DisableWorkaroundForFtpan58(spiBaseAddress, 0, 0);
|
||||
DisableWorkaroundForErratum58();
|
||||
}
|
||||
|
||||
if (preTransactionHook != nullptr) {
|
||||
preTransactionHook();
|
||||
}
|
||||
nrf_gpio_pin_clear(this->pinCsn);
|
||||
|
||||
currentBufferAddr = (uint32_t) data;
|
||||
|
@ -205,7 +214,7 @@ bool SpiMaster::Write(uint8_t pinCsn, const uint8_t* data, size_t size) {
|
|||
nrf_gpio_pin_set(this->pinCsn);
|
||||
currentBufferAddr = 0;
|
||||
|
||||
DisableWorkaroundForFtpan58(spiBaseAddress, 0, 0);
|
||||
DisableWorkaroundForErratum58();
|
||||
|
||||
xSemaphoreGive(mutex);
|
||||
}
|
||||
|
@ -216,10 +225,8 @@ bool SpiMaster::Write(uint8_t pinCsn, const uint8_t* data, size_t size) {
|
|||
bool SpiMaster::Read(uint8_t pinCsn, uint8_t* cmd, size_t cmdSize, uint8_t* data, size_t dataSize) {
|
||||
xSemaphoreTake(mutex, portMAX_DELAY);
|
||||
|
||||
taskToNotify = nullptr;
|
||||
|
||||
this->pinCsn = pinCsn;
|
||||
DisableWorkaroundForFtpan58(spiBaseAddress, 0, 0);
|
||||
DisableWorkaroundForErratum58();
|
||||
spiBaseAddress->INTENCLR = (1 << 6);
|
||||
spiBaseAddress->INTENCLR = (1 << 1);
|
||||
spiBaseAddress->INTENCLR = (1 << 19);
|
||||
|
@ -265,10 +272,8 @@ void SpiMaster::Wakeup() {
|
|||
bool SpiMaster::WriteCmdAndBuffer(uint8_t pinCsn, const uint8_t* cmd, size_t cmdSize, const uint8_t* data, size_t dataSize) {
|
||||
xSemaphoreTake(mutex, portMAX_DELAY);
|
||||
|
||||
taskToNotify = nullptr;
|
||||
|
||||
this->pinCsn = pinCsn;
|
||||
DisableWorkaroundForFtpan58(spiBaseAddress, 0, 0);
|
||||
DisableWorkaroundForErratum58();
|
||||
spiBaseAddress->INTENCLR = (1 << 6);
|
||||
spiBaseAddress->INTENCLR = (1 << 1);
|
||||
spiBaseAddress->INTENCLR = (1 << 19);
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <semphr.h>
|
||||
#include <task.h>
|
||||
#include "nrfx_gpiote.h"
|
||||
#include "nrf_ppi.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Drivers {
|
||||
|
@ -31,7 +34,7 @@ namespace Pinetime {
|
|||
SpiMaster& operator=(SpiMaster&&) = delete;
|
||||
|
||||
bool Init();
|
||||
bool Write(uint8_t pinCsn, const uint8_t* data, size_t size);
|
||||
bool Write(uint8_t pinCsn, const uint8_t* data, size_t size, const std::function<void()>& preTransactionHook);
|
||||
bool Read(uint8_t pinCsn, uint8_t* cmd, size_t cmdSize, uint8_t* data, size_t dataSize);
|
||||
|
||||
bool WriteCmdAndBuffer(uint8_t pinCsn, const uint8_t* cmd, size_t cmdSize, const uint8_t* data, size_t dataSize);
|
||||
|
@ -43,8 +46,8 @@ namespace Pinetime {
|
|||
void Wakeup();
|
||||
|
||||
private:
|
||||
void SetupWorkaroundForFtpan58(NRF_SPIM_Type* spim, uint32_t ppi_channel, uint32_t gpiote_channel);
|
||||
void DisableWorkaroundForFtpan58(NRF_SPIM_Type* spim, uint32_t ppi_channel, uint32_t gpiote_channel);
|
||||
void SetupWorkaroundForErratum58();
|
||||
void DisableWorkaroundForErratum58();
|
||||
void PrepareTx(const volatile uint32_t bufferAddress, const volatile size_t size);
|
||||
void PrepareRx(const volatile uint32_t bufferAddress, const volatile size_t size);
|
||||
|
||||
|
@ -56,8 +59,9 @@ namespace Pinetime {
|
|||
|
||||
volatile uint32_t currentBufferAddr = 0;
|
||||
volatile size_t currentBufferSize = 0;
|
||||
volatile TaskHandle_t taskToNotify;
|
||||
SemaphoreHandle_t mutex = nullptr;
|
||||
static constexpr nrf_ppi_channel_t workaroundPpi = NRF_PPI_CHANNEL0;
|
||||
bool workaroundActive = false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ void SpiNorFlash::Uninit() {
|
|||
|
||||
void SpiNorFlash::Sleep() {
|
||||
auto cmd = static_cast<uint8_t>(Commands::DeepPowerDown);
|
||||
spi.Write(&cmd, sizeof(uint8_t));
|
||||
spi.Write(&cmd, sizeof(uint8_t), nullptr);
|
||||
NRF_LOG_INFO("[SpiNorFlash] Sleep")
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "drivers/St7789.h"
|
||||
#include <hal/nrf_gpio.h>
|
||||
#include <libraries/delay/nrf_delay.h>
|
||||
#include <nrfx_log.h>
|
||||
#include "drivers/Spi.h"
|
||||
#include "task.h"
|
||||
|
||||
using namespace Pinetime::Drivers;
|
||||
|
||||
|
@ -29,37 +29,77 @@ void St7789::Init() {
|
|||
DisplayOn();
|
||||
}
|
||||
|
||||
void St7789::WriteCommand(uint8_t cmd) {
|
||||
nrf_gpio_pin_clear(pinDataCommand);
|
||||
WriteSpi(&cmd, 1);
|
||||
}
|
||||
|
||||
void St7789::WriteData(uint8_t data) {
|
||||
nrf_gpio_pin_set(pinDataCommand);
|
||||
WriteSpi(&data, 1);
|
||||
WriteData(&data, 1);
|
||||
}
|
||||
|
||||
void St7789::WriteSpi(const uint8_t* data, size_t size) {
|
||||
spi.Write(data, size);
|
||||
void St7789::WriteData(const uint8_t* data, size_t size) {
|
||||
WriteSpi(data, size, [pinDataCommand = pinDataCommand]() {
|
||||
nrf_gpio_pin_set(pinDataCommand);
|
||||
});
|
||||
}
|
||||
|
||||
void St7789::WriteCommand(uint8_t data) {
|
||||
WriteCommand(&data, 1);
|
||||
}
|
||||
|
||||
void St7789::WriteCommand(const uint8_t* data, size_t size) {
|
||||
WriteSpi(data, size, [pinDataCommand = pinDataCommand]() {
|
||||
nrf_gpio_pin_clear(pinDataCommand);
|
||||
});
|
||||
}
|
||||
|
||||
void St7789::WriteSpi(const uint8_t* data, size_t size, const std::function<void()>& preTransactionHook) {
|
||||
spi.Write(data, size, preTransactionHook);
|
||||
}
|
||||
|
||||
void St7789::SoftwareReset() {
|
||||
EnsureSleepOutPostDelay();
|
||||
WriteCommand(static_cast<uint8_t>(Commands::SoftwareReset));
|
||||
nrf_delay_ms(150);
|
||||
// If sleep in: must wait 120ms before sleep out can sent (see driver datasheet)
|
||||
// Unconditionally wait as software reset doesn't need to be performant
|
||||
sleepIn = true;
|
||||
lastSleepExit = xTaskGetTickCount();
|
||||
vTaskDelay(pdMS_TO_TICKS(125));
|
||||
}
|
||||
|
||||
void St7789::SleepOut() {
|
||||
if (!sleepIn) {
|
||||
return;
|
||||
}
|
||||
WriteCommand(static_cast<uint8_t>(Commands::SleepOut));
|
||||
// Wait 5ms for clocks to stabilise
|
||||
// pdMS rounds down => 6 used here
|
||||
vTaskDelay(pdMS_TO_TICKS(6));
|
||||
// Cannot send sleep in or software reset for 120ms
|
||||
lastSleepExit = xTaskGetTickCount();
|
||||
sleepIn = false;
|
||||
}
|
||||
|
||||
void St7789::EnsureSleepOutPostDelay() {
|
||||
TickType_t delta = xTaskGetTickCount() - lastSleepExit;
|
||||
// Due to timer wraparound, there is a chance of delaying when not necessary
|
||||
// It is very low (pdMS_TO_TICKS(125)/2^32) and waiting an extra 125ms isn't too bad
|
||||
if (delta < pdMS_TO_TICKS(125)) {
|
||||
vTaskDelay(pdMS_TO_TICKS(125) - delta);
|
||||
}
|
||||
}
|
||||
|
||||
void St7789::SleepIn() {
|
||||
if (sleepIn) {
|
||||
return;
|
||||
}
|
||||
EnsureSleepOutPostDelay();
|
||||
WriteCommand(static_cast<uint8_t>(Commands::SleepIn));
|
||||
// Wait 5ms for clocks to stabilise
|
||||
// pdMS rounds down => 6 used here
|
||||
vTaskDelay(pdMS_TO_TICKS(6));
|
||||
sleepIn = true;
|
||||
}
|
||||
|
||||
void St7789::ColMod() {
|
||||
WriteCommand(static_cast<uint8_t>(Commands::ColMod));
|
||||
WriteData(0x55);
|
||||
nrf_delay_ms(10);
|
||||
}
|
||||
|
||||
void St7789::MemoryDataAccessControl() {
|
||||
|
@ -96,12 +136,10 @@ void St7789::RowAddressSet() {
|
|||
|
||||
void St7789::DisplayInversionOn() {
|
||||
WriteCommand(static_cast<uint8_t>(Commands::DisplayInversionOn));
|
||||
nrf_delay_ms(10);
|
||||
}
|
||||
|
||||
void St7789::NormalModeOn() {
|
||||
WriteCommand(static_cast<uint8_t>(Commands::NormalModeOn));
|
||||
nrf_delay_ms(10);
|
||||
}
|
||||
|
||||
void St7789::DisplayOn() {
|
||||
|
@ -120,12 +158,11 @@ void St7789::SetAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
|
|||
WriteData(y0 & 0xff);
|
||||
WriteData(y1 >> 8);
|
||||
WriteData(y1 & 0xff);
|
||||
|
||||
WriteToRam();
|
||||
}
|
||||
|
||||
void St7789::WriteToRam() {
|
||||
void St7789::WriteToRam(const uint8_t* data, size_t size) {
|
||||
WriteCommand(static_cast<uint8_t>(Commands::WriteToRam));
|
||||
WriteData(data, size);
|
||||
}
|
||||
|
||||
void St7789::SetVdv() {
|
||||
|
@ -137,7 +174,6 @@ void St7789::SetVdv() {
|
|||
|
||||
void St7789::DisplayOff() {
|
||||
WriteCommand(static_cast<uint8_t>(Commands::DisplayOff));
|
||||
nrf_delay_ms(500);
|
||||
}
|
||||
|
||||
void St7789::VerticalScrollStartAddress(uint16_t line) {
|
||||
|
@ -152,14 +188,18 @@ void St7789::Uninit() {
|
|||
|
||||
void St7789::DrawBuffer(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t* data, size_t size) {
|
||||
SetAddrWindow(x, y, x + width - 1, y + height - 1);
|
||||
nrf_gpio_pin_set(pinDataCommand);
|
||||
WriteSpi(data, size);
|
||||
WriteToRam(data, size);
|
||||
}
|
||||
|
||||
void St7789::HardwareReset() {
|
||||
nrf_gpio_pin_clear(pinReset);
|
||||
nrf_delay_ms(10);
|
||||
vTaskDelay(pdMS_TO_TICKS(1));
|
||||
nrf_gpio_pin_set(pinReset);
|
||||
// If hardware reset started while sleep out, reset time may be up to 120ms
|
||||
// Unconditionally wait as hardware reset doesn't need to be performant
|
||||
sleepIn = true;
|
||||
lastSleepExit = xTaskGetTickCount();
|
||||
vTaskDelay(pdMS_TO_TICKS(125));
|
||||
}
|
||||
|
||||
void St7789::Sleep() {
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Drivers {
|
||||
|
@ -29,23 +32,27 @@ namespace Pinetime {
|
|||
uint8_t pinDataCommand;
|
||||
uint8_t pinReset;
|
||||
uint8_t verticalScrollingStartAddress = 0;
|
||||
bool sleepIn;
|
||||
TickType_t lastSleepExit;
|
||||
|
||||
void HardwareReset();
|
||||
void SoftwareReset();
|
||||
void SleepOut();
|
||||
void EnsureSleepOutPostDelay();
|
||||
void SleepIn();
|
||||
void ColMod();
|
||||
void MemoryDataAccessControl();
|
||||
void DisplayInversionOn();
|
||||
void NormalModeOn();
|
||||
void WriteToRam();
|
||||
void WriteToRam(const uint8_t* data, size_t size);
|
||||
void DisplayOn();
|
||||
void DisplayOff();
|
||||
|
||||
void SetAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
|
||||
void SetVdv();
|
||||
void WriteCommand(uint8_t cmd);
|
||||
void WriteSpi(const uint8_t* data, size_t size);
|
||||
void WriteCommand(const uint8_t* data, size_t size);
|
||||
void WriteSpi(const uint8_t* data, size_t size, const std::function<void()>& preTransactionHook);
|
||||
|
||||
enum class Commands : uint8_t {
|
||||
SoftwareReset = 0x01,
|
||||
|
@ -65,6 +72,7 @@ namespace Pinetime {
|
|||
VdvSet = 0xc4,
|
||||
};
|
||||
void WriteData(uint8_t data);
|
||||
void WriteData(const uint8_t* data, size_t size);
|
||||
void ColumnAddressSet();
|
||||
|
||||
static constexpr uint16_t Width = 240;
|
||||
|
|
|
@ -121,7 +121,6 @@ void DisplayLogo() {
|
|||
Pinetime::Tools::RleDecoder rleDecoder(infinitime_nb, sizeof(infinitime_nb));
|
||||
for (int i = 0; i < displayWidth; i++) {
|
||||
rleDecoder.DecodeNext(displayBuffer, displayWidth * bytesPerPixel);
|
||||
ulTaskNotifyTake(pdTRUE, 500);
|
||||
lcd.DrawBuffer(0, i, displayWidth, 1, reinterpret_cast<const uint8_t*>(displayBuffer), displayWidth * bytesPerPixel);
|
||||
}
|
||||
}
|
||||
|
@ -130,7 +129,6 @@ void DisplayProgressBar(uint8_t percent, uint16_t color) {
|
|||
static constexpr uint8_t barHeight = 20;
|
||||
std::fill(displayBuffer, displayBuffer + (displayWidth * bytesPerPixel), color);
|
||||
for (int i = 0; i < barHeight; i++) {
|
||||
ulTaskNotifyTake(pdTRUE, 500);
|
||||
uint16_t barWidth = std::min(static_cast<float>(percent) * 2.4f, static_cast<float>(displayWidth));
|
||||
lcd.DrawBuffer(0, displayWidth - barHeight + i, barWidth, 1, reinterpret_cast<const uint8_t*>(displayBuffer), barWidth * bytesPerPixel);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue