SAMV71 Xplained Ultra Software Package 1.4

main.c

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2011, Atmel Corporation
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * - Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the disclaimer below.
00013  *
00014  * Atmel's name may not be used to endorse or promote products derived from
00015  * this software without specific prior written permission.
00016  *
00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  * ----------------------------------------------------------------------------
00028  */
00029 
00030 /**
00031  *  \page lcd LCD example
00032  *
00033  *  \section Purpose
00034  *
00035  *  This example demonstrates how to configure the LCD with SPI interface
00036  *
00037  *  \section Requirements
00038  *
00039  *  This package can be used with SAM V71 Xplained Ultra board with maXtouch 
00040  *  xplained LCD board. LCD board must be set to 4-wire SPI configuration with 
00041  *  the help of switch behind LCD. It should be in IM0, IM1 and IM2 should be in 
00042  *  On position. Connect the LCD pad to EXT2 connectors.
00043  *  \section Description
00044  *
00045  *  \section Usage
00046  *
00047  *  -# Build the program and download it inside the SAM V71 Xplained Ultra board. 
00048  * Please refer to the Getting Started with SAM V71 Microcontrollers.pdf
00049  *  -# On the computer, open and configure a terminal application
00050  *     (e.g. HyperTerminal on Microsoft Windows) with these settings:
00051  *    - 115200 baud rate
00052  *    - 8 bits of data
00053  *    - No parity
00054  *    - 1 stop bit
00055  *    - No flow control
00056  *  -# Start the application.
00057  *  -# In the terminal window, the
00058  *     following text should appear (values depend on the board and chip used):
00059  *     \code
00060  *      -- LCD Example xxx --
00061  *      -- xxxxxx-xx
00062  *      -- Compiled: xxx xx xxxx xx:xx:xx --
00063  *     \endcode
00064  *
00065  *  \section References
00066  *  - lcd/main.c
00067  *  - trace.h
00068  */
00069 
00070 /** \file
00071  *
00072  *  This file contains all the specific code for the xplained LCD example.
00073  *
00074  */
00075 
00076 /*----------------------------------------------------------------------------
00077  *        Headers
00078  *----------------------------------------------------------------------------*/
00079 
00080 #include "board.h"
00081 #include "image.h"
00082 #include <stdbool.h>
00083 #include <stdio.h>
00084 #include <stdlib.h>
00085 #include <string.h>
00086 
00087 /*----------------------------------------------------------------------------
00088  *        Local Definition
00089  *----------------------------------------------------------------------------*/
00090  /* #define USE_SDRAM */
00091 #define COLOR_CONVERT       RGB_24_TO_18BIT
00092 
00093 #define HEADLINE_OFFSET     25
00094 
00095 #define LCD_MODE           ILI9488_SPIMODE
00096  
00097 #if defined USE_SDRAM 
00098 #define CANVAS_LCD_WIDTH    BOARD_LCD_WIDTH
00099 #define CANVAS_LCD_HEIGHT   BOARD_LCD_HEIGHT
00100 
00101 #else
00102 #define CANVAS_LCD_WIDTH    240
00103 #define CANVAS_LCD_HEIGHT   360
00104  
00105 #endif
00106 /*----------------------------------------------------------------------------
00107  *        Local variables
00108  *----------------------------------------------------------------------------*/
00109 /** Global DMA driver for all transfer */
00110 static sXdmad lcdSpiDma;
00111 
00112 /** Image buffer (16-bits color). */
00113 const uint32_t gImageBuffer[DEMO_IMAGE_HEIGHT * DEMO_IMAGE_WIDTH] = DEMO_IMAGE;
00114 #if defined USE_SDRAM 
00115 COMPILER_SECTION("sdram_region")
00116 #endif
00117 static sBGR gLcdCavas[CANVAS_LCD_WIDTH * CANVAS_LCD_HEIGHT];
00118 
00119 
00120 /**
00121  * ISR for XDMA interrupt
00122  */
00123 void XDMAC_Handler(void)
00124 {
00125     XDMAD_Handler(&lcdSpiDma);
00126 }
00127 
00128 /**
00129  *  \brief LCD Application entry point.
00130  *
00131  *  \return Unused (ANSI-C compatibility).
00132  */
00133 extern int main( void )
00134 {
00135     uint32_t i, j;
00136     int32_t dX, dY;
00137     rect rc;
00138     const uint8_t String[] = "LCD Example";
00139     /* Disable watchdog */
00140     WDT_Disable( WDT ) ;
00141 
00142     SCB_EnableICache();
00143     SCB_EnableDCache();
00144 
00145     /* Output example information */
00146     printf( "-- LCD Example %s --\n\r", SOFTPACK_VERSION ) ;
00147     printf( "-- %s\n\r", BOARD_NAME ) ;
00148     printf( "-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME);
00149 
00150 #if defined USE_SDRAM 
00151     BOARD_ConfigureSdram();
00152 #endif
00153     /* Configure systick for 1 ms. */
00154     TimeTick_Configure();
00155 
00156     /* Initialize LCD and its interface */
00157     LCDD_Initialize(LCD_MODE, &lcdSpiDma, 0);
00158     LCDD_SetCavasBuffer(gLcdCavas, sizeof(gLcdCavas));
00159     //LCDD_SetCavasBuffer(0, 0);
00160     rc.x = 0;
00161     rc.y = 0;
00162     rc.width = CANVAS_LCD_WIDTH - 1;
00163     rc.height = CANVAS_LCD_HEIGHT - 1;
00164     LCDD_SetUpdateWindowSize(rc);
00165 
00166     LCDD_DrawRectangleWithFill(0, 0, 0, CANVAS_LCD_WIDTH - 1, CANVAS_LCD_HEIGHT - 1, 
00167             COLOR_CONVERT(COLOR_WHITE));
00168     LCDD_UpdateWindow();
00169     Wait(1000);
00170 
00171     LCDD_DrawRectangleWithFill(0, 0, 0, CANVAS_LCD_WIDTH - 1, CANVAS_LCD_HEIGHT - 1, 
00172             COLOR_CONVERT(COLOR_BLUE));
00173     LCDD_UpdateWindow();
00174     Wait(1000);
00175     
00176     LCD_DrawString(0, 50, 5, String,  RGB_24_TO_18BIT(COLOR_BLACK));
00177     LCDD_UpdateWindow();
00178     Wait(500);
00179     
00180     /* Test basic color space translation and LCD_DrawFilledRectangle */
00181     LCDD_DrawRectangleWithFill(0, 
00182                             0, 
00183                             HEADLINE_OFFSET, 
00184                             CANVAS_LCD_WIDTH - 1, 
00185                             CANVAS_LCD_HEIGHT - 1 - HEADLINE_OFFSET, 
00186                             COLOR_CONVERT(COLOR_WHITE));
00187     LCDD_UpdateWindow();
00188     Wait(500);
00189     
00190     LCDD_DrawRectangleWithFill(0, 
00191                             4, 
00192                             4 + HEADLINE_OFFSET, 
00193                             CANVAS_LCD_WIDTH - 5 - 4, 
00194                             CANVAS_LCD_HEIGHT - 5 - HEADLINE_OFFSET, 
00195                             COLOR_CONVERT(COLOR_BLACK));
00196     LCDD_UpdateWindow();
00197     Wait(500);
00198     
00199     LCDD_DrawRectangleWithFill(0, 
00200                             8, 
00201                             8 + HEADLINE_OFFSET, 
00202                             CANVAS_LCD_WIDTH - 9 - 8, 
00203                             CANVAS_LCD_HEIGHT- 9 - 8 - HEADLINE_OFFSET, 
00204                             COLOR_CONVERT(COLOR_BLUE));
00205     LCDD_UpdateWindow();
00206     Wait(500);
00207     
00208     LCDD_DrawRectangleWithFill(0, 
00209                             12, 
00210                             12 + HEADLINE_OFFSET, 
00211                             CANVAS_LCD_WIDTH - 13 - 12, 
00212                             CANVAS_LCD_HEIGHT - 13 - 12 - HEADLINE_OFFSET, 
00213                             COLOR_CONVERT(COLOR_RED));
00214     LCDD_UpdateWindow();
00215     Wait(500);
00216     
00217     LCDD_DrawRectangleWithFill(0, 
00218                             16, 
00219                             14 + HEADLINE_OFFSET, 
00220                             CANVAS_LCD_WIDTH - 17 - 16, 
00221                             CANVAS_LCD_HEIGHT - 17 - 14 - HEADLINE_OFFSET, 
00222                             COLOR_CONVERT(COLOR_GREEN));
00223     LCDD_UpdateWindow();
00224     Wait(500);
00225     /* Test horizontal/vertical LCD_drawLine  */
00226     LCDD_DrawLine(0, 
00227                 0, 
00228                 CANVAS_LCD_HEIGHT / 2, 
00229                 CANVAS_LCD_WIDTH -1, 
00230                 CANVAS_LCD_HEIGHT / 2, 
00231             COLOR_CONVERT(COLOR_RED));
00232     LCDD_UpdateWindow();
00233     Wait(500);
00234     
00235     LCDD_DrawLine(0, 
00236                 CANVAS_LCD_WIDTH / 2, 
00237                 HEADLINE_OFFSET , 
00238                 CANVAS_LCD_WIDTH / 2, 
00239                 CANVAS_LCD_HEIGHT-1, COLOR_CONVERT(COLOR_RED));
00240     LCDD_UpdateWindow();
00241     Wait(500);
00242     
00243     /* Test LCD_drawLine  */
00244     LCDD_DrawLine(0, 
00245                 0, 
00246                 0 , 
00247                 CANVAS_LCD_WIDTH -1, 
00248                 CANVAS_LCD_HEIGHT - 1, 
00249             RGB_24_TO_RGB565(COLOR_RED));
00250     LCDD_UpdateWindow();
00251     Wait(500);
00252     
00253     LCDD_DrawLine(0, 
00254                 0, 
00255                 CANVAS_LCD_HEIGHT - 1, 
00256                 CANVAS_LCD_WIDTH - 1, 0, 
00257                 RGB_24_TO_RGB565(COLOR_RED));
00258     LCDD_UpdateWindow();
00259     Wait(500);
00260     
00261     /* Test LCD_DrawRectangle */
00262     LCDD_DrawRectangle(0, 
00263                     CANVAS_LCD_WIDTH / 4, 
00264                     CANVAS_LCD_HEIGHT / 4, 
00265                     CANVAS_LCD_WIDTH * 3 / 4 - CANVAS_LCD_WIDTH / 4 , 
00266                     CANVAS_LCD_HEIGHT * 3 / 4 - CANVAS_LCD_HEIGHT / 4 , 
00267                     COLOR_CONVERT(COLOR_RED));
00268     LCDD_UpdateWindow();
00269     Wait(500);
00270     
00271     LCDD_DrawRectangle(0, 
00272                     CANVAS_LCD_WIDTH / 3, 
00273                     CANVAS_LCD_HEIGHT / 3, 
00274                     CANVAS_LCD_WIDTH * 2 / 3 - CANVAS_LCD_WIDTH / 3, 
00275                     CANVAS_LCD_HEIGHT * 2 / 3 - CANVAS_LCD_HEIGHT / 3, 
00276                     COLOR_CONVERT(COLOR_RED));
00277     LCDD_UpdateWindow();
00278     Wait(500);
00279     
00280     /* Test LCD_DrawFilledCircle */
00281     LCD_DrawFilledCircle(0, 
00282                         CANVAS_LCD_WIDTH * 3 / 4, 
00283                         CANVAS_LCD_HEIGHT * 3 / 4, 
00284                         CANVAS_LCD_WIDTH / 4, 
00285                         COLOR_CONVERT(COLOR_BLUE));
00286     LCDD_UpdateWindow();
00287     Wait(500);
00288 
00289     LCD_DrawFilledCircle(0, 
00290                         CANVAS_LCD_WIDTH / 2, 
00291                         CANVAS_LCD_HEIGHT / 2, 
00292                         CANVAS_LCD_HEIGHT / 4, 
00293                         COLOR_CONVERT(COLOR_WHITE));
00294     LCDD_UpdateWindow();
00295     Wait(500);
00296     
00297     LCD_DrawFilledCircle(0, 
00298                         CANVAS_LCD_WIDTH / 4, 
00299                         CANVAS_LCD_HEIGHT * 3 / 4, 
00300                         CANVAS_LCD_HEIGHT / 4, 
00301                         COLOR_CONVERT(COLOR_RED));
00302     LCDD_UpdateWindow();
00303     Wait(500);
00304     
00305     LCD_DrawFilledCircle(0, 
00306                         CANVAS_LCD_WIDTH * 3 / 4, 
00307                         CANVAS_LCD_HEIGHT / 4, 
00308                         CANVAS_LCD_WIDTH / 4, 
00309                         COLOR_CONVERT(COLOR_YELLOW));
00310     LCDD_UpdateWindow();
00311     Wait(500);
00312     /* Test LCD_DrawPicture */
00313     LCDD_DrawImage(0, 50, 50, (LcdColor_t *)gImageBuffer ,  (50 + DEMO_IMAGE_WIDTH), 
00314             (50 + DEMO_IMAGE_HEIGHT));
00315     LCDD_UpdateWindow();
00316     Wait(3000);
00317 
00318     LCDD_DrawRectangleWithFill(0, 
00319                             0, 
00320                             0, 
00321                             CANVAS_LCD_WIDTH - 1, 
00322                             CANVAS_LCD_HEIGHT - 1, 
00323                             COLOR_CONVERT(COLOR_BLACK));
00324 
00325     /** Move picture across the screen */
00326     dX=2; dY=2;j=0; i=0;
00327 
00328     for(; ;) {
00329         for(; i < (CANVAS_LCD_WIDTH-DEMO_IMAGE_WIDTH - 1);) {
00330             LCDD_DrawRectangleWithFill(0, 
00331                                     0, 
00332                                     0, 
00333                                     CANVAS_LCD_WIDTH - 1, 
00334                                     CANVAS_LCD_HEIGHT - 1, 
00335                                     COLOR_CONVERT(COLOR_BLACK));
00336             LCDD_DrawImage(0, i, j, (LcdColor_t *)gImageBuffer, (i + DEMO_IMAGE_WIDTH), 
00337                     (j + DEMO_IMAGE_HEIGHT));
00338             LCDD_UpdateWindow();
00339 
00340             j +=dY;
00341             i +=dX;
00342 
00343             if((i >= (CANVAS_LCD_WIDTH - DEMO_IMAGE_WIDTH - 1 )) && 
00344                     (j < (CANVAS_LCD_HEIGHT - DEMO_IMAGE_HEIGHT - 1 ))) {
00345                 i -=dX;dX=-dX;
00346             }
00347             else if((i < (CANVAS_LCD_WIDTH-DEMO_IMAGE_WIDTH - 1)) && 
00348                     (j >= (CANVAS_LCD_HEIGHT-DEMO_IMAGE_HEIGHT - 1))) {
00349                 j -=dY;
00350                 dY=-dY;
00351             }
00352         }
00353         i = 0;
00354         j = 0;
00355     }
00356 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines