u8g_dev_uc1608_240x128.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. u8g_dev_uc1608_240x128.c
  3. Universal 8bit Graphics Library
  4. Copyright (c) 2013, olikraus@gmail.com (original 240x64 library)
  5. Modified by thieringpeti@gmail.com for Raystar rx240128 family displays
  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. /*
  29. Display: http://www.tme.eu/en/details/rx240128a-ghw/lcd-graphic-displays/raystar-optronics/
  30. Connection: HW / SW SPI.
  31. To get this display working, You need some extra capacitors:
  32. connect 4.7uF caps between:
  33. PIN1 & PIN2 VB1 +-
  34. PIN3 & PIN4 VB0 -+
  35. connect 0.1uF caps between:
  36. VLCD and VSS
  37. VBIAS and VSS
  38. You can find some schematics with a 10M resistor parallellized with the VLCD capacitor.
  39. Select 4-bit SPI mode.
  40. Connect D7 (PIN9) To VDD (+3.3V)
  41. Connect D1, D2, D4, D5, D6 to GND (PINS 10,11,12,14,15)
  42. Connect WR0, WR1, BM0, BM1 to GND (PINS 17,18,22,23)
  43. D0: (PIN16) AVR's SCK pin (HW SPI)
  44. D3: (PIN13) AVR's MOSI pin (HW SPI)
  45. CD: (PIN19) used as A0 in the library
  46. CS: (PIN21) Connect to the defined CS pin, and You can re-use the HW SPI in different routines.
  47. RST: (PIN20) optional reset, can be defined in the function, resets on initialization.
  48. Adjust contrast if necessary. Default: 0x072.
  49. */
  50. #include "u8g.h"
  51. #define WIDTH 240
  52. #define HEIGHT 128
  53. #define PAGE_HEIGHT 8
  54. /* see also ERC24064-1 for init sequence example */
  55. static const uint8_t u8g_dev_uc1608_240x128_init_seq[] PROGMEM = {
  56. U8G_ESC_CS(1), /* disable chip (UC1608 has positive logic for CS) */
  57. U8G_ESC_ADR(0), /* instruction mode */
  58. U8G_ESC_RST(1), /* do reset low pulse with (15*16)+2 milliseconds */
  59. U8G_ESC_CS(0), /* enable chip */
  60. 0x0e2, /* soft reset */
  61. U8G_ESC_DLY(100), /* delay 100 ms */
  62. U8G_ESC_DLY(100), /* delay 100 ms */
  63. 0x026, /* MUX rate and temperature compensation */
  64. 0x0c8, /* Map control, Bit 3: MY=1, Bit 2: MX=0, Bit 0: MSF =0 */
  65. 0x0eb, /* LCD bias Bits 0/1: 00=10.7 01=10.3, 10=12.0, 11=12.7*/
  66. /* default 0x0ea for 240x128 */
  67. 0x081, /* set contrast (bits 0..5) and gain (bits 6/7) */
  68. 0x072, /* default for 240x128 displays: 0x072*/
  69. 0x02f, /* power on, Bit 2 PC2=1 (internal charge pump), Bits 0/1: cap of panel */
  70. U8G_ESC_DLY(50), /* delay 50 ms */
  71. 0x040, /* set display start line to 0 */
  72. 0x090, /* no fixed lines */
  73. 0x089, /* RAM access control */
  74. 0x0af, /* disable sleep mode */
  75. 0x0a4, /* normal display */
  76. 0x0a5, /* display all points, ST7565, UC1610 */
  77. // 0x0a7, /* inverse display */
  78. 0x0a6, /* normal display */
  79. U8G_ESC_DLY(100), /* delay 100 ms */
  80. 0x0a4, /* normal display */
  81. U8G_ESC_CS(1), /* disable chip */
  82. U8G_ESC_END /* end of sequence */
  83. };
  84. static const uint8_t u8g_dev_uc1608_240x128_data_start[] PROGMEM = {
  85. U8G_ESC_ADR(0), /* instruction mode */
  86. U8G_ESC_CS(0), /* enable chip */
  87. 0x010, /* set upper 4 bit of the col adr to 0 (UC1608) */
  88. 0x000, /* set lower 4 bit of the col adr to 0 */
  89. U8G_ESC_END /* end of sequence */
  90. };
  91. uint8_t u8g_dev_uc1608_240x128_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  92. {
  93. switch(msg)
  94. {
  95. case U8G_DEV_MSG_INIT:
  96. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
  97. u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x128_init_seq);
  98. break;
  99. case U8G_DEV_MSG_STOP:
  100. break;
  101. case U8G_DEV_MSG_PAGE_NEXT:
  102. {
  103. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  104. u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x128_data_start);
  105. u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (UC1608) */
  106. u8g_SetAddress(u8g, dev, 1); /* data mode */
  107. if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
  108. return 0;
  109. u8g_SetChipSelect(u8g, dev, 1);
  110. }
  111. break;
  112. case U8G_DEV_MSG_CONTRAST:
  113. u8g_SetChipSelect(u8g, dev, 0);
  114. u8g_SetAddress(u8g, dev, 0); /* instruction mode */
  115. u8g_WriteByte(u8g, dev, 0x081);
  116. u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2); /* set contrast from, keep gain at 0 */
  117. u8g_SetChipSelect(u8g, dev, 1);
  118. return 1;
  119. }
  120. return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
  121. }
  122. uint8_t u8g_dev_uc1608_240x128_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  123. {
  124. switch(msg)
  125. {
  126. case U8G_DEV_MSG_INIT:
  127. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
  128. u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x128_init_seq);
  129. break;
  130. case U8G_DEV_MSG_STOP:
  131. break;
  132. case U8G_DEV_MSG_PAGE_NEXT:
  133. {
  134. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  135. u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x128_data_start);
  136. u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */
  137. u8g_SetAddress(u8g, dev, 1); /* data mode */
  138. u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
  139. u8g_SetChipSelect(u8g, dev, 0);
  140. u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x128_data_start);
  141. u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
  142. u8g_SetAddress(u8g, dev, 1); /* data mode */
  143. u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
  144. u8g_SetChipSelect(u8g, dev, 0);
  145. }
  146. break;
  147. case U8G_DEV_MSG_CONTRAST:
  148. u8g_SetChipSelect(u8g, dev, 1);
  149. u8g_SetAddress(u8g, dev, 0); /* instruction mode */
  150. u8g_WriteByte(u8g, dev, 0x081);
  151. u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
  152. u8g_SetChipSelect(u8g, dev, 0);
  153. return 1;
  154. }
  155. return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
  156. }
  157. U8G_PB_DEV(u8g_dev_uc1608_240x128_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1608_240x128_fn, U8G_COM_SW_SPI);
  158. U8G_PB_DEV(u8g_dev_uc1608_240x128_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1608_240x128_fn, U8G_COM_HW_SPI);
  159. uint8_t u8g_dev_uc1608_240x128_2x_buf[WIDTH*2] U8G_NOCOMMON ;
  160. u8g_pb_t u8g_dev_uc1608_240x128_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_uc1608_240x128_2x_buf};
  161. u8g_dev_t u8g_dev_uc1608_240x128_2x_sw_spi = { u8g_dev_uc1608_240x128_2x_fn, &u8g_dev_uc1608_240x128_2x_pb, U8G_COM_SW_SPI };
  162. u8g_dev_t u8g_dev_uc1608_240x128_2x_hw_spi = { u8g_dev_uc1608_240x128_2x_fn, &u8g_dev_uc1608_240x128_2x_pb, U8G_COM_HW_SPI };