µGFX library fork

gdisp_lld_R61505U.c 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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_R61505U
  20. #include "gdisp_lld_config.h"
  21. #include "../../../src/gdisp/gdisp_driver.h"
  22. #include "board_R61505U.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. #define dummy_read(g) { volatile uint16_t dummy; dummy = read_data(g); (void) dummy; }
  45. #define write_reg(g, reg, data) { write_index(g, reg); write_data(g, data); }
  46. static void set_cursor(GDisplay *g) {
  47. switch(g->g.Orientation) {
  48. default:
  49. case GDISP_ROTATE_0:
  50. case GDISP_ROTATE_180:
  51. write_reg(g, 0x20, g->p.x);
  52. write_reg(g, 0x21, g->p.y);
  53. break;
  54. case GDISP_ROTATE_90:
  55. case GDISP_ROTATE_270:
  56. write_reg(g, 0x20, g->p.y);
  57. write_reg(g, 0x21, g->p.x);
  58. break;
  59. }
  60. write_index(g, 0x22);
  61. }
  62. static void set_viewport(GDisplay *g) {
  63. switch(g->g.Orientation) {
  64. default:
  65. case GDISP_ROTATE_0:
  66. case GDISP_ROTATE_180:
  67. write_reg(g, 0x50, g->p.x);
  68. write_reg(g, 0x51, g->p.x + g->p.cx - 1);
  69. write_reg(g, 0x52, g->p.y);
  70. write_reg(g, 0x53, g->p.y + g->p.cy - 1);
  71. break;
  72. case GDISP_ROTATE_90:
  73. case GDISP_ROTATE_270:
  74. write_reg(g, 0x50, g->p.y);
  75. write_reg(g, 0x51, g->p.y + g->p.cy - 1);
  76. write_reg(g, 0x52, g->p.x);
  77. write_reg(g, 0x53, g->p.x + g->p.cx - 1);
  78. break;
  79. }
  80. }
  81. LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
  82. uint16_t cver;
  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. gfxSleepMicroseconds(1000);
  90. setpin_reset(g, FALSE);
  91. gfxSleepMicroseconds(1000);
  92. acquire_bus(g);
  93. write_index(g, 0); // Get controller version
  94. setreadmode(g);
  95. dummy_read(g);
  96. cver = read_data(g);
  97. setwritemode(g);
  98. /* initializing funciton */
  99. write_reg(g, 0xe5,0x8000); /* Set the internal vcore voltage */
  100. write_reg(g, 0x00,0x0001); /* start OSC */
  101. write_reg(g, 0x2b,0x0010); /* Set the frame rate as 80 when the internal resistor is used for oscillator circuit */
  102. write_reg(g, 0x01,0x0100); /* s720 to s1 ; G1 to G320 */
  103. write_reg(g, 0x02,0x0700); /* set the line inversion */
  104. write_reg(g, 0x03,0x1018); /* 65536 colors */
  105. write_reg(g, 0x04,0x0000);
  106. write_reg(g, 0x08,0x0202); /* specify the line number of front and back porch periods respectively */
  107. write_reg(g, 0x09,0x0000);
  108. write_reg(g, 0x0a,0x0000);
  109. write_reg(g, 0x0c,0x0000); /* select internal system clock */
  110. write_reg(g, 0x0d,0x0000);
  111. write_reg(g, 0x0f,0x0000);
  112. write_reg(g, 0x50,0x0000); /* set windows adress */
  113. write_reg(g, 0x51,0x00ef);
  114. write_reg(g, 0x52,0x0000);
  115. write_reg(g, 0x53,0x013f);
  116. write_reg(g, 0x60,0x2700);
  117. write_reg(g, 0x61,0x0001);
  118. write_reg(g, 0x6a,0x0000);
  119. write_reg(g, 0x80,0x0000);
  120. write_reg(g, 0x81,0x0000);
  121. write_reg(g, 0x82,0x0000);
  122. write_reg(g, 0x83,0x0000);
  123. write_reg(g, 0x84,0x0000);
  124. write_reg(g, 0x85,0x0000);
  125. write_reg(g, 0x90,0x0010);
  126. write_reg(g, 0x92,0x0000);
  127. write_reg(g, 0x93,0x0003);
  128. write_reg(g, 0x95,0x0110);
  129. write_reg(g, 0x97,0x0000);
  130. write_reg(g, 0x98,0x0000);
  131. /* power setting function */
  132. write_reg(g, 0x10,0x0000);
  133. write_reg(g, 0x11,0x0000);
  134. write_reg(g, 0x12,0x0000);
  135. write_reg(g, 0x13,0x0000);
  136. gfxSleepMicroseconds(100);
  137. write_reg(g, 0x10,0x17b0);
  138. write_reg(g, 0x11,0x0004);
  139. gfxSleepMicroseconds(50);
  140. write_reg(g, 0x12,0x013e);
  141. gfxSleepMicroseconds(50);
  142. write_reg(g, 0x13,0x1f00);
  143. write_reg(g, 0x29,0x000f);
  144. gfxSleepMicroseconds(50);
  145. write_reg(g, 0x20,0x0000);
  146. write_reg(g, 0x21,0x0000);
  147. /* initializing function */
  148. write_reg(g, 0x30,0x0204);
  149. write_reg(g, 0x31,0x0001);
  150. write_reg(g, 0x32,0x0000);
  151. write_reg(g, 0x35,0x0206);
  152. write_reg(g, 0x36,0x0600);
  153. write_reg(g, 0x37,0x0500);
  154. write_reg(g, 0x38,0x0505);
  155. write_reg(g, 0x39,0x0407);
  156. write_reg(g, 0x3c,0x0500);
  157. write_reg(g, 0x3d,0x0503);
  158. /* display on */
  159. write_reg(g, 0x07,0x0173);
  160. gfxSleepMicroseconds(50);
  161. // Finish Init
  162. post_init_board(g);
  163. // Release the bus
  164. release_bus(g);
  165. // Turn on the backlight
  166. set_backlight(g, GDISP_INITIAL_BACKLIGHT);
  167. /* Initialise the GDISP structure */
  168. g->g.Width = GDISP_SCREEN_WIDTH;
  169. g->g.Height = GDISP_SCREEN_HEIGHT;
  170. g->g.Orientation = GDISP_ROTATE_0;
  171. g->g.Powermode = powerOn;
  172. g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
  173. g->g.Contrast = GDISP_INITIAL_CONTRAST;
  174. return TRUE;
  175. }
  176. #if GDISP_HARDWARE_STREAM_WRITE
  177. LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
  178. acquire_bus(g);
  179. set_viewport(g);
  180. #if !GDISP_HARDWARE_STREAM_POS
  181. set_cursor(g);
  182. #endif
  183. }
  184. LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
  185. write_data(g, gdispColor2Native(g->p.color));
  186. }
  187. LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
  188. release_bus(g);
  189. }
  190. #if GDISP_HARDWARE_STREAM_POS
  191. LLDSPEC void gdisp_lld_write_pos(GDisplay *g) {
  192. set_cursor(g);
  193. }
  194. #endif
  195. #endif
  196. #if GDISP_HARDWARE_STREAM_READ
  197. LLDSPEC void gdisp_lld_read_start(GDisplay *g) {
  198. acquire_bus(g);
  199. set_viewport(g);
  200. set_cursor(g);
  201. setreadmode(g);
  202. dummy_read(g);
  203. }
  204. LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) {
  205. uint16_t data;
  206. data = read_data(g);
  207. return gdispNative2Color(data);
  208. }
  209. LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
  210. setwritemode(g);
  211. release_bus(g);
  212. }
  213. #endif
  214. #if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
  215. LLDSPEC void gdisp_lld_control(GDisplay *g) {
  216. switch(g->p.x) {
  217. case GDISP_CONTROL_POWER:
  218. if (g->g.Powermode == (powermode_t)g->p.ptr)
  219. return;
  220. switch((powermode_t)g->p.ptr) {
  221. case powerOff:
  222. acquire_bus(g);
  223. write_reg(g, 0x07, 0x0000);
  224. write_reg(g, 0x10, 0x0000);
  225. write_reg(g, 0x11, 0x0000);
  226. write_reg(g, 0x12, 0x0000);
  227. write_reg(g, 0x13, 0x0000);
  228. release_bus(g);
  229. set_backlight(g, 0);
  230. break;
  231. case powerOn:
  232. //*************Power On sequence ******************//
  233. acquire_bus(g);
  234. write_reg(g, 0x10, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  235. write_reg(g, 0x11, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
  236. write_reg(g, 0x12, 0x0000); /* VREG1OUT voltage */
  237. write_reg(g, 0x13, 0x0000); /* VDV[4:0] for VCOM amplitude */
  238. gfxSleepMicroseconds(2000); /* Dis-charge capacitor power voltage */
  239. write_reg(g, 0x10, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  240. write_reg(g, 0x11, 0x0147); /* DC1[2:0], DC0[2:0], VC[2:0] */
  241. gfxSleepMicroseconds(500);
  242. write_reg(g, 0x12, 0x013C); /* VREG1OUT voltage */
  243. gfxSleepMicroseconds(500);
  244. write_reg(g, 0x13, 0x0E00); /* VDV[4:0] for VCOM amplitude */
  245. write_reg(g, 0x29, 0x0009); /* VCM[4:0] for VCOMH */
  246. gfxSleepMicroseconds(500);
  247. write_reg(g, 0x07, 0x0173); /* 262K color and display ON */
  248. release_bus(g);
  249. set_backlight(g, g->g.Backlight);
  250. break;
  251. case powerSleep:
  252. acquire_bus(g);
  253. write_reg(g, 0x07, 0x0000); /* display OFF */
  254. write_reg(g, 0x10, 0x0000); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
  255. write_reg(g, 0x11, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
  256. write_reg(g, 0x12, 0x0000); /* VREG1OUT voltage */
  257. write_reg(g, 0x13, 0x0000); /* VDV[4:0] for VCOM amplitude */
  258. gfxSleepMicroseconds(2000); /* Dis-charge capacitor power voltage */
  259. write_reg(g, 0x10, 0x0002); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
  260. release_bus(g);
  261. set_backlight(g, 0);
  262. break;
  263. case powerDeepSleep:
  264. acquire_bus(g);
  265. write_reg(g, 0x07, 0x0000); /* display OFF */
  266. write_reg(g, 0x10, 0x0000); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
  267. write_reg(g, 0x11, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
  268. write_reg(g, 0x12, 0x0000); /* VREG1OUT voltage */
  269. write_reg(g, 0x13, 0x0000); /* VDV[4:0] for VCOM amplitude */
  270. gfxSleepMicroseconds(2000); /* Dis-charge capacitor power voltage */
  271. write_reg(g, 0x10, 0x0004); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
  272. release_bus(g);
  273. set_backlight(g, 0);
  274. break;
  275. default:
  276. return;
  277. }
  278. g->g.Powermode = (powermode_t)g->p.ptr;
  279. return;
  280. case GDISP_CONTROL_ORIENTATION:
  281. if (g->g.Orientation == (orientation_t)g->p.ptr)
  282. return;
  283. switch((orientation_t)g->p.ptr) {
  284. case GDISP_ROTATE_0:
  285. acquire_bus(g);
  286. write_reg(g, 0x01, 0x0100);
  287. write_reg(g, 0x03, 0x1038);
  288. write_reg(g, 0x60, 0x2700);
  289. release_bus(g);
  290. g->g.Height = GDISP_SCREEN_HEIGHT;
  291. g->g.Width = GDISP_SCREEN_WIDTH;
  292. break;
  293. case GDISP_ROTATE_90:
  294. acquire_bus(g);
  295. write_reg(g, 0x01, 0x0000);
  296. write_reg(g, 0x03, 0x1030);
  297. write_reg(g, 0x60, 0x2700);
  298. release_bus(g);
  299. g->g.Height = GDISP_SCREEN_WIDTH;
  300. g->g.Width = GDISP_SCREEN_HEIGHT;
  301. break;
  302. case GDISP_ROTATE_180:
  303. acquire_bus(g);
  304. write_reg(g, 0x01, 0x0000);
  305. write_reg(g, 0x03, 0x1030);
  306. write_reg(g, 0x60, 0x2700);
  307. release_bus(g);
  308. g->g.Height = GDISP_SCREEN_HEIGHT;
  309. g->g.Width = GDISP_SCREEN_WIDTH;
  310. break;
  311. case GDISP_ROTATE_270:
  312. acquire_bus(g);
  313. write_reg(g, 0x01, 0x0100);
  314. write_reg(g, 0x03, 0x1038);
  315. write_reg(g, 0x60, 0xA700);
  316. release_bus(g);
  317. g->g.Height = GDISP_SCREEN_WIDTH;
  318. g->g.Width = GDISP_SCREEN_HEIGHT;
  319. break;
  320. default:
  321. return;
  322. }
  323. g->g.Orientation = (orientation_t)g->p.ptr;
  324. return;
  325. case GDISP_CONTROL_BACKLIGHT:
  326. if ((unsigned)g->p.ptr > 100)
  327. g->p.ptr = (void *)100;
  328. set_backlight(g, (unsigned)g->p.ptr);
  329. g->g.Backlight = (unsigned)g->p.ptr;
  330. return;
  331. default:
  332. return;
  333. }
  334. }
  335. #endif
  336. #endif /* GFX_USE_GDISP */