# 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 program -F bin -O 0x00400000 -evfcfi AVR32.bmp 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

- Compiler = GNU GCC and IAR EWAVR32 for AVR32
- Supported devices = All AVR32AP devices with a SIDSA LCD controller
- AppNote = AVR32114 Using the AVR32 LCD controller

Author:
  Atmel Corporation = http =//www.atmel.com
  Support and FAQ = http =//support.atmel.no/

Definition in file lcdc_moving_bitmap_example.c.

`#include <string.h>`
`#include "usart.h"`
`#include "gpio.h"`
`#include "spi_at32ap7000.h"`
`#include "lcdc.h"`
`#include "board.h"`
`#include "ltv350qv.h"`
`#include "bmp_lib.h"`
`#include "print_funcs.h"`
`#include "pm_at32ap7000.h"`
`#include "sdramc_at32ap7000.h"`

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 | 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, long cpuHz)
| Initialise SPI in master mode for the LCD.
void | lcd_pio_config (void)
| Sets up the pins for the LCD on the STK1000.
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 | usdelay (unsigned long usec)
## Variables
static lcdc_conf_t | ltv350qv_conf
| LCD controller configuration.

## Define Documentation

#define BITMAP_FILE_ADDRESS 0x00400000

Start address of the bitmap file.

Definition at line 136 of file lcdc_moving_bitmap_example.c.

Referenced by main().

#define SWITCH0 0x00000001

Definition at line 130 of file lcdc_moving_bitmap_example.c.

Referenced by main().

#define SWITCH1 0x00000002

Definition at line 131 of file lcdc_moving_bitmap_example.c.

Referenced by main().

#define SWITCH2 0x00000004

Definition at line 132 of file lcdc_moving_bitmap_example.c.

Referenced by main().

#define SWITCH3 0x00000008

Definition at line 133 of file lcdc_moving_bitmap_example.c.

Referenced by main().

#define SWITCHES_MASK 0x000000FF

Definition at line 129 of file lcdc_moving_bitmap_example.c.

Referenced by main().

## Function Documentation

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

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

Referenced by main().

    00270                                                                      {
    00271
    00272   volatile avr32_lcdc_t *plcdc = &AVR32_LCDC;
    00273   unsigned long base1;
    00274
    00275   /* increment frame pointer by lines */
    00276   base1 = plcdc->dmabaddr1 + lcdc_conf->virtual_xres * lcdc_conf->pixelsize / 8 * line;
    00277   /* increment frame pointer by pixel */
    00278   base1 += 4 * pixel;
    00279
    00280   /* do not allow to move the viewing area out of the virtual frame buffer */
    00281   if((base1 >= lcdc_conf->dmabaddr1 ) &&
    00282       base1 <= (lcdc_conf->dmabaddr1 + lcdc_conf->virtual_xres * lcdc_conf->pixelsize / 8 * (lcdc_conf->virtual_yres - lcdc_conf->yres) ))
    00283     plcdc->dmabaddr1 = base1;
    00284   else
    00285     return -1;
    00286
    00287   /* update DMA configuration DMAUPDT */
    00288   plcdc->dmacon |=  (1 << AVR32_LCDC_DMACON_DMAUPDT_OFFSET);
    00289   return 0;
    00290 }

void init_spiMaster | ( | volatile avr32_spi_t * | spi,
|  | long | cpuHz |
| ) |  |  |

Initialise SPI in master mode for the LCD.

Parameters:

  | spi | Pointer to the correct avr32_spi_t struct
  | cpuHz | the CPU clock frequency.

Definition at line 182 of file lcdc_moving_bitmap_example.c.

Referenced by main().

    00183 {
    00184   gpio_map_t spi_piomap = {          \
    00185     {AVR32_SPI0_SCK_0_PIN, AVR32_SPI0_SCK_0_FUNCTION},  \
    00186     {AVR32_SPI0_MISO_0_PIN, AVR32_SPI0_MISO_0_FUNCTION},  \
    00187     {AVR32_SPI0_MOSI_0_PIN, AVR32_SPI0_MOSI_0_FUNCTION},  \
    00188     {AVR32_SPI0_NPCS_0_PIN, AVR32_SPI0_NPCS_0_FUNCTION},  \
    00189     {AVR32_SPI0_NPCS_1_PIN, AVR32_SPI0_NPCS_1_FUNCTION},  \
    00190     {AVR32_SPI0_NPCS_2_PIN, AVR32_SPI0_NPCS_2_FUNCTION},  \
    00191     {AVR32_SPI0_NPCS_3_PIN, AVR32_SPI0_NPCS_3_FUNCTION},  \
    00192   };
    00193   gpio_enable_module(spi_piomap, 7);
    00194
    00195   spi_options_t spiOptions = {
    00196     .reg = 1,
    00197     .baudrate = 1500000,
    00198     .bits = 8,
    00199     .spck_delay = 0,
    00200     .trans_delay = 0,
    00201     .stay_act = 1,
    00202     .spi_mode = 3,
    00203     .modfdis = 0,
    00204   };
    00205
    00206   /* Initialize as master */
    00207   spi_initMaster(spi, &spiOptions);
    00208
    00209   /* Set master mode; variable_ps, pcs_decode, delay */
    00210   spi_selectionMode(spi, 0, 0, 0);
    00211   /* Select slave chip 1 (SPI_NPCS1) */
    00212   spi_selectChip(spi, 1);
    00213   spi_setupChipReg(spi, &spiOptions, cpuHz);
    00214   spi_enable(spi);
    00215 }

void lcd_pio_config | ( | void |  | ) |

Sets up the pins for the LCD on the STK1000.

Definition at line 220 of file lcdc_moving_bitmap_example.c.

Referenced by main().

    00220                          {
    00221     gpio_map_t piomap = {
    00222       { AVR32_LCDC_CC_0_0_PIN, AVR32_LCDC_CC_0_0_FUNCTION },
    00223       { AVR32_LCDC_DVAL_0_0_PIN, AVR32_LCDC_DVAL_0_0_FUNCTION },
    00224       { AVR32_LCDC_HSYNC_0_PIN, AVR32_LCDC_HSYNC_0_FUNCTION },
    00225       { AVR32_LCDC_MODE_0_0_PIN, AVR32_LCDC_MODE_0_0_FUNCTION },
    00226       { AVR32_LCDC_PCLK_0_PIN, AVR32_LCDC_PCLK_0_FUNCTION },
    00227       { AVR32_LCDC_PWR_0_PIN, AVR32_LCDC_PWR_0_FUNCTION },
    00228       { AVR32_LCDC_VSYNC_0_PIN, AVR32_LCDC_VSYNC_0_FUNCTION },
    00229       { AVR32_LCDC_DATA_0_0_PIN, AVR32_LCDC_DATA_0_0_FUNCTION },
    00230       { AVR32_LCDC_DATA_1_0_PIN, AVR32_LCDC_DATA_1_0_FUNCTION },
    00231       { AVR32_LCDC_DATA_2_0_PIN, AVR32_LCDC_DATA_1_0_FUNCTION },
    00232       { AVR32_LCDC_DATA_3_0_PIN, AVR32_LCDC_DATA_1_0_FUNCTION },
    00233       { AVR32_LCDC_DATA_4_0_PIN, AVR32_LCDC_DATA_1_0_FUNCTION },
    00234       { AVR32_LCDC_DATA_5_PIN, AVR32_LCDC_DATA_5_FUNCTION },
    00235       { AVR32_LCDC_DATA_6_PIN, AVR32_LCDC_DATA_6_FUNCTION },
    00236       { AVR32_LCDC_DATA_7_PIN, AVR32_LCDC_DATA_7_FUNCTION },
    00237       { AVR32_LCDC_DATA_8_0_PIN, AVR32_LCDC_DATA_8_0_FUNCTION },
    00238       { AVR32_LCDC_DATA_9_0_PIN, AVR32_LCDC_DATA_9_0_FUNCTION },
    00239       { AVR32_LCDC_DATA_10_0_PIN, AVR32_LCDC_DATA_10_0_FUNCTION },
    00240       { AVR32_LCDC_DATA_11_0_PIN, AVR32_LCDC_DATA_11_0_FUNCTION },
    00241       { AVR32_LCDC_DATA_12_0_PIN, AVR32_LCDC_DATA_12_0_FUNCTION },
    00242       { AVR32_LCDC_DATA_13_PIN, AVR32_LCDC_DATA_13_FUNCTION },
    00243       { AVR32_LCDC_DATA_14_PIN, AVR32_LCDC_DATA_14_FUNCTION },
    00244       { AVR32_LCDC_DATA_15_PIN, AVR32_LCDC_DATA_15_FUNCTION },
    00245       { AVR32_LCDC_DATA_16_0_PIN, AVR32_LCDC_DATA_16_0_FUNCTION },
    00246       { AVR32_LCDC_DATA_17_0_PIN, AVR32_LCDC_DATA_17_0_FUNCTION },
    00247       { AVR32_LCDC_DATA_18_0_PIN, AVR32_LCDC_DATA_18_0_FUNCTION },
    00248       { AVR32_LCDC_DATA_19_0_PIN, AVR32_LCDC_DATA_19_0_FUNCTION },
    00249       { AVR32_LCDC_DATA_20_0_PIN, AVR32_LCDC_DATA_20_0_FUNCTION },
    00250       { AVR32_LCDC_DATA_21_0_PIN, AVR32_LCDC_DATA_21_0_FUNCTION },
    00251       { AVR32_LCDC_DATA_22_PIN, AVR32_LCDC_DATA_22_FUNCTION },
    00252       { AVR32_LCDC_DATA_23_PIN, AVR32_LCDC_DATA_23_FUNCTION }
    00253
    00254   };
    00255   gpio_enable_module(piomap, 31);
    00256 }

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

References BITMAP_FILE_ADDRESS, lcdc_configuration_s::dmabaddr1, increment_frame_base(), init_spiMaster(), lcd_pio_config(), lcdc_init(), lcdc_configuration_s::pixelsize, SWITCH0, SWITCH1, SWITCH2, SWITCH3, SWITCHES_MASK, usdelay(), lcdc_configuration_s::virtual_xres, and lcdc_configuration_s::virtual_yres.

    00300 {
    00301   volatile avr32_spi_t * spi = &AVR32_SPI0;
    00302   unsigned int input;
    00303   volatile avr32_pio_t *piob = &AVR32_PIOB;
    00304
    00305   // Reset PM. Makes sure we get the expected clocking after a soft reset (e.g.: JTAG reset)
    00306   pm_reset();
    00307
    00308   // Start PLL0 giving 80 MHz clock
    00309   pm_pll_opt_t pll_opt = {
    00310     .pll_id = 0,
    00311     .mul = 4,
    00312     .div = 1,
    00313     .osc_id = 0,
    00314     .count = 16,
    00315     .wait_for_lock = 1,
    00316   };
    00317   pm_start_pll(&pll_opt);
    00318
    00319   // Divide HSB by 2, PBB by 2 and PBA by 4 to keep them below maximum ratings
    00320   pm_set_clock_domain_scaler(PM_HSB_DOMAIN, 2);
    00321   pm_set_clock_domain_scaler(PM_PBB_DOMAIN, 2);
    00322   pm_set_clock_domain_scaler(PM_PBA_DOMAIN, 4);
    00323
    00324   pm_set_mclk_source(PM_PLL0);
    00325
    00326   /* Init debug serial line */
    00327   init_dbg_rs232(pm_read_module_freq_hz(PM_PBA_USART1));
    00328
    00329   print_dbg("\nCPU running at ");
    00330   print_dbg_ulong(pm_get_mclk_freq_hz()/1000000);
    00331   print_dbg(" MHz\n");
    00332
    00333   sdramc_init(pm_read_module_freq_hz(PM_PBB_HSDRAMC));
    00334
    00335   piob->per = SWITCHES_MASK;
    00336   piob->codr = SWITCHES_MASK;
    00337   lcd_pio_config();
    00338
    00339   print_dbg("Board init complete\n");
    00340
    00341   print_dbg("Setting up SPI for LTV350QV panel\n");
    00342   init_spiMaster(spi, pm_read_module_freq_hz(PM_PBA_SPI0));
    00343   print_dbg("Initializing LTV350QV panel\n");
    00344   ltv350qv_power_on(spi, 1);
    00345   print_dbg("Setting up LCD controller\n");
    00346
    00347   print_dbg("Enabling LCD controller\n");
    00348   /* Power manager setup
    00349   * Enable CLOCK for LCDC in HSBMASK
    00350   */
    00351   pm_enable_module(PM_HSB_LCDC);
    00352   /* Enable generic clock PLL0 for LCD controller pixel clock*/
    00353   pm_gen_clk_opt_t gen_clk_opt = {
    00354     .clock_source = PM_PLL0,
    00355     .divider = 2,
    00356   };
    00357   pm_start_generic_clock(7, &gen_clk_opt);
    00358
    00359   print_dbg("Initializing LCD controller\n");
    00360   lcdc_init(&ltv350qv_conf);
    00361
    00362   print_dbg("Clearing the frame buffer\n");
    00363   memset((void *)ltv350qv_conf.dmabaddr1, 0, ltv350qv_conf.virtual_xres * ltv350qv_conf.virtual_yres * ltv350qv_conf.pixelsize / 8);
    00364
    00365   print_dbg("Filling the frame buffer\n");
    00366   /* print the image into the virtual framebuffer */
    00367   display_virtual_bm(&ltv350qv_conf, ((void *) BITMAP_FILE_ADDRESS));
    00368
    00369   while(1){
    00370
    00371     usdelay(100000);
    00372     /* get input from the switches */
    00373     input = ~( piob->pdsr & SWITCHES_MASK);
    00374
    00375     if(input & SWITCH0){
    00376       increment_frame_base(&ltv350qv_conf, 10, 0);
    00377     }
    00378     if(input & SWITCH1){
    00379       increment_frame_base(&ltv350qv_conf, -10, 0);
    00380     }
    00381     if(input & SWITCH2){
    00382       increment_frame_base(&ltv350qv_conf, 0, -10);
    00383     }
    00384     if(input & SWITCH3){
    00385       increment_frame_base(&ltv350qv_conf, 0, 10);
    00386     }
    00387   }
    00388 }

void usdelay | ( | unsigned long | usec | ) |

Referenced by main().

## Variable Documentation

lcdc_conf_t ltv350qv_conf`[static]`

LCD controller configuration.

Definition at line 139 of file lcdc_moving_bitmap_example.c.