ili9225.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. /****************************************************************************
  2. * drivers/lcd/ili9225.c
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. /****************************************************************************
  21. * Included Files
  22. ****************************************************************************/
  23. #include <nuttx/config.h>
  24. #include <sys/types.h>
  25. #include <stdint.h>
  26. #include <stdbool.h>
  27. #include <string.h>
  28. #include <assert.h>
  29. #include <errno.h>
  30. #include <debug.h>
  31. #include <nuttx/arch.h>
  32. #include <nuttx/spi/spi.h>
  33. #include <nuttx/lcd/lcd.h>
  34. #include <nuttx/lcd/ili9225.h>
  35. #ifdef CONFIG_LCD_ILI9225
  36. /****************************************************************************
  37. * Pre-processor Definitions
  38. ****************************************************************************/
  39. /* Verify that all configuration requirements have been met */
  40. #ifndef CONFIG_LCD_ILI9225_SPIMODE
  41. # define CONFIG_LCD_ILI9225_SPIMODE SPIDEV_MODE0
  42. #endif
  43. /* SPI frequency */
  44. #ifndef CONFIG_LCD_ILI9225_FREQUENCY
  45. # define CONFIG_LCD_ILI9225_FREQUENCY 1000000
  46. #endif
  47. /* Check contrast selection */
  48. #if !defined(CONFIG_LCD_MAXCONTRAST)
  49. # define CONFIG_LCD_MAXCONTRAST 1
  50. #endif
  51. /* Check power setting */
  52. #if !defined(CONFIG_LCD_MAXPOWER) || CONFIG_LCD_MAXPOWER < 1
  53. # define CONFIG_LCD_MAXPOWER 1
  54. #endif
  55. #if CONFIG_LCD_MAXPOWER > 255
  56. # error "CONFIG_LCD_MAXPOWER must be less than 256 to fit in uint8_t"
  57. #endif
  58. /* Check orientation */
  59. #if defined(CONFIG_LCD_PORTRAIT)
  60. # if defined(CONFIG_LCD_LANDSCAPE) || defined(CONFIG_LCD_RLANDSCAPE) ||\
  61. defined(CONFIG_LCD_RPORTRAIT)
  62. # error "Cannot define both portrait and any other orientations"
  63. # endif
  64. #elif defined(CONFIG_LCD_RPORTRAIT)
  65. # if defined(CONFIG_LCD_LANDSCAPE) || defined(CONFIG_LCD_RLANDSCAPE)
  66. # error "Cannot define both rportrait and any other orientations"
  67. # endif
  68. #elif defined(CONFIG_LCD_LANDSCAPE)
  69. # ifdef CONFIG_LCD_RLANDSCAPE
  70. # error "Cannot define both landscape and any other orientations"
  71. # endif
  72. #elif !defined(CONFIG_LCD_RLANDSCAPE)
  73. # define CONFIG_LCD_LANDSCAPE 1
  74. #endif
  75. /* Display Resolution */
  76. #if !defined(CONFIG_LCD_ILI9225_XRES)
  77. # define CONFIG_LCD_ILI9225_XRES 176
  78. #endif
  79. #if !defined(CONFIG_LCD_ILI9225_YRES)
  80. # define CONFIG_LCD_ILI9225_YRES 220
  81. #endif
  82. #define ILI9225_LUT_SIZE CONFIG_LCD_ILI9225_YRES
  83. #if defined(CONFIG_LCD_LANDSCAPE) || defined(CONFIG_LCD_RLANDSCAPE)
  84. # define ILI9225_XRES CONFIG_LCD_ILI9225_YRES
  85. # define ILI9225_YRES CONFIG_LCD_ILI9225_XRES
  86. #else
  87. # define ILI9225_XRES CONFIG_LCD_ILI9225_XRES
  88. # define ILI9225_YRES CONFIG_LCD_ILI9225_YRES
  89. #endif
  90. /* Color depth and format */
  91. #ifdef CONFIG_LCD_ILI9225_BPP
  92. # if (CONFIG_LCD_ILI9225_BPP == 16)
  93. # define ILI9225_BPP 16
  94. # define ILI9225_COLORFMT FB_FMT_RGB16_565
  95. # define ILI9225_BYTESPP 2
  96. # else
  97. # define ILI9225_BPP 16
  98. # define ILI9225_COLORFMT FB_FMT_RGB16_565
  99. # define ILI9225_BYTESPP 2
  100. # warning "Invalid color depth. Falling back to 16bpp"
  101. # endif
  102. #endif
  103. /****************************************************************************
  104. * Private Types
  105. ****************************************************************************/
  106. /* This structure describes the state of this driver */
  107. struct ili9225_dev_s
  108. {
  109. /* Publicly visible device structure */
  110. struct lcd_dev_s dev;
  111. /* Private LCD-specific information follows */
  112. FAR struct spi_dev_s *spi; /* SPI device */
  113. uint8_t bpp; /* Selected color depth */
  114. uint8_t power; /* Current power setting */
  115. /* This is working memory allocated by the LCD driver for each LCD device
  116. * and for each color plane. This memory will hold one raster line of data.
  117. * The size of the allocated run buffer must therefore be at least
  118. * (bpp * xres / 8). Actual alignment of the buffer must conform to the
  119. * bitwidth of the underlying pixel type.
  120. *
  121. * If there are multiple planes, they may share the same working buffer
  122. * because different planes will not be operate on concurrently. However,
  123. * if there are multiple LCD devices, they must each have unique run
  124. * buffers.
  125. */
  126. uint16_t runbuffer[ILI9225_LUT_SIZE];
  127. };
  128. /****************************************************************************
  129. * Private Function Protototypes
  130. ****************************************************************************/
  131. /* Misc. Helpers */
  132. static void ili9225_select(FAR struct spi_dev_s *spi, int bits);
  133. static void ili9225_deselect(FAR struct spi_dev_s *spi);
  134. static inline void ili9225_sendcmd(FAR struct ili9225_dev_s *dev,
  135. uint16_t cmd);
  136. static inline void ili9225_writereg(FAR struct ili9225_dev_s *dev,
  137. uint16_t reg, uint16_t data);
  138. static void ili9225_display(FAR struct ili9225_dev_s *dev, bool on);
  139. static void ili9225_setarea(FAR struct ili9225_dev_s *dev,
  140. uint16_t x0, uint16_t y0,
  141. uint16_t x1, uint16_t y1);
  142. static void ili9225_bpp(FAR struct ili9225_dev_s *dev, int bpp);
  143. static void ili9225_wrram(FAR struct ili9225_dev_s *dev,
  144. FAR const uint16_t *buff, size_t size);
  145. #ifndef CONFIG_LCD_NOGETRUN
  146. static void ili9225_rdram(FAR struct ili9225_dev_s *dev,
  147. FAR uint16_t *buff, size_t size);
  148. #endif
  149. static void ili9225_fill(FAR struct ili9225_dev_s *dev, uint16_t color);
  150. /* LCD Data Transfer Methods */
  151. static int ili9225_putrun(fb_coord_t row, fb_coord_t col,
  152. FAR const uint8_t *buffer, size_t npixels);
  153. #ifndef CONFIG_LCD_NOGETRUN
  154. static int ili9225_getrun(fb_coord_t row, fb_coord_t col,
  155. FAR uint8_t *buffer, size_t npixels);
  156. #endif
  157. /* LCD Configuration */
  158. static int ili9225_getvideoinfo(FAR struct lcd_dev_s *dev,
  159. FAR struct fb_videoinfo_s *vinfo);
  160. static int ili9225_getplaneinfo(FAR struct lcd_dev_s *dev,
  161. unsigned int planeno,
  162. FAR struct lcd_planeinfo_s *pinfo);
  163. /* LCD Specific Controls */
  164. static int ili9225_getpower(FAR struct lcd_dev_s *dev);
  165. static int ili9225_setpower(FAR struct lcd_dev_s *dev, int power);
  166. /****************************************************************************
  167. * Private Data
  168. ****************************************************************************/
  169. static struct ili9225_dev_s g_lcddev;
  170. /****************************************************************************
  171. * Private Functions
  172. ****************************************************************************/
  173. /****************************************************************************
  174. * Name: ili9225_select
  175. *
  176. * Description:
  177. * Select the SPI, locking and re-configuring if necessary
  178. *
  179. * Input Parameters:
  180. * spi - Reference to the SPI driver structure
  181. * bits - Number of SPI bits
  182. *
  183. * Returned Value:
  184. * None
  185. *
  186. * Assumptions:
  187. *
  188. ****************************************************************************/
  189. static void ili9225_select(FAR struct spi_dev_s *spi, int bits)
  190. {
  191. /* Select ILI9225 chip (locking the SPI bus in case there are multiple
  192. * devices competing for the SPI bus
  193. */
  194. SPI_LOCK(spi, true);
  195. SPI_SELECT(spi, SPIDEV_DISPLAY(0), true);
  196. /* Now make sure that the SPI bus is configured for the ILI9225 (it
  197. * might have gotten configured for a different device while unlocked)
  198. */
  199. SPI_SETMODE(spi, CONFIG_LCD_ILI9225_SPIMODE);
  200. SPI_SETBITS(spi, bits);
  201. SPI_SETFREQUENCY(spi, CONFIG_LCD_ILI9225_FREQUENCY);
  202. }
  203. /****************************************************************************
  204. * Name: ili9225_deselect
  205. *
  206. * Description:
  207. * De-select the SPI
  208. *
  209. * Input Parameters:
  210. * spi - Reference to the SPI driver structure
  211. *
  212. * Returned Value:
  213. * None
  214. *
  215. * Assumptions:
  216. *
  217. ****************************************************************************/
  218. static void ili9225_deselect(FAR struct spi_dev_s *spi)
  219. {
  220. /* De-select ILI9225 chip and relinquish the SPI bus. */
  221. SPI_SELECT(spi, SPIDEV_DISPLAY(0), false);
  222. SPI_LOCK(spi, false);
  223. }
  224. /****************************************************************************
  225. * Name: ili9225_sendcmd
  226. *
  227. * Description:
  228. * Write data into register.
  229. *
  230. ****************************************************************************/
  231. static inline void ili9225_writereg(FAR struct ili9225_dev_s *dev,
  232. uint16_t reg, uint16_t data)
  233. {
  234. ili9225_select(dev->spi, ILI9225_BYTESPP * 8);
  235. SPI_CMDDATA(dev->spi, SPIDEV_DISPLAY(0), true);
  236. SPI_SEND(dev->spi, reg);
  237. SPI_CMDDATA(dev->spi, SPIDEV_DISPLAY(0), false);
  238. SPI_SEND(dev->spi, data);
  239. ili9225_deselect(dev->spi);
  240. }
  241. /****************************************************************************
  242. * Name: ili9225_sendcmd
  243. *
  244. * Description:
  245. * Send a data to the driver.
  246. *
  247. ****************************************************************************/
  248. static inline void ili9225_sendcmd(FAR struct ili9225_dev_s *dev,
  249. uint16_t cmd)
  250. {
  251. ili9225_select(dev->spi, ILI9225_BYTESPP * 8);
  252. SPI_CMDDATA(dev->spi, SPIDEV_DISPLAY(0), true);
  253. SPI_SEND(dev->spi, cmd);
  254. SPI_CMDDATA(dev->spi, SPIDEV_DISPLAY(0), false);
  255. ili9225_deselect(dev->spi);
  256. }
  257. /****************************************************************************
  258. * Name: ili9225_display
  259. *
  260. * Description:
  261. * Turn on or off the display.
  262. *
  263. ****************************************************************************/
  264. static void ili9225_display(FAR struct ili9225_dev_s *dev, bool on)
  265. {
  266. if (!on)
  267. {
  268. /* Start turn off sequence */
  269. ili9225_writereg(dev, ILI9225_DISP_CTRL1, ILI9225_DISP_CTRL1_GON |
  270. ILI9225_DISP_CTRL1_D(2));
  271. up_mdelay(20);
  272. ili9225_writereg(dev, ILI9225_DISP_CTRL1, 0);
  273. up_mdelay(20);
  274. ili9225_writereg(dev, ILI9225_POWER_CTRL1, ILI9225_POWER_CTRL1_SAP(0));
  275. ili9225_writereg(dev, ILI9225_POWER_CTRL2, ~ILI9225_POWER_CTRL2_PON);
  276. ili9225_writereg(dev, ILI9225_POWER_CTRL5, 0);
  277. }
  278. else
  279. {
  280. /* Turn on sequence and settings */
  281. ili9225_writereg(dev, ILI9225_POWER_CTRL2, ILI9225_POWER_CTRL2_VC(8) |
  282. ILI9225_POWER_CTRL2_VC_EN
  283. );
  284. ili9225_writereg(dev, ILI9225_POWER_CTRL3, ILI9225_POWER_CTRL3_DC3(1) |
  285. ILI9225_POWER_CTRL3_DC2(2) |
  286. ILI9225_POWER_CTRL3_DC1(1) |
  287. ILI9225_POWER_CTRL3_BT(6)
  288. );
  289. ili9225_writereg(dev, ILI9225_POWER_CTRL4,
  290. ILI9225_POWER_CTRL4_GVD(111)
  291. );
  292. ili9225_writereg(dev, ILI9225_POWER_CTRL5,
  293. ILI9225_POWER_CTRL5_VML(95) |
  294. ILI9225_POWER_CTRL5_VCM(9) |
  295. ILI9225_POWER_CTRL5_VCOMG
  296. );
  297. ili9225_writereg(dev, ILI9225_POWER_CTRL1, ILI9225_POWER_CTRL1_SAP(8));
  298. ili9225_writereg(dev, ILI9225_POWER_CTRL2, ILI9225_POWER_CTRL2_VC(11) |
  299. ILI9225_POWER_CTRL2_VC_EN |
  300. ILI9225_POWER_CTRL2_AON |
  301. ILI9225_POWER_CTRL2_APON
  302. );
  303. ili9225_writereg(dev, ILI9225_DRIVER_OUTPUT_CTRL,
  304. ILI9225_DRIVER_OUTPUT_CTRL_NL(28) |
  305. ILI9225_DRIVER_OUTPUT_CTRL_SS
  306. );
  307. ili9225_writereg(dev, ILI9225_LCD_DRIVING_CTRL,
  308. ILI9225_LCD_DRIVING_CTRL_INV0);
  309. ili9225_writereg(dev, ILI9225_ENTRY_MODE, ILI9225_ENTRY_MODE_AM |
  310. ILI9225_ENTRY_MODE_ID(3) |
  311. ILI9225_ENTRY_MODE_BGR
  312. );
  313. ili9225_writereg(dev, ILI9225_DISP_CTRL2, ILI9225_DISP_CTRL2_BP(8) |
  314. ILI9225_DISP_CTRL2_FP(8)
  315. );
  316. ili9225_writereg(dev, ILI9225_FRAME_CYCLE_CTRL,
  317. ILI9225_FRAME_CYCLE_CTRL_STD(1) |
  318. ILI9225_FRAME_CYCLE_CTRL_NO(1)
  319. );
  320. ili9225_writereg(dev, ILI9225_RGB_DISP_INT_CTRL1,
  321. ILI9225_RGB_DISP_INT_CTRL1_RIM(1));
  322. ili9225_writereg(dev, ILI9225_OSC_CTRL, ILI9225_OSC_CTRL_EN |
  323. ILI9225_OSC_CTRL_FOSC(13)
  324. );
  325. ili9225_writereg(dev, ILI9225_VCI_REC, ILI9225_VCI_REC_VCIR(2));
  326. ili9225_writereg(dev, ILI9225_VER_SCROLL_CTRL1,
  327. ILI9225_VER_SCROLL_CTRL1_SEA(219)
  328. );
  329. ili9225_writereg(dev, ILI9225_PART_SCR_DRIV_POS1,
  330. ILI9225_PART_SCR_DRIV_POS1_SE(219)
  331. );
  332. ili9225_writereg(dev, ILI9225_HORIZONTAL_ADDR_END,
  333. ILI9225_HORIZONTAL_ADDR_END_HEA(175)
  334. );
  335. ili9225_writereg(dev, ILI9225_VERTICAL_ADDR_END,
  336. ILI9225_VERTICAL_ADDR_END_VEA(219)
  337. );
  338. ili9225_writereg(dev, ILI9225_GAMMA_CTRL2, ILI9225_GAMMA_CTRL2_KP2(8) |
  339. ILI9225_GAMMA_CTRL2_KP3(8)
  340. );
  341. ili9225_writereg(dev, ILI9225_GAMMA_CTRL3,
  342. ILI9225_GAMMA_CTRL3_KP4(10) |
  343. ILI9225_GAMMA_CTRL3_KP5(8)
  344. );
  345. ili9225_writereg(dev, ILI9225_GAMMA_CTRL4,
  346. ILI9225_GAMMA_CTRL4_RP0(10)
  347. );
  348. ili9225_writereg(dev, ILI9225_GAMMA_CTRL5, ILI9225_GAMMA_CTRL5_KN0(8) |
  349. ILI9225_GAMMA_CTRL5_KN1(10)
  350. );
  351. ili9225_writereg(dev, ILI9225_GAMMA_CTRL6, ILI9225_GAMMA_CTRL6_KN2(8) |
  352. ILI9225_GAMMA_CTRL6_KN3(8)
  353. );
  354. ili9225_writereg(dev, ILI9225_GAMMA_CTRL8,
  355. ILI9225_GAMMA_CTRL8_RN1(10)
  356. );
  357. ili9225_writereg(dev, ILI9225_GAMMA_CTRL9,
  358. ILI9225_GAMMA_CTRL9_VRP0(16) |
  359. ILI9225_GAMMA_CTRL9_VRP1(7)
  360. );
  361. ili9225_writereg(dev, ILI9225_GAMMA_CTRL10,
  362. ILI9225_GAMMA_CTRL10_VRN0(10) |
  363. ILI9225_GAMMA_CTRL10_VRN1(7)
  364. );
  365. ili9225_writereg(dev, ILI9225_DISP_CTRL1, ILI9225_DISP_CTRL1_D(2) |
  366. ILI9225_DISP_CTRL1_GON
  367. );
  368. ili9225_writereg(dev, ILI9225_DISP_CTRL1, ILI9225_DISP_CTRL1_D(3) |
  369. ILI9225_DISP_CTRL1_REV |
  370. ILI9225_DISP_CTRL1_GON |
  371. ILI9225_DISP_CTRL1_TEMON
  372. );
  373. }
  374. }
  375. /****************************************************************************
  376. * Name: ili9225_setarea
  377. *
  378. * Description:
  379. * Set the rectangular area for an upcoming read or write from RAM.
  380. *
  381. ****************************************************************************/
  382. static void ili9225_setarea(FAR struct ili9225_dev_s *dev,
  383. uint16_t x0, uint16_t y0,
  384. uint16_t x1, uint16_t y1)
  385. {
  386. /* Set row address */
  387. ili9225_writereg(dev, ILI9225_HORIZONTAL_ADDR_START,
  388. ILI9225_HORIZONTAL_ADDR_START_HSA(x0));
  389. ili9225_writereg(dev, ILI9225_HORIZONTAL_ADDR_END,
  390. ILI9225_HORIZONTAL_ADDR_END_HEA(x1));
  391. /* Set column address */
  392. ili9225_writereg(dev, ILI9225_VERTICAL_ADDR_START,
  393. ILI9225_VERTICAL_ADDR_START_VSA(y0));
  394. ili9225_writereg(dev, ILI9225_VERTICAL_ADDR_END,
  395. ILI9225_VERTICAL_ADDR_END_VEA(y1));
  396. }
  397. /****************************************************************************
  398. * Name: ili9225_bpp
  399. *
  400. * Description:
  401. * Set the color depth of the device.
  402. *
  403. ****************************************************************************/
  404. static void ili9225_bpp(FAR struct ili9225_dev_s *dev, int bpp)
  405. {
  406. if (dev->bpp != bpp)
  407. {
  408. dev->bpp = bpp;
  409. }
  410. }
  411. /****************************************************************************
  412. * Name: ili9225_wrram
  413. *
  414. * Description:
  415. * Write to the driver's RAM.
  416. *
  417. ****************************************************************************/
  418. static void ili9225_wrram(FAR struct ili9225_dev_s *dev,
  419. FAR const uint16_t *buff, size_t size)
  420. {
  421. ili9225_sendcmd(dev, ILI9225_GRAM_DATA_REG);
  422. ili9225_select(dev->spi, ILI9225_BYTESPP * 8);
  423. SPI_SNDBLOCK(dev->spi, buff, size);
  424. ili9225_deselect(dev->spi);
  425. }
  426. /****************************************************************************
  427. * Name: ili9225_rdram
  428. *
  429. * Description:
  430. * Read from the driver's RAM.
  431. *
  432. ****************************************************************************/
  433. #ifndef CONFIG_LCD_NOGETRUN
  434. static void ili9225_rdram(FAR struct ili9225_dev_s *dev,
  435. FAR uint16_t *buff, size_t size)
  436. {
  437. ili9225_sendcmd(dev, ILI9225_GRAM_DATA_REG);
  438. ili9225_select(dev->spi, ILI9225_BYTESPP * 8);
  439. SPI_RECVBLOCK(dev->spi, buff, size);
  440. ili9225_deselect(dev->spi);
  441. }
  442. #endif
  443. /****************************************************************************
  444. * Name: ili9225_fill
  445. *
  446. * Description:
  447. * Fill the display with the specified color.
  448. *
  449. ****************************************************************************/
  450. static void ili9225_fill(FAR struct ili9225_dev_s *dev, uint16_t color)
  451. {
  452. int i;
  453. ili9225_setarea(dev, 0, 0, ILI9225_XRES - 1, ILI9225_YRES - 1);
  454. ili9225_sendcmd(dev, ILI9225_GRAM_DATA_REG);
  455. ili9225_select(dev->spi, ILI9225_BYTESPP * 8);
  456. for (i = 0; i < ILI9225_XRES * ILI9225_YRES; i++)
  457. {
  458. SPI_SEND(dev->spi, color);
  459. }
  460. ili9225_deselect(dev->spi);
  461. }
  462. /****************************************************************************
  463. * Name: ili9225_putrun
  464. *
  465. * Description:
  466. * This method can be used to write a partial raster line to the LCD:
  467. *
  468. * row - Starting row to write to (range: 0 <= row < yres)
  469. * col - Starting column to write to (range: 0 <= col <= xres-npixels)
  470. * buffer - The buffer containing the run to be written to the LCD
  471. * npixels - The number of pixels to write to the LCD
  472. * (range: 0 < npixels <= xres-col)
  473. *
  474. ****************************************************************************/
  475. static int ili9225_putrun(fb_coord_t row, fb_coord_t col,
  476. FAR const uint8_t *buffer, size_t npixels)
  477. {
  478. FAR struct ili9225_dev_s *priv = &g_lcddev;
  479. FAR const uint16_t *src = (FAR const uint16_t *)buffer;
  480. ginfo("row: %d col: %d npixels: %d\n", row, col, npixels);
  481. DEBUGASSERT(buffer && ((uintptr_t)buffer & 1) == 0);
  482. ili9225_setarea(priv, col, row, col + npixels - 1, row);
  483. ili9225_wrram(priv, src, npixels);
  484. return OK;
  485. }
  486. /****************************************************************************
  487. * Name: ili9225_getrun
  488. *
  489. * Description:
  490. * This method can be used to read a partial raster line from the LCD:
  491. *
  492. * row - Starting row to read from (range: 0 <= row < yres)
  493. * col - Starting column to read read (range: 0 <= col <= xres-npixels)
  494. * buffer - The buffer in which to return the run read from the LCD
  495. * npixels - The number of pixels to read from the LCD
  496. * (range: 0 < npixels <= xres-col)
  497. *
  498. ****************************************************************************/
  499. #ifndef CONFIG_LCD_NOGETRUN
  500. static int ili9225_getrun(fb_coord_t row, fb_coord_t col,
  501. FAR uint8_t *buffer, size_t npixels)
  502. {
  503. FAR struct ili9225_dev_s *priv = &g_lcddev;
  504. FAR uint16_t *dest = (FAR uint16_t *)buffer;
  505. ginfo("row: %d col: %d npixels: %d\n", row, col, npixels);
  506. DEBUGASSERT(buffer && ((uintptr_t)buffer & 1) == 0);
  507. ili9225_setarea(priv, col, row, col + npixels - 1, row);
  508. ili9225_rdram(priv, dest, npixels);
  509. return OK;
  510. }
  511. #endif
  512. /****************************************************************************
  513. * Name: ili9225_getvideoinfo
  514. *
  515. * Description:
  516. * Get information about the LCD video controller configuration.
  517. *
  518. ****************************************************************************/
  519. static int ili9225_getvideoinfo(FAR struct lcd_dev_s *dev,
  520. FAR struct fb_videoinfo_s *vinfo)
  521. {
  522. DEBUGASSERT(dev && vinfo);
  523. lcdinfo("fmt: %d xres: %d yres: %d nplanes: 1\n",
  524. ILI9225_COLORFMT, ILI9225_XRES, ILI9225_YRES);
  525. vinfo->fmt = ILI9225_COLORFMT; /* Color format: RGB16-565: RRRR RGGG GGGB BBBB */
  526. vinfo->xres = ILI9225_XRES; /* Horizontal resolution in pixel columns */
  527. vinfo->yres = ILI9225_YRES; /* Vertical resolution in pixel rows */
  528. vinfo->nplanes = 1; /* Number of color planes supported */
  529. return OK;
  530. }
  531. /****************************************************************************
  532. * Name: ili9225_getplaneinfo
  533. *
  534. * Description:
  535. * Get information about the configuration of each LCD color plane.
  536. *
  537. ****************************************************************************/
  538. static int ili9225_getplaneinfo(FAR struct lcd_dev_s *dev,
  539. unsigned int planeno,
  540. FAR struct lcd_planeinfo_s *pinfo)
  541. {
  542. FAR struct ili9225_dev_s *priv = (FAR struct ili9225_dev_s *)dev;
  543. DEBUGASSERT(dev && pinfo && planeno == 0);
  544. lcdinfo("planeno: %d bpp: %d\n", planeno, ILI9225_BPP);
  545. pinfo->putrun = ili9225_putrun; /* Put a run into LCD memory */
  546. #ifndef CONFIG_LCD_NOGETRUN
  547. pinfo->getrun = ili9225_getrun; /* Get a run from LCD memory */
  548. #endif
  549. pinfo->buffer = (FAR uint8_t *)priv->runbuffer; /* Run scratch buffer */
  550. pinfo->bpp = priv->bpp; /* Bits-per-pixel */
  551. return OK;
  552. }
  553. /****************************************************************************
  554. * Name: ili9225_getpower
  555. ****************************************************************************/
  556. static int ili9225_getpower(FAR struct lcd_dev_s *dev)
  557. {
  558. FAR struct ili9225_dev_s *priv = (FAR struct ili9225_dev_s *)dev;
  559. lcdinfo("power: %d\n", priv->power);
  560. return priv->power;
  561. }
  562. /****************************************************************************
  563. * Name: ili9225_setpower
  564. ****************************************************************************/
  565. static int ili9225_setpower(FAR struct lcd_dev_s *dev, int power)
  566. {
  567. FAR struct ili9225_dev_s *priv = (FAR struct ili9225_dev_s *)dev;
  568. lcdinfo("power: %d\n", power);
  569. DEBUGASSERT((unsigned)power <= CONFIG_LCD_MAXPOWER);
  570. /* Set new power level */
  571. if (power > 0)
  572. {
  573. /* Turn on the display */
  574. ili9225_display(priv, true);
  575. /* Save the power */
  576. priv->power = power;
  577. }
  578. else
  579. {
  580. /* Turn off the display */
  581. ili9225_display(priv, false);
  582. /* Save the power */
  583. priv->power = 0;
  584. }
  585. return OK;
  586. }
  587. /****************************************************************************
  588. * Public Functions
  589. ****************************************************************************/
  590. /****************************************************************************
  591. * Name: ili9225_initialize
  592. *
  593. * Description:
  594. * Initialize the ILI9225 video hardware. The initial state of the
  595. * LCD is fully initialized, display memory cleared, and the LCD ready
  596. * to use, but with the power setting at 0 (full off == sleep mode).
  597. *
  598. * Returned Value:
  599. *
  600. * On success, this function returns a reference to the LCD object for
  601. * the specified LCD. NULL is returned on any failure.
  602. *
  603. ****************************************************************************/
  604. FAR struct lcd_dev_s *ili9225_lcdinitialize(FAR struct spi_dev_s *spi)
  605. {
  606. FAR struct ili9225_dev_s *priv = &g_lcddev;
  607. /* Initialize the driver data structure */
  608. priv->dev.getvideoinfo = ili9225_getvideoinfo;
  609. priv->dev.getplaneinfo = ili9225_getplaneinfo;
  610. priv->dev.getpower = ili9225_getpower;
  611. priv->dev.setpower = ili9225_setpower;
  612. priv->spi = spi;
  613. /* Init the hardware and clear the display */
  614. ili9225_display(priv, true);
  615. ili9225_bpp(priv, ILI9225_BPP);
  616. /* Set background color */
  617. ili9225_fill(priv, 0x07ff);
  618. return &priv->dev;
  619. }
  620. #endif /* CONFIG_LCD_ILI9225 */