My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ultralcd_st7920_u8glib_rrd.h 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #ifndef ULCDST7920_H
  23. #define ULCDST7920_H
  24. #include "Marlin.h"
  25. #if ENABLED(U8GLIB_ST7920)
  26. //set optimization so ARDUINO optimizes this file
  27. #pragma GCC optimize (3)
  28. #define ST7920_CLK_PIN LCD_PINS_D4
  29. #define ST7920_DAT_PIN LCD_PINS_ENABLE
  30. #define ST7920_CS_PIN LCD_PINS_RS
  31. //#define PAGE_HEIGHT 8 //128 byte framebuffer
  32. //#define PAGE_HEIGHT 16 //256 byte framebuffer
  33. #define PAGE_HEIGHT 32 //512 byte framebuffer
  34. #define LCD_PIXEL_WIDTH 128
  35. #define LCD_PIXEL_HEIGHT 64
  36. #include <U8glib.h>
  37. static void ST7920_SWSPI_SND_8BIT(uint8_t val) {
  38. uint8_t i;
  39. for (i = 0; i < 8; i++) {
  40. WRITE(ST7920_CLK_PIN,0);
  41. #if F_CPU == 20000000
  42. __asm__("nop\n\t");
  43. #endif
  44. WRITE(ST7920_DAT_PIN,val&0x80);
  45. val<<=1;
  46. WRITE(ST7920_CLK_PIN,1);
  47. #if F_CPU == 20000000
  48. __asm__("nop\n\t""nop\n\t");
  49. #endif
  50. }
  51. }
  52. #define ST7920_CS() {WRITE(ST7920_CS_PIN,1);u8g_10MicroDelay();}
  53. #define ST7920_NCS() {WRITE(ST7920_CS_PIN,0);}
  54. #define ST7920_SET_CMD() {ST7920_SWSPI_SND_8BIT(0xf8);u8g_10MicroDelay();}
  55. #define ST7920_SET_DAT() {ST7920_SWSPI_SND_8BIT(0xfa);u8g_10MicroDelay();}
  56. #define ST7920_WRITE_BYTE(a) {ST7920_SWSPI_SND_8BIT((uint8_t)((a)&0xf0u));ST7920_SWSPI_SND_8BIT((uint8_t)((a)<<4u));u8g_10MicroDelay();}
  57. #define ST7920_WRITE_BYTES(p,l) {uint8_t i;for(i=0;i<l;i++){ST7920_SWSPI_SND_8BIT(*p&0xf0);ST7920_SWSPI_SND_8BIT(*p<<4);p++;}u8g_10MicroDelay();}
  58. uint8_t u8g_dev_rrd_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
  59. uint8_t i, y;
  60. switch (msg) {
  61. case U8G_DEV_MSG_INIT: {
  62. OUT_WRITE(ST7920_CS_PIN, LOW);
  63. OUT_WRITE(ST7920_DAT_PIN, LOW);
  64. OUT_WRITE(ST7920_CLK_PIN, HIGH);
  65. ST7920_CS();
  66. u8g_Delay(120); //initial delay for boot up
  67. ST7920_SET_CMD();
  68. ST7920_WRITE_BYTE(0x08); //display off, cursor+blink off
  69. ST7920_WRITE_BYTE(0x01); //clear CGRAM ram
  70. u8g_Delay(15); //delay for CGRAM clear
  71. ST7920_WRITE_BYTE(0x3E); //extended mode + GDRAM active
  72. for (y = 0; y < (LCD_PIXEL_HEIGHT) / 2; y++) { //clear GDRAM
  73. ST7920_WRITE_BYTE(0x80 | y); //set y
  74. ST7920_WRITE_BYTE(0x80); //set x = 0
  75. ST7920_SET_DAT();
  76. for (i = 0; i < 2 * (LCD_PIXEL_WIDTH) / 8; i++) //2x width clears both segments
  77. ST7920_WRITE_BYTE(0);
  78. ST7920_SET_CMD();
  79. }
  80. ST7920_WRITE_BYTE(0x0C); //display on, cursor+blink off
  81. ST7920_NCS();
  82. }
  83. break;
  84. case U8G_DEV_MSG_STOP:
  85. break;
  86. case U8G_DEV_MSG_PAGE_NEXT: {
  87. uint8_t* ptr;
  88. u8g_pb_t* pb = (u8g_pb_t*)(dev->dev_mem);
  89. y = pb->p.page_y0;
  90. ptr = (uint8_t*)pb->buf;
  91. ST7920_CS();
  92. for (i = 0; i < PAGE_HEIGHT; i ++) {
  93. ST7920_SET_CMD();
  94. if (y < 32) {
  95. ST7920_WRITE_BYTE(0x80 | y); //y
  96. ST7920_WRITE_BYTE(0x80); //x=0
  97. }
  98. else {
  99. ST7920_WRITE_BYTE(0x80 | (y - 32)); //y
  100. ST7920_WRITE_BYTE(0x80 | 8); //x=64
  101. }
  102. ST7920_SET_DAT();
  103. ST7920_WRITE_BYTES(ptr, (LCD_PIXEL_WIDTH) / 8); //ptr is incremented inside of macro
  104. y++;
  105. }
  106. ST7920_NCS();
  107. }
  108. break;
  109. }
  110. #if PAGE_HEIGHT == 8
  111. return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
  112. #elif PAGE_HEIGHT == 16
  113. return u8g_dev_pb16h1_base_fn(u8g, dev, msg, arg);
  114. #else
  115. return u8g_dev_pb32h1_base_fn(u8g, dev, msg, arg);
  116. #endif
  117. }
  118. uint8_t u8g_dev_st7920_128x64_rrd_buf[(LCD_PIXEL_WIDTH) * (PAGE_HEIGHT) / 8] U8G_NOCOMMON;
  119. u8g_pb_t u8g_dev_st7920_128x64_rrd_pb = {{PAGE_HEIGHT, LCD_PIXEL_HEIGHT, 0, 0, 0}, LCD_PIXEL_WIDTH, u8g_dev_st7920_128x64_rrd_buf};
  120. u8g_dev_t u8g_dev_st7920_128x64_rrd_sw_spi = {u8g_dev_rrd_st7920_128x64_fn, &u8g_dev_st7920_128x64_rrd_pb, &u8g_com_null_fn};
  121. class U8GLIB_ST7920_128X64_RRD : public U8GLIB {
  122. public:
  123. U8GLIB_ST7920_128X64_RRD(uint8_t dummy) : U8GLIB(&u8g_dev_st7920_128x64_rrd_sw_spi) {}
  124. };
  125. #endif //U8GLIB_ST7920
  126. #endif //ULCDST7920_H