µGFX library fork

gdisp_lld_Nokia6610GE12.c 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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_Nokia6610GE12
  19. #include "gdisp_lld_config.h"
  20. #include "../../../src/gdisp/gdisp_driver.h"
  21. #include "board_Nokia6610GE12.h"
  22. /*===========================================================================*/
  23. /* Driver local definitions. */
  24. /*===========================================================================*/
  25. #include "GE12.h"
  26. #define GDISP_SCAN_LINES 132
  27. #define GDISP_SLEEP_SIZE 32 /* Sleep mode window lines - this must be 32 on this controller */
  28. // Set parameters if they are not already set
  29. #ifndef GDISP_SCREEN_HEIGHT
  30. #define GDISP_SCREEN_HEIGHT 130
  31. #endif
  32. #ifndef GDISP_SCREEN_WIDTH
  33. #define GDISP_SCREEN_WIDTH 130
  34. #endif
  35. #ifndef GDISP_RAM_X_OFFSET
  36. #define GDISP_RAM_X_OFFSET 0 /* Offset in RAM of visible area */
  37. #endif
  38. #ifndef GDISP_RAM_Y_OFFSET
  39. #define GDISP_RAM_Y_OFFSET 2 /* Offset in RAM of visible area */
  40. #endif
  41. #ifndef GDISP_SLEEP_POS
  42. #define GDISP_SLEEP_POS ((GDISP_SCAN_LINES-GDISP_SLEEP_SIZE)/2 & ~3)
  43. #endif
  44. #ifndef GDISP_INITIAL_CONTRAST
  45. #define GDISP_INITIAL_CONTRAST 50
  46. #endif
  47. #ifndef GDISP_INITIAL_BACKLIGHT
  48. #define GDISP_INITIAL_BACKLIGHT 100
  49. #endif
  50. /*===========================================================================*/
  51. /* Driver exported variables. */
  52. /*===========================================================================*/
  53. /*===========================================================================*/
  54. /* Driver local variables. */
  55. /*===========================================================================*/
  56. // Use the priv pointer itself to save our color. This save allocating ram for it
  57. // and works provided sizeof(uint16_t) <= sizeof(void *)
  58. #define savecolor(g) (*(uint16_t *)&g->priv)
  59. #define GDISP_FLG_ODDBYTE (GDISP_FLG_DRIVER<<0)
  60. /*===========================================================================*/
  61. /* Driver local functions. */
  62. /*===========================================================================*/
  63. // Some macros just to make reading the code easier
  64. #define delayms(ms) gfxSleepMilliseconds(ms)
  65. #define write_data2(g, d1, d2) { write_data(g, d1); write_data(g, d2); }
  66. #define write_data3(g, d1, d2, d3) { write_data(g, d1); write_data(g, d2); write_data(g, d3); }
  67. #define write_reg(g, cmd, d1) { write_index(g, cmd); write_data(g, d1); }
  68. #define write_reg2(g, cmd, d1, d2) { write_index(g, cmd); write_data2(g, d1, d2); }
  69. #define write_reg3(g, cmd, d1, d2, d3) { write_index(g, cmd); write_data3(g, d1, d2, d3); }
  70. static GFXINLINE void set_viewport(GDisplay* g) {
  71. write_reg2(g, CASET, GDISP_RAM_X_OFFSET+g->p.x, GDISP_RAM_X_OFFSET+g->p.x+g->p.cx-1); // Column address set
  72. write_reg2(g, PASET, GDISP_RAM_Y_OFFSET+g->p.y, GDISP_RAM_Y_OFFSET+g->p.y+g->p.cy-1); // Page address set
  73. write_index(g, RAMWR);
  74. }
  75. /*===========================================================================*/
  76. /* Driver exported functions. */
  77. /*===========================================================================*/
  78. LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
  79. // No private area for this controller
  80. g->priv = 0;
  81. // Initialise the board interface
  82. init_board(g);
  83. // Hardware reset
  84. setpin_reset(g, TRUE);
  85. delayms(20);
  86. setpin_reset(g, FALSE);
  87. delayms(20);
  88. acquire_bus(g);
  89. write_index(g, SLEEPOUT); // Sleep out
  90. write_reg(g, COLMOD, 0x03); // Color Interface Pixel Format - 0x03 = 12 bits-per-pixel
  91. write_reg(g, MADCTL, 0x00); // Memory access controller
  92. write_reg(g, SETCON, 128*GDISP_INITIAL_CONTRAST/101-64); // Write contrast
  93. delayms(20);
  94. // Finish Init
  95. post_init_board(g);
  96. release_bus(g);
  97. /* Turn on the back-light */
  98. set_backlight(g, GDISP_INITIAL_BACKLIGHT);
  99. /* Initialise the GDISP structure to match */
  100. g->g.Width = GDISP_SCREEN_WIDTH;
  101. g->g.Height = GDISP_SCREEN_HEIGHT;
  102. g->g.Orientation = GDISP_ROTATE_0;
  103. g->g.Powermode = powerOn;
  104. g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
  105. g->g.Contrast = GDISP_INITIAL_CONTRAST;
  106. return TRUE;
  107. }
  108. #if GDISP_HARDWARE_STREAM_WRITE
  109. LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
  110. acquire_bus(g);
  111. set_viewport(g);
  112. g->flags &= ~GDISP_FLG_ODDBYTE;
  113. }
  114. LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
  115. uint16_t c;
  116. c = gdispColor2Native(g->p.color);
  117. if ((g->flags & GDISP_FLG_ODDBYTE)) {
  118. // Write the pair of pixels to the display
  119. write_data3(g, ((savecolor(g) >> 4) & 0xFF),
  120. (((savecolor(g) << 4) & 0xF0)|((c >> 8) & 0x0F)),
  121. (c & 0xFF));
  122. g->flags &= ~GDISP_FLG_ODDBYTE;
  123. } else {
  124. savecolor(g) = c;
  125. g->flags |= GDISP_FLG_ODDBYTE;
  126. }
  127. }
  128. LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
  129. if ((g->flags & GDISP_FLG_ODDBYTE)) {
  130. write_data2(g, ((savecolor(g) >> 4) & 0xFF), ((savecolor(g) << 4) & 0xF0));
  131. write_index(g, NOP);
  132. }
  133. release_bus(g);
  134. }
  135. #endif
  136. #if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
  137. LLDSPEC void gdisp_lld_control(GDisplay *g) {
  138. /* The hardware is capable of supporting...
  139. * GDISP_CONTROL_POWER - supported
  140. * GDISP_CONTROL_ORIENTATION - supported
  141. * GDISP_CONTROL_BACKLIGHT - supported
  142. * GDISP_CONTROL_CONTRAST - supported
  143. */
  144. switch(g->p.x) {
  145. case GDISP_CONTROL_POWER:
  146. if (g->g.Powermode == (powermode_t)g->p.ptr)
  147. return;
  148. switch((powermode_t)g->p.ptr) {
  149. case powerOff:
  150. acquire_bus(g);
  151. write_index(g, SLEEPIN);
  152. release_bus(g);
  153. break;
  154. case powerOn:
  155. acquire_bus(g);
  156. write_index(g, SLEEPOUT);
  157. delayms(20);
  158. write_index(g, NORON); // Set Normal mode (my)
  159. release_bus(g);
  160. break;
  161. case powerSleep:
  162. acquire_bus(g);
  163. write_index(g, SLEEPOUT);
  164. delayms(20);
  165. write_reg2(g, PTLAR, GDISP_SLEEP_POS, GDISP_SLEEP_POS+GDISP_SLEEP_SIZE)
  166. write_index(g, PTLON);
  167. release_bus(g);
  168. break;
  169. default:
  170. return;
  171. }
  172. g->g.Powermode = (powermode_t)g->p.ptr;
  173. return;
  174. case GDISP_CONTROL_ORIENTATION:
  175. if (g->g.Orientation == (orientation_t)g->p.ptr)
  176. return;
  177. switch((orientation_t)g->p.ptr) {
  178. case GDISP_ROTATE_0:
  179. acquire_bus(g);
  180. write_reg(g, MADCTL, 0x00);
  181. release_bus(g);
  182. g->g.Height = GDISP_SCREEN_HEIGHT;
  183. g->g.Width = GDISP_SCREEN_WIDTH;
  184. break;
  185. case GDISP_ROTATE_90:
  186. acquire_bus(g);
  187. write_reg(g, MADCTL, 0xA0); // MY, MX, V, LAO, RGB, X, X, X
  188. release_bus(g);
  189. g->g.Height = GDISP_SCREEN_WIDTH;
  190. g->g.Width = GDISP_SCREEN_HEIGHT;
  191. break;
  192. case GDISP_ROTATE_180:
  193. acquire_bus(g);
  194. write_reg(g, MADCTL, 0xC0);
  195. release_bus(g);
  196. g->g.Height = GDISP_SCREEN_HEIGHT;
  197. g->g.Width = GDISP_SCREEN_WIDTH;
  198. break;
  199. case GDISP_ROTATE_270:
  200. acquire_bus(g);
  201. write_reg(g, MADCTL, 0x60);
  202. release_bus(g);
  203. g->g.Height = GDISP_SCREEN_WIDTH;
  204. g->g.Width = GDISP_SCREEN_HEIGHT;
  205. break;
  206. default:
  207. return;
  208. }
  209. g->g.Orientation = (orientation_t)g->p.ptr;
  210. return;
  211. case GDISP_CONTROL_BACKLIGHT:
  212. if ((unsigned)g->p.ptr > 100) g->p.ptr = (void *)100;
  213. set_backlight(g, (unsigned)g->p.ptr);
  214. g->g.Backlight = (unsigned)g->p.ptr;
  215. return;
  216. case GDISP_CONTROL_CONTRAST:
  217. if ((unsigned)g->p.ptr > 100) g->p.ptr = (void *)100;
  218. acquire_bus(g);
  219. write_reg(g, SETCON,(unsigned)128*(unsigned)g->p.ptr/101-64);
  220. release_bus(g);
  221. g->g.Contrast = (unsigned)g->p.ptr;
  222. return;
  223. }
  224. }
  225. #endif
  226. #endif /* GFX_USE_GDISP */