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