diff --git a/components/CalEPD/epdspi.cpp b/components/CalEPD/epdspi.cpp index 95f0655..88cbfbc 100644 --- a/components/CalEPD/epdspi.cpp +++ b/components/CalEPD/epdspi.cpp @@ -120,7 +120,6 @@ void EpdSpi::data(uint8_t data) assert(ret==ESP_OK); } - void EpdSpi::dataBuffer(uint8_t data) { spi_transaction_t t; @@ -163,3 +162,28 @@ void EpdSpi::reset(uint8_t millis=20) { gpio_set_level((gpio_num_t)CONFIG_EINK_RST, 1); vTaskDelay(millis / portTICK_RATE_MS); } + +/** + * Send multiple data in one transaction using vectors + */ +void EpdSpi::dataVector(vector _buffer) +{ + if (_buffer.size()==0) return; + + 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); +} \ No newline at end of file diff --git a/components/CalEPD/include/color/wave5i7Color.h b/components/CalEPD/include/color/wave5i7Color.h index 970bdfe..b319a72 100644 --- a/components/CalEPD/include/color/wave5i7Color.h +++ b/components/CalEPD/include/color/wave5i7Color.h @@ -13,6 +13,8 @@ #include #include #include +#include +using namespace std; // Controller: Unknown #define WAVE5I7COLOR_WIDTH 600 @@ -36,7 +38,9 @@ class Wave5i7Color : public Epd7Color private: EpdSpi& IO; - uint8_t _buffer[WAVE5I7COLOR_BUFFER_SIZE]; + vector _buffer; + vector::iterator buffer_it; + bool _vec_bonds_check = true; bool _initial = true; void _wakeUp(); diff --git a/components/CalEPD/include/epdspi.h b/components/CalEPD/include/epdspi.h index 1fa5c45..605e90f 100644 --- a/components/CalEPD/include/epdspi.h +++ b/components/CalEPD/include/epdspi.h @@ -2,6 +2,8 @@ #include "driver/spi_master.h" #include "driver/gpio.h" #include "iointerface.h" +#include +using namespace std; #ifndef epdspi_h #define epdspi_h @@ -14,7 +16,7 @@ class EpdSpi : IoInterface void data(uint8_t data) override; void dataBuffer(uint8_t data); void data(const uint8_t *data, int len) override; - + void dataVector(vector _buffer); void reset(uint8_t millis) override; void init(uint8_t frequency, bool debug) override; private: diff --git a/components/CalEPD/models/color/wave5i7Color.cpp b/components/CalEPD/models/color/wave5i7Color.cpp index 9906ff9..6dd21f4 100644 --- a/components/CalEPD/models/color/wave5i7Color.cpp +++ b/components/CalEPD/models/color/wave5i7Color.cpp @@ -32,9 +32,9 @@ void Wave5i7Color::fillScreen(uint16_t color) { uint8_t pv = _color7(color); uint8_t pv2 = pv | pv << 4; - for (uint32_t x = 0; x < sizeof(_buffer); x++) + for (uint32_t x = 0; x < WAVE5I7COLOR_BUFFER_SIZE; x++) { - _buffer[x] = pv2; + _buffer.push_back(pv2); } if (debug_enabled) printf("fillScreen(%x) black/red _buffer len:%d\n", color, sizeof(_buffer)); @@ -114,7 +114,7 @@ void Wave5i7Color::update() { for (uint16_t x = 1; x <= xLineBytes; x++) { - uint8_t data = i < sizeof(_buffer) ? _buffer[i] : 0x33; + uint8_t data = i < _buffer.size() ? _buffer.at(i) : 0x33; x1buf[x - 1] = data; if (x == xLineBytes) { // Flush the X line buffer to SPI @@ -130,7 +130,7 @@ void Wave5i7Color::update() } else { for (uint32_t i = 0; i < sizeof(_buffer); i++) { - IO.data(_buffer[i]); + IO.data(_buffer.at(i)); } } @@ -219,9 +219,18 @@ void Wave5i7Color::drawPixel(int16_t x, int16_t y, uint16_t color) { y = WAVE5I7COLOR_HEIGHT - y - 1; break; } - uint32_t i = x / 2 + uint32_t(y) * (WAVE5I7COLOR_WIDTH / 2); + uint32_t pos = x / 2 + uint32_t(y) * (WAVE5I7COLOR_WIDTH / 2); uint8_t pv = _color7(color); - if (x & 1) _buffer[i] = (_buffer[i] & 0xF0) | pv; - else _buffer[i] = (_buffer[i] & 0x0F) | (pv << 4); + // #43 TODO: Check why is trying to update out of bonds anyways + if (pos >= _buffer.size()) { + if (_vec_bonds_check) { + printf("x:%d y:%d Vpos:%d >out bonds\n",x,y, pos); + _vec_bonds_check = false; + } + return; + } + buffer_it = _buffer.begin()+pos; + if (x & 1) *(buffer_it) = (_buffer.at(pos) & 0xF0) | pv; + else *(buffer_it) = (_buffer.at(pos) & 0x0F) | (pv << 4); }