My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ultralcd_st7920_u8glib_rrd.h 4.0KB

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