sama_lcdc.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  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. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file SAMA5D2x/sama_lcdc.h
  15. * @brief SAMA LCDC support macros and structures.
  16. *
  17. * @addtogroup SAMA5D2x_LCDC
  18. * @{
  19. */
  20. #ifndef SAMA_LCDC_LLD_H
  21. #define SAMA_LCDC_LLD_H
  22. /**
  23. * @brief Using the LCDC driver.
  24. */
  25. #if !defined(SAMA_USE_LCDC) || defined(__DOXYGEN__)
  26. #define SAMA_USE_LCDC FALSE
  27. #endif
  28. #if (SAMA_USE_LCDC) || defined(__DOXYGEN__)
  29. /*===========================================================================*/
  30. /* Driver constants. */
  31. /*===========================================================================*/
  32. /**
  33. * @name LCDC ID LAYERS
  34. * @{
  35. */
  36. /* LCD controller ID, no display, configuration ONLY */
  37. #define LCDD_CONTROLLER 0
  38. /* LCD base layer, display fixed size image */
  39. #define LCDD_BASE 1
  40. /* LCD Overlay 1 */
  41. #define LCDD_OVR1 2
  42. /* LCD Overlay 2 */
  43. #define LCDD_OVR2 4
  44. /* LCD HighEndOverlay, support resize */
  45. #define LCDD_HEO 3
  46. /* LCD Cursor, max size 128x128 */
  47. #define LCDD_CUR 6
  48. /** @} */
  49. /**
  50. * @name BPP MODE
  51. * @{
  52. */
  53. #define LCDC_CFG_RGBMODE_12BPP_RGB_444 (0x0u << 4)
  54. #define LCDC_CFG_RGBMODE_16BPP_ARGB_4444 (0x1u << 4)
  55. #define LCDC_CFG_RGBMODE_16BPP_RGBA_4444 (0x2u << 4)
  56. #define LCDC_CFG_RGBMODE_16BPP_RGB_565 (0x3u << 4)
  57. #define LCDC_CFG_RGBMODE_16BPP_TRGB_1555 (0x4u << 4)
  58. #define LCDC_CFG_RGBMODE_18BPP_RGB_666 (0x5u << 4)
  59. #define LCDC_CFG_RGBMODE_18BPP_RGB_666PACKED (0x6u << 4)
  60. #define LCDC_CFG_RGBMODE_19BPP_TRGB_1666 (0x7u << 4)
  61. #define LCDC_CFG_RGBMODE_19BPP_TRGB_PACKED (0x8u << 4)
  62. #define LCDC_CFG_RGBMODE_24BPP_RGB_888 (0x9u << 4)
  63. #define LCDC_CFG_RGBMODE_24BPP_RGB_888_PACKED (0xAu << 4)
  64. #define LCDC_CFG_RGBMODE_25BPP_TRGB_1888 (0xBu << 4)
  65. #define LCDC_CFG_RGBMODE_32BPP_ARGB_8888 (0xCu << 4)
  66. #define LCDC_CFG_RGBMODE_32BPP_RGBA_8888 (0xDu << 4)
  67. /** @} */
  68. /*===========================================================================*/
  69. /* Driver pre-compile time settings. */
  70. /*===========================================================================*/
  71. /*===========================================================================*/
  72. /* Derived constants and error checks. */
  73. /*===========================================================================*/
  74. /**
  75. * @brief LCDC_USE_WAIT.
  76. */
  77. #if !defined(LCDC_USE_WAIT) || defined(__DOXYGEN__)
  78. #define LCDC_USE_WAIT FALSE
  79. #endif
  80. /**
  81. * @brief LCDC_USE_MUTUAL_EXCLUSION.
  82. */
  83. #if !defined(LCDC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
  84. #define LCDC_USE_MUTUAL_EXCLUSION FALSE
  85. #endif
  86. /*===========================================================================*/
  87. /* Driver data structures and types. */
  88. /*===========================================================================*/
  89. /**
  90. * @brief Driver state machine possible states.
  91. */
  92. typedef enum {
  93. LCDC_UNINIT = 0, /**< Not initialized.*/
  94. LCDC_STOP = 1, /**< Stopped.*/
  95. LCDC_READY = 2, /**< Ready.*/
  96. LCDC_ACTIVE = 3, /**< Executing commands.*/
  97. } lcdcstate_t;
  98. /**
  99. * @brief Type of a structure representing an LCDC driver.
  100. */
  101. typedef struct LCDCDriver LCDCDriver;
  102. /**
  103. * @brief LCD display layer information.
  104. */
  105. typedef struct {
  106. /**
  107. * @brief Display image buffer.
  108. */
  109. void *buffer;
  110. /**
  111. * @brief Display image width.
  112. */
  113. uint16_t width;
  114. /**
  115. * @brief Display image height.
  116. */
  117. uint16_t height;
  118. /**
  119. * @brief Display image x position.
  120. */
  121. uint16_t x_pos;
  122. /**
  123. * @brief Display image y_pos.
  124. */
  125. uint16_t y_pos;
  126. /**
  127. * @brief Horizontal image Size in Memory.
  128. */
  129. uint16_t w_img;
  130. /**
  131. * @brief Vertical image Size in Memory.
  132. */
  133. uint16_t h_img;
  134. /**
  135. * @brief BPP mode.
  136. */
  137. uint8_t bpp;
  138. /**
  139. * @brief Layer ID.
  140. */
  141. uint8_t layer_id;
  142. } LCDCLayerConfig;
  143. /**
  144. * @brief Driver LCD configuration structure.
  145. */
  146. typedef struct {
  147. /**
  148. * @brief Display image width.
  149. */
  150. uint16_t width;
  151. /**
  152. * @brief Display image height.
  153. */
  154. uint16_t height;
  155. /**
  156. * @brief Frame rate in Hz.
  157. */
  158. uint8_t framerate;
  159. /**
  160. * @brief Vertical front porch in number of lines.
  161. */
  162. uint8_t timing_vfp;
  163. /**
  164. * @brief Vertical back porch in number of lines.
  165. */
  166. uint8_t timing_vbp;
  167. /**
  168. * @brief Vertical pulse width in number of lines.
  169. */
  170. uint8_t timing_vpw;
  171. /**
  172. * @brief Horizontal front porch in LCDDOTCLK cycles.
  173. */
  174. uint8_t timing_hfp;
  175. /**
  176. * @brief Horizontal back porch in LCDDOTCLK cycles.
  177. */
  178. uint8_t timing_hbp;
  179. /**
  180. * @brief Horizontal pulse width in LCDDOTCLK cycles.
  181. */
  182. uint8_t timing_hpw;
  183. /**
  184. * @brief lenght of LCDCLayerConfig array
  185. * @note Number of layers to configure
  186. */
  187. size_t length;
  188. /**
  189. * @brief pointer to LCDCLayerConfig array
  190. */
  191. LCDCLayerConfig *listp;
  192. } LCDCConfig;
  193. /**
  194. * @brief Structure representing an LCDC driver.
  195. */
  196. struct LCDCDriver {
  197. /**
  198. * @brief Driver state.
  199. */
  200. lcdcstate_t state;
  201. /**
  202. * @brief Current configuration lcd data.
  203. */
  204. const LCDCConfig *config;
  205. /**
  206. * @brief Pointer to the LCDC registers block.
  207. */
  208. Lcdc *lcdc;
  209. /* Multithreading stuff.*/
  210. #if (LCDC_USE_WAIT == TRUE) || defined(__DOXYGEN__)
  211. thread_t *thread;
  212. #endif /* LCDC_USE_WAIT */
  213. #if (LCDC_USE_MUTUAL_EXCLUSION == TRUE)
  214. #if (CH_CFG_USE_MUTEXES == TRUE)
  215. mutex_t lock;
  216. #elif (CH_CFG_USE_SEMAPHORES == TRUE)
  217. semaphore_t lock;
  218. #endif
  219. #endif /* LCDC_USE_MUTUAL_EXCLUSION */
  220. };
  221. /*===========================================================================*/
  222. /* Driver macros. */
  223. /*===========================================================================*/
  224. /*===========================================================================*/
  225. /* External declarations. */
  226. /*===========================================================================*/
  227. extern LCDCDriver LCDCD0;
  228. #ifdef __cplusplus
  229. extern "C" {
  230. #endif
  231. void lcdcObjectInit(LCDCDriver *lcdcp);
  232. void lcdcInit(void);
  233. void lcdcStart(LCDCDriver *lcdcp, const LCDCConfig *configp);
  234. void lcdcStop(LCDCDriver *lcdcp);
  235. void lcdcShowLayer(LCDCDriver *lcdcp, uint8_t id, bool enable);
  236. void lcdcSetBacklight(uint32_t level);
  237. #if (LCDC_USE_MUTUAL_EXCLUSION)
  238. void lcdcAcquireBusS(LCDCDriver *lcdcp);
  239. void lcdcAcquireBus(LCDCDriver *lcdcp);
  240. void lcdcReleaseBusS(LCDCDriver *lcdcp);
  241. void lcdcReleaseBus(LCDCDriver *lcdcp);
  242. #endif /* LCDC_USE_MUTUAL_EXCLUSION */
  243. #ifdef __cplusplus
  244. }
  245. #endif
  246. #endif /* SAMA_USE_LCDC */
  247. #endif /* SAMA_LCDC_LLD_H */
  248. /** @} */