u8x8_d_gu800.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /*
  2. u8x8_d_gu800.c
  3. Support for GU800 series of VFD displays
  4. https://www.noritake-elec.com/products/vfd-display-module/dot-matrix-graphic-display/gu-800-series
  5. Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
  6. Copyright (c) 2021, 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. u8x8_gu800_cad_110
  29. WARNING: DO NOT USE THIS FILE AS TEMPLATE:
  30. This code requires a special cad callback which includes the start
  31. and end transfer code. As a consequence this code does not include any
  32. start / end transfer calls.
  33. */
  34. #include "u8x8.h"
  35. static const uint8_t u8x8_d_gu800_128x64_powersave0_seq[] = {
  36. U8X8_CA(0x024, 0x040), /* Byte 1: Layer 0010xx00, Byte 2: 0x40 (graphics on, normal mode, no or/xor) */
  37. U8X8_END() /* end of sequence */
  38. };
  39. static const uint8_t u8x8_d_gu800_128x64_powersave1_seq[] = {
  40. U8X8_CA(0x020, 0x040), /* Byte 1: Layer 0010xx00, Byte 2: 0x40 (graphics on, normal mode, no or/xor) */
  41. U8X8_END() /* end of sequence */
  42. };
  43. /* hardware flip is not supported by GU800 */
  44. #ifdef NOT_SUPPORTED
  45. static const uint8_t u8x8_d_gu800_128x64_flip0_seq[] = {
  46. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  47. U8X8_END_TRANSFER(), /* disable chip */
  48. U8X8_END() /* end of sequence */
  49. };
  50. static const uint8_t u8x8_d_gu800_128x64_flip1_seq[] = {
  51. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  52. U8X8_END_TRANSFER(), /* disable chip */
  53. U8X8_END() /* end of sequence */
  54. };
  55. #endif
  56. uint8_t u8x8_d_gu800_common(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  57. {
  58. uint8_t x, c;
  59. uint8_t *ptr;
  60. switch(msg)
  61. {
  62. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  63. if ( arg_int == 0 )
  64. u8x8_cad_SendSequence(u8x8, u8x8_d_gu800_128x64_powersave0_seq);
  65. else
  66. u8x8_cad_SendSequence(u8x8, u8x8_d_gu800_128x64_powersave1_seq);
  67. break;
  68. #ifdef NOT_SUPPORTED
  69. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  70. if ( arg_int == 0 )
  71. {
  72. u8x8_cad_SendSequence(u8x8, u8x8_d_gu800_128x64_flip0_seq);
  73. u8x8->x_offset = u8x8->display_info->default_x_offset;
  74. }
  75. else
  76. {
  77. u8x8_cad_SendSequence(u8x8, u8x8_d_gu800_128x64_flip1_seq);
  78. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  79. }
  80. break;
  81. #endif
  82. #ifdef U8X8_WITH_SET_CONTRAST
  83. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  84. u8x8_cad_SendCmd(u8x8, 0x4f - ((arg_int >> 4)&0x0f) ); /* GU800 has range from 0..15, max brightness is 0x040 */
  85. break;
  86. #endif
  87. case U8X8_MSG_DISPLAY_DRAW_TILE:
  88. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  89. x *= 8;
  90. x += u8x8->x_offset;
  91. u8x8_cad_SendCmd(u8x8, 0x064 );
  92. u8x8_cad_SendArg(u8x8, x );
  93. u8x8_cad_SendCmd(u8x8, 0x060 );
  94. u8x8_cad_SendArg(u8x8, (((u8x8_tile_t *)arg_ptr)->y_pos) );
  95. do
  96. {
  97. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  98. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  99. /* SendData can not handle more than 255 bytes, treat c > 31 correctly */
  100. if ( c > 31 )
  101. {
  102. u8x8_cad_SendData(u8x8, 248, ptr); /* 31*8=248 */
  103. ptr+=248;
  104. c -= 31;
  105. }
  106. u8x8_cad_SendData(u8x8, c*8, ptr);
  107. arg_int--;
  108. } while( arg_int > 0 );
  109. break;
  110. default:
  111. return 0;
  112. }
  113. return 1;
  114. }
  115. /*=================================================*/
  116. static const uint8_t u8x8_d_gu800_128x64_init_seq[] = {
  117. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  118. U8X8_C(0x05f), /* clear all RAM, clear address counters */
  119. U8X8_DLY(1), /* delay for 1 ms (see datasheet) */
  120. /* configure all area as graphics RAM */
  121. U8X8_CA(0x62,0), U8X8_D1(0xff),
  122. U8X8_CA(0x62,1), U8X8_D1(0xff),
  123. U8X8_CA(0x62,2), U8X8_D1(0xff),
  124. U8X8_CA(0x62,3), U8X8_D1(0xff),
  125. U8X8_CA(0x62,4), U8X8_D1(0xff),
  126. U8X8_CA(0x62,5), U8X8_D1(0xff),
  127. U8X8_CA(0x62,6), U8X8_D1(0xff),
  128. U8X8_CA(0x62,7), U8X8_D1(0xff),
  129. U8X8_CA(0x70, 0), /* horizontal shift */
  130. U8X8_C(0xb0), /* vertical shift */
  131. U8X8_C(0x40), /* min (0x04f) / max (0x040) brightness */
  132. U8X8_C(0x84), /* x increment */
  133. // U8X8_CA(0x024, 0x040) /* display on */
  134. U8X8_END_TRANSFER(), /* disable chip */
  135. U8X8_END() /* end of sequence */
  136. };
  137. static const u8x8_display_info_t u8x8_d_gu800_128x64_display_info =
  138. {
  139. /* chip_enable_level = */ 0, /* GU800: CSS signal */
  140. /* chip_disable_level = */ 1, /* GU800: CSS signal */
  141. /* post_chip_enable_wait_ns = */ 40,
  142. /* pre_chip_disable_wait_ns = */ 150,
  143. /* reset_pulse_width_ms = */ 2, /* GU800: Unspecified in datasheet */
  144. /* post_reset_wait_ms = */ 2, /* GU800: Min 1.5ms per datasheet */
  145. /* sda_setup_time_ns = */ 40, /* GU800: 40ns according to the timing diagram */
  146. /* sck_pulse_width_ns = */ 80, /* GU800: Min 80ns per datasheet */
  147. /* sck_clock_hz = */ 4000000UL,
  148. /* spi_mode = */ 2, /* active high, rising edge */
  149. /* i2c_bus_clock_100kHz = */ 4, /* GU800: Not used */
  150. /* data_setup_time_ns = */ 40, /* GU800: Min 40ns per datasheet */
  151. /* write_pulse_width_ns = */ 150, /* GU800: Min 150ns per datasheet */
  152. /* tile_width = */ 16, /* width of 16*8=128 pixel */
  153. /* tile_height = */ 8,
  154. /* default_x_offset = */ 0,
  155. /* flipmode_x_offset = */ 0,
  156. /* pixel_width = */ 128,
  157. /* pixel_height = */ 64
  158. };
  159. uint8_t u8x8_d_gu800_128x64(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  160. {
  161. if ( u8x8_d_gu800_common(u8x8, msg, arg_int, arg_ptr) )
  162. return 1;
  163. switch(msg)
  164. {
  165. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  166. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_d_gu800_128x64_display_info);
  167. break;
  168. case U8X8_MSG_DISPLAY_INIT:
  169. u8x8_d_helper_display_init(u8x8);
  170. u8x8_cad_SendSequence(u8x8, u8x8_d_gu800_128x64_init_seq);
  171. break;
  172. default:
  173. return 0;
  174. }
  175. return 1;
  176. }
  177. /*=================================================*/
  178. /* https://github.com/olikraus/u8g2/issues/1970 */
  179. static const uint8_t u8x8_d_gu800_160x16_init_seq[] = {
  180. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  181. U8X8_C(0x05f), /* clear all RAM, clear address counters */
  182. U8X8_DLY(1), /* delay for 1 ms (see datasheet) */
  183. /* configure all area as graphics RAM */
  184. U8X8_CA(0x62,0), U8X8_D1(0xff),
  185. U8X8_CA(0x62,1), U8X8_D1(0xff),
  186. U8X8_CA(0x62,2), U8X8_D1(0xff),
  187. U8X8_CA(0x62,3), U8X8_D1(0xff),
  188. U8X8_CA(0x62,4), U8X8_D1(0xff),
  189. U8X8_CA(0x62,5), U8X8_D1(0xff),
  190. U8X8_CA(0x62,6), U8X8_D1(0xff),
  191. U8X8_CA(0x62,7), U8X8_D1(0xff),
  192. U8X8_CA(0x70, 0), /* horizontal shift */
  193. U8X8_C(0xb0), /* vertical shift */
  194. U8X8_C(0x40), /* min (0x04f) / max (0x040) brightness */
  195. U8X8_C(0x84), /* x increment */
  196. // U8X8_CA(0x024, 0x040) /* display on */
  197. U8X8_END_TRANSFER(), /* disable chip */
  198. U8X8_END() /* end of sequence */
  199. };
  200. static const u8x8_display_info_t u8x8_d_gu800_160x16_display_info =
  201. {
  202. /* chip_enable_level = */ 0, /* GU800: CSS signal */
  203. /* chip_disable_level = */ 1, /* GU800: CSS signal */
  204. /* post_chip_enable_wait_ns = */ 40,
  205. /* pre_chip_disable_wait_ns = */ 150,
  206. /* reset_pulse_width_ms = */ 2, /* GU800: Unspecified in datasheet */
  207. /* post_reset_wait_ms = */ 2, /* GU800: Min 1.5ms per datasheet */
  208. /* sda_setup_time_ns = */ 40, /* GU800: 40ns according to the timing diagram */
  209. /* sck_pulse_width_ns = */ 80, /* GU800: Min 80ns per datasheet */
  210. /* sck_clock_hz = */ 4000000UL,
  211. /* spi_mode = */ 3, /* active high, rising edge, ISSUE 1970 */
  212. /* i2c_bus_clock_100kHz = */ 4, /* GU800: Not used */
  213. /* data_setup_time_ns = */ 40, /* GU800: Min 40ns per datasheet */
  214. /* write_pulse_width_ns = */ 150, /* GU800: Min 150ns per datasheet */
  215. /* tile_width = */ 20, /* width of 8*20=160 pixel */
  216. /* tile_height = */ 2,
  217. /* default_x_offset = */ 0,
  218. /* flipmode_x_offset = */ 0,
  219. /* pixel_width = */ 160,
  220. /* pixel_height = */ 16
  221. };
  222. uint8_t u8x8_d_gu800_160x16(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  223. {
  224. if ( u8x8_d_gu800_common(u8x8, msg, arg_int, arg_ptr) )
  225. return 1;
  226. switch(msg)
  227. {
  228. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  229. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_d_gu800_160x16_display_info);
  230. break;
  231. case U8X8_MSG_DISPLAY_INIT:
  232. u8x8_d_helper_display_init(u8x8);
  233. u8x8_cad_SendSequence(u8x8, u8x8_d_gu800_160x16_init_seq);
  234. break;
  235. default:
  236. return 0;
  237. }
  238. return 1;
  239. }
  240. /*=================================================*/