waveshare_epaper

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

EPD_2in13b_V3.c (7043B)


      1 /*****************************************************************************
      2 * | File      	:   EPD_2in13b_V3.c
      3 * | Author      :   Waveshare team
      4 * | Function    :   2.13inch e-paper b V3
      5 * | Info        :
      6 *----------------
      7 * |	This version:   V1.0
      8 * | Date        :   2020-04-13
      9 * | Info        :
     10 * -----------------------------------------------------------------------------
     11 #
     12 # Permission is hereby granted, free of charge, to any person obtaining a copy
     13 # of this software and associated documnetation files (the "Software"), to deal
     14 # in the Software without restriction, including without limitation the rights
     15 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     16 # copies of the Software, and to permit persons to  whom the Software is
     17 # furished to do so, subject to the following conditions:
     18 #
     19 # The above copyright notice and this permission notice shall be included in
     20 # all copies or substantial portions of the Software.
     21 #
     22 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     23 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     24 # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     25 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     26 # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     27 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     28 # THE SOFTWARE.
     29 #
     30 ******************************************************************************/
     31 #include "EPD_2in13b_V3.h"
     32 #include "Debug.h"
     33 
     34 /******************************************************************************
     35 function :	Software reset
     36 parameter:
     37 ******************************************************************************/
     38 static void EPD_2IN13B_V3_Reset(void)
     39 {
     40     DEV_Digital_Write(EPD_CS_PIN, 1);
     41     
     42     DEV_Digital_Write(EPD_RST_PIN, 1);
     43     DEV_Delay_ms(1000);
     44     DEV_Digital_Write(EPD_RST_PIN, 0);
     45     DEV_Delay_ms(10);
     46     DEV_Digital_Write(EPD_RST_PIN, 1);
     47     DEV_Delay_ms(10);
     48 }
     49 
     50 /******************************************************************************
     51 function :	send command
     52 parameter:
     53      Reg : Command register
     54 ******************************************************************************/
     55 static void EPD_2IN13B_V3_SendCommand(UBYTE Reg)
     56 {
     57     
     58     DEV_Digital_Write(EPD_DC_PIN, 0);
     59     DEV_Digital_Write(EPD_CS_PIN, 0);
     60     DEV_SPI_WriteByte(Reg);
     61     DEV_Digital_Write(EPD_CS_PIN, 1);
     62 }
     63 
     64 /******************************************************************************
     65 function :	send data
     66 parameter:
     67     Data : Write data
     68 ******************************************************************************/
     69 static void EPD_2IN13B_V3_SendData(UBYTE Data)
     70 {
     71     DEV_Digital_Write(EPD_DC_PIN, 1);
     72     DEV_Digital_Write(EPD_CS_PIN, 0);
     73     DEV_SPI_WriteByte(Data);
     74     DEV_Digital_Write(EPD_CS_PIN, 1);
     75 }
     76 
     77 /******************************************************************************
     78 function :	Wait until the busy_pin goes LOW
     79 parameter:
     80 ******************************************************************************/
     81 void EPD_2IN13B_V3_ReadBusy(void)
     82 {
     83     UBYTE busy;
     84     Debug("e-Paper busy\r\n");
     85     do{
     86         EPD_2IN13B_V3_SendCommand(0x71);
     87         busy = DEV_Digital_Read(EPD_BUSY_PIN);
     88         busy =!(busy & 0x01);
     89     }while(busy);
     90     Debug("e-Paper busy release\r\n");
     91     DEV_Delay_ms(200);
     92 }
     93 
     94 /******************************************************************************
     95 function :	Turn On Display
     96 parameter:
     97 ******************************************************************************/
     98 static void EPD_2IN13B_V3_TurnOnDisplay(void)
     99 {
    100     EPD_2IN13B_V3_SendCommand(0x12);		 //DISPLAY REFRESH
    101     DEV_Delay_ms(100);
    102     EPD_2IN13B_V3_ReadBusy();
    103 }
    104 
    105 /******************************************************************************
    106 function :	Initialize the e-Paper register
    107 parameter:
    108 ******************************************************************************/
    109 void EPD_2IN13B_V3_Init(void)
    110 {
    111     EPD_2IN13B_V3_Reset();
    112     DEV_Delay_ms(10);
    113     
    114     EPD_2IN13B_V3_SendCommand(0x04);  
    115     EPD_2IN13B_V3_ReadBusy();//waiting for the electronic paper IC to release the idle signal
    116 
    117     EPD_2IN13B_V3_SendCommand(0x00);//panel setting
    118     EPD_2IN13B_V3_SendData(0x0f);//LUT from OTP,128x296
    119     EPD_2IN13B_V3_SendData(0x89);//Temperature sensor, boost and other related timing settings
    120 
    121     EPD_2IN13B_V3_SendCommand(0x61);//resolution setting
    122     EPD_2IN13B_V3_SendData (0x68);
    123     EPD_2IN13B_V3_SendData (0x00);
    124     EPD_2IN13B_V3_SendData (0xD4);
    125 
    126     EPD_2IN13B_V3_SendCommand(0X50);//VCOM AND DATA INTERVAL SETTING
    127     EPD_2IN13B_V3_SendData(0x77);//WBmode:VBDF 17|D7 VBDW 97 VBDB 57
    128                                  //WBRmode:VBDF F7 VBDW 77 VBDB 37  VBDR B7;
    129 }
    130 
    131 /******************************************************************************
    132 function :	Clear screen
    133 parameter:
    134 ******************************************************************************/
    135 void EPD_2IN13B_V3_Clear(void)
    136 {
    137     UWORD Width = (EPD_2IN13B_V3_WIDTH % 8 == 0)? (EPD_2IN13B_V3_WIDTH / 8 ): (EPD_2IN13B_V3_WIDTH / 8 + 1);
    138     UWORD Height = EPD_2IN13B_V3_HEIGHT;
    139     
    140     //send black data
    141     EPD_2IN13B_V3_SendCommand(0x10);
    142     for (UWORD j = 0; j < Height; j++) {
    143         for (UWORD i = 0; i < Width; i++) {
    144             EPD_2IN13B_V3_SendData(0xFF);
    145         }
    146     }
    147 
    148     //send red data
    149     EPD_2IN13B_V3_SendCommand(0x13);
    150     for (UWORD j = 0; j < Height; j++) {
    151         for (UWORD i = 0; i < Width; i++) {
    152             EPD_2IN13B_V3_SendData(0xFF);
    153         }
    154     }
    155     EPD_2IN13B_V3_TurnOnDisplay();
    156 }
    157 
    158 /******************************************************************************
    159 function :	Sends the image buffer in RAM to e-Paper and displays
    160 parameter:
    161 ******************************************************************************/
    162 void EPD_2IN13B_V3_Display(const UBYTE *blackimage, const UBYTE *ryimage)
    163 {
    164     UWORD Width, Height;
    165     Width = (EPD_2IN13B_V3_WIDTH % 8 == 0)? (EPD_2IN13B_V3_WIDTH / 8 ): (EPD_2IN13B_V3_WIDTH / 8 + 1);
    166     Height = EPD_2IN13B_V3_HEIGHT;
    167     
    168     EPD_2IN13B_V3_SendCommand(0x10);
    169     for (UWORD j = 0; j < Height; j++) {
    170         for (UWORD i = 0; i < Width; i++) {
    171             EPD_2IN13B_V3_SendData(blackimage[i + j * Width]);
    172         }
    173     }
    174     
    175     EPD_2IN13B_V3_SendCommand(0x13);
    176     for (UWORD j = 0; j < Height; j++) {
    177         for (UWORD i = 0; i < Width; i++) {
    178             EPD_2IN13B_V3_SendData(ryimage[i + j * Width]);
    179         }
    180     }
    181     EPD_2IN13B_V3_TurnOnDisplay();
    182 }
    183 
    184 /******************************************************************************
    185 function :	Enter sleep mode
    186 parameter:
    187 ******************************************************************************/
    188 void EPD_2IN13B_V3_Sleep(void)
    189 {
    190     EPD_2IN13B_V3_SendCommand(0X50);
    191     EPD_2IN13B_V3_SendData(0xf7); 
    192 
    193     EPD_2IN13B_V3_SendCommand(0X02); //power off
    194     EPD_2IN13B_V3_ReadBusy();          //waiting for the electronic paper IC to release the idle signal
    195     EPD_2IN13B_V3_SendCommand(0X07); //deep sleep
    196     EPD_2IN13B_V3_SendData(0xA5);
    197 }