Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: ePD_2R13inch_test_program
epd2in13c.cpp
00001 /** 00002 * @filename : epd2in9b.cpp 00003 * @brief : Implements for Dual-color e-paper library 00004 * @author : Yehui from Waveshare 00005 * 00006 * Copyright (C) Waveshare August 10 2017 00007 * 00008 * Permission is hereby granted, free of charge, to any person obtaining a copy 00009 * of this software and associated documnetation files (the "Software"), to deal 00010 * in the Software without restriction, including without limitation the rights 00011 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00012 * copies of the Software, and to permit persons to whom the Software is 00013 * furished to do so, subject to the following conditions: 00014 * 00015 * The above copyright notice and this permission notice shall be included in 00016 * all copies or substantial portions of the Software. 00017 * 00018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00019 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00020 * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00021 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00022 * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00023 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00024 * THE SOFTWARE. 00025 */ 00026 00027 /* 00028 * Modified by Kenji Arai / JH1PJL 00029 * 00030 * http://www.page.sannet.ne.jp/kenjia/index.html 00031 * http://mbed.org/users/kenjiArai/ 00032 * Created: April 27th, 2019 00033 * Revised: April 30th, 2019 00034 * 00035 * Refrence software 00036 * https://github.com/waveshare/e-Paper 00037 * https://os.mbed.com/users/imachooon/code/epd1in54/ 00038 * 00039 * Technical documents 00040 * https://www.waveshare.com/wiki/2.13inch_e-Paper_HAT_(B) 00041 * 00042 * Product 00043 * http://akizukidenshi.com/catalog/g/gP-13757/ 00044 * https://www.waveshare.com/2.13inch-e-paper-hat-b.htm 00045 * 00046 */ 00047 00048 #include "epd2in13c.h" 00049 00050 Epd::Epd(PinName mosi, 00051 PinName miso, 00052 PinName sclk, 00053 PinName cs, 00054 PinName dc, 00055 PinName rst, 00056 PinName busy, 00057 PinName pwr 00058 ):EpdIf(mosi, miso, sclk, cs, dc, rst, busy, pwr) 00059 { 00060 width = EPD_WIDTH; 00061 height = EPD_HEIGHT; 00062 }; 00063 00064 int Epd::Init(void) 00065 { 00066 /* this calls the peripheral hardware interface, see epdif */ 00067 if (IfInit() != 0) { 00068 return -1; 00069 } 00070 /* EPD hardware init start */ 00071 Reset(); 00072 SendCommand(BOOSTER_SOFT_START); 00073 SendData(0x17); 00074 SendData(0x17); 00075 SendData(0x17); 00076 SendCommand(POWER_ON); 00077 WaitUntilIdle(); 00078 SendCommand(PANEL_SETTING); 00079 SendData(0x8F); 00080 SendCommand(VCOM_AND_DATA_INTERVAL_SETTING); 00081 SendData(0x37); 00082 SendCommand(RESOLUTION_SETTING); 00083 SendData(0x68); // width: 104 00084 SendData(0x00); 00085 SendData(0xD4); // height: 212 00086 /* EPD hardware init end */ 00087 return 0; 00088 } 00089 00090 /** 00091 * @brief: basic function for sending commands 00092 */ 00093 void Epd::SendCommand(unsigned char command) 00094 { 00095 DigitalWrite(m_dc, LOW); 00096 SpiTransfer(command); 00097 } 00098 00099 /** 00100 * @brief: basic function for sending data 00101 */ 00102 void Epd::SendData(unsigned char data) 00103 { 00104 DigitalWrite(m_dc, HIGH); 00105 SpiTransfer(data); 00106 } 00107 00108 /** 00109 * @brief: Wait until the busy_pin goes HIGH 00110 */ 00111 void Epd::WaitUntilIdle(void) 00112 { 00113 while(DigitalRead(m_busy) == 0) { //0: busy, 1: idle 00114 DelayMs(100); 00115 } 00116 } 00117 00118 /** 00119 * @brief: module reset. 00120 * often used to awaken the module in deep sleep, 00121 * see Epd::Sleep(); 00122 */ 00123 void Epd::Reset(void) 00124 { 00125 DigitalWrite(m_rst, LOW); 00126 DelayMs(200); 00127 DigitalWrite(m_rst, HIGH); 00128 DelayMs(200); 00129 } 00130 00131 /** 00132 * @brief: transmit partial data to the SRAM 00133 */ 00134 void Epd::SetPartialWindow(const unsigned char* buffer_black, const unsigned char* buffer_yellow, int x, int y, int w, int l) 00135 { 00136 SendCommand(PARTIAL_IN); 00137 SendCommand(PARTIAL_WINDOW); 00138 SendData(x & 0xf8); // x should be the multiple of 8, the last 3 bit will always be ignored 00139 SendData(((x & 0xf8) + w - 1) | 0x07); 00140 SendData(y >> 8); 00141 SendData(y & 0xff); 00142 SendData((y + l - 1) >> 8); 00143 SendData((y + l - 1) & 0xff); 00144 SendData(0x01); // Gates scan both inside and outside of the partial window. (default) 00145 DelayMs(2); 00146 SendCommand(DATA_START_TRANSMISSION_1); 00147 if (buffer_black != NULL) { 00148 for(int i = 0; i < w / 8 * l; i++) { 00149 SendData(buffer_black[i]); 00150 } 00151 } else { 00152 for(int i = 0; i < w / 8 * l; i++) { 00153 SendData(0x00); 00154 } 00155 } 00156 DelayMs(2); 00157 SendCommand(DATA_START_TRANSMISSION_2); 00158 if (buffer_yellow != NULL) { 00159 for(int i = 0; i < w / 8 * l; i++) { 00160 SendData(buffer_yellow[i]); 00161 } 00162 } else { 00163 for(int i = 0; i < w / 8 * l; i++) { 00164 SendData(0x00); 00165 } 00166 } 00167 DelayMs(2); 00168 SendCommand(PARTIAL_OUT); 00169 } 00170 00171 /** 00172 * @brief: transmit partial data to the black part of SRAM 00173 */ 00174 void Epd::SetPartialWindowBlack(const unsigned char* buffer_black, int x, int y, int w, int l) 00175 { 00176 SendCommand(PARTIAL_IN); 00177 SendCommand(PARTIAL_WINDOW); 00178 SendData(x & 0xf8); // x should be the multiple of 8, the last 3 bit will always be ignored 00179 SendData(((x & 0xf8) + w - 1) | 0x07); 00180 SendData(y >> 8); 00181 SendData(y & 0xff); 00182 SendData((y + l - 1) >> 8); 00183 SendData((y + l - 1) & 0xff); 00184 SendData(0x01); // Gates scan both inside and outside of the partial window. (default) 00185 DelayMs(2); 00186 SendCommand(DATA_START_TRANSMISSION_1); 00187 if (buffer_black != NULL) { 00188 for(int i = 0; i < w / 8 * l; i++) { 00189 SendData(buffer_black[i]); 00190 } 00191 } else { 00192 for(int i = 0; i < w / 8 * l; i++) { 00193 SendData(0x00); 00194 } 00195 } 00196 DelayMs(2); 00197 SendCommand(PARTIAL_OUT); 00198 } 00199 00200 /** 00201 * @brief: transmit partial data to the yellow part of SRAM 00202 */ 00203 void Epd::SetPartialWindowYellow(const unsigned char* buffer_yellow, int x, int y, int w, int l) 00204 { 00205 SendCommand(PARTIAL_IN); 00206 SendCommand(PARTIAL_WINDOW); 00207 SendData(x & 0xf8); // x should be the multiple of 8, the last 3 bit will always be ignored 00208 SendData(((x & 0xf8) + w - 1) | 0x07); 00209 SendData(y >> 8); 00210 SendData(y & 0xff); 00211 SendData((y + l - 1) >> 8); 00212 SendData((y + l - 1) & 0xff); 00213 SendData(0x01); // Gates scan both inside and outside of the partial window. (default) 00214 DelayMs(2); 00215 SendCommand(DATA_START_TRANSMISSION_2); 00216 if (buffer_yellow != NULL) { 00217 for(int i = 0; i < w / 8 * l; i++) { 00218 SendData(buffer_yellow[i]); 00219 } 00220 } else { 00221 for(int i = 0; i < w / 8 * l; i++) { 00222 SendData(0x00); 00223 } 00224 } 00225 DelayMs(2); 00226 SendCommand(PARTIAL_OUT); 00227 } 00228 00229 /** 00230 * @brief: refresh and displays the frame 00231 */ 00232 void Epd::DisplayFrame(const unsigned char* frame_buffer_black, const unsigned char* frame_buffer_yellow) 00233 { 00234 if (frame_buffer_black != NULL) { 00235 SendCommand(DATA_START_TRANSMISSION_1); 00236 DelayMs(2); 00237 for (int i = 0; i < this->width * this->height / 8; i++) { 00238 SendData(*(frame_buffer_black + i)); 00239 } 00240 DelayMs(2); 00241 } 00242 if (frame_buffer_yellow != NULL) { 00243 SendCommand(DATA_START_TRANSMISSION_2); 00244 DelayMs(2); 00245 for (int i = 0; i < this->width * this->height / 8; i++) { 00246 SendData(*(frame_buffer_yellow + i)); 00247 } 00248 DelayMs(2); 00249 } 00250 SendCommand(DISPLAY_REFRESH); 00251 WaitUntilIdle(); 00252 } 00253 00254 /** 00255 * @brief: clear the frame data from the SRAM, this won't refresh the display 00256 */ 00257 void Epd::ClearFrame(void) 00258 { 00259 SendCommand(DATA_START_TRANSMISSION_1); 00260 DelayMs(2); 00261 for(int i = 0; i < width * height / 8; i++) { 00262 SendData(0xFF); 00263 } 00264 DelayMs(2); 00265 SendCommand(DATA_START_TRANSMISSION_2); 00266 DelayMs(2); 00267 for(int i = 0; i < width * height / 8; i++) { 00268 SendData(0xFF); 00269 } 00270 DelayMs(2); 00271 } 00272 00273 /** 00274 * @brief: This displays the frame data from SRAM 00275 */ 00276 void Epd::DisplayFrame(void) 00277 { 00278 SendCommand(DISPLAY_REFRESH); 00279 WaitUntilIdle(); 00280 } 00281 00282 /** 00283 * @brief: After this command is transmitted, the chip would enter the deep-sleep mode to save power. 00284 * The deep sleep mode would return to standby by hardware reset. The only one parameter is a 00285 * check code, the command would be executed if check code = 0xA5. 00286 * You can use Epd::Reset() to awaken and use Epd::Init() to initialize. 00287 */ 00288 void Epd::Sleep() 00289 { 00290 SendCommand(POWER_OFF); 00291 WaitUntilIdle(); 00292 SendCommand(DEEP_SLEEP); 00293 SendData(0xA5); // check code 00294 } 00295 00296 /** 00297 * @brief: e-Paper power control 00298 */ 00299 void Epd::PwrOn() 00300 { 00301 DigitalWrite(m_pwr, 1); 00302 } 00303 00304 void Epd::PwrOff() 00305 { 00306 DigitalWrite(m_pwr, 0); 00307 } 00308 00309 /* END OF FILE */
Generated on Sat Jul 16 2022 10:11:16 by
1.7.2