The following example shows how to use the LCD Controller API
to configure an 800x480 resolution raster panel and start it displaying
from an 8bpp frame buffer. Note that raster timing configuration
varies from display to display. Consult your display’s datasheet and
modify tLCDRasterTiming values as required for your display.
//*****************************************************************************
//
// Define the frame buffer dimensions and format.
//
//*****************************************************************************
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 8
//*****************************************************************************
//
// Define labels containing the size of the image bitmap and palette.
//
//*****************************************************************************
#define SIZE_IMAGE ((SCREEN_WIDTH * SCREEN_HEIGHT * SCREEN_BPP) / 8)
#define SIZE_PALETTE ((SCREEN_BPP == 8) ? (256 * 2) : (16 * 2))
//*****************************************************************************
//
// Position the frame buffer at an appropriate point in memory, most likely in
// EPI-connected SDRAM at 0x10000000. The frame buffer will be (SIZE_IMAGE +
// SIZE_PALETTE) bytes long.
//
//*****************************************************************************
uint32_t *g_pui32DisplayBuffer = (uint32_t *)LCD_FRAME_BUFFER_ADDR;
//*****************************************************************************
//
// Calculate pointers to the frame buffer palette and the first byte of the
// actual image bitmap.
//
//*****************************************************************************
uint16_t *g_pui16Palette = (uint16_t *)LCD_FRAME_BUFFER_ADDR;
uint8_t *g_pBitmap = (uint8_t *)(LCD_FRAME_BUFFER_ADDR + SIZE_PALETTE);
//*****************************************************************************
//
// Initialize our source color palette. These colors are defined in RGB888
// format as used by the TivaWare Graphics Library.
//
//*****************************************************************************
const uint32_t g_pulSrcPalette[256] =
{
ClrBlack,
ClrWhite,
ClrRed,
ClrLightGreen,
ClrBlue,
ClrYellow,
ClrMagenta,
ClrCyan,
ClrOrange,
//
// and so on...
//
};
//*****************************************************************************
//
// Labels defining the desired pixel clock, PLL VCO frequency and system clock.
// Note that the system clock must be an integer multiple of the pixel clock.
//
//*****************************************************************************
#define PIXEL_CLOCK_FREQ 30000000
#define SYSTEM_VCO_FREQ SYSCTL_CFG_VCO_480
#define SYSTEM_CLOCK_FREQ 120000000
//*****************************************************************************
//
// The timings and signal polarities for the various raster interface signals.
// Timing parameters are defined in terms of pixel clocks (for horizontal
// timings) and lines (for vertical timings).
//
//*****************************************************************************
tLCDRasterTiming g_sRasterTimings =
{
(RASTER_TIMING_ACTIVE_HIGH_PIXCLK |
RASTER_TIMING_SYNCS_ON_RISING_PIXCLK),
SCREEN_WIDTH, SCREEN_HEIGHT,
2, 30, 8,
10, 10, 8,
0
};
//*****************************************************************************
//
// The interrupt handler for the LCD controller. This function merely
// counts the interrupts received.
//
//*****************************************************************************
void
LCDIntHandler(void)
{
uint32_t ui32Status;
//
// Get the current interrupt status and clear any active interrupts.
//
ui32Status = LCDIntStatus(LCD0_BASE, true);
LCDIntClear(LCD0_BASE, ui32Status);
//
// Handle any interrupts as required by the application. In normal
// operation, no action is required at interrupt time to keep the raster
// scan running.
//
}
//*****************************************************************************
//
// Initialize the LCD controller to drive the display in raster mode and
// enable the raster engine.
//
//*****************************************************************************
void
InitDisplay(uint32_t ui32SysClkHz, uint32_t ui32PixClock,
tLCDRasterTiming *psTimings)
{
uint32_t ui32Loop;
//
// Enable the LCD controller peripheral.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_LCD0);
//
// Wait to ensure that the LCD controller is enabled.
//
SysCtlDelay(2);
//
// Configure the LCD controller for raster operation with a pixel clock
// as close to the requested pixel clock as possible.
//
ui32PixClock = LCDModeSet(LCD0_BASE, (LCD_MODE_RASTER |
LCD_MODE_AUTO_UFLOW_RESTART),
ui32PixClock, ui32SysClkHz);
//
// Set the output format for the raster interface.
//
LCDRasterConfigSet(LCD0_BASE, RASTER_FMT_ACTIVE_PALETTIZED_16BIT, 0);
//
// Program the raster engine timings according to the display requirements.
//
LCDRasterTimingSet(LCD0_BASE, psTimings);
//
// Configure LCD DMA-related parameters.
//
LCDDMAConfigSet(LCD0_BASE, LCD_DMA_BURST_4);
//
// Set up the frame buffer.
//
LCDRasterFrameBufferSet(LCD0_BASE, 0, g_pui32DisplayBuffer,
SIZE_PALETTE + SIZE_IMAGE);
//
// Write the palette to the frame buffer.
//
LCDRasterPaletteSet(LCD0_BASE,
LCD_PALETTE_SRC_24BIT | LCD_PALETTE_TYPE_8BPP,
(uint32_t *)g_pui16Palette, g_pulSrcPalette, 0,
(SIZE_PALETTE / 2));
//
// Fill the frame buffer with black (pixel value 0 corresponds to black
// in the palette we just set).
//
for(ui32Loop = 0; ui32Loop < (SIZE_IMAGE / sizeof(uint32_t)); ui32Loop++)
{
g_pui32DisplayBuffer[ui32Loop] = 0;
}
//
// Enable the LCD interrupts.
//
LCDIntEnable(LCD0_BASE, (LCD_INT_DMA_DONE | LCD_INT_RASTER_FRAME_DONE |
LCD_INT_SYNC_LOST | LCD_INT_AC_BIAS_CNT | LCD_INT_UNDERFLOW |
LCD_INT_PAL_LOAD | LCD_INT_EOF0 | LCD_INT_EOF1));
IntEnable(INT_LCD0);
//
// Enable the raster output.
//
LCDRasterEnable(LCD0_BASE);
}
//*****************************************************************************
//
// This example demonstrates the use of the LCD Controller in raster mode.
//
//*****************************************************************************
int
main(void)
{
uint32_t ui32SysClock;
//
// Set the system clock to run from the PLL at 120 MHz.
//
ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSTEM_VCO_FREQ), SYSTEM_CLOCK_FREQ);
//
// Configure the device pins.
//
PinoutSet();
//
// Enable interrupts in the CPU.
//
IntMasterEnable();
//
// Initialize the display controller and start the raster engine.
//
InitDisplay(ui32SysClock, PIXEL_CLOCK_FREQ, &g_sRasterTimings);
while(1)
{
//
// Other application code...
//
}
}