waveshare_epaper

Waveshare e-paper display shenanigans
git clone git://bsandro.tech/waveshare_epaper
Log | Files | Refs | README

EPD_7in5b_V2.c (8260B)


      1 /*****************************************************************************
      2 * | File      	:	EPD_7IN5B_V2_7in5.c
      3 * | Author      :   Waveshare team
      4 * | Function    :   Electronic paper driver
      5 * | Info        :
      6 *----------------
      7 * |	This version:   V2.0
      8 * | Date        :   2018-11-09
      9 * | Info        :
     10 ******************************************************************************
     11 # Permission is hereby granted, free of charge, to any person obtaining a copy
     12 # of this software and associated documnetation files(the "Software"), to deal
     13 # in the Software without restriction, including without limitation the rights
     14 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     15 # copies of the Software, and to permit persons to  whom the Software is
     16 # furished to do so, subject to the following conditions:
     17 #
     18 # The above copyright notice and this permission notice shall be included in
     19 # all copies or substantial portions of the Software.
     20 #
     21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     22 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     23 # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     24 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     25 # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     26 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     27 # THE SOFTWARE.
     28 #
     29 ******************************************************************************/
     30 #include "EPD_7in5b_V2.h"
     31 #include "Debug.h"
     32 
     33 /******************************************************************************
     34 function :	Software reset
     35 parameter:
     36 ******************************************************************************/
     37 static void EPD_7IN5B_V2_Reset(void)
     38 {
     39     DEV_Digital_Write(EPD_RST_PIN, 1);
     40     DEV_Delay_ms(200);
     41     DEV_Digital_Write(EPD_RST_PIN, 0);
     42     DEV_Delay_ms(2);
     43     DEV_Digital_Write(EPD_RST_PIN, 1);
     44     DEV_Delay_ms(200);
     45 }
     46 
     47 /******************************************************************************
     48 function :	send command
     49 parameter:
     50      Reg : Command register
     51 ******************************************************************************/
     52 static void EPD_7IN5B_V2_SendCommand(UBYTE Reg)
     53 {
     54     DEV_Digital_Write(EPD_DC_PIN, 0);
     55     DEV_Digital_Write(EPD_CS_PIN, 0);
     56     DEV_SPI_WriteByte(Reg);
     57     DEV_Digital_Write(EPD_CS_PIN, 1);
     58 }
     59 
     60 /******************************************************************************
     61 function :	send data
     62 parameter:
     63     Data : Write data
     64 ******************************************************************************/
     65 static void EPD_7IN5B_V2_SendData(UBYTE Data)
     66 {
     67     DEV_Digital_Write(EPD_DC_PIN, 1);
     68     DEV_Digital_Write(EPD_CS_PIN, 0);
     69     DEV_SPI_WriteByte(Data);
     70     DEV_Digital_Write(EPD_CS_PIN, 1);
     71 }
     72 
     73 /******************************************************************************
     74 function :	Wait until the busy_pin goes LOW
     75 parameter:
     76 ******************************************************************************/
     77 void EPD_7IN5B_V2_WaitUntilIdle(void)
     78 {
     79     Debug("e-Paper busy\r\n");
     80     unsigned char busy;
     81 	do	{
     82 		EPD_7IN5B_V2_SendCommand(0x71);
     83 		busy = DEV_Digital_Read(EPD_BUSY_PIN);
     84 		busy =!(busy & 0x01);        
     85 	}while(busy);
     86 	DEV_Delay_ms(200);      
     87 		
     88 		
     89 		Debug("e-Paper busy release\r\n");
     90 		
     91 }
     92 
     93 
     94 /******************************************************************************
     95 function :	Turn On Display
     96 parameter:
     97 ******************************************************************************/
     98 static void EPD_7IN5B_V2_TurnOnDisplay(void)
     99 {
    100     EPD_7IN5B_V2_SendCommand(0x12);			//DISPLAY REFRESH
    101     DEV_Delay_ms(100);	        //!!!The delay here is necessary, 200uS at least!!!
    102     EPD_7IN5B_V2_WaitUntilIdle();
    103 }
    104 
    105 /******************************************************************************
    106 function :	Initialize the e-Paper register
    107 parameter:
    108 ******************************************************************************/
    109 UBYTE EPD_7IN5B_V2_Init(void)
    110 {
    111     EPD_7IN5B_V2_Reset();
    112 
    113     EPD_7IN5B_V2_SendCommand(0x01);			//POWER SETTING
    114     EPD_7IN5B_V2_SendData(0x07);
    115     EPD_7IN5B_V2_SendData(0x07);    //VGH=20V,VGL=-20V
    116     EPD_7IN5B_V2_SendData(0x3f);		//VDH=15V
    117     EPD_7IN5B_V2_SendData(0x3f);		//VDL=-15V
    118 
    119     EPD_7IN5B_V2_SendCommand(0x04); //POWER ON
    120     DEV_Delay_ms(100);
    121     EPD_7IN5B_V2_WaitUntilIdle();
    122 
    123     EPD_7IN5B_V2_SendCommand(0X00);			//PANNEL SETTING
    124     EPD_7IN5B_V2_SendData(0x0F);   //KW-3f   KWR-2F	BWROTP 0f	BWOTP 1f
    125 
    126     EPD_7IN5B_V2_SendCommand(0x61);        	//tres
    127     EPD_7IN5B_V2_SendData(0x03);		//source 800
    128     EPD_7IN5B_V2_SendData(0x20);
    129     EPD_7IN5B_V2_SendData(0x01);		//gate 480
    130     EPD_7IN5B_V2_SendData(0xE0);
    131 
    132     EPD_7IN5B_V2_SendCommand(0X15);
    133     EPD_7IN5B_V2_SendData(0x00);
    134 
    135     EPD_7IN5B_V2_SendCommand(0X50);			//VCOM AND DATA INTERVAL SETTING
    136     EPD_7IN5B_V2_SendData(0x11);
    137     EPD_7IN5B_V2_SendData(0x07);
    138 
    139     EPD_7IN5B_V2_SendCommand(0X60);			//TCON SETTING
    140     EPD_7IN5B_V2_SendData(0x22);
    141 
    142     return 0;
    143 }
    144 
    145 /******************************************************************************
    146 function :	Clear screen
    147 parameter:
    148 ******************************************************************************/
    149 void EPD_7IN5B_V2_Clear(void)
    150 {
    151     UWORD Width, Height;
    152     Width =(EPD_7IN5B_V2_WIDTH % 8 == 0)?(EPD_7IN5B_V2_WIDTH / 8 ):(EPD_7IN5B_V2_WIDTH / 8 + 1);
    153     Height = EPD_7IN5B_V2_HEIGHT;
    154 
    155     UWORD i;
    156     EPD_7IN5B_V2_SendCommand(0x10);
    157     for(i=0; i<Width*Height; i++) {
    158         EPD_7IN5B_V2_SendData(0xff);
    159 
    160     }
    161     EPD_7IN5B_V2_SendCommand(0x13);
    162     for(i=0; i<Width*Height; i++)	{
    163         EPD_7IN5B_V2_SendData(0x00);
    164 
    165     }
    166     EPD_7IN5B_V2_TurnOnDisplay();
    167 }
    168 
    169 void EPD_7IN5B_V2_ClearRed(void)
    170 {
    171     UWORD Width, Height;
    172     Width =(EPD_7IN5B_V2_WIDTH % 8 == 0)?(EPD_7IN5B_V2_WIDTH / 8 ):(EPD_7IN5B_V2_WIDTH / 8 + 1);
    173     Height = EPD_7IN5B_V2_HEIGHT;
    174 
    175     UWORD i;
    176     EPD_7IN5B_V2_SendCommand(0x10);
    177     for(i=0; i<Width*Height; i++) {
    178         EPD_7IN5B_V2_SendData(0xff);
    179 
    180     }
    181     EPD_7IN5B_V2_SendCommand(0x13);
    182     for(i=0; i<Width*Height; i++)	{
    183         EPD_7IN5B_V2_SendData(0xff);
    184 
    185     }
    186     EPD_7IN5B_V2_TurnOnDisplay();
    187 }
    188 
    189 void EPD_7IN5B_V2_ClearBlack(void)
    190 {
    191     UWORD Width, Height;
    192     Width =(EPD_7IN5B_V2_WIDTH % 8 == 0)?(EPD_7IN5B_V2_WIDTH / 8 ):(EPD_7IN5B_V2_WIDTH / 8 + 1);
    193     Height = EPD_7IN5B_V2_HEIGHT;
    194 
    195     UWORD i;
    196     EPD_7IN5B_V2_SendCommand(0x10);
    197     for(i=0; i<Width*Height; i++) {
    198         EPD_7IN5B_V2_SendData(0x00);
    199 
    200     }
    201     EPD_7IN5B_V2_SendCommand(0x13);
    202     for(i=0; i<Width*Height; i++)	{
    203         EPD_7IN5B_V2_SendData(0x00);
    204 
    205     }
    206     EPD_7IN5B_V2_TurnOnDisplay();
    207 }
    208 
    209 /******************************************************************************
    210 function :	Sends the image buffer in RAM to e-Paper and displays
    211 parameter:
    212 ******************************************************************************/
    213 void EPD_7IN5B_V2_Display(const UBYTE *blackimage, const UBYTE *ryimage)
    214 {
    215     UDOUBLE Width, Height;
    216     Width =(EPD_7IN5B_V2_WIDTH % 8 == 0)?(EPD_7IN5B_V2_WIDTH / 8 ):(EPD_7IN5B_V2_WIDTH / 8 + 1);
    217     Height = EPD_7IN5B_V2_HEIGHT;
    218 
    219  //send black data
    220     EPD_7IN5B_V2_SendCommand(0x10);
    221     for (UDOUBLE j = 0; j < Height; j++) {
    222         for (UDOUBLE i = 0; i < Width; i++) {
    223             EPD_7IN5B_V2_SendData(blackimage[i + j * Width]);
    224         }
    225     }
    226     EPD_7IN5B_V2_SendCommand(0x92); 
    227 
    228     //send red data
    229     EPD_7IN5B_V2_SendCommand(0x13);
    230     for (UDOUBLE j = 0; j < Height; j++) {
    231         for (UDOUBLE i = 0; i < Width; i++) {
    232             EPD_7IN5B_V2_SendData(~ryimage[i + j * Width]);
    233         }
    234     }
    235     EPD_7IN5B_V2_TurnOnDisplay();
    236 }
    237 
    238 /******************************************************************************
    239 function :	Enter sleep mode
    240 parameter:
    241 ******************************************************************************/
    242 void EPD_7IN5B_V2_Sleep(void)
    243 {
    244     EPD_7IN5B_V2_SendCommand(0X02);  	//power off
    245     EPD_7IN5B_V2_WaitUntilIdle();
    246     EPD_7IN5B_V2_SendCommand(0X07);  	//deep sleep
    247     EPD_7IN5B_V2_SendData(0xA5);
    248 }