My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

u8g_dev_st7565_nhd_c12864.c 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. u8g_dev_st7565_nhd_c12864.c
  3. Support for the NHD-C12864A1Z-FSB-FBW (Newhaven Display)
  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 128
  30. #define HEIGHT 64
  31. #define PAGE_HEIGHT 8
  32. const uint8_t u8g_dev_st7565_nhd_c12864_init_seq[] PROGMEM = {
  33. U8G_ESC_CS(0), /* disable chip */
  34. U8G_ESC_ADR(0), /* instruction mode */
  35. U8G_ESC_RST(10), /* do reset low pulse with (10*16)+2 milliseconds */
  36. U8G_ESC_CS(1), /* enable chip */
  37. 0x040, /* set display start line */
  38. 0x0a1, /* ADC set to reverse */
  39. 0x0c0, /* common output mode: set scan direction normal operation */
  40. 0x0a6, /* display normal, bit val 0: LCD pixel off. */
  41. 0x0a2, /* LCD bias 1/9 */
  42. 0x02f, /* all power control circuits on */
  43. 0x0f8, /* set booster ratio to */
  44. 0x000, /* 4x */
  45. 0x027, /* set V0 voltage resistor ratio to large */
  46. 0x081, /* set contrast */
  47. 0x008, /* contrast: 0x008 is a good value for NHD C12864, Nov 2012: User reports that 0x1a is much better */
  48. 0x0ac, /* indicator */
  49. 0x000, /* disable */
  50. 0x0af, /* display on */
  51. U8G_ESC_DLY(100), /* delay 100 ms */
  52. 0x0a5, /* display all points, ST7565 */
  53. U8G_ESC_DLY(100), /* delay 100 ms */
  54. U8G_ESC_DLY(100), /* delay 100 ms */
  55. 0x0a4, /* normal display */
  56. U8G_ESC_CS(0), /* disable chip */
  57. U8G_ESC_END /* end of sequence */
  58. };
  59. static const uint8_t u8g_dev_st7565_nhd_c12864_data_start[] PROGMEM = {
  60. U8G_ESC_ADR(0), /* instruction mode */
  61. U8G_ESC_CS(1), /* enable chip */
  62. 0x010, /* set upper 4 bit of the col adr to 0 */
  63. 0x004, /* set lower 4 bit of the col adr to 4 (NHD C12864) */
  64. U8G_ESC_END /* end of sequence */
  65. };
  66. static const uint8_t u8g_dev_st7565_c12864_sleep_on[] PROGMEM = {
  67. U8G_ESC_ADR(0), /* instruction mode */
  68. U8G_ESC_CS(1), /* enable chip */
  69. 0x0ac, /* static indicator off */
  70. 0x000, /* indicator register set (not sure if this is required) */
  71. 0x0ae, /* display off */
  72. 0x0a5, /* all points on */
  73. U8G_ESC_CS(1), /* disable chip */
  74. U8G_ESC_END /* end of sequence */
  75. };
  76. static const uint8_t u8g_dev_st7565_c12864_sleep_off[] PROGMEM = {
  77. U8G_ESC_ADR(0), /* instruction mode */
  78. U8G_ESC_CS(1), /* enable chip */
  79. 0x0a4, /* all points off */
  80. 0x0af, /* display on */
  81. U8G_ESC_DLY(50), /* delay 50 ms */
  82. U8G_ESC_CS(1), /* disable chip */
  83. U8G_ESC_END /* end of sequence */
  84. };
  85. uint8_t u8g_dev_st7565_nhd_c12864_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);
  91. u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_nhd_c12864_init_seq);
  92. break;
  93. case U8G_DEV_MSG_STOP:
  94. break;
  95. case U8G_DEV_MSG_PAGE_NEXT:
  96. {
  97. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  98. u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_nhd_c12864_data_start);
  99. u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (ST7565R) */
  100. u8g_SetAddress(u8g, dev, 1); /* data mode */
  101. if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
  102. return 0;
  103. u8g_SetChipSelect(u8g, dev, 0);
  104. }
  105. break;
  106. case U8G_DEV_MSG_CONTRAST:
  107. u8g_SetChipSelect(u8g, dev, 1);
  108. u8g_SetAddress(u8g, dev, 0); /* instruction mode */
  109. u8g_WriteByte(u8g, dev, 0x081);
  110. u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
  111. u8g_SetChipSelect(u8g, dev, 0);
  112. return 1;
  113. case U8G_DEV_MSG_SLEEP_ON:
  114. u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_c12864_sleep_on);
  115. return 1;
  116. case U8G_DEV_MSG_SLEEP_OFF:
  117. u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_c12864_sleep_off);
  118. return 1;
  119. }
  120. return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
  121. }
  122. U8G_PB_DEV(u8g_dev_st7565_nhd_c12864_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_nhd_c12864_fn, U8G_COM_SW_SPI);
  123. U8G_PB_DEV(u8g_dev_st7565_nhd_c12864_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_nhd_c12864_fn, U8G_COM_HW_SPI);