EPD_2in9b_V2.c (6553B)
1 /***************************************************************************** 2 * | File : EPD_2in9b_V2.c 3 * | Author : Waveshare team 4 * | Function : 2.9inch e-paper b V2 5 * | Info : 6 *---------------- 7 * | This version: V1.0 8 * | Date : 2020-04-12 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_2in9b_V2.h" 32 #include "Debug.h" 33 34 /****************************************************************************** 35 function : Software reset 36 parameter: 37 ******************************************************************************/ 38 static void EPD_2IN9B_V2_Reset(void) 39 { 40 DEV_Digital_Write(EPD_RST_PIN, 1); 41 DEV_Delay_ms(200); 42 DEV_Digital_Write(EPD_RST_PIN, 0); 43 DEV_Delay_ms(10); 44 DEV_Digital_Write(EPD_RST_PIN, 1); 45 DEV_Delay_ms(200); 46 } 47 48 /****************************************************************************** 49 function : send command 50 parameter: 51 Reg : Command register 52 ******************************************************************************/ 53 static void EPD_2IN9B_V2_SendCommand(UBYTE Reg) 54 { 55 DEV_Digital_Write(EPD_DC_PIN, 0); 56 DEV_Digital_Write(EPD_CS_PIN, 0); 57 DEV_SPI_WriteByte(Reg); 58 DEV_Digital_Write(EPD_CS_PIN, 1); 59 } 60 61 /****************************************************************************** 62 function : send data 63 parameter: 64 Data : Write data 65 ******************************************************************************/ 66 static void EPD_2IN9B_V2_SendData(UBYTE Data) 67 { 68 DEV_Digital_Write(EPD_DC_PIN, 1); 69 DEV_Digital_Write(EPD_CS_PIN, 0); 70 DEV_SPI_WriteByte(Data); 71 DEV_Digital_Write(EPD_CS_PIN, 1); 72 } 73 74 /****************************************************************************** 75 function : Wait until the busy_pin goes LOW 76 parameter: 77 ******************************************************************************/ 78 void EPD_2IN9B_V2_ReadBusy(void) 79 { 80 Debug("e-Paper busy\r\n"); 81 UBYTE busy; 82 do 83 { 84 EPD_2IN9B_V2_SendCommand(0x71); 85 busy = DEV_Digital_Read(EPD_BUSY_PIN); 86 busy =!(busy & 0x01); 87 } 88 while(busy); 89 Debug("e-Paper busy release\r\n"); 90 DEV_Delay_ms(200); 91 } 92 93 /****************************************************************************** 94 function : Initialize the e-Paper register 95 parameter: 96 ******************************************************************************/ 97 void EPD_2IN9B_V2_Init(void) 98 { 99 EPD_2IN9B_V2_Reset(); 100 101 EPD_2IN9B_V2_SendCommand(0x04); 102 EPD_2IN9B_V2_ReadBusy();//waiting for the electronic paper IC to release the idle signal 103 104 EPD_2IN9B_V2_SendCommand(0x00);//panel setting 105 EPD_2IN9B_V2_SendData(0x0f);//LUT from OTP,128x296 106 EPD_2IN9B_V2_SendData(0x89);//Temperature sensor, boost and other related timing settings 107 108 EPD_2IN9B_V2_SendCommand(0x61);//resolution setting 109 EPD_2IN9B_V2_SendData (0x80); 110 EPD_2IN9B_V2_SendData (0x01); 111 EPD_2IN9B_V2_SendData (0x28); 112 113 EPD_2IN9B_V2_SendCommand(0X50);//VCOM AND DATA INTERVAL SETTING 114 EPD_2IN9B_V2_SendData(0x77);//WBmode:VBDF 17|D7 VBDW 97 VBDB 57 115 //WBRmode:VBDF F7 VBDW 77 VBDB 37 VBDR B7 116 } 117 118 /****************************************************************************** 119 function : Clear screen 120 parameter: 121 ******************************************************************************/ 122 void EPD_2IN9B_V2_Clear(void) 123 { 124 UWORD Width = (EPD_2IN9B_V2_WIDTH % 8 == 0)? (EPD_2IN9B_V2_WIDTH / 8 ): (EPD_2IN9B_V2_WIDTH / 8 + 1); 125 UWORD Height = EPD_2IN9B_V2_HEIGHT; 126 127 //send black data 128 EPD_2IN9B_V2_SendCommand(0x10); 129 for (UWORD j = 0; j < Height; j++) { 130 for (UWORD i = 0; i < Width; i++) { 131 EPD_2IN9B_V2_SendData(0xFF); 132 } 133 } 134 135 //send red data 136 EPD_2IN9B_V2_SendCommand(0x13); 137 for (UWORD j = 0; j < Height; j++) { 138 for (UWORD i = 0; i < Width; i++) { 139 EPD_2IN9B_V2_SendData(0xFF); 140 } 141 } 142 143 EPD_2IN9B_V2_SendCommand(0x12); 144 EPD_2IN9B_V2_ReadBusy(); 145 } 146 147 /****************************************************************************** 148 function : Sends the image buffer in RAM to e-Paper and displays 149 parameter: 150 ******************************************************************************/ 151 void EPD_2IN9B_V2_Display(const UBYTE *blackimage, const UBYTE *ryimage) 152 { 153 UWORD Width, Height; 154 Width = (EPD_2IN9B_V2_WIDTH % 8 == 0)? (EPD_2IN9B_V2_WIDTH / 8 ): (EPD_2IN9B_V2_WIDTH / 8 + 1); 155 Height = EPD_2IN9B_V2_HEIGHT; 156 157 EPD_2IN9B_V2_SendCommand(0x10); 158 for (UWORD j = 0; j < Height; j++) { 159 for (UWORD i = 0; i < Width; i++) { 160 EPD_2IN9B_V2_SendData(blackimage[i + j * Width]); 161 } 162 } 163 EPD_2IN9B_V2_SendCommand(0x92); 164 165 EPD_2IN9B_V2_SendCommand(0x13); 166 for (UWORD j = 0; j < Height; j++) { 167 for (UWORD i = 0; i < Width; i++) { 168 EPD_2IN9B_V2_SendData(ryimage[i + j * Width]); 169 } 170 } 171 EPD_2IN9B_V2_SendCommand(0x92); 172 173 EPD_2IN9B_V2_SendCommand(0x12); 174 EPD_2IN9B_V2_ReadBusy(); 175 } 176 177 /****************************************************************************** 178 function : Enter sleep mode 179 parameter: 180 ******************************************************************************/ 181 void EPD_2IN9B_V2_Sleep(void) 182 { 183 EPD_2IN9B_V2_SendCommand(0x02); // POWER_OFF 184 EPD_2IN9B_V2_ReadBusy(); 185 EPD_2IN9B_V2_SendCommand(0x07); // DEEP_SLEEP 186 EPD_2IN9B_V2_SendData(0xA5); // check code 187 }