u8x8_d_s1d15e06.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. u8x8_d_s1d15e06.c
  3. https://github.com/olikraus/u8g2/pull/1190
  4. https://github.com/olikraus/u8g2/issues/1172
  5. Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
  6. Copyright (c) 2020, 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. static const uint8_t u8x8_d_s1d15e06_powersave0_seq[] = {
  31. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  32. U8X8_C(0xA8), /* display on */
  33. U8X8_END_TRANSFER(), /* disable chip */
  34. U8X8_END() /* end of sequence */
  35. };
  36. static const uint8_t u8x8_d_s1d15e06_powersave1_seq[] = {
  37. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  38. U8X8_C(0xA8|1), /* display off, enter sleep mode */
  39. U8X8_END_TRANSFER(), /* disable chip */
  40. U8X8_END() /* end of sequence */
  41. };
  42. static const uint8_t u8x8_d_s1d15e06_flip0_seq[] = {
  43. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  44. U8X8_C(0xA6), /* LCD Mapping */
  45. U8X8_END_TRANSFER(), /* disable chip */
  46. U8X8_END() /* end of sequence */
  47. };
  48. static const uint8_t u8x8_d_s1d15e06_flip1_seq[] = {
  49. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  50. U8X8_C(0xA7), /* LCD Mapping */
  51. U8X8_END_TRANSFER(), /* disable chip */
  52. U8X8_END() /* end of sequence */
  53. };
  54. uint8_t u8x8_d_s1d15e06_common(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  55. {
  56. uint8_t x, y, c;
  57. uint8_t *ptr;
  58. switch(msg)
  59. {
  60. case U8X8_MSG_DISPLAY_DRAW_TILE:
  61. u8x8_cad_StartTransfer(u8x8);
  62. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  63. x *= 8;
  64. u8x8_cad_SendCmd(u8x8, 0xB1); //Page Address - Row
  65. u8x8_cad_SendArg(u8x8, (((u8x8_tile_t *)arg_ptr)->y_pos));
  66. y = ((u8x8_tile_t *)arg_ptr)->y_pos;
  67. y += u8x8->x_offset;
  68. u8x8_cad_SendCmd(u8x8, 0x13); /* col */
  69. u8x8_cad_SendArg(u8x8, x);
  70. u8x8_cad_SendCmd(u8x8, 0x1D ); //Data Write
  71. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  72. c *= 8;
  73. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  74. do
  75. {
  76. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  77. arg_int--;
  78. } while( arg_int > 0 );
  79. u8x8_cad_EndTransfer(u8x8);
  80. break;
  81. /* handled in the calling procedure
  82. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  83. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1608_128x64_display_info);
  84. break;
  85. case U8X8_MSG_DISPLAY_INIT:
  86. u8x8_d_helper_display_init(u8x8);
  87. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1701_dogs102_init_seq);
  88. break;
  89. */
  90. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  91. if ( arg_int == 0 )
  92. u8x8_cad_SendSequence(u8x8, u8x8_d_s1d15e06_powersave0_seq);
  93. else
  94. u8x8_cad_SendSequence(u8x8, u8x8_d_s1d15e06_powersave1_seq);
  95. break;
  96. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  97. if ( arg_int == 0 )
  98. {
  99. u8x8_cad_SendSequence(u8x8, u8x8_d_s1d15e06_flip0_seq);
  100. u8x8->x_offset = u8x8->display_info->default_x_offset;
  101. }
  102. else
  103. {
  104. u8x8_cad_SendSequence(u8x8, u8x8_d_s1d15e06_flip1_seq);
  105. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  106. }
  107. break;
  108. #ifdef U8X8_WITH_SET_CONTRAST
  109. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  110. break;
  111. #endif
  112. default:
  113. return 0;
  114. }
  115. return 1;
  116. }
  117. /*================================================*/
  118. /* s1d15e06 160x100 */
  119. static const u8x8_display_info_t u8x8_s1d15e06_160100_display_info =
  120. {
  121. /* chip_enable_level = */ 0, /* s1d15e06 has low active CS */
  122. /* chip_disable_level = */ 1,
  123. /* post_chip_enable_wait_ns = */ 10, /* uc1608 datasheet, page 39, actually 0 */
  124. /* pre_chip_disable_wait_ns = */ 20, /* uc1608 datasheet, page 39 */
  125. /* reset_pulse_width_ms = */ 1, /* uc1608 datasheet, page 42 */
  126. /* post_reset_wait_ms = */ 10,
  127. /* sda_setup_time_ns = */ 30, /* uc1608 datasheet, page 41 */
  128. /* sck_pulse_width_ns = */ 65, /* half of cycle time */
  129. /* sck_clock_hz = */ 8000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
  130. /* spi_mode = */ 0, /* active high, rising edge */
  131. /* i2c_bus_clock_100kHz = */ 4,
  132. /* data_setup_time_ns = */ 30, /* uc1608 datasheet, page 39 */
  133. /* write_pulse_width_ns = */ 65, /* uc1608 datasheet, page 39 */
  134. /* tile_width = */ 20, /* width of 20*8=160 pixel */
  135. /* tile_height = */ 13,
  136. /* default_x_offset = */ 0, /* reused as y page offset */
  137. /* flipmode_x_offset = */ 0, /* reused as y page offset */
  138. /* pixel_width = */ 160,
  139. /* pixel_height = */ 100
  140. };
  141. static const uint8_t u8x8_d_s1d15e06_160100_init_seq[] = {
  142. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  143. /* (Command no in datasheet) Description */
  144. U8X8_C(0xA0|1), /* (12) Column Address Direction (Reverse) */
  145. U8X8_C(0xC4|1), /* (5) Common Output Status (Reverse) */
  146. U8X8_C(0x84), /* (11) Display Data In. Direction (Normal) */
  147. U8X8_C(0xA6), /* (3) Display Normal Reverse (Normal) */
  148. U8X8_C(0xA4), /* (4) Display All Light (Normal) */
  149. U8X8_CAA(0x6D,0x18,0x04), /* (18) Duty Set Command,
  150. Parameter "Duty Set" 1/96 ,
  151. Parameter "Start Point Set" */
  152. U8X8_CA(0x66, 0x01), /* (15) Display Mode, Parameter 0 (4 Gray Scale) 1 (Binary) */
  153. U8X8_CA(0x39, 0x43), /* (16) Gray Scale Pattern Set, Pattern */
  154. U8X8_C(0xBE|1), /* (2) Display Off Mode (0 VSS / 1 Vcc) */
  155. U8X8_CA(0x2B, 0x03), /* (27) LCD Drive Mode Voltage Select, Parameter */
  156. U8X8_CA(0x81, 0x32), /* (28) Electronic Volume, Parameter */
  157. U8X8_C(0xE4|1), /* (14) N-Line On Off (On) */
  158. U8X8_CA(0x36, 0x05), /* (13) N-Line Inversion Drive, Parameter (6x4) */
  159. U8X8_CA(0x41, 0x03), /* (13) (26) Step-up CK Frequency Select, fosc/8 */
  160. U8X8_CA(0x5F, 0x04), /* (24) Built-in Oscillator Frequency, Parameter */
  161. U8X8_C(0xAA|1), /* (23) Built-in OSC On */
  162. U8X8_CA(0x25, 0x1F), /* (25) Power Control Set, Parameter */
  163. U8X8_CA(0x8A, 0x00), /* (6) Start Line Setup, Parameter */
  164. U8X8_CA(0xB1, 0x00), /* (7) Page Address Set, Parameter */
  165. U8X8_CA(0x13, 0x00), /* (8) Column Address Set */
  166. U8X8_C(0xAE|1), /* (1) Display ON/OFF */
  167. U8X8_END_TRANSFER(), /* disable chip */
  168. U8X8_END() /* end of sequence */
  169. };
  170. uint8_t u8x8_d_s1d15e06_160100(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  171. {
  172. /* checking for the flip mode cmd first */
  173. if ( msg == U8X8_MSG_DISPLAY_SET_FLIP_MODE )
  174. {
  175. if ( arg_int == 0 )
  176. {
  177. u8x8_cad_SendSequence(u8x8, u8x8_d_s1d15e06_flip0_seq);
  178. u8x8->x_offset = u8x8->display_info->default_x_offset;
  179. }
  180. else
  181. {
  182. u8x8_cad_SendSequence(u8x8, u8x8_d_s1d15e06_flip1_seq);
  183. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  184. }
  185. return 1;
  186. }
  187. /* call the common procedure, this now leads to the effect, that the flip code is executed again */
  188. /* maybe we should paste the common code here to avoid this */
  189. if ( u8x8_d_s1d15e06_common(u8x8, msg, arg_int, arg_ptr) == 0 )
  190. {
  191. /* msg not handled, then try here */
  192. switch(msg)
  193. {
  194. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  195. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_s1d15e06_160100_display_info);
  196. break;
  197. case U8X8_MSG_DISPLAY_INIT:
  198. u8x8_d_helper_display_init(u8x8);
  199. u8x8_cad_SendSequence(u8x8, u8x8_d_s1d15e06_160100_init_seq);
  200. break;
  201. default:
  202. return 0; /* msg unknown */
  203. }
  204. }
  205. return 1;
  206. }