u8g_dev_st7920_192x32.c 5.9 KB

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