ucg_dev_tft_240x320_ili9325_spi.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. ucg_dev_tft_240x320_ili9325_spi.c
  3. Device for the ILI9325 in 8 bit SPI mode (IM3=0, IM2=1, IM1=1, IM0=1)
  4. All commands are 8 bit width only.
  5. 1 May 2014: Currently, this is not working
  6. Universal uC Color Graphics Library
  7. Copyright (c) 2014, olikraus@gmail.com
  8. All rights reserved.
  9. Redistribution and use in source and binary forms, with or without modification,
  10. are permitted provided that the following conditions are met:
  11. * Redistributions of source code must retain the above copyright notice, this list
  12. of conditions and the following disclaimer.
  13. * Redistributions in binary form must reproduce the above copyright notice, this
  14. list of conditions and the following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  17. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  18. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  21. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  26. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  28. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include "ucg.h"
  31. //static const uint8_t ucg_dev_ssd1351_128x128_init_seq[] PROGMEM = {
  32. static const ucg_pgm_uint8_t ucg_tft_240x320_ili9325_spi_init_seq[] = {
  33. UCG_CFG_CD(0,1), /* DC=0 for command mode, DC=1 for data and args */
  34. UCG_RST(1),
  35. UCG_CS(1), /* disable chip */
  36. UCG_DLY_MS(5),
  37. UCG_RST(0),
  38. UCG_DLY_MS(5),
  39. UCG_RST(1),
  40. UCG_DLY_MS(50),
  41. UCG_CS(0), /* enable chip */
  42. UCG_DLY_MS(1), /* delay 1 ms */
  43. UCG_C12(0x001,0x001, 0x000), /* Driver Output Control, bits 8 & 10 */
  44. UCG_C12(0x002, 0x007, 0x000), /* LCD Driving Wave Control, bit 9: Set line inversion */
  45. //UCG_C12(0x003, 0x010, 0x030), /* Entry Mode, GRAM write direction and BGR (Bit 12)=1 (16 bit transfer, 65K Mode)*/
  46. UCG_C12(0x003, 0xc0 | 0x010, 0x030), /* Entry Mode, GRAM write direction and BGR (Bit 12)=1, set TRI (Bit 15) and DFM (Bit 14) --> three byte transfer */
  47. //UCG_C12(0x004, 0x000, 0x000), /* Resize register, all 0: no resize */
  48. UCG_C12(0x008, 0x002, 0x007), /* Display Control 2: set the back porch and front porch */
  49. //UCG_C12(0x009, 0x000, 0x000), /* Display Control 3: normal scan */
  50. //UCG_C12(0x00a, 0x000, 0x000), /* Display Control 4: set to "no FMARK output" */
  51. UCG_C12(0x00c, 0x000, 0x000), /* RGB Display Interface Control 1, RIM=10 (3x6 Bit), 12 Jan 14: RIM=00 */
  52. //UCG_C12(0x00d, 0x000, 0x000), /* Frame Maker Position */
  53. //UCG_C12(0x00f, 0x000, 0x000), /* RGB Display Interface Control 2 */
  54. UCG_C12(0x010, 0x000, 0x000), /* Power Control 1: SAP, BT[3:0], AP, DSTB, SLP, STB, actual setting is done below */
  55. UCG_C12(0x011, 0x000, 0x007), /* Power Control 2: DC1[2:0], DC0[2:0], VC[2:0] */
  56. UCG_C12(0x012, 0x000, 0x000), /* Power Control 3: VREG1OUT voltage */
  57. UCG_C12(0x013, 0x000, 0x000), /* Power Control 4: VDV[4:0] for VCOM amplitude */
  58. //UCG_C12(0x007, 0x000, 0x001), /* Display Control 1: Operate, but do not display */
  59. UCG_C12( 0x007, 0x001, 0x033), /* Display Control 1: Operate, display ON, Partial image off */
  60. UCG_DLY_MS(100), /* delay 100 ms */ /* ITDB02 none D verion: 50ms */
  61. UCG_C12( 0x010, 0x010, 0x090), /* Power Control 1: SAP, BT[3:0], AP, DSTB, SLP, STB */
  62. /* 12. Jan 14. Prev value: 0x016, 0x090 */
  63. /* ITDB02 none D verion: 0x010, 0x090 */
  64. //UCG_C12( 0x010, 0x017, 0x0f0), /* Power Control 1: Setting for max quality & power consumption: SAP(Bit 12)=1, BT[3:0]=7 (max), APE (Bit 8)=1, AP=7 (max), disable sleep: SLP=0, STB=0 */
  65. UCG_C12( 0x011, 0x002, 0x027), /* Power Control 2 VCI ration, step up circuits 1 & 2 */
  66. UCG_DLY_MS(50), /* delay 50 ms */
  67. UCG_C12( 0x012, 0x000, 0x01f), /* Power Control 3: VCI: External, VCI*1.80 */
  68. /* 12. Jan 14. Prev value: 0x000, 0x00d */
  69. UCG_DLY_MS(50), /* delay 50 ms */
  70. UCG_C12( 0x013, 0x015, 0x000), /* Power Control 4: VDV[4:0] for VCOM amplitude */
  71. /* 12. Jan 14. Prev value: 0x012, 0x009 */
  72. UCG_C12( 0x029, 0x000, 0x027), /* Power Control 7 */
  73. /* 12. Jan 14. Prev value: 0x000, 0x00a */
  74. UCG_C12( 0x02b, 0x000, 0x00d), /* Frame Rate: 93 */
  75. //UCG_C12( 0x02b, 0x000, 0x00b), /* Frame Rate: 70, too less, some flicker visible */
  76. UCG_DLY_MS(50), /* delay 50 ms */
  77. /* Gamma Control, values from iteadstudio.com reference software on google code */
  78. /*
  79. UCG_C12(0x30,0x00,0x00),
  80. UCG_C12(0x31,0x07,0x07),
  81. UCG_C12(0x32,0x03,0x07),
  82. UCG_C12(0x35,0x02,0x00),
  83. UCG_C12(0x36,0x00,0x08),
  84. UCG_C12(0x37,0x00,0x04),
  85. UCG_C12(0x38,0x00,0x00),
  86. UCG_C12(0x39,0x07,0x07),
  87. UCG_C12(0x3C,0x00,0x02),
  88. UCG_C12(0x3D,0x1D,0x04),
  89. */
  90. UCG_C12( 0x020, 0x000, 0x000), /* Horizontal GRAM Address Set */
  91. UCG_C12( 0x021, 0x000, 0x000), /* Vertical GRAM Address Set */
  92. UCG_C12( 0x050, 0x000, 0x000), /* Horizontal GRAM Start Address */
  93. UCG_C12( 0x051, 0x000, 0x0EF), /* Horizontal GRAM End Address: 239 */
  94. UCG_C12( 0x052, 0x000, 0x000), /* Vertical GRAM Start Address */
  95. UCG_C12( 0x053, 0x001, 0x03F), /* Vertical GRAM End Address: 319 */
  96. UCG_C12( 0x060, 0x0a7, 0x000), /* Driver Output Control 2, NL = 0x027 = 320 lines, GS (bit 15) = 1 */
  97. UCG_C12( 0x061, 0x000, 0x001), /* Base Image Display Control: NDL,VLE = 0 (Disbale Vertical Scroll), REV */
  98. //UCG_C12( 0x06a, 0x000, 0x000), /* Vertical Scroll Control */
  99. //UCG_C12( 0x080, 0x000, 0x000), /* Partial Image 1 Display Position */
  100. //UCG_C12( 0x081, 0x000, 0x000), /* Partial Image 1 RAM Start Address */
  101. //UCG_C12( 0x082, 0x000, 0x000), /* Partial Image 1 RAM End Address */
  102. //UCG_C12( 0x083, 0x000, 0x000), /* Partial Image 2 Display Position */
  103. //UCG_C12( 0x084, 0x000, 0x000), /* Partial Image 2 RAM Start Address */
  104. //UCG_C12( 0x085, 0x000, 0x000), /* Partial Image 2 RAM End Address */
  105. UCG_C12( 0x090, 0x000, 0x010), /* Panel Interface Control 1 */
  106. UCG_C12( 0x092, 0x000, 0x000), /* Panel Interface Control 2 */
  107. /* 0x006, 0x000 */
  108. UCG_C12( 0x007, 0x001, 0x033), /* Display Control 1: Operate, display ON, Partial image off */
  109. UCG_DLY_MS(10), /* delay 10 ms */
  110. /* write test pattern */
  111. //UCG_C12( 0x020, 0x000, 0x000), /* Horizontal GRAM Address Set */
  112. //UCG_C12( 0x021, 0x000, 0x011), /* Vertical GRAM Address Set */
  113. UCG_C10( 0x022), /* Write Data to GRAM */
  114. UCG_CS(1), /* disable chip */
  115. UCG_END(), /* end of sequence */
  116. };
  117. ucg_int_t ucg_dev_ili9325_spi_18x240x320(ucg_t *ucg, ucg_int_t msg, void *data)
  118. {
  119. switch(msg)
  120. {
  121. case UCG_MSG_DEV_POWER_UP:
  122. /* 1. Call to the controller procedures to setup the com interface */
  123. if ( ucg_dev_ic_ili9325_spi_18(ucg, msg, data) == 0 )
  124. return 0;
  125. /* 2. Send specific init sequence for this display module */
  126. ucg_com_SendCmdSeq(ucg, ucg_tft_240x320_ili9325_spi_init_seq);
  127. return 1;
  128. case UCG_MSG_DEV_POWER_DOWN:
  129. /* let do power down by the conroller procedures */
  130. return ucg_dev_ic_ili9325_spi_18(ucg, msg, data);
  131. case UCG_MSG_GET_DIMENSION:
  132. ((ucg_wh_t *)data)->w = 240;
  133. ((ucg_wh_t *)data)->h = 320;
  134. return 1;
  135. }
  136. /* all other messages are handled by the controller procedures */
  137. return ucg_dev_ic_ili9325_spi_18(ucg, msg, data);
  138. }