lcd.c 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802
  1. //*****************************************************************************
  2. //
  3. // lcd.c - Defines and Macros for the LCD Controller module.
  4. //
  5. // Copyright (c) 2012-2017 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. //*****************************************************************************
  37. //*****************************************************************************
  38. //
  39. //! \addtogroup lcd_api
  40. //! @{
  41. //
  42. //*****************************************************************************
  43. #include <ti/devices/msp432e4/inc/msp432e411y.h>
  44. #include "types.h"
  45. #include <stdint.h>
  46. #include <stdbool.h>
  47. #include <stdint.h>
  48. #include "inc/hw_lcd.h"
  49. #include "interrupt.h"
  50. #include "sysctl.h"
  51. #include "lcd.h"
  52. #include "debug.h"
  53. //*****************************************************************************
  54. //
  55. // These are currently missing from hw_lcd.h and included here as a stopgap
  56. // until the hardware header is updated.
  57. //
  58. //*****************************************************************************
  59. #ifndef LCD_RASTRTIM0_MSBPPL_S
  60. #define LCD_RASTRTIM0_MSBPPL_S 3
  61. #endif
  62. #ifndef LCD_RASTRTIM2_MSBLPP_S
  63. #define LCD_RASTRTIM2_MSBLPP_S 26
  64. #endif
  65. //*****************************************************************************
  66. //
  67. //! Configures the basic operating mode and clock rate for the LCD controller.
  68. //!
  69. //! \param ui32Base specifies the LCD controller module base address.
  70. //! \param ui8Mode specifies the basic operating mode to be used.
  71. //! \param ui32PixClk specifies the desired LCD controller pixel or master
  72. //! clock rate in Hz.
  73. //! \param ui32SysClk specifies the current system clock rate in Hz.
  74. //!
  75. //! This function sets the basic operating mode of the LCD controller and also
  76. //! its master clock. The \e ui8Mode parameter may be set to either \b
  77. //! LCD_MODE_LIDD or \b LCD_MODE_RASTER. \b LCD_MODE_LIDD is used to select
  78. //! LCD Interface Display Driver mode for character panels connected via
  79. //! an asynchronous interface (CS, WE, OE, ALE, data) and \b LCD_MODE_RASTER
  80. //! is used to communicate with panels via a synchronous video interface using
  81. //! data and sync signals. Additionally, \b LCD_MODE_AUTO_UFLOW_RESTART may
  82. //! be ORed with either of these modes to indicate that the hardware should
  83. //! restart automatically if a data underflow occurs.
  84. //!
  85. //! The \e ui32PixClk parameter specifies the desired master clock for the
  86. //! the LCD controller. In LIDD mode, this value controls the MCLK used in
  87. //! communication with the display and valid values are between \e ui32SysClk
  88. //! and \e ui32SysClk/255. In raster mode, \e ui32PixClk specifies the pixel
  89. //! clock rate for the raster interface and valid values are between \e
  90. //! ui32SysClk/2 and \e ui32SysClk/255. The actual clock rate set may differ
  91. //! slightly from the desired rate due to the fact that only integer dividers
  92. //! are supported. The rate set will, however, be no higher than the requested
  93. //! value.
  94. //!
  95. //! The \e ui32SysClk parameter provides the current system clock rate and is
  96. //! used to allow the LCD controller clock rate divisor to be correctly set
  97. //! to give the desired \e ui32PixClk rate.
  98. //!
  99. //! \return Returns the actual LCD controller pixel clock or MCLK rate set.
  100. //
  101. //*****************************************************************************
  102. uint32_t
  103. LCDModeSet(uint32_t ui32Base, uint8_t ui8Mode, uint32_t ui32PixClk,
  104. uint32_t ui32SysClk)
  105. {
  106. uint32_t ui32Div;
  107. //
  108. // Sanity check parameters.
  109. //
  110. ASSERT(ui32Base == LCD0_BASE);
  111. ASSERT((ui8Mode & ~(LCD_MODE_RASTER | LCD_MODE_LIDD |
  112. LCD_MODE_AUTO_UFLOW_RESTART)) == 0);
  113. //
  114. // Enable clocks to the LCD controller submodules.
  115. //
  116. HWREG(ui32Base + LCD_O_CLKEN) = (LCD_CLKEN_DMA | LCD_CLKEN_CORE |
  117. LCD_CLKEN_LIDD);
  118. //
  119. // Determine the clock divider to use to get as close as possible to the
  120. // desired pixel clock. Note that we set the division up so that we
  121. // round the divisor up and ensure that the clock used is never faster
  122. // than the requested rate.
  123. //
  124. ui32Div = (ui32SysClk + (ui32PixClk - 1)) / ui32PixClk;
  125. //
  126. // Check that the calculated value is valid.
  127. //
  128. ASSERT(ui32Div);
  129. ASSERT(ui32Div < 256);
  130. ASSERT(!((ui8Mode & LCD_MODE_RASTER) && (ui32Div < 2)));
  131. //
  132. // Write the LCDCTL register to set the mode.
  133. //
  134. HWREG(ui32Base + LCD_O_CTL) = (uint32_t)ui8Mode |
  135. (ui32Div << LCD_CTL_CLKDIV_S);
  136. //
  137. // Return the selected clock rate. Finding ui32Div set to 0 should not
  138. // happen unless someone passed pathological arguments and builds without
  139. // the ASSERTS, but we guard against it just in case.
  140. //
  141. return (ui32Div ? (ui32SysClk / ui32Div) : ui32SysClk);
  142. }
  143. //*****************************************************************************
  144. //
  145. //! Resets one or more of the LCD controller clock domains.
  146. //!
  147. //! \param ui32Base specifies the LCD controller module base address.
  148. //! \param ui32Clocks defines the subset of clock domains to be reset.
  149. //!
  150. //! This function allows sub-modules of the LCD controller to be reset under
  151. //! software control. The \e ui32Clocks parameter is the logical OR of the
  152. //! following clocks:
  153. //!
  154. //! - \b LCD_CLOCK_MAIN causes the entire LCD controller module to be reset.
  155. //! - \b LCD_CLOCK_DMA causes the DMA controller submodule to be reset.
  156. //! - \b LCD_CLOCK_LIDD causes the LIDD submodule to be reset.
  157. //! - \b LCD_CLOCK_CORE causes the core module, including the raster logic to
  158. //! be reset.
  159. //!
  160. //! In all cases, LCD controller register values are preserved across these
  161. //! resets.
  162. //!
  163. //! \return None.
  164. //
  165. //*****************************************************************************
  166. void
  167. LCDClockReset(uint32_t ui32Base, uint32_t ui32Clocks)
  168. {
  169. //
  170. // Sanity check parameters.
  171. //
  172. ASSERT(ui32Base == LCD0_BASE);
  173. ASSERT(!(ui32Clocks & ~(LCD_CLOCK_MAIN | LCD_CLOCK_LIDD | LCD_CLOCK_DMA |
  174. LCD_CLOCK_CORE)));
  175. //
  176. // Reset the required LCD controller sub-module(s).
  177. //
  178. HWREG(LCD0_BASE + 0x70) = ui32Clocks;
  179. //
  180. // Wait a while.
  181. //
  182. SysCtlDelay(10);
  183. //
  184. // Remove software reset.
  185. //
  186. HWREG(LCD0_BASE + 0x70) = 0x00000000;
  187. //
  188. // Wait a while.
  189. //
  190. SysCtlDelay(10);
  191. }
  192. //*****************************************************************************
  193. //
  194. //! Sets the LCD controller communication parameters when in LIDD mode.
  195. //!
  196. //! \param ui32Base specifies the LCD controller module base address.
  197. //! \param ui32Config defines the display interface configuration.
  198. //!
  199. //! This function is used when the LCD controller is configured in LIDD
  200. //! mode and specifies the configuration of the interface between the
  201. //! controller and the display panel. The \e ui32Config parameter is
  202. //! comprised of one of the following modes:
  203. //!
  204. //! - \b LIDD_CONFIG_SYNC_MPU68 selects Sync MPU68 mode. LCDCP = EN, LCDLP =
  205. //! DIR, LCDFP = ALE, LCDAC = CS0, LCDMCLK = MCLK.
  206. //! - \b LIDD_CONFIG_ASYNC_MPU68 selects Async MPU68 mode. LCDCP = EN, LCDLP =
  207. //! DIR, LCDFP = ALE, LCDAC = CS0, LCDMCLK = CS1.
  208. //! - \b LIDD_CONFIG_SYNC_MPU80 selects Sync MPU80 mode. LCDCP = RS, LCDLP =
  209. //! WS, LCDFP = ALE, LCDAC = CS0, LCDMCLK = MCLK.
  210. //! - \b LIDD_CONFIG_ASYNC_MPU80 selects Async MPU80 mode. LCDCP = RS, LCDLP =
  211. //! WS, LCDFP = ALE, LCDAC = CS0, LCDMCLK = CS1.
  212. //! - \b LIDD_CONFIG_ASYNC_HITACHI selects Hitachi (async) mode. LCDCP = N/C,
  213. //! LCDLP = DIR, LCDFP = ALE, LCDAC = E0, LCDMCLK = E1.
  214. //!
  215. //! Additional flags may be ORed into \e ui32Config to control the polarities
  216. //! of various control signals:
  217. //!
  218. //! - \b LIDD_CONFIG_INVERT_ALE - Address Latch Enable (ALE) polarity control.
  219. //! By default, ALE is active low. If this flag is set, it becomes active
  220. //! high.
  221. //! - \b LIDD_CONFIG_INVERT_RS_EN - Read Strobe/Enable polarity control. By
  222. //! default, RS is active low and Enable is active high. If this flag is set,
  223. //! RS becomes active high and Enable active low.
  224. //! - \b LIDD_CONFIG_INVERT_WS_DIR - Write Strobe/Direction polarity control.
  225. //! By default, WS is active low and Direction write low/read high. If this
  226. //! flag is set, WS becomes active high and Direction becomes write high/read
  227. //! low.
  228. //! - \b LIDD_CONFIG_INVERT_CS0 - Chip Select 0/Enable 0 polarity control. By
  229. //! default, CS0 and E0 are active high. If this flag is set, they become
  230. //! active low.
  231. //! - \b LIDD_CONFIG_INVERT_CS1 - Chip Select 1/Enable 1 polarity control. By
  232. //! default, CS1 and E1 are active high. If this flag is set, they become
  233. //! active low.
  234. //!
  235. //! \return None.
  236. //
  237. //*****************************************************************************
  238. void
  239. LCDIDDConfigSet(uint32_t ui32Base, uint32_t ui32Config)
  240. {
  241. //
  242. // Sanity check parameters.
  243. //
  244. ASSERT(ui32Base == LCD0_BASE);
  245. ASSERT(!(ui32Config & ~(LIDD_CONFIG_SYNC_MPU68 | LIDD_CONFIG_ASYNC_MPU68 |
  246. LIDD_CONFIG_SYNC_MPU80 | LIDD_CONFIG_ASYNC_MPU80 |
  247. LIDD_CONFIG_ASYNC_HITACHI |
  248. LIDD_CONFIG_INVERT_ALE |
  249. LIDD_CONFIG_INVERT_RS_EN |
  250. LIDD_CONFIG_INVERT_WS_DIR |
  251. LIDD_CONFIG_INVERT_CS0 | LIDD_CONFIG_INVERT_CS1)));
  252. //
  253. // Write the LIDD Control Register.
  254. //
  255. HWREG(ui32Base + LCD_O_LIDDCTL) = ui32Config;
  256. }
  257. //*****************************************************************************
  258. //
  259. //! Sets the LCD controller interface timing when in LIDD mode.
  260. //!
  261. //! \param ui32Base specifies the LCD controller module base address.
  262. //! \param ui32CS specifies the chip select whose timings are to be set.
  263. //! \param pTiming points to a structure containing the desired timing
  264. //! parameters.
  265. //!
  266. //! This function is used in LIDD mode to set the setup, strobe and hold times
  267. //! for the various interface control signals. Independent timings are stored
  268. //! for each of the two supported chip selects offered by the LCD controller.
  269. //!
  270. //! For a definition of the timing parameters required, see the definition of
  271. //! tLCDIDDTiming.
  272. //!
  273. //! \note CS1 is not available when operating in Sync MPU68 or Sync MPU80
  274. //! modes.
  275. //!
  276. //! \return None
  277. //
  278. //*****************************************************************************
  279. void
  280. LCDIDDTimingSet(uint32_t ui32Base, uint32_t ui32CS,
  281. const tLCDIDDTiming *pTiming)
  282. {
  283. uint32_t ui32Val;
  284. //
  285. // Sanity check parameters.
  286. //
  287. ASSERT(ui32Base == LCD0_BASE);
  288. ASSERT((ui32CS == 0) || (ui32CS == 1));
  289. ASSERT(pTiming);
  290. ASSERT(pTiming->ui8WSSetup < 32);
  291. ASSERT(pTiming->ui8WSDuration && (pTiming->ui8WSDuration < 64));
  292. ASSERT(pTiming->ui8WSHold && (pTiming->ui8WSHold < 16));
  293. ASSERT(pTiming->ui8RSSetup < 32);
  294. ASSERT(pTiming->ui8RSDuration && (pTiming->ui8RSDuration < 64));
  295. ASSERT(pTiming->ui8RSHold && (pTiming->ui8RSHold < 16));
  296. ASSERT(pTiming->ui8DelayCycles && (pTiming->ui8DelayCycles < 5));
  297. //
  298. // Convert the timings provided into a value ready for the register.
  299. //
  300. ui32Val =
  301. (((uint32_t)(pTiming->ui8WSSetup) << LCD_LIDDCS0CFG_WRSU_S) |
  302. ((uint32_t)(pTiming->ui8WSDuration) << LCD_LIDDCS0CFG_WRDUR_S) |
  303. ((uint32_t)(pTiming->ui8WSHold) << LCD_LIDDCS0CFG_WRHOLD_S) |
  304. ((uint32_t)(pTiming->ui8RSSetup) << LCD_LIDDCS0CFG_RDSU_S) |
  305. ((uint32_t)(pTiming->ui8RSDuration) << LCD_LIDDCS0CFG_RDDUR_S) |
  306. ((uint32_t)(pTiming->ui8RSHold) << LCD_LIDDCS0CFG_RDHOLD_S) |
  307. ((uint32_t)(pTiming->ui8DelayCycles - 1) << LCD_LIDDCS0CFG_GAP_S));
  308. //
  309. // Write the appropriate LCD LIDD CS configuration register.
  310. //
  311. if (!ui32CS)
  312. {
  313. HWREG(ui32Base + LCD_O_LIDDCS0CFG) = ui32Val;
  314. }
  315. else
  316. {
  317. HWREG(ui32Base + LCD_O_LIDDCS1CFG) = ui32Val;
  318. }
  319. }
  320. //*****************************************************************************
  321. //
  322. //! Disables internal DMA operation when the LCD controller is in LIDD mode.
  323. //!
  324. //! \param ui32Base specifies the LCD controller module base address.
  325. //!
  326. //! When the LCD controller is operating in LCD Interface Display Driver mode,
  327. //! this function must be called after completion of a DMA transaction and
  328. //! before calling LCDIDDCommandWrite(), LCDIDDDataWrite(), LCDIDDStatusRead(),
  329. //! LCDIDDIndexedWrite(), LCDIDDIndexedRead() or LCDIDDDataRead() to disable
  330. //! DMA mode and allow CPU-initiated transactions to the display.
  331. //!
  332. //! \note LIDD DMA mode is enabled automatically when LCDIDDDMAWrite() is
  333. //! called.
  334. //!
  335. //! \return None.
  336. //
  337. //*****************************************************************************
  338. void
  339. LCDIDDDMADisable(uint32_t ui32Base)
  340. {
  341. //
  342. // Sanity check parameters.
  343. //
  344. ASSERT(ui32Base == LCD0_BASE);
  345. //
  346. // Disable DMA.
  347. //
  348. HWREG(ui32Base + LCD_O_LIDDCTL) &= ~LCD_LIDDCTL_DMAEN;
  349. }
  350. //*****************************************************************************
  351. //
  352. //! Writes a command to the display when the LCD controller is in LIDD mode.
  353. //!
  354. //! \param ui32Base specifies the LCD controller module base address.
  355. //! \param ui32CS specifies the chip select to use. Valid values are 0 and 1.
  356. //! \param ui16Cmd is the 16-bit command word to write.
  357. //!
  358. //! This function writes a 16-bit command word to the display when the LCD
  359. //! controller is in LIDD mode. A command write occurs with the ALE signal
  360. //! active.
  361. //!
  362. //! This function must not be called if the LIDD interface is currently
  363. //! configured to expect DMA transactions. If DMA was previously used to
  364. //! write to the panel, LCDIDDDMADisable() must be called before this function
  365. //! can be used.
  366. //!
  367. //! \note CS1 is not available when operating in Sync MPU68 or Sync MPU80
  368. //! modes.
  369. //!
  370. //! \return None.
  371. //
  372. //*****************************************************************************
  373. void
  374. LCDIDDCommandWrite(uint32_t ui32Base, uint32_t ui32CS, uint16_t ui16Cmd)
  375. {
  376. uint32_t ui32Reg;
  377. //
  378. // Sanity check parameters.
  379. //
  380. ASSERT(ui32Base == LCD0_BASE);
  381. ASSERT((ui32CS == 0) || (ui32CS == 1));
  382. //
  383. // Determine the register to write based on the CS value supplied.
  384. //
  385. ui32Reg = ui32CS ? LCD_O_LIDDCS1ADDR : LCD_O_LIDDCS0ADDR;
  386. //
  387. // Write the command/address to the register.
  388. //
  389. HWREG(ui32Base + ui32Reg) = ui16Cmd;
  390. }
  391. //*****************************************************************************
  392. //
  393. //! Writes a data value to the display when the LCD controller is in LIDD mode.
  394. //!
  395. //! \param ui32Base specifies the LCD controller module base address.
  396. //! \param ui32CS specifies the chip select to use. Valid values are 0 and 1.
  397. //! \param ui16Data is the 16-bit data word to write.
  398. //!
  399. //! This function writes a 16-bit data word to the display when the LCD
  400. //! controller is in LIDD mode. A data write occurs with the ALE signal
  401. //! inactive.
  402. //!
  403. //! This function must not be called if the LIDD interface is currently
  404. //! configured to expect DMA transactions. If DMA was previously used to
  405. //! write to the panel, LCDIDDDMADisable() must be called before this function
  406. //! can be used.
  407. //!
  408. //! \note CS1 is not available when operating in Sync MPU68 or Sync MPU80
  409. //! modes.
  410. //!
  411. //! \return None.
  412. //
  413. //*****************************************************************************
  414. void
  415. LCDIDDDataWrite(uint32_t ui32Base, uint32_t ui32CS, uint16_t ui16Data)
  416. {
  417. uint32_t ui32Reg;
  418. //
  419. // Sanity check parameters.
  420. //
  421. ASSERT(ui32Base == LCD0_BASE);
  422. ASSERT((ui32CS == 0) || (ui32CS == 1));
  423. //
  424. // Determine the register to write based on the CS value supplied.
  425. //
  426. ui32Reg = ui32CS ? LCD_O_LIDDCS1DATA : LCD_O_LIDDCS0DATA;
  427. //
  428. // Write the data value to the register.
  429. //
  430. HWREG(ui32Base + ui32Reg) = ui16Data;
  431. }
  432. //*****************************************************************************
  433. //
  434. //! Writes data to a given display register when the LCD controller is in LIDD
  435. //! mode.
  436. //!
  437. //! \param ui32Base specifies the LCD controller module base address.
  438. //! \param ui32CS specifies the chip select to use. Valid values are 0 and 1.
  439. //! \param ui16Addr is the address of the display register to write.
  440. //! \param ui16Data is the data to write.
  441. //!
  442. //! This function writes a 16-bit data word to a register in the display when
  443. //! the LCD controller is in LIDD mode and configured to use either the
  444. //! Motorola (\b LIDD_CONFIG_SYNC_MPU68 or \b LIDD_CONFIG_ASYNC_MPU68) or
  445. //! Intel (\b LIDD_CONFIG_SYNC_MPU80 or \b LIDD_CONFIG_ASYNC_MPU80) modes
  446. //! that employ an external address latch.
  447. //!
  448. //! When configured in Hitachi mode (\b LIDD_CONFIG_ASYNC_HITACHI), this
  449. //! function should not be used. In this case the functions
  450. //! LCDIDDCommandWrite() and LCDIDDDataWrite() may be used to transfer
  451. //! command and data bytes to the panel.
  452. //!
  453. //! This function must not be called if the LIDD interface is currently
  454. //! configured to expect DMA transactions. If DMA was previously used to
  455. //! write to the panel, LCDIDDDMADisable() must be called before this function
  456. //! can be used.
  457. //!
  458. //! \note CS1 is not available when operating in Sync MPU68 or Sync MPU80
  459. //! modes.
  460. //!
  461. //! \return None.
  462. //
  463. //*****************************************************************************
  464. void
  465. LCDIDDIndexedWrite(uint32_t ui32Base, uint32_t ui32CS, uint16_t ui16Addr,
  466. uint16_t ui16Data)
  467. {
  468. uint32_t ui32Addr;
  469. //
  470. // Sanity check parameters.
  471. //
  472. ASSERT(ui32Base == LCD0_BASE);
  473. ASSERT((ui32CS == 0) || (ui32CS == 1));
  474. //
  475. // Determine the address register to write.
  476. //
  477. ui32Addr = ui32CS ? LCD_O_LIDDCS1ADDR : LCD_O_LIDDCS0ADDR;
  478. //
  479. // Write the address.
  480. //
  481. HWREG(ui32Base + ui32Addr) = ui16Addr;
  482. //
  483. // Determine the data register to write.
  484. //
  485. ui32Addr = ui32CS ? LCD_O_LIDDCS1DATA : LCD_O_LIDDCS0DATA;
  486. //
  487. // Write the data.
  488. //
  489. HWREG(ui32Base + ui32Addr) = ui16Data;
  490. }
  491. //*****************************************************************************
  492. //
  493. //! Reads a status word from the display when the LCD controller is in LIDD
  494. //! mode.
  495. //!
  496. //! \param ui32Base specifies the LCD controller module base address.
  497. //! \param ui32CS specifies the chip select to use. Valid values are 0 and 1.
  498. //!
  499. //! This function reads the 16-bit status word from the display when the LCD
  500. //! controller is in LIDD mode. A status read occurs with the ALE signal
  501. //! active. If the interface is configured in Hitachi mode (\b
  502. //! LIDD_CONFIG_ASYNC_HITACHI), this operation corresponds to a command mode
  503. //! read.
  504. //!
  505. //! This function must not be called if the LIDD interface is currently
  506. //! configured to expect DMA transactions. If DMA was previously used to
  507. //! write to the panel, LCDIDDDMADisable() must be called before this function
  508. //! can be used.
  509. //!
  510. //! \note CS1 is not available when operating in Sync MPU68 or Sync MPU80
  511. //! modes.
  512. //!
  513. //! \return Returns the status word read from the display panel.
  514. //
  515. //*****************************************************************************
  516. uint16_t
  517. LCDIDDStatusRead(uint32_t ui32Base, uint32_t ui32CS)
  518. {
  519. uint32_t ui32Reg;
  520. //
  521. // Sanity check parameters.
  522. //
  523. ASSERT(ui32Base == LCD0_BASE);
  524. ASSERT((ui32CS == 0) || (ui32CS == 1));
  525. //
  526. // Determine the register to read based on the CS value supplied.
  527. //
  528. ui32Reg = ui32CS ? LCD_O_LIDDCS1ADDR : LCD_O_LIDDCS0ADDR;
  529. //
  530. // Read the relevant status register.
  531. //
  532. return ((uint16_t)HWREG(ui32Base + ui32Reg));
  533. }
  534. //*****************************************************************************
  535. //
  536. //! Reads a data word from the display when the LCD controller is in LIDD
  537. //! mode.
  538. //!
  539. //! \param ui32Base specifies the LCD controller module base address.
  540. //! \param ui32CS specifies the chip select to use. Valid values are 0 and 1.
  541. //!
  542. //! This function reads the 16-bit data word from the display when the LCD
  543. //! controller is in LIDD mode. A data read occurs with the ALE signal
  544. //! inactive.
  545. //!
  546. //! This function must not be called if the LIDD interface is currently
  547. //! configured to expect DMA transactions. If DMA was previously used to
  548. //! write to the panel, LCDIDDDMADisable() must be called before this function
  549. //! can be used.
  550. //!
  551. //! \note CS1 is not available when operating in Sync MPU68 or Sync MPU80
  552. //! modes.
  553. //!
  554. //! \return Returns the status word read from the display panel.
  555. //
  556. //*****************************************************************************
  557. uint16_t
  558. LCDIDDDataRead(uint32_t ui32Base, uint32_t ui32CS)
  559. {
  560. uint32_t ui32Reg;
  561. //
  562. // Sanity check parameters.
  563. //
  564. ASSERT(ui32Base == LCD0_BASE);
  565. ASSERT((ui32CS == 0) || (ui32CS == 1));
  566. //
  567. // Determine the register to read based on the CS value supplied.
  568. //
  569. ui32Reg = ui32CS ? LCD_O_LIDDCS1DATA : LCD_O_LIDDCS0DATA;
  570. //
  571. // Read the relevant data register.
  572. //
  573. return ((uint16_t)HWREG(ui32Base + ui32Reg));
  574. }
  575. //*****************************************************************************
  576. //
  577. //! Reads a given display register when the LCD controller is in LIDD mode.
  578. //!
  579. //! \param ui32Base specifies the LCD controller module base address.
  580. //! \param ui32CS specifies the chip select to use. Valid values are 0 and 1.
  581. //! \param ui16Addr is the address of the display register to read.
  582. //!
  583. //! This function reads a 16-bit word from a register in the display when
  584. //! the LCD controller is in LIDD mode and configured to use either the
  585. //! Motorola (\b LIDD_CONFIG_SYNC_MPU68 or \b LIDD_CONFIG_ASYNC_MPU68) or
  586. //! Intel (\b LIDD_CONFIG_SYNC_MPU80 or \b LIDD_CONFIG_ASYNC_MPU80) modes
  587. //! that employ an external address latch.
  588. //!
  589. //! When configured in Hitachi mode (\b LIDD_CONFIG_ASYNC_HITACHI), this
  590. //! function should not be used. In this case, the functions
  591. //! LCDIDDStatusRead() and LCDIDDDataRead() may be used to read status
  592. //! and data bytes from the panel.
  593. //!
  594. //! This function must not be called if the LIDD interface is currently
  595. //! configured to expect DMA transactions. If DMA was previously used to
  596. //! write to the panel, LCDIDDDMADisable() must be called before this function
  597. //! can be used.
  598. //!
  599. //! \note CS1 is not available when operating in Sync MPU68 or Sync MPU80
  600. //! modes.
  601. //!
  602. //! \return None.
  603. //
  604. //*****************************************************************************
  605. uint16_t
  606. LCDIDDIndexedRead(uint32_t ui32Base, uint32_t ui32CS, uint16_t ui16Addr)
  607. {
  608. uint32_t ui32Addr;
  609. //
  610. // Sanity check parameters.
  611. //
  612. ASSERT(ui32Base == LCD0_BASE);
  613. ASSERT((ui32CS == 0) || (ui32CS == 1));
  614. //
  615. // Determine the address register to write.
  616. //
  617. ui32Addr = ui32CS ? LCD_O_LIDDCS1ADDR : LCD_O_LIDDCS0ADDR;
  618. //
  619. // Write the address.
  620. //
  621. HWREG(ui32Base + ui32Addr) = ui16Addr;
  622. //
  623. // Determine the data register to read.
  624. //
  625. ui32Addr = ui32CS ? LCD_O_LIDDCS1DATA : LCD_O_LIDDCS0DATA;
  626. //
  627. // Return the data read.
  628. //
  629. return ((uint16_t)HWREG(ui32Base + ui32Addr));
  630. }
  631. //*****************************************************************************
  632. //
  633. //! Writes a block of data to the display using DMA when the LCD controller is
  634. //! in LIDD mode.
  635. //!
  636. //! \param ui32Base specifies the LCD controller module base address.
  637. //! \param ui32CS specifies the chip select to use. Valid values are 0 and 1.
  638. //! \param pui32Data is the address of the first 16-bit word to write. This
  639. //! address must be aligned on a 32-bit word boundary.
  640. //! \param ui32Count is the number of 16-bit words to write. This value must
  641. //! be a multiple of 2.
  642. //!
  643. //! This function writes a block of 16-bit data words to the display using
  644. //! DMA. It is only valid when the LCD controller is in LIDD mode.
  645. //! Completion of the DMA transfer is signaled by the \b
  646. //! LCD_INT_DMA_DONE interrupt.
  647. //!
  648. //! This function enables DMA mode prior to starting the transfer. The
  649. //! caller is responsible for ensuring that any earlier DMA transfer has
  650. //! completed before initiating another transfer.
  651. //!
  652. //! During the time that DMA is enabled, none of the other LCD LIDD data
  653. //! transfer functions may be called. When the DMA transfer is complete and
  654. //! the application wishes to use the CPU to communicate with the display,
  655. //! LCDIDDDMADisable() must be called to disable DMA access prior to calling
  656. //! LCDIDDCommandWrite(), LCDIDDDataWrite(), LCDIDDStatusRead(),
  657. //! LCDIDDIndexedWrite(), LCDIDDIndexedRead() or LCDIDDDataRead().
  658. //!
  659. //! \note CS1 is not available when operating in Sync MPU68 or Sync MPU80
  660. //! modes.
  661. //!
  662. //! \return None.
  663. //
  664. //*****************************************************************************
  665. void
  666. LCDIDDDMAWrite(uint32_t ui32Base, uint32_t ui32CS, const uint32_t *pui32Data,
  667. uint32_t ui32Count)
  668. {
  669. //
  670. // Sanity check parameters.
  671. //
  672. ASSERT(ui32Base == LCD0_BASE);
  673. ASSERT((ui32CS == 0) || (ui32CS == 1));
  674. ASSERT(!((uint32_t)pui32Data & 3));
  675. ASSERT(!(ui32Count & 1));
  676. //
  677. // Make sure DMA is disabled so that enabling it triggers this new
  678. // transfer.
  679. //
  680. HWREG(ui32Base + LCD_O_LIDDCTL) &= ~LCD_LIDDCTL_DMAEN;
  681. //
  682. // Set up the transfer. Note that the ceiling register must contain the
  683. // address of the last word which contains data we want transfered and NOT
  684. // the first location after the data we want written.
  685. //
  686. HWREG(ui32Base + LCD_O_DMABAFB0) = (uint32_t)pui32Data;
  687. HWREG(ui32Base + LCD_O_DMACAFB0) = ((uint32_t)pui32Data +
  688. (ui32Count * 2) - 4);
  689. //
  690. // Tell the controller which CS to use for the DMA transaction.
  691. //
  692. if (!ui32CS)
  693. {
  694. //
  695. // Use CS0.
  696. //
  697. HWREG(ui32Base + LCD_O_LIDDCTL) &= ~LCD_LIDDCTL_DMACS;
  698. }
  699. else
  700. {
  701. //
  702. // Use CS1.
  703. //
  704. HWREG(ui32Base + LCD_O_LIDDCTL) |= LCD_LIDDCTL_DMACS;
  705. }
  706. //
  707. // Enable the DMA engine and start the transaction.
  708. //
  709. HWREG(ui32Base + LCD_O_LIDDCTL) |= LCD_LIDDCTL_DMAEN;
  710. }
  711. //*****************************************************************************
  712. //
  713. //! Sets the LCD controller interface timing when in raster mode.
  714. //!
  715. //! \param ui32Base specifies the LCD controller module base address.
  716. //! \param ui32Config specifies properties of the raster interface and the
  717. //! attached display panel.
  718. //! \param ui8PalLoadDelay specifies the number of system clocks to wait
  719. //! between each 16 halfword (16-bit) burst when loading the palette from
  720. //! SRAM into the internal palette RAM of the controller.
  721. //!
  722. //! This function configures the basic operating mode of the raster interface
  723. //! and specifies the type of panel that the controller is to drive.
  724. //!
  725. //! The \e ui32Config parameter must be defined as one of the following to
  726. //! select the required target panel type and output pixel format:
  727. //!
  728. //! - \b RASTER_FMT_ACTIVE_24BPP_PACKED selects an active matrix display
  729. //! and uses a packed 24-bit per pixel packet frame buffer where 4 pixels
  730. //! are described within 3 consecutive 32-bit words.
  731. //! - \b RASTER_FMT_ACTIVE_24BPP_UNPACKED selects an active matrix display
  732. //! and uses an unpacked 24-bit per pixel packet frame buffer where each
  733. //! 32-bit word contains a single pixel and 8 bits of padding.
  734. //! - \b RASTER_FMT_ACTIVE_16BPP selects an active matrix display
  735. //! and uses a 16-bit per pixel frame buffer with 2 pixels in each 32-bit
  736. //! word.
  737. //! - \b RASTER_FMT_ACTIVE_PALETTIZED_12BIT selects an active matrix display
  738. //! and uses a 1, 2, 4 or 8bpp frame buffer with palette lookup. Output color
  739. //! data is described in 12-bit format using bits 11:0 of the data bus. The
  740. //! frame buffer pixel format is defined by the value passed in the \e ui32Type
  741. //! parameter to LCDRasterPaletteSet().
  742. //! - \b RASTER_FMT_ACTIVE_PALETTIZED_16BIT selects an active matrix display
  743. //! and uses a 1, 2, 4 or 8bpp frame buffer with palette lookup. Output color
  744. //! data is described in 16-bit 5:6:5 format. The frame buffer pixel format is
  745. //! defined by the value passed in the \e ui32Type parameter to
  746. //! LCDRasterPaletteSet().
  747. //! - \b RASTER_FMT_PASSIVE_MONO_4PIX selects a monochrome, passive matrix
  748. //! display that outputs 4 pixels on each pixel clock.
  749. //! - \b RASTER_FMT_PASSIVE_MONO_8PIX selects a monochrome, passive matrix
  750. //! display that outputs 8 pixels on each pixel clock.
  751. //! - \b RASTER_FMT_PASSIVE_COLOR_12BIT selects a passive matrix display
  752. //! and uses a 12bpp frame buffer. The palette is bypassed and 12-bit pixel
  753. //! data is sent to the grayscaler for the display.
  754. //! - \b RASTER_FMT_PASSIVE_COLOR_16BIT selects a passive matrix display
  755. //! and uses a 16bpp frame buffer with pixels in 5:6:5 format. Only the 4
  756. //! most significant bits of each color component are sent to the grayscaler
  757. //! for the display.
  758. //!
  759. //! Additionally, the following flags may be ORed into \e ui32Config:
  760. //!
  761. //! - \b RASTER_ACTVID_DURING_BLANK sets Actvid to toggle during vertical
  762. //! blanking.
  763. //! - \b RASTER_NIBBLE_MODE_ENABLED enables nibble mode. This parameter works
  764. //! with \b RASTER_READ_ORDER_REVERSED to determine how 1, 2 and 4bpp pixels
  765. //! are extracted from words read from the frame buffer. If specified, words
  766. //! read from the frame buffer are byte swapped prior to individual pixels
  767. //! being parsed from them.
  768. //! - \b RASTER_LOAD_DATA_ONLY tells the controller to read only pixel data
  769. //! from the frame buffer and to use the last palette read. No palette load
  770. //! is performed.
  771. //! - \b RASTER_LOAD_PALETTE_ONLY tells the controller to read only the palette
  772. //! data from the frame buffer.
  773. //! - \b RASTER_READ_ORDER_REVERSED when using 1, 2, 4 and 8bpp frame buffers,
  774. //! this option reverses the order in which frame buffer words are parsed.
  775. //! When this option is specified, the leftmost pixel in a word is taken from
  776. //! the most significant bits. When absent, the leftmost pixel is parsed from
  777. //! the least significant bits.
  778. //!
  779. //! If the LCD controller's raster engine is enabled when this function is
  780. //! called, it is disabled as a result of the call.
  781. //!
  782. //! \return None.
  783. //
  784. //*****************************************************************************
  785. void
  786. LCDRasterConfigSet(uint32_t ui32Base, uint32_t ui32Config,
  787. uint8_t ui8PalLoadDelay)
  788. {
  789. //
  790. // Sanity check parameters.
  791. //
  792. ASSERT(ui32Base == LCD0_BASE);
  793. ASSERT(!(ui32Config & ~(RASTER_FMT_ACTIVE_24BPP_PACKED |
  794. RASTER_FMT_ACTIVE_24BPP_UNPACKED |
  795. RASTER_FMT_ACTIVE_PALETTIZED_12BIT |
  796. RASTER_FMT_ACTIVE_PALETTIZED_16BIT |
  797. RASTER_FMT_PASSIVE_MONO_4PIX |
  798. RASTER_FMT_PASSIVE_MONO_8PIX |
  799. RASTER_FMT_PASSIVE_PALETTIZED |
  800. RASTER_FMT_PASSIVE_COLOR_12BIT |
  801. RASTER_FMT_PASSIVE_COLOR_16BIT |
  802. RASTER_ACTVID_DURING_BLANK |
  803. RASTER_NIBBLE_MODE_ENABLED |
  804. RASTER_LOAD_DATA_ONLY |
  805. RASTER_LOAD_PALETTE_ONLY |
  806. RASTER_READ_ORDER_REVERSED)));
  807. //
  808. // Write the raster control register.
  809. //
  810. HWREG(ui32Base + LCD_O_RASTRCTL) = (ui32Config |
  811. ((uint32_t)ui8PalLoadDelay <<
  812. LCD_RASTRCTL_REQDLY_S));
  813. }
  814. //*****************************************************************************
  815. //
  816. //! Sets the LCD controller interface timing when in raster mode.
  817. //!
  818. //! \param ui32Base specifies the LCD controller module base address.
  819. //! \param pTiming points to a structure containing the desired timing
  820. //! parameters.
  821. //!
  822. //! This function is used in raster mode to set the panel size and sync timing
  823. //! parameters.
  824. //!
  825. //! For a definition of the timing parameters required, see the definition of
  826. //! tLCDRasterTiming.
  827. //!
  828. //! \return None
  829. //
  830. //*****************************************************************************
  831. void
  832. LCDRasterTimingSet(uint32_t ui32Base, const tLCDRasterTiming *pTiming)
  833. {
  834. uint32_t ui32T0, ui32T1, ui32T2;
  835. //
  836. // Sanity check parameters.
  837. //
  838. ASSERT(ui32Base == LCD0_BASE);
  839. ASSERT(pTiming);
  840. ASSERT(!(pTiming->ui32Flags & ~(RASTER_TIMING_SYNCS_OPPOSITE_PIXCLK |
  841. RASTER_TIMING_SYNCS_ON_FALLING_PIXCLK |
  842. RASTER_TIMING_SYNCS_ON_RISING_PIXCLK |
  843. RASTER_TIMING_ACTIVE_LOW_OE |
  844. RASTER_TIMING_ACTIVE_LOW_PIXCLK |
  845. RASTER_TIMING_ACTIVE_LOW_HSYNC |
  846. RASTER_TIMING_ACTIVE_LOW_VSYNC)));
  847. ASSERT(pTiming->ui16PanelWidth && (pTiming->ui16PanelWidth <= 2048) &&
  848. ((pTiming->ui16PanelWidth % 16) == 0));
  849. ASSERT(pTiming->ui16PanelHeight && (pTiming->ui16PanelHeight <= 2048));
  850. ASSERT(pTiming->ui16HFrontPorch && (pTiming->ui16HFrontPorch <= 1024));
  851. ASSERT(pTiming->ui16HBackPorch && (pTiming->ui16HBackPorch <= 1024));
  852. ASSERT(pTiming->ui16HSyncWidth && (pTiming->ui16HSyncWidth <= 1024));
  853. ASSERT(pTiming->ui8VSyncWidth && (pTiming->ui8VSyncWidth <= 64));
  854. //
  855. // Construct the values we need for the three raster timing registers.
  856. //
  857. ui32T0 = ((uint32_t)((pTiming->ui16HBackPorch - 1) & 0xFF) <<
  858. LCD_RASTRTIM0_HBP_S) |
  859. ((uint32_t)((pTiming->ui16HFrontPorch - 1) & 0xFF) <<
  860. LCD_RASTRTIM0_HFP_S) |
  861. ((uint32_t)((pTiming->ui16HSyncWidth - 1) & 0x3F) <<
  862. LCD_RASTRTIM0_HSW_S) |
  863. (((uint32_t)((pTiming->ui16PanelWidth - 1) & 0x3F0) >> 4) <<
  864. LCD_RASTRTIM0_PPL_S) |
  865. (((uint32_t)((pTiming->ui16PanelWidth - 1) & 0x400) >> 10) <<
  866. LCD_RASTRTIM0_MSBPPL_S);
  867. ui32T1 = ((uint32_t)pTiming->ui8VBackPorch << LCD_RASTRTIM1_VBP_S) |
  868. ((uint32_t)pTiming->ui8VFrontPorch << LCD_RASTRTIM1_VFP_S) |
  869. ((uint32_t)((pTiming->ui8VSyncWidth - 1) & 0x3F) <<
  870. LCD_RASTRTIM1_VSW_S) |
  871. ((uint32_t)(pTiming->ui16PanelHeight - 1) & 0x3FF) <<
  872. LCD_RASTRTIM1_LPP_S;
  873. ui32T2 = pTiming->ui32Flags |
  874. ((((pTiming->ui16HSyncWidth - 1) & 0x3C0) >> 6) <<
  875. LCD_RASTRTIM2_HSW_S) |
  876. ((((pTiming->ui16PanelHeight - 1) & 0x400) >> 10) <<
  877. LCD_RASTRTIM2_MSBLPP_S) |
  878. ((((pTiming->ui16HBackPorch - 1) & 0x300) >> 8) <<
  879. LCD_RASTRTIM2_MSBHBP_S) |
  880. ((((pTiming->ui16HFrontPorch - 1) & 0x300) >> 8) <<
  881. LCD_RASTRTIM2_MSBHFP_S) |
  882. (pTiming->ui8ACBiasLineCount << LCD_RASTRTIM2_ACBF_S);
  883. //
  884. // Write the timing registers, taking care to preserve any existing value
  885. // in the AC Bias interrupt field of RASTRTIM2.
  886. //
  887. HWREG(ui32Base + LCD_O_RASTRTIM0) = ui32T0;
  888. HWREG(ui32Base + LCD_O_RASTRTIM1) = ui32T1;
  889. HWREG(ui32Base + LCD_O_RASTRTIM2) = (HWREG(ui32Base + LCD_O_RASTRTIM2) &
  890. LCD_RASTRTIM2_ACBI_M) | ui32T2;
  891. }
  892. //*****************************************************************************
  893. //
  894. //! Sets the number of AC bias pin transitions per interrupt.
  895. //!
  896. //! \param ui32Base is the base address of the controller.
  897. //! \param ui8Count is the number of AC bias pin transitions to count before
  898. //! the AC bias count interrupt is asserted. Valid values are from 0 to 15.
  899. //!
  900. //! This function is used to set the number of AC bias transitions between
  901. //! each AC bias count interrupt (\b LCD_INT_AC_BIAS_CNT). If \e ui8Count is
  902. //! 0, no AC bias count interrupt is generated.
  903. //!
  904. //! \return None.
  905. //
  906. //*****************************************************************************
  907. void
  908. LCDRasterACBiasIntCountSet(uint32_t ui32Base, uint8_t ui8Count)
  909. {
  910. uint32_t ui32Val;
  911. //
  912. // Sanity check parameters.
  913. //
  914. ASSERT(ui32Base == LCD0_BASE);
  915. ASSERT(ui8Count < 16);
  916. //
  917. // Get the existing raster timing 2 register value and mask in the new
  918. // AC Bias interrupt count.
  919. //
  920. ui32Val = HWREG(ui32Base + LCD_O_RASTRTIM2);
  921. ui32Val &= ~LCD_RASTRTIM2_ACBI_M;
  922. ui32Val |= ((ui8Count << LCD_RASTRTIM2_ACBI_S) & LCD_RASTRTIM2_ACBI_M);
  923. //
  924. // Write the new value back to the register.
  925. //
  926. HWREG(ui32Base + LCD_O_RASTRTIM2) = ui32Val;
  927. }
  928. //*****************************************************************************
  929. //
  930. //! Enables the raster output.
  931. //!
  932. //! \param ui32Base is the base address of the controller.
  933. //!
  934. //! This function enables the LCD controller raster output and starts
  935. //! displaying the content of the current frame buffer on the attached panel.
  936. //! Prior to enabling the raster output, LCDModeSet(), LCDRasterConfigSet(),
  937. //! LCDDMAConfigSet(), LCDRasterTimingSet(), LCDRasterPaletteSet() and
  938. //! LCDRasterFrameBufferSet() must have been called.
  939. //!
  940. //! \return None.
  941. //
  942. //*****************************************************************************
  943. void
  944. LCDRasterEnable(uint32_t ui32Base)
  945. {
  946. //
  947. // Sanity check parameters.
  948. //
  949. ASSERT(ui32Base == LCD0_BASE);
  950. //
  951. // Reset the module prior to starting the raster. This is required to
  952. // ensure correct operation of the raster engine.
  953. //
  954. LCDClockReset(ui32Base, LCD_CLOCK_MAIN);
  955. //
  956. // Enable the raster engine.
  957. //
  958. HWREG(ui32Base + LCD_O_RASTRCTL) |= LCD_RASTRCTL_LCDEN;
  959. }
  960. //*****************************************************************************
  961. //
  962. //! Determines whether or not the raster output is currently enabled.
  963. //!
  964. //! \param ui32Base is the base address of the controller.
  965. //!
  966. //! This function may be used to query whether or not the raster output is
  967. //! currently enabled.
  968. //!
  969. //! \return Returns \b true if the raster is enabled or \b false if it is
  970. //! disabled.
  971. //
  972. //*****************************************************************************
  973. bool
  974. LCDRasterEnabled(uint32_t ui32Base)
  975. {
  976. //
  977. // Sanity check parameters.
  978. //
  979. ASSERT(ui32Base == LCD0_BASE);
  980. //
  981. // Return the current raster engine status.
  982. //
  983. return ((HWREG(ui32Base + LCD_O_RASTRCTL) & LCD_RASTRCTL_LCDEN) ?
  984. true : false);
  985. }
  986. //*****************************************************************************
  987. //
  988. //! Disables the raster output.
  989. //!
  990. //! \param ui32Base is the base address of the controller.
  991. //!
  992. //! This function disables the LCD controller raster output and stops driving
  993. //! the attached display.
  994. //!
  995. //! \note Once disabled, the raster engine continues to scan data until the
  996. //! end of the current frame. If the display is to be re-enabled, wait until
  997. //! after the final \b LCD_INT_RASTER_FRAME_DONE has been received, indicating
  998. //! that the raster engine has stopped.
  999. //!
  1000. //! \return None.
  1001. //
  1002. //*****************************************************************************
  1003. void
  1004. LCDRasterDisable(uint32_t ui32Base)
  1005. {
  1006. //
  1007. // Sanity check parameters.
  1008. //
  1009. ASSERT(ui32Base == LCD0_BASE);
  1010. //
  1011. // Disable the raster engine.
  1012. //
  1013. HWREG(ui32Base + LCD_O_RASTRCTL) &= ~LCD_RASTRCTL_LCDEN;
  1014. }
  1015. //*****************************************************************************
  1016. //
  1017. //! Sets the position and size of the subpanel on the raster display.
  1018. //!
  1019. //! \param ui32Base is the base address of the controller.
  1020. //! \param ui32Flags may be either \b LCD_SUBPANEL_AT_TOP to show frame buffer
  1021. //! image data in the top portion of the display and default color in the
  1022. //! bottom portion, or \b LCD_SUBPANEL_AT_BOTTOM to show image data at the
  1023. //! bottom of the display and default color at the top.
  1024. //! \param ui32BottomLines defines the number of lines comprising the bottom
  1025. //! portion of the display. If \b LCD_SUBPANEL_AT_TOP is set in \e ui32Flags,
  1026. //! these lines contain the default pixel color when the subpanel is
  1027. //! enabled, otherwise they contain image data.
  1028. //! \param ui32DefaultPixel is the 24-bit RGB color to show in the portion of
  1029. //! the display not configured to show image data.
  1030. //!
  1031. //! The LCD controller provides a feature that allows a portion of the display
  1032. //! to be filled with a default color rather than image data from the frame
  1033. //! buffer. This feature reduces SRAM bandwidth requirements because no data
  1034. //! is fetched for lines containing the default color. This feature is only
  1035. //! available when the LCD controller is in raster mode and configured to drive
  1036. //! an active matrix display.
  1037. //!
  1038. //! The subpanel area containing image data from the frame buffer may be
  1039. //! positioned either at the top or bottom of the display as controlled by
  1040. //! the value of \e ui32Flags. The height of the bottom portion of the display
  1041. //! is defined by \e ui32BottomLines.
  1042. //!
  1043. //! When a subpanel is configured, the application must also reconfigure the
  1044. //! frame buffer to ensure that it contains the correct number of lines for
  1045. //! the subpanel size in use. This configuration can be achieved by calling
  1046. //! LCDRasterFrameBufferSet() with the \e ui32NumBytes parameter set
  1047. //! appropriately to describe the required number of active video lines in
  1048. //! the subpanel area.
  1049. //!
  1050. //! The subpanel display mode is not enabled using this function. To enable
  1051. //! the subpanel once it has been configured, call LCDRasterSubPanelEnable().
  1052. //!
  1053. //! \return None.
  1054. //
  1055. //*****************************************************************************
  1056. void
  1057. LCDRasterSubPanelConfigSet(uint32_t ui32Base, uint32_t ui32Flags,
  1058. uint32_t ui32BottomLines, uint32_t ui32DefaultPixel)
  1059. {
  1060. //
  1061. // Sanity check parameters.
  1062. //
  1063. ASSERT(ui32Base == LCD0_BASE);
  1064. ASSERT((ui32Flags == LCD_SUBPANEL_AT_TOP) ||
  1065. (ui32Flags == LCD_SUBPANEL_AT_BOTTOM));
  1066. ASSERT(ui32BottomLines && (ui32BottomLines <= 2048));
  1067. //
  1068. // Adjust the line count into the 0-2047 range.
  1069. //
  1070. ui32BottomLines--;
  1071. //
  1072. // Set the first subpanel configuration register, taking care to leave the
  1073. // subpanel enabled if it already was.
  1074. //
  1075. HWREG(ui32Base + LCD_O_RASTRSUBP1) = (HWREG(ui32Base + LCD_O_RASTRSUBP1) &
  1076. LCD_RASTRSUBP1_SPEN) | ui32Flags |
  1077. ((ui32DefaultPixel & 0xFFFF) <<
  1078. LCD_RASTRSUBP1_DPDLSB_S) |
  1079. ((ui32BottomLines <<
  1080. LCD_RASTRSUBP1_LPPT_S) &
  1081. LCD_RASTRSUBP1_LPPT_M);
  1082. //
  1083. // Set the second subpanel configuration register.
  1084. //
  1085. HWREG(ui32Base + LCD_O_RASTRSUBP2) =
  1086. ((ui32DefaultPixel >> 16) & LCD_RASTRSUBP2_DPDMSB_M) |
  1087. (((ui32BottomLines >> LCD_RASTRSUBP1_LPPT_S) & 1) << 8);
  1088. }
  1089. //*****************************************************************************
  1090. //
  1091. //! Enables subpanel display mode.
  1092. //!
  1093. //! \param ui32Base is the base address of the controller.
  1094. //!
  1095. //! This function enables subpanel display mode and displays a default color
  1096. //! rather than image data in the number of lines and at the position specified
  1097. //! by a previous call to LCDRasterSubPanelConfigSet(). Prior to calling
  1098. //! LCDRasterSubPanelEnable(), the frame buffer should have been reconfigured
  1099. //! to match the desired subpanel size using a call to
  1100. //! LCDRasterFrameBufferSet().
  1101. //!
  1102. //! Subpanel display is only possible when the LCD controller is in raster
  1103. //! mode and is configured to drive an active matrix display.
  1104. //!
  1105. //! \return None.
  1106. //
  1107. //*****************************************************************************
  1108. void
  1109. LCDRasterSubPanelEnable(uint32_t ui32Base)
  1110. {
  1111. //
  1112. // Sanity check parameters.
  1113. //
  1114. ASSERT(ui32Base == LCD0_BASE);
  1115. //
  1116. // Enable the subpanel.
  1117. //
  1118. HWREG(ui32Base + LCD_O_RASTRSUBP1) |= LCD_RASTRSUBP1_SPEN;
  1119. }
  1120. //*****************************************************************************
  1121. //
  1122. //! Disables subpanel display mode.
  1123. //!
  1124. //! \param ui32Base is the base address of the controller.
  1125. //!
  1126. //! This function disables subpanel display mode and reverts to showing the
  1127. //! entire frame buffer image on the display. After the subpanel is disabled,
  1128. //! the frame buffer size must be reconfigured to match the full dimensions of
  1129. //! the display area by calling LCDRasterFrameBufferSet() with an appropriate
  1130. //! value for the \e ui32NumBytes parameter.
  1131. //!
  1132. //! \return None.
  1133. //
  1134. //*****************************************************************************
  1135. void
  1136. LCDRasterSubPanelDisable(uint32_t ui32Base)
  1137. {
  1138. //
  1139. // Sanity check parameters.
  1140. //
  1141. ASSERT(ui32Base == LCD0_BASE);
  1142. //
  1143. // Disable the subpanel.
  1144. //
  1145. HWREG(ui32Base + LCD_O_RASTRSUBP1) &= ~LCD_RASTRSUBP1_SPEN;
  1146. }
  1147. //*****************************************************************************
  1148. //
  1149. //! Configures the LCD controller's internal DMA engine.
  1150. //!
  1151. //! \param ui32Base is the base address of the controller.
  1152. //! \param ui32Config provides flags defining the desired DMA parameters.
  1153. //!
  1154. //! This function is used to configure the DMA engine within the LCD
  1155. //! controller. This engine is responsible for performing bulk data transfers
  1156. //! to the display when in LIDD mode or for transferring palette and pixel data
  1157. //! from SRAM to the display panel when in raster mode.
  1158. //!
  1159. //! The \e ui32Config parameter is a logical OR of various flags. It must
  1160. //! contain one value from each of the following groups.
  1161. //!
  1162. //! The first group of flags set the number of words that have to be in the
  1163. //! FIFO before it signals that it is ready:
  1164. //!
  1165. //! - \b LCD_DMA_FIFORDY_8_WORDS
  1166. //! - \b LCD_DMA_FIFORDY_16_WORDS
  1167. //! - \b LCD_DMA_FIFORDY_32_WORDS
  1168. //! - \b LCD_DMA_FIFORDY_64_WORDS
  1169. //! - \b LCD_DMA_FIFORDY_128_WORDS
  1170. //! - \b LCD_DMA_FIFORDY_256_WORDS
  1171. //! - \b LCD_DMA_FIFORDY_512_WORDS
  1172. //!
  1173. //! The second group of flags set the number of 32-bit words in each DMA burst
  1174. //! transfer:
  1175. //!
  1176. //! - \b LCD_DMA_BURST_1
  1177. //! - \b LCD_DMA_BURST_2
  1178. //! - \b LCD_DMA_BURST_4
  1179. //! - \b LCD_DMA_BURST_8
  1180. //! - \b LCD_DMA_BURST_16
  1181. //!
  1182. //! The final group of flags set internal byte lane controls and allow byte
  1183. //! swapping within the DMA engine. The label represents the output byte order
  1184. //! for an input 32-bit word ordered ``0123''.
  1185. //!
  1186. //! - \b LCD_DMA_BYTE_ORDER_0123
  1187. //! - \b LCD_DMA_BYTE_ORDER_1023
  1188. //! - \b LCD_DMA_BYTE_ORDER_3210
  1189. //! - \b LCD_DMA_BYTE_ORDER_2301
  1190. //!
  1191. //! Additionally, \b LCD_DMA_PING_PONG may be specified. This flag configures
  1192. //! the controller to operate in double-buffered mode. When data is scanned
  1193. //! out from the first frame buffer, the DMA engine immediately moves to
  1194. //! the second frame buffer and scans from there before moving back to the
  1195. //! first. If this flag is clear, the DMA engine uses a single frame buffer,
  1196. //! restarting the scan from the beginning of the buffer each time it completes
  1197. //! a frame.
  1198. //!
  1199. //! \note DMA burst size \b LCD_DMA_BURST_16 should be set when using frame
  1200. //! buffers in external, EPI-connected memory. Using a smaller burst size in
  1201. //! this case is likely to result in occasional FIFO underflows and associated
  1202. //! display glitches.
  1203. //!
  1204. //! \return None.
  1205. //
  1206. //*****************************************************************************
  1207. void
  1208. LCDDMAConfigSet(uint32_t ui32Base, uint32_t ui32Config)
  1209. {
  1210. //
  1211. // Sanity check parameters.
  1212. //
  1213. ASSERT(ui32Base == LCD0_BASE);
  1214. ASSERT(!(ui32Config & ~(LCD_DMACTL_FIFORDY_M | LCD_DMACTL_BURSTSZ_M |
  1215. LCD_DMACTL_BYTESWAP | LCD_DMACTL_BIGDEND |
  1216. LCD_DMACTL_FMODE)));
  1217. //
  1218. // Write the DMA control register.
  1219. //
  1220. HWREG(ui32Base + LCD_O_DMACTL) = ui32Config;
  1221. }
  1222. //*****************************************************************************
  1223. //
  1224. //! Initializes the color palette in a frame buffer.
  1225. //!
  1226. //! \param ui32Base is the base address of the controller.
  1227. //! \param ui32Type specifies the type of pixel data to be held in the frame
  1228. //! buffer and also the format of the source color values passed.
  1229. //! \param pui32Addr points to the start of the frame buffer into which the
  1230. //! palette information is to be written.
  1231. //! \param pui32SrcColors points to the first color value that is to be
  1232. //! written into the frame buffer palette.
  1233. //! \param ui32Start specifies the index of the first color in the palette
  1234. //! to update.
  1235. //! \param ui32Count specifies the number of source colors to be copied into
  1236. //! the frame buffer palette.
  1237. //!
  1238. //! This function is used to initialize the color palette stored at the
  1239. //! beginning of a frame buffer. It writes the relevant pixel type into the
  1240. //! first entry of the frame buffer and copies the requested number of colors
  1241. //! from a source buffer into the palette starting at the required index,
  1242. //! optionally converting them from 24-bit color format into the 12-bit format
  1243. //! used by the LCD controller.
  1244. //!
  1245. //! \e ui32Type must be set to one of the following values to indicate the
  1246. //! type of frame buffer for which the palette is being initialized:
  1247. //!
  1248. //! - \b LCD_PALETTE_TYPE_1BPP indicates a 1 bit per pixel
  1249. //! (monochrome) frame buffer. This format requires a 2 entry palette.
  1250. //! - \b LCD_PALETTE_TYPE_2BPP indicates a 2 bit per pixel frame
  1251. //! buffer. This format requires a 4 entry palette.
  1252. //! - \b LCD_PALETTE_TYPE_4BPP indicates a 4 bit per pixel frame
  1253. //! buffer. This format requires a 4 entry palette.
  1254. //! - \b LCD_PALETTE_TYPE_8BPP indicates an 8 bit per pixel frame
  1255. //! buffer. This format requires a 256 entry palette.
  1256. //! - \b LCD_PALETTE_TYPE_DIRECT indicates a direct color (12, 16 or
  1257. //! 24 bit per pixel). The color palette is not used in these modes, but the
  1258. //! frame buffer type must still be initialized to ensure that the hardware
  1259. //! uses the correct pixel type. When this value is used, the format of the
  1260. //! pixels in the frame buffer is defined by the \e ui32Config parameter
  1261. //! previously passed to LCDRasterConfigSet().
  1262. //!
  1263. //! Optionally, the \b LCD_PALETTE_SRC_24BIT flag may be ORed into \e ui32Type
  1264. //! to indicate that the supplied colors in the \e pui32SrcColors array are in
  1265. //! the 24-bit format as used by the MSP432E4 Graphics Library with one color
  1266. //! stored in each 32-bit word. In this case, the colors read from the source
  1267. //! array are converted to the 12-bit format used by the LCD controller before
  1268. //! being written into the frame buffer palette.
  1269. //!
  1270. //! If \b LCD_PALETTE_SRC_24BIT is not present, it is assumed that the
  1271. //! \e pui32SrcColors array contains 12-bit colors in the format required by
  1272. //! the LCD controller with 2 colors stored in each 32-bit word. In this case,
  1273. //! the values are copied directly into the frame buffer palette without any
  1274. //! reformatting.
  1275. //!
  1276. //! \return None.
  1277. //
  1278. //*****************************************************************************
  1279. void
  1280. LCDRasterPaletteSet(uint32_t ui32Base, uint32_t ui32Type, uint32_t *pui32Addr,
  1281. const uint32_t *pui32SrcColors, uint32_t ui32Start,
  1282. uint32_t ui32Count)
  1283. {
  1284. uint16_t *pui16Pal;
  1285. uint16_t *pui16Src;
  1286. uint32_t ui32Loop;
  1287. //
  1288. // Sanity check parameters.
  1289. //
  1290. ASSERT(ui32Base == LCD0_BASE);
  1291. ASSERT(ui32Start < 256);
  1292. ASSERT((ui32Start + ui32Count) <= 256);
  1293. ASSERT(pui32Addr);
  1294. ASSERT((pui32SrcColors) || (ui32Count == 0));
  1295. ASSERT(!(ui32Type & ~(LCD_PALETTE_SRC_24BIT | LCD_PALETTE_TYPE_DIRECT |
  1296. LCD_PALETTE_TYPE_8BPP | LCD_PALETTE_TYPE_4BPP |
  1297. LCD_PALETTE_TYPE_2BPP | LCD_PALETTE_TYPE_1BPP)));
  1298. //
  1299. // Get a pointer to the start of the palette.
  1300. //
  1301. pui16Pal = (uint16_t *)pui32Addr;
  1302. //
  1303. // Are we converting the palette color format?
  1304. //
  1305. if (ui32Type & LCD_PALETTE_SRC_24BIT)
  1306. {
  1307. //
  1308. // Yes - loop through each of the supplied 24-bit colors converting
  1309. // and storing each.
  1310. //
  1311. ui32Loop = 0;
  1312. while (ui32Count)
  1313. {
  1314. pui16Pal[ui32Start + ui32Loop] =
  1315. PAL_FROM_RGB(pui32SrcColors[ui32Loop]);
  1316. ui32Loop++;
  1317. ui32Count--;
  1318. }
  1319. }
  1320. else
  1321. {
  1322. //
  1323. // No - loop through the supplied 12-bit colors storing each.
  1324. //
  1325. pui16Src = (uint16_t *)pui32SrcColors;
  1326. while (ui32Count)
  1327. {
  1328. pui16Pal[ui32Start] = pui16Src[ui32Start];
  1329. ui32Start++;
  1330. ui32Count--;
  1331. }
  1332. }
  1333. //
  1334. // Write the pixel type into the first palette entry.
  1335. //
  1336. pui16Pal[0] &= ~(LCD_PALETTE_TYPE_8BPP | LCD_PALETTE_TYPE_DIRECT);
  1337. pui16Pal[0] |= (ui32Type & ~LCD_PALETTE_SRC_24BIT);
  1338. }
  1339. //*****************************************************************************
  1340. //
  1341. //! Sets the LCD controller frame buffer start address and size in raster mode.
  1342. //!
  1343. //! \param ui32Base is the base address of the controller.
  1344. //! \param ui8Buffer specifies which frame buffer to configure. Valid values
  1345. //! are 0 and 1.
  1346. //! \param pui32Addr points to the first byte of the frame buffer. This
  1347. //! pointer must be aligned on a 32-bit (word) boundary.
  1348. //! \param ui32NumBytes specifies the size of the frame buffer in bytes. This
  1349. //! value must be a multiple of 4.
  1350. //!
  1351. //! This function is used to configure the position and size of one of the
  1352. //! two supported frame buffers while in raster mode. The second frame buffer
  1353. //! (configured when ui8Buffer is set to 1) is only used if the controller
  1354. //! is set to operate in ping-pong mode (by specifying the \b LCD_DMA_PING_PONG
  1355. //! configuration flag on a call to LCDDMAConfigSet()).
  1356. //!
  1357. //! The format of the frame buffer depends on the image type in use and
  1358. //! the current raster configuration settings. If \b RASTER_LOAD_DATA_ONLY
  1359. //! was specified in a previous call to LCDRasterConfigSet(), the frame buffer
  1360. //! contains only packed pixel data in the required bit depth and format.
  1361. //! In other cases, the frame buffer comprises a palette of either 8 or 128
  1362. //! 32-bit words followed by the packed pixel data. The palette size is 8
  1363. //! words (16 16-bit entries) for all pixel formats other than 8bpp which
  1364. //! uses a palette of 128 words (256 16-bit entries). Note that the 8 word
  1365. //! palette is still present even for 12, 16 and 24-bit formats, which do not
  1366. //! use the lookup table.
  1367. //!
  1368. //! The frame buffer size, specified using the \e ui32NumBytes parameter, must
  1369. //! be the palette size (if any) plus the size of the image bitmap required
  1370. //! for the currently configured display resolution.
  1371. //!
  1372. //! \e ui32NumBytes = (Palette Size) + ((Width * Height) * BPP) / 8)
  1373. //!
  1374. //! If \b RASTER_LOAD_DATA_ONLY is not specified, frame buffers passed to this
  1375. //! function must be initialized using a call to LCDRasterPaletteSet() prior to
  1376. //! enabling the raster output. If this is not done, the pixel format
  1377. //! identifier and color table required by the hardware is not present
  1378. //! and the results are unpredictable.
  1379. //!
  1380. //! \return None.
  1381. //*****************************************************************************
  1382. void
  1383. LCDRasterFrameBufferSet(uint32_t ui32Base, uint8_t ui8Buffer,
  1384. uint32_t *pui32Addr, uint32_t ui32NumBytes)
  1385. {
  1386. //
  1387. // Sanity check parameters.
  1388. //
  1389. ASSERT(ui32Base == LCD0_BASE);
  1390. ASSERT(!((uint32_t)pui32Addr & 3));
  1391. ASSERT(!(ui32NumBytes & 3));
  1392. ASSERT(ui8Buffer < 2);
  1393. //
  1394. // Are we setting the values for frame buffer 0?
  1395. //
  1396. if (!ui8Buffer)
  1397. {
  1398. //
  1399. // Yes - set the registers for frame buffer 0.
  1400. //
  1401. HWREG(ui32Base + LCD_O_DMABAFB0) = (uint32_t)pui32Addr;
  1402. HWREG(ui32Base + LCD_O_DMACAFB0) = (uint32_t)pui32Addr +
  1403. ui32NumBytes - 4;
  1404. }
  1405. else
  1406. {
  1407. //
  1408. // No - set the registers for frame buffer 1.
  1409. //
  1410. HWREG(ui32Base + LCD_O_DMABAFB1) = (uint32_t)pui32Addr;
  1411. HWREG(ui32Base + LCD_O_DMACAFB1) = (uint32_t)pui32Addr +
  1412. ui32NumBytes - 4;
  1413. }
  1414. }
  1415. //*****************************************************************************
  1416. //
  1417. //! Enables individual LCD controller interrupt sources.
  1418. //!
  1419. //! \param ui32Base is the base address of the controller.
  1420. //! \param ui32IntFlags is the bit mask of the interrupt sources to be enabled.
  1421. //!
  1422. //! This function enables the indicated LCD controller interrupt sources.
  1423. //! Only the sources that are enabled can be reflected to the processor
  1424. //! interrupt; disabled sources have no effect on the processor.
  1425. //!
  1426. //! The \e ui32IntFlags parameter is the logical OR of any of the following:
  1427. //!
  1428. //! - \b LCD_INT_DMA_DONE - indicates that a LIDD DMA transfer is complete.
  1429. //! - \b LCD_INT_RASTER_FRAME_DONE - indicates that a raster-mode frame is
  1430. //! complete.
  1431. //! - \b LCD_INT_SYNC_LOST - indicates that frame synchronization was lost.
  1432. //! - \b LCD_INT_AC_BIAS_CNT - indicates that that AC bias transition counter
  1433. //! has decremented to zero and is is valid for passive matrix panels only.
  1434. //! The counter, set by a call to LCDRasterACBiasIntCountSet(), is reloaded
  1435. //! but remains disabled until this interrupt is cleared.
  1436. //! - \b LCD_INT_UNDERFLOW - indicates that a data underflow occurred. The
  1437. //! internal FIFO was empty when the output logic attempted to read data to
  1438. //! send to the display.
  1439. //! - \b LCD_INT_PAL_LOAD - indicates that the color palette has been loaded.
  1440. //! - \b LCD_INT_EOF0 - indicates that the raw End-of-Frame 0 has been
  1441. //! signaled.
  1442. //! - \b LCD_INT_EOF2 - indicates that the raw End-of-Frame 1 has been
  1443. //! signaled.
  1444. //!
  1445. //! \return None.
  1446. //
  1447. //*****************************************************************************
  1448. void
  1449. LCDIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
  1450. {
  1451. ASSERT(ui32Base == LCD0_BASE);
  1452. ASSERT(!(ui32IntFlags & ~(LCD_INT_DMA_DONE | LCD_INT_SYNC_LOST |
  1453. LCD_INT_AC_BIAS_CNT | LCD_INT_UNDERFLOW |
  1454. LCD_INT_PAL_LOAD | LCD_INT_EOF0 | LCD_INT_EOF1 |
  1455. LCD_INT_RASTER_FRAME_DONE)));
  1456. //
  1457. // Enable the interrupt sources by setting the appropriate bits in the
  1458. // mask register.
  1459. //
  1460. HWREG(ui32Base + LCD_O_IM) = ui32IntFlags;
  1461. }
  1462. //*****************************************************************************
  1463. //
  1464. //! Disables individual LCD controller interrupt sources.
  1465. //!
  1466. //! \param ui32Base is the base address of the controller.
  1467. //! \param ui32IntFlags is the bit mask of the interrupt sources to be
  1468. //! disabled.
  1469. //!
  1470. //! This function disables the indicated LCD controller interrupt sources.
  1471. //! Only the sources that are enabled can be reflected to the processor
  1472. //! interrupt; disabled sources have no effect on the processor.
  1473. //!
  1474. //! The \e ui32IntFlags parameter is the logical OR of any of the following:
  1475. //!
  1476. //! - \b LCD_INT_DMA_DONE - indicates that a LIDD DMA transfer is complete.
  1477. //! - \b LCD_INT_RASTER_FRAME_DONE - indicates that a raster-mode frame is
  1478. //! complete.
  1479. //! - \b LCD_INT_SYNC_LOST - indicates that frame synchronization was lost.
  1480. //! - \b LCD_INT_AC_BIAS_CNT - indicates that that AC bias transition counter
  1481. //! has decremented to zero and is is valid for passive matrix panels only.
  1482. //! The counter, set by a call to LCDRasterACBiasIntCountSet(), is reloaded
  1483. //! but remains disabled until this interrupt is cleared.
  1484. //! - \b LCD_INT_UNDERFLOW - indicates that a data underflow occurred. The
  1485. //! internal FIFO was empty when the output logic attempted to read data to
  1486. //! send to the display.
  1487. //! - \b LCD_INT_PAL_LOAD - indicates that the color palette has been loaded.
  1488. //! - \b LCD_INT_EOF0 - indicates that the raw End-of-Frame 0 has been
  1489. //! signaled.
  1490. //! - \b LCD_INT_EOF2 - indicates that the raw End-of-Frame 1 has been
  1491. //! signaled.
  1492. //!
  1493. //! \return None.
  1494. //
  1495. //*****************************************************************************
  1496. void
  1497. LCDIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
  1498. {
  1499. ASSERT(ui32Base == LCD0_BASE);
  1500. ASSERT(!(ui32IntFlags & ~(LCD_INT_DMA_DONE | LCD_INT_SYNC_LOST |
  1501. LCD_INT_AC_BIAS_CNT | LCD_INT_UNDERFLOW |
  1502. LCD_INT_PAL_LOAD | LCD_INT_EOF0 | LCD_INT_EOF1 |
  1503. LCD_INT_RASTER_FRAME_DONE)));
  1504. //
  1505. // Disable the interrupt sources by clearing the appropriate bits in the
  1506. // mask register.
  1507. //
  1508. HWREG(ui32Base + LCD_O_IENC) = ui32IntFlags;
  1509. }
  1510. //*****************************************************************************
  1511. //
  1512. //! Gets the current LCD controller interrupt status.
  1513. //!
  1514. //! \param ui32Base is the base address of the controller.
  1515. //! \param bMasked is false if the raw interrupt status is required and true
  1516. //! if the masked interrupt status is required.
  1517. //!
  1518. //! This function returns the interrupt status for the LCD controller.
  1519. //! Either the raw interrupt status or the status of interrupts that are
  1520. //! allowed to reflect to the processor can be returned.
  1521. //!
  1522. //! \return Returns the current interrupt status as the logical OR of any of
  1523. //! the following:
  1524. //!
  1525. //! - \b LCD_INT_DMA_DONE - indicates that a LIDD DMA transfer is complete.
  1526. //! - \b LCD_INT_RASTER_FRAME_DONE - indicates that a raster-mode frame is
  1527. //! complete.
  1528. //! - \b LCD_INT_SYNC_LOST - indicates that frame synchronization was lost.
  1529. //! - \b LCD_INT_AC_BIAS_CNT - indicates that that AC bias transition counter
  1530. //! has decremented to zero and is is valid for passive matrix panels only.
  1531. //! The counter, set by a call to LCDRasterACBiasIntCountSet(), is reloaded
  1532. //! but remains disabled until this interrupt is cleared.
  1533. //! - \b LCD_INT_UNDERFLOW - indicates that a data underflow occurred. The
  1534. //! internal FIFO was empty when the output logic attempted to read data to
  1535. //! send to the display.
  1536. //! - \b LCD_INT_PAL_LOAD - indicates that the color palette has been loaded.
  1537. //! - \b LCD_INT_EOF0 - indicates that the raw End-of-Frame 0 has been
  1538. //! signaled.
  1539. //! - \b LCD_INT_EOF2 - indicates that the raw End-of-Frame 1 has been
  1540. //! signaled.
  1541. //
  1542. //*****************************************************************************
  1543. uint32_t
  1544. LCDIntStatus(uint32_t ui32Base, bool bMasked)
  1545. {
  1546. ASSERT(ui32Base == LCD0_BASE);
  1547. //
  1548. // Were we asked for the masked or raw interrupt status?
  1549. //
  1550. if (bMasked)
  1551. {
  1552. //
  1553. // Return the masked interrupt status.
  1554. //
  1555. return (HWREG(ui32Base + LCD_O_MISCLR));
  1556. }
  1557. else
  1558. {
  1559. //
  1560. // Return the raw interrupts status.
  1561. //
  1562. return (HWREG(ui32Base + LCD_O_RISSET));
  1563. }
  1564. }
  1565. //*****************************************************************************
  1566. //
  1567. //! Clears LCD controller interrupt sources.
  1568. //!
  1569. //! \param ui32Base is the base address of the controller.
  1570. //! \param ui32IntFlags is a bit mask of the interrupt sources to be cleared.
  1571. //!
  1572. //! The specified LCD controller interrupt sources are cleared so that they no
  1573. //! longer assert. This function must be called in the interrupt handler to
  1574. //! keep the interrupt from being triggered again immediately upon exit.
  1575. //!
  1576. //! The \e ui32IntFlags parameter is the logical OR of any of the following:
  1577. //!
  1578. //! - \b LCD_INT_DMA_DONE - indicates that a LIDD DMA transfer is complete.
  1579. //! - \b LCD_INT_RASTER_FRAME_DONE - indicates that a raster-mode frame is
  1580. //! complete.
  1581. //! - \b LCD_INT_SYNC_LOST - indicates that frame synchronization was lost.
  1582. //! - \b LCD_INT_AC_BIAS_CNT - indicates that that AC bias transition counter
  1583. //! has decremented to zero and is is valid for passive matrix panels only.
  1584. //! The counter, set by a call to LCDRasterACBiasIntCountSet(), is reloaded
  1585. //! but remains disabled until this interrupt is cleared.
  1586. //! - \b LCD_INT_UNDERFLOW - indicates that a data underflow occurred. The
  1587. //! internal FIFO was empty when the output logic attempted to read data to
  1588. //! send to the display.
  1589. //! - \b LCD_INT_PAL_LOAD - indicates that the color palette has been loaded.
  1590. //! - \b LCD_INT_EOF0 - indicates that the raw End-of-Frame 0 has been
  1591. //! signaled.
  1592. //! - \b LCD_INT_EOF2 - indicates that the raw End-of-Frame 1 has been
  1593. //! signaled.
  1594. //!
  1595. //! \note Because there is a write buffer in the Cortex-M processor, it may
  1596. //! take several clock cycles before the interrupt source is actually cleared.
  1597. //! Therefore, it is recommended that the interrupt source be cleared early in
  1598. //! the interrupt handler (as opposed to the very last action) to avoid
  1599. //! returning from the interrupt handler before the interrupt source is
  1600. //! actually cleared. Failure to do so may result in the interrupt handler
  1601. //! being immediately reentered (because the interrupt controller still sees
  1602. //! the interrupt source asserted).
  1603. //!
  1604. //! \return None.
  1605. //
  1606. //*****************************************************************************
  1607. void
  1608. LCDIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
  1609. {
  1610. ASSERT(ui32Base == LCD0_BASE);
  1611. ASSERT(!(ui32IntFlags & ~(LCD_INT_DMA_DONE | LCD_INT_SYNC_LOST |
  1612. LCD_INT_AC_BIAS_CNT | LCD_INT_UNDERFLOW |
  1613. LCD_INT_PAL_LOAD | LCD_INT_EOF0 | LCD_INT_EOF1 |
  1614. LCD_INT_RASTER_FRAME_DONE)));
  1615. //
  1616. // Clear the requested interrupts.
  1617. //
  1618. HWREG(ui32Base + LCD_O_MISCLR) = ui32IntFlags;
  1619. }
  1620. //*****************************************************************************
  1621. //
  1622. //! Registers an interrupt handler for the LCD controller module.
  1623. //!
  1624. //! \param ui32Base specifies the LCD controller module base address.
  1625. //! \param pfnHandler is a pointer to the function to be called when the LCD
  1626. //! controller interrupt occurs.
  1627. //!
  1628. //! This function registers the handler to be called when the LCD controller
  1629. //! module interrupt occurs.
  1630. //!
  1631. //! \note This function need not be called if the appropriate interrupt vector
  1632. //! is statically linked into the vector table in the application startup code.
  1633. //!
  1634. //! \sa IntRegister() for important information about registering interrupt
  1635. //! handlers.
  1636. //!
  1637. //! \return None.
  1638. //
  1639. //*****************************************************************************
  1640. void
  1641. LCDIntRegister(uint32_t ui32Base, void (*pfnHandler)(void))
  1642. {
  1643. //
  1644. // Check the arguments.
  1645. //
  1646. ASSERT(ui32Base == LCD0_BASE);
  1647. ASSERT(pfnHandler);
  1648. //
  1649. // Register the interrupt handler.
  1650. //
  1651. IntRegister(INT_LCD0, pfnHandler);
  1652. //
  1653. // Enable the interrupt in the interrupt controller.
  1654. //
  1655. IntEnable(INT_LCD0);
  1656. }
  1657. //*****************************************************************************
  1658. //
  1659. //! Unregisters the interrupt handler for the LCD controller module.
  1660. //!
  1661. //! \param ui32Base specifies the LCD controller module base address.
  1662. //!
  1663. //! This function unregisters the interrupt handler and disables the global LCD
  1664. //! controller interrupt in the interrupt controller.
  1665. //!
  1666. //! \note This function need not be called if the appropriate interrupt vector
  1667. //! is statically linked into the vector table in the application startup code.
  1668. //!
  1669. //! \sa IntRegister() for important information about registering interrupt
  1670. //! handlers.
  1671. //!
  1672. //! \return None.
  1673. //
  1674. //*****************************************************************************
  1675. void
  1676. LCDIntUnregister(uint32_t ui32Base)
  1677. {
  1678. //
  1679. // Check the arguments.
  1680. //
  1681. ASSERT(ui32Base == LCD0_BASE);
  1682. //
  1683. // Disable the interrupt in the interrupt controller.
  1684. //
  1685. IntDisable(INT_LCD0);
  1686. //
  1687. // Unregister the interrupt handler.
  1688. //
  1689. IntUnregister(INT_LCD0);
  1690. }
  1691. //*****************************************************************************
  1692. //
  1693. // Close the Doxygen group.
  1694. //! @}
  1695. //
  1696. //*****************************************************************************