µGFX library fork

gdisp_lld_S6D1121.c 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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_S6D1121
  19. #include "gdisp_lld_config.h"
  20. #include "../../../src/gdisp/gdisp_driver.h"
  21. #include "board_S6D1121.h"
  22. /*===========================================================================*/
  23. /* Driver local definitions. */
  24. /*===========================================================================*/
  25. #ifndef GDISP_SCREEN_HEIGHT
  26. #define GDISP_SCREEN_HEIGHT 320
  27. #endif
  28. #ifndef GDISP_SCREEN_WIDTH
  29. #define GDISP_SCREEN_WIDTH 240
  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 definitions. */
  39. /*===========================================================================*/
  40. /* Some common routines and macros */
  41. #define dummy_read(g) { volatile uint16_t dummy; dummy = read_data(g); (void) dummy; }
  42. #define write_reg(g, reg, data) { write_index(g, reg); write_data(g, data); }
  43. #define delay(us) gfxSleepMicroseconds(us)
  44. #define delayms(ms) gfxSleepMilliseconds(ms)
  45. static GFXINLINE void set_cursor(GDisplay *g) {
  46. /* R20h - 8 bit
  47. * R21h - 9 bit
  48. */
  49. switch(g->g.Orientation) {
  50. default:
  51. case GDISP_ROTATE_0:
  52. write_reg(g, 0x20, g->p.x & 0x00FF);
  53. write_reg(g, 0x21, g->p.y & 0x01FF);
  54. break;
  55. case GDISP_ROTATE_90:
  56. write_reg(g, 0x20, g->p.y & 0x00FF);
  57. write_reg(g, 0x21, (GDISP_SCREEN_HEIGHT - 1 - g->p.x) & 0x01FF);
  58. break;
  59. case GDISP_ROTATE_180:
  60. write_reg(g, 0x20, (GDISP_SCREEN_WIDTH - 1 - g->p.x) & 0x00FF);
  61. write_reg(g, 0x21, (GDISP_SCREEN_HEIGHT - 1 - g->p.y) & 0x01FF);
  62. break;
  63. case GDISP_ROTATE_270:
  64. write_reg(g, 0x20, (GDISP_SCREEN_WIDTH - 1 - g->p.y) & 0x00FF);
  65. write_reg(g, 0x21, g->p.x & 0x01FF);
  66. break;
  67. }
  68. write_index(g, 0x22);
  69. }
  70. static GFXINLINE void set_viewport(GDisplay *g) {
  71. /* HSA / HEA are 8 bit
  72. * VSA / VEA are 9 bit
  73. * use masks 0x00FF and 0x01FF to enforce this
  74. */
  75. switch(g->g.Orientation) {
  76. default:
  77. case GDISP_ROTATE_0:
  78. write_reg(g, 0x46, (((g->p.x + g->p.cx - 1) << 8) & 0xFF00 ) | (g->p.x & 0x00FF));
  79. write_reg(g, 0x48, g->p.y & 0x01FF);
  80. write_reg(g, 0x47, (g->p.y + g->p.cy - 1) & 0x01FF);
  81. break;
  82. case GDISP_ROTATE_90:
  83. write_reg(g, 0x46, (((g->p.y + g->p.cy - 1) << 8) & 0xFF00) | (g->p.y & 0x00FF));
  84. write_reg(g, 0x48, (GDISP_SCREEN_HEIGHT - (g->p.x + g->p.cx)) & 0x01FF);
  85. write_reg(g, 0x47, (GDISP_SCREEN_HEIGHT-1 - g->p.x) & 0x01FF);
  86. break;
  87. case GDISP_ROTATE_180:
  88. write_reg(g, 0x46, (((GDISP_SCREEN_WIDTH-1 - g->p.x) & 0x00FF) << 8) |
  89. ((GDISP_SCREEN_WIDTH - (g->p.x + g->p.cx)) & 0x00FF));
  90. write_reg(g, 0x48, (GDISP_SCREEN_HEIGHT - (g->p.y + g->p.cy)) & 0x01FF);
  91. write_reg(g, 0x47, (GDISP_SCREEN_HEIGHT-1 - g->p.y) & 0x01FF);
  92. break;
  93. case GDISP_ROTATE_270:
  94. write_reg(g, 0x46, (((GDISP_SCREEN_WIDTH-1 - g->p.y) & 0x00FF) << 8) |
  95. ((GDISP_SCREEN_WIDTH - (g->p.y + g->p.cy)) & 0x00FF));
  96. write_reg(g, 0x48, g->p.x & 0x01FF);
  97. write_reg(g, 0x47, (g->p.x + g->p.cx - 1) & 0x01FF);
  98. break;
  99. }
  100. }
  101. LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
  102. // No private area for this controller
  103. g->priv = 0;
  104. // Initialise the board interface
  105. init_board(g);
  106. /* Hardware reset */
  107. setpin_reset(g, TRUE);
  108. delayms(20);
  109. setpin_reset(g, TRUE);
  110. delayms(20);
  111. /* Get the bus for the following initialisation commands */
  112. acquire_bus(g);
  113. write_reg(g, 0x11, 0x2004);
  114. write_reg(g, 0x13, 0xCC00);
  115. write_reg(g, 0x15, 0x2600);
  116. write_reg(g, 0x14, 0x252A);
  117. write_reg(g, 0x12, 0x0033);
  118. write_reg(g, 0x13, 0xCC04);
  119. delayms(1);
  120. write_reg(g, 0x13, 0xCC06);
  121. delayms(1);
  122. write_reg(g, 0x13, 0xCC4F);
  123. delayms(1);
  124. write_reg(g, 0x13, 0x674F);
  125. write_reg(g, 0x11, 0x2003);
  126. delayms(1);
  127. // Gamma Setting
  128. write_reg(g, 0x30, 0x2609);
  129. write_reg(g, 0x31, 0x242C);
  130. write_reg(g, 0x32, 0x1F23);
  131. write_reg(g, 0x33, 0x2425);
  132. write_reg(g, 0x34, 0x2226);
  133. write_reg(g, 0x35, 0x2523);
  134. write_reg(g, 0x36, 0x1C1A);
  135. write_reg(g, 0x37, 0x131D);
  136. write_reg(g, 0x38, 0x0B11);
  137. write_reg(g, 0x39, 0x1210);
  138. write_reg(g, 0x3A, 0x1315);
  139. write_reg(g, 0x3B, 0x3619);
  140. write_reg(g, 0x3C, 0x0D00);
  141. write_reg(g, 0x3D, 0x000D);
  142. write_reg(g, 0x16, 0x0007);
  143. write_reg(g, 0x02, 0x0013);
  144. write_reg(g, 0x03, 0x0003);
  145. write_reg(g, 0x01, 0x0127);
  146. delayms(1);
  147. write_reg(g, 0x08, 0x0303);
  148. write_reg(g, 0x0A, 0x000B);
  149. write_reg(g, 0x0B, 0x0003);
  150. write_reg(g, 0x0C, 0x0000);
  151. write_reg(g, 0x41, 0x0000);
  152. write_reg(g, 0x50, 0x0000);
  153. write_reg(g, 0x60, 0x0005);
  154. write_reg(g, 0x70, 0x000B);
  155. write_reg(g, 0x71, 0x0000);
  156. write_reg(g, 0x78, 0x0000);
  157. write_reg(g, 0x7A, 0x0000);
  158. write_reg(g, 0x79, 0x0007);
  159. write_reg(g, 0x07, 0x0051);
  160. delayms(1);
  161. write_reg(g, 0x07,0x0053);
  162. write_reg(g, 0x79,0x0000);
  163. // Finish Init
  164. post_init_board(g);
  165. // Release the bus
  166. release_bus(g);
  167. /* Turn on the back-light */
  168. set_backlight(g, GDISP_INITIAL_BACKLIGHT);
  169. /* Initialise the GDISP structure */
  170. g->g.Width = GDISP_SCREEN_WIDTH;
  171. g->g.Height = GDISP_SCREEN_HEIGHT;
  172. g->g.Orientation = GDISP_ROTATE_0;
  173. g->g.Powermode = powerOn;
  174. g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
  175. g->g.Contrast = GDISP_INITIAL_CONTRAST;
  176. return TRUE;
  177. }
  178. #if GDISP_HARDWARE_STREAM_WRITE
  179. LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
  180. acquire_bus(g);
  181. set_viewport(g);
  182. }
  183. LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
  184. write_data(g, gdispColor2Native(g->p.color));
  185. }
  186. LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
  187. release_bus(g);
  188. }
  189. LLDSPEC void gdisp_lld_write_pos(GDisplay *g) {
  190. set_cursor(g);
  191. }
  192. #endif
  193. #if GDISP_HARDWARE_STREAM_READ
  194. LLDSPEC void gdisp_lld_read_start(GDisplay *g) {
  195. acquire_bus(g);
  196. set_viewport(g);
  197. set_cursor(g);
  198. setreadmode(g);
  199. dummy_read(g);
  200. }
  201. LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) {
  202. uint16_t data;
  203. data = read_data(g);
  204. return gdispNative2Color(data);
  205. }
  206. LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
  207. setwritemode(g);
  208. release_bus(g);
  209. }
  210. #endif
  211. #if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
  212. LLDSPEC void gdisp_lld_control(GDisplay *g) {
  213. switch(g->p.x) {
  214. #if 0
  215. case GDISP_CONTROL_POWER:
  216. if (g->g.Powermode == (powermode_t)g->p.ptr)
  217. return;
  218. switch((powermode_t)g->p.ptr) {
  219. case powerOff:
  220. acquire_bus(g);
  221. // TODO
  222. release_bus(g);
  223. break;
  224. case powerOn:
  225. acquire_bus(g);
  226. // TODO
  227. release_bus(g);
  228. break;
  229. case powerSleep:
  230. acquire_bus(g);
  231. // TODO
  232. release_bus(g);
  233. break;
  234. default:
  235. return;
  236. }
  237. g->g.Powermode = (powermode_t)g->p.ptr;
  238. return;
  239. #endif
  240. case GDISP_CONTROL_ORIENTATION:
  241. if (g->g.Orientation == (orientation_t)g->p.ptr)
  242. return;
  243. switch((orientation_t)g->p.ptr) {
  244. case GDISP_ROTATE_0:
  245. acquire_bus(g);
  246. write_reg(g, 0x03, 0b0011);
  247. release_bus(g);
  248. g->g.Height = GDISP_SCREEN_HEIGHT;
  249. g->g.Width = GDISP_SCREEN_WIDTH;
  250. break;
  251. case GDISP_ROTATE_90:
  252. acquire_bus(g);
  253. write_reg(g, 0x03, 0b1001);
  254. release_bus(g);
  255. g->g.Height = GDISP_SCREEN_WIDTH;
  256. g->g.Width = GDISP_SCREEN_HEIGHT;
  257. break;
  258. case GDISP_ROTATE_180:
  259. acquire_bus(g);
  260. write_reg(g, 0x03, 0b0000);
  261. release_bus(g);
  262. g->g.Height = GDISP_SCREEN_HEIGHT;
  263. g->g.Width = GDISP_SCREEN_WIDTH;
  264. break;
  265. case GDISP_ROTATE_270:
  266. acquire_bus(g);
  267. write_reg(g, 0x03, 0b1010);
  268. release_bus(g);
  269. g->g.Height = GDISP_SCREEN_WIDTH;
  270. g->g.Width = GDISP_SCREEN_HEIGHT;
  271. break;
  272. default:
  273. return;
  274. }
  275. g->g.Orientation = (orientation_t)g->p.ptr;
  276. return;
  277. case GDISP_CONTROL_BACKLIGHT:
  278. if ((unsigned)g->p.ptr > 100)
  279. g->p.ptr = (void *)100;
  280. set_backlight(g, (unsigned)g->p.ptr);
  281. g->g.Backlight = (unsigned)g->p.ptr;
  282. return;
  283. //case GDISP_CONTROL_CONTRAST:
  284. default:
  285. return;
  286. }
  287. }
  288. #endif
  289. #endif /* GFX_USE_GDISP */