u8x8_d_gp1287ai.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. u8x8_d_gp1287ai.c
  3. https://github.com/olikraus/u8g2/issues/1907
  4. https://github.com/olikraus/u8g2/pull/1892
  5. Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
  6. Copyright (c) 2022, olikraus@gmail.com
  7. All rights reserved.
  8. Redistribution and use in source and binary forms, with or without modification,
  9. are permitted provided that the following conditions are met:
  10. * Redistributions of source code must retain the above copyright notice, this list
  11. of conditions and the following disclaimer.
  12. * Redistributions in binary form must reproduce the above copyright notice, this
  13. list of conditions and the following disclaimer in the documentation and/or other
  14. materials provided with the distribution.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  16. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  17. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  20. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  21. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  25. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  27. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #include "u8x8.h"
  30. #define SWAP8(a) ((((a)&0x80) >> 7) | (((a)&0x40) >> 5) | (((a)&0x20) >> 3) | (((a)&0x10) >> 1) | (((a)&0x08) << 1) | (((a)&0x04) << 3) | (((a)&0x02) << 5) | (((a)&0x01) << 7))
  31. /* ========== GP1287AI ========== */
  32. static const u8x8_display_info_t u8x8_gp1287ai_display_info = {
  33. /* chip_enable_level = */ 0,
  34. /* chip_disable_level = */ 1,
  35. /* post_chip_enable_wait_ns = */ 240, /* tCS-CLK */
  36. /* pre_chip_disable_wait_ns = */ 120, /* tCLK-CS */
  37. /* reset_pulse_width_ms = */ 1, /* Trw */
  38. /* post_reset_wait_ms = */ 1, /* Trth */
  39. /* sda_setup_time_ns = */ 60, /* tsu */
  40. /* sck_pulse_width_ns = */ 120, /* tcyc/2 */
  41. /* sck_clock_hz = */ 4000000UL, /* MAX 4.16 MHz */
  42. /* spi_mode = */ 3, /* active low, falling edge, MSBFIRST */
  43. /* i2c_bus_clock_100kHz = */ 4, /* */
  44. /* data_setup_time_ns = */ 60, /* tsu */
  45. /* write_pulse_width_ns = */ 120, /* tcyc/2 */
  46. /* tile_width = */ 32, /* 32*8=256 memory size */
  47. /* tile_height = */ 7, /* 7*8=56 memory size */
  48. /* default_x_offset = */ 0, /* */
  49. /* flipmode_x_offset = */ 0, /* */
  50. /* pixel_width = */ 256, /* display size */
  51. /* pixel_height = */ 50 /* display size */
  52. };
  53. static const uint8_t u8x8_d_gp1287ai_init_seq[] = {
  54. U8X8_START_TRANSFER(),
  55. U8X8_C(SWAP8(0x0AA)), /* Software reset */
  56. U8X8_END_TRANSFER(),
  57. U8X8_DLY(1), /* Wait for reset */
  58. U8X8_START_TRANSFER(),
  59. U8X8_CA(SWAP8(0x078), SWAP8(0x008)), /* Oscillation Setting */
  60. U8X8_END_TRANSFER(),
  61. U8X8_START_TRANSFER(),
  62. U8X8_CAA(SWAP8(0x0CC), SWAP8(0x002), SWAP8(0x000)), /* VFD Mode Setting */
  63. U8X8_END_TRANSFER(),
  64. U8X8_START_TRANSFER(),
  65. U8X8_CAAA(SWAP8(0x0E0), SWAP8(0x0FF), SWAP8(0x031), SWAP8(0x000)), /* Display Area Setting */
  66. U8X8_A4(SWAP8(0x020), SWAP8(0x000), SWAP8(0x000), SWAP8(0x080)), /* Display Area Setting */
  67. U8X8_END_TRANSFER(),
  68. U8X8_START_TRANSFER(),
  69. U8X8_CAAAA(SWAP8(0x0B1), SWAP8(0x020), SWAP8(0x03F), SWAP8(0x000), SWAP8(0x001)), /* Internal Speed Setting */
  70. U8X8_END_TRANSFER(),
  71. U8X8_START_TRANSFER(),
  72. U8X8_CAA(SWAP8(0x0A0), SWAP8(0x000), SWAP8(0x028)), /* Dimming level Setting (1024 level, 0x3FF max) */
  73. U8X8_END_TRANSFER(),
  74. U8X8_START_TRANSFER(),
  75. U8X8_C(SWAP8(0x055)), /* Memory Map Clear */
  76. U8X8_END_TRANSFER(),
  77. U8X8_DLY(15), /* Waiting for memory clear */
  78. U8X8_START_TRANSFER(),
  79. U8X8_CAA(SWAP8(0x0C0), SWAP8(0x000), SWAP8(0x004)), /* DW1 position setting */
  80. U8X8_END_TRANSFER(),
  81. U8X8_START_TRANSFER(),
  82. U8X8_CAA(SWAP8(0x0D0), SWAP8(0x000), SWAP8(0x03C)), /* DW2 position setting */
  83. U8X8_END_TRANSFER(),
  84. U8X8_START_TRANSFER(),
  85. U8X8_CA(SWAP8(0x090), SWAP8(0x000)), /* Internal Command */
  86. U8X8_END_TRANSFER(),
  87. U8X8_START_TRANSFER(),
  88. U8X8_CA(SWAP8(0x008), SWAP8(0x000)), /* T1 INT Setting */
  89. U8X8_END_TRANSFER(),
  90. U8X8_START_TRANSFER(),
  91. U8X8_CA(SWAP8(0x080), SWAP8(0x000)), /* Display Mode Setting */
  92. U8X8_END_TRANSFER(),
  93. U8X8_START_TRANSFER(),
  94. U8X8_C(SWAP8(0x061)), /* Standby Mode */
  95. U8X8_END_TRANSFER(),
  96. U8X8_END() /* end of sequence */
  97. };
  98. static const uint8_t u8x8_d_gp1287ai_standby_seq[] = {
  99. U8X8_START_TRANSFER(),
  100. U8X8_C(SWAP8(0x061)), /* Standby */
  101. U8X8_END_TRANSFER(),
  102. U8X8_END() /* end of sequence */
  103. };
  104. static const uint8_t u8x8_d_gp1287ai_wakeup_seq[] = {
  105. U8X8_START_TRANSFER(),
  106. U8X8_C(SWAP8(0x06D)), /* Wake up */
  107. U8X8_END_TRANSFER(),
  108. U8X8_DLY(1), /* Wait for OSC stabilize */
  109. U8X8_START_TRANSFER(),
  110. U8X8_CA(SWAP8(0x080), SWAP8(0x000)), /* After entering standby mode, the SC bit will be automatically cleared */
  111. U8X8_END_TRANSFER(),
  112. U8X8_END() /* end of sequence */
  113. };
  114. uint8_t u8x8_d_gp1287ai_common(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  115. {
  116. uint8_t *ptr;
  117. uint8_t x, y;
  118. uint16_t tx_cnt;
  119. uint8_t swapped_byte;
  120. switch (msg)
  121. {
  122. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  123. if (arg_int == 0)
  124. u8x8_cad_SendSequence(u8x8, u8x8_d_gp1287ai_wakeup_seq);
  125. else
  126. u8x8_cad_SendSequence(u8x8, u8x8_d_gp1287ai_standby_seq);
  127. break;
  128. #ifdef U8X8_WITH_SET_CONTRAST
  129. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  130. u8x8_cad_StartTransfer(u8x8);
  131. u8x8_cad_SendCmd(u8x8, SWAP8(0x0A0));
  132. u8x8_cad_SendArg(u8x8, SWAP8((arg_int * 4) >> 8)); /* Dimming level */
  133. u8x8_cad_SendArg(u8x8, SWAP8((arg_int * 4) & 0xFF)); /* Dimming level */
  134. u8x8_cad_EndTransfer(u8x8);
  135. break;
  136. #endif
  137. case U8X8_MSG_DISPLAY_DRAW_TILE:
  138. x = ((u8x8_tile_t *)arg_ptr)->x_pos * 8;
  139. y = ((u8x8_tile_t *)arg_ptr)->y_pos * 8 + 4;
  140. u8x8_cad_StartTransfer(u8x8);
  141. u8x8_cad_SendCmd(u8x8, SWAP8(0x0F0));
  142. u8x8_cad_SendArg(u8x8, SWAP8(x));
  143. u8x8_cad_SendArg(u8x8, SWAP8(y));
  144. u8x8_cad_SendArg(u8x8, SWAP8(0x007)); /* return every 8 pixels */
  145. do
  146. {
  147. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  148. tx_cnt = ((u8x8_tile_t *)arg_ptr)->cnt * 8;
  149. while (tx_cnt > 0)
  150. {
  151. swapped_byte = SWAP8(*ptr);
  152. u8x8_cad_SendData(u8x8, 1, &swapped_byte);
  153. ptr += 1;
  154. tx_cnt -= 1;
  155. }
  156. arg_int--;
  157. } while (arg_int > 0);
  158. u8x8_cad_EndTransfer(u8x8);
  159. break;
  160. default:
  161. return 0;
  162. }
  163. return 1;
  164. }
  165. uint8_t u8x8_d_gp1287ai_256x50(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  166. {
  167. switch (msg)
  168. {
  169. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  170. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_gp1287ai_display_info);
  171. break;
  172. case U8X8_MSG_DISPLAY_INIT:
  173. u8x8_d_helper_display_init(u8x8);
  174. u8x8_cad_SendSequence(u8x8, u8x8_d_gp1287ai_init_seq);
  175. break;
  176. default:
  177. return u8x8_d_gp1287ai_common(u8x8, msg, arg_int, arg_ptr);
  178. }
  179. return 1;
  180. }