Skip to content

Commit

Permalink
#14 Initial and failed test to use Vector (error in wakeup)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinberlin committed Jul 9, 2021
1 parent c66d355 commit 9de124a
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 78 deletions.
3 changes: 3 additions & 0 deletions components/CalEPD/include/epdspi2cs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "driver/spi_master.h"
#include "driver/gpio.h"
#include "iointerface.h"
#include <vector>
using namespace std;

#ifndef epdspi2cs_h
#define epdspi2cs_h
Expand All @@ -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<uint8_t> _buffer);

void release();
uint8_t readTemp();
Expand Down
9 changes: 7 additions & 2 deletions components/CalEPD/include/plasticlogic014.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <Adafruit_GFX.h>
#include <plasticlogic.h>
#include <epdspi2cs.h>
#include <vector>
using namespace std;

// Controller: UC8156 Manufacturer: https://www.plasticlogic.com/products/displays
#define PLOGIC014_WIDTH 180
Expand All @@ -31,9 +33,12 @@ class PlasticLogic014 : public PlasticLogic

private:
EpdSpi2Cs& IO;
uint8_t _buffer[PLOGIC014_BUFFER_SIZE];
// Vector test:
vector<uint8_t> _buffer;
vector<uint8_t>::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;
Expand Down
30 changes: 30 additions & 0 deletions components/CalEPD/models/plasticlogic/epdspi2cs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string.h>
#include "freertos/task.h"
#include "esp_log.h"
using namespace std;

#ifdef CONFIG_IDF_TARGET_ESP32
#define EPD_HOST HSPI_HOST
Expand Down Expand Up @@ -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<uint8_t> _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);
Expand Down
41 changes: 24 additions & 17 deletions components/CalEPD/models/plasticlogic/plasticlogic014.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
Expand All @@ -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)
Expand All @@ -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);

Expand Down Expand Up @@ -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;
}
8 changes: 5 additions & 3 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
67 changes: 11 additions & 56 deletions main/demos/demo-fonts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,9 @@
#include "freertos/task.h"

// Should match with your epaper module, size
#include <gdew042t2.h>
#include <gdew0583t7.h>
#include <gdew075T7.h>
#include <gdew075T8.h>
#include <gdew027w3.h>
//#include <gdeh0213b73.h>
// 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 <plasticlogic014.h>
EpdSpi2Cs io;
PlasticLogic014 display(io);


// FONT used for title / message body - Only after display library
Expand All @@ -34,9 +14,7 @@ Wave12I48RB display(io);

//#include <Fonts/ubuntu/Ubuntu_M18pt8b.h>
#include <Fonts/ubuntu/Ubuntu_M8pt8b.h>
#include <Fonts/ubuntu/Ubuntu_M12pt8b.h>
//#include <Fonts/ubuntu/Ubuntu_M16pt8b.h>
//#include <Fonts/ubuntu/Ubuntu_M20pt8b.h>


extern "C"
{
Expand All @@ -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);
Expand All @@ -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();
}
50 changes: 50 additions & 0 deletions main/demos/vector-test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <string.h>
#include <vector>
using namespace std;

vector<int> 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<sizeof(static_buffer); ++i) {
static_buffer[i] = 0xff;
} */



// Takes 1004 2072 of heap
/* uint8_t* p = (uint8_t*) malloc(custom_size);
memset(p, 1, custom_size); */

// int : 5072 of heap
// uint8_t : 2164 of heap
// Dynamic size vector
vector<uint8_t> vic;
vector<uint8_t>::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());
}

0 comments on commit 9de124a

Please sign in to comment.