mirror of https://github.com/sqfmi/Watchy.git
parent
12c282e7c8
commit
179f7657e5
|
@ -3,24 +3,23 @@
|
|||
* Sets the RTC time if not set, goes to sleep and wakes up every minute to update the time on the display
|
||||
*/
|
||||
|
||||
#include <WiFi.h>
|
||||
#ifndef ESP32
|
||||
#error Please select ESP32 Wrover Module under Tools > Board
|
||||
#endif
|
||||
|
||||
#include <DS3232RTC.h>
|
||||
#include <GxEPD.h>
|
||||
#include <GxIO/GxIO_SPI/GxIO_SPI.h>
|
||||
#include <GxIO/GxIO.h>
|
||||
#include "GxGDEH0154D67.h"
|
||||
#include <GxEPD2_BW.h>
|
||||
|
||||
#define RTC_PIN GPIO_NUM_33
|
||||
#define ORIGIN_X GxGDEH0154D67_WIDTH/2
|
||||
#define ORIGIN_Y GxGDEH0154D67_HEIGHT/2
|
||||
#define ORIGIN_X 200/2
|
||||
#define ORIGIN_Y 200/2
|
||||
#define HOUR_HAND_LENGTH 50
|
||||
#define HOUR_HAND_WIDTH 11
|
||||
#define MINUTE_HAND_LENGTH 90
|
||||
#define MINUTE_HAND_WIDTH 7
|
||||
|
||||
DS3232RTC RTC(false);
|
||||
GxIO_Class io(SPI, /*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16); // arbitrary selection of 17, 16
|
||||
GxEPD_Class display(io, /*RST=*/ 16, /*BUSY=*/ 4); // arbitrary selection of (16), 4
|
||||
GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH0154D67
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
@ -50,13 +49,13 @@ void updateTime(bool reset)
|
|||
tmElements_t currentTime;
|
||||
RTC.read(currentTime);
|
||||
|
||||
display.init();
|
||||
display.init(0, reset); //_initial_refresh to false to prevent full update on init
|
||||
display.fillScreen(GxEPD_WHITE);
|
||||
display.setTextColor(GxEPD_BLACK);
|
||||
setHands(currentTime);
|
||||
|
||||
display.update();
|
||||
display.deepSleep();
|
||||
display.display(true);
|
||||
display.hibernate();
|
||||
}
|
||||
|
||||
void setHands(tmElements_t time){
|
||||
|
|
|
@ -3,19 +3,18 @@
|
|||
* Sets the RTC time if not set, goes to sleep and wakes up every minute to update the time on the display
|
||||
*/
|
||||
|
||||
#include <WiFi.h>
|
||||
#ifndef ESP32
|
||||
#error Please select ESP32 Wrover Module under Tools > Board
|
||||
#endif
|
||||
|
||||
#include <DS3232RTC.h>
|
||||
#include <GxEPD.h>
|
||||
#include <GxIO/GxIO_SPI/GxIO_SPI.h>
|
||||
#include <GxIO/GxIO.h>
|
||||
#include "GxGDEH0154D67.h"
|
||||
#include <GxEPD2_BW.h>
|
||||
#include "DSEG7_Classic_Bold_48.h"
|
||||
|
||||
#define RTC_PIN GPIO_NUM_33
|
||||
|
||||
DS3232RTC RTC(false);
|
||||
GxIO_Class io(SPI, /*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16); // arbitrary selection of 17, 16
|
||||
GxEPD_Class display(io, /*RST=*/ 16, /*BUSY=*/ 4); // arbitrary selection of (16), 4
|
||||
GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH0154D67
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
@ -45,7 +44,8 @@ void updateTime(bool reset)
|
|||
tmElements_t currentTime;
|
||||
RTC.read(currentTime);
|
||||
|
||||
display.init();
|
||||
display.init(0, reset); //_initial_refresh to false to prevent full update on init
|
||||
display.setFullWindow();
|
||||
display.fillScreen(GxEPD_BLACK);
|
||||
display.setTextColor(GxEPD_WHITE);
|
||||
display.setFont(&DSEG7_Classic_Bold_48);
|
||||
|
@ -60,14 +60,8 @@ void updateTime(bool reset)
|
|||
display.print('0');
|
||||
}
|
||||
display.print(currentTime.Minute);
|
||||
|
||||
if(reset){
|
||||
display.update();
|
||||
}else{
|
||||
display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true);
|
||||
}
|
||||
|
||||
display.deepSleep();
|
||||
display.display(true); //partial refresh
|
||||
display.hibernate();
|
||||
}
|
||||
|
||||
time_t compileTime()
|
||||
|
|
|
@ -12,12 +12,13 @@
|
|||
* |--------------|
|
||||
* ==============
|
||||
*/
|
||||
|
||||
#ifndef ESP32
|
||||
#error Please select ESP32 Wrover Module under Tools > Board
|
||||
#endif
|
||||
|
||||
#include <DS3232RTC.h>
|
||||
#include <GxEPD.h>
|
||||
#include <GxIO/GxIO_SPI/GxIO_SPI.h>
|
||||
#include <GxIO/GxIO.h>
|
||||
#include "GxGDEH0154D67.h"
|
||||
#include <GxEPD2_BW.h>
|
||||
#include "DSEG7_Classic_Bold_48.h"
|
||||
#include "DSEG14_Classic_Bold_18.h"
|
||||
|
||||
|
@ -30,17 +31,24 @@
|
|||
#define BTN_PIN_MASK BTN_1|BTN_2|BTN_3|BTN_4
|
||||
|
||||
DS3232RTC RTC(false);
|
||||
GxIO_Class io(SPI, /*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16); // arbitrary selection of 17, 16
|
||||
GxEPD_Class display(io, /*RST=*/ 16, /*BUSY=*/ 4); // arbitrary selection of (16), 4
|
||||
GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH0154D67
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
detect_wakeup_reason();
|
||||
delay(100);
|
||||
esp_sleep_enable_ext0_wakeup(RTC_PIN, 0); //enable deep sleep wake on RTC interrupt
|
||||
esp_sleep_enable_ext1_wakeup(BTN_PIN_MASK, ESP_EXT1_WAKEUP_ANY_HIGH); //enable deep sleep wake on button press
|
||||
esp_deep_sleep_start();
|
||||
esp_sleep_wakeup_cause_t wakeup_reason;
|
||||
wakeup_reason = esp_sleep_get_wakeup_cause();
|
||||
|
||||
switch(wakeup_reason)
|
||||
{
|
||||
case ESP_SLEEP_WAKEUP_EXT0: updateTime(false); break; //RTC Alarm Interrupt
|
||||
case ESP_SLEEP_WAKEUP_EXT1: handleButton(); break; //Button Press
|
||||
default: updateTime(true); //Hard Reset
|
||||
}
|
||||
|
||||
esp_sleep_enable_ext0_wakeup(RTC_PIN, 0); //enable deep sleep wake on RTC interrupt
|
||||
esp_sleep_enable_ext1_wakeup(BTN_PIN_MASK, ESP_EXT1_WAKEUP_ANY_HIGH); //enable deep sleep wake on button press
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
void loop(){}
|
||||
|
@ -74,40 +82,41 @@ void handleButton()
|
|||
else if (wakeupBit & BTN_1) {
|
||||
display.println("BTN 1");
|
||||
}
|
||||
display.update();
|
||||
display.deepSleep();
|
||||
display.display(false);
|
||||
display.hibernate();
|
||||
}
|
||||
|
||||
void updateTime()
|
||||
void updateTime(bool reset)
|
||||
{
|
||||
RTC.begin();
|
||||
if(RTC.oscStopped(false)){ //check if RTC has been stopped
|
||||
RTC.squareWave(SQWAVE_NONE); //disable square wave output
|
||||
RTC.set(compileTime()); //set RTC time to compile time
|
||||
RTC.setAlarm(ALM2_EVERY_MINUTE, 0, 0, 0, 1); //set alarm to every minute
|
||||
RTC.alarmInterrupt(ALARM_2, true); //enable alarm interrupt
|
||||
}
|
||||
RTC.alarm(ALARM_2); //resets the alarm flag in the RTC
|
||||
tmElements_t currentTime;
|
||||
RTC.read(currentTime);
|
||||
RTC.begin();
|
||||
if(reset){
|
||||
RTC.squareWave(SQWAVE_NONE); //disable square wave output
|
||||
RTC.set(compileTime()); //set RTC time to compile time
|
||||
RTC.setAlarm(ALM2_EVERY_MINUTE, 0, 0, 0, 0);
|
||||
RTC.alarmInterrupt(ALARM_2, true); //enable alarm interrupt
|
||||
}
|
||||
RTC.alarm(ALARM_2); //resets the alarm flag in the RTC
|
||||
tmElements_t currentTime;
|
||||
RTC.read(currentTime);
|
||||
|
||||
display.init();
|
||||
display.fillScreen(GxEPD_BLACK);
|
||||
display.setTextColor(GxEPD_WHITE);
|
||||
display.setFont(&DSEG7_Classic_Bold_48);
|
||||
display.setCursor(15, 120);
|
||||
display.init(0, reset); //_initial_refresh to false to prevent full update on init
|
||||
display.setFullWindow();
|
||||
display.fillScreen(GxEPD_BLACK);
|
||||
display.setTextColor(GxEPD_WHITE);
|
||||
display.setFont(&DSEG7_Classic_Bold_48);
|
||||
display.setCursor(15, 120);
|
||||
|
||||
if(currentTime.Hour < 10){
|
||||
display.print('0');
|
||||
}
|
||||
display.print(currentTime.Hour);
|
||||
display.print(':');
|
||||
if(currentTime.Minute < 10){
|
||||
display.print('0');
|
||||
}
|
||||
display.print(currentTime.Minute);
|
||||
display.update();
|
||||
display.deepSleep();
|
||||
if(currentTime.Hour < 10){
|
||||
display.print('0');
|
||||
}
|
||||
display.print(currentTime.Hour);
|
||||
display.print(':');
|
||||
if(currentTime.Minute < 10){
|
||||
display.print('0');
|
||||
}
|
||||
display.print(currentTime.Minute);
|
||||
display.display(true); //partial refresh
|
||||
display.hibernate();
|
||||
}
|
||||
|
||||
time_t compileTime()
|
||||
|
@ -130,17 +139,4 @@ time_t compileTime()
|
|||
|
||||
time_t t = makeTime(tm);
|
||||
return t + FUDGE; //add fudge factor to allow for compile time
|
||||
}
|
||||
|
||||
void detect_wakeup_reason(){
|
||||
esp_sleep_wakeup_cause_t wakeup_reason;
|
||||
|
||||
wakeup_reason = esp_sleep_get_wakeup_cause();
|
||||
|
||||
switch(wakeup_reason)
|
||||
{
|
||||
case ESP_SLEEP_WAKEUP_EXT0: updateTime(); break; //RTC Alarm
|
||||
case ESP_SLEEP_WAKEUP_EXT1: handleButton(); break; //Button Press
|
||||
default: updateTime(); //Reset
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
name=Watchy
|
||||
version=1.1.3
|
||||
version=1.1.4
|
||||
author=SQFMI
|
||||
maintainer=SQFMI
|
||||
sentence=Watchy - An Open Source E-Ink SmartWatch by SQFMI
|
||||
paragraph=This library contains drivers and code samples for Watchy
|
||||
category=Other
|
||||
url=https://github.com/sqfmi/Watchy
|
||||
depends=GxEPD
|
||||
depends=GxEPD2,DS3232RTC
|
||||
|
|
|
@ -1,873 +0,0 @@
|
|||
// class GxGDEH0154D67 : Display class for GDEH0154D67 e-Paper from Dalian Good Display Co., Ltd.: www.good-display.com
|
||||
//
|
||||
// Author : SQFMI
|
||||
//
|
||||
// Version : see library.properties
|
||||
//
|
||||
// Library: https://github.com/sqfmi/GxEPD
|
||||
|
||||
#include "GxGDEH0154D67.h"
|
||||
|
||||
//#define DISABLE_DIAGNOSTIC_OUTPUT
|
||||
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
#include <pgmspace.h>
|
||||
#else
|
||||
#include <avr/pgmspace.h>
|
||||
#endif
|
||||
|
||||
// Partial Update Delay, may have an influence on degradation. Changed to 0 to not wait after partial refresh
|
||||
#define GxGDEH0154D67_PU_DELAY 0
|
||||
|
||||
/*const uint8_t GxGDEH0154D67::LUTDefault_full[] =
|
||||
{
|
||||
0x32, // command
|
||||
0x50, 0xAA, 0x55, 0xAA, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
const uint8_t GxGDEH0154D67::LUTDefault_part[] =
|
||||
{
|
||||
0x32, // command
|
||||
0x10, 0x18, 0x18, 0x08, 0x18, 0x18, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x14, 0x44, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
const uint8_t GxGDEH0154D67::GDOControl[] = {0x01, (GxGDEH0154D67_Y_PIXELS - 1) % 256, (GxGDEH0154D67_Y_PIXELS - 1) / 256, 0x00}; //for 1.54inch
|
||||
const uint8_t GxGDEH0154D67::softstart[] = {0x0c, 0xd7, 0xd6, 0x9d};
|
||||
const uint8_t GxGDEH0154D67::VCOMVol[] = {0x2c, 0x9b}; // VCOM 7c
|
||||
const uint8_t GxGDEH0154D67::DummyLine[] = {0x3a, 0x1a}; // 4 dummy line per gate
|
||||
const uint8_t GxGDEH0154D67::Gatetime[] = {0x3b, 0x08}; // 2us per line*/
|
||||
|
||||
GxGDEH0154D67::GxGDEH0154D67(GxIO& io, int8_t rst, int8_t busy) :
|
||||
GxEPD(GxGDEH0154D67_WIDTH, GxGDEH0154D67_HEIGHT), IO(io),
|
||||
_current_page(-1), _using_partial_mode(false), _diag_enabled(false),
|
||||
_rst(rst), _busy(busy)
|
||||
{
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::drawPixel(int16_t x, int16_t y, uint16_t color)
|
||||
{
|
||||
if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) return;
|
||||
|
||||
// check rotation, move pixel around if necessary
|
||||
switch (getRotation())
|
||||
{
|
||||
case 1:
|
||||
swap(x, y);
|
||||
x = GxGDEH0154D67_WIDTH - x - 1;
|
||||
break;
|
||||
case 2:
|
||||
x = GxGDEH0154D67_WIDTH - x - 1;
|
||||
y = GxGDEH0154D67_HEIGHT - y - 1;
|
||||
break;
|
||||
case 3:
|
||||
swap(x, y);
|
||||
y = GxGDEH0154D67_HEIGHT - y - 1;
|
||||
break;
|
||||
}
|
||||
uint16_t i = x / 8 + y * GxGDEH0154D67_WIDTH / 8;
|
||||
if (_current_page < 1)
|
||||
{
|
||||
if (i >= sizeof(_buffer)) return;
|
||||
}
|
||||
else
|
||||
{
|
||||
y -= _current_page * GxGDEH0154D67_PAGE_HEIGHT;
|
||||
if ((y < 0) || (y >= GxGDEH0154D67_PAGE_HEIGHT)) return;
|
||||
i = x / 8 + y * GxGDEH0154D67_WIDTH / 8;
|
||||
}
|
||||
|
||||
if (!color)
|
||||
_buffer[i] = (_buffer[i] | (1 << (7 - x % 8)));
|
||||
else
|
||||
_buffer[i] = (_buffer[i] & (0xFF ^ (1 << (7 - x % 8))));
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::init(uint32_t serial_diag_bitrate)
|
||||
{
|
||||
if (serial_diag_bitrate > 0)
|
||||
{
|
||||
Serial.begin(serial_diag_bitrate);
|
||||
_diag_enabled = true;
|
||||
}
|
||||
IO.init();
|
||||
IO.setFrequency(4000000); // 4MHz
|
||||
if (_rst >= 0)
|
||||
{
|
||||
digitalWrite(_rst, HIGH);
|
||||
pinMode(_rst, OUTPUT);
|
||||
}
|
||||
if (_busy >= 0) pinMode(_busy, INPUT);
|
||||
fillScreen(GxEPD_WHITE);
|
||||
_current_page = -1;
|
||||
_using_partial_mode = false;
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::fillScreen(uint16_t color)
|
||||
{
|
||||
uint8_t data = (color == GxEPD_BLACK) ? 0xFF : 0x00;
|
||||
for (uint16_t x = 0; x < sizeof(_buffer); x++)
|
||||
{
|
||||
_buffer[x] = data;
|
||||
}
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::update(void)
|
||||
{
|
||||
if (_current_page != -1) return;
|
||||
_using_partial_mode = false;
|
||||
_Init_Full(0x03);
|
||||
_writeCommand(0x24);
|
||||
for (uint16_t y = 0; y < GxGDEH0154D67_HEIGHT; y++)
|
||||
{
|
||||
for (uint16_t x = 0; x < GxGDEH0154D67_WIDTH / 8; x++)
|
||||
{
|
||||
uint16_t idx = y * (GxGDEH0154D67_WIDTH / 8) + x;
|
||||
uint8_t data = (idx < sizeof(_buffer)) ? _buffer[idx] : 0x00;
|
||||
_writeData(~data);
|
||||
}
|
||||
}
|
||||
_Update_Full();
|
||||
_PowerOff();
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::drawBitmap(const uint8_t *bitmap, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color, int16_t mode)
|
||||
{
|
||||
if (mode & bm_default) mode |= bm_flip_x | bm_invert;
|
||||
drawBitmapBM(bitmap, x, y, w, h, color, mode);
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::drawBitmap(const uint8_t *bitmap, uint32_t size, int16_t mode)
|
||||
{
|
||||
if (_current_page != -1) return;
|
||||
// example bitmaps are made for y-decrement, x-increment, for origin on opposite corner
|
||||
// bm_flip_x for normal display (bm_flip_y would be rotated)
|
||||
if (mode & bm_default) mode |= bm_flip_x;
|
||||
uint8_t ram_entry_mode = 0x03; // y-increment, x-increment for normal mode
|
||||
if ((mode & bm_flip_y) && (mode & bm_flip_x)) ram_entry_mode = 0x00; // y-decrement, x-decrement
|
||||
else if (mode & bm_flip_y) ram_entry_mode = 0x01; // y-decrement, x-increment
|
||||
else if (mode & bm_flip_x) ram_entry_mode = 0x02; // y-increment, x-decrement
|
||||
if (mode & bm_partial_update)
|
||||
{
|
||||
_using_partial_mode = true; // remember
|
||||
_Init_Part(ram_entry_mode);
|
||||
_writeCommand(0x24);
|
||||
for (uint32_t i = 0; i < GxGDEH0154D67_BUFFER_SIZE; i++)
|
||||
{
|
||||
uint8_t data = 0xFF; // white is 0xFF on device
|
||||
if (i < size)
|
||||
{
|
||||
#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
|
||||
data = pgm_read_byte(&bitmap[i]);
|
||||
#else
|
||||
data = bitmap[i];
|
||||
#endif
|
||||
if (mode & bm_invert) data = ~data;
|
||||
}
|
||||
_writeData(data);
|
||||
}
|
||||
_Update_Part();
|
||||
delay(GxGDEH0154D67_PU_DELAY);
|
||||
// update erase buffer
|
||||
_writeCommand(0x24);
|
||||
for (uint32_t i = 0; i < GxGDEH0154D67_BUFFER_SIZE; i++)
|
||||
{
|
||||
uint8_t data = 0xFF; // white is 0xFF on device
|
||||
if (i < size)
|
||||
{
|
||||
#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
|
||||
data = pgm_read_byte(&bitmap[i]);
|
||||
#else
|
||||
data = bitmap[i];
|
||||
#endif
|
||||
if (mode & bm_invert) data = ~data;
|
||||
}
|
||||
_writeData(data);
|
||||
}
|
||||
delay(GxGDEH0154D67_PU_DELAY);
|
||||
_PowerOff();
|
||||
}
|
||||
else
|
||||
{
|
||||
_using_partial_mode = false; // remember
|
||||
_Init_Full(ram_entry_mode);
|
||||
_writeCommand(0x24);
|
||||
for (uint32_t i = 0; i < GxGDEH0154D67_BUFFER_SIZE; i++)
|
||||
{
|
||||
uint8_t data = 0xFF; // white is 0xFF on device
|
||||
if (i < size)
|
||||
{
|
||||
#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
|
||||
data = pgm_read_byte(&bitmap[i]);
|
||||
#else
|
||||
data = bitmap[i];
|
||||
#endif
|
||||
if (mode & bm_invert) data = ~data;
|
||||
}
|
||||
_writeData(data);
|
||||
}
|
||||
_Update_Full();
|
||||
_PowerOff();
|
||||
}
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::eraseDisplay(bool using_partial_update)
|
||||
{
|
||||
if (_current_page != -1) return;
|
||||
if (using_partial_update)
|
||||
{
|
||||
_using_partial_mode = true; // remember
|
||||
_Init_Part(0x01);
|
||||
_writeCommand(0x24);
|
||||
for (uint32_t i = 0; i < GxGDEH0154D67_BUFFER_SIZE; i++)
|
||||
{
|
||||
_writeData(0xFF);
|
||||
}
|
||||
_Update_Part();
|
||||
delay(GxGDEH0154D67_PU_DELAY);
|
||||
// update erase buffer
|
||||
_writeCommand(0x24);
|
||||
for (uint32_t i = 0; i < GxGDEH0154D67_BUFFER_SIZE; i++)
|
||||
{
|
||||
_writeData(0xFF);
|
||||
}
|
||||
delay(GxGDEH0154D67_PU_DELAY);
|
||||
}
|
||||
else
|
||||
{
|
||||
_using_partial_mode = false; // remember
|
||||
_Init_Full(0x01);
|
||||
_writeCommand(0x24);
|
||||
for (uint32_t i = 0; i < GxGDEH0154D67_BUFFER_SIZE; i++)
|
||||
{
|
||||
_writeData(0xFF);
|
||||
}
|
||||
_Update_Full();
|
||||
_PowerOff();
|
||||
}
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::updateWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h, bool using_rotation)
|
||||
{
|
||||
if (_current_page != -1) return;
|
||||
if (using_rotation) _rotate(x, y, w, h);
|
||||
if (x >= GxGDEH0154D67_WIDTH) return;
|
||||
if (y >= GxGDEH0154D67_HEIGHT) return;
|
||||
uint16_t xe = gx_uint16_min(GxGDEH0154D67_WIDTH, x + w) - 1;
|
||||
uint16_t ye = gx_uint16_min(GxGDEH0154D67_HEIGHT, y + h) - 1;
|
||||
uint16_t xs_d8 = x / 8;
|
||||
uint16_t xe_d8 = xe / 8;
|
||||
_Init_Part(0x03);
|
||||
_SetRamArea(xs_d8, xe_d8, y % 256, y / 256, ye % 256, ye / 256); // X-source area,Y-gate area
|
||||
_SetRamPointer(xs_d8, y % 256, y / 256); // set ram
|
||||
_waitWhileBusy(0, 100); // needed ?
|
||||
_writeCommand(0x24);
|
||||
for (int16_t y1 = y; y1 <= ye; y1++)
|
||||
{
|
||||
for (int16_t x1 = xs_d8; x1 <= xe_d8; x1++)
|
||||
{
|
||||
uint16_t idx = y1 * (GxGDEH0154D67_WIDTH / 8) + x1;
|
||||
uint8_t data = (idx < sizeof(_buffer)) ? _buffer[idx] : 0x00;
|
||||
_writeData(~data);
|
||||
}
|
||||
}
|
||||
_Update_Part();
|
||||
delay(GxGDEH0154D67_PU_DELAY);
|
||||
// update erase buffer
|
||||
_SetRamArea(xs_d8, xe_d8, y % 256, y / 256, ye % 256, ye / 256); // X-source area,Y-gate area
|
||||
_SetRamPointer(xs_d8, y % 256, y / 256); // set ram
|
||||
_waitWhileBusy(0, 100); // needed ?
|
||||
_writeCommand(0x24);
|
||||
for (int16_t y1 = y; y1 <= ye; y1++)
|
||||
{
|
||||
for (int16_t x1 = xs_d8; x1 <= xe_d8; x1++)
|
||||
{
|
||||
uint16_t idx = y1 * (GxGDEH0154D67_WIDTH / 8) + x1;
|
||||
uint8_t data = (idx < sizeof(_buffer)) ? _buffer[idx] : 0x00;
|
||||
_writeData(~data);
|
||||
}
|
||||
}
|
||||
delay(GxGDEH0154D67_PU_DELAY);
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::_writeToWindow(uint16_t xs, uint16_t ys, uint16_t xd, uint16_t yd, uint16_t w, uint16_t h)
|
||||
{
|
||||
//Serial.printf("_writeToWindow(%d, %d, %d, %d, %d, %d)\n", xs, ys, xd, yd, w, h);
|
||||
// the screen limits are the hard limits
|
||||
if (xs >= GxGDEH0154D67_WIDTH) return;
|
||||
if (ys >= GxGDEH0154D67_HEIGHT) return;
|
||||
if (xd >= GxGDEH0154D67_WIDTH) return;
|
||||
if (yd >= GxGDEH0154D67_HEIGHT) return;
|
||||
w = gx_uint16_min(w, GxGDEH0154D67_WIDTH - xs);
|
||||
w = gx_uint16_min(w, GxGDEH0154D67_WIDTH - xd);
|
||||
h = gx_uint16_min(h, GxGDEH0154D67_HEIGHT - ys);
|
||||
h = gx_uint16_min(h, GxGDEH0154D67_HEIGHT - yd);
|
||||
uint16_t xds_d8 = xd / 8;
|
||||
uint16_t xde_d8 = (xd + w - 1) / 8;
|
||||
uint16_t yde = yd + h - 1;
|
||||
// soft limits, must send as many bytes as set by _SetRamArea
|
||||
uint16_t xse_d8 = xs / 8 + xde_d8 - xds_d8;
|
||||
uint16_t yse = ys + h - 1;
|
||||
_SetRamArea(xds_d8, xde_d8, yd % 256, yd / 256, yde % 256, yde / 256); // X-source area,Y-gate area
|
||||
_SetRamPointer(xds_d8, yd % 256, yd / 256); // set ram
|
||||
_waitWhileBusy(0, 100); // needed ?
|
||||
_writeCommand(0x24);
|
||||
for (int16_t y1 = ys; y1 <= yse; y1++)
|
||||
{
|
||||
for (int16_t x1 = xs / 8; x1 <= xse_d8; x1++)
|
||||
{
|
||||
uint16_t idx = y1 * (GxGDEH0154D67_WIDTH / 8) + x1;
|
||||
uint8_t data = (idx < sizeof(_buffer)) ? _buffer[idx] : 0x00;
|
||||
_writeData(~data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::updateToWindow(uint16_t xs, uint16_t ys, uint16_t xd, uint16_t yd, uint16_t w, uint16_t h, bool using_rotation)
|
||||
{
|
||||
if (using_rotation)
|
||||
{
|
||||
switch (getRotation())
|
||||
{
|
||||
case 1:
|
||||
swap(xs, ys);
|
||||
swap(xd, yd);
|
||||
swap(w, h);
|
||||
xs = GxGDEH0154D67_WIDTH - xs - w - 1;
|
||||
xd = GxGDEH0154D67_WIDTH - xd - w - 1;
|
||||
break;
|
||||
case 2:
|
||||
xs = GxGDEH0154D67_WIDTH - xs - w - 1;
|
||||
ys = GxGDEH0154D67_HEIGHT - ys - h - 1;
|
||||
xd = GxGDEH0154D67_WIDTH - xd - w - 1;
|
||||
yd = GxGDEH0154D67_HEIGHT - yd - h - 1;
|
||||
break;
|
||||
case 3:
|
||||
swap(xs, ys);
|
||||
swap(xd, yd);
|
||||
swap(w, h);
|
||||
ys = GxGDEH0154D67_HEIGHT - ys - h - 1;
|
||||
yd = GxGDEH0154D67_HEIGHT - yd - h - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_Init_Part(0x03);
|
||||
_writeToWindow(xs, ys, xd, yd, w, h);
|
||||
_Update_Part();
|
||||
delay(GxGDEH0154D67_PU_DELAY);
|
||||
// update erase buffer
|
||||
_writeToWindow(xs, ys, xd, yd, w, h);
|
||||
delay(GxGDEH0154D67_PU_DELAY);
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::powerDown()
|
||||
{
|
||||
_using_partial_mode = false;
|
||||
_PowerOff();
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::deepSleep()
|
||||
{
|
||||
_writeCommand(0x10); //enter deep sleep
|
||||
_writeData(0x01);
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::_writeCommand(uint8_t command)
|
||||
{
|
||||
if ((_busy >= 0) && digitalRead(_busy))
|
||||
{
|
||||
String str = String("command 0x") + String(command, HEX);
|
||||
_waitWhileBusy(str.c_str(), 100); // needed?
|
||||
}
|
||||
IO.writeCommandTransaction(command);
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::_writeData(uint8_t data)
|
||||
{
|
||||
IO.writeDataTransaction(data);
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::_writeCommandData(const uint8_t* pCommandData, uint8_t datalen)
|
||||
{
|
||||
if ((_busy >= 0) && digitalRead(_busy))
|
||||
{
|
||||
String str = String("command 0x") + String(pCommandData[0], HEX);
|
||||
_waitWhileBusy(str.c_str(), 100); // needed?
|
||||
}
|
||||
IO.startTransaction();
|
||||
IO.writeCommand(*pCommandData++);
|
||||
for (uint8_t i = 0; i < datalen - 1; i++) // sub the command
|
||||
{
|
||||
IO.writeData(*pCommandData++);
|
||||
}
|
||||
IO.endTransaction();
|
||||
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::_waitWhileBusy(const char* comment, uint16_t busy_time)
|
||||
{
|
||||
if (_busy >= 0)
|
||||
{
|
||||
unsigned long start = micros();
|
||||
while (1)
|
||||
{
|
||||
if (!digitalRead(_busy)) break;
|
||||
delay(1);
|
||||
if (micros() - start > 10000000)
|
||||
{
|
||||
if (_diag_enabled) Serial.println("Busy Timeout!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (comment)
|
||||
{
|
||||
#if !defined(DISABLE_DIAGNOSTIC_OUTPUT)
|
||||
if (_diag_enabled)
|
||||
{
|
||||
unsigned long elapsed = micros() - start;
|
||||
Serial.print(comment);
|
||||
Serial.print(" : ");
|
||||
Serial.println(elapsed);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
(void) start;
|
||||
}
|
||||
else delay(busy_time);
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::_setRamDataEntryMode(uint8_t em)
|
||||
{
|
||||
const uint16_t xPixelsPar = GxGDEH0154D67_X_PIXELS - 1;
|
||||
const uint16_t yPixelsPar = GxGDEH0154D67_Y_PIXELS - 1;
|
||||
em = gx_uint16_min(em, 0x03);
|
||||
_writeCommand(0x11);
|
||||
_writeData(em);
|
||||
switch (em)
|
||||
{
|
||||
case 0x00: // x decrease, y decrease
|
||||
_SetRamArea(xPixelsPar / 8, 0x00, yPixelsPar % 256, yPixelsPar / 256, 0x00, 0x00); // X-source area,Y-gate area
|
||||
_SetRamPointer(xPixelsPar / 8, yPixelsPar % 256, yPixelsPar / 256); // set ram
|
||||
break;
|
||||
case 0x01: // x increase, y decrease : as in demo code
|
||||
_SetRamArea(0x00, xPixelsPar / 8, yPixelsPar % 256, yPixelsPar / 256, 0x00, 0x00); // X-source area,Y-gate area
|
||||
_SetRamPointer(0x00, yPixelsPar % 256, yPixelsPar / 256); // set ram
|
||||
break;
|
||||
case 0x02: // x decrease, y increase
|
||||
_SetRamArea(xPixelsPar / 8, 0x00, 0x00, 0x00, yPixelsPar % 256, yPixelsPar / 256); // X-source area,Y-gate area
|
||||
_SetRamPointer(xPixelsPar / 8, 0x00, 0x00); // set ram
|
||||
break;
|
||||
case 0x03: // x increase, y increase : normal mode
|
||||
_SetRamArea(0x00, xPixelsPar / 8, 0x00, 0x00, yPixelsPar % 256, yPixelsPar / 256); // X-source area,Y-gate area
|
||||
_SetRamPointer(0x00, 0x00, 0x00); // set ram
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::_SetRamArea(uint8_t Xstart, uint8_t Xend, uint8_t Ystart, uint8_t Ystart1, uint8_t Yend, uint8_t Yend1)
|
||||
{
|
||||
_writeCommand(0x44);
|
||||
_writeData(Xstart);
|
||||
_writeData(Xend);
|
||||
_writeCommand(0x45);
|
||||
_writeData(Ystart);
|
||||
_writeData(Ystart1);
|
||||
_writeData(Yend);
|
||||
_writeData(Yend1);
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::_SetRamPointer(uint8_t addrX, uint8_t addrY, uint8_t addrY1)
|
||||
{
|
||||
_writeCommand(0x4e);
|
||||
_writeData(addrX);
|
||||
_writeCommand(0x4f);
|
||||
_writeData(addrY);
|
||||
_writeData(addrY1);
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::_PowerOn(void)
|
||||
{
|
||||
_writeCommand(0x22);
|
||||
_writeData(0xc0);
|
||||
_writeCommand(0x20);
|
||||
_waitWhileBusy("_PowerOn", power_on_time);
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::_PowerOff(void)
|
||||
{
|
||||
_writeCommand(0x22);
|
||||
_writeData(0xc3);
|
||||
_writeCommand(0x20);
|
||||
_waitWhileBusy("_PowerOff", power_off_time);
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::_InitDisplay(uint8_t em)
|
||||
{
|
||||
_writeCommand(0x12);
|
||||
_waitWhileBusy("_SWReset", power_on_time);
|
||||
|
||||
_writeCommand(0x01);
|
||||
_writeData(0xC7);
|
||||
_writeData(0x00);
|
||||
_writeData(0x00);
|
||||
|
||||
_writeCommand(0x3C);
|
||||
_writeData(0x05);
|
||||
_writeCommand(0x18);
|
||||
_writeData(0x80);
|
||||
|
||||
/*_writeCommandData(GDOControl, sizeof(GDOControl)); // Pannel configuration, Gate selection
|
||||
_writeCommandData(softstart, sizeof(softstart)); // X decrease, Y decrease
|
||||
_writeCommandData(VCOMVol, sizeof(VCOMVol)); // VCOM setting
|
||||
_writeCommandData(DummyLine, sizeof(DummyLine)); // dummy line per gate
|
||||
_writeCommandData(Gatetime, sizeof(Gatetime)); // Gate time setting*/
|
||||
_setRamDataEntryMode(em);
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::_Init_Full(uint8_t em)
|
||||
{
|
||||
_InitDisplay(em);
|
||||
//_writeCommandData(LUTDefault_full, sizeof(LUTDefault_full));
|
||||
_PowerOn();
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::_Init_Part(uint8_t em)
|
||||
{
|
||||
_InitDisplay(em);
|
||||
//_writeCommandData(LUTDefault_part, sizeof(LUTDefault_part));
|
||||
_PowerOn();
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::_Update_Full(void)
|
||||
{
|
||||
_writeCommand(0x22);
|
||||
_writeData(0xf7);
|
||||
_writeCommand(0x20);
|
||||
_waitWhileBusy("_Update_Full", full_refresh_time);
|
||||
//_writeCommand(0xff);
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::_Update_Part(void)
|
||||
{
|
||||
_writeCommand(0x22);
|
||||
_writeData(0xff);
|
||||
_writeCommand(0x20);
|
||||
_waitWhileBusy("_Update_Part", partial_refresh_time);
|
||||
//_writeCommand(0xff);
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::drawPaged(void (*drawCallback)(void))
|
||||
{
|
||||
if (_current_page != -1) return;
|
||||
_using_partial_mode = false;
|
||||
_Init_Full(0x03);
|
||||
_writeCommand(0x24);
|
||||
for (_current_page = 0; _current_page < GxGDEH0154D67_PAGES; _current_page++)
|
||||
{
|
||||
fillScreen(GxEPD_WHITE);
|
||||
drawCallback();
|
||||
for (int16_t y1 = 0; y1 < GxGDEH0154D67_PAGE_HEIGHT; y1++)
|
||||
{
|
||||
for (int16_t x1 = 0; x1 < GxGDEH0154D67_WIDTH / 8; x1++)
|
||||
{
|
||||
uint16_t idx = y1 * (GxGDEH0154D67_WIDTH / 8) + x1;
|
||||
uint8_t data = (idx < sizeof(_buffer)) ? _buffer[idx] : 0x00;
|
||||
_writeData(~data);
|
||||
}
|
||||
}
|
||||
}
|
||||
_current_page = -1;
|
||||
_Update_Full();
|
||||
_PowerOff();
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::drawPaged(void (*drawCallback)(uint32_t), uint32_t p)
|
||||
{
|
||||
if (_current_page != -1) return;
|
||||
_using_partial_mode = false;
|
||||
_Init_Full(0x03);
|
||||
_writeCommand(0x24);
|
||||
for (_current_page = 0; _current_page < GxGDEH0154D67_PAGES; _current_page++)
|
||||
{
|
||||
fillScreen(GxEPD_WHITE);
|
||||
drawCallback(p);
|
||||
for (int16_t y1 = 0; y1 < GxGDEH0154D67_PAGE_HEIGHT; y1++)
|
||||
{
|
||||
for (int16_t x1 = 0; x1 < GxGDEH0154D67_WIDTH / 8; x1++)
|
||||
{
|
||||
uint16_t idx = y1 * (GxGDEH0154D67_WIDTH / 8) + x1;
|
||||
uint8_t data = (idx < sizeof(_buffer)) ? _buffer[idx] : 0x00;
|
||||
_writeData(~data);
|
||||
}
|
||||
}
|
||||
}
|
||||
_current_page = -1;
|
||||
_Update_Full();
|
||||
_PowerOff();
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::drawPaged(void (*drawCallback)(const void*), const void* p)
|
||||
{
|
||||
if (_current_page != -1) return;
|
||||
_using_partial_mode = false;
|
||||
_Init_Full(0x03);
|
||||
_writeCommand(0x24);
|
||||
for (_current_page = 0; _current_page < GxGDEH0154D67_PAGES; _current_page++)
|
||||
{
|
||||
fillScreen(GxEPD_WHITE);
|
||||
drawCallback(p);
|
||||
for (int16_t y1 = 0; y1 < GxGDEH0154D67_PAGE_HEIGHT; y1++)
|
||||
{
|
||||
for (int16_t x1 = 0; x1 < GxGDEH0154D67_WIDTH / 8; x1++)
|
||||
{
|
||||
uint16_t idx = y1 * (GxGDEH0154D67_WIDTH / 8) + x1;
|
||||
uint8_t data = (idx < sizeof(_buffer)) ? _buffer[idx] : 0x00;
|
||||
_writeData(~data);
|
||||
}
|
||||
}
|
||||
}
|
||||
_current_page = -1;
|
||||
_Update_Full();
|
||||
_PowerOff();
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::drawPaged(void (*drawCallback)(const void*, const void*), const void* p1, const void* p2)
|
||||
{
|
||||
if (_current_page != -1) return;
|
||||
_using_partial_mode = false;
|
||||
_Init_Full(0x03);
|
||||
_writeCommand(0x24);
|
||||
for (_current_page = 0; _current_page < GxGDEH0154D67_PAGES; _current_page++)
|
||||
{
|
||||
fillScreen(GxEPD_WHITE);
|
||||
drawCallback(p1, p2);
|
||||
for (int16_t y1 = 0; y1 < GxGDEH0154D67_PAGE_HEIGHT; y1++)
|
||||
{
|
||||
for (int16_t x1 = 0; x1 < GxGDEH0154D67_WIDTH / 8; x1++)
|
||||
{
|
||||
uint16_t idx = y1 * (GxGDEH0154D67_WIDTH / 8) + x1;
|
||||
uint8_t data = (idx < sizeof(_buffer)) ? _buffer[idx] : 0x00;
|
||||
_writeData(~data);
|
||||
}
|
||||
}
|
||||
}
|
||||
_current_page = -1;
|
||||
_Update_Full();
|
||||
_PowerOff();
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::_rotate(uint16_t& x, uint16_t& y, uint16_t& w, uint16_t& h)
|
||||
{
|
||||
switch (getRotation())
|
||||
{
|
||||
case 1:
|
||||
swap(x, y);
|
||||
swap(w, h);
|
||||
x = GxGDEH0154D67_WIDTH - x - w - 1;
|
||||
break;
|
||||
case 2:
|
||||
x = GxGDEH0154D67_WIDTH - x - w - 1;
|
||||
y = GxGDEH0154D67_HEIGHT - y - h - 1;
|
||||
break;
|
||||
case 3:
|
||||
swap(x, y);
|
||||
swap(w, h);
|
||||
y = GxGDEH0154D67_HEIGHT - y - h - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::drawPagedToWindow(void (*drawCallback)(void), uint16_t x, uint16_t y, uint16_t w, uint16_t h)
|
||||
{
|
||||
if (_current_page != -1) return;
|
||||
_rotate(x, y, w, h);
|
||||
if (!_using_partial_mode)
|
||||
{
|
||||
eraseDisplay(false);
|
||||
eraseDisplay(true);
|
||||
}
|
||||
_using_partial_mode = true;
|
||||
_Init_Part(0x03);
|
||||
for (_current_page = 0; _current_page < GxGDEH0154D67_PAGES; _current_page++)
|
||||
{
|
||||
uint16_t yds = gx_uint16_max(y, _current_page * GxGDEH0154D67_PAGE_HEIGHT);
|
||||
uint16_t yde = gx_uint16_min(y + h, (_current_page + 1) * GxGDEH0154D67_PAGE_HEIGHT);
|
||||
if (yde > yds)
|
||||
{
|
||||
fillScreen(GxEPD_WHITE);
|
||||
drawCallback();
|
||||
uint16_t ys = yds % GxGDEH0154D67_PAGE_HEIGHT;
|
||||
_writeToWindow(x, ys, x, yds, w, yde - yds);
|
||||
}
|
||||
}
|
||||
_Update_Part();
|
||||
delay(GxGDEH0154D67_PU_DELAY);
|
||||
// update erase buffer
|
||||
for (_current_page = 0; _current_page < GxGDEH0154D67_PAGES; _current_page++)
|
||||
{
|
||||
uint16_t yds = gx_uint16_max(y, _current_page * GxGDEH0154D67_PAGE_HEIGHT);
|
||||
uint16_t yde = gx_uint16_min(y + h, (_current_page + 1) * GxGDEH0154D67_PAGE_HEIGHT);
|
||||
if (yde > yds)
|
||||
{
|
||||
fillScreen(GxEPD_WHITE);
|
||||
drawCallback();
|
||||
uint16_t ys = yds % GxGDEH0154D67_PAGE_HEIGHT;
|
||||
_writeToWindow(x, ys, x, yds, w, yde - yds);
|
||||
}
|
||||
}
|
||||
delay(GxGDEH0154D67_PU_DELAY);
|
||||
_current_page = -1;
|
||||
_PowerOff();
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::drawPagedToWindow(void (*drawCallback)(uint32_t), uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t p)
|
||||
{
|
||||
if (_current_page != -1) return;
|
||||
_rotate(x, y, w, h);
|
||||
if (!_using_partial_mode)
|
||||
{
|
||||
eraseDisplay(false);
|
||||
eraseDisplay(true);
|
||||
}
|
||||
_using_partial_mode = true;
|
||||
_Init_Part(0x03);
|
||||
for (_current_page = 0; _current_page < GxGDEH0154D67_PAGES; _current_page++)
|
||||
{
|
||||
uint16_t yds = gx_uint16_max(y, _current_page * GxGDEH0154D67_PAGE_HEIGHT);
|
||||
uint16_t yde = gx_uint16_min(y + h, (_current_page + 1) * GxGDEH0154D67_PAGE_HEIGHT);
|
||||
if (yde > yds)
|
||||
{
|
||||
fillScreen(GxEPD_WHITE);
|
||||
drawCallback(p);
|
||||
uint16_t ys = yds % GxGDEH0154D67_PAGE_HEIGHT;
|
||||
_writeToWindow(x, ys, x, yds, w, yde - yds);
|
||||
}
|
||||
}
|
||||
_Update_Part();
|
||||
delay(GxGDEH0154D67_PU_DELAY);
|
||||
// update erase buffer
|
||||
for (_current_page = 0; _current_page < GxGDEH0154D67_PAGES; _current_page++)
|
||||
{
|
||||
uint16_t yds = gx_uint16_max(y, _current_page * GxGDEH0154D67_PAGE_HEIGHT);
|
||||
uint16_t yde = gx_uint16_min(y + h, (_current_page + 1) * GxGDEH0154D67_PAGE_HEIGHT);
|
||||
if (yde > yds)
|
||||
{
|
||||
fillScreen(GxEPD_WHITE);
|
||||
drawCallback(p);
|
||||
uint16_t ys = yds % GxGDEH0154D67_PAGE_HEIGHT;
|
||||
_writeToWindow(x, ys, x, yds, w, yde - yds);
|
||||
}
|
||||
}
|
||||
delay(GxGDEH0154D67_PU_DELAY);
|
||||
_current_page = -1;
|
||||
_PowerOff();
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::drawPagedToWindow(void (*drawCallback)(const void*), uint16_t x, uint16_t y, uint16_t w, uint16_t h, const void* p)
|
||||
{
|
||||
if (_current_page != -1) return;
|
||||
_rotate(x, y, w, h);
|
||||
if (!_using_partial_mode)
|
||||
{
|
||||
eraseDisplay(false);
|
||||
eraseDisplay(true);
|
||||
}
|
||||
_using_partial_mode = true;
|
||||
_Init_Part(0x03);
|
||||
for (_current_page = 0; _current_page < GxGDEH0154D67_PAGES; _current_page++)
|
||||
{
|
||||
uint16_t yds = gx_uint16_max(y, _current_page * GxGDEH0154D67_PAGE_HEIGHT);
|
||||
uint16_t yde = gx_uint16_min(y + h, (_current_page + 1) * GxGDEH0154D67_PAGE_HEIGHT);
|
||||
if (yde > yds)
|
||||
{
|
||||
fillScreen(GxEPD_WHITE);
|
||||
drawCallback(p);
|
||||
uint16_t ys = yds % GxGDEH0154D67_PAGE_HEIGHT;
|
||||
_writeToWindow(x, ys, x, yds, w, yde - yds);
|
||||
}
|
||||
}
|
||||
_Update_Part();
|
||||
delay(GxGDEH0154D67_PU_DELAY);
|
||||
// update erase buffer
|
||||
for (_current_page = 0; _current_page < GxGDEH0154D67_PAGES; _current_page++)
|
||||
{
|
||||
uint16_t yds = gx_uint16_max(y, _current_page * GxGDEH0154D67_PAGE_HEIGHT);
|
||||
uint16_t yde = gx_uint16_min(y + h, (_current_page + 1) * GxGDEH0154D67_PAGE_HEIGHT);
|
||||
if (yde > yds)
|
||||
{
|
||||
fillScreen(GxEPD_WHITE);
|
||||
drawCallback(p);
|
||||
uint16_t ys = yds % GxGDEH0154D67_PAGE_HEIGHT;
|
||||
_writeToWindow(x, ys, x, yds, w, yde - yds);
|
||||
}
|
||||
}
|
||||
delay(GxGDEH0154D67_PU_DELAY);
|
||||
_current_page = -1;
|
||||
_PowerOff();
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::drawPagedToWindow(void (*drawCallback)(const void*, const void*), uint16_t x, uint16_t y, uint16_t w, uint16_t h, const void* p1, const void* p2)
|
||||
{
|
||||
if (_current_page != -1) return;
|
||||
_rotate(x, y, w, h);
|
||||
if (!_using_partial_mode)
|
||||
{
|
||||
eraseDisplay(false);
|
||||
eraseDisplay(true);
|
||||
}
|
||||
_using_partial_mode = true;
|
||||
_Init_Part(0x03);
|
||||
for (_current_page = 0; _current_page < GxGDEH0154D67_PAGES; _current_page++)
|
||||
{
|
||||
uint16_t yds = gx_uint16_max(y, _current_page * GxGDEH0154D67_PAGE_HEIGHT);
|
||||
uint16_t yde = gx_uint16_min(y + h, (_current_page + 1) * GxGDEH0154D67_PAGE_HEIGHT);
|
||||
if (yde > yds)
|
||||
{
|
||||
fillScreen(GxEPD_WHITE);
|
||||
drawCallback(p1, p2);
|
||||
uint16_t ys = yds % GxGDEH0154D67_PAGE_HEIGHT;
|
||||
_writeToWindow(x, ys, x, yds, w, yde - yds);
|
||||
}
|
||||
}
|
||||
_Update_Part();
|
||||
delay(GxGDEH0154D67_PU_DELAY);
|
||||
// update erase buffer
|
||||
for (_current_page = 0; _current_page < GxGDEH0154D67_PAGES; _current_page++)
|
||||
{
|
||||
uint16_t yds = gx_uint16_max(y, _current_page * GxGDEH0154D67_PAGE_HEIGHT);
|
||||
uint16_t yde = gx_uint16_min(y + h, (_current_page + 1) * GxGDEH0154D67_PAGE_HEIGHT);
|
||||
if (yde > yds)
|
||||
{
|
||||
fillScreen(GxEPD_WHITE);
|
||||
drawCallback(p1, p2);
|
||||
uint16_t ys = yds % GxGDEH0154D67_PAGE_HEIGHT;
|
||||
_writeToWindow(x, ys, x, yds, w, yde - yds);
|
||||
}
|
||||
}
|
||||
delay(GxGDEH0154D67_PU_DELAY);
|
||||
_current_page = -1;
|
||||
_PowerOff();
|
||||
}
|
||||
|
||||
void GxGDEH0154D67::drawCornerTest(uint8_t em)
|
||||
{
|
||||
if (_current_page != -1) return;
|
||||
_Init_Full(em);
|
||||
_writeCommand(0x24);
|
||||
for (uint32_t y = 0; y < GxGDEH0154D67_HEIGHT; y++)
|
||||
{
|
||||
for (uint32_t x = 0; x < GxGDEH0154D67_WIDTH / 8; x++)
|
||||
{
|
||||
uint8_t data = 0xFF;
|
||||
if ((x < 1) && (y < 8)) data = 0x00;
|
||||
if ((x > GxGDEH0154D67_WIDTH / 8 - 3) && (y < 16)) data = 0x00;
|
||||
if ((x > GxGDEH0154D67_WIDTH / 8 - 4) && (y > GxGDEH0154D67_HEIGHT - 25)) data = 0x00;
|
||||
if ((x < 4) && (y > GxGDEH0154D67_HEIGHT - 33)) data = 0x00;
|
||||
_writeData(data);
|
||||
}
|
||||
}
|
||||
_Update_Full();
|
||||
_PowerOff();
|
||||
}
|
||||
|
|
@ -1,130 +0,0 @@
|
|||
// class GxGDEH0154D67 : Display class for GDEH0154D67 e-Paper from Dalian Good Display Co., Ltd.: www.good-display.com
|
||||
//
|
||||
// based on Demo Example from Good Display, available here: http://www.e-paper-display.com/download_detail/downloadsId=806.html
|
||||
// Controller : SSD1681 : http://www.e-paper-display.com/download_detail/downloadsId=825.html
|
||||
//
|
||||
// Author : SQFMI
|
||||
//
|
||||
// Version : see library.properties
|
||||
//
|
||||
// Library: https://github.com/sqfmi/GxEPD
|
||||
|
||||
#ifndef _GxGDEH0154D67_H_
|
||||
#define _GxGDEH0154D67_H_
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <GxEPD.h>
|
||||
|
||||
// the physical number of pixels (for controller parameter)
|
||||
#define GxGDEH0154D67_X_PIXELS 200
|
||||
#define GxGDEH0154D67_Y_PIXELS 200
|
||||
|
||||
#define GxGDEH0154D67_WIDTH GxGDEH0154D67_X_PIXELS
|
||||
#define GxGDEH0154D67_HEIGHT GxGDEH0154D67_Y_PIXELS
|
||||
|
||||
#define GxGDEH0154D67_BUFFER_SIZE (uint32_t(GxGDEH0154D67_WIDTH) * uint32_t(GxGDEH0154D67_HEIGHT) / 8)
|
||||
|
||||
// divisor for AVR, should be factor of GxGDEH0154D67_HEIGHT
|
||||
#define GxGDEH0154D67_PAGES 5
|
||||
|
||||
#define GxGDEH0154D67_PAGE_HEIGHT (GxGDEH0154D67_HEIGHT / GxGDEH0154D67_PAGES)
|
||||
#define GxGDEH0154D67_PAGE_SIZE (GxGDEH0154D67_BUFFER_SIZE / GxGDEH0154D67_PAGES)
|
||||
|
||||
class GxGDEH0154D67 : public GxEPD
|
||||
{
|
||||
public:
|
||||
#if defined(ESP8266)
|
||||
//GxGDEH0154D67(GxIO& io, int8_t rst = D4, int8_t busy = D2);
|
||||
// use pin numbers, other ESP8266 than Wemos may not use Dx names
|
||||
GxGDEH0154D67(GxIO& io, int8_t rst = 2, int8_t busy = 4);
|
||||
#else
|
||||
GxGDEH0154D67(GxIO& io, int8_t rst = 9, int8_t busy = 7);
|
||||
#endif
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color);
|
||||
void init(uint32_t serial_diag_bitrate = 0); // = 0 : disabled
|
||||
void fillScreen(uint16_t color); // 0x0 black, >0x0 white, to buffer
|
||||
void update(void);
|
||||
// to buffer, may be cropped, drawPixel() used, update needed
|
||||
void drawBitmap(const uint8_t *bitmap, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color, int16_t mode = bm_normal);
|
||||
// to full screen, filled with white if size is less, no update needed
|
||||
void drawBitmap(const uint8_t *bitmap, uint32_t size, int16_t mode = bm_normal); // only bm_normal, bm_invert, bm_partial_update modes implemented
|
||||
void eraseDisplay(bool using_partial_update = false);
|
||||
// partial update of rectangle from buffer to screen, does not power off
|
||||
void updateWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h, bool using_rotation = true);
|
||||
// partial update of rectangle at (xs,ys) from buffer to screen at (xd,yd), does not power off
|
||||
void updateToWindow(uint16_t xs, uint16_t ys, uint16_t xd, uint16_t yd, uint16_t w, uint16_t h, bool using_rotation = true);
|
||||
// terminate cleanly updateWindow or updateToWindow before removing power or long delays
|
||||
void powerDown();
|
||||
void deepSleep();
|
||||
// paged drawing, for limited RAM, drawCallback() is called GxGDEH0154D67_PAGES times
|
||||
// each call of drawCallback() should draw the same
|
||||
void drawPaged(void (*drawCallback)(void));
|
||||
void drawPaged(void (*drawCallback)(uint32_t), uint32_t);
|
||||
void drawPaged(void (*drawCallback)(const void*), const void*);
|
||||
void drawPaged(void (*drawCallback)(const void*, const void*), const void*, const void*);
|
||||
// paged drawing to screen rectangle at (x,y) using partial update
|
||||
void drawPagedToWindow(void (*drawCallback)(void), uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
||||
void drawPagedToWindow(void (*drawCallback)(uint32_t), uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t);
|
||||
void drawPagedToWindow(void (*drawCallback)(const void*), uint16_t x, uint16_t y, uint16_t w, uint16_t h, const void*);
|
||||
void drawPagedToWindow(void (*drawCallback)(const void*, const void*), uint16_t x, uint16_t y, uint16_t w, uint16_t h, const void*, const void*);
|
||||
void drawCornerTest(uint8_t em = 0x01);
|
||||
private:
|
||||
template <typename T> static inline void
|
||||
swap(T& a, T& b)
|
||||
{
|
||||
T t = a;
|
||||
a = b;
|
||||
b = t;
|
||||
}
|
||||
void _writeToWindow(uint16_t xs, uint16_t ys, uint16_t xd, uint16_t yd, uint16_t w, uint16_t h);
|
||||
void _writeData(uint8_t data);
|
||||
void _writeCommand(uint8_t command);
|
||||
void _writeCommandData(const uint8_t* pCommandData, uint8_t datalen);
|
||||
void _SetRamPointer(uint8_t addrX, uint8_t addrY, uint8_t addrY1);
|
||||
void _SetRamArea(uint8_t Xstart, uint8_t Xend, uint8_t Ystart, uint8_t Ystart1, uint8_t Yend, uint8_t Yend1);
|
||||
void _PowerOn(void);
|
||||
void _PowerOff(void);
|
||||
void _waitWhileBusy(const char* comment, uint16_t busy_time);
|
||||
void _setRamDataEntryMode(uint8_t em);
|
||||
void _InitDisplay(uint8_t em);
|
||||
void _Init_Full(uint8_t em);
|
||||
void _Init_Part(uint8_t em);
|
||||
void _Update_Full(void);
|
||||
void _Update_Part(void);
|
||||
void _rotate(uint16_t& x, uint16_t& y, uint16_t& w, uint16_t& h);
|
||||
protected:
|
||||
#if defined(__AVR)
|
||||
uint8_t _buffer[GxGDEH0154D67_PAGE_SIZE];
|
||||
#else
|
||||
uint8_t _buffer[GxGDEH0154D67_BUFFER_SIZE];
|
||||
#endif
|
||||
private:
|
||||
GxIO& IO;
|
||||
int16_t _current_page;
|
||||
bool _using_partial_mode;
|
||||
bool _diag_enabled;
|
||||
int8_t _rst;
|
||||
int8_t _busy;
|
||||
static const uint16_t power_on_time = 80; // ms, e.g. 73508us
|
||||
static const uint16_t power_off_time = 80; // ms, e.g. 68982us
|
||||
static const uint16_t full_refresh_time = 200; // ms, e.g. 1113273us
|
||||
static const uint16_t partial_refresh_time = 200; // ms, changed to 0 to make it as fast as possible
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
public:
|
||||
// the compiler of these packages has a problem with signature matching to base classes
|
||||
void drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color)
|
||||
{
|
||||
Adafruit_GFX::drawBitmap(x, y, bitmap, w, h, color);
|
||||
};
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifndef GxEPD_Class
|
||||
#define GxEPD_Class GxGDEH0154D67
|
||||
#define GxEPD_WIDTH GxGDEH0154D67_WIDTH
|
||||
#define GxEPD_HEIGHT GxGDEH0154D67_HEIGHT
|
||||
#define GxEPD_BitmapExamples <GxGDEH0154D67/BitmapExamples.h>
|
||||
#define GxEPD_BitmapExamplesQ "GxGDEH0154D67/BitmapExamples.h"
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue