u8x8_d_ld7032_60x32.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*
  2. u8x8_d_ld7032_60x32.c
  3. Note: Flip Mode is NOT supported
  4. Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
  5. Copyright (c) 2016, olikraus@gmail.com
  6. All rights reserved.
  7. Redistribution and use in source and binary forms, with or without modification,
  8. are permitted provided that the following conditions are met:
  9. * Redistributions of source code must retain the above copyright notice, this list
  10. of conditions and the following disclaimer.
  11. * Redistributions in binary form must reproduce the above copyright notice, this
  12. list of conditions and the following disclaimer in the documentation and/or other
  13. materials provided with the distribution.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  15. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  16. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  17. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  19. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  24. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  26. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #include "u8x8.h"
  29. /* testboard U8GLIB_LD7032_60x32 u8g(11, 12, 9, 10, 8); // SPI Com: SCK = 11, MOSI = 12, CS = 9, A0 = 10, RST = 8 (SW SPI Nano Board) */
  30. /* http://www.seeedstudio.com/document/pdf/0.5OLED%20SPEC.pdf */
  31. #ifdef OBSOLETE
  32. static const uint8_t u8x8_d_ld7032_60x32_init_seq_old[] = {
  33. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  34. //U8X8_CA(0x002, 0x001), /* Dot Matrix Display ON */
  35. U8X8_CA(0x014, 0x000), /* Stand-by OFF */
  36. U8X8_CA(0x01a, 0x004), /* Dot Matrix Frame Rate, special value for this OLED from manual*/
  37. U8X8_CA(0x01d, 0x000), /* Graphics Memory Writing Direction: reset default (right down, horizontal) */
  38. U8X8_CA(0x009, 0x000), /* Display Direction: reset default (x,y: min --> max) */
  39. U8X8_CAA(0x030, 0x000, 0x03b), /* Display Size X, Column Start - End*/
  40. U8X8_CAA(0x032, 0x000, 0x01f), /* Display Size Y, Row Start - End*/
  41. U8X8_CA(0x010, 0x000), /* Peak Pulse Width Set: 0 SCLK */
  42. U8X8_CA(0x016, 0x000), /* Peak Pulse Delay Set: 0 SCLK */
  43. U8X8_CA(0x012, 0x040), /* Dot Matrix Current Level Set: 0x050 * 1 uA = 80 uA */
  44. U8X8_CA(0x018, 0x003), /* Pre-Charge Pulse Width: 3 SCLK */
  45. U8X8_CA(0x044, 0x002), /* Pre-Charge Mode: Every Time */
  46. U8X8_CA(0x048, 0x003), /* Row overlap timing: Pre-Charge + Peak Delay + Peak boot Timing */
  47. U8X8_CA(0x03f, 0x011), /* VCC_R_SEL: ??? */
  48. U8X8_CA(0x03d, 0x000), /* VSS selection: 2.8V */
  49. //U8X8_CA(0x002, 0x001), /* Dot Matrix Display ON */
  50. U8X8_END_TRANSFER(), /* disable chip */
  51. U8X8_END() /* end of sequence */
  52. };
  53. #endif
  54. /* new sequence https://github.com/olikraus/u8g2/issues/865 */
  55. static const uint8_t u8x8_d_ld7032_60x32_init_seq[] = {
  56. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  57. U8X8_CA(0x02, 0x00), /* Dot Matrix Display OFF */
  58. U8X8_CA(0x14, 0x00), /* Stand-by OFF, OSCA Start */
  59. U8X8_CA(0x1a, 0x04), /* Dot Matrix Frame Rate, special value for this OLED from manual 4 => 120Hz*/
  60. U8X8_CA(0x1d, 0x00), /* Graphics Memory Writing Direction: reset default (right down, horizontal) */
  61. U8X8_CA(0x09, 0x00), /* Display Direction: reset default (x,y: min --> max) */
  62. U8X8_CAA(0x30, 0x00, 0x3B), /* Display Size X, Column Start - End 0-0x3b(59)*/
  63. U8X8_CAA(0x32, 0x00, 0x1F), /* Display Size Y, Row Start - End 0-0x1f(31)*/
  64. U8X8_CA(0x34, 0x00), /* Data Reading/Writing Box X start */
  65. U8X8_CA(0x35, 0x07), /* Data Reading/Writing Box X end */
  66. U8X8_CA(0x36, 0x00), /* Data Reading/Writing Box Y start */
  67. U8X8_CA(0x37, 0x1F), /* Data Reading/Writing Box Y end */
  68. U8X8_CA(0x38, 0x00), /* Display Start Address X */
  69. U8X8_CA(0x39, 0x00), /* Display Start Address Y */
  70. U8X8_CA(0x10, 0x00), /* Peak Pulse Width Set: 0 SCLK */
  71. U8X8_CA(0x16, 0x00), /* Peak Pulse Delay Set: 0 SCLK */
  72. U8X8_CA(0x12, 0x40), /* 0x32, 0x50 or 0x40 Dot Matrix Current Level Set: 0x050 * 1 uA = 80 uA */
  73. U8X8_CA(0x18, 0x03), /* Pre-Charge Pulse Width: 3 SCLK */
  74. U8X8_CA(0x44, 0x02), /* Pre-Charge Mode: Every Time */
  75. U8X8_CA(0x48, 0x03), /* Row overlap timing: Pre-Charge + Peak Delay + Peak boot Timing */
  76. U8X8_CA(0x17, 0x00), /* Row Scan */
  77. U8X8_CA(0x13, 0x00), /* Row Scan Sequence Setting */
  78. U8X8_CA(0x1C, 0x00), /* Data Reverse */
  79. U8X8_CA(0x3f, 0x11), /* VCC_R_SEL: Internal Regulator enabled(D4=1) and VCC_R=VCC_C*0.7(D0=1) */
  80. U8X8_CA(0x3d, 0x00), /* VSS selection: 2.8V */
  81. U8X8_END_TRANSFER(), /* disable chip */
  82. U8X8_END() /* end of sequence */
  83. };
  84. static const uint8_t u8x8_d_ld7032_60x32_powersave0_seq[] = {
  85. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  86. U8X8_CA(0x002, 0x001), /* Dot Matrix Display ON */
  87. U8X8_END_TRANSFER(), /* disable chip */
  88. U8X8_END() /* end of sequence */
  89. };
  90. static const uint8_t u8x8_d_ld7032_60x32_powersave1_seq[] = {
  91. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  92. U8X8_CA(0x002, 0x000), /* Dot Matrix Display ON */
  93. U8X8_END_TRANSFER(), /* disable chip */
  94. U8X8_END() /* end of sequence */
  95. };
  96. static const uint8_t u8x8_d_ld7032_60x32_flip0_seq[] = {
  97. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  98. U8X8_CA(0x009, 0x000), /* Display Direction: reset default (x,y: min --> max) */
  99. U8X8_END_TRANSFER(), /* disable chip */
  100. U8X8_END() /* end of sequence */
  101. };
  102. static const uint8_t u8x8_d_ld7032_60x32_flip1_seq[] = {
  103. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  104. //U8X8_CA(0x009, 0x002), /* Display Direction: reset default (x,y: min --> max) */
  105. U8X8_END_TRANSFER(), /* disable chip */
  106. U8X8_END() /* end of sequence */
  107. };
  108. static uint8_t u8x8_d_ld7032_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  109. {
  110. uint8_t x, c;
  111. uint8_t *ptr;
  112. switch(msg)
  113. {
  114. /* handled by the calling function
  115. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  116. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ld7032_60x32_display_info);
  117. break;
  118. */
  119. case U8X8_MSG_DISPLAY_INIT:
  120. u8x8_d_helper_display_init(u8x8);
  121. u8x8_cad_SendSequence(u8x8, u8x8_d_ld7032_60x32_init_seq);
  122. break;
  123. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  124. if ( arg_int == 0 )
  125. u8x8_cad_SendSequence(u8x8, u8x8_d_ld7032_60x32_powersave0_seq);
  126. else
  127. u8x8_cad_SendSequence(u8x8, u8x8_d_ld7032_60x32_powersave1_seq);
  128. break;
  129. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  130. if ( arg_int == 0 )
  131. {
  132. u8x8_cad_SendSequence(u8x8, u8x8_d_ld7032_60x32_flip0_seq);
  133. u8x8->x_offset = u8x8->display_info->default_x_offset;
  134. }
  135. else
  136. {
  137. u8x8_cad_SendSequence(u8x8, u8x8_d_ld7032_60x32_flip1_seq);
  138. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  139. }
  140. break;
  141. #ifdef U8X8_WITH_SET_CONTRAST
  142. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  143. u8x8_cad_StartTransfer(u8x8);
  144. u8x8_cad_SendCmd(u8x8, 0x012 );
  145. if ( arg_int > 0x07f ) /* default is 0x040, limit to 0x07f to be on the safe side (hopefully) */
  146. arg_int= 0x07f;
  147. u8x8_cad_SendArg(u8x8, arg_int ); /* values from 0x00 to 0x0ff are allowed, bit will all values be safe??? */
  148. u8x8_cad_EndTransfer(u8x8);
  149. break;
  150. #endif
  151. case U8X8_MSG_DISPLAY_DRAW_TILE:
  152. u8x8_cad_StartTransfer(u8x8);
  153. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  154. x += u8x8->x_offset/8;
  155. u8x8_cad_SendCmd(u8x8, 0x034 );
  156. u8x8_cad_SendArg(u8x8, x );
  157. u8x8_cad_SendCmd(u8x8, 0x035 );
  158. u8x8_cad_SendArg(u8x8, 0x007 );
  159. u8x8_cad_SendCmd(u8x8, 0x036 );
  160. u8x8_cad_SendArg(u8x8, (((u8x8_tile_t *)arg_ptr)->y_pos)*8 );
  161. u8x8_cad_SendCmd(u8x8, 0x037 );
  162. u8x8_cad_SendArg(u8x8, 0x01f );
  163. u8x8_cad_SendCmd(u8x8, 0x008 );
  164. do
  165. {
  166. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  167. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  168. u8x8_cad_SendData(u8x8, c*8, ptr); /* note: SendData can not handle more than 255 bytes */
  169. arg_int--;
  170. } while( arg_int > 0 );
  171. u8x8_cad_EndTransfer(u8x8);
  172. break;
  173. default:
  174. return 0;
  175. }
  176. return 1;
  177. }
  178. static const u8x8_display_info_t u8x8_ld7032_60x32_display_info =
  179. {
  180. /* chip_enable_level = */ 0,
  181. /* chip_disable_level = */ 1,
  182. /* post_chip_enable_wait_ns = */ 15,
  183. /* pre_chip_disable_wait_ns = */ 20,
  184. /* reset_pulse_width_ms = */ 100,
  185. /* post_reset_wait_ms = */ 100,
  186. /* sda_setup_time_ns = */ 30, /* 20ns, but cycle time is 60ns, so use 60/2 */
  187. /* sck_pulse_width_ns = */ 30, /* 20ns, but cycle time is 60ns, so use 60/2 */
  188. /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
  189. /* spi_mode = */ 0, /* active high, rising edge */
  190. /* i2c_bus_clock_100kHz = */ 4,
  191. /* data_setup_time_ns = */ 20,
  192. /* write_pulse_width_ns = */ 40,
  193. /* tile_width = */ 8,
  194. /* tile_hight = */ 4,
  195. /* default_x_offset = */ 0,
  196. /* flipmode_x_offset = */ 0,
  197. /* pixel_width = */ 60,
  198. /* pixel_height = */ 32
  199. };
  200. uint8_t u8x8_d_ld7032_60x32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  201. {
  202. if ( msg == U8X8_MSG_DISPLAY_SETUP_MEMORY )
  203. {
  204. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ld7032_60x32_display_info);
  205. return 1;
  206. }
  207. return u8x8_d_ld7032_generic(u8x8, msg, arg_int, arg_ptr);
  208. }
  209. /* alternative version, issue #1189 */
  210. /* new sequence https://github.com/olikraus/u8g2/issues/1189 */
  211. static const uint8_t u8x8_d_ld7032_60x32_alt_init_seq[] = {
  212. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  213. U8X8_CA(0x02, 0x00),
  214. U8X8_CA(0x14, 0x00),
  215. U8X8_CA(0x1A, 0x05),
  216. U8X8_CA(0x1D, 0x00),
  217. U8X8_CA(0x09, 0x00),
  218. U8X8_CAA(0x30, 0x00, 0x3F),
  219. U8X8_CAA(0x32, 0x08, 0x27),
  220. U8X8_CA(0x34, 0x00),
  221. U8X8_CA(0x35, 0x07),
  222. U8X8_CA(0x36, 0x08),
  223. U8X8_CA(0x37, 0x27),
  224. U8X8_CA(0x38, 0x00),
  225. U8X8_CA(0x39, 0x20),
  226. U8X8_CA(0x10, 0x05),
  227. U8X8_CA(0x16, 0x00),
  228. U8X8_CA(0x18, 0x08),
  229. U8X8_CA(0x12, 0x2F),
  230. U8X8_CA(0x3D, 0x01),
  231. U8X8_CA(0x3F, 0x10),
  232. U8X8_CA(0x44, 0x02),
  233. U8X8_CA(0x48, 0x03),
  234. U8X8_CA(0x17, 0x00),
  235. U8X8_CA(0x13, 0x01),
  236. U8X8_CA(0x3F, 0x11),
  237. U8X8_CA(0x3D, 0x00),
  238. U8X8_END_TRANSFER(), /* disable chip */
  239. U8X8_END() /* end of sequence */};
  240. uint8_t u8x8_d_ld7032_60x32_alt(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  241. {
  242. if ( msg == U8X8_MSG_DISPLAY_SETUP_MEMORY )
  243. {
  244. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ld7032_60x32_display_info);
  245. return 1;
  246. }
  247. if ( msg ==U8X8_MSG_DISPLAY_INIT )
  248. {
  249. u8x8_d_helper_display_init(u8x8);
  250. u8x8_cad_SendSequence(u8x8, u8x8_d_ld7032_60x32_alt_init_seq);
  251. return 1;
  252. }
  253. return u8x8_d_ld7032_generic(u8x8, msg, arg_int, arg_ptr);
  254. }