ucg_dev_tft_128x128_ili9163.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. ucg_dev_tft_128x128_ili9163.c
  3. ILI9341 with 4-Wire SPI (SCK, SDI, CS, D/C and optional reset)
  4. Universal uC Color Graphics Library
  5. Copyright (c) 2015, olikraus@gmail.com
  6. All rights reserved.
  7. Redistribution and use in source and binary forms, with or without modification,
  8. are permitted provided that the following conditions are met:
  9. * Redistributions of source code must retain the above copyright notice, this list
  10. of conditions and the following disclaimer.
  11. * Redistributions in binary form must reproduce the above copyright notice, this
  12. list of conditions and the following disclaimer in the documentation and/or other
  13. materials provided with the distribution.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  15. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  16. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  17. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  19. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  24. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  26. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #include "ucg.h"
  29. static const ucg_pgm_uint8_t ucg_tft_128x128_ili9163_init_seq[] = {
  30. UCG_CFG_CD(0,1), /* DC=0 for command mode, DC=1 for data and args */
  31. UCG_RST(1),
  32. UCG_CS(1), /* disable chip */
  33. UCG_DLY_MS(5),
  34. UCG_RST(0),
  35. UCG_DLY_MS(5),
  36. UCG_RST(1),
  37. UCG_DLY_MS(50),
  38. UCG_CS(0), /* enable chip */
  39. UCG_C10(0x011), /* sleep out */
  40. UCG_DLY_MS(10),
  41. //UCG_C10(0x038), /* idle mode off */
  42. UCG_C10(0x013), /* normal display on */
  43. //UCG_C14(0x0ed, 0x055, 0x001, 0x023, 0x001), /* power on sequence control (POR values) */
  44. //UCG_C11(0x0f7, 0x020), /* pump ratio control (POR value) */
  45. UCG_C10(0x20), /* not inverted */
  46. //UCG_C10(0x21), /* inverted */
  47. UCG_C11(0x03a, 0x066), /* set pixel format to 18 bit */
  48. //UCG_C11(0x03a, 0x055), /* set pixel format to 16 bit */
  49. //UCG_C12(0x0b1, 0x000, 0x01b), /* frame rate control (POR values) */
  50. //UCG_C14(0x0b6, 0x00a, 0x082 | (1<<5), 0x027, 0x000), /* display function control (POR values, except for shift direction bit) */
  51. //UCG_C11(0x0b7, 0x006), /* entry mode, bit 0: Low voltage detection control (0=off) */
  52. UCG_C12(0x0c0, 0x00a, 0x002), /* power control 1 */
  53. UCG_C11(0x0c1, 0x002), /* power control 2 (step up factor), POR=2 */
  54. UCG_C11(0x0c7, 0x0d0), /* VCOM control 2, enable VCOM control 1 */
  55. UCG_C12(0x0c5, 0x040, 0x04a), /* VCOM control 1, POR=31,3C */
  56. // UCG_C15(0x0cb, 0x039, 0x02c, 0x000, 0x034, 0x002), /* power control A (POR values) */
  57. // UCG_C13(0x0cf, 0x000, 0x081, 0x030), /* power control B (POR values) */
  58. // UCG_C13(0x0e8, 0x084, 0x011, 0x07a), /* timer driving control A (POR values) */
  59. // UCG_C12(0x0ea, 0x066, 0x000), /* timer driving control B (POR values) */
  60. //UCG_C12(0x0ea, 0x000, 0x000), /* timer driving control B */
  61. //UCG_C10(0x28), /* display off */
  62. //UCG_C11(0x0bf, 0x003), /* backlight control 8 */
  63. UCG_C10(0x029), /* display on */
  64. //UCG_C11(0x051, 0x07f), /* brightness */
  65. //UCG_C11(0x053, 0x02c), /* control brightness */
  66. //UCG_C10(0x028), /* display off */
  67. UCG_C11( 0x036, 0x008),
  68. UCG_C14( 0x02a, 0x000, 0x000, 0x000, 0x07f), /* Horizontal GRAM Address Set */
  69. UCG_C14( 0x02b, 0x000, 0x000, 0x000, 0x07f), /* Vertical GRAM Address Set */
  70. UCG_C10( 0x02c), /* Write Data to GRAM */
  71. UCG_CS(1), /* disable chip */
  72. UCG_END(), /* end of sequence */
  73. };
  74. ucg_int_t ucg_dev_ili9163_18x128x128(ucg_t *ucg, ucg_int_t msg, void *data)
  75. {
  76. switch(msg)
  77. {
  78. case UCG_MSG_DEV_POWER_UP:
  79. /* 1. Call to the controller procedures to setup the com interface */
  80. if ( ucg_dev_ic_ili9163_18(ucg, msg, data) == 0 )
  81. return 0;
  82. /* 2. Send specific init sequence for this display module */
  83. ucg_com_SendCmdSeq(ucg, ucg_tft_128x128_ili9163_init_seq);
  84. return 1;
  85. case UCG_MSG_DEV_POWER_DOWN:
  86. /* let do power down by the conroller procedures */
  87. return ucg_dev_ic_ili9163_18(ucg, msg, data);
  88. case UCG_MSG_GET_DIMENSION:
  89. ((ucg_wh_t *)data)->w = 128;
  90. ((ucg_wh_t *)data)->h = 128;
  91. return 1;
  92. }
  93. /* all other messages are handled by the controller procedures */
  94. return ucg_dev_ic_ili9163_18(ucg, msg, data);
  95. }