00001
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
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
00163 spi_initMaster(spi, &spiOptions);
00164
00165
00166 spi_selectionMode(spi, 0, 0, 0);
00167
00168
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
00248 base1 = plcdc->dmabaddr1 + lcdc_conf->virtual_xres * lcdc_conf->pixelsize / 8 * line;
00249
00250 base1 += 4 * pixel;
00251
00252
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
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
00292
00293
00294 ppm->hsb_mask |= 0x00000080;
00295
00296 ppm->gcctrl[7] |= 0x00000006;
00297
00298 print(usart, "Initializing LCD controller\n");
00299 lcdc_init(<v350qv_conf);
00300
00301 print(usart, "Filling frame buffer with data\n");
00302
00303 display_virtual_bm(<v350qv_conf, ((void *) BITMAP_FILE_ADDRESS));
00304
00305 while(1){
00306
00307 usdelay(100000);
00308
00309 input = ~( piob->pdsr & SWITCHES_MASK);
00310
00311 if(input & SWITCH0){
00312 increment_frame_base(<v350qv_conf, 10, 0);
00313 }
00314 if(input & SWITCH1){
00315 increment_frame_base(<v350qv_conf, -10, 0);
00316 }
00317 if(input & SWITCH2){
00318 increment_frame_base(<v350qv_conf, 0, -10);
00319 }
00320 if(input & SWITCH3){
00321 increment_frame_base(<v350qv_conf, 0, 10);
00322 }
00323 }
00324 return 0;
00325 }