diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/include/README b/include/README new file mode 100644 index 0000000..49819c0 --- /dev/null +++ b/include/README @@ -0,0 +1,37 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the convention is to give header files names that end with `.h'. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/lib/README b/lib/README new file mode 100644 index 0000000..9379397 --- /dev/null +++ b/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into the executable file. + +The source code of each library should be placed in a separate directory +("lib/your_library_name/[Code]"). + +For example, see the structure of the following example libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +Example contents of `src/main.c` using Foo and Bar: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +The PlatformIO Library Dependency Finder will find automatically dependent +libraries by scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..607e958 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,20 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:esp32-s3-devkitc-1] +platform = espressif32 +board = esp32-s3-devkitc-1 +framework = arduino +monitor_speed = 115200 +board_build.arduino.partitions = app3M_fat9M_16MB.csv +board_build.arduino.memory_type = qio_opi +build_flags = -DBOARD_HAS_PSRAM +board_upload.flash_size = 16MB +lib_deps = bblanchon/ArduinoJson@^7.3.1 diff --git a/src/buff/buff.cpp b/src/buff/buff.cpp new file mode 100644 index 0000000..0e3a4af --- /dev/null +++ b/src/buff/buff.cpp @@ -0,0 +1,61 @@ +#include + +#include "buff_wifi.h" +#include "buff_bt.h" +#include "epd_driver/epd_conf.h" + + +JsonDocument document; + +int Buff__bufInd; +char* Buff__bufArr = NULL; + +// init buffer +void Buff__init() { + Buff__bufArr = (char*)malloc(Buff__SIZE); + if (Buff__bufArr == NULL) { + Serial.println("malloc for Buff__bufArr failed. exit!"); + exit(-2); + } + memset(Buff__bufArr, 0, Buff__SIZE); +} + +/* Reads a word from the buffer at specified position ------------------------*/ +int Buff__getByte(int index) +{ + if (loadMode == LOAD_MODE_BT) { + return myBUFFBt.Buff__getByte(index); + } else if (loadMode == LOAD_MODE_WIFI) { + return myBUFFWifi.Buff__getByte(index); + } +} + +/* Reads a byte from the buffer at specified position ------------------------*/ +int Buff__getWord(int index) +{ + if (loadMode == LOAD_MODE_BT) { + return myBUFFBt.Buff__getWord(index); + } else if (loadMode == LOAD_MODE_WIFI) { + return myBUFFWifi.Buff__getWord(index); + } +} + +/* Reads a byte from the buffer at specified position ------------------------*/ +int Buff__getN3(int index) +{ + if (loadMode == LOAD_MODE_BT) { + return myBUFFBt.Buff__getN3(index); + } else if (loadMode == LOAD_MODE_WIFI) { + return myBUFFWifi.Buff__getN3(index); + } +} + +/* Checks if the buffer's data ends with specified string --------------------*/ +int Buff__signature(int index, char*str) +{ + if (loadMode == LOAD_MODE_BT) { + return myBUFFBt.Buff__signature(index, str); + } else if (loadMode == LOAD_MODE_WIFI) { + return myBUFFWifi.Buff__signature(index, str); + } +} \ No newline at end of file diff --git a/src/buff/buff.h b/src/buff/buff.h new file mode 100644 index 0000000..61eca9a --- /dev/null +++ b/src/buff/buff.h @@ -0,0 +1,38 @@ +/** + ****************************************************************************** + * @file buff.h + * @author Waveshare Team + * @version V1.0.0 + * @date 23-January-2018 + * @brief ESP8266 WiFi server. + * This file provides firmware functions: + * + Sending web page of the tool to a client's browser + * + Uploading images from client part by part + * + ****************************************************************************** + */ + +#include + +/* Size, current position index and byte array of the buffer -----------------*/ +#define Buff__SIZE 800*480 // may need increase + +#define JSON_BUFF_SIZE 256 + +extern JsonDocument document; + +extern int Buff__bufInd; +extern char* Buff__bufArr; + +void Buff__init(); + +/* Reads a word from the buffer at specified position ------------------------*/ +int Buff__getByte(int index); +/* Reads a byte from the buffer at specified position ------------------------*/ +int Buff__getWord(int index); + +/* Reads a byte from the buffer at specified position ------------------------*/ +int Buff__getN3(int index); + +/* Checks if the buffer's data ends with specified string --------------------*/ +int Buff__signature(int index, char*str); diff --git a/src/buff/buff_bt.cpp b/src/buff/buff_bt.cpp new file mode 100644 index 0000000..9b359a0 --- /dev/null +++ b/src/buff/buff_bt.cpp @@ -0,0 +1,41 @@ +#include "buff_bt.h" + +BUFFBt myBUFFBt; + +/* Reads a word from the buffer at specified position ------------------------*/ +int BUFFBt::Buff__getByte(int index) +{ + return Buff__bufArr[index]; +} + +/* Reads a byte from the buffer at specified position ------------------------*/ +int BUFFBt::Buff__getWord(int index) +{ + if (index + 1 >= Buff__SIZE) return -1; + return Buff__bufArr[index] + (Buff__bufArr[index + 1] << 8); +} + +/* Reads a byte from the buffer at specified position ------------------------*/ +int BUFFBt::Buff__getN3(int index) +{ + return (index + 3 > Buff__SIZE) ? 0 : + (Buff__bufArr[index ] ) + + (Buff__bufArr[index + 1] << 8) + + (Buff__bufArr[index + 2] << 16); +} + +/* Checks if the buffer's data ends with specified string --------------------*/ +int BUFFBt::Buff__signature(int index, char*str) +{ + // characters of the string to the end of the string + while (*str != 0) + { + // If the correspondent character in the buffer isn't equal + // to the string's character, return false + if (Buff__bufArr[index++] != *str) return false; + str++; + } + + // Otherwise return true + return true; +} \ No newline at end of file diff --git a/src/buff/buff_bt.h b/src/buff/buff_bt.h new file mode 100644 index 0000000..0c8af18 --- /dev/null +++ b/src/buff/buff_bt.h @@ -0,0 +1,24 @@ + + #ifndef WIFI_BT_H_ + #define WIFI_BT_H_ + +#include "Arduino.h" +#include "buff.h" + +class BUFFBt { +public: + /* Reads a word from the buffer at specified position ------------------------*/ + static int Buff__getByte(int index); + + /* Reads a byte from the buffer at specified position ------------------------*/ + static int Buff__getWord(int index); + + /* Reads a byte from the buffer at specified position ------------------------*/ + static int Buff__getN3(int index); + + /* Checks if the buffer's data ends with specified string --------------------*/ + static int Buff__signature(int index, char*str); +}; // class BUFFBt + +extern BUFFBt myBUFFBt; +#endif \ No newline at end of file diff --git a/src/buff/buff_wifi.cpp b/src/buff/buff_wifi.cpp new file mode 100644 index 0000000..cc4ae6d --- /dev/null +++ b/src/buff/buff_wifi.cpp @@ -0,0 +1,62 @@ +#include "buff_wifi.h" + +BUFFWifi myBUFFWifi; + +/* Reads a word from the buffer at specified position ------------------------*/ +int BUFFWifi::Buff__getByte(int index) +{ + // The first and second characters of the byte stored in the buffer + // are supposed to be in range ['a'; 'p'], otherwise it isn't a image data's byte + if ((Buff__bufArr[index ] < 'a') || (Buff__bufArr[index ] > 'p')) return -1; + if ((Buff__bufArr[index + 1] < 'a') || (Buff__bufArr[index + 1] > 'p')) return -1; + + // The character 'a' means 0, the character 'p' means 15 consequently, + // The 1st character describes 4 low bits if the byte and the 2nd one - 4 high bits + // return ((int)Buff__bufArr[index] - 'a') + (((int)Buff__bufArr[index + 1] - 'a') << 4); + return (((int)Buff__bufArr[index] - 'a') << 4) + (((int)Buff__bufArr[index + 1] - 'a') & 0x0f); +} + +/* Reads a byte from the buffer at specified position ------------------------*/ +int BUFFWifi::Buff__getWord(int index) +{ + // Read low byte of the word + int a = Buff__getByte(index); + + // If it is not a image data byte, then exit + if (a == -1) return -1; + + // Read high byte of the word + int b = Buff__getByte(index + 2); + + // If it is not a image data byte, then exit + if (b == -1) return -1; + + // Return the word's value + return a + (b << 8); +} + +/* Reads a byte from the buffer at specified position ------------------------*/ +int BUFFWifi::Buff__getN3(int index) +{ + return (index + 3 > Buff__SIZE) ? 0 : + (Buff__bufArr[index ] ) + + (Buff__bufArr[index + 1] << 8) + + (Buff__bufArr[index + 2] << 16); +} + +/* Checks if the buffer's data ends with specified string --------------------*/ +int BUFFWifi::Buff__signature(int index, char*str) +{ + index = 0; // temp add + // characters of the string to the end of the string + while (*str != 0) + { + // If the correspondent character in the buffer isn't equal + // to the string's character, return false + if (Buff__bufArr[index++] != *str) return false; + str++; + } + + // Otherwise return true + return true; +} \ No newline at end of file diff --git a/src/buff/buff_wifi.h b/src/buff/buff_wifi.h new file mode 100644 index 0000000..ed3ae6f --- /dev/null +++ b/src/buff/buff_wifi.h @@ -0,0 +1,38 @@ +/** + ****************************************************************************** + * @file buff.h + * @author Waveshare Team + * @version V1.0.0 + * @date 23-January-2018 + * @brief ESP8266 WiFi server. + * This file provides firmware functions: + * + Sending web page of the tool to a client's browser + * + Uploading images from client part by part + * + ****************************************************************************** + */ + + #ifndef WIFI_BUFF_H_ + #define WIFI_BUFF_H_ + +#include "Arduino.h" +#include "buff.h" + +class BUFFWifi { +public: + /* Reads a word from the buffer at specified position ------------------------*/ + static int Buff__getByte(int index); + + /* Reads a byte from the buffer at specified position ------------------------*/ + static int Buff__getWord(int index); + + /* Reads a byte from the buffer at specified position ------------------------*/ + static int Buff__getN3(int index); + + /* Checks if the buffer's data ends with specified string --------------------*/ + static int Buff__signature(int index, char*str); +}; // class BUFFWifi + +extern BUFFWifi myBUFFWifi; + +#endif \ No newline at end of file diff --git a/src/config/ble_config.cpp b/src/config/ble_config.cpp new file mode 100644 index 0000000..7a87786 --- /dev/null +++ b/src/config/ble_config.cpp @@ -0,0 +1,140 @@ +#include + +#include + +#include "buff/buff.h" +#include "epd_driver/epd.h" + +#include "config/wifi_config.h" +#include "config/ble_config.h" + + +BLEServer *pServer = NULL; +BLECharacteristic *pReadCharacteristic; + +esp_bd_addr_t connectedAddress; // destination device address + +char json_buff[JSON_BUFF_SIZE]; + +class MyServerCallbacks: public BLEServerCallbacks { + void onConnect(BLEServer* pServer, esp_ble_gatts_cb_param_t* param) { + Serial.println("Try connecting.."); + + // update connection params + memcpy(connectedAddress, param->connect.remote_bda, sizeof(esp_bd_addr_t)); + + Serial.printf("connId:%d, mtu=%d\n", param->mtu.conn_id, param->mtu.mtu); + + pServer->updateConnParams(connectedAddress,6,6,0,500); + }; + + void onDisconnect(BLEServer* pServer) { + Serial.println("Disconnected.."); + pServer->getAdvertising()->start(); + } + + // // Maximum Transmission Unit allowed in GATT + // #define ESP_GATT_MAX_MTU_SIZE 517 /* relate to GATT_MAX_MTU_SIZE in stack/gatt_api.h */ + void onMtuChanged(BLEServer* pServer, esp_ble_gatts_cb_param_t* param) { + Serial.printf(">>> onMtuChanged: connId=%d, mtu=%d\n", param->mtu.conn_id, param->mtu.mtu); + } + +}; + +class MsgCallbacks: public BLECharacteristicCallbacks { + void onWrite(BLECharacteristic *pCharacteristic) { + std::string rxValue = pCharacteristic->getValue(); + + if (rxValue.length() > 0) { + Serial.println("*********"); + + // receive data + Buff__bufInd = 0; + Serial.print("Received Value: "); + for (int i = 0; i < rxValue.length(); i++){ + Buff__bufArr[Buff__bufInd++] = rxValue[i]; + Serial.print(rxValue[i]); + } + + Serial.println(); + Serial.println("*********"); + Serial.println(); + } + } +}; + + +class DataCallbacks: public BLECharacteristicCallbacks { + void onWrite(BLECharacteristic *pCharacteristic) { + uint8_t* rxValue = pCharacteristic->getData(); + size_t rxLength = pCharacteristic->getLength(); + + if (rxLength > 0) { + + // receive data + Buff__bufInd = 0; + memset(Buff__bufArr, 0, Buff__SIZE); + + for (int i = 0; i < rxLength; i++){ + Buff__bufArr[Buff__bufInd++] = (byte)rxValue[i]; + } + + Srvr__rcvProc(); + } + } +}; + + +void my_ble_init() { + Serial.println("1- Download and install an BLE scanner app in your phone"); + Serial.println("2- Scan for BLE devices in the app"); + Serial.println("3- Connect to MyESP32"); + Serial.println("4- Go to CUSTOM CHARACTERISTIC in CUSTOM SERVICE and write something"); + Serial.println("5- See the magic =)"); + + // init ble device + BLEDevice::init("MyESP32"); + + // create server for ble device + pServer = BLEDevice::createServer(); + pServer->setCallbacks(new MyServerCallbacks()); + + // create service based on SERVICE_UUID + BLEService *pService = pServer->createService(SERVICE_UUID); + pReadCharacteristic = pService->createCharacteristic( + CHARACTERISTIC_UUID_READ, + BLECharacteristic::PROPERTY_READ + ); + pReadCharacteristic->addDescriptor(new BLE2902()); + + + document["ip_address"] = get_local_ip(); + document["host_name"] = get_host_name(); + + // serialize data and prepare to send + serializeJson(document, json_buff); + Serial.println(json_buff); + + pReadCharacteristic->setValue(json_buff); + + + BLECharacteristic * pWriteCharacteristic = pService->createCharacteristic( + CHARACTERISTIC_UUID_WRITE, + BLECharacteristic::PROPERTY_WRITE + ); + pWriteCharacteristic->setCallbacks(new MsgCallbacks()); + + BLECharacteristic * pWriteDataCharacteristic = pService->createCharacteristic( + CHARACTERISTIC_UUID_WRITE_DATA, + BLECharacteristic::PROPERTY_WRITE + ); + pWriteDataCharacteristic->setCallbacks(new DataCallbacks()); + + // start service + pService->start(); + + pServer->getAdvertising()->start(); + + Serial.println("Waiting a client connection to notify..."); + Serial.println(); +} \ No newline at end of file diff --git a/src/config/ble_config.h b/src/config/ble_config.h new file mode 100644 index 0000000..5f3d1af --- /dev/null +++ b/src/config/ble_config.h @@ -0,0 +1,25 @@ +#ifndef __BLE_CONFIG_H +#define __BLE_CONFIG_H + +#include +#include +#include +#include + +// define service UUID +#define SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E" +// notify +#define CHARACTERISTIC_UUID_NOTIFY "6E400002-B5A3-F393-E0A9-E50E24DCCA9E" +// read +#define CHARACTERISTIC_UUID_READ "6E400003-B5A3-F393-E0A9-E50E24DCCA9E" +// write_msg +#define CHARACTERISTIC_UUID_WRITE "6E400004-B5A3-F393-E0A9-E50E24DCCA9E" +// write_data +#define CHARACTERISTIC_UUID_WRITE_DATA "6E400005-B5A3-F393-E0A9-E50E24DCCA9E" + +void my_ble_init(); + + +extern esp_bd_addr_t connectedAddress; // destination device addresss + +#endif \ No newline at end of file diff --git a/src/config/wifi_config.cpp b/src/config/wifi_config.cpp new file mode 100644 index 0000000..00b957e --- /dev/null +++ b/src/config/wifi_config.cpp @@ -0,0 +1,86 @@ +#include + +#include +#include + +#include "epd_driver/epd.h" +//web +#include "web/Web_Scripts.h" // JavaScript code +#include "web/Web_CSS.h" // Cascading Style Sheets +#include "web/Web_HTML.h" // HTML page of the tool + +#include "config/wifi_config.h" + +/* Server and IP address ------------------------------------------------------*/ +WebServer server(80); +IPAddress myIP; + +void handleNotFound() { + // digitalWrite(led, 1); + String message = "File Not Found\n\n"; + message += "URI: "; + message += server.uri(); + message += "\nMethod: "; + message += (server.method() == HTTP_GET) ? "GET" : "POST"; + message += "\nArguments: "; + message += server.args(); + message += "\n"; + for (uint8_t i = 0; i < server.args(); i++) { + message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; + } + server.send(404, "text/plain", message); + // digitalWrite(led, 0); + Serial.println(message); + } + + +void my_wifi_init() { + Serial.println("start to config network."); + Serial.printf("Connecting to %s\n", WIFI_SSID); + + WiFi.mode(WIFI_MODE_STA); + + // Applying SSID and password + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); + + // Waiting the connection to a router + int try_count = 0; + int wait = WiFi.waitForConnectResult(10000); + Serial.println(wait); + if (wait != WL_CONNECTED) { + Serial.println("wifi connected failed."); + return; + } + + myIP = WiFi.localIP(); + Serial.print("Local IP: "); + Serial.println(myIP); + + // Connection is complete + Serial.println(""); + + Serial.println("WiFi connected"); + server.on("/", Web_SendHTML); + server.on("/index.css", Web_SendCSS); + server.on("/Web_SendJS_A.js", Web_SendJS_A); + + server.on("/EPD", Srvr__postProc); + server.on("/LOADA", Srvr__postProc); + server.on("/LOADB", Srvr__postProc); + server.on("/SHOW", Srvr__postProc); + + server.onNotFound(handleNotFound); + + // Start the server + server.begin(); + Serial.println("Server started"); + +} + +String get_local_ip() { + return WiFi.localIP().toString(); +} + +String get_host_name() { + return WiFi.getHostname(); +} \ No newline at end of file diff --git a/src/config/wifi_config.h b/src/config/wifi_config.h new file mode 100644 index 0000000..11ec4c7 --- /dev/null +++ b/src/config/wifi_config.h @@ -0,0 +1,12 @@ +#ifndef __WIFI_CONFIG_H +#define __WIFI_CONFIG_H + +#define WIFI_SSID "WIFI_SSID" +#define WIFI_PASSWORD "WIFI_PASSWORD" + +void my_wifi_init(); + +String get_local_ip(); +String get_host_name(); + +#endif \ No newline at end of file diff --git a/src/epd_driver/epd.cpp b/src/epd_driver/epd.cpp new file mode 100644 index 0000000..f890fd4 --- /dev/null +++ b/src/epd_driver/epd.cpp @@ -0,0 +1,701 @@ +#include + +#include "buff/buff.h" +#include "epd_conf.h" +#include "epd.h" +#include "epd_wifi.h" +#include "epd_bt.h" + +#include "epd_panel/epd1in54.h" +#include "epd_panel/epd2in13.h" +#include "epd_panel/epd2in9.h" +#include "epd_panel/epd2in7.h" +#include "epd_panel/epd2in66.h" +#include "epd_panel/epd3in7.h" +#include "epd_panel/epd3in52.h" +#include "epd_panel/epd4in01f.h" +#include "epd_panel/epd4in2.h" +#include "epd_panel/epd5in65f.h" +#include "epd_panel/epd5in83.h" +#include "epd_panel/epd7in5.h" +#include "epd_panel/epd7in5_HD.h" +#include "epd_panel/epd7in3f.h" +#include "epd_panel/EPD_12in48b.h" +#include "epd_panel/epd9in7g.h" +#include "epd_panel/EPD_9in69b.h" +#include "epd_panel/epd7in3e.h" + +/* Lut mono ------------------------------------------------------------------*/ +byte lut_full_mono[] = +{ + 0x02, 0x02, 0x01, 0x11, 0x12, 0x12, 0x22, 0x22, + 0x66, 0x69, 0x69, 0x59, 0x58, 0x99, 0x99, 0x88, + 0x00, 0x00, 0x00, 0x00, 0xF8, 0xB4, 0x13, 0x51, + 0x35, 0x51, 0x51, 0x19, 0x01, 0x00 +}; + +byte lut_partial_mono[] = +{ + 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 +}; + +byte lut_vcom0[] = { 15, 0x0E, 0x14, 0x01, 0x0A, 0x06, 0x04, 0x0A, 0x0A, 0x0F, 0x03, 0x03, 0x0C, 0x06, 0x0A, 0x00 }; +byte lut_w [] = { 15, 0x0E, 0x14, 0x01, 0x0A, 0x46, 0x04, 0x8A, 0x4A, 0x0F, 0x83, 0x43, 0x0C, 0x86, 0x0A, 0x04 }; +byte lut_b [] = { 15, 0x0E, 0x14, 0x01, 0x8A, 0x06, 0x04, 0x8A, 0x4A, 0x0F, 0x83, 0x43, 0x0C, 0x06, 0x4A, 0x04 }; +byte lut_g1 [] = { 15, 0x8E, 0x94, 0x01, 0x8A, 0x06, 0x04, 0x8A, 0x4A, 0x0F, 0x83, 0x43, 0x0C, 0x06, 0x0A, 0x04 }; +byte lut_g2 [] = { 15, 0x8E, 0x94, 0x01, 0x8A, 0x06, 0x04, 0x8A, 0x4A, 0x0F, 0x83, 0x43, 0x0C, 0x06, 0x0A, 0x04 }; +byte lut_vcom1[] = { 15, 0x03, 0x1D, 0x01, 0x01, 0x08, 0x23, 0x37, 0x37, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +byte lut_red0 [] = { 15, 0x83, 0x5D, 0x01, 0x81, 0x48, 0x23, 0x77, 0x77, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +byte lut_red1 [] = { 15, 0x03, 0x1D, 0x01, 0x01, 0x08, 0x23, 0x37, 0x37, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + + +int loadMode = LOAD_MODE_BT; + +int PIN_SPI_DIN = -1; +int PIN_SPI_SCK = -1; +int PIN_SPI_CS = -1; +int PIN_SPI_DC = -1; +int PIN_SPI_RST = -1; +int PIN_SPI_BUSY = -1; + +bool is_compress = false; + +uint8_t *rcv_image_data = NULL; +uint32_t rcv_image_data_size = 0; +uint8_t *image_data = NULL; +uint32_t image_data_size = 0; +bool load_stage = false; +bool next_stage = false; + +void decompress_image_data() { + uint32_t size_out = 0; + unsigned long start_time = millis(); + unsigned long end_time = 0; + uint32_t result = ArduinoUZlib::decompress(rcv_image_data, rcv_image_data_size, image_data, image_data_size); + + end_time = millis(); + Serial.printf("cost time=%d\n", end_time - start_time); + Serial.printf("\n=========out buffer=========\n"); + Serial.printf("Byte: %lu, result=%lu\n", image_data_size, result); +} + +void EPD_SPISetCfg( + int din = DEFAULT_PIN_SPI_DIN, + int sck = DEFAULT_PIN_SPI_SCK, + int cs = DEFAULT_PIN_SPI_CS, + int dc = DEFAULT_PIN_SPI_DC, + int rst = DEFAULT_PIN_SPI_RST, + int busy = DEFAULT_PIN_SPI_BUSY) +{ + Serial.printf("SPI config: din=%d, sck=%d, cs=%d, dc=%d, rst=%d, busy=%d\n", + din, sck, cs, dc, rst, busy); + PIN_SPI_DIN = din; + PIN_SPI_SCK = sck; + PIN_SPI_CS = cs; + PIN_SPI_DC = dc; + PIN_SPI_RST = rst; + PIN_SPI_BUSY = busy; +} + +void EPD_initSPI() +{ + pinMode(PIN_SPI_BUSY, INPUT); + pinMode(PIN_SPI_RST , OUTPUT); + pinMode(PIN_SPI_DC , OUTPUT); + + pinMode(PIN_SPI_SCK, OUTPUT); + pinMode(PIN_SPI_DIN, OUTPUT); + pinMode(PIN_SPI_CS , OUTPUT); + + digitalWrite(PIN_SPI_CS , HIGH); + digitalWrite(PIN_SPI_SCK, LOW); +} + +void EpdSpiTransferCallback(byte data) +{ + digitalWrite(PIN_SPI_CS, GPIO_PIN_RESET); + + for (int i = 0; i < 8; i++) + { + if ((data & 0x80) == 0) digitalWrite(PIN_SPI_DIN, GPIO_PIN_RESET); + else digitalWrite(PIN_SPI_DIN, GPIO_PIN_SET); + + data <<= 1; + digitalWrite(PIN_SPI_SCK, GPIO_PIN_SET); + digitalWrite(PIN_SPI_SCK, GPIO_PIN_RESET); + } + + digitalWrite(PIN_SPI_CS, GPIO_PIN_SET); +} + +/* Sending a byte as a command -----------------------------------------------*/ +void EPD_SendCommand(byte command) +{ + digitalWrite(PIN_SPI_DC, LOW); + EpdSpiTransferCallback(command); +} + +/* Sending a byte as a data --------------------------------------------------*/ +void EPD_SendData(byte data) +{ + digitalWrite(PIN_SPI_DC, HIGH); + EpdSpiTransferCallback(data); +} + +/* Waiting the e-Paper is ready for further instructions ---------------------*/ +void EPD_WaitUntilIdle() +{ + //0: busy, 1: idle + while(digitalRead(PIN_SPI_BUSY) == 0) delay(100); +} + +/* Waiting the e-Paper is ready for further instructions ---------------------*/ +void EPD_WaitUntilIdle_high() +{ + //1: busy, 0: idle + while(digitalRead(PIN_SPI_BUSY) == 1) delay(100); +} + +/* Send a one-argument command -----------------------------------------------*/ +void EPD_Send_1(byte c, byte v1) +{ + EPD_SendCommand(c); + EPD_SendData(v1); +} + +/* Send a two-arguments command ----------------------------------------------*/ +void EPD_Send_2(byte c, byte v1, byte v2) +{ + EPD_SendCommand(c); + EPD_SendData(v1); + EPD_SendData(v2); +} + +/* Send a three-arguments command --------------------------------------------*/ +void EPD_Send_3(byte c, byte v1, byte v2, byte v3) +{ + EPD_SendCommand(c); + EPD_SendData(v1); + EPD_SendData(v2); + EPD_SendData(v3); +} + +/* Send a four-arguments command ---------------------------------------------*/ +void EPD_Send_4(byte c, byte v1, byte v2, byte v3, byte v4) +{ + EPD_SendCommand(c); + EPD_SendData(v1); + EPD_SendData(v2); + EPD_SendData(v3); + EPD_SendData(v4); +} + +/* Send a five-arguments command ---------------------------------------------*/ +void EPD_Send_5(byte c, byte v1, byte v2, byte v3, byte v4, byte v5) +{ + EPD_SendCommand(c); + EPD_SendData(v1); + EPD_SendData(v2); + EPD_SendData(v3); + EPD_SendData(v4); + EPD_SendData(v5); +} + +/* Writting lut-data into the e-Paper ----------------------------------------*/ +void EPD_lut(byte c, byte l, byte*p) +{ + // lut-data writting initialization + EPD_SendCommand(c); + + // lut-data writting doing + for (int i = 0; i < l; i++, p++) EPD_SendData(*p); +} + +/* Writting lut-data of the black-white channel ------------------------------*/ +void EPD_SetLutBw(byte*c20, byte*c21, byte*c22, byte*c23, byte*c24) +{ + EPD_lut(0x20, *c20, c20 + 1);//g vcom + EPD_lut(0x21, *c21, c21 + 1);//g ww -- + EPD_lut(0x22, *c22, c22 + 1);//g bw r + EPD_lut(0x23, *c23, c23 + 1);//g wb w + EPD_lut(0x24, *c24, c24 + 1);//g bb b +} + +/* Writting lut-data of the red channel --------------------------------------*/ +void EPD_SetLutRed(byte*c25, byte*c26, byte*c27) +{ + EPD_lut(0x25, *c25, c25 + 1); + EPD_lut(0x26, *c26, c26 + 1); + EPD_lut(0x27, *c27, c27 + 1); +} + +/* This function is used to 'wake up" the e-Paper from the deep sleep mode ---*/ +void EPD_Reset() +{ + digitalWrite(PIN_SPI_RST, HIGH); + delay(200); + digitalWrite(PIN_SPI_RST, LOW); + delay(5); + digitalWrite(PIN_SPI_RST, HIGH); + delay(200); +} + + +/* Image data loading function for a-type e-Paper ----------------------------*/ +void EPD_loadA() +{ + if (loadMode == LOAD_MODE_BT) { + myEPDBt.EPD_loadA(); + return; + } + + int pos = 0; + + // Enumerate all of image data bytes + while (pos < Buff__bufInd) + { + // Get current byte + int value = Buff__getByte(pos); + // Invert byte's bits in case of '2.7' e-Paper + if (EPD_invert) value = ~value; + + // Write the byte into e-Paper's memory + EPD_SendData((byte)value); + + // Increment the current byte index on 2 characters + pos += 2; + } +} + +void EPD_loadAFilp() +{ + if (loadMode == LOAD_MODE_BT) { + myEPDBt.EPD_loadAFilp(); + return; + } + + int pos = 0; + + // Enumerate all of image data bytes + while (pos < Buff__bufInd) + { + // Get current byte + int value = Buff__getByte(pos); + + // Invert byte's bits in case of '2.7' e-Paper + if (EPD_invert) value = ~value; + + // Write the byte into e-Paper's memory + EPD_SendData(~(byte)value); + + // Increment the current byte index on 2 characters + pos += 2; + } +} + +/* Image data loading function for b-type e-Paper ----------------------------*/ +void EPD_loadB() +{ + if (loadMode == LOAD_MODE_BT) { + // not done + return; + } + + // Come back to the image data end + Buff__bufInd -= 8; + + // Get the index of the image data begin + int pos = Buff__bufInd - Buff__getWord(Buff__bufInd); + + // Enumerate all of image data bytes + while (pos < Buff__bufInd) + { + // Get current word from obtained image data + int valueA = (int)Buff__getByte(pos) + ((int)Buff__getByte(pos + 2) << 8); + + // Clean current word of processed image data + int valueB = 0; + + // Enumerate next 8 pixels + for (int p = 0; p < 8; p++) + { + // Current obtained pixel data + int pixInd = valueA & 3; + + // Remove the obtained pixel data from 'valueA' word + valueA = valueA >> 2; + + // Processing of 8 2-bit pixels to 8 2-bit pixels: + // black(value 0) to bits 00, white(value 1) to bits 11, gray(otherwise) to bits 10 + valueB = (valueB << 2) + (pixInd == 1 ? 3 : (pixInd == 0 ? 0 : 2)); + } + + // Write the word into e-Paper's memory + EPD_SendData((byte)(valueB >> 8)); + EPD_SendData((byte)valueB); + + // Increment the current byte index on 2 characters + pos += 4; + } +} + +/* Image data loading function for 2.13 e-Paper ------------------------------*/ +void EPD_loadC() +{ + if (loadMode == LOAD_MODE_BT) { + // not done + return; + } + + // Come back to the image data end + Buff__bufInd -= 8; + + // Get the index of the image data begin + int pos = Buff__bufInd - Buff__getWord(Buff__bufInd); + + EPD_Send_2(0x44, 0, 15); //SET_RAM_X_ADDRESS_START_END_POSITION LO(x >> 3), LO((w - 1) >> 3) + EPD_Send_4(0x45, 0, 0, 249, 0); //SET_RAM_Y_ADDRESS_START_END_POSITION LO(y), HI(y), LO(h - 1), HI(h - 1) + + // Enumerate all of image data bytes + while (pos < Buff__bufInd) + { + // Before write a line of image data + // 2.13 e-Paper requires to set the address counter + // Every line has 15*8-6 pixels + 6 empty bits, totally 15*8 bits + if (EPD_dispX == 0) + { + EPD_Send_1(0x4E, 0 );//SET_RAM_X_ADDRESS_COUNTER: LO(x >> 3) + EPD_Send_2(0x4F, EPD_dispY, 0);//SET_RAM_Y_ADDRESS_COUNTER: LO(y), HI(y) + EPD_SendCommand(0x24);//WRITE_RAM + } + + // Write the byte into e-Paper's memory + EPD_SendData((byte)Buff__getByte(pos)); + + // Increment the current byte index on 2 characters + pos += 2; + + // EPD_dispX and EPD_dispY increments + if (++EPD_dispX > 15) + { + EPD_dispX = 0; + + // If the client's browser sends more bits, than it needs, then exit the function + if (++EPD_dispY > 250) return; + } + } +} + +/* Image data loading function for 7.5 e-Paper -------------------------------*/ +void EPD_loadD() +{ + if (loadMode == LOAD_MODE_BT) { + // not done + return; + } + + // Come back to the image data end + Buff__bufInd -= 8; + + // Get the index of the image data begin + int pos = Buff__bufInd - Buff__getWord(Buff__bufInd); + + // Enumerate all of image data bytes + while (pos < Buff__bufInd) + { + // Get current byte from obtained image data + int valueA = Buff__getByte(pos); + + // Processing of 4 1-bit pixels to 4 4-bit pixels: + // black(value 0) to bits 0000, white(value 1) to bits 0011 + EPD_SendData((byte)((valueA & 0x80) ? 0x30 : 0x00) + ((valueA & 0x40) ? 0x03 : 0x00)); + EPD_SendData((byte)((valueA & 0x20) ? 0x30 : 0x00) + ((valueA & 0x10) ? 0x03 : 0x00)); + EPD_SendData((byte)((valueA & 0x08) ? 0x30 : 0x00) + ((valueA & 0x04) ? 0x03 : 0x00)); + EPD_SendData((byte)((valueA & 0x02) ? 0x30 : 0x00) + ((valueA & 0x01) ? 0x03 : 0x00)); + + // Increment the current byte index on 2 characters + pos += 2; + } +} + +/* Image data loading function for 7.5b e-Paper ------------------------------*/ +void EPD_loadE() +{ + if (loadMode == LOAD_MODE_BT) { + // not done + return; + } + + // Come back to the image data end + Buff__bufInd -= 8; + + // Get the index of the image data begin + int pos = Buff__bufInd - Buff__getWord(Buff__bufInd); + + // Enumerate all of image data bytes + while (pos < Buff__bufInd) + { + // Get current byte from obtained image data + int value = Buff__getByte(pos); + + // Processing of 4 1-bit pixels to 4 4-bit pixels: + // red(value 1) to bits 0011, white(value 3) to bits 0100 + int A = (value ) & 3;if (A == 3) A = 4;if (A == 1) A = 3; + int B = (value >> 2) & 3;if (B == 3) B = 4;if (B == 1) B = 3; + int C = (value >> 4) & 3;if (C == 3) C = 4;if (C == 1) C = 3; + int D = (value >> 6) & 3;if (D == 3) D = 4;if (D == 1) D = 3; + + // Write the word into e-Paper's memory + EPD_SendData((A << 4) + B); + EPD_SendData((C << 4) + D); + + // Increment the current byte index on 2 characters + pos += 2; + } +} + +/* Image data loading function for 5.83b e-Paper -----------------------------*/ +void EPD_loadF() +{ + if (loadMode == LOAD_MODE_BT) { + // not done + return; + } + + // Come back to the image data end + Buff__bufInd -= 8; + + // Get the index of the image data begin + int pos = Buff__bufInd - Buff__getWord(Buff__bufInd); + + // Enumerate all of image data bytes + while (pos < Buff__bufInd) + { + // Get current byte from obtained image data + int value = Buff__getByte(pos); + int value1 = Buff__getByte(pos+2); + // Processing of 4 1-bit pixels to 4 4-bit pixels: + // white(value 1) to bits 0011, red(value 2) to bits 0100 + int A = (value ) & 3;if (A == 2) A = 4; + int B = (value >> 8) & 3;if (B == 2) B = 4; + int C = (value1 >> 4) & 3;if (C == 2) C = 4; + int D = (value1 >> 6) & 3;if (D == 2) D = 4; + + // Write the word into e-Paper's memory + EPD_SendData((A << 4) + B); + EPD_SendData((C << 4) + D); + + // Increment the current byte index on 2 characters + pos += 4; + } +} +/* Image data loading function for 5.65f e-Paper -----------------------------*/ +void EPD_loadG() +{ + if (loadMode == LOAD_MODE_BT) { + myEPDBt.EPD_loadG(); + return; + } + + int pos = 0; + + // Enumerate all of image data bytes + while (pos < Buff__bufInd) + { + // Get current byte + int value = Buff__getByte(pos); + // Invert byte's bits in case of '2.7' e-Paper + if (EPD_invert) value = ~value; + + // Write the byte into e-Paper's memory + EPD_SendData((byte)value); + + // Increment the current byte index on 2 characters + pos += 2; + } +} + +/* Show image and turn to deep sleep mode (a-type, 4.2 and 2.7 e-Paper) ------*/ +void EPD_showA() +{ + // Refresh + EPD_Send_1(0x22, 0xC4);// DISPLAY_UPDATE_CONTROL_2 + EPD_SendCommand( 0x20);// MASTER_ACTIVATION + EPD_SendCommand( 0xFF);// TERMINATE_FRAME_READ_WRITE + EPD_WaitUntilIdle(); + + // Sleep + EPD_SendCommand(0x10);// DEEP_SLEEP_MODE + EPD_WaitUntilIdle(); +} + +/* Show image and turn to deep sleep mode (b-type, e-Paper) ------------------*/ +void EPD_showB() +{ + // Refresh + EPD_SendCommand(0x12);// DISPLAY_REFRESH + delay(100); + EPD_WaitUntilIdle(); + + // Sleep + EPD_Send_1(0x50, 0x17);// VCOM_AND_DATA_INTERVAL_SETTING + EPD_Send_1(0x82, 0x00);// VCM_DC_SETTING_REGISTER, to solve Vcom drop + EPD_Send_4(0x01, 0x02, 0x00, 0x00, 0x00);// POWER_SETTING + EPD_WaitUntilIdle(); + EPD_SendCommand(0x02);// POWER_OFF +} + +/* Show image and turn to deep sleep mode (7.5 and 7.5b e-Paper) -------------*/ +void EPD_showC() +{ + // Refresh + EPD_SendCommand(0x12);// DISPLAY_REFRESH + delay(100); + EPD_WaitUntilIdle(); + + // Sleep + EPD_SendCommand(0x02);// POWER_OFF + EPD_WaitUntilIdle(); + EPD_Send_1(0x07, 0xA5);// DEEP_SLEEP +} + +/* Show image and turn to deep sleep mode (2.13 e-Paper) ---------------------*/ +void EPD_showD() +{ + // VCOM AND DATA INTERVAL SETTING + // WBmode:VBDF 17, D7 VBDW 97, VBDB 57 + // WBRmode:VBDF F7, VBDW 77, VBDB 37, VBDR B7 + EPD_Send_1(0x50, 0x97); + + EPD_SendCommand(0x20); + for(int count=0; count<44; count++) EPD_SendData(lut_vcomDC_2in13d[count]); + + EPD_SendCommand(0x21); + for(int count=0; count<42; count++) EPD_SendData(lut_ww_2in13d[count]); + + EPD_SendCommand(0x22); + for(int count=0; count<42; count++) EPD_SendData(lut_bw_2in13d[count]); + + EPD_SendCommand(0x23); + for(int count=0; count<42; count++) EPD_SendData(lut_wb_2in13d[count]); + + EPD_SendCommand(0x24); + for(int count=0; count<42; count++) EPD_SendData(lut_bb_2in13d[count]); + + delay(10); + EPD_SendCommand(0x12);//DISPLAY REFRESH + delay(100); //!!!The delay here is necessary, 200uS at least!!! + EPD_WaitUntilIdle(); + + EPD_Send_1(0x50, 0xf7); + EPD_SendCommand( 0x02);//POWER_OFF + EPD_Send_1(0x07, 0xA5);//DEEP_SLEEP +} + +/* Initialization of an e-Paper ----------------------------------------------*/ +void EPD_dispInit() +{ + // Call initialization function + EPD_dispMass[EPD_dispIndex].init(); + + // Set loading function for black channel + EPD_dispLoad = EPD_dispMass[EPD_dispIndex].chBk; + + // Set initial coordinates + EPD_dispX = 0; + EPD_dispY = 0; + + // The inversion of image data bits isn't needed by default + EPD_invert = false; + +} + +// for web +bool Srvr__loop() { + bool wifiRet = myEPDWifi.Srvr__loop(); + + return true; +} + +// create queue for bt +bool Srvr__init() { + bool btRet = myEPDBt.Srvr__init(); + return true; +} + +// for bluetooth +void Srvr__rcvProc() { + myEPDBt.Srvr__rcvProc(); +} + +// for wifi +void Srvr__postProc() { + myEPDWifi.Srvr__postProc(); +} + +void reboot_device() { + Serial.println("Now reboot device..."); + esp_restart(); +} + +/* e-Paper initialization functions ------------------------------------------*/ + +bool EPD_invert; // If true, then image data bits must be inverted +int EPD_dispIndex; // The index of the e-Paper's type +int EPD_dispX, EPD_dispY; // Current pixel's coordinates (for 2.13 only) +void(*EPD_dispLoad)(); // Pointer on a image data writting function +/* Array of sets describing the usage of e-Papers ----------------------------*/ +EPD_dispInfo EPD_dispMass[] = +{ + { EPD_Init_1in54 , EPD_loadA, -1 , 0, EPD_showA, "1.54 inch" },// a 0 + { EPD_Init_1in54b, EPD_loadB, 0x13, EPD_loadA, EPD_showB, "1.54 inch b" },// b 1 + { EPD_Init_1in54c, EPD_loadA, 0x13, EPD_loadA, EPD_showB, "1.54 inch c" },// c 2 + { EPD_Init_2in13 , EPD_loadC, -1 , 0, EPD_showA, "2.13 inch" },// d 3 + { EPD_Init_2in13b, EPD_loadA, 0x13, EPD_loadA, EPD_showB, "2.13 inch b" },// e 4 + { EPD_Init_2in13b, EPD_loadA, 0x13, EPD_loadA, EPD_showB, "2.13 inch c" },// f 5 + { EPD_Init_2in13d, EPD_loadA, -1 , 0, EPD_showD, "2.13 inch d" },// g 6 + { EPD_Init_2in7 , EPD_loadA, -1 , 0, EPD_showB, "2.7 inch" },// h 7 + { EPD_Init_2in7b , EPD_loadA, 0x13, EPD_loadA, EPD_showB, "2.7 inch b" },// i 8 + { EPD_Init_2in9 , EPD_loadA, -1 , 0, EPD_showA, "2.9 inch" },// j 9 + { EPD_Init_2in9b , EPD_loadA, 0x13, EPD_loadA, EPD_showB, "2.9 inch b" },// k 10 + { EPD_Init_2in9b , EPD_loadA, 0x13, EPD_loadA, EPD_showB, "2.9 inch c" },// l 11 + { EPD_Init_2in9d , EPD_loadA, -1 , 0, EPD_2IN9D_Show, "2.9 inch d" },// M 12 + { EPD_Init_4in2 , EPD_loadA, -1 , 0, EPD_showB, "4.2 inch" },// m 14 + { EPD_Init_4in2b , EPD_loadA, 0x13, EPD_loadA, EPD_showB, "4.2 inch b" },// n 15 + { EPD_Init_4in2b , EPD_loadA, 0x13, EPD_loadA, EPD_showB, "4.2 inch c" },// o 16 + { EPD_Init_5in83 , EPD_loadD, -1 , 0, EPD_showC, "5.83 inch" },// p 17 + { EPD_Init_5in83b, EPD_loadE, -1 , 0, EPD_showC, "5.83 inch b" },// q 16 + { EPD_Init_5in83b, EPD_loadE, -1 , 0, EPD_showC, "5.83 inch c" },// r 18 + { EPD_Init_7in5 , EPD_loadD, -1 , 0, EPD_showC, "7.5 inch" },// s 19 + { EPD_Init_7in5 , EPD_loadE, -1 , 0, EPD_showC, "7.5 inch b" },// t 20 + { EPD_Init_7in5 , EPD_loadE, -1 , 0, EPD_showC, "7.5 inch c" }, // u 21 + { EPD_7in5_V2_init , EPD_loadAFilp, -1 , 0, EPD_7IN5_V2_Show, "7.5 inch V2" },// w 22 + { EPD_7in5B_V2_Init , EPD_loadA, 0x13 , EPD_loadAFilp, EPD_7IN5_V2_Show, "7.5 inch B V2 "},// x 23 + { EPD_7IN5B_HD_init , EPD_loadA, 0x26 , EPD_loadAFilp, EPD_7IN5B_HD_Show, "7.5 inch B HD "},// x 24 + { EPD_5IN65F_init, EPD_loadG, -1 , 0, EPD_5IN65F_Show, "5.65 inch F " },// z 25 + { EPD_7IN5_HD_init, EPD_loadA, -1, 0, EPD_7IN5_HD_Show, "7.5 inch HD" },// 26 + { EPD_3IN7_1Gray_Init, EPD_loadA, -1 , 0, EPD_3IN7_1Gray_Show,"3.7 inch" },// 27 + { EPD_2IN66_Init, EPD_loadA, -1 , 0, EPD_2IN66_Show, "2.66 inch" },// 28 + { EPD_5in83b_V2_init, EPD_loadA, 0x13, EPD_loadAFilp, EPD_showC, "5.83 inch B V2"},// 29 + { EPD_Init_2in9b_V3, EPD_loadA, 0x13, EPD_loadA, EPD_showC, "2.9 inch B V3" },// 30 + { EPD_1IN54B_V2_Init, EPD_loadA, 0x26, EPD_loadAFilp, EPD_1IN54B_V2_Show, "1.54 inch B V2"},// 31 + { EPD_2IN13B_V3_Init, EPD_loadA, 0x13, EPD_loadA, EPD_2IN13B_V3_Show, "2.13 inch B V3"},// 32 + { EPD_Init_2in9_V2, EPD_loadA, -1, 0, EPD_2IN9_V2_Show, "2.9 inch V2" },// 33 + { EPD_Init_4in2b_V2, EPD_loadA, 0x13, EPD_loadA, EPD_4IN2B_V2_Show, "4.2 inch B V2" },// 34 + { EPD_2IN66B_Init, EPD_loadA, 0x26, EPD_loadAFilp, EPD_2IN66_Show, "2.66 inch B" },// 35 + { EPD_Init_5in83_V2, EPD_loadAFilp, -1, 0, EPD_showC, "5.83 inch V2" },// 36 + { EPD_4IN01F_init, EPD_loadG, -1, 0, EPD_4IN01F_Show, "4.01 inch F" },// 37 + { EPD_Init_2in7b_V2, EPD_loadA, 0x26, EPD_loadAFilp, EPD_2in7b_V2_Show, "2.7 inch B V2" },// 38 + { EPD_Init_2in13_V3, EPD_loadC, -1, 0, EPD_2IN13_V3_Show, "2.13 inch V3" },// 39 + { EPD_2IN13B_V4_Init, EPD_loadA, 0x26, EPD_loadA, EPD_2IN13B_V4_Show, "2.13 inch B V4"},// 40 + { EPD_3IN52_Init, EPD_loadA, -1, 0, EPD_3IN52_Show, "3.52 inch" },// 41 + { EPD_2IN7_V2_Init, EPD_loadA, -1 , 0, EPD_2IN7_V2_Show, "2.7 inch V2" },// 42 + { EPD_7IN3F_init, EPD_loadG, -1 , 0, EPD_7IN3F_Show, "7.3 inch F" },// 43 + { EPD_12in48B_Init, NULL, 0x13, NULL, EPD_12in48B_Show, "12.48 inch B V1" },// 44 + { EPD_9IN7G_init, EPD_loadA, -1 , 0, EPD_9IN7G_Show, "9.7 inch G" },// 45 + { EPD_9IN69B_Init, EPD_loadA, -1 , EPD_loadAFilp, EPD_9IN69B_Show, "9.69 inch B" },// 46 + { EPD_7IN3E_init, EPD_loadG, -1 , 0, EPD_7IN3E_Show, "7.3 inch E" },// 47 +}; diff --git a/src/epd_driver/epd.h b/src/epd_driver/epd.h new file mode 100644 index 0000000..bd03113 --- /dev/null +++ b/src/epd_driver/epd.h @@ -0,0 +1,126 @@ +/** + ****************************************************************************** + * @file epd.h + * @author Waveshare Team + * @version V1.0.0 + * @date 23-January-2018 + * @brief This file provides e-Paper driver functions + * void EPD_SendCommand(byte command); + * void EPD_SendData(byte data); + * void EPD_WaitUntilIdle(); + * void EPD_Send_1(byte c, byte v1); + * void EPD_Send_2(byte c, byte v1, byte v2); + * void EPD_Send_3(byte c, byte v1, byte v2, byte v3); + * void EPD_Send_4(byte c, byte v1, byte v2, byte v3, byte v4); + * void EPD_Send_5(byte c, byte v1, byte v2, byte v3, byte v4, byte v5); + * void EPD_Reset(); + * void EPD_dispInit(); + * + * varualbes: + * EPD_dispLoad; - pointer on current loading function + * EPD_dispIndex; - index of current e-Paper + * EPD_dispInfo EPD_dispMass[]; - array of e-Paper properties + * + ****************************************************************************** + */ +#ifndef EPD_H_ +#define EPD_H_ +// #include "epd_wifi.h" +#include + +void EPD_SPISetCfg( + int din, + int sck, + int cs, + int dc, + int rst, + int busy +); +void EPD_initSPI(); + +/* The procedure of sending a byte to e-Paper by SPI -------------------------*/ +void EpdSpiTransferCallback(byte data); + +/* Sending a byte as a command -----------------------------------------------*/ +void EPD_SendCommand(byte command); + +/* Sending a byte as a data --------------------------------------------------*/ +void EPD_SendData(byte data); + +/* Waiting the e-Paper is ready for further instructions ---------------------*/ +void EPD_WaitUntilIdle(); + +/* Waiting the e-Paper is ready for further instructions ---------------------*/ +void EPD_WaitUntilIdle_high(); + +/* Send a one-argument command -----------------------------------------------*/ +void EPD_Send_1(byte c, byte v1); + +/* Send a two-arguments command ----------------------------------------------*/ +void EPD_Send_2(byte c, byte v1, byte v2); + +/* Send a three-arguments command --------------------------------------------*/ +void EPD_Send_3(byte c, byte v1, byte v2, byte v3); + +/* Send a four-arguments command ---------------------------------------------*/ +void EPD_Send_4(byte c, byte v1, byte v2, byte v3, byte v4); + +/* Send a five-arguments command ---------------------------------------------*/ +void EPD_Send_5(byte c, byte v1, byte v2, byte v3, byte v4, byte v5); + +/* Writting lut-data into the e-Paper ----------------------------------------*/ +void EPD_lut(byte c, byte l, byte*p); + +/* Writting lut-data of the black-white channel ------------------------------*/ +void EPD_SetLutBw(byte*c20, byte*c21, byte*c22, byte*c23, byte*c24); + +/* Writting lut-data of the red channel --------------------------------------*/ +void EPD_SetLutRed(byte*c25, byte*c26, byte*c27); + +/* This function is used to 'wake up" the e-Paper from the deep sleep mode ---*/ +void EPD_Reset(); + +/* Image data loading function for a-type e-Paper ----------------------------*/ +void EPD_loadA(); +void EPD_loadAFilp(); + +/* Image data loading function for b-type e-Paper ----------------------------*/ +void EPD_loadB(); + +/* Image data loading function for 2.13 e-Paper ------------------------------*/ +void EPD_loadC(); + +/* Image data loading function for 7.5 e-Paper -------------------------------*/ +void EPD_loadD(); +/* Image data loading function for 7.5b e-Paper ------------------------------*/ +void EPD_loadE(); + +/* Image data loading function for 5.83b e-Paper -----------------------------*/ +void EPD_loadF(); +/* Image data loading function for 5.65f e-Paper -----------------------------*/ +void EPD_loadG(); + +/* Show image and turn to deep sleep mode (a-type, 4.2 and 2.7 e-Paper) ------*/ +void EPD_showA(); + +/* Show image and turn to deep sleep mode (b-type, e-Paper) ------------------*/ +void EPD_showB(); + +/* Show image and turn to deep sleep mode (7.5 and 7.5b e-Paper) -------------*/ +void EPD_showC(); + +/* Show image and turn to deep sleep mode (2.13 e-Paper) ---------------------*/ +void EPD_showD(); + +/* Initialization of an e-Paper ----------------------------------------------*/ +void EPD_dispInit(); + +bool Srvr__loop(); +bool Srvr__init(); + +void Srvr__rcvProc(); +void Srvr__postProc(); + +void reboot_device(); + +#endif /* EPD_H_ */ \ No newline at end of file diff --git a/src/epd_driver/epd_bt.cpp b/src/epd_driver/epd_bt.cpp new file mode 100644 index 0000000..1a1cb6e --- /dev/null +++ b/src/epd_driver/epd_bt.cpp @@ -0,0 +1,346 @@ +#include "freertos/FreeRTOS.h" +#include "freertos/queue.h" +#include "freertos/task.h" +#include "esp_task_wdt.h" + +#include "buff/buff.h" +#include "epd_conf.h" +#include "epd.h" +#include "config/ble_config.h" +#include "epd_bt.h" + +EPDBt myEPDBt; +QueueHandle_t btQueue; +TaskHandle_t btTask; + +bt_data_t btInBuf; +bt_data_t btOutBuf; + +/* Image data loading function for a-type e-Paper ----------------------------*/ +void EPDBt::EPD_loadA() +{ + if (is_compress) { + EPD_loadCompressA(false); + } else { + EPD_loadUncompressA(false); + } + return; +} + +void EPDBt::EPD_loadAFilp() +{ + if (is_compress) { + EPD_loadCompressA(true); + } else { + EPD_loadUncompressA(true); + } + return; +} + +/* Image data loading function for 5.65f e-Paper -----------------------------*/ +void EPDBt::EPD_loadG() +{ + if (is_compress) { + EPD_loadCompressG(false); + } else { + EPD_loadUncompressG(false); + } + return; +} + + +void EPDBt::msgProc() { + + char *pBuf = btOutBuf.Buff__bufArr; + int data_len = btOutBuf.data_len; + + int width = 0; + int height = 0; + + // Initialization + if (pBuf[0] == 'I' && data_len == 13) + { + // config load mode + loadMode = LOAD_MODE_BT; + + // Getting of e-Paper's type + // 1 -> index + EPD_dispIndex = pBuf[1]; + + // 2 -> is_compress + if (pBuf[2] != 0) { + is_compress = true; + } else { + is_compress = false; + } + + Serial.printf("is_compress: %d\n", is_compress); + // Print log message: initialization of e-Paper (e-Paper's type) + Serial.printf("<< spi pin + if (data_len > 3) { + EPD_SPISetCfg(pBuf[3], pBuf[4], pBuf[5], pBuf[6], pBuf[7], pBuf[8]); + width = (pBuf[9] << 8) + pBuf[10]; + height = (pBuf[11] << 8) + pBuf[12]; + Serial.printf("width=%d, height=%d\n", width, height); + } + EPD_initSPI(); + + // alloc image buffer + if (rcv_image_data == NULL) { + rcv_image_data = (uint8_t*)malloc(width*height); + image_data = (uint8_t*)malloc(width*height*2); + if (rcv_image_data == NULL || image_data == NULL) { + Serial.println("malloc failed."); + exit(-1); + } + Serial.printf("rcv_image_data=%p, image_data=%p\n", rcv_image_data, image_data); + } + rcv_image_data_size = 0; + image_data_size = 0; + + esp_gap_conn_params_t connParams; + esp_ble_conn_update_params_t updateParams; + memcpy(updateParams.bda, connectedAddress, sizeof(esp_bd_addr_t)); + updateParams.min_int = 6; + updateParams.max_int = 6; + updateParams.latency = 0; + updateParams.timeout = 500; + esp_ble_gap_update_conn_params(&updateParams); + + esp_ble_get_current_conn_params(connectedAddress, &connParams); + Serial.printf("interval=%d, latency=%d, timeout=%d\n", connParams.interval, connParams.latency, connParams.timeout); + + // Initialization + EPD_dispInit(); + } + + // Loading of pixels' data + else if (pBuf[0] == 'L' && data_len == 1) + { + // Print log message: image loading + Serial.print("<<(); + Serial.println("CMD: " + cmd_type); + if (cmd_type == "reboot_device") { + reboot_device(); + } else { + Serial.println("unknown command - failed!>>>"); + } + } + } else { + if (!load_stage) { + Serial.print("unknown header - failed!>>>"); + } else { + Serial.printf("."); + // Load data into the e-Paper + // if there is loading function for current channel (black or red) + memcpy(&rcv_image_data[rcv_image_data_size], pBuf, data_len); + rcv_image_data_size += (data_len); + } + } + + Buff__bufInd = 0; +} + +// process msg +void btRcvTask(void *pvParameters) { + while (1) { + xQueueReceive(btQueue, &btOutBuf, portMAX_DELAY); + + myEPDBt.msgProc(); + + esp_task_wdt_reset(); + } + +} + +bool EPDBt::Srvr__init() { + int queLen = 100; + + btQueue = xQueueCreate(queLen, sizeof(bt_data_t)); + + xTaskCreate(btRcvTask, "BT_RCV", 20480, NULL, tskIDLE_PRIORITY, &btTask); + + return true; +} + +// Type A: each value represents 8 pixels +void EPDBt::EPD_loadCompressA(bool flip) { + int pos = 0; + // Enumerate all of image data + for (pos = 0; pos < image_data_size; pos++) + { + // Get current byte + // int value = Buff__getByte(pos); + int value = image_data[pos]; + + // Invert byte's bits in case of '2.7' e-Paper + if (EPD_invert) value = ~value; + + // Write the byte into e-Paper's + // if (next_stage && (EPD_dispMass[EPD_dispIndex].chBk != EPD_dispMass[EPD_dispIndex].chRd)) { + if (flip) { + EPD_SendData(~(byte)value); + } else { + EPD_SendData((byte)value); + } + } +} + +void EPDBt::EPD_loadUncompressA(bool flip) { + int pos = 0; + // Enumerate all of image data + for (pos = 0; pos < rcv_image_data_size; pos++) + { + // Get current byte + // int value = Buff__getByte(pos); + int value = rcv_image_data[pos]; + + // Invert byte's bits in case of '2.7' e-Paper + if (EPD_invert) value = ~value; + + // Write the byte into e-Paper's + if (flip) { + EPD_SendData(~(byte)value); + } else { + EPD_SendData((byte)value); + } + } +} + +// Type G: each value represents 2 pixels +void EPDBt::EPD_loadCompressG(bool flip) { + int pos = 0; + // Enumerate all of image data + for (pos = 0; pos < image_data_size; pos++) + { + // Get current byte + // int value = Buff__getByte(pos); + int value = image_data[pos]; + + // Switch the positions of the two 4-bits pixels + // Black:0b000;White:0b001;Green:0b010;Blue:0b011;Red:0b100;Yellow:0b101;Orange:0b110; + int A = (value ) & 0x07; + int B = (value >> 4) & 0x07; + + // Write the data into e-Paper's memory + EPD_SendData((byte)(A << 4) + B); + } +} + +void EPDBt::EPD_loadUncompressG(bool flip) { + int pos = 0; + // Enumerate all of image data + for (pos = 0; pos < rcv_image_data_size; pos++) + { + // Get current byte + // int value = Buff__getByte(pos); + int value = rcv_image_data[pos]; + + // Switch the positions of the two 4-bits pixels + // Black:0b000;White:0b001;Green:0b010;Blue:0b011;Red:0b100;Yellow:0b101;Orange:0b110; + int A = (value ) & 0x07; + int B = (value >> 4) & 0x07; + + // Write the data into e-Paper's memory + EPD_SendData((byte)(A << 4) + B); + } +} + +void EPDBt::EPD_loadCompress(bool flip) { + if (EPD_dispIndex == 43) { + EPD_loadCompressG(flip); + } else { + EPD_loadCompressA(flip); + } +} + +void EPDBt::EPD_loadUncompress(bool flip) { + if (EPD_dispIndex == 43) { + EPD_loadUncompressG(flip); + } else { + EPD_loadUncompressA(flip); + } +} + +void EPDBt::Srvr__rcvProc() { + memcpy(btInBuf.Buff__bufArr, Buff__bufArr, Buff__bufInd); + btInBuf.data_len = Buff__bufInd; + + xQueueSend(btQueue, &btInBuf, portMAX_DELAY); + + return; +} \ No newline at end of file diff --git a/src/epd_driver/epd_bt.h b/src/epd_driver/epd_bt.h new file mode 100644 index 0000000..2271756 --- /dev/null +++ b/src/epd_driver/epd_bt.h @@ -0,0 +1,42 @@ +#ifndef EPD_BT_H_ +#define EPD_BT_H_ + +#include "Arduino.h" +#include +#include + +#define BT_BUFFER_SIZE 512 + +// define bluetooth async data structure +typedef struct { + int data_len; + char Buff__bufArr[BT_BUFFER_SIZE]; +} bt_data_t; + +class EPDBt { +public: + + void EPD_loadA(); + void EPD_loadAFilp(); + void EPD_loadG(); + + void EPD_loadCompress(bool flip); + void EPD_loadCompressA(bool flip); + void EPD_loadCompressG(bool flip); + + void EPD_loadUncompress(bool flip); + void EPD_loadUncompressA(bool flip); + void EPD_loadUncompressG(bool flip); + + void Srvr__rcvProc(); + bool Srvr__init(); + void msgProc(); + +private: + +}; // class EPDBt + +extern EPDBt myEPDBt; + + +#endif \ No newline at end of file diff --git a/src/epd_driver/epd_conf.h b/src/epd_driver/epd_conf.h new file mode 100644 index 0000000..a6f9917 --- /dev/null +++ b/src/epd_driver/epd_conf.h @@ -0,0 +1,75 @@ +#ifndef EPD_CONF_H_ +#define EPD_CONF_H_ + +#include + +/* SPI pin definition --------------------------------------------------------*/ +#define DEFAULT_PIN_SPI_SCK 13 +#define DEFAULT_PIN_SPI_DIN 14 +#define DEFAULT_PIN_SPI_CS 15 +#define DEFAULT_PIN_SPI_BUSY 25//19 +#define DEFAULT_PIN_SPI_RST 26//21 +#define DEFAULT_PIN_SPI_DC 27//22 + +/* Pin level definition ------------------------------------------------------*/ +#define GPIO_PIN_SET 1 +#define GPIO_PIN_RESET 0 + +#define UBYTE uint8_t +#define UWORD uint16_t +#define UDOUBLE uint32_t + +#define LOAD_MODE_BT 1 +#define LOAD_MODE_WIFI 2 + +/* The set of pointers on 'init', 'load' and 'show' functions, title and code */ +struct EPD_dispInfo +{ + int(*init)(); // Initialization + void(*chBk)();// Black channel loading + int next; // Change channel code + void(*chRd)();// Red channel loading + void(*show)();// Show and sleep + char*title; // Title of an e-Paper +}; + +extern int loadMode; + +extern bool EPD_invert; // If true, then image data bits must be inverted +extern int EPD_dispIndex; // The index of the e-Paper's type +extern int EPD_dispX, EPD_dispY; // Current pixel's coordinates (for 2.13 only) +extern void(*EPD_dispLoad)(); // Pointer on a image data writting function + +extern EPD_dispInfo EPD_dispMass[]; + +extern bool is_compress; +extern uint8_t *rcv_image_data; +extern uint32_t rcv_image_data_size; +extern uint8_t *image_data; +extern uint32_t image_data_size; +extern bool load_stage; +extern bool next_stage; + +extern int PIN_SPI_SCK; +extern int PIN_SPI_DIN; +extern int PIN_SPI_CS; +extern int PIN_SPI_BUSY; +extern int PIN_SPI_RST; +extern int PIN_SPI_DC; + +// /* Lut mono ------------------------------------------------------------------*/ +extern byte lut_full_mono[]; +extern byte lut_partial_mono[]; + +extern byte lut_vcom0[]; +extern byte lut_w []; +extern byte lut_b []; +extern byte lut_g1 []; +extern byte lut_g2 []; +extern byte lut_vcom1[]; +extern byte lut_red0 []; +extern byte lut_red1 []; + +void decompress_image_data(); + +#endif \ No newline at end of file diff --git a/src/epd_driver/epd_wifi.cpp b/src/epd_driver/epd_wifi.cpp new file mode 100644 index 0000000..7e0eefc --- /dev/null +++ b/src/epd_driver/epd_wifi.cpp @@ -0,0 +1,532 @@ + +#include + +#include "freertos/FreeRTOS.h" +#include "freertos/queue.h" +#include "freertos/task.h" +#include "esp_task_wdt.h" + +#include "epd_conf.h" +#include "epd.h" +#include "buff/buff_wifi.h" + +#include "epd_wifi.h" + +EPDWifi myEPDWifi; + +// cost time record +int start_time = -1; +int end_time = -1; +int last_time = 0; + +int loaded_size = 0; +int bw_loaded_index = 0; +int r_loaded_index = 0; +bool cmd_s2 = false; + +bool EPDWifi::Srvr__loop() +{ + server.handleClient(); + return true; +} + +/* Reads a word from the buffer at specified position ------------------------*/ +int EPDWifi::Buff__getByte(char* pBuf, int index) +{ + // The first and second characters of the byte stored in the buffer + // are supposed to be in range ['a'; 'p'], otherwise it isn't a image data's byte + if ((pBuf[index ] < 'a') || (pBuf[index ] > 'p')) return -1; + if ((pBuf[index + 1] < 'a') || (pBuf[index + 1] > 'p')) return -1; + + // The character 'a' means 0, the character 'p' means 15 consequently, + // The 1st character describes 4 low bits if the byte and the 2nd one - 4 high bits + return ((int)pBuf[index] - 'a') + (((int)pBuf[index + 1] - 'a') << 4); +} + +// A类型,每个value代表8个像素 +void EPDWifi::EPD_loadCompressA(char* pBuf) { + int pos = 0; + int buf_size = strlen(pBuf); + Serial.printf("buf_size=%d, next_stage=%d\n", buf_size, next_stage); + // Enumerate all of image data bytes + while (pos < buf_size) + { + // Get current byte + int value = Buff__getByte(pBuf, pos); + // Invert byte's bits in case of '2.7' e-Paper + if (EPD_invert) value = ~value; + + // Write the byte into e-Paper's memory + if (next_stage && (EPD_dispMass[EPD_dispIndex].chBk != EPD_dispMass[EPD_dispIndex].chRd)) { + EPD_SendData(~(byte)value); + } else { + EPD_SendData((byte)value); + } + + // Increment the current byte index on 2 characters + pos += 2; + } +} + +// A类型,每个value代表8个像素 +void EPDWifi:: EPD_loadCompressA2(char* pBuf) { + int pos = 0; + int x = 0; + int y = 0; + int pixel_index = 0; + int buf_size = strlen(pBuf); + Serial.println("EPD_loadCompressA2"); + Serial.printf("buf_size=%d, loaded_size=%d, next_stage=%d\n", buf_size, loaded_size, next_stage); + + return; + // Enumerate all of image data bytes + while (pos < buf_size) + { + // 计算像素点对应的坐标(x,y),判断落在哪个区域 + pixel_index = (pos + loaded_size) * 8 / 2; + x = pixel_index % EPD_12IN48B_WIDTH; + y = pixel_index / EPD_12IN48B_WIDTH; + + // Get current byte + int value = Buff__getByte(pBuf, pos); + // Invert byte's bits in case of '2.7' e-Paper + if (EPD_invert) value = ~value; + + + // 非等分... + if (x < 648 && y < EPD_12IN48B_HEIGHT/2) { + // Write the byte into e-Paper's memory + if (cmd_s2 != true) { + EPD_12in48B_cmd1S2(); + cmd_s2 = true; + } + if (next_stage && (EPD_dispMass[EPD_dispIndex].chBk != EPD_dispMass[EPD_dispIndex].chRd)) { + EPD_12in48B_data1S2(~(byte)value); + } else { + EPD_12in48B_data1S2((byte)value); + } + } + + // Increment the current byte index on 2 characters + pos += 2; + } + + loaded_size += buf_size; +} + +// G类型,每个vanlue代表2个像素 +void EPDWifi::EPD_loadCompressG(char* pBuf) { + int pos = 0; + int buf_size = strlen(pBuf); + // Enumerate all of image data + while (pos < buf_size) + { + // Get current byte + int value = Buff__getByte(pBuf, pos); + // int value = pBuf[pos]; + + // Switch the positions of the two 4-bits pixels + // Black:0b000;White:0b001;Green:0b010;Blue:0b011;Red:0b100;Yellow:0b101;Orange:0b110; + int A = (value ) & 0x07; + int B = (value >> 4) & 0x07; + + // Write the data into e-Paper's memory + EPD_SendData((byte)(A << 4) + B); + + pos += 2; + } +} + +void EPDWifi::EPD_loadCompress(char* pBuf) { + if (EPD_dispIndex == 43) { // 7.3f + EPD_loadCompressG(pBuf); + } else if (EPD_dispIndex == 44) { // 12.48b + EPD_loadCompressA2(pBuf); + } else { + EPD_loadCompressA(pBuf); + } +} + +void EPDWifi::msgProc(char* pBuf) { + if (0 == strncmp(pBuf, "NEXT", sizeof("NEXT"))) { + + end_time = millis(); + Serial.printf("----%dms----\n", end_time - last_time - start_time); + last_time = end_time - start_time; + + Serial.println("NEXT"); + + next_stage = true; + + // Instruction code for for writting data into + // e-Paper's memory + int code = EPD_dispMass[EPD_dispIndex].next; + + // If the instruction code isn't '-1', then... + if (code != -1) { + // Print log message: instruction code + Serial.printf(" %d", code); + + // Do the selection of the next data channel + if (EPD_dispIndex == 44) { + Serial.println("12.48 next"); + // EPD_SendCommand(code); + } else { + EPD_SendCommand(code); + } + delay(2); + } + + // Setup the function for loading choosen channel's data + EPD_dispLoad = EPD_dispMass[EPD_dispIndex].chRd; + + loaded_size = 0; + } else if (0 == strncmp(pBuf, "SHOW", sizeof("SHOW"))) { + + end_time = millis(); + Serial.printf("----%dms----\n", end_time - last_time - start_time); + last_time = end_time - start_time; + + Serial.print("<<(), document["height"].as()); + } + + // Print log message: initialization of e-Paper (e-Paper's type) + Serial.printf("EPD_dispIndex %d", EPD_dispIndex); + Serial.printf("EPD %s", EPD_dispMass[EPD_dispIndex].title); + + // Initialization + EPD_dispInit(); + + loaded_size = 0; + bw_loaded_index = 0; + r_loaded_index = 0; + cmd_s2 = false; + + end_time = millis(); + Serial.printf("----%dms----\n", end_time - last_time - start_time); + last_time = end_time - start_time; +} + +void EPDWifi::EPD_12in48B_loadA(String image_data) { + UDOUBLE index = 0; + while (index < image_data.length()) { + // Get current byte + int value = ((((int)image_data[index] - 'a') << 4) + (((int)image_data[index + 1] - 'a') & 0x0f)); + // total resolution 1304 * 984 + // devided into 4 parts: (648*492 + 656*492 + 656*492 + 648*492) + // according index within range, use different cmd + if(bw_loaded_index == 0){ // 162 * 492 / 2 + Serial.println("12.48inch e-Paper B LoadA S2"); + EPD_12in48B_cmd1S2(); + }else if(bw_loaded_index == 39852){ // 164 * 492 / 2, = 492 * (648/8) + Serial.println("12.48inch e-Paper B LoadA M2"); + EPD_12in48B_cmd1M2(); + }else if(bw_loaded_index == 80196){ // 162 * 492 / 2, = 492 * (656/8) + Serial.println("12.48inch e-Paper B LoadA M1"); + EPD_12in48B_cmd1M1(); + }else if(bw_loaded_index == 120048){ // 164 * 492 / 2 + Serial.println("12.48inch e-Paper B LoadA S1"); + EPD_12in48B_cmd1S1(); + } + + if(bw_loaded_index < 39852){ + EPD_12in48B_data1S2((byte)value); + }else if(bw_loaded_index < 80196 && bw_loaded_index >= 39852){ + EPD_12in48B_data1M2((byte)value); + }else if(bw_loaded_index < 120048 && bw_loaded_index >= 80196){ + EPD_12in48B_data1M1((byte)value); + }else if(bw_loaded_index >= 120048){ + EPD_12in48B_data1S1((byte)value); + } + + // Increment the current byte index on 2 characters + index += 2; + bw_loaded_index++; + } +} + +void EPDWifi::EPD_9IN69B_loadA(String image_data) { + UDOUBLE index = 0; + while (index < image_data.length()) { + // Get current byte + int value = ((((int)image_data[index] - 'a') << 4) + (((int)image_data[index + 1] - 'a') & 0x0f)); + value = ~value; + // total resolution 960 * 672 + // devided into 2 parts: 480 * 672 + 480 * 672 + // total data num: 960*672 * 2 / 8 = 161280 + // each parts has data num:161280 / 2 = 80640 + // pixels seperated line: 80640 / 2 = 40320 + // according index within range, use different cmd + if(bw_loaded_index == 0){ + Serial.println("9.69inch e-Paper B LoadA Master"); + EPD_9IN69B_Prepare(); + EPD_9IN69B_SendCommandM(0x12); + EPD_9IN69B_SendDataM(0x3b); + EPD_9IN69B_SendDataM(0x00); + EPD_9IN69B_SendDataM(0x14); + //First frame for Master + EPD_9IN69B_SendCommandM(0x10); + }else if(bw_loaded_index == 40320){ + Serial.println("12.48inch e-Paper B LoadA Slave"); + EPD_9IN69B_SendCommandS(0x12); + EPD_9IN69B_SendDataS(0x3b); + EPD_9IN69B_SendDataS(0x00); + EPD_9IN69B_SendDataS(0x14); + //First frame for Slave + EPD_9IN69B_SendCommandS(0x10); + } + + if(bw_loaded_index < 40320){ + EPD_9IN69B_SendDataM((byte)value); + } else { + EPD_9IN69B_SendDataS((byte)value); + } + + // Increment the current byte index on 2 characters + index += 2; + bw_loaded_index++; + } +} + +void EPDWifi::Web_EPD_LoadA(String arg_info) { + Serial.print("L>"); + + String image_data = arg_info; + Buff__bufInd = image_data.length(); + memset(Buff__bufArr, 0, Buff__bufInd); + memcpy(Buff__bufArr, image_data.c_str(), Buff__bufInd); + Buff__bufArr[Buff__bufInd] = '\0'; + + loaded_size += Buff__bufInd; + Serial.printf("Buff__bufInd=%d, loaded_size=%d\n", Buff__bufInd, loaded_size); + + Serial.println("LOADA"); + + // 12.48 & 9.69 use specific pins initialization + if (EPD_dispIndex == 44) { + return EPD_12in48B_loadA(image_data); + } else if (EPD_dispIndex == 46) { + return EPD_9IN69B_loadA(image_data); + } + + EPD_dispLoad(); +} + +void EPDWifi::EPD_12in48B_loadB(String image_data) { + UDOUBLE index = 0; + while (index < image_data.length()) { + // Get current byte + int value = ((((int)image_data[index] - 'a') << 4) + (((int)image_data[index + 1] - 'a') & 0x0f)); + + if(r_loaded_index == 0){ // 162 * 492 / 2 + Serial.println("Web_EPD_LoadB 0"); + EPD_12in48B_cmd2S2(); + }else if(r_loaded_index == 39852){ // 164 * 492 / 2 + Serial.println("Web_EPD_LoadB 2"); + EPD_12in48B_cmd2M2(); + }else if(r_loaded_index == 80196){ // 162 * 492 / 2 + Serial.println("Web_EPD_LoadB 6"); + EPD_12in48B_cmd2M1(); + }else if(r_loaded_index == 120048){ // 164 * 492 / 2 + Serial.println("Web_EPD_LoadB 8"); + EPD_12in48B_cmd2S1(); + } + + if(r_loaded_index < 39852){ + EPD_12in48B_data2S2((byte)value); + }else if(r_loaded_index < 80196 && r_loaded_index >= 39852){ + EPD_12in48B_data2M2((byte)value); + }else if(r_loaded_index < 120048 && r_loaded_index >= 80196){ + EPD_12in48B_data2M1((byte)value); + }else if(r_loaded_index >= 120048){ + EPD_12in48B_data2S1((byte)value); + } + + // Increment the current byte index on 2 characters + index += 2; + r_loaded_index++; + } +} + +void EPDWifi::EPD_9IN69B_loadB(String image_data) { + UDOUBLE index = 0; + while (index < image_data.length()) { + // Get current byte + int value = ((((int)image_data[index] - 'a') << 4) + (((int)image_data[index + 1] - 'a') & 0x0f)); + value = ~value; + // total resolution 960 * 672 + // devided into 2 parts: 480 * 672 + 480 * 672 + // total data num: 960*672 * 2 / 8 = 161280 + // each parts has data num:161280 / 2 = 80640 + // pixels seperated line: 80640 / 2 = 40320 + // according index within range, use different cmd + if(r_loaded_index == 0){ + Serial.println("9.69inch e-Paper B LoadB Master"); + // RAM_RW for Master + EPD_9IN69B_Prepare(); + EPD_9IN69B_SendCommandM(0x12); + EPD_9IN69B_SendDataM(0x3b); + EPD_9IN69B_SendDataM(0x00); + EPD_9IN69B_SendDataM(0x14); + //Second frame for Master + EPD_9IN69B_SendCommandM(0x11); + }else if(r_loaded_index == 40320){ + Serial.println("12.48inch e-Paper B LoadB Slave"); + // RAM_RW for Slave + EPD_9IN69B_SendCommandS(0x12); + EPD_9IN69B_SendDataS(0x3b); + EPD_9IN69B_SendDataS(0x00); + EPD_9IN69B_SendDataS(0x14); + //Second frame for Slave + EPD_9IN69B_SendCommandS(0x11); + } + + if(r_loaded_index < 40320){ + EPD_9IN69B_SendDataM((byte)value); + } else { + EPD_9IN69B_SendDataS((byte)value); + } + + // Increment the current byte index on 2 characters + index += 2; + r_loaded_index++; + } +} + +void EPDWifi::Web_EPD_LoadB(String arg_info) { + Serial.print("L>"); + + String image_data = arg_info; + Buff__bufInd = image_data.length(); + + memset(Buff__bufArr, 0, Buff__bufInd); + memcpy(Buff__bufArr, image_data.c_str(), Buff__bufInd); + Buff__bufArr[Buff__bufInd] = '\0'; + loaded_size += Buff__bufInd; + Serial.printf("Buff__bufInd=%d, loaded_size=%d\n", Buff__bufInd, loaded_size); + + Serial.println("LOADB"); + + // 12.48 & 9.69 use specific pins initialization + if (EPD_dispIndex == 44) { + return EPD_12in48B_loadB(image_data); + } else if (EPD_dispIndex == 46) { + return EPD_9IN69B_loadB(image_data); + } + + + // change to next + if (next_stage != true) { + next_stage = true; + + // next + int code = EPD_dispMass[EPD_dispIndex].next; + + // If the instruction code isn't '-1', then... + if (code != -1) { + // Print log message: instruction code + Serial.printf(" %d", code); + + // Do the selection of the next data channel + EPD_SendCommand(code); + delay(2); + } + + // Setup the function for loading choosen channel's data + EPD_dispLoad = EPD_dispMass[EPD_dispIndex].chRd; + + loaded_size = 0; + } + + EPD_dispLoad(); +} + +void EPDWifi::Web_EPD_Show() { + end_time = millis(); + Serial.printf("----%dms----\n", end_time - last_time - start_time); + last_time = end_time - start_time; + + Serial.print("<< + +#include + +#define WIFI_BUFFER_SIZE 2048 + +// 定义结构体类型 +typedef struct { + int data_len; + char Buff__bufArr[WIFI_BUFFER_SIZE]; +} wifi_data_t; + +class EPDWifi { +public: + void EPD_12in48B_loadA(String image_data); + void EPD_12in48B_loadB(String image_data); + + void EPD_9IN69B_loadA(String image_data); + void EPD_9IN69B_loadB(String image_data); + + void Web_EPD_Init(String arg_info); + void Web_EPD_LoadA(String arg_info); + void Web_EPD_LoadB(String arg_info); + void Web_EPD_Show(); + + void EPD_loadCompress(char* pBuf); + void EPD_loadCompressA(char* pBuf); + void EPD_loadCompressA2(char* pBuf); + void EPD_loadCompressG(char* pBuf); + int Buff__getByte(char* pBuf, int index); + + bool Srvr__loop(); + + bool Srvr__init(); + void Srvr__postProc(); + void msgProc(char* pBuf); +private: + +}; // class EPDWifi + +extern EPDWifi myEPDWifi; + +/* Server and IP address ------------------------------------------------------*/ +// extern WiFiServer server; // Wifi server exemplar using port 80 +extern WebServer server; // Web server exemplar using port 80 +extern IPAddress myIP; // IP address in your local wifi net + + +#define EPD_12IN48B_WIDTH 1304 +#define EPD_12IN48B_HEIGHT 984 + +extern void EPD_12in48b_initSPI(void); +extern void EPD_12in48B_cmd1S2(void); +extern void EPD_12in48B_cmd1M2(void); +extern void EPD_12in48B_cmd1M1(void); +extern void EPD_12in48B_cmd1S1(void); +extern void EPD_12in48B_data1S2(UBYTE data); +extern void EPD_12in48B_data1M2(UBYTE data); +extern void EPD_12in48B_data1M1(UBYTE data); +extern void EPD_12in48B_data1S1(UBYTE data); +extern void EPD_12in48B_cmd2S2(void); +extern void EPD_12in48B_cmd2M2(void); +extern void EPD_12in48B_cmd2M1(void); +extern void EPD_12in48B_cmd2S1(void); +extern void EPD_12in48B_data2S2(UBYTE data); +extern void EPD_12in48B_data2M2(UBYTE data); +extern void EPD_12in48B_data2M1(UBYTE data); +extern void EPD_12in48B_data2S1(UBYTE data); + +extern void EPD_9IN69B_InitSPI(void); +extern void EPD_9IN69B_Prepare(); +extern void EPD_9IN69B_SendCommandM(UBYTE Reg); +extern void EPD_9IN69B_SendDataM(UBYTE Data); +extern void EPD_9IN69B_SendCommandS(UBYTE Reg); +extern void EPD_9IN69B_SendDataS(UBYTE Data); +#endif \ No newline at end of file diff --git a/src/epd_panel/EPD_12in48b.h b/src/epd_panel/EPD_12in48b.h new file mode 100644 index 0000000..c30777b --- /dev/null +++ b/src/epd_panel/EPD_12in48b.h @@ -0,0 +1,859 @@ +/***************************************************************************** +* | File : EPD_12in48b.c +* | Author : Waveshare team +* | Function : Electronic paper driver +* | Info : +*---------------- +* | This version: V1.0 +* | Date : 2018-11-29 +* | Info : +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documnetation files(the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +******************************************************************************/ +#ifndef _EPD_12IN48B_H +#define _EPD_12IN48B_H + +// use 14 pins, specially defined here +#define EPD_S1_BUSY_PIN 3 +#define EPD_MOSI_PIN 46 +#define EPD_S1_CS_PIN 9 +#define EPD_M1S1_DC_PIN 10 +#define EPD_M1S1_RST_PIN 11 +#define EPD_M1_BUSY_PIN 12 +#define EPD_M1_CS_PIN 13 + +#define EPD_S2_BUSY_PIN 14 +#define EPD_SCK_PIN 21 +#define EPD_M2_CS_PIN 47 +#define EPD_M2S2_DC_PIN 48 +#define EPD_M2S2_RST_PIN 45 +#define EPD_M2_BUSY_PIN 7 +#define EPD_S2_CS_PIN 6 + +/** + * GPIO read and write +**/ +#define DEV_Digital_Write(_pin, _value) digitalWrite(_pin, _value == 0? LOW:HIGH) +#define DEV_Digital_Read(_pin) digitalRead(_pin) + +static void EPD_12in48b_Reset(void); +static void EPD_M1_SendCommand(UBYTE Reg); +static void EPD_M1_SendData(UBYTE Data); +static void EPD_S1_SendCommand(UBYTE Reg); +static void EPD_S1_SendData(UBYTE Data); +static void EPD_M2_SendCommand(UBYTE Reg); +static void EPD_M2_SendData(UBYTE Data); +static void EPD_S2_SendCommand(UBYTE Reg); +static void EPD_S2_SendData(UBYTE Data); +static void EPD_M1M2_SendCommand(UBYTE Reg); +static void EPD_M1M2_SendData(UBYTE Data); +static void EPD_M1S1M2S2_SendCommand(UBYTE Reg); +static void EPD_M1S1M2S2_SendData(UBYTE Data); +static void EPD_M1_ReadBusy(void); +static void EPD_M2_ReadBusy(void); +static void EPD_S1_ReadBusy(void); +static void EPD_S2_ReadBusy(void); +static void EPD_M1_ReadTemperature(void); +static void EPD_12in48b_SetLut(void); +void EPD_12in48B_TurnOnDisplay(void); +void EPD_12in48B_Sleep(void); + +void EPD_12in48b_initSPI(void) +{ + Serial.println("EPD_12in48b_initSPI"); + // return; + // SPI + pinMode(EPD_SCK_PIN, OUTPUT); + pinMode(EPD_MOSI_PIN, OUTPUT); + + // GPIO + pinMode(EPD_M1_CS_PIN, OUTPUT); + pinMode(EPD_S1_CS_PIN, OUTPUT); + pinMode(EPD_M2_CS_PIN, OUTPUT); + pinMode(EPD_S2_CS_PIN, OUTPUT); + pinMode(EPD_M1S1_DC_PIN, OUTPUT); + pinMode(EPD_M2S2_DC_PIN, OUTPUT); + pinMode(EPD_M1S1_RST_PIN, OUTPUT); + pinMode(EPD_M2S2_RST_PIN, OUTPUT); + + pinMode(EPD_M1_BUSY_PIN, INPUT); + pinMode(EPD_S1_BUSY_PIN, INPUT); + pinMode(EPD_M2_BUSY_PIN, INPUT); + pinMode(EPD_S2_BUSY_PIN, INPUT); + + // Init + // CS: High代表非选中,Low代表选中 + DEV_Digital_Write(EPD_M1_CS_PIN, HIGH); + DEV_Digital_Write(EPD_S1_CS_PIN, HIGH); + DEV_Digital_Write(EPD_M2_CS_PIN, HIGH); + DEV_Digital_Write(EPD_S2_CS_PIN, HIGH); + DEV_Digital_Write(EPD_SCK_PIN, LOW); + + DEV_Digital_Write(EPD_SCK_PIN, 0); + DEV_Digital_Write(EPD_MOSI_PIN, 0); + DEV_Digital_Write(EPD_M1_CS_PIN, 0); + DEV_Digital_Write(EPD_S1_CS_PIN, 0); + DEV_Digital_Write(EPD_M2_CS_PIN, 0); + DEV_Digital_Write(EPD_S2_CS_PIN, 0); + DEV_Digital_Write(EPD_M1S1_DC_PIN, 0); + DEV_Digital_Write(EPD_M2S2_DC_PIN, 0); + DEV_Digital_Write(EPD_M1S1_RST_PIN, 0); + DEV_Digital_Write(EPD_M2S2_RST_PIN, 0); + DEV_Digital_Write(EPD_M1_BUSY_PIN, 0); + DEV_Digital_Write(EPD_S1_BUSY_PIN, 0); + DEV_Digital_Write(EPD_M2_BUSY_PIN, 0); + DEV_Digital_Write(EPD_S2_BUSY_PIN, 0); +} + +/****************************************************************************** +function : Initialize the e-Paper register +parameter: +******************************************************************************/ +int EPD_12in48B_Init(void) +{ + Serial.println("EPD_12in48B_Init"); + + UBYTE Version = 2; // The latest version is V2 + + EPD_12in48b_Reset(); + + // deselected 4 channels + DEV_Digital_Write(EPD_M1_CS_PIN, 1); + DEV_Digital_Write(EPD_S1_CS_PIN, 1); + DEV_Digital_Write(EPD_M2_CS_PIN, 1); + DEV_Digital_Write(EPD_S2_CS_PIN, 1); + + if(Version == 1) { + //panel setting + EPD_M1_SendCommand(0x00); + EPD_M1_SendData(0x2f); //KW-3f KWR-2F BWROTP 0f BWOTP 1f + EPD_S1_SendCommand(0x00); + EPD_S1_SendData(0x2f); + EPD_M2_SendCommand(0x00); + EPD_M2_SendData(0x23); + EPD_S2_SendCommand(0x00); + EPD_S2_SendData(0x23); + + // POWER SETTING + EPD_M1_SendCommand(0x01); + EPD_M1_SendData(0x07); + EPD_M1_SendData(0x17); //VGH=20V,VGL=-20V + EPD_M1_SendData(0x3F); //VDH=15V + EPD_M1_SendData(0x3F); //VDL=-15V + EPD_M1_SendData(0x0d); + EPD_M2_SendCommand(0x01); + EPD_M2_SendData(0x07); + EPD_M2_SendData(0x17); //VGH=20V,VGL=-20V + EPD_M2_SendData(0x3F); //VDH=15V + EPD_M2_SendData(0x3F); //VDL=-15V + EPD_M2_SendData(0x0d); + + // booster soft start + EPD_M1_SendCommand(0x06); + EPD_M1_SendData(0x17); //A + EPD_M1_SendData(0x17); //B + EPD_M1_SendData(0x39); //C + EPD_M1_SendData(0x17); + EPD_M2_SendCommand(0x06); + EPD_M2_SendData(0x17); + EPD_M2_SendData(0x17); + EPD_M2_SendData(0x39); + EPD_M2_SendData(0x17); + + //resolution setting + EPD_M1_SendCommand(0x61); + EPD_M1_SendData(0x02); + EPD_M1_SendData(0x88); //source 648 + EPD_M1_SendData(0x01); //gate 492 + EPD_M1_SendData(0xEC); + EPD_S1_SendCommand(0x61); + EPD_S1_SendData(0x02); + EPD_S1_SendData(0x90); //source 656 + EPD_S1_SendData(0x01); //gate 492 + EPD_S1_SendData(0xEC); + EPD_M2_SendCommand(0x61); + EPD_M2_SendData(0x02); + EPD_M2_SendData(0x90); //source 656 + EPD_M2_SendData(0x01); //gate 492 + EPD_M2_SendData(0xEC); + EPD_S2_SendCommand(0x61); + EPD_S2_SendData(0x02); + EPD_S2_SendData(0x88); //source 648 + EPD_S2_SendData(0x01); //gate 492 + EPD_S2_SendData(0xEC); + + EPD_M1S1M2S2_SendCommand(0x15); //DUSPI + EPD_M1S1M2S2_SendData(0x20); + + EPD_M1S1M2S2_SendCommand(0x30); // PLL + EPD_M1S1M2S2_SendData(0x08); + + EPD_M1S1M2S2_SendCommand(0x50); //Vcom and data interval setting + EPD_M1S1M2S2_SendData(0x31); + EPD_M1S1M2S2_SendData(0x07); + + EPD_M1S1M2S2_SendCommand(0x60);//TCON + EPD_M1S1M2S2_SendData(0x22); + + EPD_M1_SendCommand(0xE0); //POWER SETTING + EPD_M1_SendData(0x01); + EPD_M2_SendCommand(0xE0); //POWER SETTING + EPD_M2_SendData(0x01); + + EPD_M1S1M2S2_SendCommand(0xE3); + EPD_M1S1M2S2_SendData(0x00); + + EPD_M1_SendCommand(0x82); + EPD_M1_SendData(0x1c); + EPD_M2_SendCommand(0x82); + EPD_M2_SendData(0x1c); + + EPD_12in48b_SetLut(); + // EPD_M1_ReadTemperature(); + return 0; + } + else if(Version == 2) { + // panel setting for Display + // bit3: UD:Gate Scan Direction 0: Scan down; 1: Scan up(default) G0->G1 -> Gn-1 + // bit5: REG 0: LUT from OTP(default) + // bit4: KW/R 0: Pixel with B/W/R(default) + EPD_M1_SendCommand(0x00); + EPD_M1_SendData(0x0f); //KW-3f KWR-2F BWROTP 0f BWOTP 1f + EPD_S1_SendCommand(0x00); + EPD_S1_SendData(0x0f); + // bit2: SHL: Source shift direction 0: Shift left; 1: Shift right(default) + EPD_M2_SendCommand(0x00); + EPD_M2_SendData(0x03); + EPD_S2_SendCommand(0x00); + EPD_S2_SendData(0x03); + + // booster soft start + EPD_M1_SendCommand(0x06); + // Phase A/B + // bit[7:6] Soft start period of phase A. 00b: 10ms(default) + // bit[5:3] Driving strength of phase A. 010b: strength 3(default) + // bit[2:0] Minimum OFF time setting of GDR in phase A. 111b: 6.58uS(default) + EPD_M1_SendData(0x17); //A + EPD_M1_SendData(0x17); //B + // Phase C1 + // bit[5:3] Driving strength of phase C. 000b: strength 3(default) 111b: strength 8(strongest) + EPD_M1_SendData(0x39); //C + // Phase C2 + // bit[7] Booster phase-C2 enable 0:disable 1:enable + EPD_M1_SendData(0x17); + + + EPD_M2_SendCommand(0x06); + EPD_M2_SendData(0x17); + EPD_M2_SendData(0x17); + EPD_M2_SendData(0x39); + EPD_M2_SendData(0x17); + + //resolution setting + // total resolution: 1304 * 984 (0x518 * 0x3D8) + // devided into 4 parts: (648*492 + 656*492 + 656*492 + 648*492) + EPD_M1_SendCommand(0x61); + EPD_M1_SendData(0x02); + EPD_M1_SendData(0x88); //source 648 + EPD_M1_SendData(0x01); //gate 492 + EPD_M1_SendData(0xEC); + EPD_S1_SendCommand(0x61); + EPD_S1_SendData(0x02); + EPD_S1_SendData(0x90); //source 656 + EPD_S1_SendData(0x01); //gate 492 + EPD_S1_SendData(0xEC); + EPD_M2_SendCommand(0x61); + EPD_M2_SendData(0x02); + EPD_M2_SendData(0x90); //source 656 + EPD_M2_SendData(0x01); //gate 492 + EPD_M2_SendData(0xEC); + EPD_S2_SendCommand(0x61); + EPD_S2_SendData(0x02); + EPD_S2_SendData(0x88); //source 648 + EPD_S2_SendData(0x01); //gate 492 + EPD_S2_SendData(0xEC); + + // Dual SPI Mode + // bit[5]: MM_EN MM input pin definition enable(stack). 0: disable; 1: enable + // bit[4]: DUSPI_EN Dual SPI mode enable. 0: disable; 1: enable + EPD_M1S1M2S2_SendCommand(0x15); //DUSPI + EPD_M1S1M2S2_SendData(0x20); + + EPD_M1S1M2S2_SendCommand(0x50); //Vcom and data interval setting + EPD_M1S1M2S2_SendData(0x11); + EPD_M1S1M2S2_SendData(0x07); + + EPD_M1S1M2S2_SendCommand(0x60);//TCON + EPD_M1S1M2S2_SendData(0x22); + + EPD_M1S1M2S2_SendCommand(0xE3); + EPD_M1S1M2S2_SendData(0x00); + + // read M1 temperature + EPD_M1_ReadTemperature(); + + return 0; + } +} + +/****************************************************************************** +function : Clear screen +parameter: +******************************************************************************/ +void EPD_12in48B_Clear(void) +{ + UWORD y, x; + + // M1 part 648*492 + EPD_M1_SendCommand(0x10); + for(y = 492; y < 984; y++) { + for(x = 0; x < 81; x++) { + EPD_M1_SendData(0xff); + } + } + EPD_M1_SendCommand(0x13); + for(y = 492; y < 984; y++) { + for(x = 0; x < 81; x++) { + EPD_M1_SendData(0x00); + } + } + + // S1 part 656*492 + EPD_S1_SendCommand(0x10); + for(y = 492; y < 984; y++) { + for(x = 81; x < 163; x++) { + EPD_S1_SendData(0xff); + } + } + EPD_S1_SendCommand(0x13); + for(y = 492; y < 984; y++) { + for(x = 81; x < 163; x++) { + EPD_S1_SendData(0x00); + } + } + + // M2 part 656*492 + EPD_M2_SendCommand(0x10); + for(y = 0; y < 492; y++) { + for(x = 81; x < 163; x++) { + EPD_M2_SendData(0xff); + } + } + EPD_M2_SendCommand(0x13); + for(y = 0; y < 492; y++) { + for(x = 81; x < 163; x++) { + EPD_M2_SendData(0x00); + } + } + + // S2 part 648*492 + EPD_S2_SendCommand(0x10); + for(y = 0; y < 492; y++) { + for(x = 0; x < 81; x++) { + EPD_S2_SendData(0xff); + } + } + EPD_S2_SendCommand(0x13); + for(y = 0; y < 492; y++) { + for(x = 0; x < 81; x++) { + EPD_S2_SendData(0x00); + } + } + + // Turn On Display + EPD_12in48B_TurnOnDisplay(); +} + +/****************************************************************************** +function : Sends the image buffer in RAM to e-Paper and displays +parameter: +******************************************************************************/ +void EPD_12in48B_cmd1S2(void) +{ + EPD_S2_SendCommand(0x10); +} +void EPD_12in48B_cmd1M2(void) +{ + EPD_M2_SendCommand(0x10); +} +void EPD_12in48B_cmd1M1(void) +{ + EPD_M1_SendCommand(0x10); +} +void EPD_12in48B_cmd1S1(void) +{ + EPD_S1_SendCommand(0x10); +} +void EPD_12in48B_data1S2(UBYTE data) +{ + EPD_S2_SendData(data); +} +void EPD_12in48B_data1M2(UBYTE data) +{ + EPD_M2_SendData(data); +} +void EPD_12in48B_data1M1(UBYTE data) +{ + EPD_M1_SendData(data); +} +void EPD_12in48B_data1S1(UBYTE data) +{ + EPD_S1_SendData(data); +} + +void EPD_12in48B_cmd2S2(void) +{ + EPD_S2_SendCommand(0x13); +} +void EPD_12in48B_cmd2M2(void) +{ + EPD_M2_SendCommand(0x13); +} +void EPD_12in48B_cmd2M1(void) +{ + EPD_M1_SendCommand(0x13); +} +void EPD_12in48B_cmd2S1(void) +{ + EPD_S1_SendCommand(0x13); +} +void EPD_12in48B_data2S2(UBYTE data) +{ + EPD_S2_SendData(~data); +} +void EPD_12in48B_data2M2(UBYTE data) +{ + EPD_M2_SendData(~data); +} +void EPD_12in48B_data2M1(UBYTE data) +{ + EPD_M1_SendData(~data); +} +void EPD_12in48B_data2S1(UBYTE data) +{ + EPD_S1_SendData(~data); +} +/****************************************************************************** +function : Turn On Display +parameter: +******************************************************************************/ +void EPD_12in48B_TurnOnDisplay(void) +{ + EPD_M1M2_SendCommand(0x04); //power on + delay(300); + EPD_M1S1M2S2_SendCommand(0x12); //Display Refresh + + EPD_M1_ReadBusy(); + EPD_S1_ReadBusy(); + EPD_M2_ReadBusy(); + EPD_S2_ReadBusy(); +} + +void EPD_12in48B_Show(void) { + Serial.println("EPD_12in48B_Show"); + + EPD_12in48B_TurnOnDisplay(); + EPD_12in48B_Sleep(); +} + +/****************************************************************************** +function : Enter sleep mode +parameter: +******************************************************************************/ +void EPD_12in48B_Sleep(void) +{ + EPD_M1S1M2S2_SendCommand(0X02); //power off + delay(300); + + EPD_M1S1M2S2_SendCommand(0X07); //deep sleep + EPD_M1S1M2S2_SendData(0xA5); + delay(300); + +} + +/****************************************************************************** +function : Software reset +parameter: +******************************************************************************/ +static void EPD_12in48b_Reset(void) +{ + DEV_Digital_Write(EPD_M1S1_RST_PIN, 1); + DEV_Digital_Write(EPD_M2S2_RST_PIN, 1); + delay(200); + DEV_Digital_Write(EPD_M1S1_RST_PIN, 0); + DEV_Digital_Write(EPD_M2S2_RST_PIN, 0); + delay(10); + DEV_Digital_Write(EPD_M1S1_RST_PIN, 1); + DEV_Digital_Write(EPD_M2S2_RST_PIN, 1); + delay(200); +} + +/****************************************************************************** +function: Microsecond delay +parameter: +Info: +******************************************************************************/ +void DEV_Delay_us(UWORD xus) +{ + UWORD i; + while(xus) { + for(i = 0; i < 30; i++); + xus--; + } +} + + +/****************************************************************************** +function: + SPI read and write +******************************************************************************/ +static void DEV_SPI_WriteByte(UBYTE value) +{ + char i; + DEV_Digital_Write(EPD_SCK_PIN, 0); + for(i = 0; i < 8; i++) { + DEV_Digital_Write(EPD_SCK_PIN, 0); + DEV_Delay_us(5); + if((value << i) & 0x80) { + DEV_Digital_Write(EPD_MOSI_PIN, 1); + } else { + DEV_Digital_Write(EPD_MOSI_PIN, 0); + } + DEV_Delay_us(5); + DEV_Digital_Write(EPD_SCK_PIN, 1); + DEV_Delay_us(5); + } +} + +static UBYTE DEV_SPI_ReadByte(char x) +{ + UBYTE i,temp=0; + + return temp; +} + +/****************************************************************************** +function : send command and data(M1\M2\S1\S2\M1S1\M1S1M2S2) +parameter: + Reg : Command register +or: + Data : Write data +******************************************************************************/ +static void EPD_M1_SendCommand(UBYTE Reg) +{ + DEV_Digital_Write(EPD_M1S1_DC_PIN, 0); + DEV_Digital_Write(EPD_M1_CS_PIN, 0); + DEV_SPI_WriteByte(Reg); + DEV_Digital_Write(EPD_M1_CS_PIN, 1); +} +static void EPD_M1_SendData(UBYTE Data) +{ + DEV_Digital_Write(EPD_M1S1_DC_PIN, 1); + DEV_Digital_Write(EPD_M1_CS_PIN, 0); + DEV_SPI_WriteByte(Data); + DEV_Digital_Write(EPD_M1_CS_PIN, 1); +} + +static void EPD_S1_SendCommand(UBYTE Reg) +{ + DEV_Digital_Write(EPD_M1S1_DC_PIN, 0); + DEV_Digital_Write(EPD_S1_CS_PIN, 0); + DEV_SPI_WriteByte(Reg); + DEV_Digital_Write(EPD_S1_CS_PIN, 1); +} +static void EPD_S1_SendData(UBYTE Data) +{ + DEV_Digital_Write(EPD_M1S1_DC_PIN, 1); + DEV_Digital_Write(EPD_S1_CS_PIN, 0); + DEV_SPI_WriteByte(Data); + DEV_Digital_Write(EPD_S1_CS_PIN, 1); +} + +static void EPD_M2_SendCommand(UBYTE Reg) +{ + DEV_Digital_Write(EPD_M2S2_DC_PIN, 0); + DEV_Digital_Write(EPD_M2_CS_PIN, 0); + DEV_SPI_WriteByte(Reg); + DEV_Digital_Write(EPD_M2_CS_PIN, 1); +} +static void EPD_M2_SendData(UBYTE Data) +{ + DEV_Digital_Write(EPD_M2S2_DC_PIN, 1); + DEV_Digital_Write(EPD_M2_CS_PIN, 0); + DEV_SPI_WriteByte(Data); + DEV_Digital_Write(EPD_M2_CS_PIN, 1); +} + +static void EPD_S2_SendCommand(UBYTE Reg) +{ + DEV_Digital_Write(EPD_M2S2_DC_PIN, 0); + DEV_Digital_Write(EPD_S2_CS_PIN, 0); + DEV_SPI_WriteByte(Reg); + DEV_Digital_Write(EPD_S2_CS_PIN, 1); +} +static void EPD_S2_SendData(UBYTE Data) +{ + DEV_Digital_Write(EPD_M2S2_DC_PIN, 1); + DEV_Digital_Write(EPD_S2_CS_PIN, 0); + DEV_SPI_WriteByte(Data); + DEV_Digital_Write(EPD_S2_CS_PIN, 1); +} + +static void EPD_M1M2_SendCommand(UBYTE Reg) +{ + DEV_Digital_Write(EPD_M1S1_DC_PIN, 0); + DEV_Digital_Write(EPD_M2S2_DC_PIN, 0); + DEV_Digital_Write(EPD_M1_CS_PIN, 0); + DEV_Digital_Write(EPD_M2_CS_PIN, 0); + DEV_SPI_WriteByte(Reg); + DEV_Digital_Write(EPD_M1_CS_PIN, 1); + DEV_Digital_Write(EPD_M2_CS_PIN, 1); +} +static void EPD_M1M2_SendData(UBYTE Data) +{ + DEV_Digital_Write(EPD_M1S1_DC_PIN, 1); + DEV_Digital_Write(EPD_M2S2_DC_PIN, 1); + DEV_Digital_Write(EPD_M1_CS_PIN, 0); + DEV_Digital_Write(EPD_M2_CS_PIN, 0); + DEV_SPI_WriteByte(Data); + DEV_Digital_Write(EPD_M1_CS_PIN, 1); + DEV_Digital_Write(EPD_M2_CS_PIN, 1); +} + +static void EPD_M1S1M2S2_SendCommand(UBYTE Reg) +{ + DEV_Digital_Write(EPD_M1S1_DC_PIN, 0); // command write + DEV_Digital_Write(EPD_M2S2_DC_PIN, 0); // command write + + DEV_Digital_Write(EPD_M1_CS_PIN, 0); + DEV_Digital_Write(EPD_S1_CS_PIN, 0); + DEV_Digital_Write(EPD_M2_CS_PIN, 0); + DEV_Digital_Write(EPD_S2_CS_PIN, 0); + DEV_SPI_WriteByte(Reg); + DEV_Digital_Write(EPD_M1_CS_PIN, 1); + DEV_Digital_Write(EPD_S1_CS_PIN, 1); + DEV_Digital_Write(EPD_M2_CS_PIN, 1); + DEV_Digital_Write(EPD_S2_CS_PIN, 1); +} +static void EPD_M1S1M2S2_SendData(UBYTE Data) +{ + DEV_Digital_Write(EPD_M1S1_DC_PIN, 1); // command write + DEV_Digital_Write(EPD_M2S2_DC_PIN, 1); // command write + + DEV_Digital_Write(EPD_M1_CS_PIN, 0); + DEV_Digital_Write(EPD_S1_CS_PIN, 0); + DEV_Digital_Write(EPD_M2_CS_PIN, 0); + DEV_Digital_Write(EPD_S2_CS_PIN, 0); + DEV_SPI_WriteByte(Data); + DEV_Digital_Write(EPD_M1_CS_PIN, 1); + DEV_Digital_Write(EPD_S1_CS_PIN, 1); + DEV_Digital_Write(EPD_M2_CS_PIN, 1); + DEV_Digital_Write(EPD_S2_CS_PIN, 1); +} + +/****************************************************************************** +function : Wait until the busy_pin goes LOW(M1\M2\S1\S2) +parameter: +******************************************************************************/ +static void EPD_M1_ReadBusy(void) +{ + UBYTE busy; + do { + EPD_M1_SendCommand(0x71); + busy = DEV_Digital_Read(EPD_M1_BUSY_PIN); + busy =!(busy & 0x01); + } while(0); + Serial.print("M1 Busy free\r\n"); + delay(200); + +} +static void EPD_M2_ReadBusy(void) +{ + UBYTE busy; + do { + EPD_M2_SendCommand(0x71); + busy = DEV_Digital_Read(EPD_M2_BUSY_PIN); + busy =!(busy & 0x01); + } while(busy); + Serial.print("M2 Busy free\r\n"); + delay(200); +} +static void EPD_S1_ReadBusy(void) +{ + UBYTE busy; + do { + EPD_S1_SendCommand(0x71); + busy = DEV_Digital_Read(EPD_S1_BUSY_PIN); + busy =!(busy & 0x01); + } while(busy); + Serial.print("S1 Busy free\r\n"); + delay(200); +} +static void EPD_S2_ReadBusy(void) +{ + UBYTE busy; + do { + EPD_S2_SendCommand(0x71); + busy = DEV_Digital_Read(EPD_S2_BUSY_PIN); + busy =!(busy & 0x01); + } while(busy); + Serial.print("S2 Busy free\r\n"); + delay(200); +} + +/****************************************************************************** +function : ReadTemperature +parameter: +******************************************************************************/ +static void EPD_M1_ReadTemperature(void) +{ + EPD_M1_SendCommand(0x40); + EPD_M1_ReadBusy(); + delay(300); + + // just select M1 + DEV_Digital_Write(EPD_M1_CS_PIN, 0); + DEV_Digital_Write(EPD_S1_CS_PIN, 1); + DEV_Digital_Write(EPD_M2_CS_PIN, 1); + DEV_Digital_Write(EPD_S2_CS_PIN, 1); + + // read data + DEV_Digital_Write(EPD_M1S1_DC_PIN, 1); + DEV_Delay_us(5); + + UBYTE temp; + temp = DEV_SPI_ReadByte(0x00); + // restore deselected M1 + DEV_Digital_Write(EPD_M1_CS_PIN, 1); + printf("Read Temperature Reg:%d\r\n", temp); + + // Sync master temperature data -> slave + // bit[1] TSFIX: Let the value of slave’s temperature is same as the master’s. + // 1: Temperature value is defined by TS_SET[7:0] registers. + // bit[0] CCEN: Output clock enable/disable. + // 1: Output clock at CL pin to slave chip. + EPD_M1S1M2S2_SendCommand(0xe0);//Cascade setting + EPD_M1S1M2S2_SendData(0x03); + EPD_M1S1M2S2_SendCommand(0xe5);//Force temperature + EPD_M1S1M2S2_SendData(temp); + +} + +static unsigned char lut_12in48b_vcom1[] = { + 0x00, 0x10, 0x10, 0x01, 0x08, 0x01, + 0x00, 0x06, 0x01, 0x06, 0x01, 0x05, + 0x00, 0x08, 0x01, 0x08, 0x01, 0x06, + 0x00, 0x06, 0x01, 0x06, 0x01, 0x05, + 0x00, 0x05, 0x01, 0x1E, 0x0F, 0x06, + 0x00, 0x05, 0x01, 0x1E, 0x0F, 0x01, + 0x00, 0x04, 0x05, 0x08, 0x08, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +static unsigned char lut_12in48b_ww1[] = { + 0x91, 0x10, 0x10, 0x01, 0x08, 0x01, + 0x04, 0x06, 0x01, 0x06, 0x01, 0x05, + 0x84, 0x08, 0x01, 0x08, 0x01, 0x06, + 0x80, 0x06, 0x01, 0x06, 0x01, 0x05, + 0x00, 0x05, 0x01, 0x1E, 0x0F, 0x06, + 0x00, 0x05, 0x01, 0x1E, 0x0F, 0x01, + 0x08, 0x04, 0x05, 0x08, 0x08, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +static unsigned char lut_12in48b_bw1[] = { + 0xA8, 0x10, 0x10, 0x01, 0x08, 0x01, + 0x84, 0x06, 0x01, 0x06, 0x01, 0x05, + 0x84, 0x08, 0x01, 0x08, 0x01, 0x06, + 0x86, 0x06, 0x01, 0x06, 0x01, 0x05, + 0x8C, 0x05, 0x01, 0x1E, 0x0F, 0x06, + 0x8C, 0x05, 0x01, 0x1E, 0x0F, 0x01, + 0xF0, 0x04, 0x05, 0x08, 0x08, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +static unsigned char lut_12in48b_wb1[] = { + 0x91, 0x10, 0x10, 0x01, 0x08, 0x01, + 0x04, 0x06, 0x01, 0x06, 0x01, 0x05, + 0x84, 0x08, 0x01, 0x08, 0x01, 0x06, + 0x80, 0x06, 0x01, 0x06, 0x01, 0x05, + 0x00, 0x05, 0x01, 0x1E, 0x0F, 0x06, + 0x00, 0x05, 0x01, 0x1E, 0x0F, 0x01, + 0x08, 0x04, 0x05, 0x08, 0x08, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +static unsigned char lut_12in48b_bb1[] = { + 0x92, 0x10, 0x10, 0x01, 0x08, 0x01, + 0x80, 0x06, 0x01, 0x06, 0x01, 0x05, + 0x84, 0x08, 0x01, 0x08, 0x01, 0x06, + 0x04, 0x06, 0x01, 0x06, 0x01, 0x05, + 0x00, 0x05, 0x01, 0x1E, 0x0F, 0x06, + 0x00, 0x05, 0x01, 0x1E, 0x0F, 0x01, + 0x01, 0x04, 0x05, 0x08, 0x08, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +/****************************************************************************** +function : ReadTemperature +parameter: +******************************************************************************/ +static void EPD_12in48b_SetLut(void) +{ + UWORD count; + + EPD_M1S1M2S2_SendCommand(0x20); //vcom + for(count=0; count<60; count++) { + EPD_M1S1M2S2_SendData(lut_12in48b_vcom1[count]); + } + + EPD_M1S1M2S2_SendCommand(0x21); //red not use + for(count=0; count<60; count++) { + EPD_M1S1M2S2_SendData(lut_12in48b_ww1[count]); + } + + EPD_M1S1M2S2_SendCommand(0x22); //bw r + for(count=0; count<60; count++) { + EPD_M1S1M2S2_SendData(lut_12in48b_bw1[count]); // bw=r + } + + EPD_M1S1M2S2_SendCommand(0x23); //wb w + for(count=0; count<60; count++) { + EPD_M1S1M2S2_SendData(lut_12in48b_wb1[count]); // wb=w + } + + EPD_M1S1M2S2_SendCommand(0x24); //bb b + for(count=0; count<60; count++) { + EPD_M1S1M2S2_SendData(lut_12in48b_bb1[count]); // bb=b + } + + EPD_M1S1M2S2_SendCommand(0x25); //bb b + for(count=0; count<60; count++) { + EPD_M1S1M2S2_SendData(lut_12in48b_ww1[count]); // bb=b + } +} + +#endif \ No newline at end of file diff --git a/src/epd_panel/EPD_9in69b.h b/src/epd_panel/EPD_9in69b.h new file mode 100644 index 0000000..d882303 --- /dev/null +++ b/src/epd_panel/EPD_9in69b.h @@ -0,0 +1,529 @@ +/***************************************************************************** +* | File : EPD_9IN69B.h +* | Author : Waveshare team +* | Function : Electronic paper driver +* | Info : +*---------------- +* | This version: V2.1 +* | Date : 2020-12-01 +* | Info : +* 1.Remove:ImageBuff[EPD_HEIGHT * EPD_WIDTH / 8] +* 2.Change:EPD_Display(UBYTE *Image) +* Need to pass parameters: pointer to cached data +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documnetation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +******************************************************************************/ +#ifndef _EPD_9IN69B_H_ +#define _EPD_9IN69B_H_ + +// use 7 pins, specially defined here +#define EPD_MOSI_PIN 18 +#define EPD_SCK_PIN 17 +#define EPD_CS_PIN 16 +#define EPD_DC_PIN 15 +#define EPD_RST_PIN 14 +#define EPD_BUSY_PIN 13 +#define EPD_CS_S_PIN 12 + +// Display resolution +#define EPD_9IN69B_WIDTH 960 +#define EPD_9IN69B_HEIGHT 672 + +#define EPD_9IN69B_IMAGE_DATA_SIZE (EPD_9IN69B_WIDTH * EPD_9IN69B_HEIGHT / 8 / 2) + +/****************************************************************************** +function : Software reset +parameter: +******************************************************************************/ +static void EPD_9IN69B_Reset(void) +{ + // 200, 20, 200, 200, 5 + delay(200); + DEV_Digital_Write(EPD_RST_PIN, 1); + delay(20); + DEV_Digital_Write(EPD_RST_PIN, 0); + delay(200); + DEV_Digital_Write(EPD_RST_PIN, 1); + delay(200); + DEV_Digital_Write(EPD_CS_PIN, 1); + DEV_Digital_Write(EPD_CS_S_PIN, 1); + delay(5); +} + +void GPIO_Mode(UWORD GPIO_Pin, UWORD Mode) +{ + if(Mode == 0) { + pinMode(GPIO_Pin , INPUT); + } else { + pinMode(GPIO_Pin , OUTPUT); + } +} + +/****************************************************************************** +function: + SPI read and write +******************************************************************************/ +static void EPD_9IN69B_SPI_WriteByte(UBYTE data) +{ + for (int i = 0; i < 8; i++) + { + if ((data & 0x80) == 0) digitalWrite(EPD_MOSI_PIN, GPIO_PIN_RESET); + else digitalWrite(EPD_MOSI_PIN, GPIO_PIN_SET); + + data <<= 1; + digitalWrite(EPD_SCK_PIN, GPIO_PIN_SET); + digitalWrite(EPD_SCK_PIN, GPIO_PIN_RESET); + } +} + +static UBYTE EPD_9IN69B_SPI_ReadByte() +{ + UBYTE j=0xff; + GPIO_Mode(EPD_MOSI_PIN, 0); + + for (int i = 0; i < 8; i++) + { + j = j << 1; + if (digitalRead(EPD_MOSI_PIN)) j = j | 0x01; + else j = j & 0xfe; + + digitalWrite(EPD_SCK_PIN, GPIO_PIN_SET); + digitalWrite(EPD_SCK_PIN, GPIO_PIN_RESET); + } + + GPIO_Mode(EPD_MOSI_PIN, 1); + return j; +} + +/****************************************************************************** +function : send command +parameter: + Reg : Command register +******************************************************************************/ +static void EPD_9IN69B_SendCommand(UBYTE Reg) +{ + DEV_Digital_Write(EPD_DC_PIN, 0); + DEV_Digital_Write(EPD_CS_PIN, 0); + DEV_Digital_Write(EPD_CS_S_PIN, 0); + EPD_9IN69B_SPI_WriteByte(Reg); + DEV_Digital_Write(EPD_CS_PIN, 1); + DEV_Digital_Write(EPD_CS_S_PIN, 1); +} + +void EPD_9IN69B_SendCommandM(UBYTE Reg) +{ + DEV_Digital_Write(EPD_CS_S_PIN, 1); + + DEV_Digital_Write(EPD_DC_PIN, 0); + DEV_Digital_Write(EPD_CS_PIN, 0); + EPD_9IN69B_SPI_WriteByte(Reg); + DEV_Digital_Write(EPD_CS_PIN, 1); +} + +void EPD_9IN69B_SendCommandS(UBYTE Reg) +{ + DEV_Digital_Write(EPD_CS_PIN, 1); + + DEV_Digital_Write(EPD_DC_PIN, 0); + DEV_Digital_Write(EPD_CS_S_PIN, 0); + EPD_9IN69B_SPI_WriteByte(Reg); + DEV_Digital_Write(EPD_CS_S_PIN, 1); +} + +/****************************************************************************** +function : send data +parameter: + Data : Write data +******************************************************************************/ +static void EPD_9IN69B_SendData(UBYTE Data) +{ + DEV_Digital_Write(EPD_DC_PIN, 1); + DEV_Digital_Write(EPD_CS_PIN, 0); + DEV_Digital_Write(EPD_CS_S_PIN, 0); + EPD_9IN69B_SPI_WriteByte(Data); + DEV_Digital_Write(EPD_CS_PIN, 1); + DEV_Digital_Write(EPD_CS_S_PIN, 1); +} + +void EPD_9IN69B_SendDataM(UBYTE Data) +{ + DEV_Digital_Write(EPD_CS_S_PIN, 1); + + DEV_Digital_Write(EPD_DC_PIN, 1); + DEV_Digital_Write(EPD_CS_PIN, 0); + EPD_9IN69B_SPI_WriteByte(Data); + DEV_Digital_Write(EPD_CS_PIN, 1); +} + +void EPD_9IN69B_SendDataS(UBYTE Data) +{ + DEV_Digital_Write(EPD_CS_PIN, 1); + + DEV_Digital_Write(EPD_DC_PIN, 1); + DEV_Digital_Write(EPD_CS_S_PIN, 0); + EPD_9IN69B_SPI_WriteByte(Data); + DEV_Digital_Write(EPD_CS_S_PIN, 1); +} + +/****************************************************************************** +function : Wait until the busy_pin goes LOW +parameter: +******************************************************************************/ +static void EPD_9IN69B_WaitUntilIdle(void) +{ + Serial.print("e-Paper busy\r\n"); + unsigned char busy; + do { + busy = DEV_Digital_Read(EPD_BUSY_PIN); + busy =!(busy & 0x01); + delay(100); + }while(busy); + Serial.print("e-Paper busy release\r\n"); +} + +static void EPD_9IN69B_DCDC_SoftStart() { + //DCDC soft-start + uint8_t Index51_data[]={0x50,0x01,0x0a,0x01}; + uint8_t Index09_data[]={0x1f,0x9f,0x7f,0xff}; + + EPD_9IN69B_SendCommand(0x51); + EPD_9IN69B_SendData(Index51_data[0]); + EPD_9IN69B_SendData(Index51_data[1]); + + for(int value = 1; value <= 4; value++) { + EPD_9IN69B_SendCommand(0x09); + EPD_9IN69B_SendData(Index09_data[0]); + + Index51_data[1]=value; + EPD_9IN69B_SendCommand(0x51); + EPD_9IN69B_SendData(Index51_data[0]); + EPD_9IN69B_SendData(Index51_data[1]); + + EPD_9IN69B_SendCommand(0x09); + EPD_9IN69B_SendData(Index09_data[1]); + delay(2); + } + + for(int value = 1; value <= 10; value++) { + EPD_9IN69B_SendCommand(0x09); + EPD_9IN69B_SendData(Index09_data[0]); + + Index51_data[3]=value; + EPD_9IN69B_SendCommand(0x51); + EPD_9IN69B_SendData(Index51_data[2]); + EPD_9IN69B_SendData(Index51_data[3]); + + EPD_9IN69B_SendCommand(0x09); + EPD_9IN69B_SendData(Index09_data[1]); + delay(2); + } + + for(int value = 3; value <= 10; value++) { + EPD_9IN69B_SendCommand(0x09); + EPD_9IN69B_SendData(Index09_data[2]); + + Index51_data[3]=value; + EPD_9IN69B_SendCommand(0x51); + EPD_9IN69B_SendData(Index51_data[2]); + EPD_9IN69B_SendData(Index51_data[3]); + + EPD_9IN69B_SendCommand(0x09); + EPD_9IN69B_SendData(Index09_data[3]); + delay(2); + } + + for(int value = 9; value >= 2; value--) { + EPD_9IN69B_SendCommand(0x09); + EPD_9IN69B_SendData(Index09_data[1]); + + Index51_data[2]=value; + EPD_9IN69B_SendCommand(0x51); + EPD_9IN69B_SendData(Index51_data[2]); + EPD_9IN69B_SendData(Index51_data[3]); + + EPD_9IN69B_SendCommand(0x09); + EPD_9IN69B_SendData(Index09_data[3]); + delay(2); + } + + EPD_9IN69B_SendCommand(0x09); + EPD_9IN69B_SendData(Index09_data[3]); + delay(10); +} + +static void EPD_9IN69B_DCDC_SoftShutdown() { + EPD_9IN69B_WaitUntilIdle(); + + EPD_9IN69B_SendCommand(0x09); + EPD_9IN69B_SendData(0x7f); + EPD_9IN69B_SendCommand(0x05); + EPD_9IN69B_SendData(0x7d); + EPD_9IN69B_SendCommand(0x09); + EPD_9IN69B_SendData(0x00); + delay(200); + + EPD_9IN69B_WaitUntilIdle(); + + digitalWrite(EPD_DC_PIN, LOW); + digitalWrite(EPD_CS_PIN, LOW); + digitalWrite(EPD_RST_PIN, LOW); + digitalWrite(EPD_CS_PIN, HIGH); +} + + +/****************************************************************************** +function : Turn On Display +parameter: +******************************************************************************/ +static void EPD_9IN69B_TurnOnDisplay(void) +{ + EPD_9IN69B_DCDC_SoftStart(); + + EPD_9IN69B_SendCommand(0x12); //DISPLAY REFRESH + + EPD_9IN69B_WaitUntilIdle(); + delay(100); + + EPD_9IN69B_SendCommand(0x15); + EPD_9IN69B_SendData(0x3c); + delay(5); +} + + +void EPD_9IN69B_Prepare() { + // DUW for both + EPD_9IN69B_SendCommand(0x13); + EPD_9IN69B_SendData(0x00); + EPD_9IN69B_SendData(0x3b); + EPD_9IN69B_SendData(0x00); + EPD_9IN69B_SendData(0x00); + EPD_9IN69B_SendData(0x9f); + EPD_9IN69B_SendData(0x02); + + // DRFW for both + EPD_9IN69B_SendCommand(0x90); + EPD_9IN69B_SendData(0x00); + EPD_9IN69B_SendData(0x3b); + EPD_9IN69B_SendData(0x00); + EPD_9IN69B_SendData(0xa9); +} + +/****************************************************************************** +function : Initialize the e-Paper register +parameter: +******************************************************************************/ +static int EPD_9IN69B_Init(void) +{ + Serial.println("EPD_9IN69B_Init is calling"); + EPD_9IN69B_Reset(); + + EPD_9IN69B_SendCommand(0x05); + EPD_9IN69B_SendData(0x7d); + delay(200); + + EPD_9IN69B_SendCommand(0x05); + EPD_9IN69B_SendData(0x00); + delay(10); + + // MS_SYNC + EPD_9IN69B_SendCommand(0xd8); + EPD_9IN69B_SendData(0x80); + // BVSS + EPD_9IN69B_SendCommand(0xd6); + EPD_9IN69B_SendData(0x00); + + EPD_9IN69B_SendCommand(0xa7); + EPD_9IN69B_SendData(0x10); + delay(100); + EPD_9IN69B_SendCommand(0xa7); + EPD_9IN69B_SendData(0x00); + delay(100); + + // OSC + EPD_9IN69B_SendCommand(0x03); + EPD_9IN69B_SendData(0x00); + EPD_9IN69B_SendData(0x11); + + // Master + EPD_9IN69B_SendCommandM(0x44); + EPD_9IN69B_SendDataM(0x00); + EPD_9IN69B_SendCommandM(0x45); + EPD_9IN69B_SendDataM(0x80); + EPD_9IN69B_SendCommandM(0xa7); + EPD_9IN69B_SendDataM(0x10); + delay(100); + EPD_9IN69B_SendCommandM(0xa7); + EPD_9IN69B_SendDataM(0x00); + EPD_9IN69B_SendCommandM(0x44); + EPD_9IN69B_SendDataM(0x06); + // temperature + EPD_9IN69B_SendCommandM(0x45); + EPD_9IN69B_SendDataM(0x82); + + EPD_9IN69B_SendCommandM(0xa7); + EPD_9IN69B_SendDataM(0x10); + delay(100); + EPD_9IN69B_SendCommandM(0xa7); + EPD_9IN69B_SendDataM(0x00); + delay(100); + + // Slave + EPD_9IN69B_SendCommandS(0x44); + EPD_9IN69B_SendDataS(0x00); + EPD_9IN69B_SendCommandS(0x45); + EPD_9IN69B_SendDataS(0x80); + EPD_9IN69B_SendCommandS(0xa7); + EPD_9IN69B_SendDataS(0x10); + delay(100); + EPD_9IN69B_SendCommandS(0xa7); + EPD_9IN69B_SendDataS(0x00); + delay(100); + EPD_9IN69B_SendCommandS(0x44); + EPD_9IN69B_SendDataS(0x06); + // temperature + EPD_9IN69B_SendCommandS(0x45); + EPD_9IN69B_SendDataS(0x82); + + EPD_9IN69B_SendCommandS(0xa7); + EPD_9IN69B_SendDataS(0x10); + delay(100); + EPD_9IN69B_SendCommandS(0xa7); + EPD_9IN69B_SendDataS(0x00); + delay(100); + + // both, TCON + EPD_9IN69B_SendCommand(0x60); + EPD_9IN69B_SendData(0x25); + // Master, STV_DIR + EPD_9IN69B_SendCommandM(0x61); + EPD_9IN69B_SendDataM(0x01); + // both, VCOM + EPD_9IN69B_SendCommand(0x02); + EPD_9IN69B_SendData(0x00); + + return 0; +} + + +void EPD_9IN69B_SendImages(uint8_t* data1m, uint8_t* data2m, uint8_t* data1s, uint8_t* data2s) { + Serial.println("EPD_9IN69B_SendImages is calling"); + EPD_9IN69B_Prepare(); + + // RAM_RW for Master + EPD_9IN69B_SendCommandM(0x12); + EPD_9IN69B_SendDataM(0x3b); + EPD_9IN69B_SendDataM(0x00); + EPD_9IN69B_SendDataM(0x14); + //First frame for Master + EPD_9IN69B_SendCommandM(0x10); + for (int i = 0; i < EPD_9IN69B_IMAGE_DATA_SIZE; i++) { + EPD_9IN69B_SendDataM(data1m[i]); + } + + // RAM_RW for Master + EPD_9IN69B_SendCommandM(0x12); + EPD_9IN69B_SendDataM(0x3b); + EPD_9IN69B_SendDataM(0x00); + EPD_9IN69B_SendDataM(0x14); + //Second frame for Master + EPD_9IN69B_SendCommandM(0x11); + for (int i = 0; i < EPD_9IN69B_IMAGE_DATA_SIZE; i++) { + EPD_9IN69B_SendDataM(data2m[i]); + } + + // RAM_RW for Slave + EPD_9IN69B_SendCommandS(0x12); + EPD_9IN69B_SendDataS(0x3b); + EPD_9IN69B_SendDataS(0x00); + EPD_9IN69B_SendDataS(0x14); + //First frame for Slave + EPD_9IN69B_SendCommandS(0x10); + for (int i = 0; i < EPD_9IN69B_IMAGE_DATA_SIZE; i++) { + EPD_9IN69B_SendDataS(data1s[i]); + } + + // RAM_RW for Slave + EPD_9IN69B_SendCommandS(0x12); + EPD_9IN69B_SendDataS(0x3b); + EPD_9IN69B_SendDataS(0x00); + EPD_9IN69B_SendDataS(0x14); + //Second frame for Slave + EPD_9IN69B_SendCommandS(0x11); + for (int i = 0; i < EPD_9IN69B_IMAGE_DATA_SIZE; i++) { + EPD_9IN69B_SendDataS(data2s[i]); + } +} + +/****************************************************************************** +function : Clear screen +parameter: +******************************************************************************/ +void EPD_9IN69B_Clear(void) +{ + int buffer_size = EPD_9IN69B_IMAGE_DATA_SIZE; + uint8_t* data_buffer = (uint8_t*)malloc(buffer_size); + if (NULL == data_buffer) { + Serial.println("malloc failed."); + exit(-1); + } + memset(data_buffer, 0, buffer_size); + + EPD_9IN69B_SendImages(data_buffer, data_buffer, data_buffer, data_buffer); + + EPD_9IN69B_TurnOnDisplay(); +} + +void EPD_9IN69B_InitSPI(void) { + Serial.println("EPD_9IN69B_InitSPI is calling"); + pinMode(EPD_BUSY_PIN, INPUT); + + pinMode(EPD_RST_PIN , OUTPUT); + digitalWrite(EPD_RST_PIN , HIGH); + + pinMode(EPD_DC_PIN , OUTPUT); + digitalWrite(EPD_DC_PIN , HIGH); + + pinMode(EPD_CS_PIN , OUTPUT); + digitalWrite(EPD_CS_PIN , HIGH); + pinMode(EPD_CS_S_PIN , OUTPUT); + digitalWrite(EPD_CS_S_PIN , HIGH); + + pinMode(EPD_SCK_PIN, OUTPUT); + pinMode(EPD_MOSI_PIN, OUTPUT); + + digitalWrite(EPD_SCK_PIN, LOW); +} + +/****************************************************************************** +function : Enter sleep mode +parameter: +******************************************************************************/ +static void EPD_9IN69B_Sleep(void) +{ + EPD_9IN69B_DCDC_SoftShutdown(); +} + +static void EPD_9IN69B_Show(void) { + Serial.println("EPD_9IN69B_Show"); + + EPD_9IN69B_TurnOnDisplay(); + EPD_9IN69B_Sleep(); +} +#endif diff --git a/src/epd_panel/epd1in54.h b/src/epd_panel/epd1in54.h new file mode 100644 index 0000000..28ac7e9 --- /dev/null +++ b/src/epd_panel/epd1in54.h @@ -0,0 +1,193 @@ +/** + ****************************************************************************** + * @file edp1in54.h + * @author Waveshare Team + * @version V1.0.0 + * @date 23-January-2018 + * @brief This file describes initialisation of 1.54 and 1.54b e-Papers + * + ****************************************************************************** + */ + +int EPD_Init_1in54() +{ + int EPD1in54 = 2; + if(EPD1in54 == 1) { + Serial.print("\r\nEPD1in54 V1"); + EPD_Reset(); + EPD_Send_3(0x01, 199, 0, 00);//DRIVER_OUTPUT_CONTROL: LO(EPD_HEIGHT-1), HI(EPD_HEIGHT-1). GD = 0; SM = 0; TB = 0; + EPD_Send_3(0x0C, 0xD7, 0xD6, 0x9D);//BOOSTER_SOFT_START_CONTROL + EPD_Send_1(0x2C, 0xA8);//WRITE_VCOM_REGISTER: VCOM 7C + EPD_Send_1(0x3A, 0x1A);//SET_DUMMY_LINE_PERIOD: 4 dummy lines per gate + EPD_Send_1(0x3B, 0x08);//SET_GATE_TIME: 2us per line + EPD_Send_1(0x11, 0x03);//DATA_ENTRY_MODE_SETTING: X increment; Y increment + + EPD_lut(0x32, 30, &lut_full_mono[0]); + + EPD_Send_2(0x44, 0, 24);//SET_RAM_X_ADDRESS_START_END_POSITION: LO(x >> 3), LO((w-1) >> 3) + EPD_Send_4(0x45, 0, 0, 200, 0);//SET_RAM_Y_ADDRESS_START_END_POSITION: LO(y), HI(y), LO(h - 1), HI(h - 1) + EPD_Send_1(0x4E, 0);//LO(x >> 3) + EPD_Send_2(0x4F, 0, 0);//LO(y), HI(y >> 8) + + EPD_SendCommand(0x24);//WRITE_RAM + delay(2); + } else { + Serial.print("\r\nEPD1in54 V2"); + EPD_Reset(); + + while (digitalRead(PIN_SPI_BUSY) == 1) delay(100); + EPD_SendCommand(0x12); //SWRESET + while (digitalRead(PIN_SPI_BUSY) == 1) delay(100); + + EPD_SendCommand(0x01); //Driver output control + EPD_SendData(0xC7); + EPD_SendData(0x00); + EPD_SendData(0x01); + + EPD_SendCommand(0x11); //data entry mode + EPD_SendData(0x01); + + EPD_SendCommand(0x44); //set Ram-X address start/end position + EPD_SendData(0x00); + EPD_SendData(0x18); //0x0C-->(18+1)*8=200 + + EPD_SendCommand(0x45); //set Ram-Y address start/end position + EPD_SendData(0xC7); //0xC7-->(199+1)=200 + EPD_SendData(0x00); + EPD_SendData(0x00); + EPD_SendData(0x00); + + EPD_SendCommand(0x3C); //BorderWavefrom + EPD_SendData(0x01); + + EPD_SendCommand(0x18); + EPD_SendData(0x80); + + EPD_SendCommand(0x22); // //Load Temperature and waveform setting. + EPD_SendData(0XB1); + EPD_SendCommand(0x20); + + EPD_SendCommand(0x4E); // set RAM x address count to 0; + EPD_SendData(0x00); + EPD_SendCommand(0x4F); // set RAM y address count to 0X199; + EPD_SendData(0xC7); + EPD_SendData(0x00); + while (digitalRead(PIN_SPI_BUSY) == 1) delay(100); + Serial.print("\r\n init over"); + + EPD_SendCommand(0x24);//DATA_START_TRANSMISSION_1 + } + return 0; +} + +void EPD_1IN54_Show(void) +{ + int EPD1in54 = 2; + if(EPD1in54 == 1) { + Serial.print("\r\n EPD_1IN54_Show"); + // Refresh + EPD_Send_1(0x22, 0xC4);// DISPLAY_UPDATE_CONTROL_2 + EPD_SendCommand( 0x20);// MASTER_ACTIVATION + EPD_SendCommand( 0xFF);// TERMINATE_FRAME_READ_WRITE + EPD_WaitUntilIdle(); + + // Sleep + EPD_SendCommand(0x10);// DEEP_SLEEP_MODE + EPD_WaitUntilIdle(); + } + else { + Serial.print("\r\n EPD_1IN54_V2_Show"); + EPD_Send_1(0x22, 0xc7); //Display Update Control + EPD_SendCommand(0x20); //Activate Display Update Sequence + EPD_WaitUntilIdle(); + + EPD_Send_1(0x10, 0x01); + } +} + +int EPD_Init_1in54b() +{ + EPD_Reset(); + EPD_Send_4(0x01, 0x07, 0x00, 0x08, 0x00);//POWER_SETTING + EPD_Send_3(0x06, 0x07, 0x07, 0x07);//BOOSTER_SOFT_START + EPD_SendCommand(0x04);//POWER_ON + EPD_WaitUntilIdle(); + + EPD_Send_1(0x00, 0xCF);//PANEL_SETTING + EPD_Send_1(0x50, 0x37);//VCOM_AND_DATA_INTERVAL_SETTING + EPD_Send_1(0x30, 0x39);//PLL_CONTROL + EPD_Send_3(0x61, 0xC8, 0x00, 0xC8);//TCON_RESOLUTION + EPD_Send_1(0x82, 0x0E);//VCM_DC_SETTING_REGISTER + + EPD_SetLutBw (&lut_vcom0[0], &lut_w[0], &lut_b[0], &lut_g1[0], &lut_g2[0]); + EPD_SetLutRed(&lut_vcom1[0], &lut_red0[0], &lut_red1[0]); + + EPD_SendCommand(0x10);//DATA_START_TRANSMISSION_1 + delay(2); + return 0; +} + +int EPD_1IN54B_V2_Init(void) +{ + EPD_Reset(); + EPD_WaitUntilIdle_high(); + + EPD_SendCommand(0x12); //SWRESET + EPD_WaitUntilIdle_high(); + + EPD_Send_3(0x01, 0xc7, 0x00, 0x01); //Driver output control + + EPD_Send_1(0x11, 0x01); //data entry mode + + EPD_Send_2(0x44, 0x00, 0x18); //set Ram-X address start/end position + + EPD_Send_4(0x45, 0xc7, 0x00, 0x00, 0x00); //set Ram-Y address start/end position + + EPD_Send_1(0x3C, 0x05); //BorderWavefrom + + EPD_Send_1(0x18, 0x80); //Read built-in temperature sensor + + EPD_Send_1(0x4E, 0x00); // set RAM x address count to 0; + + EPD_Send_2(0x4F, 0xc7, 0x00); // set RAM y address count to 0X199; + + EPD_WaitUntilIdle_high(); + + EPD_SendCommand(0x24); + delay(2); + return 0; +} + +void EPD_1IN54B_V2_Show(void) +{ + //refresh + EPD_Send_1(0x22, 0xf7); //Display Update Control + EPD_SendCommand(0x20); //Activate Display Update Sequence + EPD_WaitUntilIdle_high(); + + //sleep + EPD_Send_1(0x10, 0x01); //enter deep sleep + delay(2); +} + +int EPD_Init_1in54c() +{ + EPD_Reset(); + EPD_Send_4(0x01, 0x07, 0x00, 0x08, 0x00);//POWER_SETTING + EPD_Send_3(0x06, 0x17, 0x17, 0x17);//BOOSTER_SOFT_START + EPD_SendCommand(0x04);//POWER_ON + EPD_WaitUntilIdle(); + + //EPD_Send_2(0x00, 0x0F, 0x0D);//PANEL_SETTING + EPD_Send_1(0x50, 0xF7);//VCOM_AND_DATA_INTERVAL_SETTING + EPD_Send_1(0x30, 0x39);//PLL_CONTROL + EPD_Send_3(0x61, 0x98, 0x00, 0x98);//TCON_RESOLUTION + EPD_Send_1(0x82, 0xF7);//VCM_DC_SETTING_REGISTER + + EPD_SetLutBw (&lut_vcom0[0], &lut_w[0], &lut_b[0], &lut_g1[0], &lut_g2[0]); + EPD_SetLutRed(&lut_vcom1[0], &lut_red0[0], &lut_red1[0]); + + EPD_SendCommand(0x10);//DATA_START_TRANSMISSION_1 + delay(2); + return 0; +} diff --git a/src/epd_panel/epd2in13.h b/src/epd_panel/epd2in13.h new file mode 100644 index 0000000..885e33e --- /dev/null +++ b/src/epd_panel/epd2in13.h @@ -0,0 +1,315 @@ +/** + ****************************************************************************** + * @file edp2in13.h + * @author Waveshare Team + * @version V1.0.0 + * @date 23-January-2018 + * @brief This file describes initialisation of e-Papers: + * 2.13, + * 2.13b and 2.13c, + * 2.13d. + * + ****************************************************************************** + */ + +unsigned char lut_full_2in13[] = { + 0x22, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x11, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +const unsigned char lut_full_2in3v2[] = { + 0x80,0x60,0x40,0x00,0x00,0x00,0x00, //LUT0: BB: VS 0 ~7 + 0x10,0x60,0x20,0x00,0x00,0x00,0x00, //LUT1: BW: VS 0 ~7 + 0x80,0x60,0x40,0x00,0x00,0x00,0x00, //LUT2: WB: VS 0 ~7 + 0x10,0x60,0x20,0x00,0x00,0x00,0x00, //LUT3: WW: VS 0 ~7 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, //LUT4: VCOM: VS 0 ~7 + + 0x03,0x03,0x00,0x00,0x02, // TP0 A~D RP0 + 0x09,0x09,0x00,0x00,0x02, // TP1 A~D RP1 + 0x03,0x03,0x00,0x00,0x02, // TP2 A~D RP2 + 0x00,0x00,0x00,0x00,0x00, // TP3 A~D RP3 + 0x00,0x00,0x00,0x00,0x00, // TP4 A~D RP4 + 0x00,0x00,0x00,0x00,0x00, // TP5 A~D RP5 + 0x00,0x00,0x00,0x00,0x00, // TP6 A~D RP6 + + 0x15,0x41,0xA8,0x32,0x30,0x0A, +}; + +const unsigned char WS_20_30_2IN13_V3[159] ={ + 0x80, 0x4A, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x40, 0x4A, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x80, 0x4A, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x40, 0x4A, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0xF, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0xF, 0x0, 0x0, 0xF, 0x0, 0x0, 0x2, + 0xF, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x0, 0x0, 0x0, + 0x22, 0x17, 0x41, 0x0, 0x32, 0x36 +}; + + +const unsigned char lut_vcomDC_2in13d[] = { + 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x60, 0x28, 0x28, 0x00, 0x00, + 0x01, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x12, 0x12, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +const unsigned char lut_ww_2in13d[] = { + 0x40, 0x08, 0x00, 0x00, 0x00, 0x02, 0x90, 0x28, 0x28, 0x00, 0x00, 0x01, 0x40, 0x14, + 0x00, 0x00, 0x00, 0x01, 0xA0, 0x12, 0x12, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +const unsigned char lut_bw_2in13d[] = { + 0x40, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x0F, 0x0F, 0x00, 0x00, 0x03, 0x40, 0x0A, + 0x01, 0x00, 0x00, 0x01, 0xA0, 0x0E, 0x0E, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +const unsigned char lut_wb_2in13d[] = { + 0x80, 0x08, 0x00, 0x00, 0x00, 0x02, 0x90, 0x28, 0x28, 0x00, 0x00, 0x01, 0x80, 0x14, + 0x00, 0x00, 0x00, 0x01, 0x50, 0x12, 0x12, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +const unsigned char lut_bb_2in13d[] = { + 0x80, 0x08, 0x00, 0x00, 0x00, 0x02, 0x90, 0x28, 0x28, 0x00, 0x00, 0x01, 0x80, 0x14, + 0x00, 0x00, 0x00, 0x01, 0x50, 0x12, 0x12, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + + +int EPD_Init_2in13() +{ + int EPD2in13V = 2; + if(EPD2in13V == 1) { + Serial.print("\r\nEPD_Init_2in13 V1"); + EPD_Reset(); + EPD_Send_3(0x01, 249, 0, 0); // DRIVER_OUTPUT_CONTROL: LO(h-1), HI(h-1), GD = 0; SM = 0; TB = 0; + EPD_Send_3(0x0C, 0xD7, 0xD6, 0x9D);// BOOSTER_SOFT_START_CONTROL + EPD_Send_1(0x2C, 0xA8); // WRITE_VCOM_REGISTER: VCOM 7C + EPD_Send_1(0x3A, 0x1A); // SET_DUMMY_LINE_PERIOD: 4 dummy lines per gate + EPD_Send_1(0x3B, 0x08); // SET_GATE_TIME: 2us per line + EPD_Send_1(0x11, 0x03); // DATA_ENTRY_MODE_SETTING: X increment; Y increment + + EPD_lut(0x32, 30, &lut_full_2in13[0]); + return 0; + } else if(EPD2in13V == 2){ + Serial.print("\r\nEPD_Init_2in13 V2"); + EPD_Reset(); + while (digitalRead(PIN_SPI_BUSY) == 1) delay(100); + EPD_SendCommand(0x12); + while (digitalRead(PIN_SPI_BUSY) == 1) delay(100); + EPD_Send_1(0x74, 0x54); + EPD_Send_1(0x7e, 0x3B); + EPD_Send_3(0x01, 0XF9, 0X00, 0X00); + EPD_Send_1(0X11, 0X01); + EPD_Send_2(0X44, 0X00, 0X0F); + EPD_Send_4(0x45, 0xF9, 0x00, 0x00, 0x00); + EPD_Send_1(0X3C, 0X03); + EPD_Send_1(0X2C, 0X55); + EPD_Send_1(0x03, lut_full_2in3v2[70]); + EPD_Send_3(0x04, lut_full_2in3v2[71], lut_full_2in3v2[72], lut_full_2in3v2[73]); + EPD_Send_1(0x3A, lut_full_2in3v2[74]); + EPD_Send_1(0x3B, lut_full_2in3v2[75]); + int count; + EPD_SendCommand(0x32); + for(count = 0; count < 70; count++) + EPD_SendData(lut_full_2in3v2[count]); + EPD_Send_1(0x4E, 0x00); + EPD_Send_2(0x4F, 0xF9, 0x00); + + int Width, Height; + Width = (122 % 8 == 0)? (122 / 8 ): (122 / 8 + 1); + Height = 250; + EPD_SendCommand(0x24); + for (int j = 0; j < Height; j++) { + for (int i = 0; i < Width; i++) { + EPD_SendData(0XFF); + } + } + EPD_SendCommand(0x22); + EPD_SendData(0xC7); + EPD_SendCommand(0x20); + while (digitalRead(PIN_SPI_BUSY) == 1) delay(100); + + return 0; + } +} + +int EPD_Init_2in13_V3() +{ + Serial.print("\r\nEPD_Init_2in13 V3"); + EPD_Reset(); + delay(100); + while (digitalRead(PIN_SPI_BUSY) == 1) delay(10); + EPD_SendCommand(0x12); + while (digitalRead(PIN_SPI_BUSY) == 1) delay(10); + EPD_Send_3(0x01, 0XF9, 0X00, 0X00); + EPD_Send_1(0X11, 0X03); + EPD_Send_2(0X44, 0X00, 0X0F); + EPD_Send_4(0x45, 0x00, 0x00, 0x00, 0xF9); + EPD_Send_1(0x4E, 0x00); + EPD_Send_2(0x4F, 0X00, 0X00); + EPD_Send_1(0x3C, 0x05); + EPD_Send_2(0x21, 0x00, 0x80); + EPD_Send_1(0x18, 0x80); + + while (digitalRead(PIN_SPI_BUSY) == 1) delay(100); + int count; + EPD_SendCommand(0x32); + for(count = 0; count < 153; count++) + EPD_SendData(WS_20_30_2IN13_V3[count]); + EPD_Send_1(0x3f, WS_20_30_2IN13_V3[153]); + EPD_Send_1(0x03, WS_20_30_2IN13_V3[154]); + EPD_Send_3(0x04, WS_20_30_2IN13_V3[155], WS_20_30_2IN13_V3[156], WS_20_30_2IN13_V3[157]); + EPD_Send_1(0x2C, WS_20_30_2IN13_V3[158]); + + int Width, Height; + Width = (122 % 8 == 0)? (122 / 8 ): (122 / 8 + 1); + Height = 250; + EPD_SendCommand(0x24); + for (int j = 0; j < Height; j++) { + for (int i = 0; i < Width; i++) { + EPD_SendData(0XFF); + } + } + + EPD_SendCommand(0x22); + EPD_SendData(0xC7); + EPD_SendCommand(0x20); + while (digitalRead(PIN_SPI_BUSY) == 1) delay(10); + return 0; +} + +/* Show image and turn to deep sleep mode ------*/ +void EPD_2IN13_V3_Show() +{ + Serial.print("\r\n EPD_2IN13_V3_Show"); + // Refresh + EPD_Send_1(0x22, 0xC7); //DISPLAY_UPDATE_CONTROL_2 + EPD_SendCommand(0x20); //MASTER_ACTIVATION + while (digitalRead(PIN_SPI_BUSY) == 1) delay(10); + + // Sleep + EPD_Send_1(0x10, 0x01); //DEEP_SLEEP_MODE + EPD_WaitUntilIdle(); +} + +int EPD_Init_2in13b() +{ + EPD_Reset(); + EPD_Send_3(0x06, 0x17, 0x17, 0x17);// BOOSTER_SOFT_START + EPD_SendCommand(0x04); // POWER_ON + EPD_WaitUntilIdle(); + + EPD_Send_1(0x00, 0x8F); // PANEL_SETTING + EPD_Send_1(0x50, 0x37); // VCOM_AND_DATA_INTERVAL_SETTING + EPD_Send_3(0x61, 0x68, 0, 0xD4); // TCON_RESOLUTION + + EPD_SendCommand(0x10); // DATA_START_TRANSMISSION_1 + delay(2); + return 0; +} + +int EPD_2IN13B_V3_Init(void) +{ + EPD_Reset(); + delay(10); + + EPD_SendCommand(0x04); + EPD_WaitUntilIdle();//waiting for the electronic paper IC to release the idle signal + + EPD_Send_2(0x00, 0x0f, 0x89);//panel setting + + EPD_Send_3(0x61, 0x68, 0x00, 0xd4);//resolution setting + + EPD_Send_1(0X50, 0x77);//VCOM AND DATA INTERVAL SETTING + + EPD_SendCommand(0x10); // DATA_START_TRANSMISSION_1 + delay(2); + return 0; +} + +void EPD_2IN13B_V3_Show() +{ + EPD_SendCommand(0x12); //DISPLAY REFRESH + delay(2); + EPD_WaitUntilIdle(); + + EPD_Send_1(0X50, 0xf7); + EPD_SendCommand(0X02); //power off + EPD_WaitUntilIdle(); //waiting for the electronic paper IC to release the idle signal + EPD_Send_1(0X07, 0xa5); //deep sleep +} + +int EPD_2IN13B_V4_Init(void) +{ + EPD_Reset(); + delay(10); + + EPD_WaitUntilIdle_high(); + EPD_SendCommand(0x12); //SWRESET + EPD_WaitUntilIdle_high(); + + EPD_Send_3(0x01, 0xf9, 0x00, 0x00); //Driver output control + + EPD_Send_1(0x11, 0x03); //data entry mode + + EPD_Send_2(0X44, 0X00, 0X0F); + EPD_Send_4(0x45, 0x00, 0x00, 0x00, 0xF9); + EPD_Send_1(0x4E, 0x00); + EPD_Send_2(0x4F, 0X00, 0X00); + + EPD_Send_1(0x3C, 0x05); //BorderWavefrom + EPD_Send_1(0x18, 0x80); //Read built-in temperature sensor + EPD_Send_2(0x21, 0x80, 0x80); // Display update control + + EPD_WaitUntilIdle_high(); + + EPD_SendCommand(0x24); + + return 0; +} + +void EPD_2IN13B_V4_Show() +{ + EPD_SendCommand(0x20); //DISPLAY REFRESH + delay(2); + EPD_WaitUntilIdle_high(); + + EPD_Send_1(0X10, 0x01); +} + +int EPD_Init_2in13d() +{ + EPD_Reset(); + + EPD_Send_5(0x01, 0x03, 0x00, 0x2b, 0x2b, 0x03);//POWER SETTING + EPD_Send_3(0x06, 0x17, 0x17, 0x17); //BOOSTER_SOFT_START + EPD_SendCommand(0x04); //POWER_ON + EPD_WaitUntilIdle(); + EPD_Send_2(0x00, 0xbf, 0x0d); //PANEL_SETTINGS: LUT from OTP£¬128x296 + EPD_Send_1(0x30, 0x3a); //PLL_SETTINGS: 3a 100HZ, 29 150Hz, 39 200HZ, 31 171HZ, 3c 50hz + EPD_Send_3(0x61, 0x68, 0x00, 0xD4); //TCON_RESOLUTION + EPD_Send_1(0x82, 0x28); //VCOM_DC_SETTINGS + + EPD_SendCommand(0x10); + for (int j = 0; j < 212; j++) for (int i = 0; i < 13; i++) EPD_SendData(0); + delay(10); + + EPD_SendCommand(0x13); + return 0; +} diff --git a/src/epd_panel/epd2in66.h b/src/epd_panel/epd2in66.h new file mode 100644 index 0000000..1c13c20 --- /dev/null +++ b/src/epd_panel/epd2in66.h @@ -0,0 +1,135 @@ +/***************************************************************************** +* | File : EPD_2in66.c +* | Author : Waveshare team +* | Function : 2.66inch e-paper +* | Info : +*---------------- +* | This version: V1.0 +* | Date : 2020-08-10 +* | Info : +* ----------------------------------------------------------------------------- +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documnetation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +******************************************************************************/ + +// Display resolution +#define EPD_2IN66_WIDTH 152 +#define EPD_2IN66_HEIGHT 296 + +/****************************************************************************** +function : Wait until the busy_pin goes LOW +parameter: +******************************************************************************/ +static void EPD_2IN66_ReadBusy(void) +{ + Serial.print("e-Paper busy\r\n"); + delay(100); + while(digitalRead(PIN_SPI_BUSY) == 1) { //LOW: idle, HIGH: busy + delay(100); + } + delay(100); + Serial.print("e-Paper busy release\r\n"); +} + + +/****************************************************************************** +function : Turn On Display +parameter: +******************************************************************************/ +static void EPD_2IN66_Show(void) +{ + EPD_SendCommand(0x20); + EPD_2IN66_ReadBusy(); + Serial.print("EPD_2IN66_Show END\r\n"); + + EPD_SendCommand(0x10);//sleep + EPD_SendData(0x01); +} + +/****************************************************************************** +function : Initialize the e-Paper register +parameter: +******************************************************************************/ +int EPD_2IN66_Init(void) +{ + EPD_Reset(); + EPD_2IN66_ReadBusy(); + EPD_SendCommand(0x12);//soft reset + EPD_2IN66_ReadBusy(); + /* Y increment, X increment */ + EPD_SendCommand(0x11); + EPD_SendData(0x03); + /* Set RamX-address Start/End position */ + EPD_SendCommand(0x44); + EPD_SendData(0x01); + EPD_SendData((EPD_2IN66_WIDTH % 8 == 0)? (EPD_2IN66_WIDTH / 8 ): (EPD_2IN66_WIDTH / 8 + 1) ); + /* Set RamY-address Start/End position */ + EPD_SendCommand(0x45); + EPD_SendData(0); + EPD_SendData(0); + EPD_SendData((EPD_2IN66_HEIGHT&0xff)); + EPD_SendData((EPD_2IN66_HEIGHT&0x100)>>8); + + EPD_2IN66_ReadBusy(); + + EPD_SendCommand(0x24);//show + + return 0; +} + +/****************************************************************************** +function : Initialize the e-Paper register +parameter: +******************************************************************************/ +int EPD_2IN66B_Init(void) +{ + EPD_Reset(); + EPD_2IN66_ReadBusy(); + EPD_SendCommand(0x12);//soft reset + EPD_2IN66_ReadBusy(); + + EPD_SendCommand(0x11); //data entry mode + EPD_SendData(0x03); + + EPD_SendCommand(0x44); // SET_RAM_X_ADDRESS_START_END_POSITION + EPD_SendData((0>>3) & 0x1F); + EPD_SendData(((EPD_2IN66_WIDTH-1)>>3) & 0x1F); + + EPD_SendCommand(0x45); // SET_RAM_Y_ADDRESS_START_END_POSITION + EPD_SendData(0 & 0xFF); + EPD_SendData((0 >> 8) & 0x01); + EPD_SendData((EPD_2IN66_HEIGHT-1) & 0xFF); + EPD_SendData(((EPD_2IN66_HEIGHT-1) >> 8) & 0x01); + + EPD_SendCommand(0x21); // Display update control + EPD_SendData(0x00); + EPD_SendData(0x80); + + EPD_SendCommand(0x4E); // SET_RAM_X_ADDRESS_COUNTER + EPD_SendData(0 & 0x1F); + + EPD_SendCommand(0x4F); // SET_RAM_Y_ADDRESS_COUNTER + EPD_SendData(0 & 0xFF); + EPD_SendData((0 >> 8) & 0x01); + EPD_2IN66_ReadBusy(); + + EPD_SendCommand(0x24);//show + + return 0; +} \ No newline at end of file diff --git a/src/epd_panel/epd2in7.h b/src/epd_panel/epd2in7.h new file mode 100644 index 0000000..d61122b --- /dev/null +++ b/src/epd_panel/epd2in7.h @@ -0,0 +1,240 @@ +/** + ****************************************************************************** + * @file edp2in7.h + * @author Waveshare Team + * @version V1.0.0 + * @date 23-January-2018 + * @brief This file describes initialisation of 2.7 and 2.7b e-Papers + * + ****************************************************************************** + */ +unsigned char lut_dc_2in7[] = +{ + 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x05, 0x00, 0x32, 0x32, + 0x00, 0x00, 0x02, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x05, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +//R21H +unsigned char lut_ww_2in7[] = +{ + 0x50, 0x0F, 0x0F, 0x00, 0x00, 0x05, 0x60, 0x32, 0x32, 0x00, 0x00, 0x02, 0xA0, 0x0F, + 0x0F, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +//R22H r +unsigned char lut_bw_2in7[] = +{ + 0x50, 0x0F, 0x0F, 0x00, 0x00, 0x05, 0x60, 0x32, 0x32, 0x00, 0x00, 0x02, 0xA0, 0x0F, + 0x0F, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +//R24H b +unsigned char lut_bb_2in7[] = +{ + 0xA0, 0x0F, 0x0F, 0x00, 0x00, 0x05, 0x60, 0x32, 0x32, 0x00, 0x00, 0x02, 0x50, 0x0F, + 0x0F, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +//R23H w +unsigned char lut_wb_2in7[] = +{ + 0xA0, 0x0F, 0x0F, 0x00, 0x00, 0x05, 0x60, 0x32, 0x32, 0x00, 0x00, 0x02, 0x50, 0x0F, + 0x0F, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +int EPD_Init_2in7() +{ + EPD_Reset(); + + EPD_SendCommand(0x01);//POWER_SETTING + EPD_SendData(0x03); // VDS_EN, VDG_EN + EPD_SendData(0x00); // VCOM_HV, VGHL_LV[1], VGHL_LV[0] + EPD_SendData(0x2b); // VDH + EPD_SendData(0x2b); // VDL + EPD_SendData(0x09); // VDHR + + EPD_Send_3(0x06, 0x07, 0x07, 0x17);//BOOSTER_SOFT_START + + // Power optimization + EPD_Send_2(0xF8, 0x60, 0xA5); + EPD_Send_2(0xF8, 0x89, 0xA5); + EPD_Send_2(0xF8, 0x90, 0x00); + EPD_Send_2(0xF8, 0x93, 0x2A); + EPD_Send_2(0xF8, 0xA0, 0xA5); + EPD_Send_2(0xF8, 0xA1, 0x00); + EPD_Send_2(0xF8, 0x73, 0x41); + + EPD_Send_1(0x16, 0x00);//PARTIAL_DISPLAY_REFRESH + EPD_SendCommand(0x04);//POWER_ON + EPD_WaitUntilIdle(); + + EPD_Send_1(0x00, 0xAF);//PANEL_SETTING: KW-BF, KWR-AF, BWROTP 0f + EPD_Send_1(0x30, 0x3A);//PLL_CONTROL: 3A 100HZ, 29 150Hz, 39 200HZ, 31 171HZ + EPD_Send_1(0x82, 0x12);//VCM_DC_SETTING_REGISTER + delay(2); + + EPD_lut(0x20,44,&lut_dc_2in7[0]);// LUT_FOR_VCOM + EPD_lut(0x21,42,&lut_ww_2in7[0]);// LUT_WHITE_TO_WHITE + EPD_lut(0x22,42,&lut_bw_2in7[0]);// LUT_BLACK_TO_WHITE + EPD_lut(0x23,42,&lut_wb_2in7[0]);// LUT_WHITE_TO_BLACK + EPD_lut(0x24,42,&lut_bb_2in7[0]);// LUT_BLACK_TO_BLACK + + EPD_SendCommand(0x10);//DATA_START_TRANSMISSION_1 + delay(2); + for(int i = 0; i < 176*264; i++)EPD_SendData(0xFF);//Red channel + + EPD_SendCommand(0x13);//DATA_START_TRANSMISSION_2 + delay(2); + return 0; +} + +int EPD_2IN7_V2_Init(void) +{ + EPD_Reset(); + EPD_WaitUntilIdle_high(); + + EPD_SendCommand(0x12); //SWRESET + EPD_WaitUntilIdle_high(); + + EPD_SendCommand(0x45); //set Ram-Y address start/end position + EPD_SendData(0x00); + EPD_SendData(0x00); + EPD_SendData(0x07); //0x0107-->(263+1)=264 + EPD_SendData(0x01); + + EPD_SendCommand(0x4F); // set RAM y address count to 0; + EPD_SendData(0x00); + EPD_SendData(0x00); + + EPD_SendCommand(0x11); // data entry mode + EPD_SendData(0x03); + + EPD_SendCommand(0x24); + delay(2); + return 0; +} + +void EPD_2IN7_V2_Show(void) +{ + EPD_SendCommand(0x22); //Display Update Control + EPD_SendData(0XF7); + EPD_SendCommand(0x20); //Activate Display Update Sequence + EPD_WaitUntilIdle_high(); + delay(2); + Serial.print("EPD_2IN7_V2_Show END\r\n"); + EPD_SendCommand(0X07); //deep sleep + EPD_SendData(0xA5); +} + + +unsigned char lut_dc_2in7b[] = +{ + 0x00, 0x00, 0x00, 0x1A, 0x1A, 0x00, 0x00, 0x01, 0x00, 0x0A, 0x0A, + 0x00, 0x00, 0x08, 0x00, 0x0E, 0x01, 0x0E, 0x01, 0x10, 0x00, 0x0A, + 0x0A, 0x00, 0x00, 0x08, 0x00, 0x04, 0x10, 0x00, 0x00, 0x05, 0x00, + 0x03, 0x0E, 0x00, 0x00, 0x0A, 0x00, 0x23, 0x00, 0x00, 0x00, 0x01 +}; + +//R21H +unsigned char lut_ww_2in7b[] = +{ + 0x90, 0x1A, 0x1A, 0x00, 0x00, 0x01, 0x40, 0x0A, 0x0A, 0x00, 0x00, 0x08, 0x84, 0x0E, + 0x01, 0x0E, 0x01, 0x10, 0x80, 0x0A, 0x0A, 0x00, 0x00, 0x08, 0x00, 0x04, 0x10, 0x00, + 0x00, 0x05, 0x00, 0x03, 0x0E, 0x00, 0x00, 0x0A, 0x00, 0x23, 0x00, 0x00, 0x00, 0x01 +}; + +//R22H r +unsigned char lut_bw_2in7b[] = +{ + 0xA0, 0x1A, 0x1A, 0x00, 0x00, 0x01, 0x00, 0x0A, 0x0A, 0x00, 0x00, 0x08, 0x84, 0x0E, + 0x01, 0x0E, 0x01, 0x10, 0x90, 0x0A, 0x0A, 0x00, 0x00, 0x08, 0xB0, 0x04, 0x10, 0x00, + 0x00, 0x05, 0xB0, 0x03, 0x0E, 0x00, 0x00, 0x0A, 0xC0, 0x23, 0x00, 0x00, 0x00, 0x01 +}; + +//R23H w +unsigned char lut_bb_2in7b[] = +{ + 0x90, 0x1A, 0x1A, 0x00, 0x00, 0x01, 0x40, 0x0A, 0x0A, 0x00, 0x00, 0x08, 0x84, 0x0E, + 0x01, 0x0E, 0x01, 0x10, 0x80, 0x0A, 0x0A, 0x00, 0x00, 0x08, 0x00, 0x04, 0x10, 0x00, + 0x00, 0x05, 0x00, 0x03, 0x0E, 0x00, 0x00, 0x0A, 0x00, 0x23, 0x00, 0x00, 0x00, 0x01 +}; + +//R24H b +unsigned char lut_wb_2in7b[] = +{ + 0x90, 0x1A, 0x1A, 0x00, 0x00, 0x01, 0x20, 0x0A, 0x0A, 0x00, 0x00, 0x08, 0x84, 0x0E, + 0x01, 0x0E, 0x01, 0x10, 0x10, 0x0A, 0x0A, 0x00, 0x00, 0x08, 0x00, 0x04, 0x10, 0x00, + 0x00, 0x05, 0x00, 0x03, 0x0E, 0x00, 0x00, 0x0A, 0x00, 0x23, 0x00, 0x00, 0x00, 0x01 +}; + +int EPD_Init_2in7b() +{ + EPD_Reset(); + + EPD_SendCommand(0x04);//POWER_ON + EPD_WaitUntilIdle(); + + EPD_Send_1(0x00, 0xAF);//PANEL_SETTING + EPD_Send_1(0x30,0x3A);//PLL_CONTROL: 3A 100HZ, 29 150Hz, 39 200HZ, 31 171HZ + EPD_Send_5(0x01,0x03,0x00,0x2B,0x2B,0x09);//POWER_SETTING + EPD_Send_3(0x06,0x07,0x07,0x17);//BOOSTER_SOFT_START + + // Power optimization + EPD_Send_2(0xF8,0x60,0xA5); + EPD_Send_2(0xF8,0x89,0xA5); + EPD_Send_2(0xF8,0x90,0x00); + EPD_Send_2(0xF8,0x93,0x2A); + EPD_Send_2(0xF8,0x73,0x41); + + EPD_Send_1(0x82,0x12);// VCM_DC_SETTING_REGISTER + EPD_Send_1(0x50,0x87);// VCOM_AND_DATA_INTERVAL_SETTING + + EPD_lut(0x20,44,&lut_dc_2in7b[0]);// LUT_FOR_VCOM + EPD_lut(0x21,42,&lut_ww_2in7b[0]);// LUT_WHITE_TO_WHITE + EPD_lut(0x22,42,&lut_bw_2in7b[0]);// LUT_BLACK_TO_WHITE + EPD_lut(0x23,42,&lut_wb_2in7b[0]);// LUT_WHITE_TO_BLACK + EPD_lut(0x24,42,&lut_bb_2in7b[0]);// LUT_BLACK_TO_BLACK + + EPD_Send_4(0x61, 0, 176, 1, 8);// TCON_RESOLUTION: HI(W), LO(W), HI(H), LO(H) + EPD_Send_1(0x16, 0x00);//PARTIAL_DISPLAY_REFRESH); + + EPD_SendCommand(0x10);//DATA_START_TRANSMISSION_1 + delay(2); + + return 0; +} + +int EPD_Init_2in7b_V2() +{ + EPD_Reset(); + + EPD_WaitUntilIdle_high(); + EPD_SendCommand(0x12); + EPD_WaitUntilIdle_high(); + + EPD_Send_3(0x00, 0x27, 0x01, 0x00); + + EPD_Send_1(0x11, 0x03); + + EPD_Send_2(0x44, 0x00, 0x15); // SET_RAM_X_ADDRESS_START_END_POSITION + EPD_Send_4(0x45, 0x00, 0x00, 0x07, 0x01); // SET_RAM_Y_ADDRESS_START_END_POSITION + + EPD_Send_1(0x4E, 0x00); // SET_RAM_X_ADDRESS_COUNTER + EPD_Send_2(0x4F, 0x00, 0x00); // SET_RAM_Y_ADDRESS_COUNTER + + EPD_SendCommand(0x24); + return 0; +} + +void EPD_2in7b_V2_Show() +{ + EPD_SendCommand(0x20); + EPD_WaitUntilIdle_high(); + EPD_Send_1(0x10, 0x01); +} diff --git a/src/epd_panel/epd2in9.h b/src/epd_panel/epd2in9.h new file mode 100644 index 0000000..0d5ece1 --- /dev/null +++ b/src/epd_panel/epd2in9.h @@ -0,0 +1,177 @@ +/** + ****************************************************************************** + * @file edp2in9.h + * @author Waveshare Team + * @version V1.0.0 + * @date 23-January-2018 + * @brief This file describes initialisation of 2.9 and 2.9b e-Papers + * + ****************************************************************************** + */ +int EPD_Init_2in9() +{ + EPD_Reset(); + EPD_Send_3(0x01, 39, 1, 0);//DRIVER_OUTPUT_CONTROL:LO(EPD_HEIGHT-1),HI(EPD_HEIGHT-1), GD = 0; SM = 0; TB = 0; + EPD_Send_3(0x0C, 0xD7, 0xD6, 0x9D);//BOOSTER_SOFT_START_CONTROL + EPD_Send_1(0x2C, 0xA8);//WRITE_VCOM_REGISTER:VCOM 7C + EPD_Send_1(0x3A, 0x1A);//SET_DUMMY_LINE_PERIOD: 4 dummy lines per gate + EPD_Send_1(0x3B, 0x08);//SET_GATE_TIME: 2us per line + EPD_Send_1(0x11, 0x03);//DATA_ENTRY_MODE_SETTING: X increment; Y increment + + EPD_Send_2(0x44, 0, 15);//SET_RAM_X_ADDRESS_START_END_POSITION: LO(x >> 3), HI ((w-1) >> 3) + EPD_Send_4(0x45, 0, 0, 45, 1);//SET_RAM_Y_ADDRESS_START_END_POSITION: LO(y), HI(y), LO(h - 1),HI(h - 1) + + EPD_Send_1(0x4E, 0);//SET_RAM_X_ADDRESS_COUNTER: LO(x >> 3) + EPD_Send_2(0x4F, 0, 0);//SET_RAM_Y_ADDRESS_COUNTER: LO(y), HI(y) + + EPD_lut(0x32, 30, &lut_full_mono[0]); + + EPD_SendCommand(0x24);//WRITE_RAM + delay(2); + return 0; +} + +int EPD_Init_2in9_V2() +{ + EPD_Reset(); + EPD_WaitUntilIdle_high(); + + EPD_SendCommand(0x12); //SWRESET + EPD_WaitUntilIdle_high(); + EPD_Send_3(0x01, 0x27, 0x01, 0x00);//Driver output control + EPD_Send_1(0x11, 0x03);//data entry mode + EPD_Send_2(0x21, 0x00, 0x80);// Display update control + + EPD_Send_2(0x44, 0x00, 0x0f);// SET_RAM_X_ADDRESS_START_END_POSITION + EPD_Send_4(0x45, 0x00, 0x00, 0x27, 0x01);// SET_RAM_Y_ADDRESS_START_END_POSITION + + EPD_Send_1(0x4e, 0x00);// // SET_RAM_X_ADDRESS_COUNTER + EPD_Send_2(0x4f, 0x00, 0x00);// SET_RAM_Y_ADDRESS_COUNTER + + EPD_WaitUntilIdle_high(); + EPD_SendCommand(0x24);//WRITE_RAM + delay(2); + return 0; +} + +void EPD_2IN9_V2_Show(void) +{ + Serial.printf("EPD_2IN9_V2_Show \r\n"); + EPD_Send_1(0x22, 0xF7); //Display Update Control + EPD_SendCommand(0x20); //Activate Display Update Sequence + EPD_WaitUntilIdle_high(); +} + +int EPD_Init_2in9b() +{ + EPD_Reset(); + EPD_Send_4(0x01, 0x07, 0x00, 0x08, 0x00);//POWER_SETTING + EPD_Send_3(0x06, 0x17, 0x17, 0x17);//BOOSTER_SOFT_START + EPD_SendCommand(0x04);//POWER_ON + EPD_WaitUntilIdle(); + + EPD_Send_1(0x00, 0x8F);//PANEL_SETTING + EPD_Send_1(0x50, 0x77);//VCOM_AND_DATA_INTERVAL_SETTING; + EPD_Send_1(0x30, 0x39);//PLL_CONTROL + EPD_Send_3(0x61, 0x80, 0x01, 0x28);//TCON_RESOLUTION + EPD_Send_1(0x82, 0x0A);//VCM_DC_SETTING_REGISTER + + EPD_SendCommand(0x10);//DATA_START_TRANSMISSION_1 + delay(2); + Serial.printf("EPD_SendCommand b\r\n"); + return 0; +} + + +int EPD_Init_2in9b_V3() +{ + EPD_Reset(); + EPD_SendCommand(0x04);//POWER_ON + EPD_WaitUntilIdle(); + + EPD_Send_2(0x00, 0x0F, 0x89);//PANEL_SETTING + EPD_Send_3(0x61, 0x80, 0x01, 0x28);//TCON_RESOLUTION + EPD_Send_1(0x50, 0x77);//VCOM_AND_DATA_INTERVAL_SETTING; + + EPD_SendCommand(0x10);//DATA_START_TRANSMISSION_1 + delay(2); + return 0; +} + + +/************************************************************************************/ +#define EPD_2IN9D_WIDTH 128 +#define EPD_2IN9D_HEIGHT 296 + + +void EPD_2IN9D_ReadBusy(void) +{ + Serial.print("\r\ne-Paper busy"); + UBYTE busy; + do { + EPD_SendCommand(0x71); + busy = digitalRead(PIN_SPI_BUSY); + busy = !(busy & 0x01); + delay(20); + } while(busy); + delay(20); + Serial.print("\r\ne-Paper busy free"); +} + +void EPD_2IN9D_Show(void) +{ + Serial.print("\r\nEPD_2IN9D_Show"); + EPD_SendCommand(0x12); //DISPLAY REFRESH + delay(10); //!!!The delay here is necessary, 200uS at least!!! + + EPD_2IN9D_ReadBusy(); + delay(200); + // Sleep + EPD_SendCommand(0X50); + EPD_SendData(0xf7); + EPD_SendCommand(0X02); //power off + EPD_2IN9D_ReadBusy(); + EPD_SendCommand(0X07); //deep sleep + EPD_SendData(0xA5); +} + +void EPD_2IN9D_Clear(void) +{ + UWORD Width, Height; + Width = (EPD_2IN9D_WIDTH % 8 == 0)? (EPD_2IN9D_WIDTH / 8 ): (EPD_2IN9D_WIDTH / 8 + 1); + Height = EPD_2IN9D_HEIGHT; + + EPD_SendCommand(0x10); + for (UWORD j = 0; j < Height; j++) { + for (UWORD i = 0; i < Width; i++) { + EPD_SendData(0x00); + } + } + + EPD_SendCommand(0x13); + +} + +int EPD_Init_2in9d() +{ + EPD_Reset(); + + EPD_SendCommand(0x04); + EPD_2IN9D_ReadBusy(); + + EPD_SendCommand(0x00); //panel setting + EPD_SendData(0x1f); //LUT from OTP,128x296 + + EPD_SendCommand(0x61); //resolution setting + EPD_SendData(EPD_2IN9D_WIDTH); + EPD_SendData((EPD_2IN9D_HEIGHT >> 8) & 0xff); + EPD_SendData(EPD_2IN9D_HEIGHT & 0xff); + + EPD_SendCommand(0x50); //vcom_DC setting + EPD_SendData(0x97); + delay(2); + + EPD_2IN9D_Clear(); + + return 0; +} diff --git a/src/epd_panel/epd3in52.h b/src/epd_panel/epd3in52.h new file mode 100644 index 0000000..7503a6d --- /dev/null +++ b/src/epd_panel/epd3in52.h @@ -0,0 +1,246 @@ +/***************************************************************************** +* | File : EPD_3IN52.h +* | Author : Waveshare team +* | Function : 3.52inch e-paper +* | Info : +*---------------- +* | This version: V1.0 +* | Date : 2022-11-02 +* | Info : +* ----------------------------------------------------------------------------- +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documnetation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +******************************************************************************/ + +//GC 0.9S +static const UBYTE EPD_3IN52_lut_R20_GC[] = +{ + 0x01,0x0f,0x0f,0x0f,0x01,0x01,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00 +}; +static const UBYTE EPD_3IN52_lut_R21_GC[] = +{ + 0x01,0x4f,0x8f,0x0f,0x01,0x01,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00 +}; +static const UBYTE EPD_3IN52_lut_R22_GC[] = +{ + 0x01,0x0f,0x8f,0x0f,0x01,0x01,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00 +}; +static const UBYTE EPD_3IN52_lut_R23_GC[] = +{ + 0x01,0x4f,0x8f,0x4f,0x01,0x01,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00 +}; +static const UBYTE EPD_3IN52_lut_R24_GC[] = +{ + 0x01,0x0f,0x8f,0x4f,0x01,0x01,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00 +}; + +UBYTE EPD_3IN52_Flag; + +/****************************************************************************** +function : Read Busy +parameter: +******************************************************************************/ +void EPD_3IN52_ReadBusy(void) +{ + Serial.print("e-Paper busy\r\n"); + UBYTE busy; + do { + busy = digitalRead(PIN_SPI_BUSY); + } while(!busy); + delay(200); + Serial.print("e-Paper busy release\r\n"); +} + +/** + * @brief + * + */ +void EPD_3IN52_refresh(void) +{ + EPD_SendCommand(0x17); + EPD_SendData(0xA5); + EPD_3IN52_ReadBusy(); + delay(200); +} + +// LUT download +void EPD_3IN52_lut_GC(void) +{ + UBYTE count; + EPD_SendCommand(0x20); // vcom + for(count = 0; count < 56 ; count++) + { + EPD_SendData(EPD_3IN52_lut_R20_GC[count]); + } + + EPD_SendCommand(0x21); // red not use + for(count = 0; count < 42 ; count++) + { + EPD_SendData(EPD_3IN52_lut_R21_GC[count]); + } + + EPD_SendCommand(0x24); // bb b + for(count = 0; count < 42 ; count++) + { + EPD_SendData(EPD_3IN52_lut_R24_GC[count]); + } + + if(EPD_3IN52_Flag == 0) + { + EPD_SendCommand(0x22); // bw r + for(count = 0; count < 56 ; count++) + { + EPD_SendData(EPD_3IN52_lut_R22_GC[count]); + } + + EPD_SendCommand(0x23); // wb w + for(count = 0; count < 42 ; count++) + { + EPD_SendData(EPD_3IN52_lut_R23_GC[count]); + } + + EPD_3IN52_Flag = 1; + } + + else + { + EPD_SendCommand(0x22); // bw r + for(count = 0; count < 56 ; count++) + { + EPD_SendData(EPD_3IN52_lut_R23_GC[count]); + } + + EPD_SendCommand(0x23); // wb w + for(count = 0; count < 42 ; count++) + { + EPD_SendData(EPD_3IN52_lut_R22_GC[count]); + } + + EPD_3IN52_Flag = 0; + } +} + + +void EPD_3IN52_Clear(void) +{ + EPD_SendCommand(0x13); + for(int i=0; i<10800; i++) + EPD_SendData(0xFF); + EPD_3IN52_lut_GC(); + EPD_3IN52_refresh(); + + EPD_SendCommand(0x50); + EPD_SendData(0x17); + + delay(500); +} + +/****************************************************************************** +function : Initialize the e-Paper register +parameter: +******************************************************************************/ +int EPD_3IN52_Init(void) +{ + EPD_3IN52_Flag = 0; + EPD_Reset(); + + EPD_SendCommand(0x00); // panel setting PSR + EPD_SendData(0xFF); // RES1 RES0 REG KW/R UD SHL SHD_N RST_N + EPD_SendData(0x01); // x x x VCMZ TS_AUTO TIGE NORG VC_LUTZ + + EPD_SendCommand(0x01); // POWER SETTING PWR + EPD_SendData(0x03); // x x x x x x VDS_EN VDG_EN + EPD_SendData(0x10); // x x x VCOM_SLWE VGH[3:0] VGH=20V, VGL=-20V + EPD_SendData(0x3F); // x x VSH[5:0] VSH = 15V + EPD_SendData(0x3F); // x x VSL[5:0] VSL=-15V + EPD_SendData(0x03); // OPTEN VDHR[6:0] VHDR=6.4V + // T_VDS_OFF[1:0] 00=1 frame; 01=2 frame; 10=3 frame; 11=4 frame + EPD_SendCommand(0x06); // booster soft start BTST + EPD_SendData(0x37); // BT_PHA[7:0] + EPD_SendData(0x3D); // BT_PHB[7:0] + EPD_SendData(0x3D); // x x BT_PHC[5:0] + + EPD_SendCommand(0x60); // TCON setting TCON + EPD_SendData(0x22); // S2G[3:0] G2S[3:0] non-overlap = 12 + + EPD_SendCommand(0x82); // VCOM_DC setting VDCS + EPD_SendData(0x07); // x VDCS[6:0] VCOM_DC value= -1.9v 00~3f,0x12=-1.9v + + EPD_SendCommand(0x30); + EPD_SendData(0x09); + + EPD_SendCommand(0xe3); // power saving PWS + EPD_SendData(0x88); // VCOM_W[3:0] SD_W[3:0] + + EPD_SendCommand(0x61); // resoultion setting + EPD_SendData(0xf0); // HRES[7:3] 0 0 0 + EPD_SendData(0x01); // x x x x x x x VRES[8] + EPD_SendData(0x68); // VRES[7:0] + + EPD_SendCommand(0x50); + EPD_SendData(0xB7); + + EPD_3IN52_Clear(); + + EPD_SendCommand(0x13);//DATA_START_TRANSMISSION_1 + delay(2); + return 0; +} + +void EPD_3IN52_Show(void) +{ + EPD_3IN52_lut_GC(); + EPD_3IN52_refresh(); + delay(2); + Serial.print("EPD_3IN52_Show END\r\n"); + EPD_SendCommand(0X07); //deep sleep + EPD_SendData(0xA5); +} diff --git a/src/epd_panel/epd3in7.h b/src/epd_panel/epd3in7.h new file mode 100644 index 0000000..c86625e --- /dev/null +++ b/src/epd_panel/epd3in7.h @@ -0,0 +1,174 @@ +/***************************************************************************** +* | File : EPD_3IN7.c +* | Author : Waveshare team +* | Function : 3.7inch e-paper +* | Info : +*---------------- +* | This version: V1.0 +* | Date : 2020-08-10 +* | Info : +* ----------------------------------------------------------------------------- +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documnetation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +******************************************************************************/ + +static const UBYTE lut_1Gray_GC[] = +{ +0x2A,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//1 +0x05,0x2A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//2 +0x2A,0x15,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//3 +0x05,0x0A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//4 +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//5 +0x00,0x02,0x03,0x0A,0x00,0x02,0x06,0x0A,0x05,0x00,//6 +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//7 +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//8 +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//9 +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//10 +0x22,0x22,0x22,0x22,0x22 +}; + +static void EPD_3IN7_ReadBusy_HIGH(void) +{ + Serial.print("e-Paper busy\r\n"); + UBYTE busy; + do { + busy = digitalRead(PIN_SPI_BUSY); + } while(busy); + delay(200); + Serial.print("e-Paper busy release\r\n"); +} + +/****************************************************************************** +function : set the look-up tables +parameter: +******************************************************************************/ +static void EPD_3IN7_Load_LUT(void) +{ + UWORD i; + EPD_SendCommand(0x32); + for (i = 0; i < 105; i++) + { + EPD_SendData(lut_1Gray_GC[i]); + } +} + +/****************************************************************************** +function : Initialize the e-Paper register +parameter: +******************************************************************************/ +int EPD_3IN7_1Gray_Init() +{ + EPD_Reset(); + + EPD_SendCommand(0x12); + delay(300); + + EPD_SendCommand(0x46); + EPD_SendData(0xF7); + EPD_3IN7_ReadBusy_HIGH(); + EPD_SendCommand(0x47); + EPD_SendData(0xF7); + EPD_3IN7_ReadBusy_HIGH(); + + EPD_SendCommand(0x01); // setting gaet number + EPD_SendData(0xDF); + EPD_SendData(0x01); + EPD_SendData(0x00); + + EPD_SendCommand(0x03); // set gate voltage + EPD_SendData(0x00); + + EPD_SendCommand(0x04); // set source voltage + EPD_SendData(0x41); + EPD_SendData(0xA8); + EPD_SendData(0x32); + + EPD_SendCommand(0x11); // set data entry sequence + EPD_SendData(0x03); + + EPD_SendCommand(0x3C); // set border + EPD_SendData(0x00); + + EPD_SendCommand(0x0C); // set booster strength + EPD_SendData(0xAE); + EPD_SendData(0xC7); + EPD_SendData(0xC3); + EPD_SendData(0xC0); + EPD_SendData(0xC0); + + EPD_SendCommand(0x18); // set internal sensor on + EPD_SendData(0x80); + + EPD_SendCommand(0x2C); // set vcom value + EPD_SendData(0x44); + + EPD_SendCommand(0x37); // set display option, these setting turn on previous function + EPD_SendData(0x00); //can switch 1 gray or 4 gray + EPD_SendData(0xFF); + EPD_SendData(0xFF); + EPD_SendData(0xFF); + EPD_SendData(0xFF); + EPD_SendData(0x4F); + EPD_SendData(0xFF); + EPD_SendData(0xFF); + EPD_SendData(0xFF); + EPD_SendData(0xFF); + + EPD_SendCommand(0x44); // setting X direction start/end position of RAM + EPD_SendData(0x00); + EPD_SendData(0x00); + EPD_SendData(0x17); + EPD_SendData(0x01); + + EPD_SendCommand(0x45); // setting Y direction start/end position of RAM + EPD_SendData(0x00); + EPD_SendData(0x00); + EPD_SendData(0xDF); + EPD_SendData(0x01); + + EPD_SendCommand(0x22); // Display Update Control 2 + EPD_SendData(0xCF); + + EPD_SendCommand(0x4E);//Set Resolution setting + EPD_SendData(0x00); + EPD_SendData(0x00); + EPD_SendCommand(0x4F); + EPD_SendData(0x00); + EPD_SendData(0x00); + + EPD_SendCommand(0x24);//begin write data to e-Paper + + return 0; +} + +/****************************************************************************** +function : Sends the image buffer in RAM to e-Paper and displays +parameter: +******************************************************************************/ +static void EPD_3IN7_1Gray_Show(void) +{ + EPD_3IN7_Load_LUT(); + EPD_SendCommand(0x20); + EPD_3IN7_ReadBusy_HIGH(); + Serial.print("EPD_3IN7_Show END\r\n"); + + EPD_SendCommand(0X10); //deep sleep + EPD_SendData(0x03); +} diff --git a/src/epd_panel/epd4in01f.h b/src/epd_panel/epd4in01f.h new file mode 100644 index 0000000..88bf246 --- /dev/null +++ b/src/epd_panel/epd4in01f.h @@ -0,0 +1,83 @@ +/** + ****************************************************************************** + * @file edp4in01f.h + * @author Waveshare Team + * @version V1.0.0 + * @date 29-Dec-2020 + * @brief This file describes initialisation of 4.01f e-Papers + * + ****************************************************************************** + */ + +/***************************************************************************** + EPD_4IN01F +******************************************************************************/ + +static void EPD_4IN01F_BusyHigh(void)// If BUSYN=0 then waiting +{ + while(!(digitalRead(PIN_SPI_BUSY))); +} + +static void EPD_4IN01F_BusyLow(void)// If BUSYN=1 then waiting +{ + while(digitalRead(PIN_SPI_BUSY)); +} + +static void EPD_4IN01F_Show(void) +{ + EPD_SendCommand(0x04);//0x04 + EPD_4IN01F_BusyHigh(); + EPD_SendCommand(0x12);//0x12 + EPD_4IN01F_BusyHigh(); + EPD_SendCommand(0x02);//0x02 + EPD_4IN01F_BusyLow(); + delay(200); + Serial.print("EPD_4IN01F_Show END\r\n"); + + delay(100); + EPD_SendCommand(0x07);//sleep + EPD_SendData(0xA5); + delay(100); +} + +int EPD_4IN01F_init() +{ + EPD_Reset(); + EPD_4IN01F_BusyHigh(); + EPD_SendCommand(0x00); + EPD_SendData(0x2f); + EPD_SendData(0x00); + EPD_SendCommand(0x01); + EPD_SendData(0x37); + EPD_SendData(0x00); + EPD_SendData(0x05); + EPD_SendData(0x05); + EPD_SendCommand(0x03); + EPD_SendData(0x00); + EPD_SendCommand(0x06); + EPD_SendData(0xC7); + EPD_SendData(0xC7); + EPD_SendData(0x1D); + EPD_SendCommand(0x41); + EPD_SendData(0x00); + EPD_SendCommand(0x50); + EPD_SendData(0x37); + EPD_SendCommand(0x60); + EPD_SendData(0x22); + EPD_SendCommand(0x61); + EPD_SendData(0x02); + EPD_SendData(0x80); + EPD_SendData(0x01); + EPD_SendData(0x90); + EPD_SendCommand(0xE3); + EPD_SendData(0xAA); + + EPD_SendCommand(0x61);//Set Resolution setting + EPD_SendData(0x02); + EPD_SendData(0x80); + EPD_SendData(0x01); + EPD_SendData(0x90); + EPD_SendCommand(0x10);//begin write data to e-Paper + + return 0; +} diff --git a/src/epd_panel/epd4in2.h b/src/epd_panel/epd4in2.h new file mode 100644 index 0000000..f9c04ec --- /dev/null +++ b/src/epd_panel/epd4in2.h @@ -0,0 +1,169 @@ +/** + ****************************************************************************** + * @file edp4in2.h + * @author Waveshare Team + * @version V1.0.0 + * @date 23-January-2018 + * @brief This file describes initialisation of 4.2 and 4.2b e-Papers + * + ****************************************************************************** + */ + +unsigned char lut_dc_4in2[] = +{ + 0x00, 0x17, 0x00, 0x00, 0x00, 0x02, 0x00, 0x17, 0x17, 0x00, 0x00, + 0x02, 0x00, 0x0A, 0x01, 0x00, 0x00, 0x01, 0x00, 0x0E, 0x0E, 0x00, + 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +//R21H +unsigned char lut_ww_4in2[] = +{ + 0x40, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, 0x40, 0x0A, + 0x01, 0x00, 0x00, 0x01, 0xA0, 0x0E, 0x0E, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +//R22H r +unsigned char lut_bw_4in2[] = +{ + 0x40, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, 0x40, 0x0A, + 0x01, 0x00, 0x00, 0x01, 0xA0, 0x0E, 0x0E, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +//R24H b +unsigned char lut_bb_4in2[] = +{ + 0x80, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, 0x80, 0x0A, + 0x01, 0x00, 0x00, 0x01, 0x50, 0x0E, 0x0E, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +//R23H w +unsigned char lut_wb_4in2[] = +{ + 0x80, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, 0x80, 0x0A, + 0x01, 0x00, 0x00, 0x01, 0x50, 0x0E, 0x0E, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + + +int EPD_Init_4in2() +{ + EPD_Reset(); + + EPD_SendCommand(0x01);//POWER_SETTING + EPD_SendData(0x03); // VDS_EN, VDG_EN + EPD_SendData(0x00); // VCOM_HV, VGHL_LV[1], VGHL_LV[0] + EPD_SendData(0x2F); // VDH + EPD_SendData(0x2F); // VDL + EPD_SendData(0xFF); // VDHR + + EPD_Send_3(0x06, 0x17, 0x17, 0x17);//BOOSTER_SOFT_START + EPD_SendCommand(0x04);//POWER_ON + EPD_WaitUntilIdle(); + + EPD_Send_2(0x00, 0xBF, 0x0B);//PANEL_SETTING: // KW-BF KWR-AF BWROTP 0f + EPD_Send_1(0x30, 0x3C);//PLL_CONTROL: 3A 100HZ, 29 150Hz, 39 200HZ, 31 171HZ + + EPD_Send_4(0x61, 1, 144, 1, 44);// RESOLUTION_SETTING: HI(W), LO(W), HI(H), LO(H) + EPD_Send_1(0x82, 0x12);// VCM_DC_SETTING + EPD_Send_1(0x50, 0x97);// VCOM_AND_DATA_INTERVAL_SETTING: VBDF 17|D7 VBDW 97 VBDB 57 VBDF F7 VBDW 77 VBDB 37 VBDR B7 + + EPD_lut(0x20,44,&lut_dc_4in2[0]);// LUT_FOR_VCOM + EPD_lut(0x21,42,&lut_ww_4in2[0]);// LUT_WHITE_TO_WHITE + EPD_lut(0x22,42,&lut_bw_4in2[0]);// LUT_BLACK_TO_WHITE + EPD_lut(0x23,42,&lut_wb_4in2[0]);// LUT_WHITE_TO_BLACK + EPD_lut(0x24,42,&lut_bb_4in2[0]);// LUT_BLACK_TO_BLACK + + EPD_SendCommand(0x10);//DATA_START_TRANSMISSION_1 + delay(2); + for(int i = 0; i < 400*300; i++)EPD_SendData(0xFF);//Red channel + + EPD_SendCommand(0x13);//DATA_START_TRANSMISSION_2 + delay(2); + return 0; + +} + +unsigned char lut_dc_4in2b[] = +{ + 0x00, 0x17, 0x00, 0x00, 0x00, 0x02, 0x00, 0x17, 0x17, 0x00, 0x00, + 0x02, 0x00, 0x0A, 0x01, 0x00, 0x00, 0x01, 0x00, 0x0E, 0x0E, 0x00, + 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +//R21H +unsigned char lut_ww_4in2b[] = +{ + 0x40, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, 0x40, 0x0A, + 0x01, 0x00, 0x00, 0x01, 0xA0, 0x0E, 0x0E, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +//R22H r +unsigned char lut_bw_4in2b[] = +{ + 0x40, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, 0x40, 0x0A, + 0x01, 0x00, 0x00, 0x01, 0xA0, 0x0E, 0x0E, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +//R24H b +unsigned char lut_bb_4in2b[] = +{ + 0x80, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, 0x80, 0x0A, + 0x01, 0x00, 0x00, 0x01, 0x50, 0x0E, 0x0E, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +//R23H w +unsigned char lut_wb_4in2b[] = +{ + 0x80, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, 0x80, 0x0A, + 0x01, 0x00, 0x00, 0x01, 0x50, 0x0E, 0x0E, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +int EPD_Init_4in2b() +{ + EPD_Reset(); + EPD_Send_3(0x06,0x17,0x17,0x17);//BOOSTER_SOFT_START + EPD_SendCommand(0x04);//POWER_ON + EPD_WaitUntilIdle(); + EPD_Send_1(0x00, 0x0F);//PANEL_SETTING + EPD_Send_1(0x50,0xF7);// VCOM_AND_DATA_INTERVAL_SETTING + + EPD_SendCommand(0x10);//DATA_START_TRANSMISSION_1 + delay(2); + return 0; +} + +int EPD_Init_4in2b_V2() +{ + EPD_Reset(); + + EPD_SendCommand(0x04); + EPD_WaitUntilIdle(); + EPD_Send_1(0x00, 0x0F);//PANEL_SETTING + + EPD_SendCommand(0x10);//DATA_START_TRANSMISSION_1 + delay(2); + return 0; +} + +void EPD_4IN2B_V2_Show(void) +{ + EPD_SendCommand(0x12); // DISPLAY_REFRESH + delay(100); + EPD_WaitUntilIdle(); + + EPD_Send_1(0X50, 0xf7); + EPD_SendCommand(0X02); //power off + EPD_WaitUntilIdle(); //waiting for the electronic paper IC to release the idle signal + EPD_Send_1(0X07, 0xf7); //deep sleep +} + diff --git a/src/epd_panel/epd5in65f.h b/src/epd_panel/epd5in65f.h new file mode 100644 index 0000000..c0261f5 --- /dev/null +++ b/src/epd_panel/epd5in65f.h @@ -0,0 +1,90 @@ +/** + ****************************************************************************** + * @file edp5in65.h + * @author Waveshare Team + * @version V1.0.0 + * @date 05-August-2020 + * @brief This file describes initialisation of 5.65f e-Papers + * + ****************************************************************************** + */ + +/***************************************************************************** + EPD_5IN65F +******************************************************************************/ + +static void EPD_5IN65F_BusyHigh(void)// If BUSYN=0 then waiting +{ + while(!(digitalRead(PIN_SPI_BUSY))); +} + +static void EPD_5IN65F_BusyLow(void)// If BUSYN=1 then waiting +{ + while(digitalRead(PIN_SPI_BUSY)); +} + +static void EPD_5IN65F_Show(void) +{ + EPD_SendCommand(0x04);//0x04 + EPD_5IN65F_BusyHigh(); + EPD_SendCommand(0x12);//0x12 + EPD_5IN65F_BusyHigh(); + EPD_SendCommand(0x02);//0x02 + EPD_5IN65F_BusyLow(); + delay(200); + Serial.print("EPD_5IN65F_Show END\r\n"); + + delay(100); + EPD_SendCommand(0x07);//sleep + EPD_SendData(0xA5); + delay(100); +} + +int EPD_5IN65F_init() +{ + EPD_Reset(); + + EPD_5IN65F_BusyHigh(); + EPD_SendCommand(0x00); + EPD_SendData(0xEF); + EPD_SendData(0x08); + EPD_SendCommand(0x01); + EPD_SendData(0x37); + EPD_SendData(0x00); + EPD_SendData(0x23); + EPD_SendData(0x23); + EPD_SendCommand(0x03); + EPD_SendData(0x00); + EPD_SendCommand(0x06); + EPD_SendData(0xC7); + EPD_SendData(0xC7); + EPD_SendData(0x1D); + EPD_SendCommand(0x30); + EPD_SendData(0x3C); + EPD_SendCommand(0x41); + EPD_SendData(0x00); + EPD_SendCommand(0x50); + EPD_SendData(0x37); + EPD_SendCommand(0x60); + EPD_SendData(0x22); + EPD_SendCommand(0x61); + EPD_SendData(0x02); + EPD_SendData(0x58); + EPD_SendData(0x01); + EPD_SendData(0xC0); + EPD_SendCommand(0xE3); + EPD_SendData(0xAA); + + delay(100); + EPD_SendCommand(0x50); + EPD_SendData(0x37); + + EPD_SendCommand(0x61);//Set Resolution setting + EPD_SendData(0x02); + EPD_SendData(0x58); + EPD_SendData(0x01); + EPD_SendData(0xC0); + EPD_SendCommand(0x10);//begin write data to e-Paper + + return 0; +} diff --git a/src/epd_panel/epd5in83.h b/src/epd_panel/epd5in83.h new file mode 100644 index 0000000..afbf4e5 --- /dev/null +++ b/src/epd_panel/epd5in83.h @@ -0,0 +1,92 @@ +/** + ****************************************************************************** + * @file edp5in83.h + * @author Waveshare Team + * @version V1.0.0 + * @date 8-September-2018 + * @brief This file describes initialisation of 5.83, 5.83b, 5.83c e-Papers + * + ****************************************************************************** + */ + +int EPD_Init_5in83() +{ + EPD_Reset(); + EPD_Send_2(0x01, 0x37, 0x00); // POWER_SETTING + EPD_Send_2(0x00, 0xCF, 0x08); // PANEL_SETTING + EPD_Send_3(0x06, 0xC7, 0xCC, 0x28); // BOOSTER_SOFT_START + EPD_SendCommand(0x4); // POWER_ON + EPD_WaitUntilIdle(); + EPD_Send_1(0x30, 0x3C); // PLL_CONTROL + EPD_Send_1(0x41, 0x00); // TEMPERATURE_CALIBRATION + EPD_Send_1(0x50, 0x77); // VCOM_AND_DATA_INTERVAL_SETTING + EPD_Send_1(0x60, 0x22); // TCON_SETTING + EPD_Send_4(0x61, 0x02, 0x58, 0x01, 0xC0);// TCON_RESOLUTION + EPD_Send_1(0x82, 0x1E); // VCM_DC_SETTING: decide by LUT file + EPD_Send_1(0xE5, 0x03); // FLASH MODE + EPD_SendCommand(0x10); // DATA_START_TRANSMISSION_1 + delay(2); + return 0; +} + +int EPD_Init_5in83_V2() +{ + EPD_Reset(); + + EPD_Send_4(0x01, 0x07, 0x07, 0x3f, 0x3f); // POWER_SETTING + + EPD_SendCommand(0x04); // POWER_ON + delay(100); + EPD_WaitUntilIdle(); + + EPD_Send_1(0x00, 0x1F); // PANEL_SETTING + EPD_Send_4(0x61, 0x02, 0x88, 0x01, 0xE0);// TCON_RESOLUTION + EPD_Send_1(0X15, 0x00); + EPD_Send_2(0X50, 0x10, 0x07); + EPD_Send_1(0X60, 0x22); + + EPD_SendCommand(0x10); // DATA_START_TRANSMISSION_1 + for(UDOUBLE i=0; i<38800; i++) { + EPD_SendData(0x00); + } + EPD_SendCommand(0x13); // DATA_START_TRANSMISSION_2 + delay(2); + return 0; +} + +int EPD_Init_5in83b() +{ + EPD_Reset(); + EPD_Send_2(0x01, 0x37, 0x00); // POWER_SETTING + EPD_Send_2(0x00, 0xCF, 0x08); // PANEL_SETTING + EPD_Send_3(0x06, 0xC7, 0xCC, 0x28); // BOOSTER_SOFT_START + EPD_SendCommand(0x4); // POWER_ON + EPD_WaitUntilIdle(); + EPD_Send_1(0x30, 0x3A); // PLL_CONTROL + EPD_Send_1(0x41, 0x00); // TEMPERATURE_CALIBRATION + EPD_Send_1(0x50, 0x77); // VCOM_AND_DATA_INTERVAL_SETTING + EPD_Send_1(0x60, 0x22); // TCON_SETTING + EPD_Send_4(0x61, 0x02, 0x58, 0x01, 0xC0);// TCON_RESOLUTION + EPD_Send_1(0x82, 0x20); // VCM_DC_SETTING: decide by LUT file + EPD_Send_1(0xE5, 0x03); // FLASH MODE + EPD_SendCommand(0x10); // DATA_START_TRANSMISSION_1 + delay(2); + return 0; +} + +int EPD_5in83b_V2_init() +{ + EPD_Reset(); + EPD_Send_4(0x01, 0x07, 0x07, 0x3f, 0x3f); //POWER SETTING + EPD_SendCommand(0x04); //POWER ON + delay(100); + EPD_WaitUntilIdle(); //waiting for the electronic paper IC to release the idle signal + EPD_Send_1(0X00, 0x0F); //PANNEL SETTING + EPD_Send_4(0x61, 0x02, 0x88, 0x01, 0xe0); //tres + EPD_Send_1(0X15, 0x00); + EPD_Send_2(0X50, 0x11, 0x07); //VCOM AND DATA INTERVAL SETTING + EPD_Send_1(0X60, 0x22); //TCON SETTING + EPD_SendCommand(0x10); // DATA_START_TRANSMISSION_1 + delay(2); + return 0; +} diff --git a/src/epd_panel/epd7in3e.h b/src/epd_panel/epd7in3e.h new file mode 100644 index 0000000..bc7f8cf --- /dev/null +++ b/src/epd_panel/epd7in3e.h @@ -0,0 +1,156 @@ +/** + ****************************************************************************** + * @file edp7in3e.h + * @author Waveshare Team + * @version V1.0.0 + * @date 29-Dec-2020 + * @brief This file describes initialisation of 7.3f e-Papers + * + ****************************************************************************** + */ + + /********************************** +Color Index +**********************************/ +#define EPD_7IN3E_BLACK 0x0 /// 000 +#define EPD_7IN3E_WHITE 0x1 /// 001 +#define EPD_7IN3E_YELLOW 0x2 /// 010 +#define EPD_7IN3E_RED 0x3 /// 011 +#define EPD_7IN3E_ORANGE 0x4 /// 100 +#define EPD_7IN3E_BLUE 0x5 /// 101 +#define EPD_7IN3E_GREEN 0x6 /// 110 + +#include +static void EPD_7IN3E_BusyHigh(void)// If BUSYN=0 then waiting +{ + while(!(digitalRead(PIN_SPI_BUSY))); +} + +static void EPD_7IN3E_BusyLow(void)// If BUSYN=1 then waiting +{ + while(digitalRead(PIN_SPI_BUSY)); +} + + +static void EPD_7IN3E_Show(void) +{ + Serial.println("EPD_7IN3E_Show Begin"); + + Serial.println("Turn on display."); + // turn on display + EPD_SendCommand(0x04);//0x04 + EPD_7IN3E_BusyHigh(); + + //Second setting + EPD_SendCommand(0x06); + EPD_SendData(0x6F); + EPD_SendData(0x1F); + EPD_SendData(0x1F); + EPD_SendData(0x22); + + EPD_SendCommand(0x12);//0x12 + EPD_SendData(0x00); + EPD_7IN3E_BusyHigh(); + + // sleep + EPD_SendCommand(0x02);//0x02 + EPD_SendData(0x00); + EPD_7IN3E_BusyHigh(); + + delay(200); + Serial.print("EPD_7IN3E_Show END\r\n"); + + // go to sleep + delay(100); + EPD_SendCommand(0x07);//deep sleep + EPD_SendData(0xA5); + delay(100); +} + +int EPD_7IN3E_init() +{ + Serial.print("EPD_7IN3E_init Begin\r\n"); + EPD_Reset(); + EPD_7IN3E_BusyHigh(); + + EPD_SendCommand(0xAA); // CMDH + EPD_SendData(0x49); + EPD_SendData(0x55); + EPD_SendData(0x20); + EPD_SendData(0x08); + EPD_SendData(0x09); + EPD_SendData(0x18); + + // PWRR + EPD_SendCommand(0x01); + EPD_SendData(0x3F); + + // PSR + EPD_SendCommand(0x00); + EPD_SendData(0x5F); + EPD_SendData(0x69); + + // POFS + EPD_SendCommand(0x03); + EPD_SendData(0x00); + EPD_SendData(0x54); + EPD_SendData(0x00); + EPD_SendData(0x44); + + // BTST1 + EPD_SendCommand(0x05); + EPD_SendData(0x40); + EPD_SendData(0x1F); + EPD_SendData(0x1F); + EPD_SendData(0x2C); + + // BTST2 + EPD_SendCommand(0x06); + EPD_SendData(0x6F); + EPD_SendData(0x1F); + EPD_SendData(0x1F); + EPD_SendData(0x22); + + // BTST3 + EPD_SendCommand(0x08); + EPD_SendData(0x6F); + EPD_SendData(0x1F); + EPD_SendData(0x1F); + EPD_SendData(0x22); + + // PLL + EPD_SendCommand(0x30); + // EPD_SendData(0x03); + EPD_SendData(0x08); + + // CDI + EPD_SendCommand(0x50); + EPD_SendData(0x3F); + + // TCON + EPD_SendCommand(0x60); + EPD_SendData(0x02); + EPD_SendData(0x00); + + // TRES + EPD_SendCommand(0x61); + EPD_SendData(0x03); + EPD_SendData(0x20); + EPD_SendData(0x01); + EPD_SendData(0xE0); + + // T_VDCS + EPD_SendCommand(0x84); + EPD_SendData(0x01); + + // PWS + EPD_SendCommand(0xE3); + EPD_SendData(0x2F); + + + EPD_SendCommand(0x10); //begin write data to e-Paper + + Serial.print("EPD_7IN3E_init End\r\n"); + + return 0; +} diff --git a/src/epd_panel/epd7in3f.h b/src/epd_panel/epd7in3f.h new file mode 100644 index 0000000..81da9f6 --- /dev/null +++ b/src/epd_panel/epd7in3f.h @@ -0,0 +1,155 @@ +/** + ****************************************************************************** + * @file edp7in3f.h + * @author Waveshare Team + * @version V1.0.0 + * @date 29-Dec-2020 + * @brief This file describes initialisation of 7.3f e-Papers + * + ****************************************************************************** + */ + +/***************************************************************************** + EPD_4IN01F +******************************************************************************/ +#include +static void EPD_7IN3F_BusyHigh(void)// If BUSYN=0 then waiting +{ + while(!(digitalRead(PIN_SPI_BUSY))); +} + +static void EPD_7IN3F_BusyLow(void)// If BUSYN=1 then waiting +{ + while(digitalRead(PIN_SPI_BUSY)); +} + +static void EPD_7IN3F_Show(void) +{ + Serial.println("EPD_7IN3F_Show Begin"); + + Serial.println("Turn on display."); + // turn on display + EPD_SendCommand(0x04);//0x04 + EPD_7IN3F_BusyHigh(); + + EPD_SendCommand(0x12);//0x12 + EPD_SendData(0x00); + EPD_7IN3F_BusyHigh(); + + EPD_SendCommand(0x02);//0x02 + EPD_SendData(0x00); + EPD_7IN3F_BusyHigh(); + + delay(200); + Serial.print("EPD_7IN3F_Show END\r\n"); + + // go to sleep + delay(100); + EPD_SendCommand(0x07);//sleep + EPD_SendData(0xA5); + delay(100); +} + +int EPD_7IN3F_init() +{ + Serial.print("EPD_7IN3F_init Begin\r\n"); + EPD_Reset(); + EPD_7IN3F_BusyHigh(); + + EPD_SendCommand(0xAA); // CMDH + EPD_SendData(0x49); + EPD_SendData(0x55); + EPD_SendData(0x20); + EPD_SendData(0x08); + EPD_SendData(0x09); + EPD_SendData(0x18); + + EPD_SendCommand(0x01); + EPD_SendData(0x3F); + EPD_SendData(0x00); + EPD_SendData(0x32); + EPD_SendData(0x2A); + EPD_SendData(0x0E); + EPD_SendData(0x2A); + + EPD_SendCommand(0x00); + EPD_SendData(0x5F); + EPD_SendData(0x69); + + EPD_SendCommand(0x03); + EPD_SendData(0x00); + EPD_SendData(0x54); + EPD_SendData(0x00); + EPD_SendData(0x44); + + EPD_SendCommand(0x05); + EPD_SendData(0x40); + EPD_SendData(0x1F); + EPD_SendData(0x1F); + EPD_SendData(0x2C); + + EPD_SendCommand(0x06); + EPD_SendData(0x6F); + EPD_SendData(0x1F); + EPD_SendData(0x1F); + EPD_SendData(0x22); + + EPD_SendCommand(0x08); + EPD_SendData(0x6F); + EPD_SendData(0x1F); + EPD_SendData(0x1F); + EPD_SendData(0x22); + + EPD_SendCommand(0x13); // IPC + EPD_SendData(0x00); + EPD_SendData(0x04); + + EPD_SendCommand(0x30); + EPD_SendData(0x3C); + + EPD_SendCommand(0x41); // TSE + EPD_SendData(0x00); + + EPD_SendCommand(0x50); + EPD_SendData(0x3F); + + EPD_SendCommand(0x60); + EPD_SendData(0x02); + EPD_SendData(0x00); + + EPD_SendCommand(0x61); + EPD_SendData(0x03); + EPD_SendData(0x20); + EPD_SendData(0x01); + EPD_SendData(0xE0); + + EPD_SendCommand(0x82); + EPD_SendData(0x1E); + + EPD_SendCommand(0x84); + EPD_SendData(0x00); + + EPD_SendCommand(0x86); // AGID + EPD_SendData(0x00); + + EPD_SendCommand(0xE3); + EPD_SendData(0x2F); + + EPD_SendCommand(0xE0); // CCSET + EPD_SendData(0x00); + + EPD_SendCommand(0xE6); // TSSET + EPD_SendData(0x00); + + // config resolution + EPD_SendCommand(0x61); + EPD_SendData(0x03); + EPD_SendData(0x20); + EPD_SendData(0x01); + EPD_SendData(0xE0); + EPD_SendCommand(0x10); //begin write data to e-Paper + + Serial.print("EPD_7IN3F_init End\r\n"); + + return 0; +} diff --git a/src/epd_panel/epd7in5.h b/src/epd_panel/epd7in5.h new file mode 100644 index 0000000..b0734b0 --- /dev/null +++ b/src/epd_panel/epd7in5.h @@ -0,0 +1,264 @@ +/** + ****************************************************************************** + * @file edp7in5.h + * @author Waveshare Team + * @version V1.0.0 + * @date 23-January-2018 + * @brief This file describes initialisation of 7.5 and 7.5b e-Papers + * + ****************************************************************************** + */ + +int EPD_Init_7in5() +{ + EPD_Reset(); + EPD_Send_2(0x01, 0x37, 0x00); //POWER_SETTING + EPD_Send_2(0x00, 0xCF, 0x08); //PANEL_SETTING + EPD_Send_3(0x06, 0xC7, 0xCC, 0x28); //BOOSTER_SOFT_START + EPD_SendCommand(0x4); //POWER_ON + EPD_WaitUntilIdle(); + EPD_Send_1(0x30, 0x3C); //PLL_CONTROL + EPD_Send_1(0x41, 0x00); //TEMPERATURE_CALIBRATION + EPD_Send_1(0x50, 0x77); //VCOM_AND_DATA_INTERVAL_SETTING + EPD_Send_1(0x60, 0x22); //TCON_SETTING + EPD_Send_4(0x61, 0x02, 0x80, 0x01, 0x80);//TCON_RESOLUTION + EPD_Send_1(0x82, 0x1E); //VCM_DC_SETTING: decide by LUT file + EPD_Send_1(0xE5, 0x03); //FLASH MODE + + EPD_SendCommand(0x10);//DATA_START_TRANSMISSION_1 + delay(2); + return 0; +} + +/***************************************************************************** + EPD_7in5_V2 +******************************************************************************/ +UBYTE Voltage_Frame_7IN5_V2[]={ + 0x6, 0x3F, 0x3F, 0x11, 0x24, 0x7, 0x17, +}; + +UBYTE LUT_VCOM_7IN5_V2[]={ + 0x0, 0xF, 0xF, 0x0, 0x0, 0x1, + 0x0, 0xF, 0x1, 0xF, 0x1, 0x2, + 0x0, 0xF, 0xF, 0x0, 0x0, 0x1, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, +}; + +UBYTE LUT_WW_7IN5_V2[]={ + 0x10, 0xF, 0xF, 0x0, 0x0, 0x1, + 0x84, 0xF, 0x1, 0xF, 0x1, 0x2, + 0x20, 0xF, 0xF, 0x0, 0x0, 0x1, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, +}; + +UBYTE LUT_BW_7IN5_V2[]={ + 0x10, 0xF, 0xF, 0x0, 0x0, 0x1, + 0x84, 0xF, 0x1, 0xF, 0x1, 0x2, + 0x20, 0xF, 0xF, 0x0, 0x0, 0x1, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, +}; + +UBYTE LUT_WB_7IN5_V2[]={ + 0x80, 0xF, 0xF, 0x0, 0x0, 0x3, + 0x84, 0xF, 0x1, 0xF, 0x1, 0x4, + 0x40, 0xF, 0xF, 0x0, 0x0, 0x3, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, +}; + +UBYTE LUT_BB_7IN5_V2[]={ + 0x80, 0xF, 0xF, 0x0, 0x0, 0x1, + 0x84, 0xF, 0x1, 0xF, 0x1, 0x2, + 0x40, 0xF, 0xF, 0x0, 0x0, 0x1, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, +}; + +static void EPD_7in5_V2_Readbusy(void) +{ + Serial.print("\r\ne-Paper busy\r\n"); + unsigned char busy; + do{ + EPD_SendCommand(0x71); + busy = digitalRead(PIN_SPI_BUSY); + busy =!(busy & 0x01); + delay(1); + }while(busy); + delay(200); + Serial.print("e-Paper busy release\r\n"); +} + +static void EPD_7IN5_V2_Show(void) +{ + EPD_SendCommand(0x12); //DISPLAY REFRESH + delay(100); //!!!The delay here is necessary, 200uS at least!!! + EPD_7in5_V2_Readbusy(); + + //Enter sleep mode + EPD_SendCommand(0X02); //power off + EPD_7in5_V2_Readbusy(); + EPD_SendCommand(0X07); //deep sleep + EPD_SendData(0xA5); +} + +static void EPD_7IN5_V2_LUT(UBYTE* lut_vcom, UBYTE* lut_ww, UBYTE* lut_bw, UBYTE* lut_wb, UBYTE* lut_bb) +{ + UBYTE count; + + EPD_SendCommand(0x20); //VCOM + for(count=0; count<60; count++) + EPD_SendData(lut_vcom[count]); + + EPD_SendCommand(0x21); //LUTBW + for(count=0; count<60; count++) + EPD_SendData(lut_ww[count]); + + EPD_SendCommand(0x22); //LUTBW + for(count=0; count<60; count++) + EPD_SendData(lut_bw[count]); + + EPD_SendCommand(0x23); //LUTWB + for(count=0; count<60; count++) + EPD_SendData(lut_wb[count]); + + EPD_SendCommand(0x24); //LUTBB + for(count=0; count<60; count++) + EPD_SendData(lut_bb[count]); +} + +int EPD_7in5_V2_init() +{ + EPD_Reset(); + + // EPD_SendCommand(0x01); //POWER SETTING + // EPD_SendData(0x07); + // EPD_SendData(0x07); //VGH=20V,VGL=-20V + // EPD_SendData(0x3f); //VDH=15V + // EPD_SendData(0x3f); //VDL=-15V + + EPD_SendCommand(0x01); // power setting + EPD_SendData(0x17); // 1-0=11: internal power + EPD_SendData(*(Voltage_Frame_7IN5_V2+6)); // VGH&VGL + EPD_SendData(*(Voltage_Frame_7IN5_V2+1)); // VSH + EPD_SendData(*(Voltage_Frame_7IN5_V2+2)); // VSL + EPD_SendData(*(Voltage_Frame_7IN5_V2+3)); // VSHR + + EPD_SendCommand(0x82); // VCOM DC Setting + EPD_SendData(*(Voltage_Frame_7IN5_V2+4)); // VCOM + + EPD_SendCommand(0x06); // Booster Setting + EPD_SendData(0x27); + EPD_SendData(0x27); + EPD_SendData(0x2F); + EPD_SendData(0x17); + + EPD_SendCommand(0x04); //POWER ON + delay(100); + EPD_7in5_V2_Readbusy(); + + EPD_SendCommand(0X00); //PANNEL SETTING + EPD_SendData(0x3F); //KW-3f KWR-2F BWROTP 0f BWOTP 1f + + EPD_SendCommand(0x61); //tres + EPD_SendData(0x03); //source 800 + EPD_SendData(0x20); + EPD_SendData(0x01); //gate 480 + EPD_SendData(0xE0); + + EPD_SendCommand(0X15); + EPD_SendData(0x00); + + EPD_SendCommand(0X50); //VCOM AND DATA INTERVAL SETTING + EPD_SendData(0x10); + EPD_SendData(0x00); + + EPD_SendCommand(0X60); //TCON SETTING + EPD_SendData(0x22); + + EPD_SendCommand(0x65); // Resolution setting + EPD_SendData(0x00); + EPD_SendData(0x00);//800*480 + EPD_SendData(0x00); + EPD_SendData(0x00); + + EPD_7IN5_V2_LUT(LUT_VCOM_7IN5_V2, LUT_WW_7IN5_V2, LUT_BW_7IN5_V2, LUT_WB_7IN5_V2, LUT_BB_7IN5_V2); + + EPD_SendCommand(0x10); + for(UWORD i=0; i<800 / 8 *480; i++) { + EPD_SendData(0x00); + } + + EPD_SendCommand(0x13); + return 0; +} + +/***************************************************************************** + EPD_7in5B_V2 +******************************************************************************/ + +int EPD_7in5B_V2_Init(void) +{ + EPD_Reset(); + + EPD_SendCommand(0x01); //POWER SETTING + EPD_SendData(0x07); + EPD_SendData(0x07); //VGH=20V,VGL=-20V + EPD_SendData(0x3f); //VDH=15V + EPD_SendData(0x3f); //VDL=-15V + + EPD_SendCommand(0x04); //POWER ON + delay(100); + EPD_7in5_V2_Readbusy(); + + EPD_SendCommand(0X00); //PANNEL SETTING + EPD_SendData(0x0F); //KW-3f KWR-2F BWROTP 0f BWOTP 1f + + EPD_SendCommand(0x61); //tres + EPD_SendData(0x03); //source 800 + EPD_SendData(0x20); + EPD_SendData(0x01); //gate 480 + EPD_SendData(0xE0); + + EPD_SendCommand(0X15); + EPD_SendData(0x00); + + EPD_SendCommand(0X50); //VCOM AND DATA INTERVAL SETTING + EPD_SendData(0x11); + EPD_SendData(0x07); + + EPD_SendCommand(0X60); //TCON SETTING + EPD_SendData(0x22); + + EPD_SendCommand(0x65); // Resolution setting + EPD_SendData(0x00); + EPD_SendData(0x00);//800*480 + EPD_SendData(0x00); + EPD_SendData(0x00); + + // UWORD i; + // EPD_SendCommand(0x10); + // for(i=0; i<800 / 8 *480; i++) { + // EPD_SendData(0x00); + + // } + // EPD_SendCommand(0x13); + // for(i=0; i<800 / 8 *480; i++) { + // EPD_SendData(0x00); + // } + + EPD_SendCommand(0x10); + return 0; +} diff --git a/src/epd_panel/epd7in5_HD.h b/src/epd_panel/epd7in5_HD.h new file mode 100644 index 0000000..5487de7 --- /dev/null +++ b/src/epd_panel/epd7in5_HD.h @@ -0,0 +1,196 @@ +/** + ****************************************************************************** + * @file edp7in5_HD.h + * @author Waveshare Team + * @version V1.0.0 + * @date 05-August-2020 + * @brief This file describes initialisation of 7.5 HD and 7.5b HD e-Papers + * + ****************************************************************************** + */ + + +void EPD_7IN5_HD_Readbusy(void) +{ + Serial.print("\r\ne-Paper busy\r\n"); + delay(200); + unsigned char busy; + do{ + busy = digitalRead(PIN_SPI_BUSY); + }while(busy); + delay(200); + Serial.print("e-Paper busy release\r\n"); +} + + +/***************************************************************************** + EPD_7IN5_HD +******************************************************************************/ + +static void EPD_7IN5_HD_Show(void) +{ + unsigned int i; + EPD_SendCommand(0x26); + for(i=0; i<880*528/8; i++) { + EPD_SendData(0xff); + } + EPD_SendCommand(0x22); + EPD_SendData(0xF7); + EPD_SendCommand(0x20); + delay(200); + EPD_7IN5_HD_Readbusy(); + + EPD_SendCommand(0x10);//sleep + EPD_SendData(0x01); + + Serial.print("EPD_7IN5_HD_Show END\r\n"); +} + +int EPD_7IN5_HD_init() +{ + EPD_Reset(); + + EPD_SendCommand(0x12); //SWRESET + EPD_7IN5_HD_Readbusy(); //waiting for the electronic paper IC to release the idle signal + + EPD_SendCommand(0x46); // Auto Write RAM + EPD_SendData(0xF7); + EPD_7IN5_HD_Readbusy(); //waiting for the electronic paper IC to release the idle signal + + EPD_SendCommand(0x47); // Auto Write RAM + EPD_SendData(0xF7); + EPD_7IN5_HD_Readbusy(); //waiting for the electronic paper IC to release the idle signal + + EPD_SendCommand(0x0C); // Soft start setting + EPD_SendData(0xAE); + EPD_SendData(0xC7); + EPD_SendData(0xC3); + EPD_SendData(0xC0); + EPD_SendData(0x40); + + EPD_SendCommand(0x01); // Set MUX as 527 + EPD_SendData(0xAF); + EPD_SendData(0x02); + EPD_SendData(0x01); + + EPD_SendCommand(0x11); // Data entry mode + EPD_SendData(0x01); + + EPD_SendCommand(0x44); + EPD_SendData(0x00); // RAM x address start at 0 + EPD_SendData(0x00); + EPD_SendData(0x6F); // RAM x address end at 36Fh -> 879 + EPD_SendData(0x03); + EPD_SendCommand(0x45); + EPD_SendData(0xAF); // RAM y address start at 20Fh; + EPD_SendData(0x02); + EPD_SendData(0x00); // RAM y address end at 00h; + EPD_SendData(0x00); + + EPD_SendCommand(0x3C); // VBD + EPD_SendData(0x01); // LUT1, for white + + EPD_SendCommand(0x18); + EPD_SendData(0X80); + EPD_SendCommand(0x22); + EPD_SendData(0XB1); //Load Temperature and waveform setting. + EPD_SendCommand(0x20); + EPD_7IN5_HD_Readbusy(); //waiting for the electronic paper IC to release the idle signal + + EPD_SendCommand(0x4E); + EPD_SendData(0x00); + EPD_SendData(0x00); + EPD_SendCommand(0x4F); + EPD_SendData(0x00); + EPD_SendData(0x00); + + EPD_SendCommand(0x4F); + EPD_SendData(0x00); + EPD_SendData(0x00); + EPD_SendCommand(0x24);//BLOCK + return 0; +} + +/***************************************************************************** + EPD_7IN5B_HD +******************************************************************************/ + + +static void EPD_7IN5B_HD_Show(void) +{ + EPD_SendCommand(0x22); + EPD_SendData(0xC7); + EPD_SendCommand(0x20); + delay(200); + EPD_7IN5_HD_Readbusy(); + + EPD_SendCommand(0x10);//sleep + EPD_SendData(0x01); + + Serial.print("EPD_7IN5B_HD_Show END\r\n"); +} + +int EPD_7IN5B_HD_init() +{ + EPD_Reset(); + + EPD_SendCommand(0x12); //SWRESET + EPD_7IN5_HD_Readbusy(); //waiting for the electronic paper IC to release the idle signal + + EPD_SendCommand(0x46); // Auto Write RAM + EPD_SendData(0xF7); + EPD_7IN5_HD_Readbusy(); //waiting for the electronic paper IC to release the idle signal + + EPD_SendCommand(0x47); // Auto Write RAM + EPD_SendData(0xF7); + EPD_7IN5_HD_Readbusy(); //waiting for the electronic paper IC to release the idle signal + + EPD_SendCommand(0x0C); // Soft start setting + EPD_SendData(0xAE); + EPD_SendData(0xC7); + EPD_SendData(0xC3); + EPD_SendData(0xC0); + EPD_SendData(0x40); + + EPD_SendCommand(0x01); // Set MUX as 527 + EPD_SendData(0xAF); + EPD_SendData(0x02); + EPD_SendData(0x01); + + EPD_SendCommand(0x11); // Data entry mode + EPD_SendData(0x01); + + EPD_SendCommand(0x44); + EPD_SendData(0x00); // RAM x address start at 0 + EPD_SendData(0x00); + EPD_SendData(0x6F); // RAM x address end at 36Fh -> 879 + EPD_SendData(0x03); + EPD_SendCommand(0x45); + EPD_SendData(0xAF); // RAM y address start at 20Fh; + EPD_SendData(0x02); + EPD_SendData(0x00); // RAM y address end at 00h; + EPD_SendData(0x00); + + EPD_SendCommand(0x3C); // VBD + EPD_SendData(0x01); // LUT1, for white + + EPD_SendCommand(0x18); + EPD_SendData(0X80); + EPD_SendCommand(0x22); + EPD_SendData(0XB1); //Load Temperature and waveform setting. + EPD_SendCommand(0x20); + EPD_7IN5_HD_Readbusy(); //waiting for the electronic paper IC to release the idle signal + + EPD_SendCommand(0x4E); + EPD_SendData(0x00); + EPD_SendData(0x00); + EPD_SendCommand(0x4F); + EPD_SendData(0xAF); + EPD_SendData(0x02); + + EPD_SendCommand(0x4F); + EPD_SendData(0xAf); + EPD_SendData(0x02); + EPD_SendCommand(0x24);//BLOCK + return 0; +} diff --git a/src/epd_panel/epd9in7g.h b/src/epd_panel/epd9in7g.h new file mode 100644 index 0000000..348b9f6 --- /dev/null +++ b/src/epd_panel/epd9in7g.h @@ -0,0 +1,181 @@ +/** + ****************************************************************************** + * @file edp9IN7G.h + * @author Waveshare Team + * @version V1.0.0 + * @date 29-Dec-2020 + * @brief This file describes initialisation of 7.3f e-Papers + * + ****************************************************************************** + */ + +/***************************************************************************** + EPD_4IN01F +******************************************************************************/ +#include +static void EPD_9IN7G_BusyHigh(void)// If BUSYN=0 then waiting +{ + while(!(digitalRead(PIN_SPI_BUSY))); +} + +static void EPD_9IN7G_BusyLow(void)// If BUSYN=1 then waiting +{ + while(digitalRead(PIN_SPI_BUSY)); +} + +static void EPD_9IN7G_Show(void) +{ + Serial.println("EPD_9IN7G_Show Begin"); + + Serial.println("Turn on display."); + // turn on display + EPD_SendCommand(0x04);//0x04 + EPD_9IN7G_BusyHigh(); + + EPD_SendCommand(0x12);//0x12 + EPD_SendData(0x00); + EPD_9IN7G_BusyHigh(); + + EPD_SendCommand(0x02);//0x02 + EPD_SendData(0x00); + EPD_9IN7G_BusyHigh(); + + delay(200); + Serial.print("EPD_9IN7G_Show END\r\n"); + + // go to sleep + delay(100); + EPD_SendCommand(0x07);//sleep + EPD_SendData(0xA5); + delay(100); +} + +//四色常温波形 + +const unsigned char E5_WSF[]={ +0xEF, 0x7F, 0xBE, 0xBF, 0x6F, 0x6F, 0xEF, 0x7F, 0xEF, 0x7F, 0xBE, 0xBF, 0x6F, 0x6F, 0xEF, 0x7F, 0xEF, 0x7F, 0xBE, 0xBF, 0x6F, 0x6F, 0xEF, 0x7F, 0xEF, 0x7F, 0xBE, 0xBF, 0x6F, 0x6F, 0xEF, 0x7F, 0xEF, 0x7F, 0xBE, 0xBF, 0x6F, 0x6F, 0xEF, 0x7F, 0xEF, 0x7F, 0xBE, 0xBF, 0x6F, 0x6F, 0xEF, 0x7F, +0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0xFF, 0xF3, 0xFB, 0xFF, 0xFF, 0xFF, 0xBF, 0xFF, 0xFF, 0xF3, 0xFB, 0xFF, 0xF9, 0xFB, 0xDD, 0xF7, 0xFF, 0xF3, 0xFB, 0xD7, 0xF3, 0xD7, 0xDF, 0xDF, 0xD5, 0xF3, 0xFB, 0xD7, 0xF7, 0xDF, 0x94, 0x9D, 0xFF, 0xFF, 0xFF, 0xBF, 0xBF, 0xBF, 0xBE, 0xBE, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xF3, 0xD7, 0xF3, 0xFD, 0xFE, 0xBF, 0xFE, 0xBE, 0xF3, 0xD7, 0xF3, 0xFD, 0xDD, 0xFF, 0xDF, 0xFE, 0xF3, 0xDF, 0xD2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF3, 0xDF, 0xD2, 0xD2, 0x90, 0x90, 0x90, 0xFF, 0xFF, 0xFF, 0xBA, 0xBA, 0xBA, 0xFB, 0xFB, +0x78, 0x7F, 0x7F, 0xEF, 0xEF, 0xEF, 0xBD, 0xBD, 0xA5, 0x7F, 0x7F, 0x7F, 0xEF, 0xEF, 0xBF, 0xBF, 0xA5, 0x7F, 0x7F, 0x7F, 0xEF, 0xEF, 0x7F, 0x7F, 0xA5, 0x7F, 0x7F, 0x7F, 0xEF, 0xEF, 0x7F, 0xEF, 0xA5, 0x7F, 0x7F, 0x7F, 0xEF, 0xEF, 0x7F, 0xEF, 0x78, 0x7F, 0x7F, 0x7F, 0xEF, 0xEF, 0x7F, 0x7F, +0xFF, 0x7F, 0xEF, 0x7F, 0xBF, 0x7F, 0xFF, 0xFF, 0x67, 0x7F, 0xEF, 0x7F, 0xBF, 0x7F, 0xAF, 0x6F, 0x67, 0x7F, 0xEF, 0x7F, 0xBF, 0x7F, 0x2F, 0x6F, 0x67, 0x7F, 0xEF, 0x7F, 0x6F, 0x7F, 0xFD, 0x2F, 0x67, 0x7F, 0xEF, 0x7F, 0x6F, 0x7F, 0x7F, 0xEF, 0xFF, 0x7F, 0xEF, 0x7F, 0xBF, 0x7F, 0xFD, 0xFD, +0xFF, 0xFF, 0xFF, 0xEF, 0xEF, 0xEF, 0xFF, 0xFF, 0x2D, 0xFF, 0xFF, 0xEF, 0x7F, 0xEF, 0x6F, 0xAF, 0x6C, 0xFF, 0xFF, 0xEF, 0x6F, 0xEF, 0x6F, 0xAF, 0x7C, 0xFF, 0xFF, 0xEF, 0xEF, 0xEF, 0x3F, 0x7F, 0xBE, 0xFF, 0xFF, 0xEF, 0x7F, 0xEF, 0x3F, 0x7D, 0xFF, 0xFF, 0xFF, 0xEF, 0xEF, 0xEF, 0x7F, 0x7F, +0xEF, 0xEC, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEC, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEC, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEC, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEC, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEC, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, +0x78, 0x7D, 0x7F, 0xEF, 0x6D, 0xBF, 0xED, 0xED, 0xB7, 0x7D, 0x7F, 0xEF, 0x6F, 0x7D, 0xEF, 0x2F, 0xFC, 0x7D, 0x7F, 0xBF, 0xAF, 0xAF, 0x6F, 0x6F, 0xE7, 0x7D, 0x7F, 0x2F, 0x3F, 0xFD, 0x7F, 0x6F, 0xFC, 0x7D, 0x7F, 0xBF, 0xBF, 0xFF, 0xEF, 0xEF, 0x78, 0x7D, 0x7F, 0xEF, 0xAF, 0xBF, 0xED, 0xED, +0xFF, 0x7D, 0xEF, 0x7E, 0x7D, 0xBD, 0xFF, 0xFF, 0xFE, 0x7D, 0xEF, 0x7D, 0xFE, 0x6F, 0x3F, 0x7F, 0x2E, 0x7D, 0xEF, 0x2F, 0xBD, 0x7D, 0x7F, 0x6F, 0x6E, 0x7D, 0xEF, 0x7F, 0xFE, 0x2F, 0x7F, 0xAF, 0x76, 0x7D, 0xEF, 0x7E, 0xFE, 0x6E, 0x2F, 0x3F, 0xFF, 0x7D, 0xEF, 0xEE, 0xFE, 0xBD, 0xFF, 0xFF, +0xFF, 0xEF, 0xFF, 0xFD, 0x7F, 0xBF, 0xFF, 0xFF, 0xE7, 0xEF, 0xFF, 0x2D, 0x6F, 0x2F, 0x7F, 0xFF, 0x7C, 0xEF, 0xFF, 0x2D, 0xBF, 0xAF, 0xBF, 0xBF, 0x3E, 0xEF, 0xFF, 0xEE, 0x7F, 0xAF, 0x6F, 0x7F, 0x3F, 0xEF, 0xFF, 0xBF, 0x6F, 0xEF, 0x7F, 0x7F, 0xFF, 0xEF, 0xFF, 0xFD, 0x7F, 0xBF, 0xFF, 0xFF, +0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0x7F, 0x7F, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0x7F, 0x7F, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0x7F, 0x7F, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0x7F, 0x7F, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0x7F, 0x7F, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0xEF, 0x7F, 0x7F, +0x00, 0x28, 0x78, 0x2C, 0x26, 0x14, 0x02, + +}; + +/**********切换代码*************/ + +#define Hanshow 100 +#define Qingyue 101 + + +int EPD_9IN7G_init() +{ + Serial.print("EPD_9IN7G_init Begin\r\n"); + EPD_Reset(); + EPD_9IN7G_BusyHigh(); + + EPD_SendCommand(0x00); // PSR + // EPD_SendData(0x57); + EPD_SendData(0x5F); + EPD_SendData(0xA9); + EPD_9IN7G_BusyHigh(); + + EPD_SendCommand(0x06); + EPD_SendData(0x0F); + EPD_SendData(0x8B); + EPD_SendData(0x93); + // EPD_SendData(0xA1); // 65mA + EPD_SendData(0xC1); // 100mA + + EPD_SendCommand(0x50); + EPD_SendData(0x37); + + EPD_SendCommand(0x61); // TRES + EPD_SendData(0x03); + EPD_SendData(0xC0); // Source Line 960 + EPD_SendData(0x02); + EPD_SendData(0xA0); // Gate Line 672 + EPD_9IN7G_BusyHigh(); + + EPD_SendCommand(0x62); + EPD_SendData(0x77); + EPD_SendData(0x77); + EPD_SendData(0x77); + EPD_SendData(0x5C); + EPD_SendData(0x9F); + EPD_SendData(0x8C); + EPD_SendData(0x77); + EPD_SendData(0x63); + + EPD_SendCommand(0xE7); + EPD_SendData(0x16); + + EPD_SendCommand(0xE9); + EPD_SendData(0x01); + + EPD_SendCommand(0x01); + EPD_SendData(0x07); + + int mode = Qingyue; + + if (mode == Qingyue) { + EPD_SendData(E5_WSF[528]); // +-20V VSPL 00 + EPD_SendData(E5_WSF[529]); // 绾㈢數鍘嬮粦鑹茬數鍘? + EPD_SendData(E5_WSF[531]); // 78 榛戣壊鐢靛帇 VSP + EPD_SendData(E5_WSF[530]); // SN鐢靛帇锛孭ower灏忚礋鍘嬶紝鐧借壊 + EPD_SendData(E5_WSF[532]); // 绾㈣壊Power鐢靛帇 + } else if (mode == Hanshow) { + EPD_SendData(E5_WSF[0]); // +-20V VSPL 00 + EPD_SendData(E5_WSF[1]); // 绾㈢數鍘嬮粦鑹茬數鍘? + EPD_SendData(E5_WSF[3]); // 78 榛戣壊鐢靛帇 VSP + EPD_SendData(E5_WSF[2]); // SN鐢靛帇锛孭ower灏忚礋鍘嬶紝鐧借壊 + EPD_SendData(E5_WSF[4]); // 绾㈣壊Power鐢靛帇 + } + + + EPD_SendCommand(0x82); // VCOM + if(mode == Qingyue) { + EPD_SendData(E5_WSF[533] + 0x80); + } else if(mode == Hanshow) { + EPD_SendData(E5_WSF[5] + 0x80); + } + + EPD_SendCommand(0x30); // 棰戠巼 + if(mode == Qingyue) { + EPD_SendData(E5_WSF[534]); + } else if(mode == Hanshow) { + EPD_SendData(E5_WSF[6]); + } + + // 浼犺緭娉㈠舰 + int i,j; + EPD_SendCommand(0x20); + if(mode == Qingyue) { + for (i = 528; i < 535; i++) { + EPD_SendData(E5_WSF[i]); + } + + for (i = 0; i < 48; i++) { + for (j = 0; j < 11; j++) { + EPD_SendData(E5_WSF[i + 48 * j]); + } + } + } else if(mode == Hanshow) { + for (i = 0; i < 535; i++) { + EPD_SendData(E5_WSF[i]); + } + } + + // new add + EPD_SendCommand(0x10); //begin write data to e-Paper + + Serial.print("EPD_9IN7G_init End\r\n"); + + return 0; +} diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..a23cb5a --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,42 @@ +#include + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_task_wdt.h" + +#include + +#include "config/wifi_config.h" +#include "config/ble_config.h" + +#include "buff/buff_wifi.h" +#include "epd_driver/epd.h" + +void setup() +{ + Serial.begin(115200); + + Serial.println("setup begin"); + + // init epd buffer + Buff__init(); + + // init wifi + my_wifi_init(); + + // init ble + my_ble_init(); + + // init service + Srvr__init(); + + // Initialization is complete + Serial.println("Ok!"); +} + + +void loop() +{ + // service loop + Srvr__loop(); +} diff --git a/src/web/Web_CSS.h b/src/web/Web_CSS.h new file mode 100644 index 0000000..d975e60 --- /dev/null +++ b/src/web/Web_CSS.h @@ -0,0 +1,296 @@ +/***************************************************************************** +* | File : Web_CSS.c +* | Author : Waveshare team +* | Function : send html string +* | This version: V1.0 +* | Date : 2019-08-26 +* | Info : +*---------------- +******************************************************************************/ +extern WebServer server; +void Web_SendCSS() +{ + server.send(200, "text/css", + "body {\r\n" + " margin: 0px;\r\n" + " padding: 0px;\r\n" + "}\r\n" + ".large {\r\n" + " width: 100vw;\r\n" + " height: 100vh;\r\n" + "}\r\n" + ".large .Menu {\r\n" + " float: left;\r\n" + " width: 12vw;\r\n" + " min-width: 250px;\r\n" + " height: 100%;\r\n" + " color: #FFFFFF;\r\n" + " background-color: #292929;\r\n" + " box-shadow: 0px 0px 10px #313131;\r\n" + "}\r\n" + ".large .SubMenu {\r\n" + " float: left;\r\n" + " width: 8vw;\r\n" + " min-width: 200px;\r\n" + " height: 100%;\r\n" + " display: none;\r\n" + " color: #458f00;\r\n" + " background-color: #3D3D3D;\r\n" + " box-shadow: 0px 0px 10px #515151;\r\n" + "}\r\n" + ".large .maincontent {\r\n" + " height: 100vh;\r\n" + " overflow-x: hidden;\r\n" + " line-height: 30px;\r\n" + " background: #EEEEEE;\r\n" + "}\r\n" + ".large .maincontent::-webkit-scrollbar {\r\n" + " display: none;\r\n" + "}\r\n" + ".Menu .Item {\r\n" + " width: 80%;\r\n" + " margin: auto;\r\n" + "}\r\n" + ".Menu .Item .ch-home {\r\n" + " font-size: 22px;\r\n" + " font-style: normal;\r\n" + " font-weight: 600;\r\n" + " text-decoration: none;\r\n" + " color: #079aff;\r\n" + "}\r\n" + ".Menu .Item .en-home {\r\n" + " font-size: 20px;\r\n" + " font-style: normal;\r\n" + " text-decoration: none;\r\n" + " color: green;\r\n" + "}\r\n" + ".Menu .Nav {\r\n" + " min-width: 200px;\r\n" + " width: 80%;\r\n" + " margin: 0 auto;\r\n" + " padding: 10px 0px;\r\n" + " display: block;\r\n" + "}\r\n" + ".Menu .firstDeviceIP {\r\n" + " min-width: 230px;\r\n" + " font-size: 18px;\r\n" + " color: aqua;\r\n" + "}\r\n" + ".Menu .firstDeviceIPinput {\r\n" + " font-size: 18px;\r\n" + " color: aqua;\r\n" + " width: 130px;\r\n" + " background: #292929;\r\n" + " border: 0px;\r\n" + "}\r\n" + ".Menu .firstNav {\r\n" + " margin: 0 auto;\r\n" + " padding: 10px 0px;\r\n" + " display: block;\r\n" + " text-decoration: none;\r\n" + "}\r\n" + ".Menu .Nav .firstNav {\r\n" + " display: inline-block;\r\n" + " font-size: 20px;\r\n" + " text-shadow: 0px 0px 3px #EEEEEE;\r\n" + "}\r\n" + ".Menu .Nav .firstNav:hover {\r\n" + " background-color: #3D3D3D;\r\n" + " cursor: pointer;\r\n" + "}\r\n" + ".Menu .showimage_button, .Menu .uploadimage_button {\r\n" + " width: 80%;\r\n" + " margin: 10px auto;\r\n" + " height: 50px;\r\n" + " font-size: 16px;\r\n" + " background-color: #4CAF50;\r\n" + " border: none;\r\n" + " display: block;\r\n" + " color: white;\r\n" + " border-radius: 12px;\r\n" + "}\r\n" + ".Menu .showimage_button {\r\n" + " background-color: #2712FF;\r\n" + "}\r\n" + ".showimage_button:hover {\r\n" + " background-color: #e5e5e5;\r\n" + " color: #2712FF;\r\n" + "}\r\n" + ".uploadimage_button:hover {\r\n" + " background-color: #e5e5e5;\r\n" + " color: #4CAF50;\r\n" + "}\r\n" + ".SubMenu .DrawingDrop {\r\n" + " top: 2%;\r\n" + " display: none;\r\n" + " margin: 0 auto;\r\n" + " position: relative;\r\n" + " padding: 10px;\r\n" + " padding-top: 6px;\r\n" + " padding-bottom: 6px;\r\n" + " left: 1%;\r\n" + "}\r\n" + ".SubMenu .DrawingDrop .DrawingNav {\r\n" + " text-align: left;\r\n" + " line-height: 30px;\r\n" + " font-size: 20px;\r\n" + "}\r\n" + ".SubMenu .DrawingNav:hover {\r\n" + " background-color: #458f00;\r\n" + " color: #3D3D3D;\r\n" + " cursor: pointer;\r\n" + "}\r\n" + "/*页眉主页页脚*/\r\n" + ".maincontent .header {\r\n" + " background: #c0ffb9;\r\n" + " color: #7976f2;\r\n" + " height: 70px;\r\n" + "}\r\n" + ".header .epdname {\r\n" + " text-align: center;\r\n" + " font-size: 30px;\r\n" + " font-weight: 500;\r\n" + " width: 400px;\r\n" + " margin: auto;\r\n" + " padding-top: 5px;\r\n" + " padding-bottom: 5px;\r\n" + "}\r\n" + ".header .epdpixelandcolor {\r\n" + " text-align: center;\r\n" + " font-size: 20px;\r\n" + " width: 400px;\r\n" + " margin: auto;\r\n" + "}\r\n" + ".maincontent .page {\r\n" + " background: #e5e5e5;\r\n" + "}\r\n" + ".maincontent .footer {\r\n" + " background: #c0ffb9;\r\n" + " color: #7976f2;\r\n" + "}\r\n" + ".footer .footername {\r\n" + " text-align: center;\r\n" + " font-size: 15px;\r\n" + " font-weight: 500;\r\n" + " width: 400px;\r\n" + " margin: auto;\r\n" + " padding-top: 5px;\r\n" + " padding-bottom: 5px;\r\n" + "}\r\n" + "/*******************按键+通用组件*******************/\r\n" + ".maincontent .DrawName {\r\n" + " font-size: 21px;\r\n" + " padding-left: 8px;\r\n" + "}\r\n" + ".Draw-button {\r\n" + " font-size: 16px;\r\n" + " border: none;\r\n" + " color: white;\r\n" + " padding: 8px 18px;\r\n" + " text-align: center;\r\n" + " text-decoration: none;\r\n" + " display: inline-block;\r\n" + " margin: 4px 2px;\r\n" + " cursor: pointer;\r\n" + " border-radius: 12px;\r\n" + "}\r\n" + ".Draw-button1 {\r\n" + " background-color: #4CAF50;\r\n" + "}\r\n" + ".Draw-button2 {\r\n" + " display: none;\r\n" + " background-color: #f44336;\r\n" + "}\r\n" + ".Draw-button3 {\r\n" + " background-color: #555555;\r\n" + "}\r\n" + ".Draw-button1:hover {\r\n" + " background-color: #e5e5e5;\r\n" + " color: #4CAF50;\r\n" + "}\r\n" + ".Draw-button2:hover {\r\n" + " background-color: #e5e5e5;\r\n" + " color: #f44336;\r\n" + "}\r\n" + ".Draw-button3:hover {\r\n" + " background-color: #e5e5e5;\r\n" + " color: #555555;\r\n" + "}\r\n" + ".maincontent table {\r\n" + " padding-left: 5px;\r\n" + " width: 100px;\r\n" + "}\r\n" + ".DrawNav {\r\n" + " text-align: center;\r\n" + "}\r\n" + ".DrawNav th {\r\n" + " font-size: 1.1em;\r\n" + " padding-top: 5px;\r\n" + " padding-bottom: 4px;\r\n" + " background-color: rgb(35, 36, 34);\r\n" + " color: #ffffff;\r\n" + "}\r\n" + ".DrawNav td {\r\n" + " font-size: 1em;\r\n" + " border: 1px solid #8b8792;\r\n" + " padding: 3px 7px 2px 7px;\r\n" + "}\r\n" + ".DrawNav input {\r\n" + " width: 100px;\r\n" + " text-align: center;\r\n" + "}\r\n" + ".DrawNav button {\r\n" + " width: 135px;\r\n" + " text-align: center;\r\n" + "}\r\n" + ".image-button {\r\n" + " position: relative;\r\n" + " width: 130px;\r\n" + " height: 30px;\r\n" + " border-radius: 5px;\r\n" + " background-color: rgb(124, 245, 186);\r\n" + " color: #333333;\r\n" + " font-size: 14px;\r\n" + " text-align: center;\r\n" + " overflow: hidden;\r\n" + "}\r\n" + ".image-button span {\r\n" + " text-overflow: ellipsis;\r\n" + " white-space: nowrap;\r\n" + " overflow: hidden;\r\n" + "}\r\n" + ".image-button:hover {\r\n" + " font-size: 15px;\r\n" + " border-color: rgb(39, 226, 81);\r\n" + "}\r\n" + ".image-button input[type=\'file\'] {\r\n" + " position: absolute;\r\n" + " opacity: 0;/* 隐藏浏览 */\r\n" + "}\r\n" + "/****************************************/\r\n" + ".pagewidth {\r\n" + " margin: auto;\r\n" + " min-width: 1000px;\r\n" + "}\r\n" + ".maincontent .DrawPoint, .maincontent .DrawLine, .maincontent .DrawRectangle, .maincontent .DrawCircle, .maincontent .DrawString, .maincontent .ShowPic {\r\n" + " display: none;\r\n" + " background: #f7c698;\r\n" + "}\r\n" + ".DrawCanvas, .DrawCanvas2 {\r\n" + " border: 2px dashed green;\r\n" + " border-radius: 8px;\r\n" + " background: rgb(255, 255, 255);\r\n" + " background-repeat: repeat;\r\n" + " background-repeat: no-repeat;\r\n" + " position: inherit;\r\n" + "}\r\n" + ".DrawCanvas .DrawCanvastext {\r\n" + " margin: auto;\r\n" + " text-align: center;\r\n" + " font-size: larger;\r\n" + " position: relative;\r\n" + " line-height: 0vh;\r\n" + " top: 50%;\r\n" + "}" + ); +} diff --git a/src/web/Web_HTML.h b/src/web/Web_HTML.h new file mode 100644 index 0000000..1a7c176 --- /dev/null +++ b/src/web/Web_HTML.h @@ -0,0 +1,74 @@ +/***************************************************************************** +* | File : Web_Html.c +* | Author : Waveshare team +* | Function : send html string +* | This version: V1.0 +* | Date : 2019-08-26 +* | Info : +*---------------- +******************************************************************************/ +extern WebServer server; +extern IPAddress myIP; + +void Web_SendHTML() +{ + server.send(200, "text/html", + "\r\n" + "\r\n" + "\r\n" + "\r\n" + "12.48inch e-paper\r\n" + "\r\n" + "\r\n" + "\r\n" + "\r\n" + "\r\n" + "\r\n" + "\r\n" + "\r\n" + "
\r\n" + "
\r\n" + "
\r\n" + " 微雪电子\r\n" + " waveshare\r\n" + "
\r\n" + "
  • \r\n" + "
    \r\n" + " IP : \r\n" + "
    \r\n" + "
    12.48inch e-paper
    \r\n" + "
    12.48inch e-paper b
    \r\n" + "
  • \r\n" + " \r\n" + "
    \r\n" + "
    \r\n" + "
    \r\n" + "
    Draw Point
    \r\n" + "
    Draw Line
    \r\n" + "
    Draw Rectangle
    \r\n" + "
    Draw Circle
    \r\n" + "
    Draw String
    \r\n" + "
    Show Picture
    \r\n" + "
    \r\n" + "
    \r\n" + "
    \r\n" + "
    \r\n" + "
    \r\n" + "
    \r\n" + "
    \r\n" + "
    \r\n" + " \r\n" + "
    \r\n" + "
    Drop image here...
    \r\n" + "
    \r\n" + "
    \r\n" + "
    \r\n" + "
    waveshare|深圳市微雪电子有限公司
    \r\n" + "
    \r\n" + "
    \r\n" + "
    \r\n" + "\r\n" + "" + ); +} diff --git a/src/web/Web_Scripts.h b/src/web/Web_Scripts.h new file mode 100644 index 0000000..23f5f90 --- /dev/null +++ b/src/web/Web_Scripts.h @@ -0,0 +1,730 @@ +/***************************************************************************** +* | File : Web_Scripts.c +* | Author : Waveshare team +* | Function : send Scripts string +* | This version: V1.0 +* | Date : 2019-08-26 +* | Info : +*---------------- +******************************************************************************/ +extern WebServer server; +void Web_SendJS_A() +{ + server.send(200, "text/javascript", + "var epdnum;\r\n" + "var epdArr = [\r\n" + " [\'1.54inch e-paper\', 200, 200, 0, 0],\r\n" + " [\'1.54inch e-paper V2\', 200, 200, 0, 0],\r\n" + " [\'1.54inch e-paper (B)\', 200, 200, 1, 3],\r\n" + " [\'1.54inch e-Paper (C)\', 152, 152, 2, 5],\r\n" + " [\'2.13inch e-Paper\', 250, 122, 0, 0],\r\n" + " [\'2.13inch e-Paper V2\', 250, 122, 0, 0],\r\n" + " [\'2.13inch e-Paper (B)\', 212, 104, 1, 1],\r\n" + " [\'2.13inch e-Paper (C)\', 212, 104, 2, 5],\r\n" + " [\'2.13inch e-Paper (D)\', 212, 104, 0, 0],\r\n" + " [\'2.7inch e-Paper\', 264, 176, 0, 0],\r\n" + " [\'2.7inch e-Paper (B)\', 264, 176, 1, 1],\r\n" + " [\'2.9inch e-Paper\', 296, 128, 0, 0],\r\n" + " [\'2.9inch e-Paper (B)\', 296, 128, 1, 1],\r\n" + " [\'2.9inch e-Paper (C)\', 296, 128, 2, 5],\r\n" + " [\'2.9inch e-Paper (D)\', 296, 128, 0, 0],\r\n" + " [\'4.2inch e-Paper\', 400, 300, 0, 0],\r\n" + " [\'4.2inch e-Paper (B)\', 400, 300, 1, 1],\r\n" + " [\'4.2inch e-Paper (C)\', 400, 300, 2, 5],\r\n" + " [\'5.83inch e-Paper\', 600, 448, 0, 0],\r\n" + " [\'5.83inch e-Paper (B)\', 600, 448, 1, 1],\r\n" + " [\'5.83inch e-Paper (C)\', 600, 448, 2, 5],\r\n" + " [\'7.5inch e-Paper\', 640, 384, 0, 0],\r\n" + " [\'7.5inch e-Paper (B)\', 640, 384, 1, 1],\r\n" + " [\'7.5inch e-Paper (C)\', 640, 384, 2, 5],\r\n" + " [\'7.5inch e-Paper V2\', 800, 480, 0, 0],\r\n" + " [\'7.5inch e-Paper (B) V2\', 800, 480, 1, 1],\r\n" + " [\'7.5inch e-Paper (C) V2\', 800, 480, 2, 5],\r\n" + " [\'12.48inch e-Paper\', 1304, 984, 0, 0],\r\n" + " [\'12.48inch e-Paper (B)\', 1304, 984, 1, 1],\r\n" + " [\'12.48inch e-Paper (C)\', 1304, 984, 2, 5]\r\n" + "];\r\n" + "var palArr = [\r\n" + " [[0, 0, 0], [255, 255, 255]],\r\n" + " [[0, 0, 0], [255, 255, 255], [255, 0, 0]],\r\n" + " [[0, 0, 0], [255, 255, 255], [127, 127, 127]],\r\n" + " [[0, 0, 0], [255, 255, 255], [127, 127, 127], [127, 0, 0]],\r\n" + " [[0, 0, 0], [255, 255, 255]],\r\n" + " [[0, 0, 0], [255, 255, 255], [220, 180, 0]]\r\n" + "];\r\n" + "var DrawIfShow = [\r\n" + " [\'DrawPoint\', 0],\r\n" + " [\'DrawLine\', 0],\r\n" + " [\'DrawRectangle\', 0],\r\n" + " [\'DrawCircle\', 0],\r\n" + " [\'DrawString\', 0],\r\n" + " [\'DrawChinese\', 0],\r\n" + " [\'ShowPicture\', 0]\r\n" + "];\r\n" + "/**/\r\n" + "function indexOf(arr, item) {\r\n" + " for (var i = 0; i < arr.length; i++) {\r\n" + " if (arr[i][0] === item)\r\n" + " return i;\r\n" + " }\r\n" + "}\r\n" + "function consoledebug(str) {\r\n" + " var debug = 1;\r\n" + " if (debug) console.log(str);\r\n" + "}\r\n" + "var showorhide_flag = 0; // 0:hide,1:show\r\n" + "function showorhide() {\r\n" + " if (showorhide_flag == 0) {\r\n" + " consoledebug(\'show\');\r\n" + " $(\'.SubMenu\').show();\r\n" + " $(\'.DrawingDrop\').show();\r\n" + " $(\'.page\').show();\r\n" + " $(\'.footer\').show();\r\n" + " // showorhide_flag = 1;\r\n" + " } else {\r\n" + " consoledebug(\'hide\');\r\n" + " $(\'.SubMenu\').hide();\r\n" + " $(\'.DrawingDrop\').hide();\r\n" + " showorhide_flag = 0;\r\n" + " }\r\n" + "}\r\n" + "var ry_color;\r\n" + "function hasRed(epdnum) {\r\n" + " $(\'.show_ry\').css({ \'display\': \'none\'});\r\n" + " if(epdArr[epdnum][3] == 1){\r\n" + " ry_color = \'RED\';\r\n" + " } else{\r\n" + " ry_color = \'\';\r\n" + " }\r\n" + " $(\'.show_ry\').css({ \'display\': epdArr[epdnum][3] == 0 ? \'none\' : \'block\'});\r\n" + "}\r\n" + "var canvasWidth, canvasHeight;\r\n" + "function showmain(epdnum) {\r\n" + " consoledebug(epdArr[epdnum][0]);\r\n" + " $(\'.epd\').show();\r\n" + " $(\'.epdname\').empty();\r\n" + " $(\'.epdpixelandcolor\').empty();\r\n" + " $(\'.epdname\').prepend(epdArr[epdnum][0]);\r\n" + " $(\'.epdpixelandcolor\').prepend(epdArr[epdnum][1] + \' * \' + epdArr[epdnum][2] + \' Pixel \' + \" Black + White\" + (epdArr[epdnum][3] == 0 ? \' \' : (epdArr[epdnum][3] == 1 ? \" + Red\":\" + Yellow\")));\r\n" + " hasRed(epdnum);\r\n" + " pageMinHeight = $(window).height() - $(\'.header\').height() - $(\'.footer\').height();\r\n" + " $(\'.page\').css({ \'min-height\': pageMinHeight + \'px\' });\r\n" + " canvasWidth = epdArr[epdnum][1] + \'\';\r\n" + " canvasHeight = epdArr[epdnum][2] + \'\';\r\n" + " $(\'.pagewidth\').css({\'width\': canvasWidth + \'px\'});\r\n" + " $(\'.DrawCanvas\').css({\'width\': canvasWidth + \'px\' ,\'height\': canvasHeight + \'px\' });\r\n" + "}\r\n" + "var showDrawCanvas_Flag = 0;\r\n" + "function showDrawCanvas() {\r\n" + " if (showDrawCanvas_Flag == 0) {\r\n" + " $(\'.DrawCanvas\').empty();\r\n" + " $(\'.DrawCanvas\').append(\"\');\r\n" + " showDrawCanvas_Flag = 1;\r\n" + " }\r\n" + "}\r\n" + "$(function () {\r\n" + " $(\'.12in48_epd-js\').click(function () {\r\n" + " showorhide();\r\n" + " epdnum = indexOf(epdArr, \'12.48inch e-Paper\');\r\n" + " showmain(epdnum);\r\n" + " });\r\n" + " $(\'.12in48b_epd-js\').click(function () {\r\n" + " showorhide();\r\n" + " epdnum = indexOf(epdArr, \'12.48inch e-Paper (B)\');\r\n" + " showmain(epdnum);\r\n" + " });\r\n" + " $(\'.12in48c_epd-js\').click(function () {\r\n" + " showorhide();\r\n" + " epdnum = indexOf(epdArr, \'12.48inch e-Paper (C)\');\r\n" + " showmain(epdnum);\r\n" + " });\r\n" + " $(\'.DrawPoint-js\').click(function () {\r\n" + " consoledebug(\'DrawPoint\');\r\n" + " showDrawCanvas();\r\n" + " if (DrawIfShow[0][1] == 0) {\r\n" + " $(\'.DrawCanvas\').before(\"
    Draw Point
    NumXYColorPixel
    1
    \");\r\n" + " $(\'.DrawPoint\').show();\r\n" + " DrawIfShow[0][1] = 1;\r\n" + " }\r\n" + " });\r\n" + " $(\'.DrawLine-js\').click(function () {\r\n" + " consoledebug(\'DrawLine\');\r\n" + " showDrawCanvas();\r\n" + " if (DrawIfShow[1][1] == 0) {\r\n" + " $(\'.DrawCanvas\').before(\"
    Draw Line
    NumXstartYstartXendYendColorWidthStyle
    1
    \");\r\n" + " $(\'.DrawLine\').show();\r\n" + " DrawIfShow[1][1] = 1;\r\n" + " }\r\n" + " });\r\n" + " $(\'.DrawRectangle-js\').click(function () {\r\n" + " consoledebug(\'DrawRectangle\');\r\n" + " showDrawCanvas();\r\n" + " if (DrawIfShow[2][1] == 0) {\r\n" + " $(\'.DrawCanvas\').before(\"
    Draw Rectangle
    NumXstartYstartXendYendColorWidthFill
    1
    \");\r\n" + " $(\'.DrawRectangle\').show();\r\n" + " DrawIfShow[2][1] = 1;\r\n" + " }\r\n" + " });\r\n" + " $(\'.DrawCircle-js\').click(function () {\r\n" + " consoledebug(\'DrawCircle\');\r\n" + " showDrawCanvas();\r\n" + " if (DrawIfShow[3][1] == 0) {\r\n" + " $(\'.DrawCanvas\').before(\"
    Draw Circle
    NumXCenterYCenterRadiusColorWidthFill
    1
    \");\r\n" + " $(\'.DrawCircle\').show();\r\n" + " DrawIfShow[3][1] = 1;\r\n" + " }\r\n" + " });\r\n" + " $(\'.DrawString-js\').click(function () {\r\n" + " consoledebug(\'DrawString\');\r\n" + " showDrawCanvas();\r\n" + " if (DrawIfShow[4][1] == 0) {\r\n" + " $(\'.DrawCanvas\').before(\"
    Draw String
    NumXYStringsizeColor
    1
    \");\r\n" + " $(\'.DrawString\').show();\r\n" + " DrawIfShow[4][1] = 1;\r\n" + " }\r\n" + " });\r\n" + " $(\'.ShowPic-js\').click(function () {\r\n" + " consoledebug(\'Show Picture\');\r\n" + " showDrawCanvas();\r\n" + " if (DrawIfShow[5][1] == 0) {\r\n" + " $(\'.DrawCanvas\').before(\"
    Show Picture
    NumXstartYstartimagemode1mode2mode3mode4
    1
    upload image
    \");\r\n" + " $(\'.ShowPic\').show();\r\n" + " DrawIfShow[5][1] = 1;\r\n" + " $(\'.DrawCanvas\').after(\"
    \");\r\n" + " }\r\n" + " }); \r\n" + "});\r\n" + "function tableadd(tableclass, add_click, del_click) {\r\n" + " var num = $(tableclass).find(\'tr\').length;\r\n" + " consoledebug(add_click + \'=\' + num);\r\n" + " var content = \"\" + num + \"\";\r\n" + " if (add_click == \'DrawPoint_add_click\') {\r\n" + " content += \"\";\r\n" + " } else if (add_click == \'DrawLine_add_click\') {\r\n" + " content += \"\";\r\n" + " } else if (add_click == \'DrawRectangle_add_click\') {\r\n" + " content += \"\";\r\n" + " } else if (add_click == \'DrawCircle_add_click\') {\r\n" + " content += \"\";\r\n" + " } else if (add_click == \'DrawString_add_click\') {\r\n" + " content += \"\";\r\n" + " } else if (add_click == \'ShowPic_add_click\') {\r\n" + " content += \"
    upload image
    \";\r\n" + " } else {\r\n" + " consoledebug(\"none\");\r\n" + " }\r\n" + " $(tableclass).append(content);\r\n" + " hasRed(epdnum);\r\n" + " $(del_click).css({ \'display\': \'inline\' });\r\n" + "}\r\n" + "function tabledel(tableclass, del_click) {\r\n" + " consoledebug(del_click + \'num = \' + ($(tableclass).find(\'tr\').length - 2));\r\n" + " var len = $(tableclass).find(\'tr\').length;\r\n" + " if (len > 2) {\r\n" + " $(tableclass).find(\'tr\').eq(-1).remove();\r\n" + " }\r\n" + "}\r\n" + "function tabledelall(divclass, delall_click) {\r\n" + " consoledebug(delall_click);\r\n" + " $(divclass).remove();\r\n" + " if (delall_click == \'DrawPoint_delall_click\') {\r\n" + " DrawIfShow[0][1] = 0;\r\n" + " } else if (delall_click == \'DrawLine_delall_click\') {\r\n" + " DrawIfShow[1][1] = 0; \r\n" + " } else if (delall_click == \'DrawRectangle_delall_click\') {\r\n" + " DrawIfShow[2][1] = 0; \r\n" + " } else if (delall_click == \'DrawCircle_delall_click\') {\r\n" + " DrawIfShow[3][1] = 0; \r\n" + " } else if (delall_click == \'DrawString_delall_click\') {\r\n" + " DrawIfShow[4][1] = 0; \r\n" + " } else if (delall_click == \'ShowPic_delall_click\') {\r\n" + " DrawIfShow[5][1] = 0; \r\n" + " } else {\r\n" + " consoledebug(\"none\");\r\n" + " }\r\n" + "}\r\n" + "/*****************************/\r\n" + "$(document).on(\'click\', \'.DrawPoint_add_click\', function () {\r\n" + " tableadd(\'.Point\', \'DrawPoint_add_click\', \'.DrawPoint_del_click\');\r\n" + "});\r\n" + "$(document).on(\'click\', \'.DrawPoint_del_click\', function () {\r\n" + " tabledel(\'.Point\', \'.DrawPoint_del_click\');\r\n" + "});\r\n" + "$(document).on(\'click\', \'.DrawPoint_delall_click\', function () {\r\n" + " tabledelall(\'.DrawPoint\', \'DrawPoint_delall_click\');\r\n" + "});\r\n" + "/******************************/\r\n" + "$(document).on(\'click\', \'.DrawLine_add_click\', function () {\r\n" + " tableadd(\'.Line\', \'DrawLine_add_click\', \'.DrawLine_del_click\');\r\n" + "});\r\n" + "$(document).on(\'click\', \'.DrawLine_del_click\', function () {\r\n" + " tabledel(\'.Line\', \'DrawLine_del_click\');\r\n" + "});\r\n" + "$(document).on(\'click\', \'.DrawLine_delall_click\', function () {\r\n" + " tabledelall(\'.DrawLine\', \'DrawLine_delall_click\');\r\n" + "});\r\n" + "/******************************/\r\n" + "$(document).on(\'click\', \'.DrawRectangle_add_click\', function () {\r\n" + " tableadd(\'.Rectangle\', \'DrawRectangle_add_click\', \'.DrawRectangle_del_click\');\r\n" + "});\r\n" + "$(document).on(\'click\', \'.DrawRectangle_del_click\', function () {\r\n" + " tabledel(\'.Rectangle\', \'DrawRectangle_del_click\');\r\n" + "});\r\n" + "$(document).on(\'click\', \'.DrawRectangle_delall_click\', function () {\r\n" + " tabledelall(\'.DrawRectangle\', \'DrawRectangle_delall_click\');\r\n" + "});\r\n" + "/******************************/\r\n" + "$(document).on(\'click\', \'.DrawCircle_add_click\', function () {\r\n" + " tableadd(\'.Circle\', \'DrawCircle_add_click\', \'.DrawCircle_del_click\');\r\n" + "});\r\n" + "$(document).on(\'click\', \'.DrawCircle_del_click\', function () {\r\n" + " tabledel(\'.Circle\', \'DrawCircle_del_click\');\r\n" + "});\r\n" + "$(document).on(\'click\', \'.DrawCircle_delall_click\', function () {\r\n" + " tabledelall(\'.DrawCircle\', \'DrawCircle_delall_click\');\r\n" + "});\r\n" + "/******************************/\r\n" + "$(document).on(\'click\', \'.DrawString_add_click\', function () {\r\n" + " tableadd(\'.String\', \'DrawString_add_click\', \'.DrawString_del_click\');\r\n" + "});\r\n" + "$(document).on(\'click\', \'.DrawString_del_click\', function () {\r\n" + " tabledel(\'.String\', \'DrawString_del_click\');\r\n" + "});\r\n" + "$(document).on(\'click\', \'.DrawString_delall_click\', function () {\r\n" + " tabledelall(\'.DrawString\', \'DrawString_delall_click\');\r\n" + "});\r\n" + "/* */\r\n" + "$(document).on(\'click\', \'.ShowPic_add_click\', function () {\r\n" + " tableadd(\'.pic\', \'ShowPic_add_click\', \'.ShowPic_del_click\');\r\n" + "});\r\n" + "$(document).on(\'click\', \'.ShowPic_del_click\', function () {\r\n" + " tabledel(\'.pic\', \'ShowPic_del_click\');\r\n" + "});\r\n" + "$(document).on(\'click\', \'.ShowPic_delall_click\', function () {\r\n" + " tabledelall(\'.ShowPic\', \'ShowPic_delall_click\');\r\n" + "});\r\n" + "var imgURL = new Array;\r\n" + "$(document).on(\'change\',\'.preview_img\',function(event){\r\n" + " var numname = $(this).parents(\'tr\').find(\'td\').eq(0).html();\r\n" + " consoledebug(numname);\r\n" + " var fileList = event.target.files[0];\r\n" + " consoledebug(fileList.name);\r\n" + " $(this).parents(\'tr\').find(\'span\').empty();\r\n" + " $(this).parents(\'tr\').find(\'span\').append(fileList.name);\r\n" + " var reader = new FileReader();\r\n" + " reader.readAsDataURL(fileList);\r\n" + " reader.onload = function (e) {\r\n" + " imgURL[numname - 1] = reader.result;\r\n" + " console.info(imgURL[numname - 1]);\r\n" + " drawing();\r\n" + " }\r\n" + "});\r\n" + "var curPal;\r\n" + "var source;\r\n" + "var dX, dY, dW, dH, sW, sH;\r\n" + "function getVal(p, i) {\r\n" + " if ((p.data[i] == 0x00) && (p.data[i + 1] == 0x00)) return 0;\r\n" + " if ((p.data[i] == 0xFF) && (p.data[i + 1] == 0xFF)) return 1;\r\n" + " if ((p.data[i] == 0x7F) && (p.data[i + 1] == 0x7F)) return 2;\r\n" + " return 3;\r\n" + "}\r\n" + "function setVal(p, i, c) {\r\n" + " p.data[i] = curPal[c][0];\r\n" + " p.data[i + 1] = curPal[c][1];\r\n" + " p.data[i + 2] = curPal[c][2];\r\n" + " p.data[i + 3] = 255;\r\n" + "}\r\n" + "function addVal(c, r, g, b, k) {\r\n" + " return [c[0] + (r * k) / 32, c[1] + (g * k) / 32, c[2] + (b * k) / 32];\r\n" + "}\r\n" + "function getErr(r, g, b, stdCol) {\r\n" + " r -= stdCol[0];\r\n" + " g -= stdCol[1];\r\n" + " b -= stdCol[2];\r\n" + " return r * r + g * g + b * b;\r\n" + "}\r\n" + "function getNear(r, g, b) {\r\n" + " var ind = 0;\r\n" + " var err = getErr(r, g, b, curPal[0]);\r\n" + " for (var i = 1; i < curPal.length; i++) {\r\n" + " var cur = getErr(r, g, b, curPal[i]);\r\n" + " if (cur < err) { err = cur; ind = i; }\r\n" + " }\r\n" + " return ind;\r\n" + "}\r\n" + "var imgpDst = new Array;\r\n" + "$(document).on(\'click\',\'.imagemode-js\',function(){\r\n" + " var numname = $(this).parents(\'tr\').find(\'td\').eq(0).html();\r\n" + " var img= new Image();\r\n" + " img.src = imgURL[numname - 1]; \r\n" + " consoledebug(\'img.width = \' + img.width + \',img.height = \' + img.height);\r\n" + " if (img.width == 0) {\r\n" + " alert(\'First upload image num:\' + numname);\r\n" + " return;\r\n" + " }\r\n" + " if (img.width < 3 || img.height < 3) {\r\n" + " alert(\'Image is too small, please Reselect image\');\r\n" + " return;\r\n" + " }\r\n" + " \r\n" + " var source = document.getElementById(\'epdCanvas\');\r\n" + " var canvas = document.getElementById(\'epdCanvas2\');\r\n" + " var x0 = x = $(\'.pic\').find(\'.DrawNav\').find(\'input\').eq(3 * (numname - 1)).val();\r\n" + " var y0 = y = $(\'.pic\').find(\'.DrawNav\').find(\'input\').eq(3 * (numname - 1) + 1).val();\r\n" + " consoledebug(\'x = \' + x + \',y = \' + y);\r\n" + " dX = 0;\r\n" + " dY = 0;\r\n" + " sW = img.width;\r\n" + " sH = img.height;\r\n" + " dW = img.width;\r\n" + " dH = img.height;\r\n" + " console.log(\'dX = \' + dX);\r\n" + " console.log(\'dY = \' + dY);\r\n" + " console.log(\'dW = \' + dW);\r\n" + " console.log(\'dH = \' + dH);\r\n" + " var pSrc = canvas.getContext(\'2d\').getImageData(x, y, sW, sH);\r\n" + " var pDst = source.getContext(\'2d\').getImageData(x, y, dW, dH);\r\n" + " var isLvl = (this.value & 0x02) == 0?1:0;\r\n" + " var isRed = this.value & 0x01;\r\n" + " consoledebug(\'isLvl = \' + isLvl + \',isRed = \' + isRed);\r\n" + " consoledebug(\'epdArr[epdnum][4] = \' + epdArr[epdnum][4]);\r\n" + " var palInd = epdArr[epdnum][4];\r\n" + " if (isRed && ((palInd & 1) == 0)) {\r\n" + " alert(\'This white-black display\');\r\n" + " return;\r\n" + " }\r\n" + " if (!isRed) palInd = palInd & 0xFE;\r\n" + " console.log(\'palInd = \' + palInd);\r\n" + " curPal = palArr[palInd];\r\n" + " var index = 0;\r\n" + " if (isLvl) {\r\n" + " consoledebug(\'isLvl\');\r\n" + " for (var j = 0; j < dH; j++) {\r\n" + " var y = dY + j;\r\n" + " if ((y < 0) || (y >= sH)) {\r\n" + " for (var i = 0; i < dW; i++ , index += 4) \r\n" + " setVal(pDst, index, (i + j) % 2 == 0 ? 1 : 0);\r\n" + " continue;\r\n" + " }\r\n" + " for (var i = 0; i < dW; i++) {\r\n" + " var x = dX + i;\r\n" + " if ((x < 0) || (x >= sW)) {\r\n" + " setVal(pDst, index, (i + j) % 2 == 0 ? 1 : 0);\r\n" + " index += 4;\r\n" + " continue;\r\n" + " }\r\n" + " var pos = (y * sW + x) * 4;\r\n" + " setVal(pDst, index, getNear(pSrc.data[pos], pSrc.data[pos + 1], pSrc.data[pos + 2]));\r\n" + " index += 4;\r\n" + " }\r\n" + " }\r\n" + " } else {\r\n" + " consoledebug(\'isRed\');\r\n" + " var aInd = 0;\r\n" + " var bInd = 1;\r\n" + " var errArr = new Array(2);\r\n" + " errArr[0] = new Array(dW);\r\n" + " errArr[1] = new Array(dW);\r\n" + " for (var i = 0; i < dW; i++)\r\n" + " errArr[bInd][i] = [0, 0, 0];\r\n" + " for (var j = 0; j < dH; j++) {\r\n" + " var y = dY + j;\r\n" + " if ((y < 0) || (y >= sH)) {\r\n" + " for (var i = 0; i < dW; i++ , index += 4)\r\n" + " setVal(pDst, index, (i + j) % 2 == 0 ? 1 : 0);\r\n" + " continue;\r\n" + " }\r\n" + " aInd = ((bInd = aInd) + 1) & 1;\r\n" + " for (var i = 0; i < dW; i++)errArr[bInd][i] = [0, 0, 0];\r\n" + " for (var i = 0; i < dW; i++) {\r\n" + " var x = dX + i;\r\n" + " if ((x < 0) || (x >= sW)) {\r\n" + " setVal(pDst, index, (i + j) % 2 == 0 ? 1 : 0);\r\n" + " index += 4;\r\n" + " continue;\r\n" + " }\r\n" + " var pos = (y * sW + x) * 4;\r\n" + " var old = errArr[aInd][i];\r\n" + " var r = pSrc.data[pos] + old[0];\r\n" + " var g = pSrc.data[pos + 1] + old[1];\r\n" + " var b = pSrc.data[pos + 2] + old[2];\r\n" + " var colVal = curPal[getNear(r, g, b)];\r\n" + " pDst.data[index++] = colVal[0];\r\n" + " pDst.data[index++] = colVal[1];\r\n" + " pDst.data[index++] = colVal[2];\r\n" + " pDst.data[index++] = 255;\r\n" + " r = (r - colVal[0]);\r\n" + " g = (g - colVal[1]);\r\n" + " b = (b - colVal[2]);\r\n" + " if (i == 0) {\r\n" + " errArr[bInd][i] = addVal(errArr[bInd][i], r, g, b, 7.0);\r\n" + " errArr[bInd][i + 1] = addVal(errArr[bInd][i + 1], r, g, b, 2.0);\r\n" + " errArr[aInd][i + 1] = addVal(errArr[aInd][i + 1], r, g, b, 7.0);\r\n" + " } else if (i == dW - 1) {\r\n" + " errArr[bInd][i - 1] = addVal(errArr[bInd][i - 1], r, g, b, 7.0);\r\n" + " errArr[bInd][i] = addVal(errArr[bInd][i], r, g, b, 9.0);\r\n" + " } else {\r\n" + " errArr[bInd][i - 1] = addVal(errArr[bInd][i - 1], r, g, b, 3.0);\r\n" + " errArr[bInd][i] = addVal(errArr[bInd][i], r, g, b, 5.0);\r\n" + " errArr[bInd][i + 1] = addVal(errArr[bInd][i + 1], r, g, b, 1.0);\r\n" + " errArr[aInd][i + 1] = addVal(errArr[aInd][i + 1], r, g, b, 7.0);\r\n" + " }\r\n" + " }\r\n" + " }\r\n" + " }\r\n" + " // canvas.getContext(\'2d\').putImageData(pDst, x0, y0);\r\n" + " imgpDst[numname - 1] = pDst;\r\n" + " source.getContext(\'2d\').putImageData(pDst, x0, y0);\r\n" + "});\r\n" + "function drawing(){\r\n" + " var c = document.getElementById(\'epdCanvas\');\r\n" + " var cxt = c.getContext(\'2d\');\r\n" + " cxt.clearRect(0, 0, canvasWidth, canvasHeight);\r\n" + " var x, y, color, size;\r\n" + " if (DrawIfShow[0][1] == 1) {\r\n" + " var len = $(\"input[name=\'Point_x\']\").length;\r\n" + " consoledebug(\'Point len = \' + len);\r\n" + " for (var i = 0; i < len; i++) {\r\n" + " x = $(\'.Point\').find(\'.DrawNav\').find(\'input\').eq(2 * i).val();\r\n" + " y = $(\'.Point\').find(\'.DrawNav\').find(\'input\').eq(2 * i + 1).val();\r\n" + " color = $(\'.Point\').find(\'.DrawNav\').find(\'option:selected\').eq(2 * i).val();\r\n" + " size = $(\'.Point\').find(\'.DrawNav\').find(\'option:selected\').eq(2 * i + 1).val();\r\n" + " cxt.fillStyle = (color == 0 ? \'#FFFFFF\' : (color == 1 ? \'#000000\' : \'#FF0000\'));\r\n" + " cxt.fillRect(x, y, size, size);\r\n" + " }\r\n" + " }\r\n" + " var x1, y1, x2, y2, color, size, style;\r\n" + " if (DrawIfShow[1][1] == 1) {\r\n" + " var len = $(\"input[name=\'Line_x1\']\").length;\r\n" + " consoledebug(\'Line len = \' + len);\r\n" + " for (var i = 0; i < len; i++) {\r\n" + " x1 = $(\'.Line\').find(\'.DrawNav\').find(\'input\').eq(4 * i).val();\r\n" + " y1 = $(\'.Line\').find(\'.DrawNav\').find(\'input\').eq(4 * i + 1).val();\r\n" + " x2 = $(\'.Line\').find(\'.DrawNav\').find(\'input\').eq(4 * i + 2).val();\r\n" + " y2 = $(\'.Line\').find(\'.DrawNav\').find(\'input\').eq(4 * i + 3).val();\r\n" + " color = $(\'.Line\').find(\'.DrawNav\').find(\'option:selected\').eq(3 * i).val();\r\n" + " size = $(\'.Line\').find(\'.DrawNav\').find(\'option:selected\').eq(3 * i + 1).val();\r\n" + " style = $(\'.Line\').find(\'.DrawNav\').find(\'option:selected\').eq(3 * i + 2).val();\r\n" + " cxt.beginPath();\r\n" + " cxt.strokeStyle = (color == 0 ? \'#FFFFFF\' : (color == 1 ? \'#000000\' : \'#FF0000\'));\r\n" + " cxt.lineWidth = size;\r\n" + " cxt.setLineDash(style == 1 ? [5, 0] : [5, 2]);\r\n" + " cxt.moveTo(x1, y1);\r\n" + " cxt.lineTo(x2, y2);\r\n" + " cxt.stroke();\r\n" + " }\r\n" + " }\r\n" + " var x1, y1, x2, y2, color, size, fill;\r\n" + " if (DrawIfShow[2][1] == 1) {\r\n" + " var len = $(\"input[name=\'Rectangle_x1\']\").length;\r\n" + " consoledebug(\'Rectangle len = \' + len);\r\n" + " for (var i = 0; i < len; i++) {\r\n" + " x1 = $(\'.Rectangle\').find(\'.DrawNav\').find(\'input\').eq(4 * i).val();\r\n" + " y1 = $(\'.Rectangle\').find(\'.DrawNav\').find(\'input\').eq(4 * i + 1).val();\r\n" + " x2 = $(\'.Rectangle\').find(\'.DrawNav\').find(\'input\').eq(4 * i + 2).val();\r\n" + " y2 = $(\'.Rectangle\').find(\'.DrawNav\').find(\'input\').eq(4 * i + 3).val();\r\n" + " color = $(\'.Rectangle\').find(\'.DrawNav\').find(\'option:selected\').eq(3 * i).val();\r\n" + " size = $(\'.Rectangle\').find(\'.DrawNav\').find(\'option:selected\').eq(3 * i + 1).val();\r\n" + " fill = $(\'.Rectangle\').find(\'.DrawNav\').find(\'option:selected\').eq(3 * i + 2).val();\r\n" + " if (x1 > x2) {\r\n" + " var x = x1;\r\n" + " x1 = x2;\r\n" + " x2 = x;\r\n" + " }\r\n" + " if (y1 > y2) {\r\n" + " var x = x1;\r\n" + " x1 = x2;\r\n" + " x2 = x;\r\n" + " }\r\n" + " if (fill == 1) {\r\n" + " cxt.beginPath();\r\n" + " cxt.lineWidth = size;\r\n" + " cxt.strokeStyle = (color == 0 ? \'#FFFFFF\' : (color == 1 ? \'#000000\' : \'#FF0000\'));\r\n" + " cxt.rect(x1, y1, x2 - x1, y2 - y1);\r\n" + " cxt.setLineDash([5, 0]);\r\n" + " cxt.stroke();\r\n" + " } else {\r\n" + " cxt.fillStyle = (color == 0 ? \'#FFFFFF\' : (color == 1 ? \'#000000\' : \'#FF0000\'));\r\n" + " cxt.fillRect(x1, y1, x2 - x1, y2 - y1);\r\n" + " }\r\n" + " }\r\n" + " }\r\n" + " var x, y, r, color, size, fill;\r\n" + " if (DrawIfShow[3][1] == 1) {\r\n" + " var len = $(\"input[name=\'Circle_x\']\").length;\r\n" + " consoledebug(\'Circle len = \' + len);\r\n" + " for (var i = 0; i < len; i++) {\r\n" + " x = $(\'.Circle\').find(\'.DrawNav\').find(\'input\').eq(3 * i).val();\r\n" + " y = $(\'.Circle\').find(\'.DrawNav\').find(\'input\').eq(3 * i + 1).val();\r\n" + " r = $(\'.Circle\').find(\'.DrawNav\').find(\'input\').eq(3 * i + 2).val();\r\n" + " color = $(\'.Circle\').find(\'.DrawNav\').find(\'option:selected\').eq(3 * i).val();\r\n" + " size = $(\'.Circle\').find(\'.DrawNav\').find(\'option:selected\').eq(3 * i + 1).val();\r\n" + " fill = $(\'.Circle\').find(\'.DrawNav\').find(\'option:selected\').eq(3 * i + 2).val();\r\n" + " cxt.beginPath();\r\n" + " cxt.lineWidth = size;\r\n" + " cxt.strokeStyle = (color == 0 ? \'#FFFFFF\' : (color == 1 ? \'#000000\' : \'#FF0000\'));\r\n" + " cxt.arc(x, y, r, 0, 360);\r\n" + " if (fill == 2) {\r\n" + " cxt.fillStyle = (color == 0 ? \'#FFFFFF\' : (color == 1 ? \'#000000\' : \'#FF0000\'));\r\n" + " cxt.fill();\r\n" + " }\r\n" + " cxt.stroke();\r\n" + " }\r\n" + " }\r\n" + " var x, y, str, size, fontcolor;\r\n" + " if (DrawIfShow[4][1] == 1) {\r\n" + " var len = $(\"input[name=\'String_x\']\").length;\r\n" + " consoledebug(\'String len = \' + len);\r\n" + " for (var i = 0; i < len; i++) {\r\n" + " x = $(\'.String\').find(\'.DrawNav\').find(\'input\').eq(3 * i).val();\r\n" + " y = $(\'.String\').find(\'.DrawNav\').find(\'input\').eq(3 * i + 1).val();\r\n" + " str = $(\'.String\').find(\'.DrawNav\').find(\'input\').eq(3 * i + 2).val();\r\n" + " size = $(\'.String\').find(\'.DrawNav\').find(\'option:selected\').eq(2 * i).val();\r\n" + " fontcolor = $(\'.String\').find(\'.DrawNav\').find(\'option:selected\').eq(2 * i + 1).val();\r\n" + " consoledebug(\'size = \' + size);\r\n" + " cxt.font = size + \'px Georgia\';\r\n" + " cxt.fillStyle = (fontcolor == 0 ? \'#FFFFFF\' : (fontcolor == 1 ? \'#000000\' : \'#FF0000\'));\r\n" + " cxt.fillText(str, x, y);\r\n" + " }\r\n" + " }\r\n" + " var x, y;\r\n" + " if (DrawIfShow[5][1] == 1) {\r\n" + " var c2 = document.getElementById(\'epdCanvas2\');\r\n" + " var cxt2 = c2.getContext(\'2d\');\r\n" + " cxt2.clearRect(0, 0, canvasWidth, canvasHeight);\r\n" + " var len = $(\"input[name=\'img_x\']\").length;\r\n" + " consoledebug(\'pic len = \' + len);\r\n" + " for (var i = 0; i < len; i++) {\r\n" + " x = $(\'.pic\').find(\'.DrawNav\').find(\'input\').eq(3 * i).val();\r\n" + " y = $(\'.pic\').find(\'.DrawNav\').find(\'input\').eq(3 * i + 1).val();\r\n" + " var img= new Image();\r\n" + " img.src = imgURL[i]; \r\n" + " consoledebug(\'pic:\' + i + \'x:\' + x + \'y:\' + y + \' -img.src = \' + img.src); \r\n" + " \r\n" + " cxt2.drawImage(img, x, y, img.width, img.height);\r\n" + " \r\n" + " cxt.putImageData(imgpDst[len - 1], x, y);\r\n" + " }\r\n" + " }\r\n" + "}\r\n" + "$(document).on(\'click\', \'input\', function() {\r\n" + " drawing();\r\n" + "})\r\n" + "$(document).on(\'blur\', \'input\', function() {\r\n" + " drawing();\r\n" + "})\r\n" + "$(document).on(\'click\', \'select\', function () {\r\n" + " drawing();\r\n" + "});\r\n" + "$(document).on(\'click\', \'.uploadimage_button\', function () {\r\n" + " var imagex = epdArr[epdnum][1];\r\n" + " var imagey = epdArr[epdnum][2];\r\n" + " var c = document.getElementById(\'epdCanvas\');\r\n" + " var data = c.getContext(\'2d\').getImageData(0, 0, imagex, imagey).data;\r\n" + " // console.log(data);\r\n" + " //Convert rgb888 image to black and white with 1bit = 1pixel\r\n" + " var blackimgbit = new Array(imagex * imagey);\r\n" + " var ryimgbit = new Array(imagex * imagey);\r\n" + " for (var i = 0; i < imagex * imagey; i++) {\r\n" + " blackimgbit[i] = 1;\r\n" + " ryimgbit[i] = 1;\r\n" + " } \r\n" + " for (var i = 0; i < imagex * imagey; i++) {\r\n" + " // for (var i = 0; i < 240; i++) {\r\n" + " if (data[4 * i + 3] != 0) {\r\n" + " if (data[4 * i] == 0 && data[4 * i + 1] == 0 && data[4 * i + 2] == 0) {// black\r\n" + " blackimgbit[i] = 0;\r\n" + " }else if(!(data[4 * i] == 255 && data[4 * i + 1] == 255 && data[4 * i + 2] == 255)){// Non-white, red or yellow\r\n" + " ryimgbit[i] = 0;\r\n" + " }\r\n" + " }\r\n" + " }\r\n" + " //Convert 4bit to characters, 0000-1111 to a-p for easy sending\r\n" + " var xstr = ((imagex % 4 == 0)? (imagex / 4): (imagex / 4 + 1));\r\n" + " var ystr = imagey;\r\n" + " var bimg = new Array(xstr * ystr);\r\n" + " var ryimg = new Array(xstr * ystr);\r\n" + " for (var i = 0; i < xstr * ystr; i++) {\r\n" + " bimg[i] = 0x00;\r\n" + " ryimg[i] = 0x00;\r\n" + " } \r\n" + " var x = 0, j = 0;\r\n" + " bimgMsg = \'\';\r\n" + " ryimgMsg = \'\';\r\n" + " for (var i = 0; i < imagex * imagey; i++) {\r\n" + " // for (var i = 0; i < 240; i++) {\r\n" + " bimg[x] += blackimgbit[i]<< (3 - j);\r\n" + " ryimg[x] += ryimgbit[i]<< (3 - j);\r\n" + " j = j + 1;\r\n" + " if(j == 4){\r\n" + " j = 0;\r\n" + " bimgMsg += String.fromCharCode(bimg[x] + 97);\r\n" + " ryimgMsg += String.fromCharCode(ryimg[x] + 97);\r\n" + " x++;\r\n" + " }\r\n" + " }\r\n" + " bimgm1s1m2s2=\'\';\r\n" + " ryimgm1s1m2s2=\'\';\r\n" + " for(var i = 0; i < 492; i++){\r\n" + " bimgm1s1m2s2 += bimgMsg.substr(i * 326, 162);\r\n" + " ryimgm1s1m2s2 += ryimgMsg.substr(i * 326, 162);\r\n" + " }\r\n" + " for(var i = 0; i < 492; i++){\r\n" + " bimgm1s1m2s2 += bimgMsg.substr(i * 326 + 162, 164);\r\n" + " ryimgm1s1m2s2 += ryimgMsg.substr(i * 326 + 162, 164);\r\n" + " }\r\n" + " for(var i = 492; i < 984; i++){\r\n" + " bimgm1s1m2s2 += bimgMsg.substr(i * 326, 162);\r\n" + " ryimgm1s1m2s2 += ryimgMsg.substr(i * 326, 162);\r\n" + " }\r\n" + " for(var i = 492; i < 984; i++){\r\n" + " bimgm1s1m2s2 += bimgMsg.substr(i * 326 + 162, 164);\r\n" + " ryimgm1s1m2s2 += ryimgMsg.substr(i * 326 + 162, 164);\r\n" + " }\r\n" + " //Send 30,000 characters at a time, and more may fail\r\n" + " var Btime = Math.ceil(bimgm1s1m2s2.length/30000);//Rounded up\r\n" + " var RYtime = Math.ceil(ryimgm1s1m2s2.length/30000);\r\n" + " // consoledebug(\'alltime = \' + Btime);\r\n" + " \r\n" + " var bnext = 0, rynext = 0;\r\n" + " var show = 0;\r\n" + " // consoledebug(\'bimgm1s1m2s2 = \' + bimgm1s1m2s2.substr(bnext*30000,30000));\r\n" + " var url = \'http://\' + document.getElementById(\'DeviceIP\').value + \'/\';\r\n" + " xmlHttp = new XMLHttpRequest();\r\n" + " consoledebug(\'send EPD\');\r\n" + " xmlHttp.open(\'POST\', url + \'EPD\', true); \r\n" + " xmlHttp.send(epdArr[epdnum][0]);\r\n" + " xmlHttp.onload = xmlHttp.onerror = function () {\r\n" + "consoledebug(xmlHttp.status);" + " //black\r\n" + " if (xmlHttp.status==200 && bnextBtime && epdArr[epdnum][3]!=0 && rynextBtime && epdArr[epdnum][0]!=0)// r/b/w\r\n" + " rynext++;\r\n" + " //SHOW\r\n" + " if (xmlHttp.status==200 && epdArr[epdnum][3]==0 && bnext>Btime && show==0) {\r\n" + " consoledebug(\'SHOW\');\r\n" + " xmlHttp.open(\'POST\', url + \'SHOW\', true); \r\n" + " xmlHttp.send(epdArr[epdnum][0]);\r\n" + " show = 1;\r\n" + " }else if(xmlHttp.status==200 && rynext>RYtime && show==0){\r\n" + " consoledebug(\'SHOW\');\r\n" + " xmlHttp.open(\'POST\', url + \'SHOW\', true); \r\n" + " xmlHttp.send(epdArr[epdnum][0]);\r\n" + " show = 1;\r\n" + " }\r\n" + " };\r\n" + "});" + ); +} diff --git a/test/README b/test/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html