Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ili9341.c
00001 /** 00002 ****************************************************************************** 00003 * @file ili9341.c 00004 * @author MCD Application Team 00005 * @version V1.0.2 00006 * @date 02-December-2014 00007 * @brief This file includes the LCD driver for ILI9341 LCD. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 /* Includes ------------------------------------------------------------------*/ 00039 #include "ili9341.h" 00040 00041 /** @addtogroup BSP 00042 * @{ 00043 */ 00044 00045 /** @addtogroup Components 00046 * @{ 00047 */ 00048 00049 /** @addtogroup ILI9341 00050 * @brief This file provides a set of functions needed to drive the 00051 * ILI9341 LCD. 00052 * @{ 00053 */ 00054 00055 /** @defgroup ILI9341_Private_TypesDefinitions 00056 * @{ 00057 */ 00058 /** 00059 * @} 00060 */ 00061 00062 /** @defgroup ILI9341_Private_Defines 00063 * @{ 00064 */ 00065 /** 00066 * @} 00067 */ 00068 00069 /** @defgroup ILI9341_Private_Macros 00070 * @{ 00071 */ 00072 /** 00073 * @} 00074 */ 00075 00076 /** @defgroup ILI9341_Private_Variables 00077 * @{ 00078 */ 00079 00080 LCD_DrvTypeDef ili9341_drv = 00081 { 00082 ili9341_Init, 00083 ili9341_ReadID, 00084 ili9341_DisplayOn, 00085 ili9341_DisplayOff, 00086 0, 00087 0, 00088 0, 00089 0, 00090 0, 00091 0, 00092 ili9341_GetLcdPixelWidth, 00093 ili9341_GetLcdPixelHeight, 00094 0, 00095 0, 00096 }; 00097 00098 /** 00099 * @} 00100 */ 00101 00102 /** @defgroup ILI9341_Private_FunctionPrototypes 00103 * @{ 00104 */ 00105 00106 /** 00107 * @} 00108 */ 00109 00110 /** @defgroup ILI9341_Private_Functions 00111 * @{ 00112 */ 00113 00114 /** 00115 * @brief Power on the LCD. 00116 * @param None 00117 * @retval None 00118 */ 00119 void ili9341_Init(void) 00120 { 00121 /* Initialize ILI9341 low level bus layer ----------------------------------*/ 00122 LCD_IO_Init(); 00123 00124 /* Configure LCD */ 00125 ili9341_WriteReg(0xCA); 00126 ili9341_WriteData(0xC3); 00127 ili9341_WriteData(0x08); 00128 ili9341_WriteData(0x50); 00129 ili9341_WriteReg(LCD_POWERB); 00130 ili9341_WriteData(0x00); 00131 ili9341_WriteData(0xC1); 00132 ili9341_WriteData(0x30); 00133 ili9341_WriteReg(LCD_POWER_SEQ); 00134 ili9341_WriteData(0x64); 00135 ili9341_WriteData(0x03); 00136 ili9341_WriteData(0x12); 00137 ili9341_WriteData(0x81); 00138 ili9341_WriteReg(LCD_DTCA); 00139 ili9341_WriteData(0x85); 00140 ili9341_WriteData(0x00); 00141 ili9341_WriteData(0x78); 00142 ili9341_WriteReg(LCD_POWERA); 00143 ili9341_WriteData(0x39); 00144 ili9341_WriteData(0x2C); 00145 ili9341_WriteData(0x00); 00146 ili9341_WriteData(0x34); 00147 ili9341_WriteData(0x02); 00148 ili9341_WriteReg(LCD_PRC); 00149 ili9341_WriteData(0x20); 00150 ili9341_WriteReg(LCD_DTCB); 00151 ili9341_WriteData(0x00); 00152 ili9341_WriteData(0x00); 00153 ili9341_WriteReg(LCD_FRMCTR1); 00154 ili9341_WriteData(0x00); 00155 ili9341_WriteData(0x1B); 00156 ili9341_WriteReg(LCD_DFC); 00157 ili9341_WriteData(0x0A); 00158 ili9341_WriteData(0xA2); 00159 ili9341_WriteReg(LCD_POWER1); 00160 ili9341_WriteData(0x10); 00161 ili9341_WriteReg(LCD_POWER2); 00162 ili9341_WriteData(0x10); 00163 ili9341_WriteReg(LCD_VCOM1); 00164 ili9341_WriteData(0x45); 00165 ili9341_WriteData(0x15); 00166 ili9341_WriteReg(LCD_VCOM2); 00167 ili9341_WriteData(0x90); 00168 ili9341_WriteReg(LCD_MAC); 00169 ili9341_WriteData(0xC8); 00170 ili9341_WriteReg(LCD_3GAMMA_EN); 00171 ili9341_WriteData(0x00); 00172 ili9341_WriteReg(LCD_RGB_INTERFACE); 00173 ili9341_WriteData(0xC2); 00174 ili9341_WriteReg(LCD_DFC); 00175 ili9341_WriteData(0x0A); 00176 ili9341_WriteData(0xA7); 00177 ili9341_WriteData(0x27); 00178 ili9341_WriteData(0x04); 00179 00180 /* Colomn address set */ 00181 ili9341_WriteReg(LCD_COLUMN_ADDR); 00182 ili9341_WriteData(0x00); 00183 ili9341_WriteData(0x00); 00184 ili9341_WriteData(0x00); 00185 ili9341_WriteData(0xEF); 00186 /* Page address set */ 00187 ili9341_WriteReg(LCD_PAGE_ADDR); 00188 ili9341_WriteData(0x00); 00189 ili9341_WriteData(0x00); 00190 ili9341_WriteData(0x01); 00191 ili9341_WriteData(0x3F); 00192 ili9341_WriteReg(LCD_INTERFACE); 00193 ili9341_WriteData(0x01); 00194 ili9341_WriteData(0x00); 00195 ili9341_WriteData(0x06); 00196 00197 ili9341_WriteReg(LCD_GRAM); 00198 LCD_Delay(200); 00199 00200 ili9341_WriteReg(LCD_GAMMA); 00201 ili9341_WriteData(0x01); 00202 00203 ili9341_WriteReg(LCD_PGAMMA); 00204 ili9341_WriteData(0x0F); 00205 ili9341_WriteData(0x29); 00206 ili9341_WriteData(0x24); 00207 ili9341_WriteData(0x0C); 00208 ili9341_WriteData(0x0E); 00209 ili9341_WriteData(0x09); 00210 ili9341_WriteData(0x4E); 00211 ili9341_WriteData(0x78); 00212 ili9341_WriteData(0x3C); 00213 ili9341_WriteData(0x09); 00214 ili9341_WriteData(0x13); 00215 ili9341_WriteData(0x05); 00216 ili9341_WriteData(0x17); 00217 ili9341_WriteData(0x11); 00218 ili9341_WriteData(0x00); 00219 ili9341_WriteReg(LCD_NGAMMA); 00220 ili9341_WriteData(0x00); 00221 ili9341_WriteData(0x16); 00222 ili9341_WriteData(0x1B); 00223 ili9341_WriteData(0x04); 00224 ili9341_WriteData(0x11); 00225 ili9341_WriteData(0x07); 00226 ili9341_WriteData(0x31); 00227 ili9341_WriteData(0x33); 00228 ili9341_WriteData(0x42); 00229 ili9341_WriteData(0x05); 00230 ili9341_WriteData(0x0C); 00231 ili9341_WriteData(0x0A); 00232 ili9341_WriteData(0x28); 00233 ili9341_WriteData(0x2F); 00234 ili9341_WriteData(0x0F); 00235 00236 ili9341_WriteReg(LCD_SLEEP_OUT); 00237 LCD_Delay(200); 00238 ili9341_WriteReg(LCD_DISPLAY_ON); 00239 /* GRAM start writing */ 00240 ili9341_WriteReg(LCD_GRAM); 00241 } 00242 00243 /** 00244 * @brief Disables the Display. 00245 * @param None 00246 * @retval LCD Register Value. 00247 */ 00248 uint16_t ili9341_ReadID(void) 00249 { 00250 LCD_IO_Init(); 00251 return ((uint16_t)ili9341_ReadData(LCD_READ_ID4, LCD_READ_ID4_SIZE)); 00252 } 00253 00254 /** 00255 * @brief Enables the Display. 00256 * @param None 00257 * @retval None 00258 */ 00259 void ili9341_DisplayOn(void) 00260 { 00261 /* Display On */ 00262 ili9341_WriteReg(LCD_DISPLAY_ON); 00263 } 00264 00265 /** 00266 * @brief Disables the Display. 00267 * @param None 00268 * @retval None 00269 */ 00270 void ili9341_DisplayOff(void) 00271 { 00272 /* Display Off */ 00273 ili9341_WriteReg(LCD_DISPLAY_OFF); 00274 } 00275 00276 /** 00277 * @brief Writes to the selected LCD register. 00278 * @param LCD_Reg: address of the selected register. 00279 * @retval None 00280 */ 00281 void ili9341_WriteReg(uint8_t LCD_Reg) 00282 { 00283 LCD_IO_WriteReg(LCD_Reg); 00284 } 00285 00286 /** 00287 * @brief Writes data to the selected LCD register. 00288 * @param LCD_Reg: address of the selected register. 00289 * @retval None 00290 */ 00291 void ili9341_WriteData(uint16_t RegValue) 00292 { 00293 LCD_IO_WriteData(RegValue); 00294 } 00295 00296 /** 00297 * @brief Reads the selected LCD Register. 00298 * @param RegValue: Address of the register to read 00299 * @param ReadSize: Number of bytes to read 00300 * @retval LCD Register Value. 00301 */ 00302 uint32_t ili9341_ReadData(uint16_t RegValue, uint8_t ReadSize) 00303 { 00304 /* Read a max of 4 bytes */ 00305 return (LCD_IO_ReadData(RegValue, ReadSize)); 00306 } 00307 00308 /** 00309 * @brief Get LCD PIXEL WIDTH. 00310 * @param None 00311 * @retval LCD PIXEL WIDTH. 00312 */ 00313 uint16_t ili9341_GetLcdPixelWidth(void) 00314 { 00315 /* Return LCD PIXEL WIDTH */ 00316 return ILI9341_LCD_PIXEL_WIDTH; 00317 } 00318 00319 /** 00320 * @brief Get LCD PIXEL HEIGHT. 00321 * @param None 00322 * @retval LCD PIXEL HEIGHT. 00323 */ 00324 uint16_t ili9341_GetLcdPixelHeight(void) 00325 { 00326 /* Return LCD PIXEL HEIGHT */ 00327 return ILI9341_LCD_PIXEL_HEIGHT; 00328 } 00329 00330 /** 00331 * @} 00332 */ 00333 00334 /** 00335 * @} 00336 */ 00337 00338 /** 00339 * @} 00340 */ 00341 00342 /** 00343 * @} 00344 */ 00345 00346 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Wed Jul 13 2022 21:23:00 by
