drv_lcd_defs.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _DRV_LCD_DEFS_H_
  13. #define _DRV_LCD_DEFS_H_
  14. #include "osi_compiler.h"
  15. OSI_EXTERN_C_BEGIN
  16. /**
  17. * \brief maximum overlay count
  18. */
  19. #define DRV_LCD_OVERLAY_COUNT (3)
  20. /**
  21. * \brief combine 8bits RGB to RGB565
  22. *
  23. * [15:11] red
  24. * [10:5] green
  25. * [4:0] blue
  26. */
  27. #define DRV_LCD_RGB565(r, g, b) ((((uint8_t)(b) >> 3) & 0x1f) | (((uint8_t)(g) << 3) & 0x7e0) | (((uint8_t)(r) << 8) & 0xf800))
  28. /**
  29. * \brief 8bits R from RGB565
  30. */
  31. #define DRV_LCD_RGB565_R(c) (((uint16_t)(c)&0xf800) >> 8)
  32. /**
  33. * \brief 8bits G from RGB565
  34. */
  35. #define DRV_LCD_RGB565_G(c) (((uint16_t)(c)&0x7e0) >> 3)
  36. /**
  37. * \brief 8bits B from RGB565
  38. */
  39. #define DRV_LCD_RGB565_B(c) (((uint16_t)(c)&0x1f) << 3)
  40. /**
  41. * \brief input buffer color format
  42. */
  43. typedef enum
  44. {
  45. /** RGB565 in little endian, [15:11] R, [10:5] G, [4:0] B */
  46. DRV_LCD_IN_FMT_RGB565,
  47. /** ARGB8888 in little endian, [31:24] A, [23:16] R, [15:8] G, [7:0] B */
  48. DRV_LCD_IN_FMT_ARGB8888,
  49. /** UYVY pixel-packed format */
  50. DRV_LCD_IN_FMT_UYVY,
  51. /** YUYV pixel-packed format */
  52. DRV_LCD_IN_FMT_YUYV,
  53. /** IYUV planar format */
  54. DRV_LCD_IN_FMT_IYUV,
  55. } drvLcdInputFormat_t;
  56. /**
  57. * \brief video layer blending depth
  58. */
  59. typedef enum
  60. {
  61. /** at the bottom of all overlays */
  62. DRV_LCD_VIDEO_BLEND_BOTTOM,
  63. /** above overlay 0, under overlay 1 */
  64. DRV_LCD_VIDEO_BLEND_ABOVE_0,
  65. /** above overlay 1, under overlay 2 */
  66. DRV_LCD_VIDEO_BLEND_ABOVE_1,
  67. /** above overlay 2 */
  68. DRV_LCD_VIDEO_BLEND_ABOVE_2,
  69. /** at the top of all overlays */
  70. DRV_LCD_VIDEO_BLEND_TOP = DRV_LCD_VIDEO_BLEND_ABOVE_2,
  71. } drvLcdVideoBlendDepth_t;
  72. /**
  73. * \brief LCD panel interface type
  74. */
  75. typedef enum
  76. {
  77. DRV_LCD_INTF_SPI, ///< SPI
  78. DRV_LCD_INTF_DSI, ///< MIPI DSI
  79. } drvLcdInterface_t;
  80. /**
  81. * \brief direction transform
  82. */
  83. typedef enum
  84. {
  85. /** normal direction */
  86. DRV_LCD_DIR_NORMAL,
  87. /** Y is inverted */
  88. DRV_LCD_DIR_YINV,
  89. /** X is inverted */
  90. DRV_LCD_DIR_XINV,
  91. /** both Y and X are inverted */
  92. DRV_LCD_DIR_YINV_XINV,
  93. /** X-Y are swapped */
  94. DRV_LCD_DIR_EXCHG,
  95. /** X-Y are swapped, Y is inverted */
  96. DRV_LCD_DIR_EXCHG_YINV,
  97. /** X-Y are swapped, X is inverted */
  98. DRV_LCD_DIR_EXCHG_XINV,
  99. /** X-Y are swapped, both X and Y are inverted */
  100. DRV_LCD_DIR_EXCHG_XINV_YINV,
  101. /** alias for rotate 0 degree */
  102. DRV_LCD_DIR_ROTATE_0 = DRV_LCD_DIR_NORMAL,
  103. /** alias for rotate 90 degree */
  104. DRV_LCD_DIR_ROTATE_90 = DRV_LCD_DIR_EXCHG_XINV,
  105. /** alias for rotate 180 degree */
  106. DRV_LCD_DIR_ROTATE_180 = DRV_LCD_DIR_YINV_XINV,
  107. /** alias for rotate 270 degree */
  108. DRV_LCD_DIR_ROTATE_270 = DRV_LCD_DIR_EXCHG_YINV,
  109. } drvLcdDirection_t;
  110. /**
  111. * \brief combine two transform direction
  112. *
  113. * \param first the 1st transform direction
  114. * \param second the 2nd transform direction
  115. * \return
  116. * - the combined transform direction
  117. */
  118. static inline drvLcdDirection_t drvLcdDirCombine(drvLcdDirection_t first, drvLcdDirection_t second) { return first ^ second; }
  119. /**
  120. * \brief whether the transform direction swap X and Y
  121. *
  122. * For example, rotate 90 and 270 degree will swap X and Y
  123. *
  124. * \param dir the transform direction
  125. * \return
  126. * - true if X and Y is swapped
  127. */
  128. static inline bool drvLcdDirSwapped(drvLcdDirection_t dir) { return (dir & 4) != 0; }
  129. /**
  130. * \brief panel information
  131. */
  132. typedef struct
  133. {
  134. /** string name */
  135. const char *name;
  136. /** panel ID */
  137. uint32_t dev_id;
  138. /** virtual panel width, direction transform considered */
  139. uint16_t width;
  140. /** virtual panel height, direction transform considered */
  141. uint16_t height;
  142. /** interface type */
  143. drvLcdInterface_t intf;
  144. /** whether fmark enabled */
  145. bool fmark_enabled;
  146. /** data transfer speed, in pixel per second */
  147. unsigned speed;
  148. /** frame duration, in us */
  149. unsigned frame_us;
  150. } drvLcdPanelInfo_t;
  151. /**
  152. * \brief an area
  153. *
  154. * Area with (w == 0 || h == 0) is nul or invalid area.
  155. */
  156. typedef struct
  157. {
  158. uint16_t x; ///< starting x
  159. uint16_t y; ///< starting y
  160. uint16_t w; ///< width
  161. uint16_t h; ///< height
  162. } drvLcdArea_t;
  163. /**
  164. * \brief helper to check whether area are the same
  165. * \param a first area
  166. * \param b second area
  167. * \return
  168. * - true if matches, false otherwise
  169. */
  170. static inline bool drvLcdAreaEqual(const drvLcdArea_t *a, const drvLcdArea_t *b)
  171. {
  172. return (a->x == b->x && a->y == b->y && a->w == b->w && a->h == b->h);
  173. }
  174. /**
  175. * \brief helper to check whether area shape are the same
  176. * \param a first area
  177. * \param b second area
  178. * \return
  179. * - true if matches, false otherwise
  180. */
  181. static inline bool drvLcdAreaShapeEqual(const drvLcdArea_t *a, const drvLcdArea_t *b)
  182. {
  183. return a->w == b->w && a->h == b->h;
  184. }
  185. /**
  186. * \brief helper to check whether area is nul
  187. * \param a area
  188. * \return
  189. * - true if either width or height is 0
  190. * - false if not
  191. */
  192. static inline bool drvLcdAreaIsNul(const drvLcdArea_t *a) { return (a->w == 0 || a->h == 0); }
  193. /**
  194. * \brief helper for end X of srea
  195. * \param a area
  196. * \return
  197. * - end X
  198. */
  199. static inline uint16_t drvLcdAreaEndX(const drvLcdArea_t *a) { return a->x + a->w - 1; }
  200. /**
  201. * \brief helper for end Y of srea
  202. * \param a area
  203. * \return
  204. * - end X
  205. */
  206. static inline uint16_t drvLcdAreaEndY(const drvLcdArea_t *a) { return a->y + a->h - 1; }
  207. /**
  208. * \brief video layer description
  209. */
  210. typedef struct
  211. {
  212. /** buffer at top-left */
  213. void *buf;
  214. /** U buffer at top-left for IYUV */
  215. void *buf_u;
  216. /** V buffer at top-left for IYUV */
  217. void *buf_v;
  218. /** whether this layer is enabled */
  219. bool enabled;
  220. /** video blending depth */
  221. uint8_t depth;
  222. /** input format */
  223. uint8_t in_fmt;
  224. /** blending alpha, 0 for transparent */
  225. uint8_t alpha;
  226. /** whether to rotate 90 degree clockwise */
  227. bool rotation;
  228. /** whether to enable color key */
  229. bool key_en;
  230. /** key color mask */
  231. uint8_t key_mask;
  232. /** key color in RGB565 */
  233. uint16_t key_color;
  234. /** input buffer stride in pixel */
  235. uint16_t stride;
  236. /** input buffer width in pixel */
  237. uint16_t buf_width;
  238. /** input buffer height in pixel */
  239. uint16_t buf_height;
  240. /** layer ROI */
  241. drvLcdArea_t out;
  242. } drvLcdVideoLayer_t;
  243. /**
  244. * \brief overlay definition
  245. */
  246. typedef struct
  247. {
  248. /** buffer at top-left */
  249. void *buf;
  250. /** whether this layer is enabled */
  251. bool enabled;
  252. /** input format */
  253. uint8_t in_fmt;
  254. /** blending alpha, 0 for transparent */
  255. uint8_t alpha;
  256. /** whether to enable color key */
  257. bool key_en;
  258. /** key color mask */
  259. uint8_t key_mask;
  260. /** key color in RGB565 */
  261. uint16_t key_color;
  262. /** input buffer stride in pixel */
  263. uint16_t stride;
  264. /** layer ROI */
  265. drvLcdArea_t out;
  266. } drvLcdOverlay_t;
  267. /**
  268. * \brief LCD output layers
  269. *
  270. * The configuration will be used for screen update.
  271. */
  272. typedef struct
  273. {
  274. /** video layer, NULL for not enabled */
  275. drvLcdVideoLayer_t *vl;
  276. /** overlay layers, NULL for not enabled */
  277. drvLcdOverlay_t *ovl[DRV_LCD_OVERLAY_COUNT];
  278. /** background color */
  279. uint16_t bg_color;
  280. /** blended layers ROI */
  281. drvLcdArea_t layer_roi;
  282. /** screen ROI */
  283. drvLcdArea_t screen_roi;
  284. } drvLcdLayers_t;
  285. /**
  286. * \brief panel spi interface type
  287. */
  288. typedef enum
  289. {
  290. DRV_LCD_SPI_4WIRE,
  291. DRV_LCD_SPI_3WIRE,
  292. DRV_LCD_SPI_4WIRE_START_BYTE,
  293. DRV_LCD_SPI_3WIRE_2LANE,
  294. } drvLcdSpiLineMode_t;
  295. /**
  296. * \brief panel data format
  297. */
  298. typedef enum
  299. {
  300. DRV_LCD_OUT_FMT_8BIT_RGB332 = 0,
  301. DRV_LCD_OUT_FMT_8BIT_RGB444 = 1,
  302. DRV_LCD_OUT_FMT_8BIT_RGB565 = 2,
  303. DRV_LCD_OUT_FMT_16BIT_RGB332 = 4,
  304. DRV_LCD_OUT_FMT_16BIT_RGB444 = 5,
  305. DRV_LCD_OUT_FMT_16BIT_RGB565 = 6,
  306. } drvLcdOutputFormat_t;
  307. /**
  308. * \brief LCD panel operations
  309. *
  310. * All functions can't be NULL. User won't check NULL pointer before calling
  311. * panel operations. Also, caller will take care thread safe.
  312. */
  313. typedef struct
  314. {
  315. /**
  316. * \brief probe the panel
  317. * \param d LCD instance
  318. * \return
  319. * - true if the panel matches the driver
  320. * - false if not match
  321. */
  322. bool (*probe)(void *d);
  323. /**
  324. * \brief initialization
  325. * \param d LCD instance
  326. */
  327. void (*init)(void *d);
  328. /**
  329. * \brief prepare data transfer, set direction and ROI
  330. * \param d LCD instance
  331. * \param dir direction
  332. * \param roi region of interest
  333. */
  334. void (*blit_prepare)(void *d, drvLcdDirection_t dir, const drvLcdArea_t *roi);
  335. } drvLcdPanelOps_t;
  336. /**
  337. * \brief panel configuration description
  338. */
  339. typedef struct
  340. {
  341. /** panel operation */
  342. drvLcdPanelOps_t ops;
  343. /** name string */
  344. const char *name;
  345. /** device ID */
  346. unsigned dev_id;
  347. /** reset time in us */
  348. unsigned reset_us;
  349. /** delay time after reset in us */
  350. unsigned init_delay_us;
  351. /** width in normal direction */
  352. uint16_t width;
  353. /** height in normal direction */
  354. uint16_t height;
  355. /** output format */
  356. drvLcdOutputFormat_t out_fmt;
  357. /** panel initial direction */
  358. drvLcdDirection_t dir;
  359. /** SPI line mode */
  360. drvLcdSpiLineMode_t line_mode;
  361. /** fmark enabled */
  362. bool fmark_enabled;
  363. /** fmark delay */
  364. unsigned fmark_delay;
  365. /** SPI frequency */
  366. unsigned freq;
  367. /** frmae period in us */
  368. unsigned frame_us;
  369. } drvLcdPanelDesc_t;
  370. /**
  371. * \brief get panel description from LCD instance
  372. *
  373. * This should be called only in panel driver, and implemented in lcd driver.
  374. *
  375. * \param d LCD instance
  376. * \return
  377. * - panel description
  378. */
  379. const drvLcdPanelDesc_t *drvLcdGetDesc(void *d);
  380. /**
  381. * \brief write command to panel
  382. *
  383. * This should be called only in panel driver, and implemented in lcd driver.
  384. *
  385. * \param d LCD instance
  386. * \param cmd command
  387. */
  388. void drvLcdWriteCmd(void *d, uint16_t cmd);
  389. /**
  390. * \brief write data to panel
  391. *
  392. * This should be called only in panel driver, and implemented in lcd driver.
  393. *
  394. * \param d LCD instance
  395. * \param data data
  396. */
  397. void drvLcdWriteData(void *d, uint16_t data);
  398. /**
  399. * \brief read data from panel by command
  400. *
  401. * This should be called only in panel driver, and implemented in lcd driver.
  402. *
  403. * \param d LCD instance
  404. * \param cmd command
  405. * \param data data
  406. * \param len data length
  407. */
  408. void drvLcdReadData(void *d, uint16_t cmd, uint8_t *data, unsigned len);
  409. OSI_EXTERN_C_END
  410. #endif