Skip to content

Commit

Permalink
Merge branch 'refactor/oop'
Browse files Browse the repository at this point in the history
  • Loading branch information
martinberlin committed Mar 27, 2021
2 parents 4e9cc48 + 5595a1b commit 328492c
Show file tree
Hide file tree
Showing 51 changed files with 3,057 additions and 1,800 deletions.
Empty file added .gitmodules
Empty file.
6 changes: 4 additions & 2 deletions components/CalEPD/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ set(srcs
# Parallel epapers supported by Epdiy driver (Component)
"models/parallel/ED047TC1.cpp"
"models/parallel/ED047TC1touch.cpp"
"models/parallel/ED060SC4.cpp"

# Pending for more testing:
"models/gdeh0213b73.cpp"
Expand All @@ -48,10 +49,11 @@ set(srcs
)

# If the project does not use a touch display component FT6X36-IDF can be removed or #commented
idf_component_register(SRCS ${srcs}
idf_component_register(SRCS ${srcs}
REQUIRES "Adafruit-GFX"
REQUIRES "FT6X36-IDF"
REQUIRES "Epdiy-IDF"
REQUIRES "epd_driver"

INCLUDE_DIRS "include"
)

8 changes: 6 additions & 2 deletions components/CalEPD/epd7color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ void Epd7Color::newline() {

/**
* From GxEPD2 (Jean-Marc)
* TODO: Should be migrated to Epd7Color base class so is not copied on other models
* Converts from color constants to the right 4 bit pixel color in Acep epaper 7 color
*/
uint8_t Epd7Color::_color7(uint16_t color)
Expand All @@ -115,14 +114,19 @@ uint8_t Epd7Color::_color7(uint16_t color)
case EPD_RED: cv7 = 0x04; break;
case EPD_YELLOW: cv7 = 0x05; break;
case EPD_ORANGE: cv7 = 0x06; break;
case EPD_PURPLE: cv7 = 0x07; break;
default:
{
uint16_t red = color & 0xF800;
uint16_t green = (color & 0x07E0) << 5;
uint16_t blue = (color & 0x001F) << 11;
if ((red < 0x8000) && (green < 0x8000) && (blue < 0x8000)) cv7 = 0x00; // black

else if ((red > 0x9000) && (green > 0x8800) && (blue > 0x9000)
&& (red < 0xC000) && (green < 0xC000) && (blue < 0xC000) ) cv7 = 0x07; // purple
else if ((red >= 0x8000) && (green >= 0x8000) && (blue >= 0x8000)) cv7 = 0x01; // white
else if ((red >= 0x8000) && (blue >= 0x8000)) cv7 = red > blue ? 0x04 : 0x03; // red, blue

else if ((red >= 0x8000) && (blue >= 0x8000)) cv7 = red > blue ? 0x04 : 0x03; // red, blue
else if ((green >= 0x8000) && (blue >= 0x8000)) cv7 = green > blue ? 0x02 : 0x03; // green, blue
else if ((red >= 0x8000) && (green >= 0x8000))
{
Expand Down
3 changes: 2 additions & 1 deletion components/CalEPD/include/color/wave7colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
#define EPD_YELLOW 0xFFE0 // 255, 255, 0
#define EPD_BLUE 0x001F // 0, 0, 255
#define EPD_GREEN 0x07E0 // 0, 255, 0
#define EPD_ORANGE 0xFD20 // 255, 165, 0
#define EPD_ORANGE 0xFD20 // 255, 165, 0
#define EPD_PURPLE 0x41E8 // 67, 61, 68
8 changes: 4 additions & 4 deletions components/CalEPD/include/parallel/ED047TC1.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <Adafruit_GFX.h>
#include <epdspi.h>
#include "epd_driver.h"
#include "epd_highlevel.h"

#define HAS_16_LEVELS_GRAY 1
#define ED047TC1_WIDTH 960
Expand All @@ -31,23 +32,22 @@ class Ed047TC1 : public EpdParallel
{
public:
Ed047TC1();

uint8_t *framebuffer;
uint8_t colors_supported = 1;

void drawPixel(int16_t x, int16_t y, uint16_t color); // Override GFX own drawPixel method

void init(bool debug = false);
void clearScreen();
void clearArea(Rect_t area);
void clearArea(EpdRect area);
void powerOn();
void powerOff();

void fillScreen(uint16_t color);
void update(enum DrawMode mode = BLACK_ON_WHITE);
void update(enum EpdDrawMode mode = MODE_GC16);

// Partial update of rectangle from buffer to screen, does not power off
void updateWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h, enum DrawMode mode = BLACK_ON_WHITE, bool using_rotation = true);
void updateWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h, enum EpdDrawMode mode = MODE_GL4, bool using_rotation = true);

private:
bool _tempalert = false;
Expand Down
9 changes: 5 additions & 4 deletions components/CalEPD/include/parallel/ED047TC1touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <Adafruit_GFX.h>
#include <epdspi.h>
#include "epd_driver.h"
#include "epd_highlevel.h"
#include "L58Touch.h" // Touch interface

#define HAS_16_LEVELS_GRAY 1
Expand Down Expand Up @@ -41,14 +42,14 @@ class Ed047TC1t : public EpdParallel

void init(bool debug = false);
void clearScreen();
void clearArea(Rect_t area);
void clearArea(EpdRect area);
void powerOn();
void powerOff();

void fillScreen(uint16_t color);
void update(enum DrawMode mode = BLACK_ON_WHITE);
void update(enum EpdDrawMode mode = MODE_GC16);
// Partial update of rectangle from buffer to screen, does not power off
void updateWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h, enum DrawMode mode = BLACK_ON_WHITE, bool using_rotation = true);
void updateWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h, enum EpdDrawMode mode = MODE_EPDIY_BLACK_TO_GL16, bool using_rotation = true);

// Touch methods
void touchLoop();
Expand All @@ -58,7 +59,7 @@ class Ed047TC1t : public EpdParallel

private:
L58Touch& Touch;

EpdiyHighlevelState hl;
bool color = false;
bool _initial = true;
bool _debug_buffer = false;
Expand Down
50 changes: 50 additions & 0 deletions components/CalEPD/include/parallel/ED060SC4.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "esp_system.h"
#include <stdint.h>
#include <math.h>
#include "sdkconfig.h"
#include "esp_log.h"
#include <string>
#include <epdParallel.h>
#include <Adafruit_GFX.h>
#include <epdspi.h>
#include "epd_driver.h"
#include "epd_highlevel.h"
#include "parallel/grayscales.h"

#define HAS_16_LEVELS_GRAY 1
#define ED060SC4_WIDTH 800
#define ED060SC4_HEIGHT 600

class Ed060SC4 : public EpdParallel
{
public:
Ed060SC4();

uint8_t *framebuffer;
uint8_t colors_supported = 1;

void drawPixel(int16_t x, int16_t y, uint16_t color); // Override GFX own drawPixel method

void init(bool debug = false);
void clearScreen();
void clearArea(EpdRect area);
void powerOn();
void powerOff();

void fillScreen(uint16_t color);
void update(enum EpdDrawMode mode = MODE_GC16);

// Partial update of rectangle from buffer to screen, does not power off
void updateWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h, enum EpdDrawMode mode = MODE_EPDIY_BLACK_TO_GL16, bool using_rotation = true);

private:
EpdiyHighlevelState hl;
bool _tempalert = false;
bool _initial = true;
bool _debug_buffer = false;
void _rotate(uint16_t& x, uint16_t& y, uint16_t& w, uint16_t& h);
};
9 changes: 9 additions & 0 deletions components/CalEPD/include/parallel/grayscales.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// COLOR defines (Only 8 but actually this epapers have 16 levels)
#define EPD_WHITE 255
#define EPD_WHITISH 223
#define EPD_SLGRAY 200
#define EPD_LGRAY 150
#define EPD_GRAY 100
#define EPD_DGRAY 50
#define EPD_SDGRAY 25
#define EPD_BLACK 0
50 changes: 19 additions & 31 deletions components/CalEPD/models/parallel/ED047TC1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Ed047TC1::Ed047TC1():
printf("Ed047TC1() %d*%d\n",
ED047TC1_WIDTH, ED047TC1_HEIGHT);

framebuffer = (uint8_t *)heap_caps_malloc(ED047TC1_WIDTH * ED047TC1_HEIGHT / 2, MALLOC_CAP_SPIRAM);
memset(framebuffer, 0xFF, ED047TC1_WIDTH * ED047TC1_HEIGHT / 2);

// Not anymore allocated here. It returns from epd_init_hl
//framebuffer = (uint8_t *)heap_caps_malloc(ED047TC1_WIDTH * ED047TC1_HEIGHT / 2, MALLOC_CAP_SPIRAM);
//memset(framebuffer, 0xFF, ED047TC1_WIDTH * ED047TC1_HEIGHT / 2);
}

//Initialize the display
Expand All @@ -23,64 +23,52 @@ void Ed047TC1::init(bool debug)
debug_enabled = debug;
if (debug_enabled) printf("Ed047TC1::init(%d)\n", debug);

epd_init();
epd_init(EPD_OPTIONS_DEFAULT);
framebuffer = epd_init_hl(EPD_BUILTIN_WAVEFORM);

epd_poweron();
}

void Ed047TC1::fillScreen(uint16_t color) {
// Same as: fillRect(0, 0, ED047TC1_WIDTH, ED047TC1_HEIGHT, color);
epd_fill_rect(0, 0, ED047TC1_WIDTH, ED047TC1_HEIGHT, color, framebuffer);
// Same as old: fillRect(0, 0, ED047TC1_WIDTH, ED047TC1_HEIGHT, color);
epd_fill_rect(epd_full_screen(), color, framebuffer);
}

void Ed047TC1::clearScreen()
{
epd_clear();
}

void Ed047TC1::clearArea(Rect_t area) {
void Ed047TC1::clearArea(EpdRect area) {
epd_clear_area(area);
}

void Ed047TC1::update(enum DrawMode mode)
void Ed047TC1::update(enum EpdDrawMode mode)
{
epd_draw_image(epd_full_screen(), framebuffer, mode);
//epd_draw_image(epd_full_screen(), framebuffer, mode); // Old v1
epd_update_screen(framebuffer, mode);
}

void Ed047TC1::updateWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h, enum DrawMode mode, bool using_rotation)
void Ed047TC1::updateWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h, enum EpdDrawMode mode, bool using_rotation)
{
if (using_rotation) _rotate(x, y, w, h);
/* if (x >= ED047TC1_WIDTH) {
if (x >= ED047TC1_WIDTH) {
printf("Will not update. x position:%d is major than display max width:%d\n", x, ED047TC1_WIDTH);
return;
}
if (y >= ED047TC1_HEIGHT) {
printf("Will not update. y position:%d is major than display max height:%d\n", y, ED047TC1_HEIGHT);
return;
} */
Rect_t area = {
}
if (using_rotation) _rotate(x, y, w, h);

EpdRect area = {
.x = x,
.y = y,
.width = w,
.height = h,
};

uint8_t *buffer = (uint8_t *)heap_caps_malloc(w*h/2,MALLOC_CAP_SPIRAM);
memset(buffer, 0xFF, w*h/2);

uint32_t i = 0;
// Crop only this square from the big framebuffer
for (int16_t y1 = y; y1 < y+h; y1++)
{
for (int16_t x1 = x; x1 < x+w; x1=x1+2)
{
// 0xf0 fixed -> square with light gray. Issue is when trying to read the pixel
buffer[i] = framebuffer[y1 *ED047TC1_WIDTH / 2 + x1/2];
i++;
}
//printf("buffer y: %d line: %d\n",y1,i);
}

epd_draw_image(area, buffer, mode);
epd_update_area(mode, area);
}

void Ed047TC1::powerOn(void)
Expand Down
33 changes: 16 additions & 17 deletions components/CalEPD/models/parallel/ED047TC1touch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ Ed047TC1t::Ed047TC1t(L58Touch& ts):
{
printf("Ed047TC1t() w/touch %d*%d\n",
ED047TC1_WIDTH, ED047TC1_HEIGHT);

framebuffer = (uint8_t *)heap_caps_malloc(ED047TC1_WIDTH * ED047TC1_HEIGHT / 2, MALLOC_CAP_SPIRAM);
memset(framebuffer, 0xFF, ED047TC1_WIDTH * ED047TC1_HEIGHT / 2);
}

//Initialize the display
Expand All @@ -23,7 +20,9 @@ void Ed047TC1t::init(bool debug)
debug_enabled = debug;
if (debug_enabled) printf("Ed047TC1t::init(%d)\n", debug);

epd_init();
epd_init(EPD_OPTIONS_DEFAULT);
framebuffer = epd_init_hl(EPD_BUILTIN_WAVEFORM);

epd_poweron();
// Initialize touch. Default: 22 FT6X36_DEFAULT_THRESHOLD
Touch.begin(width(), height());
Expand All @@ -32,28 +31,28 @@ void Ed047TC1t::init(bool debug)
}

void Ed047TC1t::fillScreen(uint16_t color) {
// Same as: fillRect(0, 0, ED047TC1_WIDTH, ED047TC1_HEIGHT, color);
epd_fill_rect(0, 0, ED047TC1_WIDTH, ED047TC1_HEIGHT, color, framebuffer);
// Same as old: fillRect(0, 0, ED047TC1_WIDTH, ED047TC1_HEIGHT, color);
epd_fill_rect(epd_full_screen(), color, framebuffer);
}

void Ed047TC1t::clearScreen()
{
epd_clear();
}

void Ed047TC1t::clearArea(Rect_t area) {
void Ed047TC1t::clearArea(EpdRect area) {
epd_clear_area(area);
}

void Ed047TC1t::update(enum DrawMode mode)
void Ed047TC1t::update(enum EpdDrawMode mode)
{
epd_draw_image(epd_full_screen(), framebuffer, mode);
//epd_draw_image(epd_full_screen(), framebuffer, mode);
//Todo: First implemented on Ed047TC1.cpp
}


void Ed047TC1t::updateWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h, enum DrawMode mode, bool using_rotation)
void Ed047TC1t::updateWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h, enum EpdDrawMode mode, bool using_rotation)
{
if (using_rotation) _rotate(x, y, w, h);
if (x >= ED047TC1_WIDTH) {
printf("Will not update. x position:%d is major than display max width:%d\n", x, ED047TC1_WIDTH);
return;
Expand All @@ -62,16 +61,18 @@ void Ed047TC1t::updateWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h, enu
printf("Will not update. y position:%d is major than display max height:%d\n", y, ED047TC1_HEIGHT);
return;
}
if (using_rotation) _rotate(x, y, w, h);

Rect_t area = {
EpdRect area = {
.x = x,
.y = y,
.width = w,
.height = h,
};


uint8_t *buffer = (uint8_t *)heap_caps_malloc(w*h/2,MALLOC_CAP_SPIRAM);
epd_update_area(mode, area);
// Not needed. Saved for historical reasons
/* uint8_t *buffer = (uint8_t *)heap_caps_malloc(w*h/2,MALLOC_CAP_SPIRAM);
memset(buffer, 0xFF, w*h/2);
uint32_t i = 0;
Expand All @@ -85,9 +86,7 @@ void Ed047TC1t::updateWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h, enu
i++;
}
//printf("buffer y: %d line: %d\n",y1,i);
}

epd_draw_image(area, buffer, mode);
} */
}

void Ed047TC1t::powerOn(void)
Expand Down
Loading

0 comments on commit 328492c

Please sign in to comment.