µGFX library fork

gdisp_lld_ILI9488.c 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /*
  2. * This file is subject to the terms of the GFX License. If a copy of
  3. * the license was not distributed with this file, you can obtain one at:
  4. *
  5. * http://ugfx.org/license.html
  6. */
  7. #include "gfx.h"
  8. #if GFX_USE_GDISP
  9. #if defined(GDISP_SCREEN_HEIGHT) || defined(GDISP_SCREEN_HEIGHT)
  10. #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT
  11. #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
  12. #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO
  13. COMPILER_WARNING("GDISP: This low level driver does not support setting a screen size. It is being ignored.")
  14. #endif
  15. #undef GDISP_SCREEN_WIDTH
  16. #undef GDISP_SCREEN_HEIGHT
  17. #endif
  18. #define GDISP_DRIVER_VMT GDISPVMT_ILI9488
  19. #include "gdisp_lld_config.h"
  20. #include "../../../src/gdisp/gdisp_driver.h"
  21. #include "board_ILI9488.h"
  22. /*===========================================================================*/
  23. /* Driver local definitions. */
  24. /*===========================================================================*/
  25. #ifndef GDISP_SCREEN_HEIGHT
  26. #define GDISP_SCREEN_HEIGHT 480
  27. #endif
  28. #ifndef GDISP_SCREEN_WIDTH
  29. #define GDISP_SCREEN_WIDTH 320
  30. #endif
  31. #ifndef GDISP_INITIAL_CONTRAST
  32. #define GDISP_INITIAL_CONTRAST 50
  33. #endif
  34. #ifndef GDISP_INITIAL_BACKLIGHT
  35. #define GDISP_INITIAL_BACKLIGHT 100
  36. #endif
  37. /*===========================================================================*/
  38. /* Driver local functions. */
  39. /*===========================================================================*/
  40. static void dummy_read(GDisplay* g) {
  41. volatile uint16_t dummy;
  42. dummy = read_data(g);
  43. (void)dummy;
  44. }
  45. static void set_viewport(GDisplay* g) {
  46. write_index(g, 0x2A);
  47. write_data(g, ((g->p.x >> 8) & 0x00FF));
  48. write_data(g, ((g->p.x >> 0) & 0x00FF));
  49. write_data(g, ((g->p.x + g->p.cx - 1) >> 8) & 0x00FF);
  50. write_data(g, ((g->p.x + g->p.cx - 1) >> 0) & 0x00FF);
  51. write_index(g, 0x2B);
  52. write_data(g, ((g->p.y >> 8) & 0x00FF));
  53. write_data(g, ((g->p.y >> 0) & 0x00FF));
  54. write_data(g, ((g->p.y + g->p.cy - 1) >> 8) & 0x00FF);
  55. write_data(g, ((g->p.y + g->p.cy - 1) >> 0) & 0x00FF);
  56. write_index(g, 0x2C);
  57. }
  58. /*===========================================================================*/
  59. /* Driver interrupt handlers. */
  60. /*===========================================================================*/
  61. /*===========================================================================*/
  62. /* Driver exported functions. */
  63. /*===========================================================================*/
  64. LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
  65. // No private area for this controller
  66. g->priv = 0;
  67. // Initialise the board interface
  68. init_board(g);
  69. /* Hardware reset */
  70. setpin_reset(g, TRUE);
  71. gfxSleepMilliseconds(2);
  72. setpin_reset(g, FALSE);
  73. gfxSleepMilliseconds(10);
  74. setpin_reset(g, TRUE);
  75. gfxSleepMilliseconds(120);
  76. /* Get the bus for the following initialisation commands */
  77. acquire_bus(g);
  78. write_index(g, 0xF7);
  79. write_data(g, 0xA9);
  80. write_data(g, 0x51);
  81. write_data(g, 0x2C);
  82. write_data(g, 0x82);
  83. write_index(g, 0xC0);
  84. write_data(g, 0x11);
  85. write_data(g, 0x09);
  86. write_index(g, 0xC1);
  87. write_data(g, 0x41);
  88. write_index(g, 0xC5);
  89. write_data(g, 0x00);
  90. write_data(g, 0x2A);
  91. write_data(g, 0x80);
  92. write_index(g, 0xB1);
  93. write_data(g, 0xB0);
  94. write_data(g, 0x11);
  95. write_index(g, 0xB4);
  96. write_data(g, 0x02);
  97. write_index(g, 0xB6);
  98. write_data(g, 0x02);
  99. write_data(g, 0x22);
  100. write_data(g, 0x3B);
  101. write_index(g, 0xB7);
  102. write_data(g, 0xC6);
  103. write_index(g, 0xBE);
  104. write_data(g, 0x00);
  105. write_data(g, 0x04);
  106. write_index(g, 0xE9);
  107. write_data(g, 0x00);
  108. write_index(g, 0x36);
  109. write_data(g, 0x08);
  110. write_index(g, 0x3A);
  111. write_data(g, 0x55);
  112. write_index(g, 0xE0);
  113. write_data(g, 0x00);
  114. write_data(g, 0x07);
  115. write_data(g, 0x12);
  116. write_data(g, 0x0B);
  117. write_data(g, 0x18);
  118. write_data(g, 0x0B);
  119. write_data(g, 0x3F);
  120. write_data(g, 0x9B);
  121. write_data(g, 0x4B);
  122. write_data(g, 0x0B);
  123. write_data(g, 0x0F);
  124. write_data(g, 0x0B);
  125. write_data(g, 0x15);
  126. write_data(g, 0x17);
  127. write_data(g, 0x0F);
  128. write_index(g, 0xE1);
  129. write_data(g, 0x00);
  130. write_data(g, 0x16);
  131. write_data(g, 0x1B);
  132. write_data(g, 0x02);
  133. write_data(g, 0x0F);
  134. write_data(g, 0x06);
  135. write_data(g, 0x34);
  136. write_data(g, 0x46);
  137. write_data(g, 0x48);
  138. write_data(g, 0x04);
  139. write_data(g, 0x0D);
  140. write_data(g, 0x0D);
  141. write_data(g, 0x35);
  142. write_data(g, 0x36);
  143. write_data(g, 0x0F);
  144. write_index(g, 0x11);
  145. gfxSleepMilliseconds(120);
  146. write_index(g, 0x29);
  147. // Finish Init
  148. post_init_board(g);
  149. // Release the bus
  150. release_bus(g);
  151. // Turn on the back-light
  152. set_backlight(g, GDISP_INITIAL_BACKLIGHT);
  153. // Initialise the GDISP structure
  154. g->g.Width = GDISP_SCREEN_WIDTH;
  155. g->g.Height = GDISP_SCREEN_HEIGHT;
  156. g->g.Orientation = GDISP_ROTATE_0;
  157. g->g.Powermode = powerOn;
  158. g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
  159. g->g.Contrast = GDISP_INITIAL_CONTRAST;
  160. return TRUE;
  161. }
  162. #if GDISP_HARDWARE_STREAM_WRITE
  163. LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
  164. acquire_bus(g);
  165. set_viewport(g);
  166. }
  167. LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
  168. write_data(g, gdispColor2Native(g->p.color));
  169. }
  170. LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
  171. release_bus(g);
  172. }
  173. #endif
  174. #if GDISP_HARDWARE_STREAM_READ
  175. LLDSPEC void gdisp_lld_read_start(GDisplay *g) {
  176. acquire_bus(g);
  177. set_viewport(g);
  178. setreadmode(g);
  179. dummy_read(g);
  180. }
  181. LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) {
  182. uint16_t data;
  183. data = read_data(g);
  184. return gdispNative2Color(data);
  185. }
  186. LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
  187. setwritemode(g);
  188. release_bus(g);
  189. }
  190. #endif
  191. #if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
  192. LLDSPEC void gdisp_lld_control(GDisplay *g) {
  193. switch(g->p.x) {
  194. case GDISP_CONTROL_POWER:
  195. if (g->g.Powermode == (powermode_t)g->p.ptr)
  196. return;
  197. switch((powermode_t)g->p.ptr) {
  198. case powerOff:
  199. acquire_bus(g);
  200. write_index(g, 0x28);
  201. gfxSleepMilliseconds(10);
  202. write_index(g, 0x10);
  203. release_bus(g);
  204. break;
  205. case powerOn:
  206. acquire_bus(g);
  207. write_index(g, 0x11);
  208. gfxSleepMilliseconds(120);
  209. write_index(g, 0x29);
  210. release_bus(g);
  211. if (g->g.Powermode != powerSleep)
  212. gdisp_lld_init(g);
  213. break;
  214. case powerSleep:
  215. acquire_bus(g);
  216. write_index(g, 0x28);
  217. gfxSleepMilliseconds(10);
  218. write_index(g, 0x10);
  219. release_bus(g);
  220. break;
  221. default:
  222. return;
  223. }
  224. g->g.Powermode = (powermode_t)g->p.ptr;
  225. return;
  226. case GDISP_CONTROL_ORIENTATION:
  227. if (g->g.Orientation == (orientation_t)g->p.ptr)
  228. return;
  229. switch((orientation_t)g->p.ptr) {
  230. case GDISP_ROTATE_0:
  231. acquire_bus(g);
  232. write_index(g, 0x36);
  233. write_data(g, 0x08);
  234. release_bus(g);
  235. g->g.Height = GDISP_SCREEN_HEIGHT;
  236. g->g.Width = GDISP_SCREEN_WIDTH;
  237. break;
  238. case GDISP_ROTATE_90:
  239. acquire_bus(g);
  240. write_index(g, 0x36);
  241. write_data(g, 0x68);
  242. release_bus(g);
  243. g->g.Height = GDISP_SCREEN_WIDTH;
  244. g->g.Width = GDISP_SCREEN_HEIGHT;
  245. break;
  246. case GDISP_ROTATE_180:
  247. acquire_bus(g);
  248. write_index(g, 0x36);
  249. write_data(g, 0xC8);
  250. release_bus(g);
  251. g->g.Height = GDISP_SCREEN_HEIGHT;
  252. g->g.Width = GDISP_SCREEN_WIDTH;
  253. break;
  254. case GDISP_ROTATE_270:
  255. acquire_bus(g);
  256. write_index(g, 0x36);
  257. write_data(g, 0xA8);
  258. release_bus(g);
  259. g->g.Height = GDISP_SCREEN_WIDTH;
  260. g->g.Width = GDISP_SCREEN_HEIGHT;
  261. break;
  262. default:
  263. return;
  264. }
  265. g->g.Orientation = (orientation_t)g->p.ptr;
  266. return;
  267. default:
  268. return;
  269. }
  270. }
  271. #endif
  272. #endif /* GFX_USE_GDISP */