diff --git a/.gitignore b/.gitignore index 3aa0ac9..70a670b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .config +.vscode *.o *.pyc *.a diff --git a/components/epaper/EPD.c b/components/epaper/EPD.c index e8b74e7..745954a 100644 --- a/components/epaper/EPD.c +++ b/components/epaper/EPD.c @@ -15,7 +15,8 @@ #include "time.h" #include #include "rom/tjpgd.h" -#include "esp_heap_alloc_caps.h" +//#include "esp_heap_alloc_caps.h" +#include "esp_heap_caps.h" #include "EPD.h" #include "EPDspi.h" #include "rom/tjpgd.h" @@ -2181,46 +2182,53 @@ static UINT tjd_output ( uint32_t len = ((dright-dleft+1) * (dbottom-dtop+1)); // calculate length of data - float gs_clr = 0; - uint8_t rgb_color[3]; - uint8_t last_lvl, i; + //float gs_clr = 0; + //uint8_t rgb_color[3]; + //uint8_t last_lvl, i; uint8_t pix; if ((len > 0) && (len <= JPG_IMAGE_LINE_BUF_SIZE)) { for (y = top; y <= bottom; y++) { for (x = left; x <= right; x++) { // Clip to display area if ((x >= dleft) && (y >= dtop) && (x <= dright) && (y <= dbottom)) { - // Directly convert color to 4-bit gray scale - pix = 0; - pix |= ((*src++) >> 4) & 0x08; - pix |= ((*src++) >> 5) & 0x06; - pix |= ((*src++) >> 7); - pix ^= 0x0F; - - - /* Convert rgb color to gray scale - memcpy(rgb_color, src, 3); - src += 3; - gs_clr = (GS_FACT_R * rgb_color[0]) + (GS_FACT_G * rgb_color[1]) + (GS_FACT_B * rgb_color[2]); - if (gs_clr > 255) gs_clr = 255; - // Use only 4 bits & invert - //pix = ((uint8_t)gs_clr >> 4) ^ 0x0F; - pix = (uint8_t)gs_clr; - - // Using gray scale lookup table - last_lvl = 0; - i = 0; - for (i=0; i<16; i++) { - if ((pix > last_lvl) && (pix <= lvl_buf_jpg[i])) { - pix = 15 - i; - last_lvl = lvl_buf[i]; - break; - } - last_lvl = lvl_buf[i]; - } - */ - gs_disp_buffer[(y * EPD_DISPLAY_WIDTH) + x] = pix; - gs_used_shades |= (1 << pix); + //if(_gs) { + // Directly convert color to 4-bit gray scale + pix = 0; + pix |= ((*src++) >> 4) & 0x08; + pix |= ((*src++) >> 5) & 0x06; + pix |= ((*src++) >> 7); + pix ^= 0x0F; + + /* Convert rgb color to gray scale + memcpy(rgb_color, src, 3); + src += 3; + gs_clr = (GS_FACT_R * rgb_color[0]) + (GS_FACT_G * rgb_color[1]) + (GS_FACT_B * rgb_color[2]); + if (gs_clr > 255) gs_clr = 255; + // Use only 4 bits & invert + //pix = ((uint8_t)gs_clr >> 4) ^ 0x0F; + pix = (uint8_t)gs_clr; + + // Using gray scale lookup table + last_lvl = 0; + i = 0; + for (i=0; i<16; i++) { + if ((pix > last_lvl) && (pix <= lvl_buf_jpg[i])) { + pix = 15 - i; + last_lvl = lvl_buf[i]; + break; + } + last_lvl = lvl_buf[i]; + } + */ + gs_disp_buffer[(y * EPD_DISPLAY_WIDTH) + x] = pix; + gs_used_shades |= (1 << pix); + /*} else { + pix = 0; + pix |= ((*src++) > 0); + pix ^= 0x01; + + + }*/ } else src += 3; // skip } diff --git a/components/epaper/EPDspi.c b/components/epaper/EPDspi.c index 278b253..a53cd7c 100644 --- a/components/epaper/EPDspi.c +++ b/components/epaper/EPDspi.c @@ -23,15 +23,9 @@ #define EPD_DEBUG 1 -#define EPD2X9 1 - - #define xDot 128 - #define yDot 296 - #define DELAYTIME 1500 - static uint8_t GDOControl[] = {0x01, (yDot-1)%256, (yDot-1)/256, 0x00}; static uint8_t softstart[4] = {0x0c, 0xd7, 0xd6, 0x9d}; -static uint8_t VCOMVol[2] = {0x2c, 0xa8}; // VCOM 7c +static uint8_t VCOMVol[2] = {0x2c, EPD_VCOM}; // VCOM 7c a8 static uint8_t DummyLine[2] = {0x3a, 0x1a}; // 4 dummy line per gate static uint8_t Gatetime[2] = {0x3b, 0x08}; // 2us per line static uint8_t RamDataEntryMode[2] = {0x11, 0x01}; // Ram data entry mode @@ -52,10 +46,15 @@ VS [n-XY] and TP[n] are stored in waveform lookup table register [LUT]. VS coding: VS[0-11] VS[0-10] VS[0-01] VS[0-00] */ -// --- VS ---- ---- TP ---- +// --- VS ---- ---- TP ---- //uint8_t LUTDefault_full[31] = {0x32, 0x02,0x02,0x01,0x11,0x12,0x12,0x22,0x22,0x66,0x69,0x69,0x59,0x58,0x99,0x99,0x88,0x00,0x00,0x00,0x00, 0xF8,0xB4,0x13,0x51,0x35,0x51,0x51,0x19,0x01,0x00}; +#ifdef EPD2X9 uint8_t LUTDefault_full[31] = {0x32, 0x11,0x11,0x10,0x02,0x02,0x22,0x22,0x22,0x22,0x22,0x51,0x51,0x55,0x88,0x08,0x08,0x88,0x88,0x00,0x00, 0x34,0x23,0x12,0x21,0x24,0x28,0x22,0x21,0xA1,0x01}; uint8_t LUTDefault_part[31] = {0x32, 0x10,0x18,0x18,0x08,0x18,0x18,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x13,0x14,0x44,0x12,0x00,0x00,0x00,0x00,0x00,0x00}; +#elif EPD2X13 +uint8_t LUTDefault_full[31] = {0x32, 0x22,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x1E,0x1E,0x1E, 0x1E,0x1E,0x1E,0x1E,0x01,0x00,0x00,0x00,0x00,0x00}; +uint8_t LUTDefault_part[31] = {0x32, 0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x01,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; +#endif uint8_t LUT_gs[31] = {0x32, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; uint8_t LUTFastest[31] = {0x32, 0x99,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; @@ -711,15 +710,24 @@ void EPD_gsUpdate(int xStart, int xEnd, uint8_t yStart, uint8_t yEnd, uint8_t gs uint8_t *_lutPart = LUT_part; memset(LUT_gs+1, 0, 30); if (gs > 0) { - if (gs > 0) { - LUT_gs[1] = 0x18; - LUT_gs[21] = gs; - } + #ifdef EPD2X9 + LUT_gs[1] = 0x18; + LUT_gs[21] = gs; + #elif EPD2X13 + LUT_gs[1] = 0x18; + LUT_gs[17] = gs; + #endif } else { + #ifdef EPD2X9 LUT_gs[1] = 0x28; LUT_gs[2] = 0x00; LUT_gs[21] = 15; + #elif EPD2X13 + LUT_gs[1] = 0x18; + LUT_gs[17] = 0x0F; + LUT_gs[18] = 0x01; + #endif } LUT_part = LUT_gs; EPD_DisplayPart(xStart, xEnd, yStart, yEnd, drawBuff); diff --git a/components/epaper/EPDspi.h b/components/epaper/EPDspi.h index 41b6583..acf1e87 100644 --- a/components/epaper/EPDspi.h +++ b/components/epaper/EPDspi.h @@ -15,8 +15,27 @@ #include #include "spi_master_lobo.h" -#define EPD_DISPLAY_WIDTH 296 -#define EPD_DISPLAY_HEIGHT 128 +//#define EPD2X9 1 +#define EPD2X13 1 + +#ifdef EPD2X9 + #define xDot 128 + #define yDot 296 + #define EPD_DISPLAY_WIDTH 296 + #define EPD_DISPLAY_HEIGHT 128 + #define EPD_VCOM 0xa8 + #define DELAYTIME 1500 +#elif EPD2X13 + #define xDot 122 + #define yDot 250 + #define EPD_DISPLAY_WIDTH 250 + #define EPD_DISPLAY_HEIGHT 120 + #define EPD_VCOM 0x78 + #define DELAYTIME 1500 +#endif + +//#define EPD_DISPLAY_WIDTH 296 +//#define EPD_DISPLAY_HEIGHT 128 #define SCK_Pin 18 #define MOSI_Pin 23 diff --git a/components/mkspiffs/src/mkspiffs b/components/mkspiffs/src/mkspiffs index cb8fb9a..67110c2 100755 Binary files a/components/mkspiffs/src/mkspiffs and b/components/mkspiffs/src/mkspiffs differ diff --git a/main/ePaper.c b/main/ePaper.c index 5d35407..d1450f7 100644 --- a/main/ePaper.c +++ b/main/ePaper.c @@ -15,7 +15,7 @@ #include "esp_system.h" #include "driver/gpio.h" #include "esp_system.h" -#include "esp_heap_alloc_caps.h" +#include "esp_heap_caps.h" #include "spiffs_vfs.h" #include "esp_log.h" @@ -30,7 +30,8 @@ #include #include #include "lwip/err.h" -#include "apps/sntp/sntp.h" +//#include "apps/sntp/sntp.h" +#include "lwip/apps/sntp.h" #include "nvs_flash.h" #endif @@ -64,7 +65,7 @@ static EventGroupHandle_t wifi_event_group; /* The event group allows multiple bits for each event, but we only care about one event - are we connected to the AP with an IP? */ -const int CONNECTED_BIT = 0x00000001; +const int CONNECTED_BIT = BIT0; //------------------------------------------------------------ static esp_err_t event_handler(void *ctx, system_event_t *event) @@ -164,11 +165,11 @@ void app_main() esp_err_t ret; - disp_buffer = pvPortMallocCaps(EPD_DISPLAY_WIDTH * (EPD_DISPLAY_HEIGHT/8), MALLOC_CAP_DMA); + disp_buffer = heap_caps_malloc(EPD_DISPLAY_WIDTH * (EPD_DISPLAY_HEIGHT/8), MALLOC_CAP_DMA); assert(disp_buffer); drawBuff = disp_buffer; - gs_disp_buffer = pvPortMallocCaps(EPD_DISPLAY_WIDTH * EPD_DISPLAY_HEIGHT, MALLOC_CAP_DMA); + gs_disp_buffer = heap_caps_malloc(EPD_DISPLAY_WIDTH * EPD_DISPLAY_HEIGHT, MALLOC_CAP_DMA); assert(gs_disp_buffer); gs_drawBuff = gs_disp_buffer; @@ -242,8 +243,8 @@ void app_main() EPD_setFont(DEFAULT_FONT, NULL); sprintf(tmp_buff, "Waiting for NTP time..."); EPD_print(tmp_buff, CENTER, CENTER); - EPD_drawRect(10,10,274,108, EPD_BLACK); - EPD_drawRect(12,12,270,104, EPD_BLACK); + EPD_drawRect(10,10,EPD_DISPLAY_WIDTH - 22,108, EPD_BLACK); + EPD_drawRect(12,12,EPD_DISPLAY_WIDTH - 26,104, EPD_BLACK); EPD_UpdateScreen(); // ===== Set time zone ====== @@ -382,9 +383,9 @@ void app_main() printf("==== START ====\r\n\n"); - _gs = 1; + _gs = 0; uint32_t tstart; - int pass = 0, ftype = 9; + int pass = 0, ftype = 0; while (1) { ftype++; if (ftype > 10) { @@ -406,7 +407,7 @@ void app_main() _fg = 15; _bg = 0; - EPD_drawRect(1,1,294,126, EPD_BLACK); + EPD_drawRect(1,1,EPD_DISPLAY_WIDTH - 2,EPD_DISPLAY_HEIGHT - 2, EPD_BLACK); int y = 4; tstart = clock(); @@ -438,7 +439,7 @@ void app_main() EPD_setFont(DEFAULT_FONT, NULL); sprintf(tmp_buff, "Pass: %d", pass+1); - EPD_print(tmp_buff, 4, 128-EPD_getfontheight()-2); + EPD_print(tmp_buff, 4, EPD_DISPLAY_HEIGHT-EPD_getfontheight()-2); EPD_UpdateScreen(); } else if (ftype == 2) { @@ -455,7 +456,7 @@ void app_main() _fg = 15; EPD_setFont(DEFAULT_FONT, NULL); sprintf(tmp_buff, "Pass: %d (rotated 180)", pass+1); - EPD_print(tmp_buff, 4, 128-EPD_getfontheight()-2); + EPD_print(tmp_buff, 4, EPD_DISPLAY_HEIGHT-EPD_getfontheight()-2); orientation = LANDSCAPE_0; EPD_UpdateScreen(); } @@ -473,7 +474,7 @@ void app_main() _fg = 15; EPD_setFont(DEFAULT_FONT, NULL); sprintf(tmp_buff, "Pass: %d (Fonts from file)", pass+1); - EPD_print(tmp_buff, 4, 128-EPD_getfontheight()-2); + EPD_print(tmp_buff, 4, EPD_DISPLAY_HEIGHT-EPD_getfontheight()-2); EPD_UpdateScreen(); } else if (ftype == 4) { @@ -515,7 +516,7 @@ void app_main() EPD_print(tmp_buff, 20, 4); font_rotate = 0; sprintf(tmp_buff, "Pass: %d", pass+1); - EPD_print(tmp_buff, 4, 128-EPD_getfontheight()-2); + EPD_print(tmp_buff, 4, EPD_DISPLAY_HEIGHT-EPD_getfontheight()-2); EPD_UpdateScreen(); } else if (ftype == 5) { @@ -580,7 +581,7 @@ void app_main() EPD_setFont(DEFAULT_FONT, NULL); sprintf(tmp_buff, "Pass: %d", pass+1); - EPD_print(tmp_buff, 4, 128-EPD_getfontheight()-2); + EPD_print(tmp_buff, 4, EPD_DISPLAY_HEIGHT-EPD_getfontheight()-2); EPD_UpdateScreen(); _gs = old_gs; @@ -594,7 +595,7 @@ void app_main() _fg = 0; _bg = 1; sprintf(tmp_buff, "Pass: %d", pass+1); - EPD_print(tmp_buff, 4, 128-EPD_getfontheight()-2); + EPD_print(tmp_buff, 4, EPD_DISPLAY_HEIGHT-EPD_getfontheight()-2); EPD_UpdateScreen(); _fg = 15; @@ -621,7 +622,7 @@ void app_main() EPD_setFont(DEFAULT_FONT, NULL); sprintf(tmp_buff, "Pass: %d (Gray scale image)", pass+1); - EPD_print(tmp_buff, 4, 128-EPD_getfontheight()-2); + EPD_print(tmp_buff, 4, EPD_DISPLAY_HEIGHT-EPD_getfontheight()-2); EPD_UpdateScreen(); _gs = old_gs;