lcdc_moving_bitmap_example.c

Go to the documentation of this file.
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
00036 /* Copyright (c) 2007, Atmel Corporation All rights reserved.
00037  *
00038  * Redistribution and use in source and binary forms, with or without
00039  * modification, are permitted provided that the following conditions are met:
00040  *
00041  * 1. Redistributions of source code must retain the above copyright notice,
00042  * this list of conditions and the following disclaimer.
00043  *
00044  * 2. Redistributions in binary form must reproduce the above copyright notice,
00045  * this list of conditions and the following disclaimer in the documentation
00046  * and/or other materials provided with the distribution.
00047  *
00048  * 3. The name of ATMEL may not be used to endorse or promote products derived
00049  * from this software without specific prior written permission.
00050  *
00051  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
00052  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00053  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
00054  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00055  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00056  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00057  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00058  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00059  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00060  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00061  */
00062 
00063 #include <string.h>
00064 #include "usart.h"
00065 #include "pio.h"
00066 #include "spi.h"
00067 #include "lcdc.h"
00068 #include "utils.h"
00069 #include "at32stk1000.h"
00070 
00071 extern void ltv350qv_power_on(volatile avr32_spi_t * spi, unsigned char chip_select);
00072 extern int display_virtual_bm(lcdc_conf_t *lcdc_conf, void * bm_file);
00073 extern void usdelay(unsigned long usec);
00074 extern void usart_printHex(volatile avr32_usart_t * usart, const unsigned long n);
00075 
00076 int increment_frame_base(lcdc_conf_t *lcdc_conf, int pixel, int line);
00077 void lcd_pio_config(void);
00078 void init_spiMaster(volatile avr32_spi_t * spi);
00079 void print(volatile struct avr32_usart_t * usart, char *str);
00080 
00081 #define SWITCHES_MASK 0x000000FF
00082 #define SWITCH0 0x00000001
00083 #define SWITCH1 0x00000002
00084 #define SWITCH2 0x00000004
00085 #define SWITCH3 0x00000008
00086 
00088 #define BITMAP_FILE_ADDRESS 0x00400000
00089 
00091 lcdc_conf_t ltv350qv_conf ={
00092                 
00093         dmabaddr1: 0x10000000,
00094         dmabaddr2: 0,
00095         burst_length: 4,
00096         xres: 320,
00097         yres: 240,
00098         set2dmode: MODE_2D_ON,
00099         virtual_xres: 640,
00100         virtual_yres: 480,
00101         frame_rate: 75,
00102         lcdcclock: 40000000,
00103         guard_time: 2,
00104         memor: BIG_ENDIAN,
00105         ifwidth: 0,
00106         scanmod: SINGLE_SCAN,
00107         distype: TFT,
00108         invvd: NORMAL,
00109         invframe: INVERTED,
00110         invline: INVERTED,
00111         invclk: INVERTED,
00112         invdval: INVERTED,
00113         clkmod: ALWAYS_ACTIVE,
00114         pixelsize: BPP_32,
00115         ctrstval: 0x0f,
00116         ctrst_ena: ENABLED,
00117         ctrst_pol: NORMAL,
00118         ctrst_ps: PRE_HALF,
00119         mval: 0,
00120         mmode: EACH_FRAME,
00121         hpw: 16,
00122         hbp: 15,
00123         hfp: 33,
00124         vpw: 1, 
00125         vbp: 10,
00126         vfp: 10,
00127         vhdly: 0,
00128 };
00130 volatile avr32_usart_t *usart = &AVR32_USART1;
00131 
00136 void init_spiMaster(volatile avr32_spi_t * spi)
00137 {
00138 
00139         struct spi_options_t spiOptions;
00140         avr32_piomap_t spi_piomap = {                                   \
00141                 {AVR32_SPI0_SCK_0_PIN, AVR32_SPI0_SCK_0_FUNCTION},      \
00142                 {AVR32_SPI0_MISO_0_PIN, AVR32_SPI0_MISO_0_FUNCTION},    \
00143                 {AVR32_SPI0_MOSI_0_PIN, AVR32_SPI0_MOSI_0_FUNCTION},    \
00144                 {AVR32_SPI0_NPCS_0_PIN, AVR32_SPI0_NPCS_0_FUNCTION},    \
00145                 {AVR32_SPI0_NPCS_1_PIN, AVR32_SPI0_NPCS_1_FUNCTION},    \
00146                 {AVR32_SPI0_NPCS_2_PIN, AVR32_SPI0_NPCS_2_FUNCTION},    \
00147                 {AVR32_SPI0_NPCS_3_PIN, AVR32_SPI0_NPCS_3_FUNCTION},    \
00148         };
00149         pio_enable_module(spi_piomap, 7);
00150         
00151         spiOptions.reg = 1;
00152         spiOptions.baudrate = 1500000;
00153         spiOptions.bits = 8;
00154         spiOptions.spck_delay = 0;
00155         spiOptions.trans_delay = 0;
00156         spiOptions.stay_act = 1;
00157         spiOptions.spi_mode = 3;
00158         
00159         spiOptions.fdiv = 0;
00160         spiOptions.modfdis = 0;
00161 
00162         /* Initialize as master */
00163         spi_initMaster(spi, &spiOptions);
00164 
00165         /* Set master mode; variable_ps, pcs_decode, delay */
00166         spi_selectionMode(spi, 0, 0, 0);
00167 
00168         /* Select slave chip 1 (SPI_NPCS1) */
00169         spi_selectChip(spi, 1);
00170 
00171         spi_setupChipReg(spi, &spiOptions, pm_read_module_frequency(PM_PBA_SPI0));
00172 
00173         spi_enable(spi);
00174 }
00175 
00183 void print(volatile struct avr32_usart_t * usart, char *str)
00184 {
00185         while (*str != '\0')
00186                 usart_putchar(usart, *str++);
00187 }
00188 
00192 void lcd_pio_config(void){
00193         
00194                 avr32_piomap_t piomap = {
00195                         { AVR32_LCDC_CC_0_0_PIN, AVR32_LCDC_CC_0_0_FUNCTION },
00196                         { AVR32_LCDC_DVAL_0_0_PIN, AVR32_LCDC_DVAL_0_0_FUNCTION },
00197                         { AVR32_LCDC_HSYNC_0_PIN, AVR32_LCDC_HSYNC_0_FUNCTION },
00198                         { AVR32_LCDC_MODE_0_0_PIN, AVR32_LCDC_MODE_0_0_FUNCTION },
00199                         { AVR32_LCDC_PCLK_0_PIN, AVR32_LCDC_PCLK_0_FUNCTION },
00200                         { AVR32_LCDC_PWR_0_PIN, AVR32_LCDC_PWR_0_FUNCTION },
00201                         { AVR32_LCDC_VSYNC_0_PIN, AVR32_LCDC_VSYNC_0_FUNCTION },
00202                         { AVR32_LCDC_DATA_0_0_PIN, AVR32_LCDC_DATA_0_0_FUNCTION },
00203                         { AVR32_LCDC_DATA_1_0_PIN, AVR32_LCDC_DATA_1_0_FUNCTION },
00204                         { AVR32_LCDC_DATA_2_0_PIN, AVR32_LCDC_DATA_1_0_FUNCTION },
00205                         { AVR32_LCDC_DATA_3_0_PIN, AVR32_LCDC_DATA_1_0_FUNCTION },
00206                         { AVR32_LCDC_DATA_4_0_PIN, AVR32_LCDC_DATA_1_0_FUNCTION },
00207                         { AVR32_LCDC_DATA_5_PIN, AVR32_LCDC_DATA_5_FUNCTION },
00208                         { AVR32_LCDC_DATA_6_PIN, AVR32_LCDC_DATA_6_FUNCTION },
00209                         { AVR32_LCDC_DATA_7_PIN, AVR32_LCDC_DATA_7_FUNCTION },
00210                         { AVR32_LCDC_DATA_8_0_PIN, AVR32_LCDC_DATA_8_0_FUNCTION },
00211                         { AVR32_LCDC_DATA_9_0_PIN, AVR32_LCDC_DATA_9_0_FUNCTION },
00212                         { AVR32_LCDC_DATA_10_0_PIN, AVR32_LCDC_DATA_10_0_FUNCTION },
00213                         { AVR32_LCDC_DATA_11_0_PIN, AVR32_LCDC_DATA_11_0_FUNCTION },
00214                         { AVR32_LCDC_DATA_12_0_PIN, AVR32_LCDC_DATA_12_0_FUNCTION },
00215                         { AVR32_LCDC_DATA_13_PIN, AVR32_LCDC_DATA_13_FUNCTION },
00216                         { AVR32_LCDC_DATA_14_PIN, AVR32_LCDC_DATA_14_FUNCTION },
00217                         { AVR32_LCDC_DATA_15_PIN, AVR32_LCDC_DATA_15_FUNCTION },
00218                         { AVR32_LCDC_DATA_16_0_PIN, AVR32_LCDC_DATA_16_0_FUNCTION },
00219                         { AVR32_LCDC_DATA_17_0_PIN, AVR32_LCDC_DATA_17_0_FUNCTION },
00220                         { AVR32_LCDC_DATA_18_0_PIN, AVR32_LCDC_DATA_18_0_FUNCTION },
00221                         { AVR32_LCDC_DATA_19_0_PIN, AVR32_LCDC_DATA_19_0_FUNCTION },
00222                         { AVR32_LCDC_DATA_20_0_PIN, AVR32_LCDC_DATA_20_0_FUNCTION },
00223                         { AVR32_LCDC_DATA_21_0_PIN, AVR32_LCDC_DATA_21_0_FUNCTION },
00224                         { AVR32_LCDC_DATA_22_PIN, AVR32_LCDC_DATA_22_FUNCTION },
00225                         { AVR32_LCDC_DATA_23_PIN, AVR32_LCDC_DATA_23_FUNCTION }
00226                         
00227         };
00228         pio_enable_module(piomap, 31);
00229         
00230 }
00242 int increment_frame_base(lcdc_conf_t *lcdc_conf, int pixel, int line){
00243         
00244         volatile avr32_lcdc_t *plcdc = &AVR32_LCDC;
00245         unsigned long base1;
00246         
00247         /* increment frame pointer by lines */
00248         base1 = plcdc->dmabaddr1 + lcdc_conf->virtual_xres * lcdc_conf->pixelsize / 8 * line;
00249         /* increment frame pointer by pixel */
00250         base1 += 4 * pixel;
00251 
00252         /* do not allow to move the viewing area out of the virtual frame buffer */
00253         if((base1 >= lcdc_conf->dmabaddr1 ) && 
00254                         base1 <= (lcdc_conf->dmabaddr1 + lcdc_conf->virtual_xres * lcdc_conf->pixelsize / 8 * (lcdc_conf->virtual_yres - lcdc_conf->yres) ))
00255                 plcdc->dmabaddr1 = base1;
00256         else 
00257                 return -1;
00258         
00259         /* update DMA configuration DMAUPDT */
00260         plcdc->dmacon |=  (1 << AVR32_LCDC_DMACON_DMAUPDT_OFFSET);
00261         return 0;
00262 }
00270 int main (void)
00271 {
00272         volatile avr32_spi_t * spi = &AVR32_SPI0;
00273         unsigned int input;
00274         volatile avr32_pio_t *piob = &AVR32_PIOB;
00275         volatile avr32_pm_t *ppm = &AVR32_PM;
00276         
00277         board_init();
00278         piob->per = SWITCHES_MASK;
00279         piob->codr = SWITCHES_MASK;
00280         lcd_pio_config();
00281         
00282         memset((void *)ltv350qv_conf.dmabaddr1, 0, ltv350qv_conf.virtual_xres * ltv350qv_conf.virtual_yres * ltv350qv_conf.pixelsize / 8);
00283         
00284         print(usart, "Setting up SPI for LTV350QV panel\n");
00285         init_spiMaster(spi);
00286         
00287         print(usart,"Initializing LTV350QV panel\n");
00288         ltv350qv_power_on(spi, 1);
00289         
00290         print(usart, "Enabling LCD controller\n");
00291         /* Power manager setup 
00292         * Enable CLOCK for LCDC in HSBMASK
00293         */
00294         ppm->hsb_mask |= 0x00000080;    
00295         /* Enable generic clock PLL0 for LCD controller pixel clock*/
00296         ppm->gcctrl[7] |= 0x00000006;
00297         
00298         print(usart, "Initializing LCD controller\n");
00299         lcdc_init(&ltv350qv_conf);
00300         
00301         print(usart, "Filling frame buffer with data\n");
00302         /* print the image into the virtual framebuffer */
00303         display_virtual_bm(&ltv350qv_conf, ((void *) BITMAP_FILE_ADDRESS));
00304         
00305         while(1){
00306                 
00307                 usdelay(100000);
00308                 /* get input from the switches */
00309                 input = ~( piob->pdsr & SWITCHES_MASK);
00310                 
00311                 if(input & SWITCH0){
00312                         increment_frame_base(&ltv350qv_conf, 10, 0);
00313                 }
00314                 if(input & SWITCH1){
00315                         increment_frame_base(&ltv350qv_conf, -10, 0);
00316                 }
00317                 if(input & SWITCH2){
00318                         increment_frame_base(&ltv350qv_conf, 0, -10);
00319                 }
00320                 if(input & SWITCH3){
00321                         increment_frame_base(&ltv350qv_conf, 0, 10);
00322                 }
00323         }
00324         return 0;
00325 }

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