epaper-29-ws.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. // Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef _IOT_E_PAPER_29_H_
  14. #define _IOT_E_PAPER_29_H_
  15. #ifdef __cplusplus
  16. extern "C"
  17. {
  18. #endif
  19. #include "driver/spi_master.h"
  20. // Display orientation
  21. typedef enum {
  22. E_PAPER_ROTATE_0,
  23. E_PAPER_ROTATE_90,
  24. E_PAPER_ROTATE_180,
  25. E_PAPER_ROTATE_270,
  26. } epaper_rotate_t;
  27. typedef struct
  28. {
  29. uint16_t width;
  30. uint16_t height;
  31. const uint8_t *font_table;
  32. } epaper_font_t;
  33. #define COLORED 0
  34. #define UNCOLORED 1
  35. // Display resolution
  36. #define EPD_WIDTH 128
  37. #define EPD_HEIGHT 296
  38. // Display CONTROLLER COMMANDS
  39. #define E_PAPER_DRIVER_OUTPUT_CONTROL 0x01
  40. #define E_PAPER_BOOSTER_SOFT_START_CONTROL 0x0C
  41. #define E_PAPER_GATE_SCAN_START_POSITION 0x0F
  42. #define E_PAPER_DEEP_SLEEP_MODE 0x10
  43. #define E_PAPER_DATA_ENTRY_MODE_SETTING 0x11
  44. #define E_PAPER_SW_RESET 0x12
  45. #define E_PAPER_TEMPERATURE_SENSOR_CONTROL 0x1A
  46. #define E_PAPER_MASTER_ACTIVATION 0x20
  47. #define E_PAPER_DISPLAY_UPDATE_CONTROL_1 0x21
  48. #define E_PAPER_DISPLAY_UPDATE_CONTROL_2 0x22
  49. #define E_PAPER_WRITE_RAM 0x24
  50. #define E_PAPER_WRITE_VCOM_REGISTER 0x2C
  51. #define E_PAPER_WRITE_LUT_REGISTER 0x32
  52. #define E_PAPER_SET_DUMMY_LINE_PERIOD 0x3A
  53. #define E_PAPER_SET_GATE_TIME 0x3B
  54. #define E_PAPER_BORDER_WAVEFORM_CONTROL 0x3C
  55. #define E_PAPER_SET_RAM_X_ADDRESS_START_END_POSITION 0x44
  56. #define E_PAPER_SET_RAM_Y_ADDRESS_START_END_POSITION 0x45
  57. #define E_PAPER_SET_RAM_X_ADDRESS_COUNTER 0x4E
  58. #define E_PAPER_SET_RAM_Y_ADDRESS_COUNTER 0x4F
  59. #define E_PAPER_TERMINATE_FRAME_READ_WRITE 0xFF
  60. /* Paint properties */
  61. typedef struct {
  62. unsigned char* image;
  63. epaper_rotate_t rotate;
  64. int width;
  65. int height;
  66. } epaper_paint_t;
  67. /* EPD properties */
  68. typedef struct {
  69. int reset_pin;
  70. int dc_pin;
  71. int cs_pin;
  72. int busy_pin;
  73. int mosi_pin;
  74. int miso_pin;
  75. int sck_pin;
  76. uint8_t rst_active_level;
  77. uint8_t busy_active_level;
  78. uint8_t dc_lev_data;
  79. uint8_t dc_lev_cmd;
  80. int clk_freq_hz;
  81. spi_host_device_t spi_host;
  82. int width;
  83. int height;
  84. bool color_inv;
  85. } epaper_conf_t;
  86. typedef void* epaper_handle_t; /*handle of epaper*/
  87. /**
  88. * @brief Create and init epaper and return a epaper handle
  89. *
  90. * @param bus handle of spi device
  91. * @param epconf configure struct for epaper device
  92. *
  93. * @return
  94. * - handle of epaper
  95. */
  96. epaper_handle_t iot_epaper_create(spi_device_handle_t bus, epaper_conf_t * epconf);
  97. /**
  98. * @brief delete epaper handle_t
  99. *
  100. * @param dev object handle of epaper
  101. * @param del_bus whether to delete spi bus
  102. *
  103. * @return
  104. * - ESP_OK Success
  105. * - ESP_FAIL Fail
  106. */
  107. esp_err_t iot_epaper_delete(epaper_handle_t dev, bool del_bus);
  108. /**
  109. * @brief clear display frame buffer
  110. *
  111. * @param dev object handle of epaper
  112. * @param colored to set display color
  113. */
  114. void iot_epaper_clean_paint(epaper_handle_t dev, int colored);
  115. /**
  116. * @brief get paint width
  117. *
  118. * @param dev object handle of epaper
  119. *
  120. * @return
  121. * - paint width
  122. */
  123. int iot_epaper_get_width(epaper_handle_t dev);
  124. /**
  125. * @brief set paint width
  126. * @param dev object handle of epaper
  127. * @param width paint width
  128. */
  129. void iot_epaper_set_width(epaper_handle_t dev, int width);
  130. /**
  131. * @brief get paint height
  132. * @param dev object handle of epaper
  133. * @return
  134. * - paint height
  135. */
  136. int iot_epaper_get_height(epaper_handle_t dev);
  137. /**
  138. * @brief set paint height
  139. * @param dev object handle of epaper
  140. * @param paint height
  141. */
  142. void iot_epaper_set_height(epaper_handle_t dev, int height);
  143. /**
  144. * @brief get paint rotate
  145. * @param dev object handle of epaper
  146. * @return
  147. * - current rotation
  148. */
  149. int iot_epaper_get_rotate(epaper_handle_t dev);
  150. /**
  151. * @brief set paint rotate
  152. * @param dev object handle of epaper
  153. * @param rotation
  154. */
  155. void iot_epaper_set_rotate(epaper_handle_t dev, int rotate);
  156. /**
  157. * @brief get display data
  158. * @param dev object handle of epaper
  159. * @return
  160. * - Pointer to display data
  161. */
  162. unsigned char* iot_epaper_get_image(epaper_handle_t dev);
  163. /**
  164. * @brief draw string start on point(x,y) and save on display data array,
  165. * screen will display when call iot_epaper_display_frame function.
  166. * @param dev object handle of epaper
  167. * @param x poing (x)
  168. * @param y poing (y)
  169. * @param text display string
  170. * @param font Font style
  171. * @param colored display color
  172. */
  173. void iot_epaper_draw_string(epaper_handle_t dev, int x, int y, const char* text,
  174. epaper_font_t* font, int colored);
  175. /**
  176. * @brief draw pixel and save on display data array,
  177. * screen will display when call iot_epaper_display_frame function.
  178. * @param dev object handle of epaper
  179. * @param x point (x)
  180. * @param y point (y)
  181. * @param colored display color
  182. */
  183. void iot_epaper_draw_pixel(epaper_handle_t dev, int x, int y, int colored);
  184. /**
  185. * @brief draw char and save on display data array,
  186. * screen will display when call iot_epaper_display_frame function.
  187. * @param dev object handle of epaper
  188. * @param x poing (x)
  189. * @param y poing (y)
  190. * @param ascii_char display char
  191. * @param font font style
  192. * @param colored display color
  193. */
  194. void iot_epaper_draw_char(epaper_handle_t dev, int x, int y, char ascii_char,
  195. epaper_font_t* font, int colored);
  196. /**
  197. * @brief draw line start on point(x0,y0) end on point(x1,y1) and save on display data array,
  198. * screen will display when call iot_epaper_display_frame function.
  199. *
  200. * @param dev object handle of epaper
  201. * @param x0 poing (x0)
  202. * @param y0 poing (y0)
  203. * @param x1 poing (x1)
  204. * @param y1 poing (y1)
  205. * @param colored display color
  206. */
  207. void iot_epaper_draw_line(epaper_handle_t dev, int x0, int y0, int x1, int y1,
  208. int colored);
  209. /**
  210. * @brief draw horizontal line start on point(x,y) and save on display data array,
  211. * screen will display when call iot_epaper_display_frame function.
  212. * @param dev object handle of epaper
  213. * @param x poing (x)
  214. * @param y poing (y)
  215. * @param width line width
  216. * @param colored display color
  217. */
  218. void iot_epaper_draw_horizontal_line(epaper_handle_t dev, int x, int y,
  219. int width, int colored);
  220. /**
  221. * @brief draw vertical line start on point(x,y) and save on display data array,
  222. * screen will display when call iot_epaper_display_frame function.
  223. *
  224. * @param dev object handle of epaper
  225. * @param x poing (x)
  226. * @param y poing (y)
  227. * @param line height
  228. * @param display color
  229. */
  230. void iot_epaper_draw_vertical_line(epaper_handle_t dev, int x, int y,
  231. int height, int colored);
  232. /**
  233. * @brief draw rectangle point(x0,y0) (x1,y1) and save on display data array,
  234. * screen will display when call iot_epaper_display_frame function.
  235. *
  236. * @param dev object handle of epaper
  237. * @param x0 point(x0,y0)
  238. * @param y0 point(x0,y0)
  239. * @param x1 point(x1,y1)
  240. * @param y1 point(x1,y1)
  241. * @param colored display color
  242. */
  243. void iot_epaper_draw_rectangle(epaper_handle_t dev, int x0, int y0, int x1,
  244. int y1, int colored);
  245. /**
  246. * @brief draw fill rectangle point(x0,y0) (x1,y1) and save on display data array,
  247. * screen will display when call iot_epaper_display_frame function.
  248. *
  249. * @param dev object handle of epaper
  250. * @param x0 point(x0,y0)
  251. * @param y0 point(x0,y0)
  252. * @param x1 point(x1,y1)
  253. * @param y1 point(x1,y1)
  254. * @param colored display color
  255. */
  256. void ior_epaper_draw_filled_rectangle(epaper_handle_t dev, int x0, int y0,
  257. int x1, int y1, int colored);
  258. /**
  259. * @brief draw a circle at point(x,y) and save on display data array,
  260. * screen will display when call iot_epaper_display_frame function.
  261. *
  262. * @param dev object handle of epaper
  263. * @param x point(x,y)
  264. * @param y point(x,y)
  265. * @param colored display color
  266. */
  267. void iot_epaper_draw_circle(epaper_handle_t dev, int x, int y, int radius,
  268. int colored);
  269. /**
  270. * @brief draw a fill circle at point(x,y) and save on display data array,
  271. * screen will display when call iot_epaper_display_frame function.
  272. *
  273. * @param dev object handle of epaper
  274. * @param x point(x,y)
  275. * @param y point(x,y)
  276. * @param radius radius of the circle
  277. * @param colored display color
  278. */
  279. void iot_epaper_draw_filled_circle(epaper_handle_t dev, int x, int y,
  280. int radius, int colored);
  281. /**
  282. * @brief wait until idle
  283. * @param dev object handle of epaper
  284. */
  285. void iot_epaper_wait_idle(epaper_handle_t dev);
  286. /**
  287. * @brief reset device
  288. *
  289. * @param dev object handle of epaper
  290. */
  291. void iot_epaper_reset(epaper_handle_t dev);
  292. /**
  293. * @brief dispaly frame, refresh screen
  294. *
  295. * @param dev object handle of epaper
  296. */
  297. void iot_epaper_display_frame(epaper_handle_t dev, const unsigned char* frame_buffer);
  298. /**
  299. * @brief After this command is transmitted, the chip would enter the deep-sleep mode to save power.
  300. * The deep sleep mode would return to standby by hardware reset. The only one parameter is a
  301. * check code, the command would be executed if check code = 0xA5.
  302. * You can use iot_epaper_reset() to awaken and EPD_Init() to initialize
  303. *
  304. * @param dev object handle of epaper
  305. */
  306. void iot_epaper_sleep(epaper_handle_t dev);
  307. #ifdef __cplusplus
  308. }
  309. #endif
  310. #endif //_IOT_E_PAPER_29_H_