SAMV71 Xplained Ultra Software Package 1.3

ili9488_ebi.c

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2014, 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  * \file
00032  *
00033  * Implementation of ILI9488 driver.
00034  *
00035  */
00036 
00037 /*----------------------------------------------------------------------------
00038  *        Headers
00039  *----------------------------------------------------------------------------*/
00040 #include "board.h"
00041 #include <string.h>
00042 #include <stdio.h>
00043 
00044 #ifdef BOARD_LCD_ILI9488
00045 
00046 /*----------------------------------------------------------------------------
00047  *        Local variables
00048  *----------------------------------------------------------------------------*/
00049 
00050 /** Pio pins to configure. */
00051 static const Pin lcd_ebi_reset_pin = LCD_EBI_PIN_RESET;
00052 static const Pin lcd_ebi_pwm_pin = BOARD_EBI_LCD_PIN_BACKLIGHT;
00053 /** Pins to configure for the application. */
00054 static const Pin lcd_ebi_pins[] = BOARD_EBI_LCD_PINS;
00055 /** Pins to configure for the application. */
00056 static const Pin lcd_ebi_cds_pin = BOARD_EBI_LCD_PIN_CDS;
00057 
00058 /*----------------------------------------------------------------------------
00059  *        Local functions
00060  *----------------------------------------------------------------------------*/
00061 /**
00062  * \brief ILI9488 Hardware Initialization for SMC LCD.
00063  */
00064 static void _ILI9488_EbiHW_Initialize(void) 
00065 {
00066     /* Pin configurations */
00067     PIO_Configure(&lcd_ebi_reset_pin, 1);
00068     PIO_Configure(&lcd_ebi_cds_pin, 1);
00069     PIO_Configure(lcd_ebi_pins, PIO_LISTSIZE(lcd_ebi_pins));
00070     PIO_Configure(&lcd_ebi_pwm_pin, 1);
00071     PIO_Set(&lcd_ebi_pwm_pin);
00072 }
00073 
00074 /*----------------------------------------------------------------------------
00075  *        Exported functions
00076  *----------------------------------------------------------------------------*/
00077 
00078 /*----------------------------------------------------------------------------
00079  *        Exported functions
00080  *----------------------------------------------------------------------------*/
00081 uint32_t ILI9488_EbiReadChipId (void)
00082 {
00083     uint32_t chipid = 0;
00084     uint32_t chipidBuf[5];
00085     uint8_t i;
00086     uint32_t *ptr;
00087     uint32_t shift_cnt = 2;
00088     
00089     ILI9488_EbiSendCommand(ILI9488_CMD_READ_ID4, 0, 0, AccessInst, 0);
00090     ILI9488_EbiSendCommand(0, 0, chipidBuf, AccessRead, 4);
00091     ptr = &chipidBuf[1];
00092     for(i = 1; i < 4; i++) {
00093         chipid |= (*ptr &0xFF)<< (shift_cnt << 3);
00094         ptr++;
00095         shift_cnt--;
00096     }
00097     return chipid;
00098 }
00099 
00100 /**
00101  * \brief Set ILI9488 Pixel Format in SMC mode.
00102  * \param format Format of pixel
00103  */
00104 void ILI9488_EbiSetPixelFormat(uint16_t format)
00105 {
00106     ILI9488_EbiSendCommand(ILI9488_CMD_COLMOD_PIXEL_FORMAT_SET, &format, 0, AccessWrite, 1);
00107 }
00108 
00109 /**
00110  * \brief Initialize the ILI9488 controller in SMC mode.
00111  */
00112 uint32_t ILI9488_EbiInitialize(sXdmad * dmad)
00113 {
00114     uint32_t chipid;
00115     uint16_t param;
00116 
00117     _ILI9488_EbiHW_Initialize();
00118     ILI9488_EbiInitializeWithDma(dmad);
00119 
00120     ILI9488_EbiSendCommand(ILI9488_CMD_SOFTWARE_RESET, 0, 0, AccessInst, 0);
00121     Wait(200);
00122 
00123     ILI9488_EbiSendCommand(ILI9488_CMD_SLEEP_OUT, 0, 0, AccessInst, 0);
00124     Wait(200);
00125 
00126     // make it tRGB and reverse the column order
00127     param = 0x48;
00128     ILI9488_EbiSendCommand(ILI9488_CMD_MEMORY_ACCESS_CONTROL,&param, 0, AccessWrite, 1);
00129     Wait(100);
00130 
00131     param = 0x04;
00132     ILI9488_EbiSendCommand(ILI9488_CMD_CABC_CONTROL_9, &param, 0, AccessWrite, 1);
00133 
00134     if ( (chipid = ILI9488_EbiReadChipId()) != ILI9488_DEVICE_CODE ) {
00135         printf( "Read ILI9488 chip ID (0x%04x) error, skip initialization.\r\n", 
00136                 (unsigned int)chipid ) ;
00137         return 1 ;
00138     }
00139 
00140     ILI9488_EbiSetPixelFormat(5);
00141     ILI9488_EbiSendCommand(ILI9488_CMD_NORMAL_DISP_MODE_ON, 0, 0, AccessInst, 0);
00142     ILI9488_EbiSendCommand(ILI9488_CMD_DISPLAY_ON, 0, 0, AccessInst, 0);
00143     return 0 ;
00144 }
00145 
00146 /**
00147  * \brief ILI9488 configure cursor in SMC mode.
00148  * \Param x X position.
00149  * \Param y Y position.
00150  */
00151 void ILI9488_EbiSetCursor(uint16_t x, uint16_t y)
00152 {
00153     /* Set Horizontal Address Start Position */
00154     uint32_t cnt = 0;
00155 
00156     uint16_t buf[4];
00157     cnt = sizeof(buf)/sizeof(uint16_t);
00158 
00159     buf[0] = get_8b_to_16b(x);
00160     buf[1] = get_0b_to_8b(x);
00161     x+=1;
00162     buf[2] = get_8b_to_16b(x);
00163     buf[3] = get_0b_to_8b(x);
00164     ILI9488_EbiSendCommand(ILI9488_CMD_COLUMN_ADDRESS_SET, (uint16_t*)buf, 0, AccessWrite, cnt);
00165     ILI9488_EbiSendCommand(ILI9488_CMD_NOP, 0, 0, AccessInst, 0);
00166 
00167 
00168     /* Set Horizontal Address End Position */
00169     buf[0] = get_8b_to_16b(y);
00170     buf[1] = get_0b_to_8b(y);
00171     y+=1;
00172     buf[2] = get_8b_to_16b(y);
00173     buf[3] = get_0b_to_8b(y);
00174     ILI9488_EbiSendCommand(ILI9488_CMD_PAGE_ADDRESS_SET, (uint16_t*)buf, 0, AccessWrite, cnt);
00175     ILI9488_EbiSendCommand(ILI9488_CMD_NOP, 0, 0, AccessInst, 0);
00176 }
00177 
00178 /**
00179  * \brief ILI9488 configure window.
00180  * \Param dwX X start position.
00181  * \Param dwX Y start position.
00182  * \Param dwWidth  Width of window.
00183  * \Param dwHeight Height of window.
00184  */
00185 void ILI9488_EbiSetWindow( 
00186         uint16_t dwX, uint16_t dwY, uint16_t dwWidth, uint16_t dwHeight )
00187 {
00188     uint16_t ColStart, ColEnd, RowStart, RowEnd;
00189 
00190     uint32_t cnt = 0;
00191 
00192     uint16_t buf[4];
00193     cnt = sizeof(buf)/sizeof(uint16_t);
00194 
00195     ColStart  =  dwX ;
00196     ColEnd    =  dwWidth + dwX;
00197 
00198     RowStart = dwY ;
00199     RowEnd   = dwHeight + dwY;
00200 
00201     buf[0] = get_8b_to_16b(ColStart);
00202     buf[1] = get_0b_to_8b(ColStart);
00203     buf[2] = get_8b_to_16b(ColEnd);
00204     buf[3] = get_0b_to_8b(ColEnd);
00205     ILI9488_EbiSendCommand(ILI9488_CMD_COLUMN_ADDRESS_SET, (uint16_t*)buf, 0, AccessWrite, cnt);
00206     ILI9488_EbiSendCommand(ILI9488_CMD_NOP, 0, 0, AccessInst, 0);
00207 
00208     /* Set Horizontal Address End Position */
00209     buf[0] = get_8b_to_16b(RowStart);
00210     buf[1] = get_0b_to_8b(RowStart);
00211     buf[2] = get_8b_to_16b(RowEnd);
00212     buf[3] = get_0b_to_8b(RowEnd);
00213     ILI9488_EbiSendCommand(ILI9488_CMD_PAGE_ADDRESS_SET, (uint16_t*)buf, 0, AccessWrite, cnt);
00214     ILI9488_EbiSendCommand(ILI9488_CMD_NOP, 0, 0, AccessInst, 0);
00215 }
00216 
00217 /**
00218  * \brief ILI9488 configure window with full size.
00219  */
00220 void ILI9488_EbiSetFullWindow(void)
00221 {
00222     uint16_t c_start,c_end,r_start,r_end;
00223     uint32_t cnt = 0;
00224 
00225     uint16_t buf[4];
00226     cnt = sizeof(buf)/sizeof(uint16_t);
00227 
00228     c_start  =  0 ;
00229     c_end    =  ILI9488_LCD_WIDTH- 1;
00230 
00231     r_start = 0 ;
00232     r_end   = ILI9488_LCD_HEIGHT - 1;
00233 
00234     /* Set Horizontal Address Start Position */
00235     buf[0] = get_8b_to_16b(c_start);
00236     buf[1] = get_0b_to_8b(c_start);
00237     buf[2] = get_8b_to_16b(c_end);
00238     buf[3] = get_0b_to_8b(c_end);
00239     ILI9488_EbiSendCommand(ILI9488_CMD_COLUMN_ADDRESS_SET, (uint16_t*)buf, 0, AccessWrite, cnt);
00240     ILI9488_EbiSendCommand(ILI9488_CMD_NOP ,0, 0, AccessInst, 0);
00241 
00242     /* Set Horizontal Address End Position */
00243     buf[0] = get_8b_to_16b(r_start);
00244     buf[1] = get_0b_to_8b(r_start);
00245     buf[2] = get_8b_to_16b(r_end);
00246     buf[3] = get_0b_to_8b(r_end);
00247     ILI9488_EbiSendCommand(ILI9488_CMD_COLUMN_ADDRESS_SET, (uint16_t*)buf, 0, AccessWrite, cnt);
00248     ILI9488_EbiSendCommand(ILI9488_CMD_NOP ,0, 0, AccessInst, 0);
00249 }
00250 
00251 
00252 /**
00253  * \brief Turn on the ILI9488.
00254  */
00255 void ILI9488_EbiOn( void )
00256 {
00257     ILI9488_EbiSendCommand(ILI9488_CMD_PIXEL_OFF, 0, 0, AccessInst, 0);
00258     ILI9488_EbiSendCommand(ILI9488_CMD_DISPLAY_ON, 0, 0, AccessInst, 0);
00259     ILI9488_EbiSendCommand(ILI9488_CMD_NORMAL_DISP_MODE_ON, 0, 0, AccessInst, 0);
00260 }
00261 
00262 /**
00263  * \brief Turn off the ILI9488.
00264  */
00265 void ILI9488_EbiOff( void )
00266 {
00267     ILI9488_EbiSendCommand(ILI9488_CMD_DISPLAY_OFF, 0, 0, AccessInst, 0);
00268 }
00269 
00270 /**
00271  * \brief ILI9488 configure landscape.
00272  * \Param dwRGB RGB mode.
00273  * \Param LandscaprMode Landscape Mode.
00274  */
00275 void ILI9488_EbiSetDisplayLandscape( uint8_t dwRGB, uint8_t LandscapeMode )
00276 {
00277     uint16_t value;
00278     if(LandscapeMode)   {
00279         if(dwRGB) {
00280             value = 0xE8;
00281         } else {
00282             value = 0xE0;
00283         }
00284     } else {
00285         if(dwRGB) {
00286             value = 0x48;
00287         } else {
00288             value = 0x40;
00289         }
00290     }
00291     ILI9488_EbiSendCommand(ILI9488_CMD_MEMORY_ACCESS_CONTROL, &value, 0, AccessWrite, sizeof(value));
00292 }
00293 
00294 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines