u8g_dev_lc7981_320x64.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. u8g_dev_lc7981_320x64.c
  3. Note: Requires 16 bit mode (Must be enabled in u8g.h)
  4. Tested with Varitronix MGLS32064-03.pdf
  5. Universal 8bit Graphics Library
  6. Copyright (c) 2012, olikraus@gmail.com
  7. All rights reserved.
  8. Redistribution and use in source and binary forms, with or without modification,
  9. are permitted provided that the following conditions are met:
  10. * Redistributions of source code must retain the above copyright notice, this list
  11. of conditions and the following disclaimer.
  12. * Redistributions in binary form must reproduce the above copyright notice, this
  13. list of conditions and the following disclaimer in the documentation and/or other
  14. materials provided with the distribution.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  16. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  17. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  20. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  21. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  25. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  27. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #include "u8g.h"
  30. #ifdef U8G_16BIT
  31. #define WIDTH 320
  32. #else
  33. #define WIDTH 240
  34. #endif
  35. #define HEIGHT 64
  36. #define PAGE_HEIGHT 8
  37. /*
  38. http://www.gaw.ru/pdf/lcd/lcm/Varitronix/graf/MGLS32064-03.pdf
  39. */
  40. static const uint8_t u8g_dev_lc7981_320x64_init_seq[] PROGMEM = {
  41. U8G_ESC_CS(0), /* disable chip */
  42. U8G_ESC_ADR(1), /* instruction mode */
  43. U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
  44. U8G_ESC_CS(1), /* enable chip */
  45. U8G_ESC_DLY(50), /* delay 50 ms */
  46. U8G_ESC_ADR(1), /* instruction mode */
  47. 0x000, /* mode register */
  48. U8G_ESC_ADR(0), /* data mode */
  49. 0x032, /* display on (bit 5), master mode on (bit 4), graphics mode on (bit 1)*/
  50. U8G_ESC_ADR(1), /* instruction mode */
  51. 0x001, /* character/bits per pixel pitch */
  52. U8G_ESC_ADR(0), /* data mode */
  53. 0x007, /* 8 bits per pixel */
  54. U8G_ESC_ADR(1), /* instruction mode */
  55. 0x002, /* number of chars/byte width of the screen */
  56. U8G_ESC_ADR(0), /* data mode */
  57. WIDTH/8-1, /* 8 bits per pixel */
  58. U8G_ESC_ADR(1), /* instruction mode */
  59. 0x003, /* time division */
  60. U8G_ESC_ADR(0), /* data mode */
  61. 0x07f, /* */
  62. U8G_ESC_ADR(1), /* instruction mode */
  63. 0x008, /* display start low */
  64. U8G_ESC_ADR(0), /* data mode */
  65. 0x000, /* */
  66. U8G_ESC_ADR(1), /* instruction mode */
  67. 0x009, /* display start high */
  68. U8G_ESC_ADR(0), /* data mode */
  69. 0x000, /* */
  70. U8G_ESC_DLY(10), /* delay 10 ms */
  71. U8G_ESC_CS(0), /* disable chip */
  72. U8G_ESC_END /* end of sequence */
  73. };
  74. uint8_t u8g_dev_lc7981_320x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  75. {
  76. switch(msg)
  77. {
  78. case U8G_DEV_MSG_INIT:
  79. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
  80. u8g_WriteEscSeqP(u8g, dev, u8g_dev_lc7981_320x64_init_seq);
  81. break;
  82. case U8G_DEV_MSG_STOP:
  83. break;
  84. case U8G_DEV_MSG_PAGE_NEXT:
  85. {
  86. uint8_t y, i;
  87. uint16_t disp_ram_adr;
  88. uint8_t *ptr;
  89. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  90. u8g_SetAddress(u8g, dev, 1); /* cmd mode */
  91. u8g_SetChipSelect(u8g, dev, 1);
  92. y = pb->p.page_y0;
  93. ptr = pb->buf;
  94. disp_ram_adr = WIDTH/8;
  95. disp_ram_adr *= y;
  96. for( i = 0; i < 8; i ++ )
  97. {
  98. u8g_SetAddress(u8g, dev, 1); /* cmd mode */
  99. u8g_WriteByte(u8g, dev, 0x00a ); /* display ram (cursor) address low byte */
  100. u8g_SetAddress(u8g, dev, 0); /* data mode */
  101. u8g_WriteByte(u8g, dev, disp_ram_adr & 0x0ff );
  102. u8g_SetAddress(u8g, dev, 1); /* cmd mode */
  103. u8g_WriteByte(u8g, dev, 0x00b ); /* display ram (cursor) address hight byte */
  104. u8g_SetAddress(u8g, dev, 0); /* data mode */
  105. u8g_WriteByte(u8g, dev, disp_ram_adr >> 8 );
  106. u8g_SetAddress(u8g, dev, 1); /* cmd mode */
  107. u8g_WriteByte(u8g, dev, 0x00c ); /* write data */
  108. u8g_SetAddress(u8g, dev, 0); /* data mode */
  109. u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
  110. ptr += WIDTH/8;
  111. disp_ram_adr += WIDTH/8;
  112. }
  113. u8g_SetChipSelect(u8g, dev, 0);
  114. }
  115. break;
  116. }
  117. return u8g_dev_pb8h1f_base_fn(u8g, dev, msg, arg);
  118. }
  119. U8G_PB_DEV(u8g_dev_lc7981_320x64_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_lc7981_320x64_fn, U8G_COM_FAST_PARALLEL);