µGFX library fork

gdisp_lld_LGDP4532.c 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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. /* This controller is only ever used with a 240 x 320 display */
  10. #if defined(GDISP_SCREEN_HEIGHT) || defined(GDISP_SCREEN_HEIGHT)
  11. #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT
  12. #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
  13. #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO
  14. COMPILER_WARNING("GDISP: This low level driver does not support setting a screen size. It is being ignored.")
  15. #endif
  16. #undef GDISP_SCREEN_WIDTH
  17. #undef GDISP_SCREEN_HEIGHT
  18. #endif
  19. #define GDISP_DRIVER_VMT GDISPVMT_LGDP4532
  20. #include "gdisp_lld_config.h"
  21. #include "../../../src/gdisp/gdisp_driver.h"
  22. #include "board_LGDP4532.h"
  23. /*===========================================================================*/
  24. /* Driver local definitions. */
  25. /*===========================================================================*/
  26. #ifndef GDISP_SCREEN_HEIGHT
  27. #define GDISP_SCREEN_HEIGHT 320
  28. #endif
  29. #ifndef GDISP_SCREEN_WIDTH
  30. #define GDISP_SCREEN_WIDTH 240
  31. #endif
  32. #ifndef GDISP_INITIAL_CONTRAST
  33. #define GDISP_INITIAL_CONTRAST 50
  34. #endif
  35. #ifndef GDISP_INITIAL_BACKLIGHT
  36. #define GDISP_INITIAL_BACKLIGHT 100
  37. #endif
  38. /*===========================================================================*/
  39. /* Driver local variables. */
  40. /*===========================================================================*/
  41. /*===========================================================================*/
  42. /* Driver local functions. */
  43. /*===========================================================================*/
  44. // Some common routines and macros
  45. #define dummy_read(g) { volatile uint16_t dummy; dummy = read_data(g); (void) dummy; }
  46. #define write_reg(g, reg, data) { write_index(g, reg); write_data(g, data); }
  47. static void set_cursor(GDisplay *g) {
  48. switch(g->g.Orientation) {
  49. default:
  50. case GDISP_ROTATE_0:
  51. case GDISP_ROTATE_180:
  52. write_reg(g, 0x20, g->p.x);
  53. write_reg(g, 0x21, g->p.y);
  54. break;
  55. case GDISP_ROTATE_90:
  56. case GDISP_ROTATE_270:
  57. write_reg(g, 0x20, g->p.y);
  58. write_reg(g, 0x21, g->p.x);
  59. break;
  60. }
  61. write_index(g, 0x22);
  62. }
  63. static void set_viewport(GDisplay* g) {
  64. switch(g->g.Orientation) {
  65. default:
  66. case GDISP_ROTATE_0:
  67. case GDISP_ROTATE_180:
  68. write_reg(g, 0x50, g->p.x);
  69. write_reg(g, 0x51, g->p.x + g->p.cx - 1);
  70. write_reg(g, 0x52, g->p.y);
  71. write_reg(g, 0x53, g->p.y + g->p.cy - 1);
  72. break;
  73. case GDISP_ROTATE_90:
  74. case GDISP_ROTATE_270:
  75. write_reg(g, 0x50, g->p.y);
  76. write_reg(g, 0x51, g->p.y + g->p.cy - 1);
  77. write_reg(g, 0x52, g->p.x);
  78. write_reg(g, 0x53, g->p.x + g->p.cx - 1);
  79. break;
  80. }
  81. }
  82. LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
  83. // No private area for this controller
  84. g->priv = 0;
  85. // Initialise the board interface
  86. init_board(g);
  87. /* Hardware reset */
  88. setpin_reset(g, TRUE);
  89. gfxSleepMilliseconds(1);
  90. setpin_reset(g, FALSE);
  91. gfxSleepMilliseconds(2);
  92. acquire_bus(g);
  93. setwritemode(g);
  94. // chinese code starts here
  95. //############# void Power_Set(void) ################//
  96. write_reg(g, 0x00, 0x0001);
  97. gfxSleepMilliseconds(10);
  98. write_reg(g, 0x15, 0x0030);
  99. write_reg(g, 0x11, 0x0040);
  100. write_reg(g, 0x10, 0x1628);
  101. write_reg(g, 0x12, 0x0000);
  102. write_reg(g, 0x13, 0x104d);
  103. gfxSleepMilliseconds(10);
  104. write_reg(g, 0x12, 0x0010);
  105. gfxSleepMilliseconds(10);
  106. write_reg(g, 0x10, 0x2620);
  107. write_reg(g, 0x13, 0x344d); //304d
  108. gfxSleepMilliseconds(10);
  109. write_reg(g, 0x01, 0x0100);
  110. write_reg(g, 0x02, 0x0300);
  111. write_reg(g, 0x03, 0x1038);//0x1030
  112. write_reg(g, 0x08, 0x0604);
  113. write_reg(g, 0x09, 0x0000);
  114. write_reg(g, 0x0A, 0x0008);
  115. write_reg(g, 0x41, 0x0002);
  116. write_reg(g, 0x60, 0xA700);
  117. write_reg(g, 0x61, 0x0001);
  118. write_reg(g, 0x90, 0x0182);
  119. write_reg(g, 0x93, 0x0001);
  120. write_reg(g, 0xa3, 0x0010);
  121. gfxSleepMilliseconds(10);
  122. //################# void Gamma_Set(void) ####################//
  123. write_reg(g, 0x30, 0x0000);
  124. write_reg(g, 0x31, 0x0502);
  125. write_reg(g, 0x32, 0x0307);
  126. write_reg(g, 0x33, 0x0305);
  127. write_reg(g, 0x34, 0x0004);
  128. write_reg(g, 0x35, 0x0402);
  129. write_reg(g, 0x36, 0x0707);
  130. write_reg(g, 0x37, 0x0503);
  131. write_reg(g, 0x38, 0x1505);
  132. write_reg(g, 0x39, 0x1505);
  133. gfxSleepMilliseconds(10);
  134. //################## void Display_ON(void) ####################//
  135. write_reg(g, 0x07, 0x0001);
  136. gfxSleepMilliseconds(10);
  137. write_reg(g, 0x07, 0x0021);
  138. write_reg(g, 0x07, 0x0023);
  139. gfxSleepMilliseconds(10);
  140. write_reg(g, 0x07, 0x0033);
  141. gfxSleepMilliseconds(10);
  142. write_reg(g, 0x07, 0x0133);
  143. // chinese code ends here
  144. // Finish Init
  145. post_init_board(g);
  146. // Release the bus
  147. release_bus(g);
  148. // Turn on the backlight
  149. set_backlight(g, GDISP_INITIAL_BACKLIGHT);
  150. /* Initialise the GDISP structure */
  151. g->g.Width = GDISP_SCREEN_WIDTH;
  152. g->g.Height = GDISP_SCREEN_HEIGHT;
  153. g->g.Orientation = GDISP_ROTATE_0;
  154. g->g.Powermode = powerOn;
  155. g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
  156. g->g.Contrast = GDISP_INITIAL_CONTRAST;
  157. return TRUE;
  158. }
  159. #if GDISP_HARDWARE_STREAM_WRITE
  160. LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
  161. acquire_bus(g);
  162. set_viewport(g);
  163. }
  164. LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
  165. write_data(g, gdispColor2Native(g->p.color));
  166. }
  167. LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
  168. release_bus(g);
  169. }
  170. LLDSPEC void gdisp_lld_write_pos(GDisplay *g) {
  171. set_cursor(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. set_cursor(g);
  179. setreadmode(g);
  180. dummy_read(g);
  181. }
  182. LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) {
  183. uint16_t data;
  184. data = read_data(g);
  185. return gdispNative2Color(data);
  186. }
  187. LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
  188. setwritemode(g);
  189. release_bus(g);
  190. }
  191. #endif
  192. #if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
  193. LLDSPEC void gdisp_lld_control(GDisplay *g) {
  194. switch(g->p.x) {
  195. case GDISP_CONTROL_POWER:
  196. if (g->g.Powermode == (powermode_t)g->p.ptr)
  197. return;
  198. switch((powermode_t)g->p.ptr) {
  199. case powerOff:
  200. acquire_bus(g);
  201. write_reg(g, 0x07, 0x0000);
  202. write_reg(g, 0x10, 0x0000);
  203. write_reg(g, 0x11, 0x0000);
  204. write_reg(g, 0x12, 0x0000);
  205. write_reg(g, 0x13, 0x0000);
  206. release_bus(g);
  207. set_backlight(g, 0);
  208. break;
  209. case powerOn:
  210. //*************Power On sequence ******************//
  211. acquire_bus(g);
  212. write_reg(g, 0x10, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  213. write_reg(g, 0x11, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
  214. write_reg(g, 0x12, 0x0000); /* VREG1OUT voltage */
  215. write_reg(g, 0x13, 0x0000); /* VDV[4:0] for VCOM amplitude */
  216. gfxSleepMilliseconds(200); /* Dis-charge capacitor power voltage */
  217. write_reg(g, 0x10, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  218. write_reg(g, 0x11, 0x0147); /* DC1[2:0], DC0[2:0], VC[2:0] */
  219. gfxSleepMilliseconds(50);
  220. write_reg(g, 0x12, 0x013C); /* VREG1OUT voltage */
  221. gfxSleepMilliseconds(50);
  222. write_reg(g, 0x13, 0x0E00); /* VDV[4:0] for VCOM amplitude */
  223. write_reg(g, 0x29, 0x0009); /* VCM[4:0] for VCOMH */
  224. gfxSleepMilliseconds(50);
  225. write_reg(g, 0x07, 0x0173); /* 262K color and display ON */
  226. release_bus(g);
  227. set_backlight(g, g->g.Backlight);
  228. break;
  229. case powerSleep:
  230. acquire_bus(g);
  231. write_reg(g, 0x07, 0x0000); /* display OFF */
  232. write_reg(g, 0x10, 0x0000); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
  233. write_reg(g, 0x11, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
  234. write_reg(g, 0x12, 0x0000); /* VREG1OUT voltage */
  235. write_reg(g, 0x13, 0x0000); /* VDV[4:0] for VCOM amplitude */
  236. gfxSleepMilliseconds(200); /* Dis-charge capacitor power voltage */
  237. write_reg(g, 0x10, 0x0002); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
  238. release_bus(g);
  239. set_backlight(g, g->g.Backlight);
  240. break;
  241. case powerDeepSleep:
  242. acquire_bus(g);
  243. write_reg(g, 0x07, 0x0000); /* display OFF */
  244. write_reg(g, 0x10, 0x0000); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
  245. write_reg(g, 0x11, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
  246. write_reg(g, 0x12, 0x0000); /* VREG1OUT voltage */
  247. write_reg(g, 0x13, 0x0000); /* VDV[4:0] for VCOM amplitude */
  248. gfxSleepMilliseconds(200); /* Dis-charge capacitor power voltage */
  249. write_reg(g, 0x10, 0x0004); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
  250. release_bus(g);
  251. set_backlight(g, g->g.Backlight);
  252. break;
  253. default:
  254. return;
  255. }
  256. g->g.Powermode = (powermode_t)g->p.ptr;
  257. return;
  258. case GDISP_CONTROL_ORIENTATION:
  259. if (g->g.Orientation == (orientation_t)g->p.ptr)
  260. return;
  261. switch((orientation_t)g->p.ptr) {
  262. case GDISP_ROTATE_0:
  263. acquire_bus(g);
  264. write_reg(g, 0x01, 0x0100);
  265. write_reg(g, 0x03, 0x1030);
  266. write_reg(g, 0x60, 0x2700);
  267. release_bus(g);
  268. g->g.Height = GDISP_SCREEN_HEIGHT;
  269. g->g.Width = GDISP_SCREEN_WIDTH;
  270. break;
  271. case GDISP_ROTATE_90:
  272. acquire_bus(g);
  273. write_reg(g, 0x01, 0x0100);
  274. write_reg(g, 0x03, 0x1038);
  275. write_reg(g, 0x60, 0xA700);
  276. release_bus(g);
  277. g->g.Height = GDISP_SCREEN_WIDTH;
  278. g->g.Width = GDISP_SCREEN_HEIGHT;
  279. break;
  280. case GDISP_ROTATE_180:
  281. acquire_bus(g);
  282. write_reg(g, 0x01, 0x0000);
  283. write_reg(g, 0x03, 0x1030);
  284. write_reg(g, 0x60, 0xa700);
  285. release_bus(g);
  286. g->g.Height = GDISP_SCREEN_HEIGHT;
  287. g->g.Width = GDISP_SCREEN_WIDTH;
  288. break;
  289. case GDISP_ROTATE_270:
  290. acquire_bus(g);
  291. write_reg(g, 0x01, 0x0000);
  292. write_reg(g, 0x03, 0x1038);
  293. write_reg(g, 0x60, 0x2700);
  294. release_bus(g);
  295. g->g.Height = GDISP_SCREEN_WIDTH;
  296. g->g.Width = GDISP_SCREEN_HEIGHT;
  297. break;
  298. default:
  299. return;
  300. }
  301. g->g.Orientation = (orientation_t)g->p.ptr;
  302. return;
  303. case GDISP_CONTROL_BACKLIGHT:
  304. if ((unsigned)g->p.ptr > 100)
  305. g->p.ptr = (void *)100;
  306. set_backlight(g, (unsigned)g->p.ptr);
  307. g->g.Backlight = (unsigned)g->p.ptr;
  308. return;
  309. default:
  310. return;
  311. }
  312. }
  313. #endif
  314. #endif /* GFX_USE_GDISP */