SAMV71 Xplained Ultra Software Package 1.5

main.c

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------- */
00002 /*                  Atmel Microcontroller Software Support                      */
00003 /*                       SAM Software Package License                           */
00004 /* ---------------------------------------------------------------------------- */
00005 /* Copyright (c) 2015, Atmel Corporation                                        */
00006 /*                                                                              */
00007 /* All rights reserved.                                                         */
00008 /*                                                                              */
00009 /* Redistribution and use in source and binary forms, with or without           */
00010 /* modification, are permitted provided that the following condition is met:    */
00011 /*                                                                              */
00012 /* - Redistributions of source code must retain the above copyright notice,     */
00013 /* this list of conditions and the disclaimer below.                            */
00014 /*                                                                              */
00015 /* Atmel's name may not be used to endorse or promote products derived from     */
00016 /* this software without specific prior written permission.                     */
00017 /*                                                                              */
00018 /* DISCLAIMER:  THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR   */
00019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
00020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE   */
00021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,      */
00022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
00023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,  */
00024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    */
00025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING         */
00026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
00027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                           */
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 
00140     /* Disable watchdog */
00141     WDT_Disable(WDT);
00142 
00143     SCB_EnableICache();
00144     SCB_EnableDCache();
00145 
00146     /* Output example information */
00147     printf("-- LCD Example %s --\n\r", SOFTPACK_VERSION);
00148     printf("-- %s\n\r", BOARD_NAME);
00149     printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME);
00150 
00151 #if defined USE_SDRAM
00152     BOARD_ConfigureSdram();
00153 #endif
00154 
00155     /* Configure systick for 1 ms. */
00156     TimeTick_Configure();
00157 
00158     /* Initialize LCD and its interface */
00159     LCDD_Initialize(LCD_MODE, &lcdSpiDma, 0);
00160     LCDD_SetCavasBuffer(gLcdCavas, sizeof(gLcdCavas));
00161 
00162     rc.x = 0;
00163     rc.y = 0;
00164     rc.width = CANVAS_LCD_WIDTH - 1;
00165     rc.height = CANVAS_LCD_HEIGHT - 1;
00166     LCDD_SetUpdateWindowSize(rc);
00167 
00168     LCDD_DrawRectangleWithFill(0, 0, 0, CANVAS_LCD_WIDTH - 1, CANVAS_LCD_HEIGHT - 1,
00169             COLOR_CONVERT(COLOR_WHITE));
00170     LCDD_UpdateWindow();
00171     Wait(1000);
00172 
00173     LCDD_DrawRectangleWithFill(0, 0, 0, CANVAS_LCD_WIDTH - 1, CANVAS_LCD_HEIGHT - 1,
00174             COLOR_CONVERT(COLOR_BLUE));
00175     LCDD_UpdateWindow();
00176     Wait(1000);
00177 
00178     LCD_DrawString(0, 50, 5, String,  RGB_24_TO_18BIT(COLOR_BLACK));
00179     LCDD_UpdateWindow();
00180     Wait(500);
00181 
00182     /* Test basic color space translation and LCD_DrawFilledRectangle */
00183     LCDD_DrawRectangleWithFill(0,
00184                             0,
00185                             HEADLINE_OFFSET,
00186                             CANVAS_LCD_WIDTH - 1,
00187                             CANVAS_LCD_HEIGHT - 1 - HEADLINE_OFFSET,
00188                             COLOR_CONVERT(COLOR_WHITE));
00189     LCDD_UpdateWindow();
00190     Wait(500);
00191 
00192     LCDD_DrawRectangleWithFill(0,
00193                             4,
00194                             4 + HEADLINE_OFFSET,
00195                             CANVAS_LCD_WIDTH - 5 - 4,
00196                             CANVAS_LCD_HEIGHT - 5 - HEADLINE_OFFSET,
00197                             COLOR_CONVERT(COLOR_BLACK));
00198     LCDD_UpdateWindow();
00199     Wait(500);
00200 
00201     LCDD_DrawRectangleWithFill(0,
00202                             8,
00203                             8 + HEADLINE_OFFSET,
00204                             CANVAS_LCD_WIDTH - 9 - 8,
00205                             CANVAS_LCD_HEIGHT- 9 - 8 - HEADLINE_OFFSET,
00206                             COLOR_CONVERT(COLOR_BLUE));
00207     LCDD_UpdateWindow();
00208     Wait(500);
00209 
00210     LCDD_DrawRectangleWithFill(0,
00211                             12,
00212                             12 + HEADLINE_OFFSET,
00213                             CANVAS_LCD_WIDTH - 13 - 12,
00214                             CANVAS_LCD_HEIGHT - 13 - 12 - HEADLINE_OFFSET,
00215                             COLOR_CONVERT(COLOR_RED));
00216     LCDD_UpdateWindow();
00217     Wait(500);
00218 
00219     LCDD_DrawRectangleWithFill(0,
00220                             16,
00221                             14 + HEADLINE_OFFSET,
00222                             CANVAS_LCD_WIDTH - 17 - 16,
00223                             CANVAS_LCD_HEIGHT - 17 - 14 - HEADLINE_OFFSET,
00224                             COLOR_CONVERT(COLOR_GREEN));
00225     LCDD_UpdateWindow();
00226     Wait(500);
00227     /* Test horizontal/vertical LCD_drawLine  */
00228     LCDD_DrawLine(0,
00229                 0,
00230                 CANVAS_LCD_HEIGHT / 2,
00231                 CANVAS_LCD_WIDTH - 1,
00232                 CANVAS_LCD_HEIGHT / 2,
00233             COLOR_CONVERT(COLOR_RED));
00234     LCDD_UpdateWindow();
00235     Wait(500);
00236 
00237     LCDD_DrawLine(0,
00238                 CANVAS_LCD_WIDTH / 2,
00239                 HEADLINE_OFFSET ,
00240                 CANVAS_LCD_WIDTH / 2,
00241                 CANVAS_LCD_HEIGHT - 1, COLOR_CONVERT(COLOR_RED));
00242     LCDD_UpdateWindow();
00243     Wait(500);
00244 
00245     /* Test LCD_drawLine  */
00246     LCDD_DrawLine(0,
00247                 0,
00248                 0 ,
00249                 CANVAS_LCD_WIDTH -1,
00250                 CANVAS_LCD_HEIGHT - 1,
00251             RGB_24_TO_RGB565(COLOR_RED));
00252     LCDD_UpdateWindow();
00253     Wait(500);
00254 
00255     LCDD_DrawLine(0,
00256                 0,
00257                 CANVAS_LCD_HEIGHT - 1,
00258                 CANVAS_LCD_WIDTH - 1, 0,
00259                 RGB_24_TO_RGB565(COLOR_RED));
00260     LCDD_UpdateWindow();
00261     Wait(500);
00262 
00263     /* Test LCD_DrawRectangle */
00264     LCDD_DrawRectangle(0,
00265                     CANVAS_LCD_WIDTH / 4,
00266                     CANVAS_LCD_HEIGHT / 4,
00267                     CANVAS_LCD_WIDTH * 3 / 4 - CANVAS_LCD_WIDTH / 4,
00268                     CANVAS_LCD_HEIGHT * 3 / 4 - CANVAS_LCD_HEIGHT / 4,
00269                     COLOR_CONVERT(COLOR_RED));
00270     LCDD_UpdateWindow();
00271     Wait(500);
00272 
00273     LCDD_DrawRectangle(0,
00274                     CANVAS_LCD_WIDTH / 3,
00275                     CANVAS_LCD_HEIGHT / 3,
00276                     CANVAS_LCD_WIDTH * 2 / 3 - CANVAS_LCD_WIDTH / 3,
00277                     CANVAS_LCD_HEIGHT * 2 / 3 - CANVAS_LCD_HEIGHT / 3,
00278                     COLOR_CONVERT(COLOR_RED));
00279     LCDD_UpdateWindow();
00280     Wait(500);
00281 
00282     /* Test LCD_DrawFilledCircle */
00283     LCD_DrawFilledCircle(0,
00284                         CANVAS_LCD_WIDTH * 3 / 4,
00285                         CANVAS_LCD_HEIGHT * 3 / 4,
00286                         CANVAS_LCD_WIDTH / 4,
00287                         COLOR_CONVERT(COLOR_BLUE));
00288     LCDD_UpdateWindow();
00289     Wait(500);
00290 
00291     LCD_DrawFilledCircle(0,
00292                         CANVAS_LCD_WIDTH / 2,
00293                         CANVAS_LCD_HEIGHT / 2,
00294                         CANVAS_LCD_HEIGHT / 4,
00295                         COLOR_CONVERT(COLOR_WHITE));
00296     LCDD_UpdateWindow();
00297     Wait(500);
00298 
00299     LCD_DrawFilledCircle(0,
00300                         CANVAS_LCD_WIDTH / 4,
00301                         CANVAS_LCD_HEIGHT * 3 / 4,
00302                         CANVAS_LCD_HEIGHT / 4,
00303                         COLOR_CONVERT(COLOR_RED));
00304     LCDD_UpdateWindow();
00305     Wait(500);
00306 
00307     LCD_DrawFilledCircle(0,
00308                         CANVAS_LCD_WIDTH * 3 / 4,
00309                         CANVAS_LCD_HEIGHT / 4,
00310                         CANVAS_LCD_WIDTH / 4,
00311                         COLOR_CONVERT(COLOR_YELLOW));
00312     LCDD_UpdateWindow();
00313     Wait(500);
00314     /* Test LCD_DrawPicture */
00315     LCDD_DrawImage(0, 50, 50, (LcdColor_t *)gImageBuffer ,  (50 + DEMO_IMAGE_WIDTH),
00316             (50 + DEMO_IMAGE_HEIGHT));
00317     LCDD_UpdateWindow();
00318     Wait(3000);
00319 
00320     LCDD_DrawRectangleWithFill(0,
00321                             0,
00322                             0,
00323                             CANVAS_LCD_WIDTH - 1,
00324                             CANVAS_LCD_HEIGHT - 1,
00325                             COLOR_CONVERT(COLOR_BLACK));
00326 
00327     /** Move picture across the screen */
00328     dX = 2;
00329     dY = 2;
00330     j = 0;
00331     i = 0;
00332 
00333     for (; ;) {
00334         for (; i < (CANVAS_LCD_WIDTH-DEMO_IMAGE_WIDTH - 1);) {
00335             LCDD_DrawRectangleWithFill(0,
00336                                     0,
00337                                     0,
00338                                     CANVAS_LCD_WIDTH - 1,
00339                                     CANVAS_LCD_HEIGHT - 1,
00340                                     COLOR_CONVERT(COLOR_BLACK));
00341             LCDD_DrawImage(0, i, j, (LcdColor_t *)gImageBuffer, (i + DEMO_IMAGE_WIDTH),
00342                     (j + DEMO_IMAGE_HEIGHT));
00343             LCDD_UpdateWindow();
00344 
00345             j+=dY;
00346             i+=dX;
00347 
00348             if ((i >= (CANVAS_LCD_WIDTH - DEMO_IMAGE_WIDTH - 1 )) &&
00349                     (j < (CANVAS_LCD_HEIGHT - DEMO_IMAGE_HEIGHT - 1 ))) {
00350                 i-=dX;
00351                 dX=-dX;
00352             }
00353             else if ((i < (CANVAS_LCD_WIDTH-DEMO_IMAGE_WIDTH - 1)) &&
00354                     (j >= (CANVAS_LCD_HEIGHT-DEMO_IMAGE_HEIGHT - 1))) {
00355                 j-=dY;
00356                 dY=-dY;
00357             }
00358         }
00359         i = 0;
00360         j = 0;
00361     }
00362 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines