u8x8_d_s1d15300.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. u8x8_d_s1d15300.c
  3. WARNING: As of today, flip mode 1 doesn't seem to work (see issue 2063)
  4. Created as a copy of u8x8_d_st7565.c, see https://github.com/olikraus/u8g2/issues/2063
  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. static const uint8_t u8x8_d_s1d15300_powersave0_seq[] = {
  31. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  32. U8X8_C(0x0a4), /* all pixel off, see datasheet for the s1d15300 */
  33. U8X8_C(0x0af), /* display on */
  34. U8X8_END_TRANSFER(), /* disable chip */
  35. U8X8_END() /* end of sequence */
  36. };
  37. static const uint8_t u8x8_d_s1d15300_powersave1_seq[] = {
  38. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  39. U8X8_C(0x0ae), /* display off */
  40. U8X8_C(0x0a5), /* enter powersafe, see datasheet for the s1d15300 */
  41. U8X8_END_TRANSFER(), /* disable chip */
  42. U8X8_END() /* end of sequence */
  43. };
  44. static const uint8_t u8x8_d_s1d15300_flip0_seq[] = {
  45. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  46. U8X8_C(0x0a0), /* segment remap a0/a1*/
  47. U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
  48. U8X8_END_TRANSFER(), /* disable chip */
  49. U8X8_END() /* end of sequence */
  50. };
  51. static const uint8_t u8x8_d_s1d15300_flip1_seq[] = {
  52. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  53. U8X8_C(0x0a1), /* segment remap a0/a1*/
  54. U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */
  55. U8X8_END_TRANSFER(), /* disable chip */
  56. U8X8_END() /* end of sequence */
  57. };
  58. uint8_t u8x8_d_s1d15300_common(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  59. {
  60. uint8_t x, c;
  61. uint8_t *ptr;
  62. switch(msg)
  63. {
  64. case U8X8_MSG_DISPLAY_DRAW_TILE:
  65. u8x8_cad_StartTransfer(u8x8);
  66. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  67. x *= 8;
  68. x += u8x8->x_offset;
  69. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  70. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  71. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
  72. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  73. c *= 8;
  74. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  75. /*
  76. The following if condition checks the hardware limits of the st7565
  77. controller: It is not allowed to write beyond the display limits.
  78. This is in fact an issue within flip mode.
  79. */
  80. if ( c + x > 132u )
  81. {
  82. c = 132u;
  83. c -= x;
  84. }
  85. do
  86. {
  87. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  88. arg_int--;
  89. } while( arg_int > 0 );
  90. u8x8_cad_EndTransfer(u8x8);
  91. break;
  92. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  93. if ( arg_int == 0 )
  94. u8x8_cad_SendSequence(u8x8, u8x8_d_s1d15300_powersave0_seq);
  95. else
  96. u8x8_cad_SendSequence(u8x8, u8x8_d_s1d15300_powersave1_seq);
  97. break;
  98. #ifdef U8X8_WITH_SET_CONTRAST
  99. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  100. u8x8_cad_StartTransfer(u8x8);
  101. u8x8_cad_SendCmd(u8x8, 0x080 | (arg_int >> 3) ); /* s1d15300 has only 5 bits for contrast */
  102. u8x8_cad_EndTransfer(u8x8);
  103. break;
  104. #endif
  105. default:
  106. return 0;
  107. }
  108. return 1;
  109. }
  110. /*================================================*/
  111. /* LM6023, S1D15300 controller, issue 2063 */
  112. static const u8x8_display_info_t u8x8_s1d15300_lm6023_display_info =
  113. {
  114. /* chip_enable_level = */ 0,
  115. /* chip_disable_level = */ 1,
  116. /* post_chip_enable_wait_ns = */ 250, /* */
  117. /* pre_chip_disable_wait_ns = */ 120, /* */
  118. /* reset_pulse_width_ms = */ 1,
  119. /* post_reset_wait_ms = */ 1,
  120. /* sda_setup_time_ns = */ 200, /* */
  121. /* sck_pulse_width_ns = */ 200, /* half of cycle time (100ns according to datasheet), AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
  122. /* sck_clock_hz = */ 1000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
  123. /* spi_mode = */ 0, /* active high, rising edge */
  124. /* i2c_bus_clock_100kHz = */ 4,
  125. /* data_setup_time_ns = */ 200, /* st7565 datasheet, table 24, tds8 */
  126. /* write_pulse_width_ns = */ 200, /* st7565 datasheet, table 24, tcclw */
  127. /* tile_width = */ 16, /* width of 16*8=128 pixel */
  128. /* tile_height = */ 8,
  129. /* default_x_offset = */ 0,
  130. /* flipmode_x_offset = */ 4,
  131. /* pixel_width = */ 128,
  132. /* pixel_height = */ 64
  133. };
  134. static const uint8_t u8x8_d_s1d15300_lm6023_init_seq[] = {
  135. #ifdef OBSOLETE
  136. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  137. U8X8_C(0x0e2), /* soft reset */
  138. U8X8_C(0x0ae), /* display off */
  139. U8X8_C(0x040), /* set display start line to 0 */
  140. U8X8_C(0x0a1), /* ADC set to reverse */
  141. U8X8_C(0x0c0), /* common output mode */
  142. // Flipmode
  143. //U8X8_C(0x0a0), /* ADC set to reverse */
  144. //U8X8_C(0x0c8), /* common output mode */
  145. U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */
  146. U8X8_C(0x0a2), /* LCD bias 1/9 */
  147. U8X8_C(0x02f), /* all power control circuits on */
  148. U8X8_CA(0x0f8, 0x000), /* set booster ratio to 4x */
  149. U8X8_C(0x025), /* set V0 voltage resistor ratio to large, issue 1678: changed from 0x23 to 0x25 */
  150. U8X8_CA(0x081, 170), /* set contrast, contrast value NHD C12864, see issue 186, increased contrast to 180 (issue 219), reduced to 170 (issue 1678) */
  151. U8X8_C(0x0ae), /* display off */
  152. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  153. U8X8_END_TRANSFER(), /* disable chip */
  154. U8X8_END() /* end of sequence */
  155. #endif
  156. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  157. U8X8_C(0x0e2), /* soft reset */
  158. U8X8_C(0x0ae), /* display off */
  159. U8X8_C(0x040), /* set display start line to 0 */
  160. U8X8_C(0x0a0), /* ADC set to normal */
  161. U8X8_C(0x0a6), /* Display normal */
  162. U8X8_C(0x0a4), /* all point normal */
  163. U8X8_C(0x0a2), /* LCD bias 1/8 */
  164. U8X8_C(0x0c0), /* common output mode */
  165. U8X8_C(0x02f), /* all power control circuits on */
  166. U8X8_C(0x090), /* set contrast */
  167. //U8X8_C(0x0af), /* display on */
  168. U8X8_C(0x0b0), /* set page address */
  169. U8X8_C(0x01f), /* set column address upper */
  170. U8X8_C(0x000), /* set column address lower */
  171. U8X8_END_TRANSFER(), /* disable chip */
  172. U8X8_END() /* end of sequence */
  173. };
  174. uint8_t u8x8_d_s1d15300_lm6023(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  175. {
  176. /* call common procedure first and handle messages there */
  177. if ( u8x8_d_s1d15300_common(u8x8, msg, arg_int, arg_ptr) == 0 )
  178. {
  179. /* msg not handled, then try here */
  180. switch(msg)
  181. {
  182. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  183. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_s1d15300_lm6023_display_info);
  184. break;
  185. case U8X8_MSG_DISPLAY_INIT:
  186. u8x8_d_helper_display_init(u8x8);
  187. u8x8_cad_SendSequence(u8x8, u8x8_d_s1d15300_lm6023_init_seq);
  188. break;
  189. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  190. if ( arg_int == 0 )
  191. {
  192. u8x8_cad_SendSequence(u8x8, u8x8_d_s1d15300_flip0_seq);
  193. u8x8->x_offset = u8x8->display_info->default_x_offset;
  194. }
  195. else
  196. {
  197. u8x8_cad_SendSequence(u8x8, u8x8_d_s1d15300_flip1_seq);
  198. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  199. }
  200. break;
  201. default:
  202. return 0; /* msg unknown */
  203. }
  204. }
  205. return 1;
  206. }
  207. /*================================================*/