µGFX library fork

gdisp_lld_SPFD54124B.c 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. /*
  8. * Driver for display from Nokia 1616 phone
  9. * based on the work of axillent@gmail.com (http://radiokot.ru/articles/53/)
  10. * adapted by shilow@ukr.net with the help of Federico Reds <fede.677387@hotmail.it>
  11. */
  12. #include "gfx.h"
  13. #if GFX_USE_GDISP
  14. #if defined(GDISP_SCREEN_HEIGHT) || defined(GDISP_SCREEN_HEIGHT)
  15. #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT
  16. #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
  17. #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO
  18. COMPILER_WARNING("GDISP: This low level driver does not support setting a screen size. It is being ignored.")
  19. #endif
  20. #undef GDISP_SCREEN_WIDTH
  21. #undef GDISP_SCREEN_HEIGHT
  22. #endif
  23. #include "gdisp_lld_config.h"
  24. #include "../../../src/gdisp/gdisp_driver.h"
  25. #include "board_SPFD54124B.h"
  26. /*===========================================================================*/
  27. /* Driver local definitions. */
  28. /*===========================================================================*/
  29. // Set parameters if they are not already set
  30. #ifndef GDISP_SCREEN_HEIGHT
  31. #define GDISP_SCREEN_HEIGHT 161
  32. #endif
  33. #ifndef GDISP_SCREEN_WIDTH
  34. #define GDISP_SCREEN_WIDTH 129
  35. #endif
  36. /* Offset in RAM of visible area */
  37. #ifndef GDISP_RAM_X_OFFSET
  38. #define GDISP_RAM_X_OFFSET 2
  39. #endif
  40. /* Offset in RAM of visible area */
  41. #ifndef GDISP_RAM_Y_OFFSET
  42. #define GDISP_RAM_Y_OFFSET 1
  43. #endif
  44. #ifndef GDISP_SLEEP_POS
  45. #define GDISP_SLEEP_POS ((GDISP_SCAN_LINES-GDISP_SLEEP_SIZE)/2 & ~3)
  46. #endif
  47. #ifndef GDISP_INITIAL_CONTRAST
  48. #define GDISP_INITIAL_CONTRAST 50
  49. #endif
  50. #ifndef GDISP_INITIAL_BACKLIGHT
  51. #define GDISP_INITIAL_BACKLIGHT 100
  52. #endif
  53. /*===========================================================================*/
  54. /* Driver exported variables. */
  55. /*===========================================================================*/
  56. /*===========================================================================*/
  57. /* Driver local variables. */
  58. /*===========================================================================*/
  59. // Use the priv pointer itself to save our color. This save allocating ram for it
  60. // and works provided sizeof(uint16_t) <= sizeof(void *)
  61. #define savecolor(g) (*(uint16_t *)&g->priv)
  62. /*===========================================================================*/
  63. /* Driver local functions. */
  64. /*===========================================================================*/
  65. // Some macros just to make reading the code easier
  66. #define delayms(ms) gfxSleepMilliseconds(ms)
  67. #define write_data2(g, d1, d2) { write_data(g, d1); write_data(g, d2); }
  68. #define write_data3(g, d1, d2, d3) { write_data(g, d1); write_data(g, d2); write_data(g, d3); }
  69. #define write_reg(g, cmd, d1) { write_index(g, cmd); write_data(g, d1); }
  70. #define write_reg2(g, cmd, d1, d2) { write_index(g, cmd); write_data2(g, d1, d2); }
  71. #define write_reg3(g, cmd, d1, d2, d3) { write_index(g, cmd); write_data3(g, d1, d2, d3); }
  72. static GFXINLINE void set_viewport(GDisplay* g)
  73. {
  74. write_reg2(g, SPFD54124B_CMD_CASET, GDISP_RAM_X_OFFSET+g->p.x, GDISP_RAM_X_OFFSET+g->p.x+g->p.cx-1); // Column address set
  75. write_reg2(g, SPFD54124B_CMD_RASET, GDISP_RAM_Y_OFFSET+g->p.y, GDISP_RAM_Y_OFFSET+g->p.y+g->p.cy-1); // Page address set
  76. write_index(g, SPFD54124B_CMD_RAMWR);
  77. }
  78. /*===========================================================================*/
  79. /* Driver exported functions. */
  80. /*===========================================================================*/
  81. const uint16_t lcd_init_list[] = {
  82. SPFD54124B_CMD_SLPOUT,
  83. SPFD54124B_CMD_COLMOD, SPFD54124B_SEND_DATA | SPFD54124B_CMD_COLMOD_MCU16bit,
  84. SPFD54124B_CMD_DISPON,
  85. SPFD54124B_CMD_INVOFF,
  86. SPFD54124B_CMD_NORON
  87. };
  88. LLDSPEC bool_t gdisp_lld_init(GDisplay *g)
  89. {
  90. // No private area for this controller
  91. g->priv = 0;
  92. // Initialise the board interface
  93. init_board(g);
  94. // Hardware reset
  95. setpin_reset(g, TRUE);
  96. delayms(100);
  97. setpin_reset(g, FALSE);
  98. delayms(100);
  99. acquire_bus(g);
  100. const uint16_t *list = &lcd_init_list[0];
  101. uint8_t size = sizeof(lcd_init_list) / sizeof(lcd_init_list[0]);
  102. while(size--) {
  103. write_index(g, *list++);
  104. }
  105. // Finish Init
  106. post_init_board(g);
  107. release_bus(g);
  108. // Turn on the back-light
  109. set_backlight(g, GDISP_INITIAL_BACKLIGHT);
  110. // Initialise the GDISP structure to match
  111. g->g.Width = GDISP_SCREEN_WIDTH;
  112. g->g.Height = GDISP_SCREEN_HEIGHT;
  113. g->g.Orientation = GDISP_ROTATE_0;
  114. g->g.Powermode = powerOn;
  115. g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
  116. g->g.Contrast = GDISP_INITIAL_CONTRAST;
  117. return TRUE;
  118. }
  119. #if GDISP_HARDWARE_STREAM_WRITE
  120. LLDSPEC void gdisp_lld_write_start(GDisplay *g)
  121. {
  122. acquire_bus(g);
  123. set_viewport(g);
  124. }
  125. LLDSPEC void gdisp_lld_write_color(GDisplay *g)
  126. {
  127. write_data(g, gdispColor2Native(g->p.color));
  128. }
  129. LLDSPEC void gdisp_lld_write_stop(GDisplay *g)
  130. {
  131. release_bus(g);
  132. }
  133. #endif
  134. #if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
  135. LLDSPEC void gdisp_lld_control(GDisplay *g)
  136. {
  137. /* The hardware is capable of supporting...
  138. * GDISP_CONTROL_POWER - supported
  139. * GDISP_CONTROL_ORIENTATION - supported
  140. * GDISP_CONTROL_BACKLIGHT - unsupported
  141. * GDISP_CONTROL_CONTRAST - unsupported
  142. */
  143. switch(g->p.x) {
  144. case GDISP_CONTROL_POWER:
  145. if (g->g.Powermode == (powermode_t)g->p.ptr)
  146. return;
  147. switch((powermode_t)g->p.ptr) {
  148. case powerOff:
  149. acquire_bus(g);
  150. write_index(g, SPFD54124B_CMD_SLPIN);
  151. release_bus(g);
  152. break;
  153. case powerOn:
  154. acquire_bus(g);
  155. write_index(g, SPFD54124B_CMD_SLPOUT);
  156. delayms(20);
  157. write_index(g, SPFD54124B_CMD_NORON);
  158. release_bus(g);
  159. break;
  160. case powerSleep:
  161. acquire_bus(g);
  162. write_index(g, SPFD54124B_CMD_SLPOUT);
  163. delayms(20);
  164. release_bus(g);
  165. break;
  166. default:
  167. return;
  168. }
  169. g->g.Powermode = (powermode_t)g->p.ptr;
  170. return;
  171. case GDISP_CONTROL_ORIENTATION:
  172. if (g->g.Orientation == (orientation_t)g->p.ptr)
  173. return;
  174. switch((orientation_t)g->p.ptr) {
  175. case GDISP_ROTATE_0:
  176. acquire_bus(g);
  177. write_index(g, SPFD54124B_CMD_MADCTR);
  178. write_index(g, 0x0100);
  179. release_bus(g);
  180. g->g.Height = GDISP_SCREEN_HEIGHT;
  181. g->g.Width = GDISP_SCREEN_WIDTH;
  182. break;
  183. case GDISP_ROTATE_90:
  184. acquire_bus(g);
  185. write_index(g, SPFD54124B_CMD_MADCTR);
  186. write_index(g, 0x01A0);
  187. release_bus(g);
  188. g->g.Height = GDISP_SCREEN_WIDTH;
  189. g->g.Width = GDISP_SCREEN_HEIGHT;
  190. break;
  191. case GDISP_ROTATE_180:
  192. acquire_bus(g);
  193. write_index(g, SPFD54124B_CMD_MADCTR);
  194. write_index(g, 0x01C0);
  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_index(g, SPFD54124B_CMD_MADCTR);
  202. write_index(g, 0x0160);
  203. release_bus(g);
  204. g->g.Height = GDISP_SCREEN_WIDTH;
  205. g->g.Width = GDISP_SCREEN_HEIGHT;
  206. break;
  207. default:
  208. // GDISP_ROTATE_PORTRAIT and GDISP_ROTATE_LANDSCAPE are handled by the higher level code
  209. return;
  210. }
  211. g->g.Orientation = (orientation_t)g->p.ptr;
  212. return;
  213. }
  214. }
  215. #endif
  216. #endif /* GFX_USE_GDISP */