u8g_dev_uc1601_c128032.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. u8g_dev_uc1601_c128032.c
  3. LCD-AG-C128032R-DIW W/KK E6 PBF from http://www.artronic.pl/o_produkcie.php?id=1343
  4. Universal 8bit Graphics Library
  5. Copyright (c) 2013, 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 128
  30. #define HEIGHT 32
  31. #define PAGE_HEIGHT 8
  32. /* init sequence */
  33. static const uint8_t u8g_dev_uc1601_c128032_init_seq[] PROGMEM = {
  34. U8G_ESC_CS(0), /* disable chip */
  35. U8G_ESC_ADR(0), /* instruction mode */
  36. U8G_ESC_CS(1), /* enable chip */
  37. U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
  38. 0x0a3, /* 0x0a3: LCD bias 1/7 , 0x0a2: LCD bias 1/9 */
  39. 0x0a0, /* 0x0a0: ADC set to normal, 0x0a1 ADC set to inverted */
  40. 0x0c8, /* common output mode: set scan direction normal operation/SHL Select, 0x0c0 --> SHL = 0, normal, 0x0c8 --> SHL = 1 */
  41. 0x0c2, /* 22 May 2013: mirror x */
  42. 0x040, /* set display start line */
  43. 0x028 | 0x04, /* power control: turn on voltage converter */
  44. U8G_ESC_DLY(50), /* delay 50 ms */
  45. 0x028 | 0x06, /* power control: turn on voltage regulator */
  46. U8G_ESC_DLY(50), /* delay 50 ms */
  47. 0x028 | 0x07, /* power control: turn on voltage follower */
  48. U8G_ESC_DLY(10), /* delay 10 ms */
  49. 0x020| 0x06, /* set V0 voltage resistor ratio to 6 */
  50. 0x0af, /* display on */
  51. //0x081, /* set contrast */
  52. //0x018, /* contrast value*/
  53. 0x0a6, /* display normal, bit val 0: LCD pixel off. */
  54. U8G_ESC_DLY(100), /* delay 100 ms */
  55. U8G_ESC_CS(0), /* disable chip */
  56. U8G_ESC_END /* end of sequence */
  57. };
  58. static const uint8_t u8g_dev_uc1601_c128032_data_start[] PROGMEM = {
  59. U8G_ESC_ADR(0), /* instruction mode */
  60. U8G_ESC_CS(1), /* enable chip */
  61. 0x010, /* set upper 4 bit of the col adr to 0 */
  62. 0x004, /* set lower 4 bit of the col adr */
  63. U8G_ESC_END /* end of sequence */
  64. };
  65. static const uint8_t u8g_dev_uc1601_c128032_sleep_on[] PROGMEM = {
  66. U8G_ESC_ADR(0), /* instruction mode */
  67. U8G_ESC_CS(1), /* enable chip */
  68. 0x0ac, /* static indicator off */
  69. 0x000, /* indicator register set (not sure if this is required) */
  70. 0x0ae, /* display off */
  71. 0x0a5, /* all points on */
  72. U8G_ESC_CS(1), /* disable chip */
  73. U8G_ESC_END /* end of sequence */
  74. };
  75. static const uint8_t u8g_dev_uc1601_c128032_sleep_off[] PROGMEM = {
  76. U8G_ESC_ADR(0), /* instruction mode */
  77. U8G_ESC_CS(1), /* enable chip */
  78. 0x0a4, /* all points off */
  79. 0x0af, /* display on */
  80. U8G_ESC_DLY(50), /* delay 50 ms */
  81. U8G_ESC_CS(1), /* disable chip */
  82. U8G_ESC_END /* end of sequence */
  83. };
  84. uint8_t u8g_dev_uc1601_c128032_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  85. {
  86. switch(msg)
  87. {
  88. case U8G_DEV_MSG_INIT:
  89. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
  90. u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_init_seq);
  91. break;
  92. case U8G_DEV_MSG_STOP:
  93. break;
  94. case U8G_DEV_MSG_PAGE_NEXT:
  95. {
  96. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  97. u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_data_start);
  98. u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (UC1601) */
  99. u8g_SetAddress(u8g, dev, 1); /* data mode */
  100. if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
  101. return 0;
  102. u8g_SetChipSelect(u8g, dev, 0);
  103. }
  104. break;
  105. case U8G_DEV_MSG_CONTRAST:
  106. u8g_SetChipSelect(u8g, dev, 1);
  107. u8g_SetAddress(u8g, dev, 0); /* instruction mode */
  108. u8g_WriteByte(u8g, dev, 0x081);
  109. u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
  110. u8g_SetChipSelect(u8g, dev, 0);
  111. return 1;
  112. case U8G_DEV_MSG_SLEEP_ON:
  113. u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_sleep_on);
  114. return 1;
  115. case U8G_DEV_MSG_SLEEP_OFF:
  116. u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_sleep_off);
  117. return 1;
  118. }
  119. return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
  120. }
  121. uint8_t u8g_dev_uc1601_c128032_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  122. {
  123. switch(msg)
  124. {
  125. case U8G_DEV_MSG_INIT:
  126. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
  127. u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_init_seq);
  128. break;
  129. case U8G_DEV_MSG_STOP:
  130. break;
  131. case U8G_DEV_MSG_PAGE_NEXT:
  132. {
  133. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  134. u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_data_start);
  135. u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (UC1601) */
  136. u8g_SetAddress(u8g, dev, 1); /* data mode */
  137. u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
  138. u8g_SetChipSelect(u8g, dev, 0);
  139. u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_data_start);
  140. u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (UC1601) */
  141. u8g_SetAddress(u8g, dev, 1); /* data mode */
  142. u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
  143. u8g_SetChipSelect(u8g, dev, 0);
  144. }
  145. break;
  146. case U8G_DEV_MSG_CONTRAST:
  147. u8g_SetChipSelect(u8g, dev, 1);
  148. u8g_SetAddress(u8g, dev, 0); /* instruction mode */
  149. u8g_WriteByte(u8g, dev, 0x081);
  150. u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
  151. u8g_SetChipSelect(u8g, dev, 0);
  152. return 1;
  153. case U8G_DEV_MSG_SLEEP_ON:
  154. u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_sleep_on);
  155. return 1;
  156. case U8G_DEV_MSG_SLEEP_OFF:
  157. u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_sleep_off);
  158. return 1;
  159. }
  160. return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
  161. }
  162. U8G_PB_DEV(u8g_dev_uc1601_c128032_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1601_c128032_fn, U8G_COM_SW_SPI);
  163. U8G_PB_DEV(u8g_dev_uc1601_c128032_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1601_c128032_fn, U8G_COM_HW_SPI);
  164. uint8_t u8g_dev_uc1601_c128032_2x_buf[WIDTH*2] U8G_NOCOMMON ;
  165. u8g_pb_t u8g_dev_uc1601_c128032_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_uc1601_c128032_2x_buf};
  166. u8g_dev_t u8g_dev_uc1601_c128032_2x_sw_spi = { u8g_dev_uc1601_c128032_2x_fn, &u8g_dev_uc1601_c128032_2x_pb, U8G_COM_SW_SPI };
  167. u8g_dev_t u8g_dev_uc1601_c128032_2x_hw_spi = { u8g_dev_uc1601_c128032_2x_fn, &u8g_dev_uc1601_c128032_2x_pb, U8G_COM_HW_SPI };