lcdc_testscreen_example.c

Go to the documentation of this file.
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
00023 #include "usart.h"
00024 #include "pio.h"
00025 #include "spi.h"
00026 #include "lcdc.h"
00027 #include "at32stk1000.h"
00028 #include "utils.h"
00029 #include <string.h>
00030 
00031 extern void ltv350qv_power_on(volatile avr32_spi_t * spi, unsigned char chip_select);
00032 extern int display_bm(lcdc_conf_t *lcdc_conf, void * bm_file);
00033 extern void usdelay(unsigned long usec);
00034 extern void usart_printHex(volatile avr32_usart_t * usart, const unsigned long n);
00035 extern void usart_print(volatile avr32_usart_t * usart, char *str);
00036 
00038 lcdc_conf_t ltv350qv_conf ={
00039                 
00040         dmabaddr1: 0x10000000,
00041         dmabaddr2: 0,
00042         burst_length: 4,
00043         xres: 320,
00044         yres: 240,
00045         set2dmode: MODE_2D_OFF,
00046         virtual_xres: 320,
00047         virtual_yres: 240,
00048         frame_rate: 75,
00049         lcdcclock: 40000000,
00050         guard_time: 2,
00051         memor: BIG_ENDIAN,
00052         ifwidth: 0,
00053         scanmod: SINGLE_SCAN,
00054         distype: TFT,
00055         invvd: INVERTED,
00056         invframe: INVERTED,
00057         invline: INVERTED,
00058         invclk: INVERTED,
00059         invdval: INVERTED,
00060         clkmod: ALWAYS_ACTIVE,
00061         pixelsize: BPP_24,
00062         ctrstval: 0x0f,
00063         ctrst_ena: ENABLED,
00064         ctrst_pol: NORMAL,
00065         ctrst_ps: PRE_HALF,
00066         mval: 0,
00067         mmode: EACH_FRAME,
00068         hpw: 16,
00069         hbp: 15,
00070         hfp: 33,
00071         vpw: 1, 
00072         vbp: 10,
00073         vfp: 10,
00074         vhdly: 0,
00075 };
00076 
00078 volatile avr32_usart_t *usart = &AVR32_USART1;
00079 
00080 
00084 void lcd_pio_config(void){
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 }
00127 void fill_frame_buffer (lcdc_conf_t *lcdc_conf)
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 }
00152 void init_spiMaster(volatile avr32_spi_t * spi, long cpuHz)
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 }
00194 int main (void)
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 }

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