123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974 |
- #include <stdio.h>
- #include "EPD.h"
- #include <string.h>
- #include "esp_log.h"
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "freertos/queue.h"
- #include "GUI_Paint.h"
- #include "freertos/timers.h"
- //#include "../components/../main/user_sleep.h"
- #include "esp_timer.h"
- TimerHandle_t left_display_timer;
- TimerHandle_t right_display_timer;
- bool left_refresh_complete = false;
- bool right_refresh_complete = false;
- uint8_t current_display = 0;
- #include "../../main/user_sleep.h"
- #include "esp_sleep.h"
- void left_slow_timerout_Callback(TimerHandle_t xTimer) {
- // 在这里执行定时器超时后的任务
- // 注意:回调函数中不要执行耗时的操作,避免影响其他任务的运行
- //if(current_display == SCREEN_LEFT)
- {
- left_refresh_complete = true;
- }
- // if(current_display == SCREEN_RIGHT)
- // {
- // right_refresh_complete = true;
- // }
- }
- void right_slow_timerout_Callback(TimerHandle_t xTimer) {
- // 在这里执行定时器超时后的任务
- // 注意:回调函数中不要执行耗时的操作,避免影响其他任务的运行
- // if(current_display == SCREEN_LEFT)
- // {
- // left_refresh_complete = true;
- // }
- // if(current_display == SCREEN_RIGHT)
- {
- right_refresh_complete = true;
- }
- }
- /*********************************************************************************
- * function : refresh_timer_start
- * Description :
- * Input :
- * Output :
- * Author : 祁鑫 Data : 2023 10.18
- **********************************************************************************/
- void left_refresh_timer_start(int ms)
- {
- xTimerStop(left_display_timer, 0); //停止定时器
- // 在这里可以改变定时器的超时时间
- // 第一个参数是定时器句柄,第二个参数是新的超时时间(以时钟节拍为单位)
- xTimerChangePeriod(left_display_timer, pdMS_TO_TICKS(ms), 0);
- xTimerStart(left_display_timer, 0); //开始定时器
-
- }
- /*********************************************************************************
- * function : refresh_timer_stop
- * Description :
- * Input :
- * Output :
- * Author : 祁鑫 Data : 2023 10.18
- **********************************************************************************/
- void left_refresh_timer_stop(void)
- {
- xTimerStop(left_display_timer, 0); //停止定时器
- }
- /*********************************************************************************
- * function : refresh_timer_start
- * Description :
- * Input :
- * Output :
- * Author : 祁鑫 Data : 2023 10.18
- **********************************************************************************/
- void right_refresh_timer_start(int ms)
- {
- xTimerStop(right_display_timer, 0); //停止定时器
- // 在这里可以改变定时器的超时时间
- // 第一个参数是定时器句柄,第二个参数是新的超时时间(以时钟节拍为单位)
- xTimerChangePeriod(right_display_timer, pdMS_TO_TICKS(ms), 0);
- xTimerStart(right_display_timer, 0); //开始定时器
-
- }
- /*********************************************************************************
- * function : refresh_timer_stop
- * Description :
- * Input :
- * Output :
- * Author : 祁鑫 Data : 2023 10.18
- **********************************************************************************/
- void right_refresh_timer_stop(void)
- {
- xTimerStop(right_display_timer, 0); //停止定时器
- }
- bool left_refresh_timer_isActive()
- {
- if(xTimerIsTimerActive(left_display_timer) != pdFALSE)
- {
- return true;
- }else
- {
- return false;
- }
- }
- bool right_refresh_timer_isActive()
- {
- if(xTimerIsTimerActive(right_display_timer) != pdFALSE)
- {
- return true;
- }else
- {
- return false;
- }
- }
-
- static const char *LOG_TAG = "EPD";
- #if HARDWARE_SPI
- spi_device_handle_t epd_spi;
- // uint8_t cmd[1]={0};
- // epd_write_cmd(screen,0x00,false);
- // cmd[0] = 0x17;
- // epd_write_data(screen,cmd,1);
- //Place data into DRAM. Constant data gets placed into DROM by default, which is not accessible by DMA.
- DRAM_ATTR static const epd_init_cmd_t init_cmds[]={
- {0x00,{0x1f,0x0E},2},
- {0x50,{0x18,0x07},2},
- {0xe0,{0x02},1},
- {0xe5,{0x5c},1},
- {0x11, {0}, 0x80},
- #if 0
- {0x00,{0x1B},1},
- #else
- //{0x00,{0x8F},1},
- #endif
- {0, {0}, 0xff},
- };
- //This function is called (in irq context!) just before a transmission starts. It will
- //set the D/C line to the value indicated in the user field.
- static void spi_pre_transfer_callback(spi_transaction_t *t)
- {
- int dc=(int)t->user;
- gpio_set_level(PIN_L_DC, dc);
- gpio_set_level(PIN_R_DC, dc);
- }
- #if 0
- void epd_spi_write(struct EPD_INFO_SET* epd_pin_set,unsigned char value)
- {
- int i = 0,data = value;
- epd_set_level(epd_pin_set->sclk_pin, LOW_LEVEL);
- for(i=0;i<8;i++)
- {
- if(data&0x0080)
- {
- epd_set_level(epd_pin_set->sda_pin,HIGH_LEVEL);
- }
- else
- {
- epd_set_level(epd_pin_set->sda_pin,LOW_LEVEL);
- }
- // ets_delay_us(1);
- epd_set_level(epd_pin_set->sclk_pin, HIGH_LEVEL);
- // ets_delay_us(1);
- epd_set_level(epd_pin_set->sclk_pin, LOW_LEVEL);
-
- data = ((data)<<1 & 0xff);
- }
- }
- #endif
- /*********************************************************************************
- * function : SPI_Write
- * Description : spi写入数据
- * Input :
- * Output :
- * Author : 祁鑫 Data : 2023 8.11
- **********************************************************************************/
- IRAM_ATTR void SPI_Write(unsigned char value)
- {
- int i=0,data=value;
- int j = 100;
- gpio_set_level(PIN_SPI_CLK, 0);
- for(i=0;i<8;i++)
- {
- if(data&0x0080)
- {
- gpio_set_level(PIN_SPI_MOSI, 1);
- //EPD_SDA_1;
- }else
- {
- gpio_set_level(PIN_SPI_MOSI, 0);
- //EPD_SDA_0;
- }
- //vTaskDelay(1/ portTICK_PERIOD_MS);
- gpio_set_level(PIN_SPI_CLK, 1);
- //vTaskDelay(1/ portTICK_PERIOD_MS);
- gpio_set_level(PIN_SPI_CLK, 0);
- data=((data<<1)&0xff);
- }
- }
- //Initialize the display
- void epd_init(void)
- {
- #if !SOFTWARE_SPI_ENABLE //硬件spi
- esp_err_t ret;
- spi_bus_config_t buscfg={
- .miso_io_num=-1,
- .mosi_io_num=PIN_SPI_MOSI,
- .sclk_io_num=PIN_SPI_CLK,
- .quadwp_io_num=-1,
- .quadhd_io_num=-1,
- .max_transfer_sz=4096//dma
- };
- spi_device_interface_config_t devcfg={
- .clock_speed_hz=20*1000*1000, //Clock out at 10 MHz
- .mode=0, //SPI mode 0
- .spics_io_num=-1, //CS pin
- .queue_size=7, //We want to be able to queue 7 transactions at a time
- .pre_cb=spi_pre_transfer_callback, //Specify pre-transfer callback to handle D/C line
- };
- //Initialize the SPI bus
- ret=spi_bus_initialize(EPD_HOST, &buscfg, SPI_DMA_CH_AUTO);
- ESP_ERROR_CHECK(ret);
- //Attach the LCD to the SPI bus
- ret=spi_bus_add_device(EPD_HOST, &devcfg, &epd_spi);
- ESP_ERROR_CHECK(ret);
- #else //软件模拟spi
- gpio_reset_pin(PIN_SPI_MOSI);
- gpio_reset_pin(PIN_SPI_CLK);
- gpio_reset_pin(PIN_L_CS);
- gpio_reset_pin(PIN_L_DC);
- gpio_reset_pin(PIN_L_RST);
- gpio_reset_pin(PIN_L_BUSY);
- gpio_reset_pin(PIN_R_CS);
- gpio_reset_pin(PIN_R_DC);
- gpio_reset_pin(PIN_R_RST);
- gpio_reset_pin(PIN_R_BUSY);
- #endif
- //gpio_reset_pin(PIN_L_CS);
- //Initialize non-SPI GPIOs
- gpio_config_t io_conf = {};
- io_conf.pin_bit_mask = PIN_EPD_OUTPUT;
- io_conf.mode = GPIO_MODE_OUTPUT;
- io_conf.pull_up_en = 0;
- gpio_config(&io_conf);
- io_conf.pin_bit_mask = PIN_EPD_INPUT;
- io_conf.mode = GPIO_MODE_INPUT;
- io_conf.pull_up_en = 0;
- gpio_config(&io_conf);
- //Reset the display
- int reson = is_wake_up_reson(); //返回唤醒的原因
- if
- (
- 1 //(reson != ESP_SLEEP_WAKEUP_ULP) && (reson != ESP_SLEEP_WAKEUP_TIMER) && (reson != ESP_SLEEP_WAKEUP_EXT0)
- )
- {
- gpio_set_level(PIN_L_RST, 0);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- gpio_set_level(PIN_L_RST, 1);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- gpio_set_level(PIN_R_RST, 0);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- gpio_set_level(PIN_R_RST, 1);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- #if 1
- int cmd=0;
- //Send all the commands
- while (init_cmds[cmd].databytes!=0xff) {
- #if 1
- epd_write_cmd(SCREEN_LEFT, init_cmds[cmd].cmd, false);
- epd_write_data(SCREEN_LEFT, init_cmds[cmd].data, init_cmds[cmd].databytes&0x1F);
- epd_write_cmd(SCREEN_RIGHT, init_cmds[cmd].cmd, false);
- epd_write_data(SCREEN_RIGHT, init_cmds[cmd].data, init_cmds[cmd].databytes&0x1F);
- #endif
- if (init_cmds[cmd].databytes&0x80) {
- vTaskDelay(100 / portTICK_PERIOD_MS);
- }
- cmd++;
- }
- #endif
- }
- #if QUICK_DISPLAY
- uint8_t *old_buffer= heap_caps_malloc(480*81, MALLOC_CAP_8BIT);
- memset(old_buffer,0X00,480*81);
- epd_cache_quick_full_screen_refresh(SCREEN_LEFT,NULL,old_buffer);
- epd_write_cmd(SCREEN_LEFT,0x04,false); //POWER ON
- epd_check_status(SCREEN_LEFT); //waiting for the electronic paper IC to release the idle signal
- //Refresh
- epd_refresh(SCREEN_LEFT);
- epd_write_cmd(SCREEN_LEFT,0x02,false); // Power OFF
- epd_check_status(SCREEN_LEFT);
- epd_sleep(SCREEN_LEFT);
- free(old_buffer);
- #else
- #endif
- left_display_timer = xTimerCreate(
- "right_display_timer", // 定时器名称(可以为NULL)
- pdMS_TO_TICKS(2000), // 定时器超时时间(以毫秒为单位)
- pdFALSE, // 定时器为周期性(pdTRUE)还是单次(pdFALSE)
- 0, // 定时器ID(可以为0)
- left_slow_timerout_Callback // 定时器回调函数
- );
- right_display_timer = xTimerCreate(
- "right_display_timer", // 定时器名称(可以为NULL)
- pdMS_TO_TICKS(2000), // 定时器超时时间(以毫秒为单位)
- pdFALSE, // 定时器为周期性(pdTRUE)还是单次(pdFALSE)
- 0, // 定时器ID(可以为0)
- right_slow_timerout_Callback // 定时器回调函数
- );
-
- }
- void epd_init_cmd(screen_t screen)
- {
- if( screen == SCREEN_LEFT)
- {
- gpio_set_level(PIN_L_RST, 0);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- gpio_set_level(PIN_L_RST, 1);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- int cmd=0;
- //Send all the commands
- while (init_cmds[cmd].databytes!=0xff) {
- #if 1
- epd_write_cmd(SCREEN_LEFT, init_cmds[cmd].cmd, false);
- epd_write_data(SCREEN_LEFT, init_cmds[cmd].data, init_cmds[cmd].databytes&0x1F);
-
- #endif
- if (init_cmds[cmd].databytes&0x80) {
- vTaskDelay(10 / portTICK_PERIOD_MS);
- }
- cmd++;
- }
- }
- if( screen == SCREEN_RIGHT)
- {
- gpio_set_level(PIN_R_RST, 0);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- gpio_set_level(PIN_R_RST, 1);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- int cmd=0;
- //Send all the commands
- while (init_cmds[cmd].databytes!=0xff) {
- #if 1
- epd_write_cmd(SCREEN_RIGHT, init_cmds[cmd].cmd, false);
- epd_write_data(SCREEN_RIGHT, init_cmds[cmd].data, init_cmds[cmd].databytes&0x1F);
- #endif
- if (init_cmds[cmd].databytes&0x80) {
- vTaskDelay(100 / portTICK_PERIOD_MS);
- }
- cmd++;
- }
- }
-
- }
- static void spi_get_result(spi_device_handle_t spi)
- {
- spi_transaction_t *rtrans = NULL;
- esp_err_t ret;
- spi_device_get_trans_result(spi, &rtrans, portMAX_DELAY);
- //assert(ret==ESP_OK);
- }
- void epd_cmd(spi_device_handle_t spi, const uint8_t cmd, bool keep_cs_active)
- {
- #if !SOFTWARE_SPI_ENABLE
- esp_err_t ret;
- spi_transaction_t t;
- memset(&t, 0, sizeof(t)); //Zero out the transaction
- t.length=8; //Command is 8 bits
- t.tx_buffer=&cmd; //The data is the cmd itself
- t.user=(void*)0; //D/C needs to be set to 0
- if (keep_cs_active) {
- t.flags = SPI_TRANS_CS_KEEP_ACTIVE; //Keep CS active after data transfer
- }
- ret=spi_device_queue_trans(spi, &t, portMAX_DELAY);
- // assert(ret==ESP_OK); //Should have had no issues.
- spi_get_result(spi);
- #else
- SPI_Write(cmd);
- #endif
- }
- void epd_data(spi_device_handle_t spi, const uint8_t *data, int len)
- {
- #if !SOFTWARE_SPI_ENABLE
- esp_err_t ret;
- spi_transaction_t t;
- int i;
- if (len==0) return; //no need to send anything
- if(len > SPI_MAX_LEN)
- {
- for(i=0;i<len;i=i+SPI_MAX_LEN)
- {
- memset(&t, 0, sizeof(t)); //Zero out the transaction
- t.length=SPI_MAX_LEN*8; //Len is in bytes, transaction length is in bits.
- t.tx_buffer=data+i; //Data
- t.user=(void*)1; //D/C needs to be set to 1
- ret=spi_device_queue_trans(spi, &t, portMAX_DELAY); //Transmit!
- // assert(ret==ESP_OK); //Should have had no issues.
- if(ret != ESP_OK)
- {
- printf("spi_device_queue_trans err:ret =%d",ret);
- }
- spi_get_result(spi);
- }
- i-=SPI_MAX_LEN;
- memset(&t, 0, sizeof(t)); //Zero out the transaction
- t.length=(len-i)*8; //Len is in bytes, transaction length is in bits.
- t.tx_buffer=data+i; //Data
- t.user=(void*)1; //D/C needs to be set to 1
- ret=spi_device_queue_trans(spi, &t, portMAX_DELAY); //Transmit!
- // assert(ret==ESP_OK); //Should have had no issues.
- if(ret != ESP_OK)
- {
- printf("spi_device_queue_trans err:ret =%d",ret);
- }
- spi_get_result(spi);
- return;
- }
- memset(&t, 0, sizeof(t)); //Zero out the transaction
- t.length=len*8; //Len is in bytes, transaction length is in bits.
- t.tx_buffer=data; //Data
- t.user=(void*)1; //D/C needs to be set to 1
- ret=spi_device_queue_trans(spi, &t, portMAX_DELAY); //Transmit!
- // assert(ret==ESP_OK); //Should have had no issues.
- if(ret != ESP_OK)
- {
- printf("spi_device_queue_trans err:ret =%d",ret);
- }
- spi_get_result(spi);
- #else
- {
- for(int i = 0;i<len;i++)
- {
- SPI_Write(data[i]);
- }
- }
-
-
- #endif
- }
- void epd_write_cmd(screen_t screen, unsigned char command,bool keep_cs_active)
- {
- if(screen == SCREEN_LEFT)
- {
- gpio_set_level(PIN_R_CS,1);
- gpio_set_level(PIN_L_CS,0);
-
- gpio_set_level(PIN_L_DC, 0);
- epd_cmd(epd_spi, command, keep_cs_active);
- gpio_set_level(PIN_R_CS,1);
- gpio_set_level(PIN_L_CS,1);
-
- }
- else if(screen == SCREEN_RIGHT)
- {
- gpio_set_level(PIN_L_CS,1);
- gpio_set_level(PIN_R_CS,0);
-
- gpio_set_level(PIN_R_DC, 0);
- epd_cmd(epd_spi, command, keep_cs_active);
- gpio_set_level(PIN_L_CS,1);
- gpio_set_level(PIN_R_CS,1);
-
- }
- else
- {
- ESP_LOGE(LOG_TAG,"cmd err:screen");
- }
- }
- void epd_write_data(screen_t screen, const uint8_t *data, int len)
- {
- if(screen == SCREEN_LEFT)
- {
- gpio_set_level(PIN_R_CS,1);
- gpio_set_level(PIN_L_CS,0);
-
- gpio_set_level(PIN_L_DC, 1);
- epd_data(epd_spi, data, len);
- gpio_set_level(PIN_L_CS,1);
- }
- else if(screen == SCREEN_RIGHT)
- {
- gpio_set_level(PIN_L_CS,1);
- gpio_set_level(PIN_R_CS,0);
-
- gpio_set_level(PIN_R_DC, 1);
- epd_data(epd_spi, data, len);
- gpio_set_level(PIN_R_CS,1);
- }
- else
- {
- ESP_LOGE(LOG_TAG,"data err:screen");
- }
- }
- bool epd_check_status(screen_t screen)
- {
- #if 0
- if(screen == SCREEN_LEFT)
- {
- while(!gpio_get_level(PIN_L_BUSY))
- {
- };
- }
- else if(screen == SCREEN_RIGHT)
- {
- while(!gpio_get_level(PIN_R_BUSY));
- }
- else
- {
- ESP_LOGE(LOG_TAG,"check err:screen");
- }
- #else
-
- int count = 0;
- unsigned char busy;
- int64_t t_after_us = 0;
- int64_t t_before_us = esp_timer_get_time();
- // while(1)
- {
- //=1 BUSY
- if(screen == SCREEN_LEFT)
- {
- while(1)
- {
-
- busy = gpio_get_level(PIN_L_BUSY);
- busy = (busy & 0x01);
- if(busy==1)
- {
- // printf("left lcd idle\r\n");
- break;
- }
- #if 0
- vTaskDelay(10 / portTICK_PERIOD_MS);
- count ++;
- if(count >= 200){
- printf("l---------------time out ---\n");
- break;
- }
- #else
- t_after_us = esp_timer_get_time();
- if((t_after_us-t_before_us)>1000*1000)
- {
- printf("t_before_us =%lld ,t_after_us = %lld\n",t_before_us,t_after_us);
- return 0;
- break;
- }
- #endif
- }
- }
- else if(screen == SCREEN_RIGHT)
- {
- //while(!gpio_get_level(PIN_R_BUSY));
- while(1)
- {
- busy = gpio_get_level(PIN_R_BUSY);
- busy = (busy & 0x01);
- if(busy==1)
- {
- // printf("right lcd idle\r\n");
- break;
- }
- #if 0
- vTaskDelay(10 / portTICK_PERIOD_MS);
- count ++;
- if(count >= 200){
- printf("r---------------time out ---\n");
- break;
- }
- #else
- t_after_us = esp_timer_get_time();
- if((t_after_us-t_before_us)>1000*1000)
- {
- printf(" r t_before_us =%lld ,t_after_us = %lld\n",t_before_us,t_after_us);
- return 0;
- break;
- }
- #endif
- }
- }
- else
- {
- ESP_LOGE(LOG_TAG,"check err:screen");
- }
- }
- #endif
- return 1;
- }
- void deepsleep_epd_check_status(screen_t screen)
- {
- if(screen == SCREEN_LEFT)
- {
- while(!gpio_get_level(PIN_L_BUSY));
- }
- else if(screen == SCREEN_RIGHT)
- {
- while(!gpio_get_level(PIN_R_BUSY));
- }
- else
- {
- ESP_LOGE(LOG_TAG,"check err:screen");
- }
-
- }
- void epd_check_power_off(screen_t screen)
- {
- if(screen == SCREEN_LEFT)
- {
- while(gpio_get_level(PIN_L_BUSY))
- {
- vTaskDelay(20 / portTICK_PERIOD_MS);
- printf("left power off\r\n");
- }
- }
- else if(screen == SCREEN_RIGHT)
- {
- while(gpio_get_level(PIN_R_BUSY))
- {
- vTaskDelay(20 / portTICK_PERIOD_MS);
- printf("right power off\r\n");
- }
- }
- else
- {
- ESP_LOGE(LOG_TAG,"check err:screen");
- }
- }
- void epd_check_power_on(screen_t screen)
- {
- if(screen == SCREEN_LEFT)
- {
-
- while(gpio_get_level(PIN_L_BUSY))
- {
- printf("left power on\r\n");
- }
- }
- else if(screen == SCREEN_RIGHT)
- {
- while(gpio_get_level(PIN_R_BUSY))
- {
- printf("right power on\r\n");
- }
- }
- else
- {
- ESP_LOGE(LOG_TAG,"check err:screen");
- }
- }
- void epd_refresh(screen_t screen)
- {
- epd_write_cmd(screen,0x12,false);//DISPLAY REFRESH
- //ets_delay_us(200); //!!!The delay here is necessary, 200uS at least!!!
- //vTaskDelay(1 / portTICK_PERIOD_MS);
- epd_check_status(screen); //waiting for the electronic paper
- }
- void epd_sleep(screen_t screen)
- {
- //printf("SLEEP SCREEN =%d\r\n",screen);
-
- #if 0
- epd_write_cmd(screen,0x04,false); // Power ON
-
- epd_check_power_on(screen);
- #endif
- //epd_check_status(screen);
- //epd_refresh(screen);
- uint8_t tmp = 0xa5;
- epd_write_cmd(screen,0x07,false);
- epd_write_data(screen,&tmp,1);
-
-
- //vTaskDelay(20 / portTICK_PERIOD_MS);
- #if 0
- epd_write_cmd(screen,0x02,false); // Power OFF
- vTaskDelay(20 / portTICK_PERIOD_MS);
- epd_check_power_off(screen);
- #endif
- #if 1
- //epd_write_cmd(screen,0x02,false); // Power OFF
- //epd_check_status(screen);
- #endif
- }
- IRAM_ATTR void epd_display(screen_t screen,const unsigned char* picData)
- {
- #if SOFTWARE_SPI_ENABLE
- if(screen == SCREEN_LEFT)
- {
- left_refresh_complete = false;
- }
- if(screen == SCREEN_RIGHT)
- {
- right_refresh_complete = false;
- }
- #endif
- epd_write_cmd(screen,0x13,false);
- epd_check_status(screen);
- epd_write_data(screen,picData,38880);
- epd_check_status(screen);
- epd_write_cmd(screen,0x04,false); //POWER ON
- epd_check_status(screen); //waiting for the electronic paper IC to release the idle signal
- //Refresh
- epd_refresh(screen);
- epd_write_cmd(screen,0x02,false); // Power OFF
- epd_check_status(screen);
- epd_sleep(screen);
- #if SOFTWARE_SPI_ENABLE
- current_display = screen;
- //vTaskDelay(0000 / portTICK_PERIOD_MS);
- if(screen == SCREEN_LEFT)
- {
- left_refresh_timer_start(2000);
- }
- if(screen == SCREEN_LEFT)
- {
- right_refresh_timer_start(2000);
- }
- #else
- current_display = screen;
- //vTaskDelay(0000 / portTICK_PERIOD_MS);
- if(screen == SCREEN_LEFT)
- {
- left_refresh_timer_start(2000);
- }
- if(screen == SCREEN_LEFT)
- {
- right_refresh_timer_start(2000);
- }
- #endif
- }
- #if 1
- void epd_cache(screen_t screen,const unsigned char* picData)
- {
- epd_write_cmd(screen,0x13,false);
- epd_write_data(screen,picData,38880);
- }
- void epd_cache_quick_full_screen_refresh(screen_t screen,const unsigned char* old,const unsigned char* new)
- {
- if((screen == SCREEN_LEFT)&&(old!=NULL))
- {
- printf("left quick\r\n");
- //Reset the display
- gpio_set_level(PIN_L_RST, 0);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- gpio_set_level(PIN_L_RST, 1);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- uint8_t cmd[1]={0};
- epd_write_cmd(screen,0x00,false);
- cmd[0] = 0x1F;
- epd_write_data(screen,cmd,1);
- #if 0
- uint8_t cmd[1]={0};
- epd_write_cmd(screen,0x61,false);
- cmd[0] = 0xF0;
- epd_write_data(screen,cmd,1);
- cmd[0] = 0x01;
- epd_write_data(screen,cmd,1);
- cmd[0] = 0xA0;
- epd_write_data(screen,cmd,1);
- #endif
- #if 0
- int cmd=0;
- //Send all the commands
- while (init_cmds[cmd].databytes!=0xff) {
- epd_write_cmd(SCREEN_LEFT, init_cmds[cmd].cmd, false);
- epd_write_data(SCREEN_LEFT, init_cmds[cmd].data, init_cmds[cmd].databytes&0x1F);
- epd_write_cmd(SCREEN_RIGHT, init_cmds[cmd].cmd, false);
- epd_write_data(SCREEN_RIGHT, init_cmds[cmd].data, init_cmds[cmd].databytes&0x1F);
- if (init_cmds[cmd].databytes&0x80) {
- vTaskDelay(100 / portTICK_PERIOD_MS);
- }
- cmd++;
- }
- #endif
- }
- if((screen == SCREEN_RIGHT)&&(old!=NULL))
- {
- printf("right quick\r\n");
- gpio_set_level(PIN_R_RST, 0);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- gpio_set_level(PIN_R_RST, 1);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- // uint8_t cmd[1]={0};
- // epd_write_cmd(screen,0x00,false);
- // cmd[0] = 0x1F;
- // epd_write_data(screen,cmd,1);
- #if 0
- uint8_t cmd[1]={0};
- epd_write_cmd(screen,0x61,false);
- cmd[0] = 0xF0;
- epd_write_data(screen,cmd,1);
- cmd[0] = 0x01;
- epd_write_data(screen,cmd,1);
- cmd[0] = 0xA0;
- epd_write_data(screen,cmd,1);
- #endif
- #if 0
- int cmd=0;
- //Send all the commands
- while (init_cmds[cmd].databytes!=0xff) {
- epd_write_cmd(SCREEN_LEFT, init_cmds[cmd].cmd, false);
- epd_write_data(SCREEN_LEFT, init_cmds[cmd].data, init_cmds[cmd].databytes&0x1F);
- epd_write_cmd(SCREEN_RIGHT, init_cmds[cmd].cmd, false);
- epd_write_data(SCREEN_RIGHT, init_cmds[cmd].data, init_cmds[cmd].databytes&0x1F);
- if (init_cmds[cmd].databytes&0x80) {
- vTaskDelay(100 / portTICK_PERIOD_MS);
- }
- cmd++;
- }
- #endif
- }
- if (old !=NULL)
- {
- epd_write_cmd(screen,0x10,false);
- epd_check_status(screen);
- epd_write_data(screen,old,38880);
- }
-
- #if 0
- uint8_t cmd[1]={0};
- epd_write_cmd(screen,0x61,false);
- cmd[0] = 0xF0;
- epd_write_data(screen,cmd,1);
- cmd[0] = 0x01;
- epd_write_data(screen,cmd,1);
- cmd[0] = 0xA0;
- epd_write_data(screen,cmd,1);
- #endif
- epd_write_cmd(screen,0x13,false);
- epd_write_data(screen,new,38880);
- }
- #endif
- void epd_display_partal(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,
- screen_t screen,const unsigned char* picData)
- {
- unsigned int row, col;
- uint8_t Xstart_H,Xstart_L,Ystart_H,Ystart_L,Xend_H,Xend_L,Yend_H,Yend_L;
- Xstart_H = ((Xstart)>>8) & 0xff;
- Xstart_L = (Xstart) & 0xff;
- Ystart_H = ((Ystart)>>8) & 0xff;
- Ystart_L = (Ystart) & 0xff;
- Xend_H = ((Xend-1)>>8) & 0xff;
- Xend_L = (Xend-1) & 0xff;
- Yend_H = ((Yend-1)>>8) & 0xff;
- Yend_L = (Yend-1) & 0xff;
- epd_write_cmd(screen,0x91,false); // partial in
- epd_check_status(screen);
-
- epd_write_cmd(screen,0x90,false);
- epd_check_status(screen);
- epd_write_data(screen,&Xstart_H,1);
- epd_write_data(screen,&Xstart_L,1);
- epd_write_data(screen,&Xend_H,1);
- epd_write_data(screen,&Xend_L,1);
- epd_write_data(screen,&Ystart_H,1);
- epd_write_data(screen,&Ystart_L,1);
- epd_write_data(screen,&Yend_H,1);
- epd_write_data(screen,&Yend_L,1);
- uint8_t tmp = 0x01;
- epd_write_data(screen,&tmp,1);
- epd_write_cmd(screen,0x13,false);
- epd_check_status(screen);
-
- epd_write_data(screen,picData,((Yend - Ystart)*(Xend - Xstart)/8));
- epd_write_cmd(screen,0x92,false);
-
- epd_write_cmd(screen,0x04,false); // Power ON
- epd_check_status(screen);
- epd_refresh(screen);
- epd_write_cmd(screen,0x02,false); // Power OFF
- epd_check_status(screen);
- }
- void epd_partial_cache(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,
- screen_t screen,const unsigned char* picData)
- {
- unsigned int row, col;
- uint8_t Xstart_H,Xstart_L,Ystart_H,Ystart_L,Xend_H,Xend_L,Yend_H,Yend_L;
- Xstart_H = ((Xstart)>>8) & 0xff;
- Xstart_L = (Xstart) & 0xff;
- Ystart_H = ((Ystart)>>8) & 0xff;
- Ystart_L = (Ystart) & 0xff;
- Xend_H = ((Xend-1)>>8) & 0xff;
- Xend_L = (Xend-1) & 0xff;
- Yend_H = ((Yend-1)>>8) & 0xff;
- Yend_L = (Yend-1) & 0xff;
- epd_write_cmd(screen,0x91,false); // partial in
- epd_check_status(screen);
-
- epd_write_cmd(screen,0x90,false);
- epd_check_status(screen);
- epd_write_data(screen,&Xstart_H,1);
- epd_write_data(screen,&Xstart_L,1);
- epd_write_data(screen,&Xend_H,1);
- epd_write_data(screen,&Xend_L,1);
- epd_write_data(screen,&Ystart_H,1);
- epd_write_data(screen,&Ystart_L,1);
- epd_write_data(screen,&Yend_H,1);
- epd_write_data(screen,&Yend_L,1);
- uint8_t tmp = 0x01;
- epd_write_data(screen,&tmp,1);
- epd_write_cmd(screen,0x13,false);
- epd_check_status(screen);
-
- epd_write_data(screen,picData,((Yend - Ystart)*(Xend - Xstart)/8));
- epd_write_cmd(screen,0x92,false);
- }
- void epd_cache_quick_partial_screen_refresh(screen_t screen,uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,const unsigned char* old,const unsigned char* new)
- {
- if((screen == SCREEN_LEFT)&&(old!=NULL))
- {
- printf("left partial quick\r\n");
- //Reset the display
- gpio_set_level(PIN_L_RST, 0);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- gpio_set_level(PIN_L_RST, 1);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- uint8_t cmd[1]={0};
- epd_write_cmd(screen,0x00,false);
- cmd[0] = 0x1F;
- epd_write_data(screen,cmd,1);
- }
- if((screen == SCREEN_RIGHT)&&(old!=NULL))
- {
- printf("right partial quick\r\n");
- gpio_set_level(PIN_R_RST, 0);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- gpio_set_level(PIN_R_RST, 1);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- }
- #if 0
- if (old !=NULL)
- {
- epd_write_cmd(screen,0x10,false);
- epd_write_data(screen,old,38880);
- }
- epd_write_cmd(screen,0x13,false);
- epd_write_data(screen,new,38880);
- #endif
- unsigned int row, col;
- uint8_t Xstart_H,Xstart_L,Ystart_H,Ystart_L,Xend_H,Xend_L,Yend_H,Yend_L;
- Xstart_H = ((Xstart)>>8) & 0xff;
- Xstart_L = (Xstart) & 0xff;
- Ystart_H = ((Ystart)>>8) & 0xff;
- Ystart_L = (Ystart) & 0xff;
- Xend_H = ((Xend-1)>>8) & 0xff;
- Xend_L = (Xend-1) & 0xff;
- Yend_H = ((Yend-1)>>8) & 0xff;
- Yend_L = (Yend-1) & 0xff;
- epd_write_cmd(screen,0x91,false); // partial in
- epd_check_status(screen);
-
- epd_write_cmd(screen,0x90,false);
- epd_check_status(screen);
- epd_write_data(screen,&Xstart_H,1);
- epd_write_data(screen,&Xstart_L,1);
- epd_write_data(screen,&Xend_H,1);
- epd_write_data(screen,&Xend_L,1);
- epd_write_data(screen,&Ystart_H,1);
- epd_write_data(screen,&Ystart_L,1);
- epd_write_data(screen,&Yend_H,1);
- epd_write_data(screen,&Yend_L,1);
- uint8_t tmp = 0x01;
- epd_write_data(screen,&tmp,1);
- // epd_write_cmd(screen,0x13,false);
- // epd_check_status(screen);
-
- printf("1\r\n");
- if (old !=NULL)
- {
- printf("2\r\n");
- epd_write_cmd(screen,0x10,false);
- epd_check_status(screen);
- epd_write_data(screen,old,((Yend - Ystart)*(Xend - Xstart)/8));
- epd_write_cmd(screen,0x92,false);
- }
- printf("3\r\n");
- epd_write_cmd(screen,0x13,false);
- epd_check_status(screen);
- epd_write_data(screen,new,((Yend - Ystart)*(Xend - Xstart)/8));
- epd_write_cmd(screen,0x92,false);
- }
- static uint8_t get_data(uint8_t * color, uint8_t pix_size)
- {
- uint8_t data = 0;
- int i =0, j = 0;
- for (i = 0; i < 8; i++) {
- data = data | (color[j] << (7-i));
- j = j + pix_size;
- }
- return data;
- }
- void epd_partial_cache1(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,
- screen_t screen,const unsigned char* picData)
- {
- unsigned int row, col;
- uint8_t Xstart_H,Xstart_L,Ystart_H,Ystart_L,Xend_H,Xend_L,Yend_H,Yend_L;
- Xstart_H = ((Xstart)>>8) & 0xff;
- Xstart_L = (Xstart) & 0xff;
- Ystart_H = ((Ystart)>>8) & 0xff;
- Ystart_L = (Ystart) & 0xff;
- Xend_H = ((Xend-1)>>8) & 0xff;
- Xend_L = (Xend-1) & 0xff;
- Yend_H = ((Yend-1)>>8) & 0xff;
- Yend_L = (Yend-1) & 0xff;
- epd_write_cmd(screen,0x91,false); // partial in
- epd_check_status(screen);
-
- epd_write_cmd(screen,0x90,false);
- epd_check_status(screen);
- epd_write_data(screen,&Xstart_H,1);
- epd_write_data(screen,&Xstart_L,1);
- epd_write_data(screen,&Xend_H,1);
- epd_write_data(screen,&Xend_L,1);
- epd_write_data(screen,&Ystart_H,1);
- epd_write_data(screen,&Ystart_L,1);
- epd_write_data(screen,&Yend_H,1);
- epd_write_data(screen,&Yend_L,1);
- uint8_t tmp = 0x01;
- epd_write_data(screen,&tmp,1);
- epd_write_cmd(screen,0x13,false);
- epd_check_status(screen);
- #if 0
- epd_write_data(screen,picData,((Yend - Ystart)*(Xend - Xstart)));
- #else
- uint8_t data;
- // disp_drv.hor_res = 648;
- // disp_drv.ver_res = 480;
- for (int i = 480 - 1; i >=0 ; i--) {
- for (int j = 0; j < 648; ) {
- data = get_data(&picData[j + i * 648 * 1], 1);
- //printf("%02x",data);
- epd_write_data(screen,&data,1);
- j = j + 8 * 1;
- }
- }
- #endif
- epd_write_cmd(screen,0x92,false);
- }
- void epd_powerOn_refresh(screen_t screen)
- {
- epd_write_cmd(screen,0x04,false); // Power ON
- epd_check_status(screen);
- epd_refresh(screen);
- epd_write_cmd(screen,0x02,false); // Power OFF
- epd_check_status(screen);
- }
- // 定义最大重复计数
- #define MAX_REPEAT 255
- // 压缩函数
- unsigned int compressRLE(uint8_t *input, unsigned int size, uint8_t *output) {
- unsigned int i = 0;
- unsigned int outputSize = 0;
- while (i < size) {
- uint8_t current = input[i];
- unsigned int count = 1;
- i++;
- while (i < size && input[i] == current && count < MAX_REPEAT) {
- count++;
- i++;
- }
- // 输出像素值和计数值到output
- output[outputSize++] = current;
- output[outputSize++] = count;
- }
- return outputSize;
- }
- // 解压函数
- unsigned int decompressRLE(uint8_t *input, unsigned int size, uint8_t *output) {
- unsigned int i = 0;
- unsigned int outputSize = 0;
- while (i < size) {
- uint8_t current = input[i];
- i++;
- unsigned int count = input[i];
- i++;
- // 输出像素值count次到output
- for (unsigned int j = 0; j < count; j++) {
- output[outputSize++] = current;
- }
- }
- return outputSize;
- }
- void test()
- {
- // 定义图像数据(十六进制数组)
- uint8_t imageData[] = {0x12, 0x12, 0x12, 0x13, 0x14, 0x14, 0x14, 0x15, 0x15, 0x15};
- int imageSize = sizeof(imageData) / sizeof(imageData[0]);
- printf("原始图像数据:\n");
- for (int i = 0; i < imageSize; i++) {
- printf("0x%02X ", imageData[i]);
- }
- printf("\n");
- uint8_t compressedData[2 * imageSize]; // 假设压缩后的数据不会超过原数据的两倍大小
- uint8_t decompressedData[imageSize]; // 假设解压后的数据不会超过原数据大小
- printf("压缩后的数据:\n");
- int compressedSize = compressRLE(imageData, imageSize, compressedData);
- for (int i = 0; i < compressedSize; i++) {
- printf("0x%02X ", compressedData[i]);
- }
- printf("\n");
- printf("解压后的数据:\n");
- int decompressedSize = decompressRLE(compressedData, compressedSize, decompressedData);
- for (int i = 0; i < decompressedSize; i++) {
- printf("0x%02X ", decompressedData[i]);
- }
- printf("\n");
- printf("压缩后的数据大小:%d 字节\n", compressedSize);
- printf("解压后的数据大小:%d 字节\n", decompressedSize);
- }
- // uint8_t tmp[38880];
- IRAM_ATTR bool epd_cache_quick(screen_t screen,const unsigned char* old,const unsigned char* new)
- {
- bool ret = false;
- #if SOFTWARE_SPI_ENABLE
- if(screen == SCREEN_LEFT)
- {
- left_refresh_complete = false;
- }
- if(screen == SCREEN_RIGHT)
- {
- right_refresh_complete = false;
- }
- #else
- if(screen == SCREEN_LEFT)
- {
- left_refresh_complete = false;
- }
- if(screen == SCREEN_RIGHT)
- {
- right_refresh_complete = false;
- }
- #endif
- if((screen == SCREEN_LEFT)&&(old!=NULL))
- {
- printf("left partial quick\r\n");
- //Reset the display
- gpio_set_level(PIN_L_RST, 0);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- gpio_set_level(PIN_L_RST, 1);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- ret = epd_check_status(screen);
- if(!ret)
- {
- printf("err:2busy !!!!!\n");
- goto err;
- }
- uint8_t cmd[1]={0};
- epd_write_cmd(screen,0x00,false);
- cmd[0] = 0x1F;
- epd_write_data(screen,cmd,1);
- }
- if((screen == SCREEN_RIGHT)&&(old!=NULL))
- {
- printf("right partial quick\r\n");
- gpio_set_level(PIN_R_RST, 0);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- gpio_set_level(PIN_R_RST, 1);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- ret = epd_check_status(screen);
- if(!ret)
- {
- printf("err:3busy !!!!!\n");
- goto err;
- }
- uint8_t cmd2[1]={0};
- epd_write_cmd(screen,0x00,false);
- cmd2[0] = 0x1F;
- epd_write_data(screen,cmd2,1);
- }
- #if 1
- if (old !=NULL)
- {
- epd_write_cmd(screen,0x10,false);
- ret = epd_check_status(screen);
- if(!ret)
- {
- printf("err:busy !!!!!\n");
- goto err;
- }
- epd_write_data(screen,old,38880);
- ret = epd_check_status(screen);
- if(!ret)
- {
- printf("err:2busy !!!!!\n");
- goto err;
- }
- }
- #else
- epd_write_cmd(screen,0x10,false);
- epd_check_status(screen);
- memcpy(&tmp,new,38880);
- for(int i=0;i<38880;i++)
- {
- tmp[i] = ~tmp[i];
- }
- epd_write_data(screen,&tmp,38880);
- #endif
- epd_write_cmd(screen,0x13,false);
- ret = epd_check_status(screen);
- if(!ret)
- {
- printf("err:2busy !!!!!\n");
- goto err;
- }
- epd_write_data(screen,new,38880);
- ret = epd_check_status(screen);
- if(!ret)
- {
- printf("err:2busy !!!!!\n");
- goto err;
- }
-
- #if 0
- if(screen == SCREEN_LEFT)
- {
- left_refresh_complete = true;
- }
- if(screen == SCREEN_RIGHT)
- {
- right_refresh_complete = true;
- }
- #else
- #if SOFTWARE_SPI_ENABLE
- current_display = screen;
- //vTaskDelay(0000 / portTICK_PERIOD_MS);
- if(screen == SCREEN_LEFT)
- {
- left_refresh_timer_start(1000);
- }
- if(screen == SCREEN_LEFT)
- {
- right_refresh_timer_start(1000);
- }
- #else
- current_display = screen;
- //vTaskDelay(0000 / portTICK_PERIOD_MS);
- if(screen == SCREEN_LEFT)
- {
- left_refresh_timer_start(500);
- }
- if(screen == SCREEN_LEFT)
- {
- right_refresh_timer_start(500);
- }
- #endif
- //vTaskDelay(0000 / portTICK_PERIOD_MS);
- //refresh_timer_start(500);
- //xTimerStart(slow_display_timer, 0); //开始定时器
- #endif
- return true;
- err:
- ESP_LOGE(LOG_TAG,"err:epd_check_status");
- return false;
- }
- void epd_powerOn_refresh_sleep(screen_t screen)
- {
- epd_write_cmd(screen,0x04,false); // Power ON
- epd_check_status(screen);
- epd_refresh(screen);
- epd_sleep(screen);
- }
- void deepsleep_epd_powerOn_refresh_sleep(screen_t screen)
- {
- epd_write_cmd(screen,0x04,false); // Power ON
- //epd_check_status(screen);
- deepsleep_epd_check_status(screen);
- epd_write_cmd(screen,0x12,false);//DISPLAY REFRESH
- deepsleep_epd_check_status(screen);
- //epd_refresh(screen);
- //epd_sleep(screen);
- }
- #else/*HAREWARE_SPI*/
- static void task_delay_ms(uint32_t ms_count)
- {
- vTaskDelay(ms_count / portTICK_PERIOD_MS);
- }
- void epd_pin_init(struct EPD_INFO_SET* epd_pin_set)
- {
- esp_log_level_set("gpio",ESP_LOG_NONE);//close gpio logging
- ESP_LOGI(LOG_TAG,"epd_pin_init");
- #define EPD_OUT_PIN_SEL ((1ULL<<epd_pin_set->sclk_pin)|\
- (1ULL<<epd_pin_set->sda_pin)|\
- (1ULL<<epd_pin_set->res_pin)|\
- (1ULL<<epd_pin_set->dc_pin)|\
- (1ULL<<epd_pin_set->cs_pin))
- #define EPD_IN_PIN_SEL (1ULL<<epd_pin_set->busy_pin)
- gpio_config_t epd_pin_cfg = {};
- epd_pin_cfg.intr_type = GPIO_INTR_DISABLE;
- epd_pin_cfg.mode = GPIO_MODE_OUTPUT;
- epd_pin_cfg.pin_bit_mask =EPD_OUT_PIN_SEL;
- epd_pin_cfg.pull_down_en = 0;
- epd_pin_cfg.pull_up_en = 0;
- gpio_config(&epd_pin_cfg);
- epd_pin_cfg.intr_type = GPIO_INTR_DISABLE;
- epd_pin_cfg.mode = GPIO_MODE_INPUT;
- epd_pin_cfg.pin_bit_mask =EPD_IN_PIN_SEL;
- epd_pin_cfg.pull_down_en = 0;
- epd_pin_cfg.pull_up_en = 1;
- gpio_config(&epd_pin_cfg);
- esp_log_level_set("gpio",LOG_LOCAL_LEVEL);
- }
- void epd_spi_write(struct EPD_INFO_SET* epd_pin_set,unsigned char value)
- {
- int i = 0,data = value;
- epd_set_level(epd_pin_set->sclk_pin, LOW_LEVEL);
- for(i=0;i<8;i++)
- {
- if(data&0x0080)
- {
- epd_set_level(epd_pin_set->sda_pin,HIGH_LEVEL);
- }
- else
- {
- epd_set_level(epd_pin_set->sda_pin,LOW_LEVEL);
- }
- // ets_delay_us(1);
- epd_set_level(epd_pin_set->sclk_pin, HIGH_LEVEL);
- // ets_delay_us(1);
- epd_set_level(epd_pin_set->sclk_pin, LOW_LEVEL);
-
- data = ((data)<<1 & 0xff);
- }
- }
- void epd_write_cmd(struct EPD_INFO_SET* epd_pin_set, unsigned char command)
- {
- epd_set_level(epd_pin_set->cs_pin, LOW_LEVEL);
- epd_set_level(epd_pin_set->dc_pin, LOW_LEVEL);
- epd_spi_write(epd_pin_set,command);
- epd_set_level(epd_pin_set->cs_pin, HIGH_LEVEL);
- }
- void epd_write_data(struct EPD_INFO_SET* epd_pin_set, unsigned char command)
- {
- epd_set_level(epd_pin_set->cs_pin, LOW_LEVEL);
- epd_set_level(epd_pin_set->dc_pin, HIGH_LEVEL);
- epd_spi_write(epd_pin_set,command);
- epd_set_level(epd_pin_set->cs_pin, HIGH_LEVEL);
- //ets_delay_us(2);
- }
- void epd_init(struct EPD_INFO_SET* epd_pin_set)
- {
- epd_set_level(epd_pin_set->res_pin, LOW_LEVEL);
- task_delay_ms(10);
- epd_set_level(epd_pin_set->res_pin, HIGH_LEVEL);
- task_delay_ms(10);
- }
- void epd_check_status(struct EPD_INFO_SET* epd_pin_set)
- {
- while(!epd_get_level(epd_pin_set->busy_pin));
- }
- void epd_refresh(struct EPD_INFO_SET* epd_pin_set)
- {
- epd_write_cmd(epd_pin_set,0x12);//DISPLAY REFRESH
- //ets_delay_us(200); //!!!The delay here is necessary, 200uS at least!!!
- task_delay_ms(1);
- epd_check_status(epd_pin_set); //waiting for the electronic paper
- }
- void epd_sleep(struct EPD_INFO_SET* epd_pin_set)
- {
- epd_write_cmd(epd_pin_set,0x07);
- epd_write_data(epd_pin_set,0xa5);
- }
- void epd_screen_init(struct EPD_INFO_SET* epd_pin_set)
- {
- epd_pin_init(epd_pin_set);
- epd_init(epd_pin_set);
- epd_write_cmd(epd_pin_set,0x00);
- epd_write_data(epd_pin_set,0x1f);
- epd_write_data(epd_pin_set,0x09);
- epd_write_cmd(epd_pin_set,0x50);
- epd_write_data(epd_pin_set,0x18);
- epd_write_data(epd_pin_set,0x07);
- epd_write_cmd(epd_pin_set,0xe0);
- epd_write_data(epd_pin_set,0x02);
- epd_write_cmd(epd_pin_set,0xe5);
- epd_write_data(epd_pin_set,0x5c);
- }
- void epd_clear_black(struct EPD_INFO_SET* epd_pin_set)
- {
- unsigned int i;
-
- epd_write_cmd(epd_pin_set,0x13);
- for(i=0;i<38880;i++)
- {
- epd_write_data(epd_pin_set,0xff);
- }
- epd_write_cmd(epd_pin_set,0x04); //POWER ON
- epd_check_status(epd_pin_set); //waiting for the electronic paper IC to release the idle signal
- epd_refresh(epd_pin_set);
- epd_write_cmd(epd_pin_set,0x02); // Power OFF
- epd_check_status(epd_pin_set);
- }
- void epd_clear_write(struct EPD_INFO_SET* epd_pin_set)
- {
- unsigned int i;
-
- epd_write_cmd(epd_pin_set,0x13);
- for(i=0;i<38880;i++)
- {
- epd_write_data(epd_pin_set,0x00);
- }
- epd_write_cmd(epd_pin_set,0x04); //POWER ON
- epd_check_status(epd_pin_set); //waiting for the electronic paper IC to release the idle signal
- //Refresh
- epd_refresh(epd_pin_set);
- epd_write_cmd(epd_pin_set,0x02); // Power OFF
- epd_check_status(epd_pin_set);
- }
- // PAINT left_screen_paint;
- // PAINT right_screen_paint;
- void epd_display(struct EPD_INFO_SET* epd_pin_set,const unsigned char* picData)
- {
- unsigned int i;
-
- epd_write_cmd(epd_pin_set,0x13);
- for(i=0;i<38880;i++)
- {
- epd_write_data(epd_pin_set,picData[i]);
- }
- epd_write_cmd(epd_pin_set,0x04); //POWER ON
- epd_check_status(epd_pin_set); //waiting for the electronic paper IC to release the idle signal
- //Refresh
- epd_refresh(epd_pin_set);
- epd_write_cmd(epd_pin_set,0x02); // Power OFF
- epd_check_status(epd_pin_set);
- }
- void epd_cache(struct EPD_INFO_SET* epd_pin_set,const unsigned char* picData)
- {
- unsigned int i;
-
- epd_write_cmd(epd_pin_set,0x13);
- for(i=0;i<38880;i++)
- {
- epd_write_data(epd_pin_set,picData[i]);
- }
- }
- void epd_display_partal(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,
- struct EPD_INFO_SET* epd_pin_set,const unsigned char* picData)
- {
- unsigned int row, col;
- uint8_t Xstart_H,Xstart_L,Ystart_H,Ystart_L,Xend_H,Xend_L,Yend_H,Yend_L;
- Xstart_H = ((Xstart)>>8) & 0xff;
- Xstart_L = (Xstart) & 0xff;
- Ystart_H = ((Ystart)>>8) & 0xff;
- Ystart_L = (Ystart) & 0xff;
- Xend_H = ((Xend-1)>>8) & 0xff;
- Xend_L = (Xend-1) & 0xff;
- Yend_H = ((Yend-1)>>8) & 0xff;
- Yend_L = (Yend-1) & 0xff;
- epd_write_cmd(epd_pin_set,0x91); // partial in
- epd_check_status(epd_pin_set);
-
- epd_write_cmd(epd_pin_set,0x90);
- epd_check_status(epd_pin_set);
- epd_write_data(epd_pin_set,Xstart_H);
- epd_write_data(epd_pin_set,Xstart_L);
- epd_write_data(epd_pin_set,Xend_H);
- epd_write_data(epd_pin_set,Xend_L);
- epd_write_data(epd_pin_set,Ystart_H);
- epd_write_data(epd_pin_set,Ystart_L);
- epd_write_data(epd_pin_set,Yend_H);
- epd_write_data(epd_pin_set,Yend_L);
- epd_write_data(epd_pin_set,0x01);
- epd_write_cmd(epd_pin_set,0x13);
- epd_check_status(epd_pin_set);
-
- int i = 0;
- for(col=0; col<(Yend - Ystart); col++)
- {
- for(row=0; row<((Xend - Xstart)/8); row++)
- {
- epd_write_data(epd_pin_set,picData[i++]);
- }
- }
- epd_write_cmd(epd_pin_set,0x92);
-
- epd_write_cmd(epd_pin_set,0x04); // Power ON
- epd_check_status(epd_pin_set);
- epd_refresh(epd_pin_set);
- epd_write_cmd(epd_pin_set,0x02); // Power OFF
- epd_check_status(epd_pin_set);
- }
- void epd_partial_cache(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,
- struct EPD_INFO_SET* epd_pin_set,const unsigned char* picData)
- {
- unsigned int row, col;
- uint8_t Xstart_H,Xstart_L,Ystart_H,Ystart_L,Xend_H,Xend_L,Yend_H,Yend_L;
- Xstart_H = ((Xstart)>>8) & 0xff;
- Xstart_L = (Xstart) & 0xff;
- Ystart_H = ((Ystart)>>8) & 0xff;
- Ystart_L = (Ystart) & 0xff;
- Xend_H = ((Xend-1)>>8) & 0xff;
- Xend_L = (Xend-1) & 0xff;
- Yend_H = ((Yend-1)>>8) & 0xff;
- Yend_L = (Yend-1) & 0xff;
- epd_write_cmd(epd_pin_set,0x91); // partial in
- epd_check_status(epd_pin_set);
-
- epd_write_cmd(epd_pin_set,0x90);
- epd_check_status(epd_pin_set);
- epd_write_data(epd_pin_set,Xstart_H);
- epd_write_data(epd_pin_set,Xstart_L);
- epd_write_data(epd_pin_set,Xend_H);
- epd_write_data(epd_pin_set,Xend_L);
- epd_write_data(epd_pin_set,Ystart_H);
- epd_write_data(epd_pin_set,Ystart_L);
- epd_write_data(epd_pin_set,Yend_H);
- epd_write_data(epd_pin_set,Yend_L);
- epd_write_data(epd_pin_set,0x01);
- epd_write_cmd(epd_pin_set,0x13);
- epd_check_status(epd_pin_set);
-
- int i = 0;
- for(col=0; col<(Yend - Ystart); col++)
- {
- for(row=0; row<((Xend - Xstart)/8); row++)
- {
- epd_write_data(epd_pin_set,picData[i++]);
- }
- }
- epd_write_cmd(epd_pin_set,0x92);
- }
- void epd_powerOn_refresh(struct EPD_INFO_SET* epd_pin_set)
- {
- epd_write_cmd(epd_pin_set,0x04); // Power ON
- epd_check_status(epd_pin_set);
- epd_refresh(epd_pin_set);
- epd_write_cmd(epd_pin_set,0x02); // Power OFF
- epd_check_status(epd_pin_set);
- }
- #endif/*HAREWARE_SPI*/
|