lcdc_testscreen_example.c File Reference


Detailed Description

LCD controller example for the STK1000.

This example shows how to use the LCD controller. It sets up the LCD controller for the TFT module on the STK1000 and prints a simple test pattern onto it.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/
$Name$ $Revision$ $RCSfile$ $Date$

Definition in file lcdc_testscreen_example.c.

#include "usart.h"
#include "pio.h"
#include "spi.h"
#include "lcdc.h"
#include "at32stk1000.h"
#include "utils.h"
#include <string.h>

Include dependency graph for lcdc_testscreen_example.c:

Go to the source code of this file.

Functions

int display_bm (lcdc_conf_t *lcdc_conf, void *bm_file)
 Dispays the content of a bitmap file in the frame buffer.
void fill_frame_buffer (lcdc_conf_t *lcdc_conf)
 Fill the frame buffer with a test picture Writes some colours to the framebuffer. Framebuffer pixel size is packed 24Bit.
void init_spiMaster (volatile avr32_spi_t *spi, long cpuHz)
 initialise SPI in master mode
void lcd_pio_config (void)
 Sets up the pins for the LCD on the STK1000.
void ltv350qv_power_on (volatile avr32_spi_t *spi, unsigned char chip_select)
 Power on sequence for the display.
int main (void)
 LCD test pattern example. Sets up the LCD controller and shows a test pattern on the screen.
void usart_print (volatile avr32_usart_t *usart, char *str)
void usart_printHex (volatile avr32_usart_t *usart, const unsigned long n)
void usdelay (unsigned long usec)
 Delay execution for a specificated time.

Variables

lcdc_conf_t ltv350qv_conf
 LCD controller configuration.
volatile avr32_usart_t * usart = &AVR32_USART1
 USART used for console output.


Function Documentation

int display_bm ( lcdc_conf_t lcdc_conf,
void *  file_start 
)

Dispays the content of a bitmap file in the frame buffer.

Parameters:
lcdc_conf Pointer to the LCD controller configuration
file_start Pointer to the beginning of the file

Definition at line 270 of file bmp_lib.c.

00270                                                          {
00271         
00272         bm_file_header_t bm_file_header;
00273         bm_info_header_t bm_info_header;
00274         unsigned char * data_start;
00275         
00276         /* get file header and header information */
00277         memcpy(&bm_file_header, file_start, sizeof(bm_file_header_t));
00278         memcpy(&bm_info_header, file_start + 14, sizeof(bm_info_header_t));
00279         
00280         /* correct endianess */
00281         swap_endian_blk((unsigned char *) &bm_file_header.bfType, 2);
00282         swap_endian_blk((unsigned char *) &bm_file_header.bfSize, 4);
00283         swap_endian_blk((unsigned char *) &bm_file_header.bfOffBits, 4);
00284         swap_endian_blk((unsigned char *) &bm_info_header.biWidth, 4);
00285         swap_endian_blk((unsigned char *) &bm_info_header.biHeight, 4);
00286         swap_endian_blk((unsigned char *) &bm_info_header.biBitCount, 2);
00287         swap_endian_blk((unsigned char *) &bm_info_header.biCompression, 4);
00288         
00289         
00290         data_start = file_start + bm_file_header.bfOffBits;     
00291         fill_frame_buffer_bm(lcdc_conf, &bm_info_header, data_start);
00292         
00293         return 0;               
00294 }

void fill_frame_buffer ( lcdc_conf_t lcdc_conf  ) 

Fill the frame buffer with a test picture Writes some colours to the framebuffer. Framebuffer pixel size is packed 24Bit.

Parameters:
lcdc_conf Pointer to LCD configuration structure

Definition at line 127 of file lcdc_testscreen_example.c.

References lcdc_conf_t::dmabaddr1, lcdc_conf_t::xres, and lcdc_conf_t::yres.

Referenced by main().

00128 {
00129         
00130         unsigned int k,l,x,y;
00131         unsigned char * framePtr;
00132         
00133         /* Set pointer to non-cached framebuffer address */
00134         framePtr = (unsigned char *) (lcdc_conf->dmabaddr1 | 0xA0000000);
00135         
00136         for (l=0; l < lcdc_conf->yres; l++){        /* line */
00137                 for (k=0; k < lcdc_conf->xres; k++)    /* column */
00138                 {
00139                         x = (255 * l) / lcdc_conf->yres;
00140                         y = (255 * k) / lcdc_conf->xres;
00141                         *framePtr++ = x;
00142                         *framePtr++ = y;
00143                         *framePtr++ = 255 - (x + y) / 2;
00144                 }
00145         }
00146 }

void init_spiMaster ( volatile avr32_spi_t *  spi,
long  cpuHz 
)

initialise SPI in master mode

Parameters:
spi Pointer to the correct avr32_spi_t struct
cpuHz CPU clock frequency in Hz

Definition at line 152 of file lcdc_testscreen_example.c.

References spi_options_t::baudrate, spi_options_t::bits, spi_options_t::fdiv, spi_options_t::modfdis, pio_enable_module(), spi_options_t::reg, spi_options_t::spck_delay, spi_enable(), spi_initMaster(), spi_options_t::spi_mode, spi_selectChip(), spi_selectionMode(), spi_setupChipReg(), spi_options_t::stay_act, and spi_options_t::trans_delay.

00153 {
00154 
00155         struct spi_options_t spiOptions;
00156         avr32_piomap_t spi_piomap = {                                   \
00157                 {AVR32_SPI0_SCK_0_PIN, AVR32_SPI0_SCK_0_FUNCTION},      \
00158                 {AVR32_SPI0_MISO_0_PIN, AVR32_SPI0_MISO_0_FUNCTION},    \
00159                 {AVR32_SPI0_MOSI_0_PIN, AVR32_SPI0_MOSI_0_FUNCTION},    \
00160                 {AVR32_SPI0_NPCS_0_PIN, AVR32_SPI0_NPCS_0_FUNCTION},    \
00161                 {AVR32_SPI0_NPCS_1_PIN, AVR32_SPI0_NPCS_1_FUNCTION},    \
00162                 {AVR32_SPI0_NPCS_2_PIN, AVR32_SPI0_NPCS_2_FUNCTION},    \
00163                 {AVR32_SPI0_NPCS_3_PIN, AVR32_SPI0_NPCS_3_FUNCTION},    \
00164         };
00165         pio_enable_module(spi_piomap, 7);
00166         
00167         spiOptions.reg = 1;
00168         spiOptions.baudrate = 1500000;
00169         spiOptions.bits = 8;
00170         spiOptions.spck_delay = 0;
00171         spiOptions.trans_delay = 0;
00172         spiOptions.stay_act = 1;
00173         spiOptions.spi_mode = 3;
00174         
00175         spiOptions.fdiv = 0;
00176         spiOptions.modfdis = 0;
00177 
00178         /* Initialize as master */
00179         spi_initMaster(spi, &spiOptions);
00180 
00181         /* Set master mode; variable_ps, pcs_decode, delay */
00182         spi_selectionMode(spi, 0, 0, 0);
00183 
00184         /* Select slave chip 1 (SPI_NPCS1) */
00185         spi_selectChip(spi, 1);
00186 
00187         spi_setupChipReg(spi, &spiOptions, cpuHz);
00188 
00189         spi_enable(spi);
00190 }

Here is the call graph for this function:

void lcd_pio_config ( void   ) 

Sets up the pins for the LCD on the STK1000.

Definition at line 84 of file lcdc_testscreen_example.c.

References pio_enable_module().

Referenced by main().

00084                          {
00085         
00086                 avr32_piomap_t piomap = {
00087                         { AVR32_LCDC_CC_0_0_PIN, AVR32_LCDC_CC_0_0_FUNCTION },
00088                         { AVR32_LCDC_DVAL_0_0_PIN, AVR32_LCDC_DVAL_0_0_FUNCTION },
00089                         { AVR32_LCDC_HSYNC_0_PIN, AVR32_LCDC_HSYNC_0_FUNCTION },
00090                         { AVR32_LCDC_MODE_0_0_PIN, AVR32_LCDC_MODE_0_0_FUNCTION },
00091                         { AVR32_LCDC_PCLK_0_PIN, AVR32_LCDC_PCLK_0_FUNCTION },
00092                         { AVR32_LCDC_PWR_0_PIN, AVR32_LCDC_PWR_0_FUNCTION },
00093                         { AVR32_LCDC_VSYNC_0_PIN, AVR32_LCDC_VSYNC_0_FUNCTION },
00094                         { AVR32_LCDC_DATA_0_0_PIN, AVR32_LCDC_DATA_0_0_FUNCTION },
00095                         { AVR32_LCDC_DATA_1_0_PIN, AVR32_LCDC_DATA_1_0_FUNCTION },
00096                         { AVR32_LCDC_DATA_2_0_PIN, AVR32_LCDC_DATA_1_0_FUNCTION },
00097                         { AVR32_LCDC_DATA_3_0_PIN, AVR32_LCDC_DATA_1_0_FUNCTION },
00098                         { AVR32_LCDC_DATA_4_0_PIN, AVR32_LCDC_DATA_1_0_FUNCTION },
00099                         { AVR32_LCDC_DATA_5_PIN, AVR32_LCDC_DATA_5_FUNCTION },
00100                         { AVR32_LCDC_DATA_6_PIN, AVR32_LCDC_DATA_6_FUNCTION },
00101                         { AVR32_LCDC_DATA_7_PIN, AVR32_LCDC_DATA_7_FUNCTION },
00102                         { AVR32_LCDC_DATA_8_0_PIN, AVR32_LCDC_DATA_8_0_FUNCTION },
00103                         { AVR32_LCDC_DATA_9_0_PIN, AVR32_LCDC_DATA_9_0_FUNCTION },
00104                         { AVR32_LCDC_DATA_10_0_PIN, AVR32_LCDC_DATA_10_0_FUNCTION },
00105                         { AVR32_LCDC_DATA_11_0_PIN, AVR32_LCDC_DATA_11_0_FUNCTION },
00106                         { AVR32_LCDC_DATA_12_0_PIN, AVR32_LCDC_DATA_12_0_FUNCTION },
00107                         { AVR32_LCDC_DATA_13_PIN, AVR32_LCDC_DATA_13_FUNCTION },
00108                         { AVR32_LCDC_DATA_14_PIN, AVR32_LCDC_DATA_14_FUNCTION },
00109                         { AVR32_LCDC_DATA_15_PIN, AVR32_LCDC_DATA_15_FUNCTION },
00110                         { AVR32_LCDC_DATA_16_0_PIN, AVR32_LCDC_DATA_16_0_FUNCTION },
00111                         { AVR32_LCDC_DATA_17_0_PIN, AVR32_LCDC_DATA_17_0_FUNCTION },
00112                         { AVR32_LCDC_DATA_18_0_PIN, AVR32_LCDC_DATA_18_0_FUNCTION },
00113                         { AVR32_LCDC_DATA_19_0_PIN, AVR32_LCDC_DATA_19_0_FUNCTION },
00114                         { AVR32_LCDC_DATA_20_0_PIN, AVR32_LCDC_DATA_20_0_FUNCTION },
00115                         { AVR32_LCDC_DATA_21_0_PIN, AVR32_LCDC_DATA_21_0_FUNCTION },
00116                         { AVR32_LCDC_DATA_22_PIN, AVR32_LCDC_DATA_22_FUNCTION },
00117                         { AVR32_LCDC_DATA_23_PIN, AVR32_LCDC_DATA_23_FUNCTION }
00118                         
00119         };
00120         pio_enable_module(piomap, 31);
00121         
00122 }

Here is the call graph for this function:

void ltv350qv_power_on ( volatile avr32_spi_t *  spi,
unsigned char  chip_select 
)

Power on sequence for the display.

Parameters:
spi Pointer to the SPI interface
chip_select Chip select number

Definition at line 127 of file ltv350qv.c.

References spi_selectChip(), usart, usart_print(), usdelay(), and write_reg.

00128 {
00129         int ret;
00130 
00131         usart_print(usart,"ltv350qv: do power on sequence\n");
00132         spi_selectChip(spi, chip_select);
00133         /* write startup procedure */
00134         write_reg(spi, 9, 0x0000);
00135         usdelay(15000);
00136         write_reg(spi, 9, 0x4000);
00137         write_reg(spi, 10, 0x2000);
00138         write_reg(spi, 9, 0x4055);
00139         usdelay(55000);
00140         write_reg(spi, 1, 0x409d);
00141         write_reg(spi, 2, 0x0204);
00142         write_reg(spi, 3, 0x0100);
00143         write_reg(spi, 4, 0x3000);
00144         write_reg(spi, 5, 0x4003);
00145         write_reg(spi, 6, 0x000a);
00146         write_reg(spi, 7, 0x0021);
00147         write_reg(spi, 8, 0x0c00);
00148         write_reg(spi, 10, 0x0103);
00149         write_reg(spi, 11, 0x0301);
00150         write_reg(spi, 12, 0x1f0f);
00151         write_reg(spi, 13, 0x1f0f);
00152         write_reg(spi, 14, 0x0707);
00153         write_reg(spi, 15, 0x0307);
00154         write_reg(spi, 16, 0x0707);
00155         write_reg(spi, 17, 0x0000);
00156         write_reg(spi, 18, 0x0004);
00157         write_reg(spi, 19, 0x0000);
00158 
00159         usdelay(20000);
00160         write_reg(spi, 9, 0x4a55);
00161         write_reg(spi, 5, 0x5003);
00162 
00163         usart_print(usart,"ltv350qv: power on sequence done\n");
00164 out:
00165         return;
00166 }

Here is the call graph for this function:

int main ( void   ) 

LCD test pattern example. Sets up the LCD controller and shows a test pattern on the screen.

Definition at line 194 of file lcdc_testscreen_example.c.

References board_init(), lcdc_conf_t::dmabaddr1, fill_frame_buffer(), init_spiMaster(), lcd_pio_config(), lcdc_init(), ltv350qv_power_on(), lcdc_conf_t::pixelsize, usart, usart_print(), lcdc_conf_t::xres, and lcdc_conf_t::yres.

00195 {
00196         volatile avr32_spi_t * spi = &AVR32_SPI0;
00197         volatile avr32_pm_t *ppm = &AVR32_PM;
00198         
00199         board_init();
00200         usart_print(usart, "board init complete\n");
00201         usart_print(usart, "Setting up SPI for LTV350QV panel\n");
00202         init_spiMaster(spi, 40000000);
00203         usart_print(usart,"Initializing LTV350QV panel\n");
00204         ltv350qv_power_on(spi, 1);
00205         usart_print(usart, "Setting up LCD controller\n");
00206         lcd_pio_config();
00207         
00208         /* Power manager setup 
00209         * Enable CLOCK for LCDC in HSBMASK
00210         */
00211         ppm->hsb_mask |= 0x00000080;    
00212         /* Enable generic clock PLL0 for LCD controller pixel clock */
00213         ppm->gcctrl[7] |= 0x00000006;
00214         lcdc_init(&ltv350qv_conf);
00215         
00216         usart_print(usart, "Testing frame buffer\n");
00217 
00218         /* clear framebuffer */
00219         memset((void *)ltv350qv_conf.dmabaddr1, 0, ltv350qv_conf.xres * ltv350qv_conf.yres * ltv350qv_conf.pixelsize / 8);
00220         
00221         fill_frame_buffer(&ltv350qv_conf);
00222         while(1){
00223         }
00224         
00225         return 0;
00226 }

Here is the call graph for this function:

void usart_print ( volatile avr32_usart_t *  usart,
char *  str 
)

void usart_printHex ( volatile avr32_usart_t *  usart,
const unsigned long  n 
)

Definition at line 36 of file at32stk1000.c.

References usart_print().

Referenced by board_init().

00037 {
00038         char tmp[9];
00039         int i;
00040 
00041         for (i = 0; i < 8; i++) {
00042                 unsigned long nibble;
00043 
00044                 nibble = (n >> (28 - 4 * i)) & 0x0F;
00045 
00046                 if (nibble < 10) {
00047                         tmp[i] = nibble + '0';
00048                 } else {
00049                         tmp[i] = nibble - 10 + 'a';
00050                 }
00051         }
00052 
00053         tmp[8] = 0;
00054         usart_print(usart, tmp);
00055 }

Here is the call graph for this function:

void usdelay ( unsigned long  usec  ) 

Delay execution for a specificated time.

Parameters:
usec Delay in microseconds

Definition at line 77 of file ltv350qv.c.

References get_count(), and pm_read_mclk().

00078 {
00079         unsigned long start, stop;
00080         unsigned long ticks;
00081 
00082         start = get_count();
00083         ticks = usec * (pm_read_mclk() / 1000000);
00084         stop = start + ticks;
00085 
00086         if (start > stop)
00087                 while (get_count() > start) ;
00088         
00089         while (get_count() < stop) ;
00090 }

Here is the call graph for this function:


Variable Documentation

lcdc_conf_t ltv350qv_conf

LCD controller configuration.

Definition at line 38 of file lcdc_testscreen_example.c.

volatile avr32_usart_t* usart = &AVR32_USART1

USART used for console output.

Definition at line 78 of file lcdc_testscreen_example.c.


Generated on Wed May 7 16:03:17 2008 for AVR32114 Using the AVR32 LCD Controller by  doxygen 1.5.3-20071008