epd7in3f.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*****************************************************************************
  2. * | File : EPD_7in3f.c
  3. * | Author : Waveshare team
  4. * | Function : 7.3inch e-Paper (F)
  5. * | Info :
  6. *----------------
  7. * | This version: V1.0
  8. * | Date : 2022-10-21
  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 <stdlib.h>
  32. #include "epd7in3f.h"
  33. #include "imagedata.h"
  34. Epd::~Epd() {
  35. };
  36. Epd::Epd() {
  37. reset_pin = RST_PIN;
  38. dc_pin = DC_PIN;
  39. cs_pin = CS_PIN;
  40. busy_pin = BUSY_PIN;
  41. width = EPD_WIDTH;
  42. height = EPD_HEIGHT;
  43. };
  44. /******************************************************************************
  45. function : Initialize the e-Paper register
  46. parameter:
  47. ******************************************************************************/
  48. int Epd::Init(void) {
  49. if (IfInit() != 0) {
  50. return -1;
  51. }
  52. Reset();
  53. DelayMs(20);
  54. EPD_7IN3F_BusyHigh();
  55. SendCommand(0xAA); // CMDH
  56. SendData(0x49);
  57. SendData(0x55);
  58. SendData(0x20);
  59. SendData(0x08);
  60. SendData(0x09);
  61. SendData(0x18);
  62. SendCommand(0x01);
  63. SendData(0x3F);
  64. SendData(0x00);
  65. SendData(0x32);
  66. SendData(0x2A);
  67. SendData(0x0E);
  68. SendData(0x2A);
  69. SendCommand(0x00);
  70. SendData(0x5F);
  71. SendData(0x69);
  72. SendCommand(0x03);
  73. SendData(0x00);
  74. SendData(0x54);
  75. SendData(0x00);
  76. SendData(0x44);
  77. SendCommand(0x05);
  78. SendData(0x40);
  79. SendData(0x1F);
  80. SendData(0x1F);
  81. SendData(0x2C);
  82. SendCommand(0x06);
  83. SendData(0x6F);
  84. SendData(0x1F);
  85. SendData(0x1F);
  86. SendData(0x22);
  87. SendCommand(0x08);
  88. SendData(0x6F);
  89. SendData(0x1F);
  90. SendData(0x1F);
  91. SendData(0x22);
  92. SendCommand(0x13); // IPC
  93. SendData(0x00);
  94. SendData(0x04);
  95. SendCommand(0x30);
  96. SendData(0x3C);
  97. SendCommand(0x41); // TSE
  98. SendData(0x00);
  99. SendCommand(0x50);
  100. SendData(0x3F);
  101. SendCommand(0x60);
  102. SendData(0x02);
  103. SendData(0x00);
  104. SendCommand(0x61);
  105. SendData(0x03);
  106. SendData(0x20);
  107. SendData(0x01);
  108. SendData(0xE0);
  109. SendCommand(0x82);
  110. SendData(0x1E);
  111. SendCommand(0x84);
  112. SendData(0x00);
  113. SendCommand(0x86); // AGID
  114. SendData(0x00);
  115. SendCommand(0xE3);
  116. SendData(0x2F);
  117. SendCommand(0xE0); // CCSET
  118. SendData(0x00);
  119. SendCommand(0xE6); // TSSET
  120. SendData(0x00);
  121. return 0;
  122. }
  123. /**
  124. * @brief: basic function for sending commands
  125. */
  126. void Epd::SendCommand(unsigned char command) {
  127. DigitalWrite(dc_pin, LOW);
  128. SpiTransfer(command);
  129. }
  130. /**
  131. * @brief: basic function for sending data
  132. */
  133. void Epd::SendData(unsigned char data) {
  134. DigitalWrite(dc_pin, HIGH);
  135. SpiTransfer(data);
  136. }
  137. void Epd::EPD_7IN3F_BusyHigh(void)// If BUSYN=0 then waiting
  138. {
  139. while(!DigitalRead(BUSY_PIN)) {
  140. DelayMs(1);
  141. }
  142. }
  143. /**
  144. * @brief: module reset.
  145. * often used to awaken the module in deep sleep,
  146. * see Epd::Sleep();
  147. */
  148. void Epd::Reset(void) {
  149. DigitalWrite(reset_pin, HIGH);
  150. DelayMs(20);
  151. DigitalWrite(reset_pin, LOW); //module reset
  152. DelayMs(1);
  153. DigitalWrite(reset_pin, HIGH);
  154. DelayMs(20);
  155. }
  156. void Epd::TurnOnDisplay(void) {
  157. SendCommand(0x04); // POWER_ON
  158. EPD_7IN3F_BusyHigh();
  159. SendCommand(0x12); // DISPLAY_REFRESH
  160. SendData(0x00);
  161. EPD_7IN3F_BusyHigh();
  162. SendCommand(0x02); // POWER_OFF
  163. SendData(0x00);
  164. EPD_7IN3F_BusyHigh();
  165. }
  166. /******************************************************************************
  167. function : Sends the image buffer in RAM to e-Paper and displays
  168. parameter:
  169. ******************************************************************************/
  170. void Epd::EPD_7IN3F_Display(const UBYTE *image) {
  171. unsigned long i,j;
  172. SendCommand(0x10);
  173. for(i=0; i<height; i++) {
  174. for(j=0; j<width/2; j++) {
  175. SendData(image[j + width*i]);
  176. }
  177. }
  178. TurnOnDisplay();
  179. }
  180. /******************************************************************************
  181. function : Sends the part image buffer in RAM to e-Paper and displays
  182. parameter:
  183. ******************************************************************************/
  184. void Epd::EPD_7IN3F_Display_part(const UBYTE *image, UWORD xstart, UWORD ystart,
  185. UWORD image_width, UWORD image_heigh)
  186. {
  187. unsigned long i,j;
  188. SendCommand(0x10);
  189. for(i=0; i<height; i++) {
  190. for(j=0; j< width/2; j++) {
  191. if(i<image_heigh+ystart && i>=ystart && j<(image_width+xstart)/2 && j>=xstart/2) {
  192. SendData(pgm_read_byte(&image[(j-xstart/2) + (image_width/2*(i-ystart))]));
  193. }
  194. else {
  195. SendData(0x11);
  196. }
  197. }
  198. }
  199. TurnOnDisplay();
  200. }
  201. /******************************************************************************
  202. function : show 7 kind of color block
  203. parameter:
  204. ******************************************************************************/
  205. void Epd::EPD_7IN3F_Show7Block(void)
  206. {
  207. unsigned long i, j, k;
  208. unsigned char const Color_seven[8] =
  209. {EPD_7IN3F_BLACK, EPD_7IN3F_BLUE, EPD_7IN3F_GREEN, EPD_7IN3F_ORANGE,
  210. EPD_7IN3F_RED, EPD_7IN3F_YELLOW, EPD_7IN3F_WHITE, EPD_7IN3F_WHITE};
  211. SendCommand(0x10);
  212. for(i=0; i<240; i++) {
  213. for(k = 0 ; k < 4; k ++) {
  214. for(j = 0 ; j < 100; j ++) {
  215. SendData((Color_seven[k]<<4) |Color_seven[k]);
  216. }
  217. }
  218. }
  219. for(i=0; i<240; i++) {
  220. for(k = 4 ; k < 8; k ++) {
  221. for(j = 0 ; j < 100; j ++) {
  222. SendData((Color_seven[k]<<4) |Color_seven[k]);
  223. }
  224. }
  225. }
  226. TurnOnDisplay();
  227. }
  228. /******************************************************************************
  229. function :
  230. Clear screen
  231. ******************************************************************************/
  232. void Epd::Clear(UBYTE color) {
  233. SendCommand(0x10);
  234. for(int i=0; i<width/2; i++) {
  235. for(int j=0; j<height; j++) {
  236. SendData((color<<4)|color);
  237. }
  238. }
  239. TurnOnDisplay();
  240. }
  241. /**
  242. * @brief: After this command is transmitted, the chip would enter the
  243. * deep-sleep mode to save power.
  244. * The deep sleep mode would return to standby by hardware reset.
  245. * The only one parameter is a check code, the command would be
  246. * You can use EPD_Reset() to awaken
  247. */
  248. void Epd::Sleep(void) {
  249. SendCommand(0x07);
  250. SendData(0xA5);
  251. DelayMs(10);
  252. DigitalWrite(RST_PIN, 0); // Reset
  253. }
  254. /* END OF FILE */