My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ultralcd_st7920_u8glib_rrd.h 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #ifndef ULCDST7920_H
  2. #define ULCDST7920_H
  3. #include "Marlin.h"
  4. #if ENABLED(U8GLIB_ST7920)
  5. //set optimization so ARDUINO optimizes this file
  6. #pragma GCC optimize (3)
  7. #define ST7920_CLK_PIN LCD_PINS_D4
  8. #define ST7920_DAT_PIN LCD_PINS_ENABLE
  9. #define ST7920_CS_PIN LCD_PINS_RS
  10. //#define PAGE_HEIGHT 8 //128 byte framebuffer
  11. //#define PAGE_HEIGHT 16 //256 byte framebuffer
  12. #define PAGE_HEIGHT 32 //512 byte framebuffer
  13. #define LCD_PIXEL_WIDTH 128
  14. #define LCD_PIXEL_HEIGHT 64
  15. #include <U8glib.h>
  16. static void ST7920_SWSPI_SND_8BIT(uint8_t val) {
  17. uint8_t i;
  18. for (i = 0; i < 8; i++) {
  19. WRITE(ST7920_CLK_PIN,0);
  20. #if F_CPU == 20000000
  21. __asm__("nop\n\t");
  22. #endif
  23. WRITE(ST7920_DAT_PIN,val&0x80);
  24. val<<=1;
  25. WRITE(ST7920_CLK_PIN,1);
  26. #if F_CPU == 20000000
  27. __asm__("nop\n\t""nop\n\t");
  28. #endif
  29. }
  30. }
  31. #define ST7920_CS() {WRITE(ST7920_CS_PIN,1);u8g_10MicroDelay();}
  32. #define ST7920_NCS() {WRITE(ST7920_CS_PIN,0);}
  33. #define ST7920_SET_CMD() {ST7920_SWSPI_SND_8BIT(0xf8);u8g_10MicroDelay();}
  34. #define ST7920_SET_DAT() {ST7920_SWSPI_SND_8BIT(0xfa);u8g_10MicroDelay();}
  35. #define ST7920_WRITE_BYTE(a) {ST7920_SWSPI_SND_8BIT((uint8_t)((a)&0xf0u));ST7920_SWSPI_SND_8BIT((uint8_t)((a)<<4u));u8g_10MicroDelay();}
  36. #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();}
  37. uint8_t u8g_dev_rrd_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
  38. uint8_t i, y;
  39. switch (msg) {
  40. case U8G_DEV_MSG_INIT: {
  41. OUT_WRITE(ST7920_CS_PIN, LOW);
  42. OUT_WRITE(ST7920_DAT_PIN, LOW);
  43. OUT_WRITE(ST7920_CLK_PIN, HIGH);
  44. ST7920_CS();
  45. u8g_Delay(120); //initial delay for boot up
  46. ST7920_SET_CMD();
  47. ST7920_WRITE_BYTE(0x08); //display off, cursor+blink off
  48. ST7920_WRITE_BYTE(0x01); //clear CGRAM ram
  49. u8g_Delay(15); //delay for CGRAM clear
  50. ST7920_WRITE_BYTE(0x3E); //extended mode + GDRAM active
  51. for (y = 0; y < (LCD_PIXEL_HEIGHT) / 2; y++) { //clear GDRAM
  52. ST7920_WRITE_BYTE(0x80 | y); //set y
  53. ST7920_WRITE_BYTE(0x80); //set x = 0
  54. ST7920_SET_DAT();
  55. for (i = 0; i < 2 * (LCD_PIXEL_WIDTH) / 8; i++) //2x width clears both segments
  56. ST7920_WRITE_BYTE(0);
  57. ST7920_SET_CMD();
  58. }
  59. ST7920_WRITE_BYTE(0x0C); //display on, cursor+blink off
  60. ST7920_NCS();
  61. }
  62. break;
  63. case U8G_DEV_MSG_STOP:
  64. break;
  65. case U8G_DEV_MSG_PAGE_NEXT: {
  66. uint8_t* ptr;
  67. u8g_pb_t* pb = (u8g_pb_t*)(dev->dev_mem);
  68. y = pb->p.page_y0;
  69. ptr = (uint8_t*)pb->buf;
  70. ST7920_CS();
  71. for (i = 0; i < PAGE_HEIGHT; i ++) {
  72. ST7920_SET_CMD();
  73. if (y < 32) {
  74. ST7920_WRITE_BYTE(0x80 | y); //y
  75. ST7920_WRITE_BYTE(0x80); //x=0
  76. }
  77. else {
  78. ST7920_WRITE_BYTE(0x80 | (y - 32)); //y
  79. ST7920_WRITE_BYTE(0x80 | 8); //x=64
  80. }
  81. ST7920_SET_DAT();
  82. ST7920_WRITE_BYTES(ptr, (LCD_PIXEL_WIDTH) / 8); //ptr is incremented inside of macro
  83. y++;
  84. }
  85. ST7920_NCS();
  86. }
  87. break;
  88. }
  89. #if PAGE_HEIGHT == 8
  90. return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
  91. #elif PAGE_HEIGHT == 16
  92. return u8g_dev_pb16h1_base_fn(u8g, dev, msg, arg);
  93. #else
  94. return u8g_dev_pb32h1_base_fn(u8g, dev, msg, arg);
  95. #endif
  96. }
  97. uint8_t u8g_dev_st7920_128x64_rrd_buf[(LCD_PIXEL_WIDTH) * (PAGE_HEIGHT) / 8] U8G_NOCOMMON;
  98. 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};
  99. 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};
  100. class U8GLIB_ST7920_128X64_RRD : public U8GLIB {
  101. public:
  102. U8GLIB_ST7920_128X64_RRD(uint8_t dummy) : U8GLIB(&u8g_dev_st7920_128x64_rrd_sw_spi) {}
  103. };
  104. #endif //U8GLIB_ST7920
  105. #endif //ULCDST7920_H