u8x8_d_pcf8812.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. u8x8_d_pcf8812.c
  3. pcf8812: 65x102
  4. pcf8814: 65x96
  5. Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
  6. Copyright (c) 2017, 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_pcf8812_96x65_init_seq[] = {
  31. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  32. U8X8_C(0x020), /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
  33. U8X8_C(0x008), /* blank display */
  34. U8X8_C(0x021), /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) */
  35. U8X8_C(0x006), /* temp. control: b10 = 2 */
  36. U8X8_C(0x013), /* bias system, 0x010..0x07 1:48 */
  37. U8X8_C(0x09f), /* contrast setting, 0..127 */
  38. //U8X8_CA(0x020 | 2, 0x080 | 0), /* contrast setting, pcf8814 */
  39. U8X8_C(0x024), /* deactivate chip (PD=1), horizontal increment (V=0), enter normal command set (H=0) */
  40. U8X8_END_TRANSFER(), /* disable chip */
  41. U8X8_END() /* end of sequence */
  42. };
  43. static const uint8_t u8x8_d_pcf8812_96x65_powersave0_seq[] = {
  44. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  45. U8X8_C(0x020), /* power on */
  46. U8X8_C(0x00c), /* display on */
  47. U8X8_END_TRANSFER(), /* disable chip */
  48. U8X8_END() /* end of sequence */
  49. };
  50. static const uint8_t u8x8_d_pcf8812_96x65_powersave1_seq[] = {
  51. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  52. U8X8_C(0x020), /* power on */
  53. U8X8_C(0x008), /* blank display */
  54. U8X8_C(0x024), /* power down */
  55. U8X8_END_TRANSFER(), /* disable chip */
  56. U8X8_END() /* end of sequence */
  57. };
  58. static uint8_t u8x8_d_pcf8812_96x65_generic(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. /* handled by the calling function
  65. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  66. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_pcf8812_96x65_display_info);
  67. break;
  68. */
  69. case U8X8_MSG_DISPLAY_INIT:
  70. u8x8_d_helper_display_init(u8x8);
  71. u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_init_seq);
  72. break;
  73. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  74. if ( arg_int == 0 )
  75. u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_powersave0_seq);
  76. else
  77. u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_powersave1_seq);
  78. break;
  79. /*
  80. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  81. if ( arg_int == 0 )
  82. {
  83. u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_flip0_seq);
  84. u8x8->x_offset = u8x8->display_info->default_x_offset;
  85. }
  86. else
  87. {
  88. u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_flip1_seq);
  89. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  90. }
  91. break;
  92. */
  93. #ifdef U8X8_WITH_SET_CONTRAST
  94. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  95. u8x8_cad_StartTransfer(u8x8);
  96. u8x8_cad_SendCmd(u8x8, 0x021 ); /* command mode, extended function set */
  97. u8x8_cad_SendArg(u8x8, (arg_int>>1)|0x80 ); /* 0..127 for contrast */
  98. u8x8_cad_EndTransfer(u8x8);
  99. break;
  100. #endif
  101. case U8X8_MSG_DISPLAY_DRAW_TILE:
  102. u8x8_cad_StartTransfer(u8x8);
  103. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  104. x *= 8;
  105. x += u8x8->x_offset;
  106. u8x8_cad_SendCmd(u8x8, 0x020 ); /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
  107. u8x8_cad_SendCmd(u8x8, 0x080 | x);
  108. u8x8_cad_SendCmd(u8x8, 0x040 | ((u8x8_tile_t *)arg_ptr)->y_pos);
  109. do
  110. {
  111. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  112. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  113. u8x8_cad_SendData(u8x8, c*8, ptr); /* note: SendData can not handle more than 255 bytes */
  114. /*
  115. do
  116. {
  117. u8x8_cad_SendData(u8x8, 8, ptr);
  118. ptr += 8;
  119. c--;
  120. } while( c > 0 );
  121. */
  122. arg_int--;
  123. } while( arg_int > 0 );
  124. u8x8_cad_EndTransfer(u8x8);
  125. break;
  126. default:
  127. return 0;
  128. }
  129. return 1;
  130. }
  131. static const u8x8_display_info_t u8x8_pcf8812_96x65_display_info =
  132. {
  133. /* chip_enable_level = */ 0,
  134. /* chip_disable_level = */ 1,
  135. /* post_chip_enable_wait_ns = */ 100,
  136. /* pre_chip_disable_wait_ns = */ 100,
  137. /* reset_pulse_width_ms = */ 100,
  138. /* post_reset_wait_ms = */ 100,
  139. /* sda_setup_time_ns = */ 100,
  140. /* sck_pulse_width_ns = */ 100,
  141. /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
  142. /* spi_mode = */ 0, /* active high, rising edge */
  143. /* i2c_bus_clock_100kHz = */ 4,
  144. /* data_setup_time_ns = */ 40,
  145. /* write_pulse_width_ns = */ 150,
  146. /* tile_width = */ 12,
  147. /* tile_hight = */ 9,
  148. /* default_x_offset = */ 0,
  149. /* flipmode_x_offset = */ 0,
  150. /* pixel_width = */ 96,
  151. /* pixel_height = */ 65
  152. };
  153. uint8_t u8x8_d_pcf8812_96x65(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  154. {
  155. if ( msg == U8X8_MSG_DISPLAY_SETUP_MEMORY )
  156. {
  157. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_pcf8812_96x65_display_info);
  158. return 1;
  159. }
  160. return u8x8_d_pcf8812_96x65_generic(u8x8, msg, arg_int, arg_ptr);
  161. }