Browse Source

Merge pull request #505 from MStohn/much-faster-glcd-st7920

faster GLCD (ST7920 SW-SPI) implementation / fixes
ErikZalm 12 years ago
parent
commit
1520de0093
2 changed files with 135 additions and 5 deletions
  1. 4
    5
      Marlin/dogm_lcd_implementation.h
  2. 131
    0
      Marlin/ultralcd_st7920_u8glib_rrd.h

+ 4
- 5
Marlin/dogm_lcd_implementation.h View File

33
 #define LCD_CLICKED (buttons&EN_C)
33
 #define LCD_CLICKED (buttons&EN_C)
34
 #endif
34
 #endif
35
 
35
 
36
-// CHANGE_DE begin ***
37
-#include <U8glib.h>	// DE_U8glib
36
+#include <U8glib.h>
38
 #include "DOGMbitmaps.h"
37
 #include "DOGMbitmaps.h"
39
 #include "dogm_font_data_marlin.h"
38
 #include "dogm_font_data_marlin.h"
40
 #include "ultralcd.h"
39
 #include "ultralcd.h"
40
+#include "ultralcd_st7920_u8glib_rrd.h"
41
 
41
 
42
 
42
 
43
 /* Russian language not supported yet, needs custom font
43
 /* Russian language not supported yet, needs custom font
74
 
74
 
75
 #define FONT_STATUSMENU	u8g_font_6x9
75
 #define FONT_STATUSMENU	u8g_font_6x9
76
 
76
 
77
-
78
 // LCD selection
77
 // LCD selection
79
 #ifdef U8GLIB_ST7920
78
 #ifdef U8GLIB_ST7920
80
-// SPI Com: SCK = en = (D4), MOSI = rw = (RS), CS = di = (ENABLE)
81
-U8GLIB_ST7920_128X64_1X u8g(LCD_PINS_D4, LCD_PINS_ENABLE, LCD_PINS_RS);
79
+//U8GLIB_ST7920_128X64_RRD u8g(0,0,0);
80
+U8GLIB_ST7920_128X64_RRD u8g(0);
82
 #else
81
 #else
83
 U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0);	// HW-SPI Com: CS, A0
82
 U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0);	// HW-SPI Com: CS, A0
84
 #endif
83
 #endif

+ 131
- 0
Marlin/ultralcd_st7920_u8glib_rrd.h View File

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

Loading…
Cancel
Save