small changes and many new sensors
This commit is contained in:
@@ -1,10 +1,52 @@
|
||||
|
||||
#include "Waveshare.h"
|
||||
|
||||
// www.waveshare.com/wiki/4.2inch_e-Paper_Module_(B)
|
||||
// https://www.waveshare.com/wiki/4.2inch_e-Paper_Module_(B)_Manual#Overview
|
||||
|
||||
template <int PIN_CS, int PIN_BUSY, int PIN_RST, int PIN_DC, typename SPI> class Waveshare_4_2 : public Waveshare<PIN_CS, PIN_BUSY, PIN_RST, PIN_DC, SPI> {
|
||||
|
||||
static constexpr const char* NAME = "E-Ink 4.2\"";
|
||||
|
||||
static constexpr const uint8_t PANEL_SETTING = 0x00;
|
||||
static constexpr const uint8_t POWER_SETTING = 0x01;
|
||||
static constexpr const uint8_t POWER_OFF = 0x02;
|
||||
static constexpr const uint8_t POWER_OFF_SEQUENCE_SETTING = 0x03;
|
||||
static constexpr const uint8_t POWER_ON = 0x04;
|
||||
static constexpr const uint8_t POWER_ON_MEASURE = 0x05;
|
||||
static constexpr const uint8_t BOOSTER_SOFT_START = 0x06;
|
||||
static constexpr const uint8_t DEEP_SLEEP = 0x07;
|
||||
static constexpr const uint8_t DATA_START_TRANSMISSION_1 = 0x10;
|
||||
static constexpr const uint8_t DATA_STOP = 0x11;
|
||||
static constexpr const uint8_t DISPLAY_REFRESH = 0x12;
|
||||
static constexpr const uint8_t DATA_START_TRANSMISSION_2 = 0x13;
|
||||
static constexpr const uint8_t LUT_FOR_VCOM = 0x20;
|
||||
static constexpr const uint8_t LUT_WHITE_TO_WHITE = 0x21;
|
||||
static constexpr const uint8_t LUT_BLACK_TO_WHITE = 0x22;
|
||||
static constexpr const uint8_t LUT_WHITE_TO_BLACK = 0x23;
|
||||
static constexpr const uint8_t LUT_BLACK_TO_BLACK = 0x24;
|
||||
static constexpr const uint8_t PLL_CONTROL = 0x30;
|
||||
static constexpr const uint8_t TEMPERATURE_SENSOR_COMMAND = 0x40;
|
||||
static constexpr const uint8_t TEMPERATURE_SENSOR_SELECTION = 0x41;
|
||||
static constexpr const uint8_t TEMPERATURE_SENSOR_WRITE = 0x42;
|
||||
static constexpr const uint8_t TEMPERATURE_SENSOR_READ = 0x43;
|
||||
static constexpr const uint8_t VCOM_AND_DATA_INTERVAL_SETTING = 0x50;
|
||||
static constexpr const uint8_t LOW_POWER_DETECTION = 0x51;
|
||||
static constexpr const uint8_t TCON_SETTING = 0x60;
|
||||
static constexpr const uint8_t RESOLUTION_SETTING = 0x61;
|
||||
static constexpr const uint8_t GSST_SETTING = 0x65;
|
||||
static constexpr const uint8_t GET_STATUS = 0x71;
|
||||
static constexpr const uint8_t AUTO_MEASUREMENT_VCOM = 0x80;
|
||||
static constexpr const uint8_t READ_VCOM_VALUE = 0x81;
|
||||
static constexpr const uint8_t VCM_DC_SETTING = 0x82;
|
||||
static constexpr const uint8_t PARTIAL_WINDOW = 0x90;
|
||||
static constexpr const uint8_t PARTIAL_IN = 0x91;
|
||||
static constexpr const uint8_t PARTIAL_OUT = 0x92;
|
||||
static constexpr const uint8_t PROGRAM_MODE = 0xA0;
|
||||
static constexpr const uint8_t ACTIVE_PROGRAMMING = 0xA1;
|
||||
static constexpr const uint8_t READ_OTP = 0xA2;
|
||||
static constexpr const uint8_t POWER_SAVING = 0xE3;
|
||||
|
||||
public:
|
||||
|
||||
enum class Mode {
|
||||
@@ -42,53 +84,55 @@ public:
|
||||
}
|
||||
|
||||
void enableWindow() {
|
||||
this->sendCommand(0x91);
|
||||
this->sendCommand(PARTIAL_IN);
|
||||
}
|
||||
|
||||
void disableWindow() {
|
||||
this->sendCommand(0x92);
|
||||
this->sendCommand(PARTIAL_OUT);
|
||||
}
|
||||
|
||||
void init(Mode mode) {
|
||||
|
||||
debugMod(NAME, "init()");
|
||||
Log::addInfo(NAME, "init()");
|
||||
|
||||
this->reset();
|
||||
|
||||
this->send3(0x06, 0x17, 0x17, 0x17); // BOOSTER_SOFT_START
|
||||
this->sendCommand(0x04); // POWER_ON
|
||||
this->send3(BOOSTER_SOFT_START, 0x17, 0x17, 0x17);
|
||||
this->sendCommand(POWER_ON);
|
||||
this->waitUntilIdle();
|
||||
|
||||
uint8_t cfg = 0x0F;
|
||||
if (mode == Mode::BLACK_WHITE) {cfg |= (1<<4);}
|
||||
this->send1(0x00, cfg); // PANEL_SETTING
|
||||
this->send1(0x50, 0xF7); // VCOM_AND_DATA_INTERVAL_SETTING
|
||||
this->send1(PANEL_SETTING, cfg);
|
||||
this->send1(VCOM_AND_DATA_INTERVAL_SETTING, 0xF7);
|
||||
|
||||
//this->sendCommand(0x10);//DATA_START_TRANSMISSION_1
|
||||
//usleep(10*1000);
|
||||
|
||||
debugMod(NAME, "init() complete");
|
||||
Log::addInfo(NAME, "init() complete");
|
||||
|
||||
}
|
||||
|
||||
/** load black data, bit-set = black pixel, nullptr input = clear all */
|
||||
void loadBlack(const uint8_t* black) {
|
||||
this->sendCommand(0x10);
|
||||
this->sendCommand(DATA_START_TRANSMISSION_1);
|
||||
if (black) {
|
||||
for (int i = 0; i < 400*300/8; ++i) {this->sendData(~reverse(black[i]));}
|
||||
} else {
|
||||
for (int i = 0; i < 400*300/8; ++i) {this->sendData(~0x00);}
|
||||
for (int i = 0; i < 400*300/8; ++i) {this->sendData(0);} // 0 = pixel not set (blank)
|
||||
}
|
||||
this->sendCommand(0x11);
|
||||
this->sendCommand(DATA_STOP);
|
||||
}
|
||||
|
||||
/** load black data, bit-set = red pixel, nullptr input = clear all */
|
||||
void loadRed(const uint8_t* red) {
|
||||
this->sendCommand(0x13);
|
||||
this->sendCommand(DATA_START_TRANSMISSION_2);
|
||||
if (red) {
|
||||
for (int i = 0; i < 400*300/8; ++i) {this->sendData(~reverse(red[i]));}
|
||||
} else {
|
||||
for (int i = 0; i < 400*300/8; ++i) {this->sendData(~0x00);}
|
||||
for (int i = 0; i < 400*300/8; ++i) {this->sendData(0);} // 0 = pixel not set (blank)
|
||||
}
|
||||
this->sendCommand(0x11);
|
||||
this->sendCommand(DATA_STOP);
|
||||
}
|
||||
|
||||
static uint8_t reverse(uint8_t a) {
|
||||
@@ -101,19 +145,19 @@ public:
|
||||
|
||||
void show() {
|
||||
|
||||
debugMod(NAME, "refresh");
|
||||
this->sendCommand(0x12);//DISPLAY_REFRESH
|
||||
Log::addInfo(NAME, "refresh");
|
||||
this->sendCommand(DISPLAY_REFRESH);
|
||||
usleep(100*1000);
|
||||
this->waitUntilIdle();
|
||||
debugMod(NAME, "refresh done");
|
||||
Log::addInfo(NAME, "refresh done");
|
||||
|
||||
debugMod(NAME, "sleep");
|
||||
this->send1(0x50, 0x17);//VCOM_AND_DATA_INTERVAL_SETTING
|
||||
this->send1(0x82, 0x00);//VCM_DC_SETTING_REGISTER, to solve Vcom drop
|
||||
this->send4(0x01, 0x02, 0x00, 0x00, 0x00);//POWER_SETTING
|
||||
Log::addInfo(NAME, "sleep");
|
||||
this->send1(VCOM_AND_DATA_INTERVAL_SETTING, 0x17);
|
||||
this->send1(VCM_DC_SETTING, 0x00); //to solve Vcom drop
|
||||
this->send4(POWER_SETTING, 0x02, 0x00, 0x00, 0x00);
|
||||
this->waitUntilIdle();
|
||||
this->sendCommand(0x02);//POWER_OFF
|
||||
debugMod(NAME, "sleep done");
|
||||
this->sendCommand(POWER_OFF);
|
||||
Log::addInfo(NAME, "sleep done");
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user