u8g_dev_sbn1661_122x32.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. u8g_dev_sbn1661_122x32.c
  3. WG12232 display with 2xSBN1661 / SED1520 controller (122x32 display)
  4. At the moment only available in the Arduino Environment
  5. Universal 8bit Graphics Library
  6. Copyright (c) 2011, 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. #define WIDTH 122
  31. #define HEIGHT 32
  32. #define PAGE_HEIGHT 8
  33. static const uint8_t u8g_dev_sbn1661_122x32_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 */
  37. U8G_ESC_CS(1), /* enable chip 1 */
  38. 0x0af, /* display on */
  39. 0x0c0, /* display start at line 0 */
  40. 0x0a0, /* a0: ADC forward, a1: ADC reverse */
  41. 0x0a9, /* a8: 1/16, a9: 1/32 duty */
  42. U8G_ESC_CS(2), /* enable chip 2 */
  43. 0x0af, /* display on */
  44. 0x0c0, /* display start at line 0 */
  45. 0x0a0, /* a0: ADC forward, a1: ADC reverse */
  46. 0x0a9, /* a8: 1/16, a9: 1/32 duty */
  47. U8G_ESC_CS(0), /* disable chip */
  48. U8G_ESC_END /* end of sequence */
  49. };
  50. uint8_t u8g_dev_sbn1661_122x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  51. {
  52. switch(msg)
  53. {
  54. case U8G_DEV_MSG_INIT:
  55. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
  56. u8g_WriteEscSeqP(u8g, dev, u8g_dev_sbn1661_122x32_init_seq);
  57. break;
  58. case U8G_DEV_MSG_STOP:
  59. break;
  60. case U8G_DEV_MSG_PAGE_NEXT:
  61. {
  62. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  63. u8g_SetAddress(u8g, dev, 0); /* command mode */
  64. u8g_SetChipSelect(u8g, dev, 1);
  65. u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (SBN1661/SED1520) */
  66. u8g_WriteByte(u8g, dev, 0x000 ); /* set X address */
  67. u8g_SetAddress(u8g, dev, 1); /* data mode */
  68. u8g_WriteSequence(u8g, dev, WIDTH/2, pb->buf);
  69. u8g_SetAddress(u8g, dev, 0); /* command mode */
  70. u8g_SetChipSelect(u8g, dev, 2);
  71. u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (SBN1661/SED1520) */
  72. u8g_WriteByte(u8g, dev, 0x000 ); /* set X address */
  73. u8g_SetAddress(u8g, dev, 1); /* data mode */
  74. u8g_WriteSequence(u8g, dev, WIDTH/2, WIDTH/2+(uint8_t *)pb->buf);
  75. u8g_SetChipSelect(u8g, dev, 0);
  76. }
  77. break;
  78. case U8G_DEV_MSG_CONTRAST:
  79. break;
  80. }
  81. return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
  82. }
  83. /* u8g_com_arduino_sw_spi_fn does not work, too fast??? */
  84. U8G_PB_DEV(u8g_dev_sbn1661_122x32 , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_sbn1661_122x32_fn, u8g_com_arduino_no_en_parallel_fn);