Skip to content

Commit

Permalink
#43 Using vectors in wave5i7Color seems to compile without DRAM issues
Browse files Browse the repository at this point in the history
  • Loading branch information
martinberlin committed Jul 12, 2021
1 parent 5e6983c commit 578324b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
26 changes: 25 additions & 1 deletion components/CalEPD/epdspi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ void EpdSpi::data(uint8_t data)
assert(ret==ESP_OK);
}


void EpdSpi::dataBuffer(uint8_t data)
{
spi_transaction_t t;
Expand Down Expand Up @@ -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<uint8_t> _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);
}
6 changes: 5 additions & 1 deletion components/CalEPD/include/color/wave5i7Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <Adafruit_GFX.h>
#include <epdspi.h>
#include <color/wave7colors.h>
#include <vector>
using namespace std;

// Controller: Unknown
#define WAVE5I7COLOR_WIDTH 600
Expand All @@ -36,7 +38,9 @@ class Wave5i7Color : public Epd7Color
private:
EpdSpi& IO;

uint8_t _buffer[WAVE5I7COLOR_BUFFER_SIZE];
vector<uint8_t> _buffer;
vector<uint8_t>::iterator buffer_it;
bool _vec_bonds_check = true;

bool _initial = true;
void _wakeUp();
Expand Down
4 changes: 3 additions & 1 deletion components/CalEPD/include/epdspi.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 epdspi_h
#define epdspi_h
Expand All @@ -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<uint8_t> _buffer);
void reset(uint8_t millis) override;
void init(uint8_t frequency, bool debug) override;
private:
Expand Down
23 changes: 16 additions & 7 deletions components/CalEPD/models/color/wave5i7Color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand All @@ -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));
}
}

Expand Down Expand Up @@ -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);
}

0 comments on commit 578324b

Please sign in to comment.