u8g_dev_ld7032_60x32.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. u8g_dev_ld7032_60x32.c
  3. 60x32 OLED display
  4. Universal 8bit Graphics Library
  5. Copyright (c) 2011, 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 "u8g.h"
  29. /* define width as 64, so that it is a multiple of 8 */
  30. #define WIDTH 64
  31. #define HEIGHT 32
  32. #define PAGE_HEIGHT 8
  33. static const uint8_t u8g_dev_ld7032_60x32_init_seq[] PROGMEM = {
  34. U8G_ESC_CS(0), /* disable chip */
  35. U8G_ESC_ADR(0), /* instruction mode */
  36. U8G_ESC_DLY(1), /* delay 1 ms */
  37. U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
  38. U8G_ESC_CS(1), /* enable chip */
  39. U8G_ESC_ADR(0), /* instruction mode */
  40. 0x002, /* Dot Matrix Display ON/OFF */
  41. U8G_ESC_ADR(1), /* data mode */
  42. 0x001, /* ON */
  43. U8G_ESC_ADR(0), /* instruction mode */
  44. 0x014, /* Dot Matrix Display Stand-by ON/OFF */
  45. U8G_ESC_ADR(1), /* data mode */
  46. 0x000, /* ON */
  47. U8G_ESC_ADR(0), /* instruction mode */
  48. 0x01a, /* Dot Matrix Frame Rate */
  49. U8G_ESC_ADR(1), /* data mode */
  50. 0x004, /* special value for this OLED from manual */
  51. U8G_ESC_ADR(0), /* instruction mode */
  52. 0x01d, /* Graphics Memory Writing Direction */
  53. U8G_ESC_ADR(1), /* data mode */
  54. 0x000, /* reset default (right down, horizontal) */
  55. U8G_ESC_ADR(0), /* instruction mode */
  56. 0x009, /* Display Direction */
  57. U8G_ESC_ADR(1), /* data mode */
  58. 0x000, /* reset default (x,y: min --> max) */
  59. U8G_ESC_ADR(0), /* instruction mode */
  60. 0x030, /* Display Size X */
  61. U8G_ESC_ADR(1), /* data mode */
  62. 0x000, /* Column Start Output */
  63. 0x03b, /* Column End Output */
  64. U8G_ESC_ADR(0), /* instruction mode */
  65. 0x032, /* Display Size Y */
  66. U8G_ESC_ADR(1), /* data mode */
  67. 0x000, /* Row Start Output */
  68. 0x01f, /* Row End Output */
  69. U8G_ESC_ADR(0), /* instruction mode */
  70. 0x010, /* Peak Pulse Width Set */
  71. U8G_ESC_ADR(1), /* data mode */
  72. 0x000, /* 0 SCLK */
  73. U8G_ESC_ADR(0), /* instruction mode */
  74. 0x016, /* Peak Pulse Delay Set */
  75. U8G_ESC_ADR(1), /* data mode */
  76. 0x000, /* 0 SCLK */
  77. U8G_ESC_ADR(0), /* instruction mode */
  78. 0x012, /* Dot Matrix Current Level Set */
  79. U8G_ESC_ADR(1), /* data mode */
  80. 0x050, /* 0x050 * 1 uA = 80 uA */
  81. U8G_ESC_ADR(0), /* instruction mode */
  82. 0x018, /* Pre-Charge Pulse Width */
  83. U8G_ESC_ADR(1), /* data mode */
  84. 0x003, /* 3 SCLK */
  85. U8G_ESC_ADR(0), /* instruction mode */
  86. 0x044, /* Pre-Charge Mode */
  87. U8G_ESC_ADR(1), /* data mode */
  88. 0x002, /* Every Time */
  89. U8G_ESC_ADR(0), /* instruction mode */
  90. 0x048, /* Row overlap timing */
  91. U8G_ESC_ADR(1), /* data mode */
  92. 0x003, /* Pre-Charge + Peak Delay + Peak boot Timing */
  93. U8G_ESC_ADR(0), /* instruction mode */
  94. 0x03f, /* VCC_R_SEL */
  95. U8G_ESC_ADR(1), /* data mode */
  96. 0x011, /* ??? */
  97. U8G_ESC_ADR(0), /* instruction mode */
  98. 0x03d, /* VSS selection */
  99. U8G_ESC_ADR(1), /* data mode */
  100. 0x000, /* 2.8V */
  101. U8G_ESC_ADR(0), /* instruction mode */
  102. 0x002, /* Dot Matrix Display ON/OFF */
  103. U8G_ESC_ADR(1), /* data mode */
  104. 0x001, /* ON */
  105. U8G_ESC_ADR(0), /* instruction mode */
  106. 0x008, /* write data */
  107. U8G_ESC_CS(0), /* disable chip */
  108. U8G_ESC_END /* end of sequence */
  109. };
  110. /* use box commands to set start adr */
  111. static const uint8_t u8g_dev_ld7032_60x32_data_start[] PROGMEM = {
  112. U8G_ESC_ADR(0), /* instruction mode */
  113. U8G_ESC_CS(1), /* enable chip */
  114. U8G_ESC_ADR(0), /* instruction mode */
  115. 0x034, /* box x start */
  116. U8G_ESC_ADR(1), /* data mode */
  117. 0x000, /* 0 */
  118. U8G_ESC_ADR(0), /* instruction mode */
  119. 0x035, /* box x end */
  120. U8G_ESC_ADR(1), /* data mode */
  121. 0x007, /* */
  122. U8G_ESC_ADR(0), /* instruction mode */
  123. 0x037, /* box y end */
  124. U8G_ESC_ADR(1), /* data mode */
  125. 0x01f, /* */
  126. U8G_ESC_ADR(0), /* instruction mode */
  127. 0x036, /* box y start */
  128. U8G_ESC_ADR(1), /* data mode */
  129. U8G_ESC_END /* end of sequence */
  130. };
  131. static const uint8_t u8g_dev_ld7032_60x32_sleep_on[] PROGMEM = {
  132. U8G_ESC_ADR(0), /* instruction mode */
  133. U8G_ESC_CS(1), /* enable chip */
  134. /* ... */
  135. U8G_ESC_CS(0), /* disable chip */
  136. U8G_ESC_END /* end of sequence */
  137. };
  138. static const uint8_t u8g_dev_ld7032_60x32_sleep_off[] PROGMEM = {
  139. U8G_ESC_ADR(0), /* instruction mode */
  140. U8G_ESC_CS(1), /* enable chip */
  141. /* ... */
  142. U8G_ESC_DLY(50), /* delay 50 ms */
  143. U8G_ESC_CS(0), /* disable chip */
  144. U8G_ESC_END /* end of sequence */
  145. };
  146. uint8_t u8g_dev_ld7032_60x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  147. {
  148. switch(msg)
  149. {
  150. case U8G_DEV_MSG_INIT:
  151. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
  152. u8g_WriteEscSeqP(u8g, dev, u8g_dev_ld7032_60x32_init_seq);
  153. break;
  154. case U8G_DEV_MSG_STOP:
  155. break;
  156. case U8G_DEV_MSG_PAGE_NEXT:
  157. {
  158. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  159. u8g_WriteEscSeqP(u8g, dev, u8g_dev_ld7032_60x32_data_start);
  160. u8g_WriteByte(u8g, dev, pb->p.page_y0); /* y start */
  161. u8g_SetAddress(u8g, dev, 0); /* instruction mode */
  162. u8g_WriteByte(u8g, dev, 0x008);
  163. u8g_SetAddress(u8g, dev, 1); /* data mode */
  164. if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
  165. return 0;
  166. u8g_SetChipSelect(u8g, dev, 0);
  167. }
  168. break;
  169. case U8G_DEV_MSG_CONTRAST:
  170. u8g_SetChipSelect(u8g, dev, 1);
  171. u8g_SetAddress(u8g, dev, 0); /* instruction mode */
  172. u8g_WriteByte(u8g, dev, 0x081);
  173. u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
  174. u8g_SetChipSelect(u8g, dev, 0);
  175. return 1;
  176. case U8G_DEV_MSG_SLEEP_ON:
  177. u8g_WriteEscSeqP(u8g, dev, u8g_dev_ld7032_60x32_sleep_on);
  178. return 1;
  179. case U8G_DEV_MSG_SLEEP_OFF:
  180. u8g_WriteEscSeqP(u8g, dev, u8g_dev_ld7032_60x32_sleep_off);
  181. return 1;
  182. }
  183. return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
  184. }
  185. U8G_PB_DEV(u8g_dev_ld7032_60x32_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ld7032_60x32_fn, U8G_COM_SW_SPI);
  186. U8G_PB_DEV(u8g_dev_ld7032_60x32_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ld7032_60x32_fn, U8G_COM_HW_SPI);
  187. U8G_PB_DEV(u8g_dev_ld7032_60x32_parallel, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ld7032_60x32_fn, U8G_COM_PARALLEL);
  188. U8G_PB_DEV(u8g_dev_ld7032_60x32_hw_usart_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ld7032_60x32_fn, U8G_COM_HW_USART_SPI);