u8g_dev_t6963_128x128.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. u8g_dev_t6963_128x128.c
  3. Universal 8bit Graphics Library
  4. Copyright (c) 2013, olikraus@gmail.com
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright notice, this list
  9. of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright notice, this
  11. list of conditions and the following disclaimer in the documentation and/or other
  12. materials provided with the distribution.
  13. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  14. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  15. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  16. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  19. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  23. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. Application Notes for the MGLS 128x128
  27. www.baso.no/content/pdf/T6963C_Application.pdf
  28. Hitachi App Notes:
  29. https://www.sparkfun.com/datasheets/LCD/Monochrome/AN-029-Toshiba_T6963C.pdf
  30. Notes:
  31. The font selection pins should generate the 8x8 font.
  32. For the MGLS240128TZ only FS1 is available on pin 18.
  33. FS1 must be low to generate the 8x8 font.
  34. */
  35. #include "u8g.h"
  36. #define WIDTH 128
  37. #define HEIGHT 128
  38. #define PAGE_HEIGHT 16
  39. /*
  40. http://www.mark-products.com/graphics.htm#240x64%20Pixel%20Format
  41. */
  42. /* text is not used, so settings are not relevant */
  43. static const uint8_t u8g_dev_t6963_128x128_init_seq[] PROGMEM = {
  44. U8G_ESC_CS(0), /* disable chip */
  45. U8G_ESC_ADR(0), /* data mode */
  46. U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
  47. U8G_ESC_CS(1), /* enable chip */
  48. U8G_ESC_DLY(50), /* delay 50 ms */
  49. U8G_ESC_ADR(0), /* data mode */
  50. 0x000, /* low byte */
  51. 0x000, /* height byte */
  52. U8G_ESC_ADR(1), /* instruction mode */
  53. 0x021, /* set cursor position */
  54. U8G_ESC_ADR(0), /* data mode */
  55. 0x000, /* low byte */
  56. 0x000, /* height byte */
  57. U8G_ESC_ADR(1), /* instruction mode */
  58. 0x022, /* set offset */
  59. U8G_ESC_ADR(0), /* data mode */
  60. 0x000, /* low byte */
  61. 0x000, /* height byte */
  62. U8G_ESC_ADR(1), /* instruction mode */
  63. 0x040, /* text home */
  64. U8G_ESC_ADR(0), /* data mode */
  65. WIDTH/8, /* low byte */
  66. 0x000, /* height byte */
  67. U8G_ESC_ADR(1), /* instruction mode */
  68. 0x041, /* text columns */
  69. U8G_ESC_ADR(0), /* data mode */
  70. 0x000, /* low byte */
  71. 0x000, /* height byte */
  72. U8G_ESC_ADR(1), /* instruction mode */
  73. 0x042, /* graphics home */
  74. U8G_ESC_ADR(0), /* data mode */
  75. WIDTH/8, /* low byte */
  76. 0x000, /* height byte */
  77. U8G_ESC_ADR(1), /* instruction mode */
  78. 0x043, /* graphics columns */
  79. // mode set
  80. // 0x080: Internal CG, OR Mode
  81. // 0x081: Internal CG, EXOR Mode
  82. // 0x083: Internal CG, AND Mode
  83. // 0x088: External CG, OR Mode
  84. // 0x089: External CG, EXOR Mode
  85. // 0x08B: External CG, AND Mode
  86. U8G_ESC_ADR(1), /* instruction mode */
  87. 0x080, /* mode register: OR Mode, Internal Character Mode */
  88. U8G_ESC_ADR(1), /* instruction mode */
  89. // display mode
  90. // 0x090: Display off
  91. // 0x094: Graphic off, text on, cursor off, blink off
  92. // 0x096: Graphic off, text on, cursor on, blink off
  93. // 0x097: Graphic off, text on, cursor on, blink on
  94. // 0x098: Graphic on, text off, cursor off, blink off
  95. // 0x09a: Graphic on, text off, cursor on, blink off
  96. // ...
  97. // 0x09c: Graphic on, text on, cursor off, blink off
  98. // 0x09f: Graphic on, text on, cursor on, blink on
  99. 0x098, /* mode register: Display Mode, Graphics on, Text off, Cursor off */
  100. U8G_ESC_ADR(0), /* data mode */
  101. 0x000, /* low byte */
  102. 0x000, /* height byte */
  103. U8G_ESC_ADR(1), /* instruction mode */
  104. 0x024, /* set adr pointer */
  105. U8G_ESC_DLY(100), /* delay 100 ms */
  106. U8G_ESC_ADR(0), /* data mode */
  107. U8G_ESC_CS(0), /* disable chip */
  108. U8G_ESC_END /* end of sequence */
  109. };
  110. uint8_t u8g_dev_t6963_128x128_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  111. {
  112. switch(msg)
  113. {
  114. case U8G_DEV_MSG_INIT:
  115. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
  116. u8g_WriteEscSeqP(u8g, dev, u8g_dev_t6963_128x128_init_seq);
  117. break;
  118. case U8G_DEV_MSG_STOP:
  119. break;
  120. case U8G_DEV_MSG_PAGE_NEXT:
  121. {
  122. uint8_t y, i;
  123. uint16_t disp_ram_adr;
  124. uint8_t *ptr;
  125. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  126. u8g_SetAddress(u8g, dev, 0); /* data mode */
  127. u8g_SetChipSelect(u8g, dev, 1);
  128. y = pb->p.page_y0;
  129. ptr = pb->buf;
  130. disp_ram_adr = WIDTH/8;
  131. disp_ram_adr *= y;
  132. for( i = 0; i < PAGE_HEIGHT; i ++ )
  133. {
  134. u8g_SetAddress(u8g, dev, 0); /* data mode */
  135. u8g_WriteByte(u8g, dev, disp_ram_adr&255 ); /* address low byte */
  136. u8g_WriteByte(u8g, dev, disp_ram_adr>>8 ); /* address hight byte */
  137. u8g_SetAddress(u8g, dev, 1); /* cmd mode */
  138. u8g_WriteByte(u8g, dev, 0x024 ); /* set adr ptr */
  139. u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
  140. ptr += WIDTH/8;
  141. disp_ram_adr += WIDTH/8;
  142. }
  143. u8g_SetAddress(u8g, dev, 0); /* data mode */
  144. u8g_SetChipSelect(u8g, dev, 0);
  145. }
  146. break;
  147. }
  148. return u8g_dev_pb16h1_base_fn(u8g, dev, msg, arg);
  149. }
  150. // U8G_PB_DEV(u8g_dev_t6963_128x128_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_t6963_128x128_fn, U8G_COM_T6963);
  151. uint8_t u8g_dev_t6963_128x128_2x_bw_buf[WIDTH/8*PAGE_HEIGHT] U8G_NOCOMMON ;
  152. u8g_pb_t u8g_dev_t6963_128x128_2x_bw_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_t6963_128x128_2x_bw_buf};
  153. u8g_dev_t u8g_dev_t6963_128x128_8bit = { u8g_dev_t6963_128x128_fn, &u8g_dev_t6963_128x128_2x_bw_pb, U8G_COM_T6963 };