lcdc_moving_bitmap_example.c File Reference


Detailed Description

LCD controller example for the STK1000.

This example shows the use of the 2D addressing mode on the LCD controller. The virtual frame buffer is two times the size of the LCD viewing area. Before you run this application program the picture (AVR32.bmp) into the flash at address 0x00400000. Use the avr32program application for this purpose. avr32program -F bin -O 0x00400000 If you intend to program the picture to another location change the define BITMAP_FILE_ADDRESS accordingly.

The input (switches) header marked J25, used for moving around the virtual frame buffer, must be connected to the header labeled J1 (PORTB[0..7]).

To move the viewing area use following switches: Switch0: Move viewing area 10 pixels to the right Switch1: Move viewing area 10 pixels to the left Switch2: Move viewing area 10 lines up Switch3: Move viewing area 10 lines down

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/
$Name$
Revision
668M
$RCSfile$
Date
2008-05-07 15:58:43 +0200 (Wed, 07 May 2008)

Definition in file lcdc_moving_bitmap_example.c.

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

Include dependency graph for lcdc_moving_bitmap_example.c:

Go to the source code of this file.

Defines

#define BITMAP_FILE_ADDRESS   0x00400000
 Start address of the bitmap file.
#define SWITCH0   0x00000001
#define SWITCH1   0x00000002
#define SWITCH2   0x00000004
#define SWITCH3   0x00000008
#define SWITCHES_MASK   0x000000FF

Functions

int display_virtual_bm (lcdc_conf_t *lcdc_conf, void *bm_file)
 Dispays the content of a bitmap file in the virtual frame buffer.
int increment_frame_base (lcdc_conf_t *lcdc_conf, int pixel, int line)
 Move the viewing area in the virtual frame buffer.
void init_spiMaster (volatile avr32_spi_t *spi)
 Initialise SPI in master mode for the LCD.
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)
 2D addressing mode example for the STK1000 Connect switches pins to J1. Switch0: Move viewing area 10 pixels to the right Switch1: Move viewing area 10 pixels to the left Switch2: Move viewing area 10 lines up Switch3: Move viewing area 10 lines down
void print (volatile struct avr32_usart_t *usart, char *str)
 Print a string of characters to an usart.
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.


Define Documentation

#define BITMAP_FILE_ADDRESS   0x00400000

Start address of the bitmap file.

Definition at line 88 of file lcdc_moving_bitmap_example.c.

Referenced by main().

#define SWITCH0   0x00000001

Definition at line 82 of file lcdc_moving_bitmap_example.c.

Referenced by main().

#define SWITCH1   0x00000002

Definition at line 83 of file lcdc_moving_bitmap_example.c.

Referenced by main().

#define SWITCH2   0x00000004

Definition at line 84 of file lcdc_moving_bitmap_example.c.

Referenced by main().

#define SWITCH3   0x00000008

Definition at line 85 of file lcdc_moving_bitmap_example.c.

Referenced by main().

#define SWITCHES_MASK   0x000000FF

Definition at line 81 of file lcdc_moving_bitmap_example.c.

Referenced by main().


Function Documentation

int display_virtual_bm ( lcdc_conf_t lcdc_conf,
void *  file_start 
)

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

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

Definition at line 241 of file bmp_lib.c.

References bm_file_header_t::bfOffBits, bm_file_header_t::bfSize, bm_file_header_t::bfType, bm_info_header_t::biBitCount, bm_info_header_t::biCompression, bm_info_header_t::biHeight, bm_info_header_t::biWidth, fill_virtual_frame_buffer_bm(), and swap_endian_blk().

Referenced by main().

00241                                                                  {
00242         
00243         bm_file_header_t bm_file_header;
00244         bm_info_header_t bm_info_header;
00245         unsigned char * data_start;
00246         
00247         /* get file header and header information */
00248         memcpy(&bm_file_header, file_start, sizeof(bm_file_header_t));
00249         memcpy(&bm_info_header, file_start + 14, sizeof(bm_info_header_t));
00250         
00251         /* correct endianess */
00252         swap_endian_blk((unsigned char *) &bm_file_header.bfType, 2);
00253         swap_endian_blk((unsigned char *) &bm_file_header.bfSize, 4);
00254         swap_endian_blk((unsigned char *) &bm_file_header.bfOffBits, 4);
00255         swap_endian_blk((unsigned char *) &bm_info_header.biWidth, 4);
00256         swap_endian_blk((unsigned char *) &bm_info_header.biHeight, 4);
00257         swap_endian_blk((unsigned char *) &bm_info_header.biBitCount, 2);
00258         swap_endian_blk((unsigned char *) &bm_info_header.biCompression, 4);
00259         
00260         
00261         data_start = file_start + bm_file_header.bfOffBits;     
00262         fill_virtual_frame_buffer_bm(lcdc_conf, &bm_info_header, data_start);
00263         
00264         return 0;               
00265 }

Here is the call graph for this function:

int increment_frame_base ( lcdc_conf_t lcdc_conf,
int  pixel,
int  line 
)

Move the viewing area in the virtual frame buffer.

Parameters:
lcdc_conf Pointer to the LCD controller configuration
pixel Number of pixels to move the viewing area
line Number of lines to move the viewing area
Returns:
Returns the status of the movement
Return values:
0 Movement succeeded
-1 Movement was not successfull (viewing are is out of the virtual frame buffer

Definition at line 242 of file lcdc_moving_bitmap_example.c.

References lcdc_conf_t::dmabaddr1, lcdc_conf_t::pixelsize, lcdc_conf_t::virtual_xres, lcdc_conf_t::virtual_yres, and lcdc_conf_t::yres.

Referenced by main().

00242                                                                      {
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 }

void init_spiMaster ( volatile avr32_spi_t *  spi  ) 

Initialise SPI in master mode for the LCD.

Parameters:
spi Pointer to the correct avr32_spi_t struct

Definition at line 136 of file lcdc_moving_bitmap_example.c.

References spi_options_t::baudrate, spi_options_t::bits, spi_options_t::fdiv, spi_options_t::modfdis, pio_enable_module(), PM_PBA_SPI0, pm_read_module_frequency(), 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.

Referenced by main().

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 }

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 192 of file lcdc_moving_bitmap_example.c.

References pio_enable_module().

Referenced by main().

00192                          {
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 }

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.

Referenced by main().

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 }

int main ( void   ) 

2D addressing mode example for the STK1000 Connect switches pins to J1. Switch0: Move viewing area 10 pixels to the right Switch1: Move viewing area 10 pixels to the left Switch2: Move viewing area 10 lines up Switch3: Move viewing area 10 lines down

Definition at line 270 of file lcdc_moving_bitmap_example.c.

References BITMAP_FILE_ADDRESS, board_init(), display_virtual_bm(), lcdc_conf_t::dmabaddr1, increment_frame_base(), init_spiMaster(), lcd_pio_config(), lcdc_init(), ltv350qv_power_on(), lcdc_conf_t::pixelsize, print(), SWITCH0, SWITCH1, SWITCH2, SWITCH3, SWITCHES_MASK, usart, usdelay(), lcdc_conf_t::virtual_xres, and lcdc_conf_t::virtual_yres.

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 }

Here is the call graph for this function:

void print ( volatile struct avr32_usart_t *  usart,
char *  str 
)

Print a string of characters to an usart.

Parameters:
*usart The usart to write to
*str The string of characters
Returns:
;

Definition at line 183 of file lcdc_moving_bitmap_example.c.

References usart_putchar().

Referenced by main().

00184 {
00185         while (*str != '\0')
00186                 usart_putchar(usart, *str++);
00187 }

Here is the call graph for this function:

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

Definition at line 36 of file at32stk1000.c.

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 }

void usdelay ( unsigned long  usec  ) 

Delay execution for a specificated time.

Parameters:
usec Delay in microseconds

Definition at line 77 of file ltv350qv.c.

Referenced by ltv350qv_power_off(), ltv350qv_power_on(), and main().

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 }


Variable Documentation

lcdc_conf_t ltv350qv_conf

LCD controller configuration.

Definition at line 91 of file lcdc_moving_bitmap_example.c.

volatile avr32_usart_t* usart = &AVR32_USART1

USART used for console output.

Definition at line 130 of file lcdc_moving_bitmap_example.c.

Referenced by board_init(), init_uart_a(), ltv350qv_power_off(), ltv350qv_power_on(), and main().


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