waveshare_epaper

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

EPD_2in7.c (20072B)


      1 /*****************************************************************************
      2 * | File      	:   EPD_2in7.c
      3 * | Author      :   Waveshare team
      4 * | Function    :   2.7inch e-paper
      5 * | Info        :
      6 *----------------
      7 * |	This version:   V3.1
      8 * | Date        :   2019-10-10
      9 * | Info        :
     10 * -----------------------------------------------------------------------------
     11 * V3.1(2019-10-10):
     12 * 1. Add 4 grayscale display
     13 *     Add   EPD_2in7_gray_lut_vcom[]
     14 *     Add   EPD_2in7_gray_lut_ww[]
     15 *     Add   EPD_2in7_gray_lut_bw[]
     16 *     Add   EPD_2in7_gray_lut_wb[]
     17 *     Add   EPD_2in7_gray_lut_bb[]
     18 *     Add   EPD_2in7_gray_SetLut()
     19 *     Add   EPD_2IN7_Init_4Gray()
     20 *     Add   EPD_2IN7_4GrayDisplay()
     21 * V3.0(2019-06-12):
     22 * 1.Change:
     23 *    lut_vcom_dc[] => EPD_2in7_lut_vcom_dc[]
     24 *    lut_ww[] => EPD_2in7_lut_ww[]
     25 *    lut_bw[] => EPD_2in7_lut_bw[]
     26 *    lut_bb[] => EPD_2in7_lut_bb[]
     27 *    lut_wb[] => EPD_2in7_lut_wb[]
     28 *    EPD_Reset() => EPD_2in7_Reset()
     29 *    EPD_SendCommand() => EPD_2in7_SendCommand()
     30 *    EPD_SendData() => EPD_2in7_SendData()
     31 *    EPD_WaitUntilIdle() => EPD_2in7_ReadBusy()
     32 *    EPD_SetLut() => EPD_2in7_SetLut()
     33 *    EPD_Init() => EPD_2in7_Init()
     34 *    EPD_Clear() => EPD_2in7_Clear()
     35 *    EPD_Display() => EPD_2in7_Display()
     36 *    EPD_Sleep() => EPD_2in7_Sleep()
     37 * 2.remove commands define:
     38 *   #define PANEL_SETTING                               0x00
     39 *   #define POWER_SETTING                               0x01
     40 *   #define POWER_OFF                                   0x02
     41 *   #define POWER_OFF_SEQUENCE_SETTING                  0x03
     42 *   #define POWER_ON                                    0x04
     43 *   #define POWER_ON_MEASURE                            0x05
     44 *   #define BOOSTER_SOFT_START                          0x06
     45 *   #define DEEP_SLEEP                                  0x07
     46 *   #define DATA_START_TRANSMISSION_1                   0x10
     47 *   #define DATA_STOP                                   0x11
     48 *   #define DISPLAY_REFRESH                             0x12
     49 *   #define DATA_START_TRANSMISSION_2                   0x13
     50 *   #define PLL_CONTROL                                 0x30
     51 *   #define TEMPERATURE_SENSOR_COMMAND                  0x40
     52 *   #define TEMPERATURE_SENSOR_CALIBRATION              0x41
     53 *   #define TEMPERATURE_SENSOR_WRITE                    0x42
     54 *   #define TEMPERATURE_SENSOR_READ                     0x43
     55 *   #define VCOM_AND_DATA_INTERVAL_SETTING              0x50
     56 *   #define LOW_POWER_DETECTION                         0x51
     57 *   #define TCON_SETTING                                0x60
     58 *   #define TCON_RESOLUTION                             0x61
     59 *   #define SOURCE_AND_GATE_START_SETTING               0x62
     60 *   #define GET_STATUS                                  0x71
     61 *   #define AUTO_MEASURE_VCOM                           0x80
     62 *   #define VCOM_VALUE                                  0x81
     63 *   #define VCM_DC_SETTING_REGISTER                     0x82
     64 *   #define PROGRAM_MODE                                0xA0
     65 *   #define ACTIVE_PROGRAM                              0xA1
     66 *   #define READ_OTP_DATA                               0xA2
     67 * -----------------------------------------------------------------------------
     68 * V2.0(2018-11-06):
     69 * 1.Remove:ImageBuff[EPD_HEIGHT * EPD_WIDTH / 8]
     70 * 2.Change:EPD_Display(UBYTE *Image)
     71 *   Need to pass parameters: pointer to cached data
     72 #
     73 # Permission is hereby granted, free of charge, to any person obtaining a copy
     74 # of this software and associated documnetation files (the "Software"), to deal
     75 # in the Software without restriction, including without limitation the rights
     76 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     77 # copies of the Software, and to permit persons to  whom the Software is
     78 # furished to do so, subject to the following conditions:
     79 #
     80 # The above copyright notice and this permission notice shall be included in
     81 # all copies or substantial portions of the Software.
     82 #
     83 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     84 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     85 # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     86 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     87 # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     88 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     89 # THE SOFTWARE.
     90 #
     91 ******************************************************************************/
     92 #include "EPD_2in7.h"
     93 #include "Debug.h"
     94 
     95 static const unsigned char EPD_2in7_lut_vcom_dc[] = {
     96     0x00	,0x00,
     97     0x00	,0x08	,0x00	,0x00	,0x00	,0x02,
     98     0x60	,0x28	,0x28	,0x00	,0x00	,0x01,
     99     0x00	,0x14	,0x00	,0x00	,0x00	,0x01,
    100     0x00	,0x12	,0x12	,0x00	,0x00	,0x01,
    101     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    102     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    103     0x00	,0x00	,0x00	,0x00	,0x00	,0x00
    104 };
    105 static const unsigned char EPD_2in7_lut_ww[] = {
    106     0x40	,0x08	,0x00	,0x00	,0x00	,0x02,
    107     0x90	,0x28	,0x28	,0x00	,0x00	,0x01,
    108     0x40	,0x14	,0x00	,0x00	,0x00	,0x01,
    109     0xA0	,0x12	,0x12	,0x00	,0x00	,0x01,
    110     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    111     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    112     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    113 };
    114 static const unsigned char EPD_2in7_lut_bw[] = {
    115     0x40	,0x08	,0x00	,0x00	,0x00	,0x02,
    116     0x90	,0x28	,0x28	,0x00	,0x00	,0x01,
    117     0x40	,0x14	,0x00	,0x00	,0x00	,0x01,
    118     0xA0	,0x12	,0x12	,0x00	,0x00	,0x01,
    119     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    120     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    121     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    122 };
    123 static const unsigned char EPD_2in7_lut_bb[] = {
    124     0x80	,0x08	,0x00	,0x00	,0x00	,0x02,
    125     0x90	,0x28	,0x28	,0x00	,0x00	,0x01,
    126     0x80	,0x14	,0x00	,0x00	,0x00	,0x01,
    127     0x50	,0x12	,0x12	,0x00	,0x00	,0x01,
    128     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    129     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    130     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    131 };
    132 static const unsigned char EPD_2in7_lut_wb[] = {
    133     0x80	,0x08	,0x00	,0x00	,0x00	,0x02,
    134     0x90	,0x28	,0x28	,0x00	,0x00	,0x01,
    135     0x80	,0x14	,0x00	,0x00	,0x00	,0x01,
    136     0x50	,0x12	,0x12	,0x00	,0x00	,0x01,
    137     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    138     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    139     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    140 };
    141 
    142 //////////////////////////////////////full screen update LUT////////////////////////////////////////////
    143 //0~3 gray
    144 static const unsigned char EPD_2in7_gray_lut_vcom[] = {
    145     0x00	,0x00,
    146     0x00	,0x0A	,0x00	,0x00	,0x00	,0x01,
    147     0x60	,0x14	,0x14	,0x00	,0x00	,0x01,
    148     0x00	,0x14	,0x00	,0x00	,0x00	,0x01,
    149     0x00	,0x13	,0x0A	,0x01	,0x00	,0x01,
    150     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    151     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    152     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    153 };
    154 //R21
    155 static const unsigned char EPD_2in7_gray_lut_ww[] = {
    156     0x40	,0x0A	,0x00	,0x00	,0x00	,0x01,
    157     0x90	,0x14	,0x14	,0x00	,0x00	,0x01,
    158     0x10	,0x14	,0x0A	,0x00	,0x00	,0x01,
    159     0xA0	,0x13	,0x01	,0x00	,0x00	,0x01,
    160     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    161     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    162     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    163 };
    164 //R22H	r
    165 static const unsigned char EPD_2in7_gray_lut_bw[] = {
    166     0x40	,0x0A	,0x00	,0x00	,0x00	,0x01,
    167     0x90	,0x14	,0x14	,0x00	,0x00	,0x01,
    168     0x00	,0x14	,0x0A	,0x00	,0x00	,0x01,
    169     0x99	,0x0C	,0x01	,0x03	,0x04	,0x01,
    170     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    171     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    172     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    173 };
    174 //R23H	w
    175 static const unsigned char EPD_2in7_gray_lut_wb[] = {
    176     0x40	,0x0A	,0x00	,0x00	,0x00	,0x01,
    177     0x90	,0x14	,0x14	,0x00	,0x00	,0x01,
    178     0x00	,0x14	,0x0A	,0x00	,0x00	,0x01,
    179     0x99	,0x0B	,0x04	,0x04	,0x01	,0x01,
    180     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    181     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    182     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    183 };
    184 //R24H	b
    185 static const unsigned char EPD_2in7_gray_lut_bb[] = {
    186     0x80	,0x0A	,0x00	,0x00	,0x00	,0x01,
    187     0x90	,0x14	,0x14	,0x00	,0x00	,0x01,
    188     0x20	,0x14	,0x0A	,0x00	,0x00	,0x01,
    189     0x50	,0x13	,0x01	,0x00	,0x00	,0x01,
    190     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    191     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    192     0x00	,0x00	,0x00	,0x00	,0x00	,0x00,
    193 };
    194 
    195 /******************************************************************************
    196 function :	Software reset
    197 parameter:
    198 ******************************************************************************/
    199 static void EPD_2in7_Reset(void)
    200 {
    201     DEV_Digital_Write(EPD_RST_PIN, 1);
    202     DEV_Delay_ms(200);
    203     DEV_Digital_Write(EPD_RST_PIN, 0);
    204     DEV_Delay_ms(10);
    205     DEV_Digital_Write(EPD_RST_PIN, 1);
    206     DEV_Delay_ms(200);
    207 }
    208 
    209 /******************************************************************************
    210 function :	send command
    211 parameter:
    212      Reg : Command register
    213 ******************************************************************************/
    214 static void EPD_2in7_SendCommand(UBYTE Reg)
    215 {
    216     DEV_Digital_Write(EPD_DC_PIN, 0);
    217     DEV_Digital_Write(EPD_CS_PIN, 0);
    218     DEV_SPI_WriteByte(Reg);
    219     DEV_Digital_Write(EPD_CS_PIN, 1);
    220 }
    221 
    222 /******************************************************************************
    223 function :	send data
    224 parameter:
    225     Data : Write data
    226 ******************************************************************************/
    227 static void EPD_2in7_SendData(UBYTE Data)
    228 {
    229     DEV_Digital_Write(EPD_DC_PIN, 1);
    230     DEV_Digital_Write(EPD_CS_PIN, 0);
    231     DEV_SPI_WriteByte(Data);
    232     DEV_Digital_Write(EPD_CS_PIN, 1);
    233 }
    234 
    235 /******************************************************************************
    236 function :	Wait until the busy_pin goes LOW
    237 parameter:
    238 ******************************************************************************/
    239 static void EPD_2in7_ReadBusy(void)
    240 {
    241     Debug("e-Paper busy\r\n");
    242     UBYTE busy;
    243     do {
    244         EPD_2in7_SendCommand(0x71);
    245         busy = DEV_Digital_Read(EPD_BUSY_PIN);
    246         busy =!(busy & 0x01);
    247     } while(busy);
    248     DEV_Delay_ms(200);
    249     Debug("e-Paper busy release\r\n");
    250 }
    251 
    252 /******************************************************************************
    253 function :	set the look-up tables
    254 parameter:
    255 ******************************************************************************/
    256 static void EPD_2in7_SetLut(void)
    257 {
    258     unsigned int count;
    259     EPD_2in7_SendCommand(0x20); //vcom
    260     for(count = 0; count < 44; count++) {
    261         EPD_2in7_SendData(EPD_2in7_lut_vcom_dc[count]);
    262     }
    263 
    264     EPD_2in7_SendCommand(0x21); //ww --
    265     for(count = 0; count < 42; count++) {
    266         EPD_2in7_SendData(EPD_2in7_lut_ww[count]);
    267     }
    268 
    269     EPD_2in7_SendCommand(0x22); //bw r
    270     for(count = 0; count < 42; count++) {
    271         EPD_2in7_SendData(EPD_2in7_lut_bw[count]);
    272     }
    273 
    274     EPD_2in7_SendCommand(0x23); //wb w
    275     for(count = 0; count < 42; count++) {
    276         EPD_2in7_SendData(EPD_2in7_lut_bb[count]);
    277     }
    278 
    279     EPD_2in7_SendCommand(0x24); //bb b
    280     for(count = 0; count < 42; count++) {
    281         EPD_2in7_SendData(EPD_2in7_lut_wb[count]);
    282     }
    283 }
    284 
    285 void EPD_2in7_gray_SetLut(void)
    286 {
    287     unsigned int count;
    288     EPD_2in7_SendCommand(0x20);							//vcom
    289     for(count=0; count<44; count++) {
    290         EPD_2in7_SendData(EPD_2in7_gray_lut_vcom[count]);
    291     }
    292 
    293     EPD_2in7_SendCommand(0x21);							//red not use
    294     for(count=0; count<42; count++) {
    295         EPD_2in7_SendData(EPD_2in7_gray_lut_ww[count]);
    296     }
    297 
    298     EPD_2in7_SendCommand(0x22);							//bw r
    299     for(count=0; count<42; count++) {
    300         EPD_2in7_SendData(EPD_2in7_gray_lut_bw[count]);
    301     }
    302 
    303     EPD_2in7_SendCommand(0x23);							//wb w
    304     for(count=0; count<42; count++) {
    305         EPD_2in7_SendData(EPD_2in7_gray_lut_wb[count]);
    306     }
    307 
    308     EPD_2in7_SendCommand(0x24);							//bb b
    309     for(count=0; count<42; count++) {
    310         EPD_2in7_SendData(EPD_2in7_gray_lut_bb[count]);
    311     }
    312 
    313     EPD_2in7_SendCommand(0x25);							//vcom
    314     for(count=0; count<42; count++) {
    315         EPD_2in7_SendData(EPD_2in7_gray_lut_ww[count]);
    316     }
    317 
    318 }
    319 
    320 /******************************************************************************
    321 function :	Initialize the e-Paper register
    322 parameter:
    323 ******************************************************************************/
    324 void EPD_2IN7_Init(void)
    325 {
    326     EPD_2in7_Reset();
    327 
    328     EPD_2in7_SendCommand(0x01); // POWER_SETTING
    329     EPD_2in7_SendData(0x03); // VDS_EN, VDG_EN
    330     EPD_2in7_SendData(0x00); // VCOM_HV, VGHL_LV[1], VGHL_LV[0]
    331     EPD_2in7_SendData(0x2b); // VDH
    332     EPD_2in7_SendData(0x2b); // VDL
    333     EPD_2in7_SendData(0x09); // VDHR
    334 
    335     EPD_2in7_SendCommand(0x06);  // BOOSTER_SOFT_START
    336     EPD_2in7_SendData(0x07);
    337     EPD_2in7_SendData(0x07);
    338     EPD_2in7_SendData(0x17);
    339 
    340     // Power optimization
    341     EPD_2in7_SendCommand(0xF8);
    342     EPD_2in7_SendData(0x60);
    343     EPD_2in7_SendData(0xA5);
    344 
    345     // Power optimization
    346     EPD_2in7_SendCommand(0xF8);
    347     EPD_2in7_SendData(0x89);
    348     EPD_2in7_SendData(0xA5);
    349 
    350     // Power optimization
    351     EPD_2in7_SendCommand(0xF8);
    352     EPD_2in7_SendData(0x90);
    353     EPD_2in7_SendData(0x00);
    354 
    355     // Power optimization
    356     EPD_2in7_SendCommand(0xF8);
    357     EPD_2in7_SendData(0x93);
    358     EPD_2in7_SendData(0x2A);
    359 
    360     // Power optimization
    361     EPD_2in7_SendCommand(0xF8);
    362     EPD_2in7_SendData(0xA0);
    363     EPD_2in7_SendData(0xA5);
    364 
    365     // Power optimization
    366     EPD_2in7_SendCommand(0xF8);
    367     EPD_2in7_SendData(0xA1);
    368     EPD_2in7_SendData(0x00);
    369 
    370     // Power optimization
    371     EPD_2in7_SendCommand(0xF8);
    372     EPD_2in7_SendData(0x73);
    373     EPD_2in7_SendData(0x41);
    374 
    375     EPD_2in7_SendCommand(0x16); // PARTIAL_DISPLAY_REFRESH
    376     EPD_2in7_SendData(0x00);
    377 
    378     EPD_2in7_SendCommand(0x04); // POWER_ON
    379     EPD_2in7_ReadBusy();
    380 
    381     EPD_2in7_SendCommand(0x00); // PANEL_SETTING
    382     EPD_2in7_SendData(0xAF); // KW-BF   KWR-AF    BWROTP 0f
    383     EPD_2in7_SendCommand(0x30); // PLL_CONTROL
    384     EPD_2in7_SendData(0x3A); // 3A 100HZ   29 150Hz 39 200HZ    31 171HZ
    385     EPD_2in7_SendCommand(0x82);  // VCM_DC_SETTING_REGISTER
    386     EPD_2in7_SendData(0x12);
    387 
    388     EPD_2in7_SetLut();
    389 }
    390 
    391 void EPD_2IN7_Init_4Gray(void)
    392 {
    393     EPD_2in7_Reset();
    394     EPD_2in7_SendCommand(0x01);			//POWER SETTING
    395     EPD_2in7_SendData (0x03);
    396     EPD_2in7_SendData (0x00);
    397     EPD_2in7_SendData (0x2b);
    398     EPD_2in7_SendData (0x2b);
    399 
    400 
    401     EPD_2in7_SendCommand(0x06);         //booster soft start
    402     EPD_2in7_SendData (0x07);		//A
    403     EPD_2in7_SendData (0x07);		//B
    404     EPD_2in7_SendData (0x17);		//C
    405 
    406     EPD_2in7_SendCommand(0xF8);         //boost??
    407     EPD_2in7_SendData (0x60);
    408     EPD_2in7_SendData (0xA5);
    409 
    410     EPD_2in7_SendCommand(0xF8);         //boost??
    411     EPD_2in7_SendData (0x89);
    412     EPD_2in7_SendData (0xA5);
    413 
    414     EPD_2in7_SendCommand(0xF8);         //boost??
    415     EPD_2in7_SendData (0x90);
    416     EPD_2in7_SendData (0x00);
    417 
    418     EPD_2in7_SendCommand(0xF8);         //boost??
    419     EPD_2in7_SendData (0x93);
    420     EPD_2in7_SendData (0x2A);
    421 
    422     EPD_2in7_SendCommand(0xF8);         //boost??
    423     EPD_2in7_SendData (0xa0);
    424     EPD_2in7_SendData (0xa5);
    425 
    426     EPD_2in7_SendCommand(0xF8);         //boost??
    427     EPD_2in7_SendData (0xa1);
    428     EPD_2in7_SendData (0x00);
    429 
    430     EPD_2in7_SendCommand(0xF8);         //boost??
    431     EPD_2in7_SendData (0x73);
    432     EPD_2in7_SendData (0x41);
    433 
    434     EPD_2in7_SendCommand(0x16);
    435     EPD_2in7_SendData(0x00);
    436 
    437     EPD_2in7_SendCommand(0x04);
    438     EPD_2in7_ReadBusy();
    439 
    440     EPD_2in7_SendCommand(0x00);			//panel setting
    441     EPD_2in7_SendData(0xbf);		//KW-BF   KWR-AF	BWROTP 0f
    442 
    443     EPD_2in7_SendCommand(0x30);			//PLL setting
    444     EPD_2in7_SendData (0x90);      	//100hz
    445 
    446     EPD_2in7_SendCommand(0x61);			//resolution setting
    447     EPD_2in7_SendData (0x00);		//176
    448     EPD_2in7_SendData (0xb0);
    449     EPD_2in7_SendData (0x01);		//264
    450     EPD_2in7_SendData (0x08);
    451 
    452     EPD_2in7_SendCommand(0x82);			//vcom_DC setting
    453     EPD_2in7_SendData (0x12);
    454 
    455     EPD_2in7_SendCommand(0X50);			//VCOM AND DATA INTERVAL SETTING
    456     EPD_2in7_SendData(0x97);
    457 }
    458 
    459 /******************************************************************************
    460 function :	Clear screen
    461 parameter:
    462 ******************************************************************************/
    463 void EPD_2IN7_Clear(void)
    464 {
    465     UWORD Width, Height;
    466     Width = (EPD_2IN7_WIDTH % 8 == 0)? (EPD_2IN7_WIDTH / 8 ): (EPD_2IN7_WIDTH / 8 + 1);
    467     Height = EPD_2IN7_HEIGHT;
    468 
    469 /*    EPD_2in7_SendCommand(0x10);
    470     for (UWORD j = 0; j < Height; j++) {
    471         for (UWORD i = 0; i < Width; i++) {
    472             EPD_2in7_SendData(0XFF);
    473         }
    474     }
    475 */
    476     EPD_2in7_SendCommand(0x13);
    477     for (UWORD j = 0; j < Height; j++) {
    478         for (UWORD i = 0; i < Width; i++) {
    479             EPD_2in7_SendData(0XFF);
    480         }
    481     }
    482 
    483     EPD_2in7_SendCommand(0x12);
    484     EPD_2in7_ReadBusy();
    485 }
    486 
    487 /******************************************************************************
    488 function :	Sends the image buffer in RAM to e-Paper and displays
    489 parameter:
    490 ******************************************************************************/
    491 void EPD_2IN7_Display(const UBYTE *Image)
    492 {
    493     UWORD Width, Height;
    494     Width = (EPD_2IN7_WIDTH % 8 == 0)? (EPD_2IN7_WIDTH / 8 ): (EPD_2IN7_WIDTH / 8 + 1);
    495     Height = EPD_2IN7_HEIGHT;
    496 
    497   /*  EPD_2in7_SendCommand(0x10);
    498     for (UWORD j = 0; j < Height; j++) {
    499        for (UWORD i = 0; i < Width; i++) {
    500            EPD_2in7_SendData(0XFF);
    501        }
    502     }
    503 */
    504     EPD_2in7_SendCommand(0x13);
    505     for (UWORD j = 0; j < Height; j++) {
    506         for (UWORD i = 0; i < Width; i++) {
    507             EPD_2in7_SendData(Image[i + j * Width]);
    508         }
    509     }
    510     EPD_2in7_SendCommand(0x12);
    511     EPD_2in7_ReadBusy();
    512 }
    513 
    514 void EPD_2IN7_4GrayDisplay(const UBYTE *Image)
    515 {
    516     UDOUBLE i,j,k;
    517     UBYTE temp1,temp2,temp3;
    518 
    519     // old  data
    520     EPD_2in7_SendCommand(0x10);
    521     for(i=0; i<5808; i++) {             //5808*4  46464
    522         temp3=0;
    523         for(j=0; j<2; j++) {
    524             temp1 = Image[i*2+j];
    525             for(k=0; k<2; k++) {
    526                 temp2 = temp1&0xC0;
    527                 if(temp2 == 0xC0)
    528                     temp3 |= 0x01;//white
    529                 else if(temp2 == 0x00)
    530                     temp3 |= 0x00;  //black
    531                 else if(temp2 == 0x80)
    532                     temp3 |= 0x01;  //gray1
    533                 else //0x40
    534                     temp3 |= 0x00; //gray2
    535                 temp3 <<= 1;
    536 
    537                 temp1 <<= 2;
    538                 temp2 = temp1&0xC0 ;
    539                 if(temp2 == 0xC0)  //white
    540                     temp3 |= 0x01;
    541                 else if(temp2 == 0x00) //black
    542                     temp3 |= 0x00;
    543                 else if(temp2 == 0x80)
    544                     temp3 |= 0x01; //gray1
    545                 else    //0x40
    546                     temp3 |= 0x00;	//gray2
    547                 if(j!=1 || k!=1)
    548                     temp3 <<= 1;
    549 
    550                 temp1 <<= 2;
    551             }
    552 
    553         }
    554         EPD_2in7_SendData(temp3);
    555     }
    556     // new  data
    557     EPD_2in7_SendCommand(0x13);
    558     for(i=0; i<5808; i++) {             //5808*4  46464
    559         temp3=0;
    560         for(j=0; j<2; j++) {
    561             temp1 = Image[i*2+j];
    562             for(k=0; k<2; k++) {
    563                 temp2 = temp1&0xC0 ;
    564                 if(temp2 == 0xC0)
    565                     temp3 |= 0x01;//white
    566                 else if(temp2 == 0x00)
    567                     temp3 |= 0x00;  //black
    568                 else if(temp2 == 0x80)
    569                     temp3 |= 0x00;  //gray1
    570                 else //0x40
    571                     temp3 |= 0x01; //gray2
    572                 temp3 <<= 1;
    573 
    574                 temp1 <<= 2;
    575                 temp2 = temp1&0xC0 ;
    576                 if(temp2 == 0xC0)  //white
    577                     temp3 |= 0x01;
    578                 else if(temp2 == 0x00) //black
    579                     temp3 |= 0x00;
    580                 else if(temp2 == 0x80)
    581                     temp3 |= 0x00; //gray1
    582                 else    //0x40
    583                     temp3 |= 0x01;	//gray2
    584                 if(j!=1 || k!=1)
    585                     temp3 <<= 1;
    586 
    587                 temp1 <<= 2;
    588             }
    589         }
    590         EPD_2in7_SendData(temp3);
    591     }
    592 
    593     EPD_2in7_gray_SetLut();
    594     EPD_2in7_SendCommand(0x12);
    595     DEV_Delay_ms(200);
    596     EPD_2in7_ReadBusy();
    597 }
    598 
    599 
    600 /******************************************************************************
    601 function :	Enter sleep mode
    602 parameter:
    603 ******************************************************************************/
    604 void EPD_2IN7_Sleep(void)
    605 {
    606     EPD_2in7_SendCommand(0X50);
    607     EPD_2in7_SendData(0xf7);
    608     EPD_2in7_SendCommand(0X02);  	//power off
    609     EPD_2in7_SendCommand(0X07);  	//deep sleep
    610     EPD_2in7_SendData(0xA5);
    611 }