You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

280 lines
7.8 KiB

3 years ago
  1. // Copyright 2020 Espressif Systems (Shanghai) Co. 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. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef _IOT_SCREEN_DRIVER_H_
  15. #define _IOT_SCREEN_DRIVER_H_
  16. #include "scr_interface_driver.h"
  17. #ifdef __cplusplus
  18. extern "C"
  19. {
  20. #endif
  21. /**
  22. * @brief Define all screen direction
  23. *
  24. */
  25. typedef enum
  26. {
  27. /* @---> X
  28. |
  29. Y
  30. */
  31. SCR_DIR_LRTB, /**< From left to right then from top to bottom, this consider as the original direction of the screen */
  32. /* Y
  33. |
  34. @---> X
  35. */
  36. SCR_DIR_LRBT, /**< From left to right then from bottom to top */
  37. /* X <---@
  38. |
  39. Y
  40. */
  41. SCR_DIR_RLTB, /**< From right to left then from top to bottom */
  42. /* Y
  43. |
  44. X <---@
  45. */
  46. SCR_DIR_RLBT, /**< From right to left then from bottom to top */
  47. /* @---> Y
  48. |
  49. X
  50. */
  51. SCR_DIR_TBLR, /**< From top to bottom then from left to right */
  52. /* X
  53. |
  54. @---> Y
  55. */
  56. SCR_DIR_BTLR, /**< From bottom to top then from left to right */
  57. /* Y <---@
  58. |
  59. X
  60. */
  61. SCR_DIR_TBRL, /**< From top to bottom then from right to left */
  62. /* X
  63. |
  64. Y <---@
  65. */
  66. SCR_DIR_BTRL, /**< From bottom to top then from right to left */
  67. SCR_DIR_MAX,
  68. /* Another way to represent rotation with 3 bit*/
  69. SCR_MIRROR_X = 0x40, /**< Mirror X-axis */
  70. SCR_MIRROR_Y = 0x20, /**< Mirror Y-axis */
  71. SCR_SWAP_XY = 0x80, /**< Swap XY axis */
  72. } scr_dir_t;
  73. /**
  74. * @brief The types of colors that can be displayed on the screen
  75. *
  76. */
  77. typedef enum
  78. {
  79. SCR_COLOR_TYPE_MONO, /**< The screen is monochrome */
  80. SCR_COLOR_TYPE_GRAY, /**< The screen is gray */
  81. SCR_COLOR_TYPE_RGB565, /**< The screen is colorful */
  82. } scr_color_type_t;
  83. /**
  84. * @brief All supported screen controllers
  85. *
  86. */
  87. typedef enum
  88. {
  89. /* color screen */
  90. SCREEN_CONTROLLER_ILI9341,
  91. SCREEN_CONTROLLER_ILI9806,
  92. SCREEN_CONTROLLER_ILI9486,
  93. SCREEN_CONTROLLER_ILI9488,
  94. SCREEN_CONTROLLER_NT35510,
  95. SCREEN_CONTROLLER_RM68120,
  96. SCREEN_CONTROLLER_ST7789,
  97. SCREEN_CONTROLLER_ST7796,
  98. SCREEN_CONTROLLER_SSD1351,
  99. SCREEN_CONTROLLER_SSD1963,
  100. /* monochrome screen */
  101. SCREEN_CONTROLLER_SSD1306,
  102. SCREEN_CONTROLLER_SSD1307,
  103. SCREEN_CONTROLLER_SSD1322,
  104. } scr_controller_t;
  105. /**
  106. * @brief configuration of screen controller
  107. *
  108. */
  109. typedef struct
  110. {
  111. scr_interface_driver_t *interface_drv; /*!< Interface driver for screen */
  112. int8_t pin_num_rst; /*!< Pin to hardreset LCD*/
  113. int8_t pin_num_bckl; /*!< Pin for control backlight */
  114. uint8_t rst_active_level; /*!< Reset pin active level */
  115. uint8_t bckl_active_level; /*!< Backlight active level */
  116. uint16_t width; /*!< Screen width */
  117. uint16_t height; /*!< Screen height */
  118. uint16_t offset_hor; /*!< Offset of horizontal */
  119. uint16_t offset_ver; /*!< Offset of vertical */
  120. scr_dir_t rotate; /*!< Screen rotate direction */
  121. } scr_controller_config_t;
  122. /**
  123. * @brief Information of screen
  124. *
  125. */
  126. typedef struct
  127. {
  128. uint16_t width; /*!< Current screen width, it may change when apply to rotate */
  129. uint16_t height; /*!< Current screen height, it may change when apply to rotate */
  130. scr_dir_t dir; /*!< Current screen direction */
  131. scr_color_type_t color_type; /*!< Color type of the screen, See scr_color_type_t struct */
  132. uint8_t bpp; /*!< Bits per pixel */
  133. const char *name; /*!< Name of the screen */
  134. } scr_info_t;
  135. /**
  136. * @brief Define a screen common function
  137. *
  138. */
  139. typedef struct
  140. {
  141. /**
  142. * @brief Initialize screen
  143. *
  144. * @param lcd_conf Pointer to a structure with lcd config arguments. see struct scr_controller_config_t
  145. *
  146. * @return
  147. * - ESP_OK on success
  148. * - ESP_FAIL Driver not installed
  149. */
  150. esp_err_t (*init)(const scr_controller_config_t *lcd_conf);
  151. /**
  152. * @brief Deinitialize screen
  153. *
  154. * @return
  155. * - ESP_OK on success
  156. * - ESP_FAIL Deinitialize failed
  157. * - ESP_ERR_NOT_SUPPORTED unsupported
  158. */
  159. esp_err_t (*deinit)(void);
  160. /**
  161. * @brief Set screen direction of rotation
  162. *
  163. * @param dir Pointer to a scr_dir_t structure.
  164. * You can set the direction in two ways, for example, set it to "SCR_DIR_LRBT" or "SCR_MIRROR_Y", They are the same, depending on which expression you want to use
  165. *
  166. * @note Not all screens support eight directions, it depends on the screen controller.
  167. *
  168. * @return
  169. * - ESP_OK on success
  170. * - ESP_FAIL Failed
  171. */
  172. esp_err_t (*set_direction)(scr_dir_t dir);
  173. /**
  174. * @brief Set screen window
  175. *
  176. * @param x0 Starting point in X direction
  177. * @param y0 Starting point in Y direction
  178. * @param x1 End point in X direction
  179. * @param y1 End point in Y direction
  180. *
  181. * @note When the BPP of the screen controller is less than 8, the coordinate value is limited to a multiple of some number
  182. *
  183. * @return
  184. * - ESP_OK on success
  185. * - ESP_FAIL Failed
  186. */
  187. esp_err_t (*set_window)(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
  188. /**
  189. * @brief Write a RAM data
  190. *
  191. * @param color New color of a pixel
  192. *
  193. * @return
  194. * - ESP_OK on success
  195. * - ESP_FAIL Failed
  196. */
  197. esp_err_t (*write_ram_data)(uint16_t color);
  198. /**
  199. * @brief Draw one pixel in screen with color
  200. *
  201. * @param x X co-ordinate of set orientation
  202. * @param y Y co-ordinate of set orientation
  203. * @param color New color of the pixel
  204. *
  205. * @return
  206. * - ESP_OK on success
  207. * - ESP_FAIL Failed
  208. */
  209. esp_err_t (*draw_pixel)(uint16_t x, uint16_t y, uint16_t color);
  210. /**
  211. * @brief Fill the pixels on LCD screen with bitmap
  212. *
  213. * @param x Starting point in X direction
  214. * @param y Starting point in Y direction
  215. * @param w width of image in bitmap array
  216. * @param h height of image in bitmap array
  217. * @param bitmap pointer to bitmap array
  218. *
  219. * @return
  220. * - ESP_OK on success
  221. * - ESP_FAIL Failed
  222. */
  223. esp_err_t (*draw_bitmap)(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t *bitmap);
  224. /**
  225. * @brief Get screen information
  226. *
  227. * @param info Pointer to a scr_info_t structure.
  228. *
  229. * @return
  230. * - ESP_OK on success
  231. * - ESP_FAIL Failed
  232. */
  233. esp_err_t (*get_info)(scr_info_t *info);
  234. } scr_driver_t;
  235. /**
  236. * @brief Find a screen driver
  237. *
  238. * @param controller Screen controller to initialize
  239. * @param out_screen Pointer to a screen driver
  240. *
  241. * @return
  242. * - ESP_OK on success
  243. * - ESP_ERR_INVALID_ARG Arguments is NULL.
  244. * - ESP_ERR_NOT_FOUND Screen controller was not found.
  245. */
  246. esp_err_t scr_find_driver(scr_controller_t controller, scr_driver_t *out_screen);
  247. #ifdef __cplusplus
  248. }
  249. #endif
  250. #endif