From 5109d598dfbc3b7f65e6f4a300ef76ecba1cc88b Mon Sep 17 00:00:00 2001 From: mtribiere Date: Sat, 9 Jan 2021 22:45:18 +0100 Subject: [PATCH 1/2] Added drawing functions + improved stability --- main/EPD.c | 5 ++++ main/painterEPD.c | 72 +++++++++++++++++++---------------------------- main/painterEPD.h | 6 ++-- main/spiEPD.c | 4 +-- main/spi_epaper.c | 2 +- 5 files changed, 39 insertions(+), 50 deletions(-) diff --git a/main/EPD.c b/main/EPD.c index c0a15f9..22afc42 100644 --- a/main/EPD.c +++ b/main/EPD.c @@ -51,6 +51,8 @@ esp_err_t epaper_update(){ //Set RAM position epaper_write_cmd(0x4E); epaper_write_data(0x00); + + waitUntilIdle(); epaper_write_cmd(0x4F); epaper_write_data(0x00); @@ -66,6 +68,7 @@ esp_err_t epaper_update(){ } } + waitUntilIdle(); //Send update command epaper_write_cmd(0x22); @@ -87,6 +90,8 @@ esp_err_t epaper_clear(){ esp_err_t epaper_deepsleep(){ + waitUntilIdle(); + //Send deep sleep command epaper_write_cmd(0x10); epaper_write_data(0x01); diff --git a/main/painterEPD.c b/main/painterEPD.c index 5b9c42b..d1a002a 100644 --- a/main/painterEPD.c +++ b/main/painterEPD.c @@ -1,5 +1,17 @@ #include "painterEPD.h" + +esp_err_t epaper_inverse_color(){ + + for(int j = 0;j= 0 ? x1 - x0 : x0 - x1; + int sx = x0 < x1 ? 1 : -1; + int dy = y1 - y0 <= 0 ? y1 - y0 : y0 - y1; + int sy = y0 < y1 ? 1 : -1; + int err = dx + dy; + while((x0 != x1) && (y0 != y1)) { + epaper_draw_pixel(x0, y0 , BLACK); + if (2 * err >= dy) { + err += dy; + x0 += sx; + } + if (2 * err <= dx) { + err += dx; + y0 += sy; } - - drawed++; } return ESP_OK; - } + esp_err_t epaper_draw_char(char c,uint8_t x, uint8_t y, Font font){ //Font size in pixel diff --git a/main/painterEPD.h b/main/painterEPD.h index c88c39b..b5b0aa6 100644 --- a/main/painterEPD.h +++ b/main/painterEPD.h @@ -7,9 +7,6 @@ #define BLACK 0 #define WHITE 1 -//Define directions -enum Direction {UP, RIGHT, DOWN, LEFT}; - //Define font struct typedef struct{ uint16_t fontW; //Using 16 bits int to help memory management @@ -17,10 +14,11 @@ typedef struct{ uint8_t *charset; }Font; +esp_err_t epaper_inverse_color(); esp_err_t epaper_draw_pixel(uint8_t x, uint8_t y, uint8_t value); esp_err_t epaper_draw_square(uint8_t x, uint8_t y,uint8_t size); -esp_err_t epaper_draw_line(uint8_t x, uint8_t y, enum Direction direction, uint8_t length ,uint8_t width); +esp_err_t epaper_draw_line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1); esp_err_t epaper_draw_char(char c,uint8_t x, uint8_t y, Font font); esp_err_t epaper_draw_string(char *str,uint32_t size,uint8_t x, uint8_t y, Font font); diff --git a/main/spiEPD.c b/main/spiEPD.c index e9c63aa..0a73b57 100644 --- a/main/spiEPD.c +++ b/main/spiEPD.c @@ -26,11 +26,10 @@ esp_err_t waitUntilIdle(){ esp_err_t epaper_rst() { - gpio_set_level(EPAPER_RST_GPIO, 1); - delay_ms(200); gpio_set_level(EPAPER_RST_GPIO, 0); delay_ms(10); gpio_set_level(EPAPER_RST_GPIO, 1); + delay_ms(200); return ESP_OK; } @@ -171,6 +170,7 @@ esp_err_t init_SPI(){ trans.cmd = NULL; trans.addr = NULL; trans.mosi = NULL; + trans.miso = NULL; return ESP_OK; } \ No newline at end of file diff --git a/main/spi_epaper.c b/main/spi_epaper.c index 500cdd4..9f36f02 100644 --- a/main/spi_epaper.c +++ b/main/spi_epaper.c @@ -66,7 +66,7 @@ void app_main(void) epaper_draw_string("Hello world !",13,35,60,font20); epaper_draw_string("from ESP8266",12,40,52,font12); - + //Update the screen epaper_update(); From fd65d357471cffd57b221a7f7521191cb49aed96 Mon Sep 17 00:00:00 2001 From: mtribiere Date: Sun, 10 Jan 2021 14:57:47 +0100 Subject: [PATCH 2/2] Added drawing functions + stability improvement --- main/spi_epaper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/spi_epaper.c b/main/spi_epaper.c index 9f36f02..b644657 100644 --- a/main/spi_epaper.c +++ b/main/spi_epaper.c @@ -18,7 +18,6 @@ */ #include -#include #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -71,6 +70,7 @@ void app_main(void) epaper_update(); //Turn off the display + ESP_LOGI(TAG, "Sending deepsleep command"); epaper_deepsleep(); printf("====== Done, have a nice day ! ========\n");