12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718 |
- #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"
- uint8_t current_display = 0;
- #include "../../main/user_sleep.h"
- #include "esp_sleep.h"
-
- 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
- }
- 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)
- {
- 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 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((screen == SCREEN_LEFT)&&(old!=NULL))
- {
- printf("SCREEN_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);
- 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("SCREEN_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);
- 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
- //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*/
|