SAMV71 Xplained Ultra Software Package 1.5

ili9488_ebi.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  * \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 COMPILER_ALIGNED(32) static uint32_t chipidBuf[5];
00082 uint32_t ILI9488_EbiReadChipId (void)
00083 {
00084     uint32_t chipid = 0;
00085 
00086     uint8_t i;
00087     uint32_t *ptr;
00088     uint32_t shift_cnt = 2;
00089 
00090     ILI9488_EbiSendCommand(ILI9488_CMD_READ_ID4, 0, 0, AccessInst, 0);
00091     ILI9488_EbiSendCommand(0, 0, chipidBuf, AccessRead, 4);
00092     ptr = &chipidBuf[1];
00093 
00094     for (i = 1; i < 4; i++) {
00095         chipid |= (*ptr & 0xFF) << (shift_cnt << 3);
00096         ptr++;
00097         shift_cnt--;
00098     }
00099 
00100     return chipid;
00101 }
00102 
00103 /**
00104  * \brief Set ILI9488 Pixel Format in SMC mode.
00105  * \param format Format of pixel
00106  */
00107 void ILI9488_EbiSetPixelFormat(uint16_t format)
00108 {
00109     ILI9488_EbiSendCommand(ILI9488_CMD_COLMOD_PIXEL_FORMAT_SET, &format, 0,
00110                            AccessWrite, 1);
00111 }
00112 
00113 /**
00114  * \brief Initialize the ILI9488 controller in SMC mode.
00115  */
00116 uint32_t ILI9488_EbiInitialize(sXdmad *dmad)
00117 {
00118     uint32_t chipid;
00119     uint16_t param;
00120 
00121     _ILI9488_EbiHW_Initialize();
00122     ILI9488_EbiInitializeWithDma(dmad);
00123 
00124     ILI9488_EbiSendCommand(ILI9488_CMD_SOFTWARE_RESET, 0, 0, AccessInst, 0);
00125     Wait(200);
00126 
00127     ILI9488_EbiSendCommand(ILI9488_CMD_SLEEP_OUT, 0, 0, AccessInst, 0);
00128     Wait(200);
00129 
00130     // make it tRGB and reverse the column order
00131     param = 0x48;
00132     ILI9488_EbiSendCommand(ILI9488_CMD_MEMORY_ACCESS_CONTROL, &param, 0,
00133                            AccessWrite, 1);
00134     Wait(100);
00135 
00136     param = 0x04;
00137     ILI9488_EbiSendCommand(ILI9488_CMD_CABC_CONTROL_9, &param, 0, AccessWrite, 1);
00138 
00139     if ((chipid = ILI9488_EbiReadChipId()) != ILI9488_DEVICE_CODE) {
00140         printf("Read ILI9488 chip ID (0x%04x) error, skip initialization.\r\n",
00141                 (unsigned int)chipid);
00142         return 1;
00143     }
00144 
00145     ILI9488_EbiSetPixelFormat(5);
00146     ILI9488_EbiSendCommand(ILI9488_CMD_NORMAL_DISP_MODE_ON, 0, 0, AccessInst, 0);
00147     ILI9488_EbiSendCommand(ILI9488_CMD_DISPLAY_ON, 0, 0, AccessInst, 0);
00148     return 0;
00149 }
00150 
00151 /**
00152  * \brief ILI9488 configure cursor in SMC mode.
00153  * \Param x X position.
00154  * \Param y Y position.
00155  */
00156 void ILI9488_EbiSetCursor(uint16_t x, uint16_t y)
00157 {
00158     /* Set Horizontal Address Start Position */
00159     uint32_t cnt = 0;
00160 
00161     uint16_t buf[4];
00162     cnt = sizeof(buf) / sizeof(uint16_t);
00163 
00164     buf[0] = get_8b_to_16b(x);
00165     buf[1] = get_0b_to_8b(x);
00166     x += 1;
00167     buf[2] = get_8b_to_16b(x);
00168     buf[3] = get_0b_to_8b(x);
00169     ILI9488_EbiSendCommand(ILI9488_CMD_COLUMN_ADDRESS_SET, (uint16_t *)buf, 0,
00170                            AccessWrite, cnt);
00171     ILI9488_EbiSendCommand(ILI9488_CMD_NOP, 0, 0, AccessInst, 0);
00172 
00173 
00174     /* Set Horizontal Address End Position */
00175     buf[0] = get_8b_to_16b(y);
00176     buf[1] = get_0b_to_8b(y);
00177     y += 1;
00178     buf[2] = get_8b_to_16b(y);
00179     buf[3] = get_0b_to_8b(y);
00180     ILI9488_EbiSendCommand(ILI9488_CMD_PAGE_ADDRESS_SET, (uint16_t *)buf, 0,
00181                            AccessWrite, cnt);
00182     ILI9488_EbiSendCommand(ILI9488_CMD_NOP, 0, 0, AccessInst, 0);
00183 }
00184 
00185 /**
00186  * \brief ILI9488 configure window.
00187  * \Param dwX X start position.
00188  * \Param dwX Y start position.
00189  * \Param dwWidth  Width of window.
00190  * \Param dwHeight Height of window.
00191  */
00192 COMPILER_ALIGNED(32) static uint16_t buf[4];
00193 void ILI9488_EbiSetWindow(
00194     uint16_t dwX, uint16_t dwY, uint16_t dwWidth, uint16_t dwHeight)
00195 {
00196     uint16_t ColStart, ColEnd, RowStart, RowEnd;
00197 
00198     uint32_t cnt = 0;
00199 
00200 
00201     cnt = sizeof(buf) / sizeof(uint16_t);
00202 
00203     ColStart  =  dwX;
00204     ColEnd    =  dwWidth + dwX;
00205 
00206     RowStart = dwY;
00207     RowEnd   = dwHeight + dwY;
00208 
00209     buf[0] = get_8b_to_16b(ColStart);
00210     buf[1] = get_0b_to_8b(ColStart);
00211     buf[2] = get_8b_to_16b(ColEnd);
00212     buf[3] = get_0b_to_8b(ColEnd);
00213     ILI9488_EbiSendCommand(ILI9488_CMD_COLUMN_ADDRESS_SET, (uint16_t *)buf, 0,
00214                            AccessWrite, cnt);
00215     ILI9488_EbiSendCommand(ILI9488_CMD_NOP, 0, 0, AccessInst, 0);
00216 
00217     /* Set Horizontal Address End Position */
00218     buf[0] = get_8b_to_16b(RowStart);
00219     buf[1] = get_0b_to_8b(RowStart);
00220     buf[2] = get_8b_to_16b(RowEnd);
00221     buf[3] = get_0b_to_8b(RowEnd);
00222     ILI9488_EbiSendCommand(ILI9488_CMD_PAGE_ADDRESS_SET, (uint16_t *)buf, 0,
00223                            AccessWrite, cnt);
00224     ILI9488_EbiSendCommand(ILI9488_CMD_NOP, 0, 0, AccessInst, 0);
00225 }
00226 
00227 /**
00228  * \brief ILI9488 configure window with full size.
00229  */
00230 void ILI9488_EbiSetFullWindow(void)
00231 {
00232     uint16_t c_start, c_end, r_start, r_end;
00233     uint32_t cnt = 0;
00234 
00235     cnt = sizeof(buf) / sizeof(uint16_t);
00236 
00237     c_start  =  0;
00238     c_end    =  ILI9488_LCD_WIDTH - 1;
00239 
00240     r_start = 0;
00241     r_end   = ILI9488_LCD_HEIGHT - 1;
00242 
00243     /* Set Horizontal Address Start Position */
00244     buf[0] = get_8b_to_16b(c_start);
00245     buf[1] = get_0b_to_8b(c_start);
00246     buf[2] = get_8b_to_16b(c_end);
00247     buf[3] = get_0b_to_8b(c_end);
00248     ILI9488_EbiSendCommand(ILI9488_CMD_COLUMN_ADDRESS_SET, (uint16_t *)buf, 0,
00249                            AccessWrite, cnt);
00250     ILI9488_EbiSendCommand(ILI9488_CMD_NOP , 0, 0, AccessInst, 0);
00251 
00252     /* Set Horizontal Address End Position */
00253     buf[0] = get_8b_to_16b(r_start);
00254     buf[1] = get_0b_to_8b(r_start);
00255     buf[2] = get_8b_to_16b(r_end);
00256     buf[3] = get_0b_to_8b(r_end);
00257     ILI9488_EbiSendCommand(ILI9488_CMD_COLUMN_ADDRESS_SET, (uint16_t *)buf, 0,
00258                            AccessWrite, cnt);
00259     ILI9488_EbiSendCommand(ILI9488_CMD_NOP , 0, 0, AccessInst, 0);
00260 }
00261 
00262 
00263 /**
00264  * \brief Turn on the ILI9488.
00265  */
00266 void ILI9488_EbiOn(void)
00267 {
00268     ILI9488_EbiSendCommand(ILI9488_CMD_PIXEL_OFF, 0, 0, AccessInst, 0);
00269     ILI9488_EbiSendCommand(ILI9488_CMD_DISPLAY_ON, 0, 0, AccessInst, 0);
00270     ILI9488_EbiSendCommand(ILI9488_CMD_NORMAL_DISP_MODE_ON, 0, 0, AccessInst, 0);
00271 }
00272 
00273 /**
00274  * \brief Turn off the ILI9488.
00275  */
00276 void ILI9488_EbiOff(void)
00277 {
00278     ILI9488_EbiSendCommand(ILI9488_CMD_DISPLAY_OFF, 0, 0, AccessInst, 0);
00279 }
00280 
00281 /**
00282  * \brief ILI9488 configure landscape.
00283  * \Param dwRGB RGB mode.
00284  * \Param LandscaprMode Landscape Mode.
00285  */
00286 void ILI9488_EbiSetDisplayLandscape(uint8_t dwRGB, uint8_t LandscapeMode)
00287 {
00288     uint16_t value;
00289 
00290     if (LandscapeMode)   {
00291         if (dwRGB)
00292             value = 0xE8;
00293         else
00294             value = 0xE0;
00295     } else {
00296         if (dwRGB)
00297             value = 0x48;
00298         else
00299             value = 0x40;
00300     }
00301 
00302     ILI9488_EbiSendCommand(ILI9488_CMD_MEMORY_ACCESS_CONTROL, &value, 0,
00303                            AccessWrite, sizeof(value));
00304 }
00305 
00306 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines