u8g_dev_lc7981_240x64.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. u8g_dev_lc7981_240x64.c
  3. Tested with Nan Ya LM_J6_003_
  4. Universal 8bit Graphics Library
  5. Copyright (c) 2012, 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 240
  30. #define HEIGHT 64
  31. #define PAGE_HEIGHT 8
  32. /*
  33. http://www.mark-products.com/graphics.htm#240x64%20Pixel%20Format
  34. */
  35. static const uint8_t u8g_dev_lc7981_240x64_init_seq[] PROGMEM = {
  36. U8G_ESC_CS(0), /* disable chip */
  37. U8G_ESC_ADR(1), /* instruction mode */
  38. U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
  39. U8G_ESC_CS(1), /* enable chip */
  40. U8G_ESC_DLY(50), /* delay 50 ms */
  41. U8G_ESC_ADR(1), /* instruction mode */
  42. 0x000, /* mode register */
  43. U8G_ESC_ADR(0), /* data mode */
  44. 0x032, /* display on (bit 5), master mode on (bit 4), graphics mode on (bit 1)*/
  45. U8G_ESC_ADR(1), /* instruction mode */
  46. 0x001, /* character/bits per pixel pitch */
  47. U8G_ESC_ADR(0), /* data mode */
  48. 0x007, /* 8 bits per pixel */
  49. U8G_ESC_ADR(1), /* instruction mode */
  50. 0x002, /* number of chars/byte width of the screen */
  51. U8G_ESC_ADR(0), /* data mode */
  52. WIDTH/8-1, /* 8 bits per pixel */
  53. U8G_ESC_ADR(1), /* instruction mode */
  54. 0x003, /* time division */
  55. U8G_ESC_ADR(0), /* data mode */
  56. 0x07f, /* */
  57. U8G_ESC_ADR(1), /* instruction mode */
  58. 0x008, /* display start low */
  59. U8G_ESC_ADR(0), /* data mode */
  60. 0x000, /* */
  61. U8G_ESC_ADR(1), /* instruction mode */
  62. 0x009, /* display start high */
  63. U8G_ESC_ADR(0), /* data mode */
  64. 0x000, /* */
  65. U8G_ESC_DLY(10), /* delay 10 ms */
  66. U8G_ESC_CS(0), /* disable chip */
  67. U8G_ESC_END /* end of sequence */
  68. };
  69. uint8_t u8g_dev_lc7981_240x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  70. {
  71. switch(msg)
  72. {
  73. case U8G_DEV_MSG_INIT:
  74. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
  75. u8g_WriteEscSeqP(u8g, dev, u8g_dev_lc7981_240x64_init_seq);
  76. break;
  77. case U8G_DEV_MSG_STOP:
  78. break;
  79. case U8G_DEV_MSG_PAGE_NEXT:
  80. {
  81. uint8_t y, i;
  82. uint16_t disp_ram_adr;
  83. uint8_t *ptr;
  84. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  85. u8g_SetAddress(u8g, dev, 1); /* cmd mode */
  86. u8g_SetChipSelect(u8g, dev, 1);
  87. y = pb->p.page_y0;
  88. ptr = pb->buf;
  89. disp_ram_adr = WIDTH/8;
  90. disp_ram_adr *= y;
  91. for( i = 0; i < 8; i ++ )
  92. {
  93. u8g_SetAddress(u8g, dev, 1); /* cmd mode */
  94. u8g_WriteByte(u8g, dev, 0x00a ); /* display ram (cursor) address low byte */
  95. u8g_SetAddress(u8g, dev, 0); /* data mode */
  96. u8g_WriteByte(u8g, dev, disp_ram_adr & 0x0ff );
  97. u8g_SetAddress(u8g, dev, 1); /* cmd mode */
  98. u8g_WriteByte(u8g, dev, 0x00b ); /* display ram (cursor) address hight byte */
  99. u8g_SetAddress(u8g, dev, 0); /* data mode */
  100. u8g_WriteByte(u8g, dev, disp_ram_adr >> 8 );
  101. u8g_SetAddress(u8g, dev, 1); /* cmd mode */
  102. u8g_WriteByte(u8g, dev, 0x00c ); /* write data */
  103. u8g_SetAddress(u8g, dev, 0); /* data mode */
  104. u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
  105. ptr += WIDTH/8;
  106. disp_ram_adr += WIDTH/8;
  107. }
  108. u8g_SetChipSelect(u8g, dev, 0);
  109. }
  110. break;
  111. }
  112. return u8g_dev_pb8h1f_base_fn(u8g, dev, msg, arg);
  113. }
  114. U8G_PB_DEV(u8g_dev_lc7981_240x64_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_lc7981_240x64_fn, U8G_COM_FAST_PARALLEL);