lcd.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. //*****************************************************************************
  2. //
  3. // lcd.h - Defines and Macros for the LCD Controller module.
  4. //
  5. // Copyright (c) 2012-2020 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions
  10. // are met:
  11. //
  12. // Redistributions of source code must retain the above copyright
  13. // notice, this list of conditions and the following disclaimer.
  14. //
  15. // Redistributions in binary form must reproduce the above copyright
  16. // notice, this list of conditions and the following disclaimer in the
  17. // documentation and/or other materials provided with the
  18. // distribution.
  19. //
  20. // Neither the name of Texas Instruments Incorporated nor the names of
  21. // its contributors may be used to endorse or promote products derived
  22. // from this software without specific prior written permission.
  23. //
  24. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. // This is part of revision 2.2.0.295 of the Tiva Peripheral Driver Library.
  37. //
  38. //*****************************************************************************
  39. #ifndef __DRIVERLIB_LCD_H__
  40. #define __DRIVERLIB_LCD_H__
  41. //*****************************************************************************
  42. //
  43. //! \addtogroup lcd_api
  44. //! @{
  45. //
  46. //*****************************************************************************
  47. //*****************************************************************************
  48. //
  49. // If building with a C++ compiler, make all of the definitions in this header
  50. // have a C binding.
  51. //
  52. //*****************************************************************************
  53. #ifdef __cplusplus
  54. extern "C"
  55. {
  56. #endif
  57. //*****************************************************************************
  58. //
  59. //! This macro can be used to convert a 24-bit RGB color value as used by the
  60. //! TivaWare Graphics Library into a 12-bit LCD controller color palette
  61. //! entry.
  62. //
  63. //*****************************************************************************
  64. #define PAL_FROM_RGB(ui32RGBColor) (((ui32RGBColor & 0xF0) >> 4) | \
  65. ((ui32RGBColor & 0xF000) >> 8) | \
  66. ((ui32RGBColor & 0xF00000) >> 12))
  67. //*****************************************************************************
  68. //
  69. //! This macro can be used to convert from time in microseconds to periods of
  70. //! the supplied clock in Hertz as required when setting up the LIDD and raster
  71. //! timing structures. The calculation will round such that the number of
  72. //! cycles returned represents no longer a time than specified in the
  73. //! ui32Time_uS parameter. Values of ui32Time_uS less than or equal to
  74. //! 4294967uS (4.29 seconds) are supported by the macro. Larger values will
  75. //! cause arithmetic overflow and yield incorrect values. It is further
  76. //! assumed that ui32ClockFreq is a non-zero multiple of 1000000 (1MHz).
  77. //
  78. //*****************************************************************************
  79. #define CYCLES_FROM_TIME_US(ui32ClockFreq, ui32Time_uS) \
  80. (((ui32Time_uS) == 0) ? 0 : \
  81. (((ui32ClockFreq) / 1000000) * ((((ui32Time_uS) * 1000) - 1) / 1000)) + 1)
  82. //*****************************************************************************
  83. //
  84. //! This macro can be used to convert from time in nanoseconds to periods of
  85. //! the supplied clock in Hertz as required when setting up the LIDD and raster
  86. //! timing structures. The calculation will round such that the number of
  87. //! cycles returned represents no longer a time than specified in the
  88. //! ui32Time_nS parameter. Values of ui32Time_nS less than or equal to
  89. //! 35791394 (35.79 milliseconds) are supported by the macro. Larger values
  90. //! will cause arithmetic overflow and yield incorrect values. It is further
  91. //! assumed that ui32ClockFreq is a non-zero multiple of 1000000 (1MHz).
  92. //
  93. //*****************************************************************************
  94. #define CYCLES_FROM_TIME_NS(ui32ClockFreq, ui32Time_nS) \
  95. (((ui32Time_nS) == 0) ? 0 : \
  96. ((((((ui32ClockFreq) / 1000000) * ((ui32Time_nS) - 1)) / 1000)) + 1))
  97. //*****************************************************************************
  98. //
  99. //! A structure containing timing parameters for the LIDD (LCD Interface
  100. //! Display Driver) interface. This is used with the LCDIDDTimingSet function.
  101. //
  102. //*****************************************************************************
  103. typedef struct
  104. {
  105. //
  106. //! Write Strobe Set-Up cycles. When performing a write access, this
  107. //! field defines the number of MCLK cycles that Data Bus/Pad Output
  108. //! Enable, ALE, the Direction bit, and Chip Select have to be ready before
  109. //! the Write Strobe is asserted. Valid values are from 0 to 31.
  110. //
  111. uint8_t ui8WSSetup;
  112. //
  113. //! Write Strobe Duration cycles. Field value defines the number of MCLK
  114. //! cycles for which the Write Strobe is held active when performing a
  115. //! write access. Valid values are from 1 to 63.
  116. //
  117. uint8_t ui8WSDuration;
  118. //
  119. //! Write Strobe Hold cycles. Field value defines the number of MCLK
  120. //! cycles for which Data Bus/Pad Output Enable, ALE, the Direction bit,
  121. //! and Chip Select are held after the Write Strobe is deasserted when
  122. //! performing a write access. Valid values are from 1 to 15.
  123. //
  124. uint8_t ui8WSHold;
  125. //
  126. //! Read Strobe Set-Up cycles. When performing a read access, this field
  127. //! defines the number of MCLK cycles that Data Bus/Pad Output Enable, ALE,
  128. //! the Direction bit, and Chip Select have to be ready before the Read
  129. //! Strobe is asserted. Valid values are from 0 to 31.
  130. //
  131. uint8_t ui8RSSetup;
  132. //
  133. //! Read Strobe Duration cycles. Field value defines the number of MCLK
  134. //! cycles for which the Read Strobe is held active when performing a read
  135. //! access. Valid values are from 1 to 63.
  136. //
  137. uint8_t ui8RSDuration;
  138. //
  139. //! Read Strobe Hold cycles. Field value defines the number of MCLK cycles
  140. //! for which Data Bus/Pad Output Enable, ALE, the Direction bit, and Chip
  141. //! Select are held after the Read Strobe is deasserted when performing a
  142. //! read access. Valid values are from 1 to 15.
  143. //
  144. uint8_t ui8RSHold;
  145. //
  146. //! Field value defines the number of MCLK cycles between the end of one
  147. //! device access and the start of another device access using the same
  148. //! Chip Select unless the two accesses are both Reads. In this case,
  149. //! this delay is not incurred. Valid vales are from 1 to 4.
  150. //
  151. uint8_t ui8DelayCycles;
  152. }
  153. tLCDIDDTiming;
  154. //
  155. // Values which can be ORed together within the ui32Flags field of the
  156. // tLCDRasterTiming structure.
  157. //
  158. #define RASTER_TIMING_SYNCS_OPPOSITE_PIXCLK \
  159. 0x00000000
  160. #define RASTER_TIMING_SYNCS_ON_RISING_PIXCLK \
  161. 0x02000000
  162. #define RASTER_TIMING_SYNCS_ON_FALLING_PIXCLK \
  163. 0x03000000
  164. #define RASTER_TIMING_ACTIVE_HIGH_OE \
  165. 0x00000000
  166. #define RASTER_TIMING_ACTIVE_LOW_OE \
  167. 0x00800000
  168. #define RASTER_TIMING_ACTIVE_HIGH_PIXCLK \
  169. 0x00000000
  170. #define RASTER_TIMING_ACTIVE_LOW_PIXCLK \
  171. 0x00400000
  172. #define RASTER_TIMING_ACTIVE_HIGH_HSYNC \
  173. 0x00000000
  174. #define RASTER_TIMING_ACTIVE_LOW_HSYNC \
  175. 0x00200000
  176. #define RASTER_TIMING_ACTIVE_HIGH_VSYNC \
  177. 0x00000000
  178. #define RASTER_TIMING_ACTIVE_LOW_VSYNC \
  179. 0x00100000
  180. //
  181. //! A structure containing timing parameters for the raster interface. This is
  182. //! used with the LCDRasterTimingSet function.
  183. //
  184. typedef struct
  185. {
  186. //
  187. //! Flags configuring the polarity and active edges of the various signals
  188. //! in the raster interface. This field is comprised of a logical OR of
  189. //! the labels with prefix ``RASTER_TIMING_''.
  190. //
  191. uint32_t ui32Flags;
  192. //
  193. //! The number of pixels contained within each line on the LCD display.
  194. //! Valid values are multiple of 16 less than or equal to 2048.
  195. //
  196. uint16_t ui16PanelWidth;
  197. //
  198. //! The number of lines on the LCD display. Valid values are from 1 to
  199. //! 2048.
  200. //
  201. uint16_t ui16PanelHeight;
  202. //
  203. //! A value from 1 to 1024 that specifies the number of pixel clock periods
  204. //! to add to the end of each line after active video has ended.
  205. //
  206. uint16_t ui16HFrontPorch;
  207. //
  208. //! A value from 1 to 1024 that specifies the number of pixel clock periods
  209. //! to add to the beginning of a line before active video is asserted.
  210. //
  211. uint16_t ui16HBackPorch;
  212. //
  213. //! A value from 1 to 1024 that specifies the number of pixel clock periods
  214. //! to pulse the line clock at the end of each line.
  215. //
  216. uint16_t ui16HSyncWidth;
  217. //
  218. //! A value from 0 to 255 that specifies the number of line clock periods
  219. //! to add to the end of each frame after the last active line.
  220. //
  221. uint8_t ui8VFrontPorch;
  222. //
  223. //! A value from 0 to 255 that specifies the number of line clock periods
  224. //! to add to the beginning of a frame before the first active line is
  225. //! output to the display.
  226. //
  227. uint8_t ui8VBackPorch;
  228. //
  229. //! In active mode, a value from 1 to 64 that specifies the number of
  230. //! line clock periods to set the lcd_fp pin active at the end of each
  231. //! frame after the vertical front porch period elapses. The number of
  232. //! The frame clock is used as the VSYNC signal in active mode.
  233. //!
  234. //! In passive mode, a value from 1 to 64 that specifies the number of
  235. //! extra line clock periods to insert after the vertical front porch
  236. //! period has elapsed. Note that the width of lcd_fp is not affected by
  237. //! this value in passive mode.
  238. //
  239. uint8_t ui8VSyncWidth;
  240. //
  241. //! A value from 0 to 255 that specifies the number of line clocks to
  242. //! count before transitioning the AC Bias pin. This pin is used to
  243. //! periodically invert the polarity of the power supply to prevent DC
  244. //! charge build-up within the display.
  245. //
  246. uint8_t ui8ACBiasLineCount;
  247. }
  248. tLCDRasterTiming;
  249. //*****************************************************************************
  250. //
  251. // Possible values for the ui8Mode parameter to LCDModeSet(). The label
  252. // LCD_MODE_AUTO_UFLOW_RESTART may be ORed with either of the other two.
  253. //
  254. //*****************************************************************************
  255. #define LCD_MODE_LIDD ((uint8_t)0x00)
  256. #define LCD_MODE_RASTER ((uint8_t)0x01)
  257. #define LCD_MODE_AUTO_UFLOW_RESTART \
  258. ((uint8_t)0x02)
  259. //*****************************************************************************
  260. //
  261. // Values used to construct the ui32Config parameter to LCDIDDConfigSet().
  262. //
  263. //*****************************************************************************
  264. #define LIDD_CONFIG_SYNC_MPU68 0x00000000
  265. #define LIDD_CONFIG_ASYNC_MPU68 0x00000001
  266. #define LIDD_CONFIG_SYNC_MPU80 0x00000002
  267. #define LIDD_CONFIG_ASYNC_MPU80 0x00000003
  268. #define LIDD_CONFIG_ASYNC_HITACHI \
  269. 0x00000004
  270. #define LIDD_CONFIG_INVERT_ALE 0x00000008
  271. #define LIDD_CONFIG_INVERT_RS_EN \
  272. 0x00000010
  273. #define LIDD_CONFIG_INVERT_WS_DIR \
  274. 0x00000020
  275. #define LIDD_CONFIG_INVERT_CS0 0x00000040
  276. #define LIDD_CONFIG_INVERT_CS1 0x00000080
  277. //*****************************************************************************
  278. //
  279. // Values used to construct the ui32Config parameter to
  280. // LCDRasterConfigSet(). Valid parameters contain one of the RASTER_FMT_xxx
  281. // labels optionally ORed with the other flags. Only one of
  282. // RASTER_LOAD_DATA_ONLY and RASTER_LOAD_PALETTE_ONLY may be specified (if
  283. // neither is specified, the controller will load both palette and data when
  284. // scanning out the frame buffer).
  285. //
  286. //*****************************************************************************
  287. #define RASTER_FMT_ACTIVE_24BPP_PACKED \
  288. 0x02000080
  289. #define RASTER_FMT_ACTIVE_24BPP_UNPACKED \
  290. 0x06000080
  291. #define RASTER_FMT_ACTIVE_PALETTIZED_12BIT \
  292. 0x00000080
  293. #define RASTER_FMT_ACTIVE_PALETTIZED_16BIT \
  294. 0x00800080
  295. #define RASTER_FMT_PASSIVE_MONO_4PIX \
  296. 0x00000002
  297. #define RASTER_FMT_PASSIVE_MONO_8PIX \
  298. 0x00000202
  299. #define RASTER_FMT_PASSIVE_PALETTIZED \
  300. 0x00000000
  301. #define RASTER_FMT_PASSIVE_COLOR_12BIT \
  302. 0x00000000
  303. #define RASTER_FMT_PASSIVE_COLOR_16BIT \
  304. 0x01000000
  305. #define RASTER_ACTVID_DURING_BLANK \
  306. 0x08000000
  307. #define RASTER_NIBBLE_MODE_ENABLED \
  308. 0x00400000
  309. #define RASTER_LOAD_DATA_ONLY 0x00200000
  310. #define RASTER_LOAD_PALETTE_ONLY \
  311. 0x00100000
  312. #define RASTER_READ_ORDER_REVERSED \
  313. 0x00000100
  314. //*****************************************************************************
  315. //
  316. // Interrupt sources for the LCD controller. These may be ORed together and
  317. // passed to LCDIntEnable(), LCDIntDisable() and LCDIntClear(). They are also
  318. // returned by LCDIntStatus().
  319. //
  320. //*****************************************************************************
  321. #define LCD_INT_DMA_DONE 0x00000001
  322. #define LCD_INT_RASTER_FRAME_DONE \
  323. 0x00000002
  324. #define LCD_INT_SYNC_LOST 0x00000004
  325. #define LCD_INT_AC_BIAS_CNT 0x00000008
  326. #define LCD_INT_UNDERFLOW 0x00000020
  327. #define LCD_INT_PAL_LOAD 0x00000040
  328. #define LCD_INT_EOF0 0x00000100
  329. #define LCD_INT_EOF1 0x00000200
  330. //*****************************************************************************
  331. //
  332. // Configuration values used with LCDDMAConfigSet().
  333. //
  334. //*****************************************************************************
  335. #define LCD_DMA_FIFORDY_8_WORDS 0x00000000
  336. #define LCD_DMA_FIFORDY_16_WORDS \
  337. 0x00000100
  338. #define LCD_DMA_FIFORDY_32_WORDS \
  339. 0x00000200
  340. #define LCD_DMA_FIFORDY_64_WORDS \
  341. 0x00000300
  342. #define LCD_DMA_FIFORDY_128_WORDS \
  343. 0x00000400
  344. #define LCD_DMA_FIFORDY_256_WORDS \
  345. 0x00000500
  346. #define LCD_DMA_FIFORDY_512_WORDS \
  347. 0x00000600
  348. #define LCD_DMA_BURST_1 0x00000010
  349. #define LCD_DMA_BURST_2 0x00000010
  350. #define LCD_DMA_BURST_4 0x00000020
  351. #define LCD_DMA_BURST_8 0x00000030
  352. #define LCD_DMA_BURST_16 0x00000040
  353. #define LCD_DMA_BYTE_ORDER_0123 0x00000000
  354. #define LCD_DMA_BYTE_ORDER_1023 0x00000008
  355. #define LCD_DMA_BYTE_ORDER_3210 0x00000002
  356. #define LCD_DMA_BYTE_ORDER_2301 0x0000000A
  357. #define LCD_DMA_PING_PONG 0x00000001
  358. //*****************************************************************************
  359. //
  360. // Type values used with LCDRasterPaletteSet().
  361. //
  362. //*****************************************************************************
  363. #define LCD_PALETTE_TYPE_1BPP 0x00000000
  364. #define LCD_PALETTE_TYPE_2BPP 0x00001000
  365. #define LCD_PALETTE_TYPE_4BPP 0x00002000
  366. #define LCD_PALETTE_TYPE_8BPP 0x00003000
  367. #define LCD_PALETTE_TYPE_DIRECT 0x00004000
  368. #define LCD_PALETTE_SRC_24BIT 0x80000000
  369. //*****************************************************************************
  370. //
  371. // Flags used in the ui32Clocks parameter to LCDClockReset().
  372. //
  373. //*****************************************************************************
  374. #define LCD_CLOCK_MAIN 0x00000008
  375. #define LCD_CLOCK_DMA 0x00000004
  376. #define LCD_CLOCK_LIDD 0x00000002
  377. #define LCD_CLOCK_CORE 0x00000001
  378. //*****************************************************************************
  379. //
  380. // Flags used in with LCDSubPanelConfigSet().
  381. //
  382. //*****************************************************************************
  383. #define LCD_SUBPANEL_AT_TOP 0x20000000
  384. #define LCD_SUBPANEL_AT_BOTTOM 0x00000000
  385. //*****************************************************************************
  386. //
  387. // Close the Doxygen group.
  388. //! @}
  389. //
  390. //*****************************************************************************
  391. //*****************************************************************************
  392. //
  393. // Function Prototypes.
  394. //
  395. //*****************************************************************************
  396. extern uint32_t LCDModeSet(uint32_t ui32Base, uint8_t ui8Mode,
  397. uint32_t ui32PixClk, uint32_t ui32SysClk);
  398. extern void LCDClockReset(uint32_t ui32Base, uint32_t ui32Clocks);
  399. extern void LCDIDDConfigSet(uint32_t ui32Base, uint32_t ui32Config);
  400. extern void LCDIDDTimingSet(uint32_t ui32Base, uint32_t ui32CS,
  401. const tLCDIDDTiming *pTiming);
  402. extern void LCDIDDDMADisable(uint32_t ui32Base);
  403. extern void LCDIDDCommandWrite(uint32_t ui32Base, uint32_t ui32CS,
  404. uint16_t ui16Cmd);
  405. extern void LCDIDDDataWrite(uint32_t ui32Base, uint32_t ui32CS,
  406. uint16_t ui16Data);
  407. extern void LCDIDDIndexedWrite(uint32_t ui32Base, uint32_t ui32CS,
  408. uint16_t ui16Addr, uint16_t ui16Data);
  409. extern uint16_t LCDIDDStatusRead(uint32_t ui32Base, uint32_t ui32CS);
  410. extern uint16_t LCDIDDDataRead(uint32_t ui32Base, uint32_t ui32CS);
  411. extern uint16_t LCDIDDIndexedRead(uint32_t ui32Base, uint32_t ui32CS,
  412. uint16_t ui16Addr);
  413. extern void LCDIDDDMAWrite(uint32_t ui32Base, uint32_t ui32CS,
  414. const uint32_t *pui32Data, uint32_t ui32Count);
  415. extern void LCDRasterConfigSet(uint32_t ui32Base, uint32_t ui32Config,
  416. uint8_t ui8PalLoadDelay);
  417. extern void LCDRasterTimingSet(uint32_t ui32Base,
  418. const tLCDRasterTiming *pTiming);
  419. extern void LCDRasterACBiasIntCountSet(uint32_t ui32Base, uint8_t ui8Count);
  420. extern void LCDRasterEnable(uint32_t ui32Base);
  421. extern bool LCDRasterEnabled(uint32_t ui32Base);
  422. extern void LCDRasterDisable(uint32_t ui32Base);
  423. extern void LCDRasterSubPanelConfigSet(uint32_t ui32Base, uint32_t ui32Flags,
  424. uint32_t ui32BottomLines,
  425. uint32_t ui32DefaultPixel);
  426. extern void LCDRasterSubPanelEnable(uint32_t ui32Base);
  427. extern void LCDRasterSubPanelDisable(uint32_t ui32Base);
  428. extern void LCDDMAConfigSet(uint32_t ui32Base, uint32_t ui32Config);
  429. extern void LCDRasterPaletteSet(uint32_t ui32Base, uint32_t ui32Type,
  430. uint32_t *pui32PalAddr,
  431. const uint32_t *pui32SrcColors,
  432. uint32_t ui32Start,
  433. uint32_t ui32Count);
  434. extern void LCDRasterFrameBufferSet(uint32_t ui32Base, uint8_t ui8Buffer,
  435. uint32_t *pui32Addr,
  436. uint32_t ui32NumBytes);
  437. extern void LCDIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags);
  438. extern void LCDIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags);
  439. extern uint32_t LCDIntStatus(uint32_t ui32Base, bool bMasked);
  440. extern void LCDIntClear(uint32_t ui32Base, uint32_t ui32IntFlags);
  441. extern void LCDIntRegister(uint32_t ui32Base, void (*pfnHandler)(void));
  442. extern void LCDIntUnregister(uint32_t ui32Base);
  443. //*****************************************************************************
  444. //
  445. // Mark the end of the C bindings section for C++ compilers.
  446. //
  447. //*****************************************************************************
  448. #ifdef __cplusplus
  449. }
  450. #endif
  451. #endif // __DRIVERLIB_LCD_H__