ili9341.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /**
  2. ******************************************************************************
  3. * @file ili9341.c
  4. * @author MCD Application Team
  5. * @version V1.0.2
  6. * @date 02-December-2014
  7. * @brief This file includes the LCD driver for ILI9341 LCD.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Includes ------------------------------------------------------------------*/
  38. #include "ili9341.h"
  39. /** @addtogroup BSP
  40. * @{
  41. */
  42. /** @addtogroup Components
  43. * @{
  44. */
  45. /** @addtogroup ILI9341
  46. * @brief This file provides a set of functions needed to drive the
  47. * ILI9341 LCD.
  48. * @{
  49. */
  50. /** @defgroup ILI9341_Private_TypesDefinitions
  51. * @{
  52. */
  53. /**
  54. * @}
  55. */
  56. /** @defgroup ILI9341_Private_Defines
  57. * @{
  58. */
  59. /**
  60. * @}
  61. */
  62. /** @defgroup ILI9341_Private_Macros
  63. * @{
  64. */
  65. /**
  66. * @}
  67. */
  68. /** @defgroup ILI9341_Private_Variables
  69. * @{
  70. */
  71. LCD_DrvTypeDef ili9341_drv =
  72. {
  73. ili9341_Init,
  74. ili9341_ReadID,
  75. ili9341_DisplayOn,
  76. ili9341_DisplayOff,
  77. 0,
  78. 0,
  79. 0,
  80. 0,
  81. 0,
  82. 0,
  83. ili9341_GetLcdPixelWidth,
  84. ili9341_GetLcdPixelHeight,
  85. 0,
  86. 0,
  87. };
  88. /**
  89. * @}
  90. */
  91. /** @defgroup ILI9341_Private_FunctionPrototypes
  92. * @{
  93. */
  94. /**
  95. * @}
  96. */
  97. /** @defgroup ILI9341_Private_Functions
  98. * @{
  99. */
  100. /**
  101. * @brief Power on the LCD.
  102. * @param None
  103. * @retval None
  104. */
  105. void ili9341_Init(void)
  106. {
  107. /* Initialize ILI9341 low level bus layer ----------------------------------*/
  108. LCD_IO_Init();
  109. /* Configure LCD */
  110. ili9341_WriteReg(0xCA);
  111. ili9341_WriteData(0xC3);
  112. ili9341_WriteData(0x08);
  113. ili9341_WriteData(0x50);
  114. ili9341_WriteReg(LCD_POWERB);
  115. ili9341_WriteData(0x00);
  116. ili9341_WriteData(0xC1);
  117. ili9341_WriteData(0x30);
  118. ili9341_WriteReg(LCD_POWER_SEQ);
  119. ili9341_WriteData(0x64);
  120. ili9341_WriteData(0x03);
  121. ili9341_WriteData(0x12);
  122. ili9341_WriteData(0x81);
  123. ili9341_WriteReg(LCD_DTCA);
  124. ili9341_WriteData(0x85);
  125. ili9341_WriteData(0x00);
  126. ili9341_WriteData(0x78);
  127. ili9341_WriteReg(LCD_POWERA);
  128. ili9341_WriteData(0x39);
  129. ili9341_WriteData(0x2C);
  130. ili9341_WriteData(0x00);
  131. ili9341_WriteData(0x34);
  132. ili9341_WriteData(0x02);
  133. ili9341_WriteReg(LCD_PRC);
  134. ili9341_WriteData(0x20);
  135. ili9341_WriteReg(LCD_DTCB);
  136. ili9341_WriteData(0x00);
  137. ili9341_WriteData(0x00);
  138. ili9341_WriteReg(LCD_FRMCTR1);
  139. ili9341_WriteData(0x00);
  140. ili9341_WriteData(0x1B);
  141. ili9341_WriteReg(LCD_DFC);
  142. ili9341_WriteData(0x0A);
  143. ili9341_WriteData(0xA2);
  144. ili9341_WriteReg(LCD_POWER1);
  145. ili9341_WriteData(0x10);
  146. ili9341_WriteReg(LCD_POWER2);
  147. ili9341_WriteData(0x10);
  148. ili9341_WriteReg(LCD_VCOM1);
  149. ili9341_WriteData(0x45);
  150. ili9341_WriteData(0x15);
  151. ili9341_WriteReg(LCD_VCOM2);
  152. ili9341_WriteData(0x90);
  153. ili9341_WriteReg(LCD_MAC);
  154. ili9341_WriteData(0xC8);
  155. ili9341_WriteReg(LCD_3GAMMA_EN);
  156. ili9341_WriteData(0x00);
  157. ili9341_WriteReg(LCD_RGB_INTERFACE);
  158. ili9341_WriteData(0xC2);
  159. ili9341_WriteReg(LCD_DFC);
  160. ili9341_WriteData(0x0A);
  161. ili9341_WriteData(0xA7);
  162. ili9341_WriteData(0x27);
  163. ili9341_WriteData(0x04);
  164. /* Colomn address set */
  165. ili9341_WriteReg(LCD_COLUMN_ADDR);
  166. ili9341_WriteData(0x00);
  167. ili9341_WriteData(0x00);
  168. ili9341_WriteData(0x00);
  169. ili9341_WriteData(0xEF);
  170. /* Page address set */
  171. ili9341_WriteReg(LCD_PAGE_ADDR);
  172. ili9341_WriteData(0x00);
  173. ili9341_WriteData(0x00);
  174. ili9341_WriteData(0x01);
  175. ili9341_WriteData(0x3F);
  176. ili9341_WriteReg(LCD_INTERFACE);
  177. ili9341_WriteData(0x01);
  178. ili9341_WriteData(0x00);
  179. ili9341_WriteData(0x06);
  180. ili9341_WriteReg(LCD_GRAM);
  181. LCD_Delay(200);
  182. ili9341_WriteReg(LCD_GAMMA);
  183. ili9341_WriteData(0x01);
  184. ili9341_WriteReg(LCD_PGAMMA);
  185. ili9341_WriteData(0x0F);
  186. ili9341_WriteData(0x29);
  187. ili9341_WriteData(0x24);
  188. ili9341_WriteData(0x0C);
  189. ili9341_WriteData(0x0E);
  190. ili9341_WriteData(0x09);
  191. ili9341_WriteData(0x4E);
  192. ili9341_WriteData(0x78);
  193. ili9341_WriteData(0x3C);
  194. ili9341_WriteData(0x09);
  195. ili9341_WriteData(0x13);
  196. ili9341_WriteData(0x05);
  197. ili9341_WriteData(0x17);
  198. ili9341_WriteData(0x11);
  199. ili9341_WriteData(0x00);
  200. ili9341_WriteReg(LCD_NGAMMA);
  201. ili9341_WriteData(0x00);
  202. ili9341_WriteData(0x16);
  203. ili9341_WriteData(0x1B);
  204. ili9341_WriteData(0x04);
  205. ili9341_WriteData(0x11);
  206. ili9341_WriteData(0x07);
  207. ili9341_WriteData(0x31);
  208. ili9341_WriteData(0x33);
  209. ili9341_WriteData(0x42);
  210. ili9341_WriteData(0x05);
  211. ili9341_WriteData(0x0C);
  212. ili9341_WriteData(0x0A);
  213. ili9341_WriteData(0x28);
  214. ili9341_WriteData(0x2F);
  215. ili9341_WriteData(0x0F);
  216. ili9341_WriteReg(LCD_SLEEP_OUT);
  217. LCD_Delay(200);
  218. ili9341_WriteReg(LCD_DISPLAY_ON);
  219. /* GRAM start writing */
  220. ili9341_WriteReg(LCD_GRAM);
  221. }
  222. /**
  223. * @brief Disables the Display.
  224. * @param None
  225. * @retval LCD Register Value.
  226. */
  227. uint16_t ili9341_ReadID(void)
  228. {
  229. LCD_IO_Init();
  230. return ((uint16_t)ili9341_ReadData(LCD_READ_ID4, LCD_READ_ID4_SIZE));
  231. }
  232. /**
  233. * @brief Enables the Display.
  234. * @param None
  235. * @retval None
  236. */
  237. void ili9341_DisplayOn(void)
  238. {
  239. /* Display On */
  240. ili9341_WriteReg(LCD_DISPLAY_ON);
  241. }
  242. /**
  243. * @brief Disables the Display.
  244. * @param None
  245. * @retval None
  246. */
  247. void ili9341_DisplayOff(void)
  248. {
  249. /* Display Off */
  250. ili9341_WriteReg(LCD_DISPLAY_OFF);
  251. }
  252. /**
  253. * @brief Writes to the selected LCD register.
  254. * @param LCD_Reg: address of the selected register.
  255. * @retval None
  256. */
  257. void ili9341_WriteReg(uint8_t LCD_Reg)
  258. {
  259. LCD_IO_WriteReg(LCD_Reg);
  260. }
  261. /**
  262. * @brief Writes data to the selected LCD register.
  263. * @param LCD_Reg: address of the selected register.
  264. * @retval None
  265. */
  266. void ili9341_WriteData(uint16_t RegValue)
  267. {
  268. LCD_IO_WriteData(RegValue);
  269. }
  270. /**
  271. * @brief Reads the selected LCD Register.
  272. * @param RegValue: Address of the register to read
  273. * @param ReadSize: Number of bytes to read
  274. * @retval LCD Register Value.
  275. */
  276. uint32_t ili9341_ReadData(uint16_t RegValue, uint8_t ReadSize)
  277. {
  278. /* Read a max of 4 bytes */
  279. return (LCD_IO_ReadData(RegValue, ReadSize));
  280. }
  281. /**
  282. * @brief Get LCD PIXEL WIDTH.
  283. * @param None
  284. * @retval LCD PIXEL WIDTH.
  285. */
  286. uint16_t ili9341_GetLcdPixelWidth(void)
  287. {
  288. /* Return LCD PIXEL WIDTH */
  289. return ILI9341_LCD_PIXEL_WIDTH;
  290. }
  291. /**
  292. * @brief Get LCD PIXEL HEIGHT.
  293. * @param None
  294. * @retval LCD PIXEL HEIGHT.
  295. */
  296. uint16_t ili9341_GetLcdPixelHeight(void)
  297. {
  298. /* Return LCD PIXEL HEIGHT */
  299. return ILI9341_LCD_PIXEL_HEIGHT;
  300. }
  301. /**
  302. * @}
  303. */
  304. /**
  305. * @}
  306. */
  307. /**
  308. * @}
  309. */
  310. /**
  311. * @}
  312. */
  313. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/