u8g_dev_st7920_202x32.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. u8g_dev_st7920_202x32.c
  3. tested with CFAG20232
  4. Universal 8bit Graphics Library
  5. Copyright (c) 2011, 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 202
  30. #define HEIGHT 32
  31. #define PAGE_HEIGHT 8
  32. /* init sequence from https://github.com/adafruit/ST7565-LCD/blob/master/ST7565/ST7565.cpp */
  33. static const uint8_t u8g_dev_st7920_202x32_init_seq[] PROGMEM = {
  34. U8G_ESC_CS(0), /* disable chip */
  35. U8G_ESC_ADR(0), /* instruction mode */
  36. U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
  37. U8G_ESC_DLY(100), /* 8 Dez 2012: additional delay 100 ms because of reset*/
  38. U8G_ESC_CS(1), /* enable chip */
  39. U8G_ESC_DLY(50), /* delay 50 ms */
  40. 0x038, /* 8 Bit interface (DL=1), basic instruction set (RE=0) */
  41. 0x00c, /* display on, cursor & blink off; 0x08: all off */
  42. 0x006, /* Entry mode: Cursor move to right ,DDRAM address counter (AC) plus 1, no shift */
  43. 0x002, /* disable scroll, enable CGRAM adress */
  44. 0x001, /* clear RAM, needs 1.6 ms */
  45. U8G_ESC_DLY(100), /* delay 10 ms */
  46. U8G_ESC_CS(0), /* disable chip */
  47. U8G_ESC_END /* end of sequence */
  48. };
  49. uint8_t u8g_dev_st7920_202x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  50. {
  51. switch(msg)
  52. {
  53. case U8G_DEV_MSG_INIT:
  54. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
  55. u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_202x32_init_seq);
  56. break;
  57. case U8G_DEV_MSG_STOP:
  58. break;
  59. case U8G_DEV_MSG_PAGE_NEXT:
  60. {
  61. uint8_t y, i;
  62. uint8_t *ptr;
  63. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  64. u8g_SetAddress(u8g, dev, 0); /* cmd mode */
  65. u8g_SetChipSelect(u8g, dev, 1);
  66. y = pb->p.page_y0;
  67. ptr = pb->buf;
  68. for( i = 0; i < 8; i ++ )
  69. {
  70. u8g_SetAddress(u8g, dev, 0); /* cmd mode */
  71. u8g_WriteByte(u8g, dev, 0x03e ); /* enable extended mode */
  72. u8g_WriteByte(u8g, dev, 0x080 | y ); /* y pos */
  73. u8g_WriteByte(u8g, dev, 0x080 ); /* set x pos to 0*/
  74. u8g_SetAddress(u8g, dev, 1); /* data mode */
  75. u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
  76. ptr += WIDTH/8;
  77. y++;
  78. }
  79. u8g_SetChipSelect(u8g, dev, 0);
  80. }
  81. break;
  82. }
  83. return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
  84. }
  85. uint8_t u8g_dev_st7920_202x32_4x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  86. {
  87. switch(msg)
  88. {
  89. case U8G_DEV_MSG_INIT:
  90. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
  91. u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_202x32_init_seq);
  92. break;
  93. case U8G_DEV_MSG_STOP:
  94. break;
  95. case U8G_DEV_MSG_PAGE_NEXT:
  96. {
  97. uint8_t y, i;
  98. uint8_t *ptr;
  99. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  100. u8g_SetAddress(u8g, dev, 0); /* cmd mode */
  101. u8g_SetChipSelect(u8g, dev, 1);
  102. y = pb->p.page_y0;
  103. ptr = pb->buf;
  104. for( i = 0; i < 32; i ++ )
  105. {
  106. u8g_SetAddress(u8g, dev, 0); /* cmd mode */
  107. u8g_WriteByte(u8g, dev, 0x03e ); /* enable extended mode */
  108. u8g_WriteByte(u8g, dev, 0x080 | y ); /* y pos */
  109. u8g_WriteByte(u8g, dev, 0x080 ); /* set x pos to 0*/
  110. u8g_SetAddress(u8g, dev, 1); /* data mode */
  111. u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
  112. ptr += WIDTH/8;
  113. y++;
  114. }
  115. u8g_SetChipSelect(u8g, dev, 0);
  116. }
  117. break;
  118. }
  119. return u8g_dev_pb32h1_base_fn(u8g, dev, msg, arg);
  120. }
  121. U8G_PB_DEV(u8g_dev_st7920_202x32_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_202x32_fn, U8G_COM_ST7920_SW_SPI);
  122. U8G_PB_DEV(u8g_dev_st7920_202x32_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_202x32_fn, U8G_COM_ST7920_HW_SPI);
  123. U8G_PB_DEV(u8g_dev_st7920_202x32_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_202x32_fn, U8G_COM_FAST_PARALLEL);
  124. #define QWIDTH (WIDTH*4)
  125. uint8_t u8g_dev_st7920_202x32_4x_buf[QWIDTH] U8G_NOCOMMON ;
  126. u8g_pb_t u8g_dev_st7920_202x32_4x_pb = { {32, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7920_202x32_4x_buf};
  127. u8g_dev_t u8g_dev_st7920_202x32_4x_sw_spi = { u8g_dev_st7920_202x32_4x_fn, &u8g_dev_st7920_202x32_4x_pb, U8G_COM_ST7920_SW_SPI };
  128. u8g_dev_t u8g_dev_st7920_202x32_4x_hw_spi = { u8g_dev_st7920_202x32_4x_fn, &u8g_dev_st7920_202x32_4x_pb, U8G_COM_ST7920_HW_SPI };
  129. u8g_dev_t u8g_dev_st7920_202x32_4x_8bit = { u8g_dev_st7920_202x32_4x_fn, &u8g_dev_st7920_202x32_4x_pb, U8G_COM_FAST_PARALLEL };