diff --git a/components/CalEPD/include/epdspi2cs.h b/components/CalEPD/include/epdspi2cs.h index ff497f4..08973cc 100644 --- a/components/CalEPD/include/epdspi2cs.h +++ b/components/CalEPD/include/epdspi2cs.h @@ -2,6 +2,8 @@ #include "driver/spi_master.h" #include "driver/gpio.h" #include "iointerface.h" +#include +using namespace std; #ifndef epdspi2cs_h #define epdspi2cs_h @@ -19,6 +21,7 @@ class EpdSpi2Cs : IoInterface void data(const uint8_t *data, int len) override; void reset(uint8_t millis) override; void init(uint8_t frequency, bool debug) override; + void dataVector(vector _buffer); void release(); uint8_t readTemp(); diff --git a/components/CalEPD/include/plasticlogic014.h b/components/CalEPD/include/plasticlogic014.h index 1802ce5..b331759 100644 --- a/components/CalEPD/include/plasticlogic014.h +++ b/components/CalEPD/include/plasticlogic014.h @@ -12,6 +12,8 @@ #include #include #include +#include +using namespace std; // Controller: UC8156 Manufacturer: https://www.plasticlogic.com/products/displays #define PLOGIC014_WIDTH 180 @@ -31,9 +33,12 @@ class PlasticLogic014 : public PlasticLogic private: EpdSpi2Cs& IO; - uint8_t _buffer[PLOGIC014_BUFFER_SIZE]; + // Vector test: + vector _buffer; + vector::iterator buffer_it; + //uint8_t _buffer[PLOGIC014_BUFFER_SIZE]; // Buffer sent to EPD prefixed with 0x10: - uint8_t bufferEpd[PLOGIC014_BUFFER_SIZE+1]; + //uint8_t bufferEpd[PLOGIC014_BUFFER_SIZE+1]; bool _initial = true; bool _debug_buffer = false; diff --git a/components/CalEPD/models/plasticlogic/epdspi2cs.cpp b/components/CalEPD/models/plasticlogic/epdspi2cs.cpp index 04aa2d4..ed1b2de 100644 --- a/components/CalEPD/models/plasticlogic/epdspi2cs.cpp +++ b/components/CalEPD/models/plasticlogic/epdspi2cs.cpp @@ -3,6 +3,7 @@ #include #include "freertos/task.h" #include "esp_log.h" +using namespace std; #ifdef CONFIG_IDF_TARGET_ESP32 #define EPD_HOST HSPI_HOST @@ -204,6 +205,35 @@ void EpdSpi2Cs::data(const uint8_t *data, int len) assert(ret==ESP_OK); } +/** + * Send multiple data in one transaction using vectors + */ +void EpdSpi2Cs::dataVector(vector _buffer) +{ + if (_buffer.size()==0) return; + /* uint8_t *data = 0; + for (int i = 0; i < _buffer.size(); i++) { + data[i] = _buffer.at(i); + } */ + + if (debug_enabled) { + printf("D\n"); + for (int i = 0; i < _buffer.size(); i++) { + printf("%x ", _buffer.operator[](i)); + } + printf("\n"); + } + esp_err_t ret; + spi_transaction_t t; + + memset(&t, 0, sizeof(t)); + t.length = _buffer.size()*8; + t.tx_buffer = _buffer.data(); + ret=spi_device_polling_transmit(spi, &t); + + assert(ret==ESP_OK); +} + void EpdSpi2Cs::reset(uint8_t millis=5) { gpio_set_level((gpio_num_t)CONFIG_EINK_RST, 0); vTaskDelay(millis / portTICK_RATE_MS); diff --git a/components/CalEPD/models/plasticlogic/plasticlogic014.cpp b/components/CalEPD/models/plasticlogic/plasticlogic014.cpp index 46eb933..db03669 100644 --- a/components/CalEPD/models/plasticlogic/plasticlogic014.cpp +++ b/components/CalEPD/models/plasticlogic/plasticlogic014.cpp @@ -9,8 +9,9 @@ PlasticLogic014::PlasticLogic014(EpdSpi2Cs& dio): Adafruit_GFX(PLOGIC014_WIDTH, PLOGIC014_HEIGHT), PlasticLogic(PLOGIC014_WIDTH, PLOGIC014_HEIGHT, dio), IO(dio) { - printf("PlasticLogic014() %d*%d\n", - PLOGIC014_WIDTH, PLOGIC014_HEIGHT); + + printf("PlasticLogic014() %d*%d buffer_vector_size:%d (at start)\n", + PLOGIC014_WIDTH, PLOGIC014_HEIGHT, _buffer.size()); } // Destructor @@ -35,7 +36,7 @@ void PlasticLogic014::init(bool debug) if (size != 14) { ESP_LOGE(TAG, "ATTENTION the size responded by the display: %d does not mach this class", size); } - + clearScreen(); _wakeUp(); //printf("Epaper temperature after wakeUp: %d °C\n", IO.readTemp()); @@ -44,10 +45,13 @@ void PlasticLogic014::init(bool debug) } void PlasticLogic014::clearScreen(){ - for (uint16_t x = 0; x < sizeof(_buffer); x++) + uint16_t x = 0; + for (x = 0; x < PLOGIC014_BUFFER_SIZE+1; x++) { - _buffer[x] = 0xff; + _buffer.push_back(0xff); //WHITE } + + printf("clearScreen() vector_size:%d RAM:%d\n", _buffer.size(), xPortGetFreeHeapSize()); } void PlasticLogic014::update(uint8_t updateMode) @@ -60,13 +64,10 @@ void PlasticLogic014::update(uint8_t updateMode) IO.data(pixelAccessPos, sizeof(pixelAccessPos)); - bufferEpd[0] = 0x10; - // Copy GFX buffer contents: - for (int i=1; i < sizeof(bufferEpd); i++) { - bufferEpd[i] = _buffer[i-1]; - } - - IO.data(bufferEpd,sizeof(bufferEpd)); + buffer_it = _buffer.begin(); + *(buffer_it) = 0x10; // First element + + IO.dataVector(_buffer); _waitBusy("Buffer sent", EPD_TMG_SRT); @@ -120,11 +121,17 @@ void PlasticLogic014::drawPixel(int16_t x, int16_t y, uint16_t color) { } y=y+3; - uint8_t pixels = _buffer[x/4 + (y) * _nextline]; + uint16_t pos = x/4 + (y) * _nextline; + + uint8_t pixels = _buffer.at(pos); + uint8_t pixel = 0xff; + switch (x%4) { //2-bit grayscale dot - case 0: _buffer[x/4 + (y) * _nextline] = (pixels & 0x3F) | ((uint8_t)color << 6); break; - case 1: _buffer[x/4 + (y) * _nextline] = (pixels & 0xCF) | ((uint8_t)color << 4); break; - case 2: _buffer[x/4 + (y) * _nextline] = (pixels & 0xF3) | ((uint8_t)color << 2); break; - case 3: _buffer[x/4 + (y) * _nextline] = (pixels & 0xFC) | (uint8_t)color; break; + case 0: pixel = (pixels & 0x3F) | ((uint8_t)color << 6); break; + case 1: pixel = (pixels & 0xCF) | ((uint8_t)color << 4); break; + case 2: pixel = (pixels & 0xF3) | ((uint8_t)color << 2); break; + case 3: pixel = (pixels & 0xFC) | (uint8_t)color; break; } + buffer_it = _buffer.begin()+pos+1; + *(buffer_it) = pixel; } diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index eb498fc..3d5b6aa 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -2,8 +2,8 @@ idf_component_register( # CALE official ESP-IDF Firmware #SRCS "cale.cpp" - SRCS "cale-7-color.cpp" - + #SRCS "cale-7-color.cpp" + # SRCS "demos/cale-sensor.cpp" # CALE with grayscale support (For now only plasticLogic) # Grayscale is also good to test parallel epaper with 16 gray levels @@ -20,7 +20,9 @@ idf_component_register( # Generic demos for any displays #SRCS "demos/demo-sleep-clock.cpp" # SRCS "demo-sleep-clock-v2.cpp" - # SRCS "demos/demo-fonts.cpp" + SRCS "demos/demo-fonts.cpp" + + #SRCS "demos/vector-test.cpp" # Demo to print 7 colors in Waveshare Acep epapers #SRCS "demos/demo-7-colors.cpp" diff --git a/main/demos/demo-fonts.cpp b/main/demos/demo-fonts.cpp index 98a1ba0..af4f679 100644 --- a/main/demos/demo-fonts.cpp +++ b/main/demos/demo-fonts.cpp @@ -3,29 +3,9 @@ #include "freertos/task.h" // Should match with your epaper module, size -#include -#include -#include -#include -#include -//#include -// Single SPI EPD -//EpdSpi io; -//Gdew075T8 display(io); -//Gdew075T7 display(io); -//Gdew042t2 display(io); -//Gdew0583T7 display(io); -//Gdew027w3 display(io); -//Gdeh0213b73 display(io); - -// Multi-SPI 4 channels EPD only - 12.48 Epaper display -// Please note that in order to use this big buffer (160 Kb) on this display external memory should be used -// Otherwise you will run out of DRAM very shortly! -//#include "wave12i48.h" // Only to use with Edp4Spi IO -#include "wave12i48BR.h" // Only to use with Edp4Spi IO, Black Red model -Epd4Spi io; -Wave12I48RB display(io); - +#include +EpdSpi2Cs io; +PlasticLogic014 display(io); // FONT used for title / message body - Only after display library @@ -34,9 +14,7 @@ Wave12I48RB display(io); //#include #include -#include -//#include -//#include + extern "C" { @@ -59,8 +37,8 @@ void app_main(void) { printf("CalEPD version: %s\n", CALEPD_VERSION); // Show available Dynamic Random Access Memory available after display.init() - printf("Fonts-demo. Free heap: %d (After epaper instantiation)\nDRAM : %d\n", - xPortGetFreeHeapSize(),heap_caps_get_free_size(MALLOC_CAP_8BIT)); + printf("Fonts-demo. Free heap: %d (After epaper instantiation)\n", + xPortGetFreeHeapSize()); // Bootstrap epaper class display.init(false); @@ -73,47 +51,24 @@ void app_main(void) display.setRotation(2); // 0 - 12.48 w/USB pointing down - display.fillScreen(EPD_RED); + display.fillScreen(EPD_LGRAY); display.update(); vTaskDelay(700); // short delay to demonstrate red color working display.fillScreen(EPD_WHITE); - display.fillCircle(300,300, 100, EPD_BLACK); + display.fillCircle(30,30, 10, EPD_LGRAY); - display.setCursor(10,40); + display.setCursor(1,10); display.setTextColor(EPD_BLACK); - display.setFont(&Ubuntu_M12pt8b); + display.setFont(&Ubuntu_M8pt8b); display.println("German characters test"); display.println("° äöü ÄÖÜ ß"); display.println("Löwen, Bären, Vögel und Käfer sind Tiere. Völlerei lässt grüßen! Heute ist 38° zu warm."); - display.println(""); - display.println("Spanish / French characters test"); - display.println("æçèé êëìí ï ñ"); - display.println("La cigüeña estaba sola en la caña. Estás allí?"); - display.newline(); // new way to add a newline - // German sentence - display.setFont(&Ubuntu_M8pt8b); - display.print("Ubuntu 8pt"); - display.setTextColor(EPD_RED); // test red characters - demo_chars(); - - - display.println(""); - display.print("\nUbuntu 12pt"); - display.setFont(&Ubuntu_M12pt8b); - display.setTextColor(EPD_RED); - display.setTextColor(EPD_WHITE); // test white on the black circle - demo_chars(); - - // Let's draw one 100px radius circle Black and another on the right 120px radius Red - display.fillCircle(300,650, 165, EPD_RED); // test bottom left quadrant - - display.fillCircle(600,300, 120, EPD_RED); - display.fillCircle(900,700, 150, EPD_BLACK); // test bottom right quadrant + //demo_chars(); display.update(); } diff --git a/main/demos/vector-test.cpp b/main/demos/vector-test.cpp new file mode 100644 index 0000000..5d9a642 --- /dev/null +++ b/main/demos/vector-test.cpp @@ -0,0 +1,50 @@ +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include +#include +using namespace std; + +vector vic(100); + + +extern "C" +{ + void app_main(); +} + + +void app_main() { + + uint16_t custom_size = 10000; + // 1068 bytes + /* + uint8_t static_buffer[custom_size]; + + for (uint16_t i = 0; i vic; + vector::iterator buffer_pos; + buffer_pos = vic.begin(); + + for (uint16_t i = 0; i<10; ++i) { + // Hangs everything + //vic.insert(buffer_pos+i, 0xff); + vic.push_back(0xff); + } + + //printf("Hello this is a Vector test\n"); + + printf("Free heap: %d vector size: %d\n", xPortGetFreeHeapSize(), vic.size()); +} \ No newline at end of file