Просмотр исходного кода

Add support for ST7565-64128N

Based on #7447 by @Bob-the-Kuhn
Scott Lahteine 7 лет назад
Родитель
Сommit
381ebc043f

+ 14
- 6
Marlin/Conditionals_LCD.h Просмотреть файл

@@ -38,6 +38,10 @@
38 38
     #define LCD_CONTRAST_MIN 60
39 39
     #define LCD_CONTRAST_MAX 140
40 40
 
41
+  #elif ENABLED(MAKRPANEL)
42
+
43
+    #define U8GLIB_ST7565_64128N
44
+
41 45
   #elif ENABLED(ANET_KEYPAD_LCD)
42 46
 
43 47
     #define REPRAPWORLD_KEYPAD
@@ -67,14 +71,18 @@
67 71
     #define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
68 72
 
69 73
     #if ENABLED(miniVIKI)
70
-      #define LCD_CONTRAST_MIN  75
71
-      #define LCD_CONTRAST_MAX 115
72
-      #define DEFAULT_LCD_CONTRAST 95
74
+      #define LCD_CONTRAST_MIN      75
75
+      #define LCD_CONTRAST_MAX     115
76
+      #define DEFAULT_LCD_CONTRAST  95
77
+      #define U8GLIB_ST7565_64128N
73 78
     #elif ENABLED(VIKI2)
74
-      #define DEFAULT_LCD_CONTRAST 40
79
+      #define LCD_CONTRAST_MIN       0
80
+      #define LCD_CONTRAST_MAX     255
81
+      #define DEFAULT_LCD_CONTRAST 140
82
+      #define U8GLIB_ST7565_64128N
75 83
     #elif ENABLED(ELB_FULL_GRAPHIC_CONTROLLER)
76
-      #define LCD_CONTRAST_MIN  90
77
-      #define LCD_CONTRAST_MAX 130
84
+      #define LCD_CONTRAST_MIN      90
85
+      #define LCD_CONTRAST_MAX     130
78 86
       #define DEFAULT_LCD_CONTRAST 110
79 87
       #define U8GLIB_LM6059_AF
80 88
       #define SD_DETECT_INVERTED

+ 13
- 4
Marlin/ultralcd_impl_DOGM.h Просмотреть файл

@@ -43,7 +43,15 @@
43 43
  * These are common LCD 128x64 pixel graphic displays.
44 44
  */
45 45
 #include "ultralcd.h"
46
-#include "ultralcd_st7920_u8glib_rrd.h"
46
+
47
+#if ENABLED(U8GLIB_ST7920)
48
+  #include "ultralcd_st7920_u8glib_rrd.h"
49
+#endif
50
+
51
+#if ENABLED(U8GLIB_ST7565_64128N)
52
+  #include "ultralcd_st7565_u8glib_VIKI.h"
53
+#endif
54
+
47 55
 #include "dogm_bitmaps.h"
48 56
 #include "utility.h"
49 57
 #include "duration_t.h"
@@ -174,10 +182,11 @@
174 182
   // Based on the Adafruit ST7565 (http://www.adafruit.com/products/250)
175 183
   //U8GLIB_LM6059 u8g(DOGLCD_CS, DOGLCD_A0);  // 8 stripes
176 184
   U8GLIB_LM6059_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
177
-#elif ENABLED(MAKRPANEL) || ENABLED(VIKI2) || ENABLED(miniVIKI)
185
+#elif ENABLED(U8GLIB_ST7565_64128N)
178 186
   // The MaKrPanel, Mini Viki, and Viki 2.0, ST7565 controller as well
179
-  //U8GLIB_NHD_C12864 u8g(DOGLCD_CS, DOGLCD_A0);  // 8 stripes
180
-  U8GLIB_NHD_C12864_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
187
+  // U8GLIB_ST7565_64128n_2x_VIKI u8g(0);  // using SW-SPI DOGLCD_MOSI != -1 && DOGLCD_SCK
188
+  U8GLIB_ST7565_64128n_2x_VIKI u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0);  // using SW-SPI
189
+  //U8GLIB_NHD_C12864_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes  HWSPI
181 190
 #elif ENABLED(U8GLIB_SSD1306)
182 191
   // Generic support for SSD1306 OLED I2C LCDs
183 192
   //U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST);  // 8 stripes

+ 253
- 0
Marlin/ultralcd_st7565_u8glib_VIKI.h Просмотреть файл

@@ -0,0 +1,253 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 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
+
23
+#ifndef ULCDST7565_H
24
+#define ULCDST7565_H
25
+
26
+#include <U8glib.h>
27
+
28
+#define ST7565_CLK_PIN  DOGLCD_SCK
29
+#define ST7565_DAT_PIN  DOGLCD_MOSI
30
+#define ST7565_CS_PIN   DOGLCD_CS
31
+#define ST7565_A0_PIN   DOGLCD_A0
32
+
33
+#define LCD_PIXEL_WIDTH 128
34
+#define LCD_PIXEL_HEIGHT 64
35
+#define PAGE_HEIGHT 8
36
+
37
+//set optimization so ARDUINO optimizes this file
38
+#pragma GCC optimize (3)
39
+
40
+// If you want you can define your own set of delays in Configuration.h
41
+//#define ST7565_DELAY_1 DELAY_0_NOP
42
+//#define ST7565_DELAY_2 DELAY_0_NOP
43
+//#define ST7565_DELAY_3 DELAY_0_NOP
44
+
45
+/*
46
+#define ST7565_DELAY_1 u8g_10MicroDelay()
47
+#define ST7565_DELAY_2 u8g_10MicroDelay()
48
+#define ST7565_DELAY_3 u8g_10MicroDelay()
49
+*/
50
+
51
+#if F_CPU >= 20000000
52
+  #define CPU_ST7565_DELAY_1 DELAY_0_NOP
53
+  #define CPU_ST7565_DELAY_2 DELAY_0_NOP
54
+  #define CPU_ST7565_DELAY_3 DELAY_1_NOP
55
+#elif (MOTHERBOARD == BOARD_3DRAG) || (MOTHERBOARD == BOARD_K8200) || (MOTHERBOARD == BOARD_K8400)
56
+  #define CPU_ST7565_DELAY_1 DELAY_0_NOP
57
+  #define CPU_ST7565_DELAY_2 DELAY_3_NOP
58
+  #define CPU_ST7565_DELAY_3 DELAY_0_NOP
59
+#elif (MOTHERBOARD == BOARD_MINIRAMBO)
60
+  #define CPU_ST7565_DELAY_1 DELAY_0_NOP
61
+  #define CPU_ST7565_DELAY_2 DELAY_4_NOP
62
+  #define CPU_ST7565_DELAY_3 DELAY_0_NOP
63
+#elif (MOTHERBOARD == BOARD_RAMBO)
64
+  #define CPU_ST7565_DELAY_1 DELAY_0_NOP
65
+  #define CPU_ST7565_DELAY_2 DELAY_0_NOP
66
+  #define CPU_ST7565_DELAY_3 DELAY_0_NOP
67
+#elif F_CPU == 16000000
68
+  #define CPU_ST7565_DELAY_1 DELAY_0_NOP
69
+  #define CPU_ST7565_DELAY_2 DELAY_0_NOP
70
+  #define CPU_ST7565_DELAY_3 DELAY_1_NOP
71
+#else
72
+  #error "No valid condition for delays in 'ultralcd_st7565_u8glib_VIKI.h'"
73
+#endif
74
+
75
+#ifndef ST7565_DELAY_1
76
+  #define ST7565_DELAY_1 CPU_ST7565_DELAY_1
77
+#endif
78
+#ifndef ST7565_DELAY_2
79
+  #define ST7565_DELAY_2 CPU_ST7565_DELAY_2
80
+#endif
81
+#ifndef ST7565_DELAY_3
82
+  #define ST7565_DELAY_3 CPU_ST7565_DELAY_3
83
+#endif
84
+
85
+#if ENABLED(SHARED_SPI)  // Re-ARM requires that the LCD and the SD card share a single SPI
86
+
87
+  #define ST7565_WRITE_BYTE(a)                 { spiSend((uint8_t)a); U8G_DELAY(); }
88
+  #define ST7560_WriteSequence(count, pointer) { uint8_t *ptr = pointer; for (uint8_t i = 0; i <  count; i++) {spiSend( *ptr++);} DELAY_10US; }
89
+
90
+#else
91
+  #define ST7565_SND_BIT \
92
+    WRITE(ST7565_CLK_PIN, LOW);        ST7565_DELAY_1; \
93
+    WRITE(ST7565_DAT_PIN, val & 0x80); ST7565_DELAY_2; \
94
+    WRITE(ST7565_CLK_PIN, HIGH);       ST7565_DELAY_3; \
95
+    WRITE(ST7565_CLK_PIN, LOW);\
96
+    val <<= 1
97
+
98
+  static void ST7565_SWSPI_SND_8BIT(uint8_t val) {
99
+    ST7565_SND_BIT; // 1
100
+    ST7565_SND_BIT; // 2
101
+    ST7565_SND_BIT; // 3
102
+    ST7565_SND_BIT; // 4
103
+    ST7565_SND_BIT; // 5
104
+    ST7565_SND_BIT; // 6
105
+    ST7565_SND_BIT; // 7
106
+    ST7565_SND_BIT; // 8
107
+  }
108
+
109
+  #define ST7565_WRITE_BYTE(a)                 { ST7565_SWSPI_SND_8BIT((uint8_t)a); U8G_DELAY(); }
110
+  #define ST7560_WriteSequence(count, pointer) { uint8_t *ptr = pointer; for (uint8_t i = 0; i <  count; i++) {ST7565_SWSPI_SND_8BIT( *ptr++);} DELAY_10US; }
111
+#endif
112
+
113
+#if defined(DOGM_SPI_DELAY_US) && DOGM_SPI_DELAY_US > 0
114
+  #define U8G_DELAY() delayMicroseconds(DOGM_SPI_DELAY_US)
115
+#else
116
+  #define U8G_DELAY() u8g_10MicroDelay()
117
+#endif
118
+
119
+#define ST7565_CS()                          { WRITE(ST7565_CS_PIN,1); U8G_DELAY(); }
120
+#define ST7565_NCS()                         { WRITE(ST7565_CS_PIN,0); }
121
+#define ST7565_A0()                          { WRITE(ST7565_A0_PIN,1); U8G_DELAY(); }
122
+#define ST7565_NA0()                         { WRITE(ST7565_A0_PIN,0); }
123
+
124
+
125
+uint8_t u8g_dev_st7565_64128n_2x_VIKI_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
126
+  switch (msg) {
127
+    case U8G_DEV_MSG_INIT: {
128
+      OUT_WRITE(ST7565_CS_PIN, LOW);
129
+      #if ENABLED(SHARED_SPI)
130
+        u8g_Delay(250);
131
+        spiBegin();
132
+        #ifndef SPI_SPEED
133
+          #define SPI_SPEED SPI_FULL_SPEED  // use same SPI speed as SD card
134
+        #endif
135
+        spiInit(SPI_SPEED);
136
+      #else
137
+        OUT_WRITE(ST7565_DAT_PIN, LOW);
138
+        OUT_WRITE(ST7565_CLK_PIN, LOW);
139
+      #endif
140
+      OUT_WRITE(ST7565_A0_PIN, LOW);
141
+
142
+      ST7565_CS();                      /* disable chip */
143
+      ST7565_NA0();                     /* instruction mode */
144
+      ST7565_NCS();                     /* enable chip */
145
+
146
+      ST7565_WRITE_BYTE(0x0A2);         /* 0x0A2: LCD bias 1/9 (according to Displaytech 64128N datasheet) */
147
+      ST7565_WRITE_BYTE(0x0A0);         /* Normal ADC Select (according to Displaytech 64128N datasheet) */
148
+
149
+      ST7565_WRITE_BYTE(0x0C8);         /* common output mode: set scan direction normal operation/SHL Select; 0x0C0 --> SHL = 0; normal; 0x0C8 --> SHL = 1 */
150
+      ST7565_WRITE_BYTE(0x040);         /* Display start line for Displaytech 64128N */
151
+
152
+      ST7565_WRITE_BYTE(0x028 | 0x04);  /* power control: turn on voltage converter */
153
+      //U8G_ESC_DLY(50);                /* delay 50 ms - hangs after a reset if used */
154
+
155
+      ST7565_WRITE_BYTE(0x028 | 0x06);  /* power control: turn on voltage regulator */
156
+      //U8G_ESC_DLY(50);                /* delay 50 ms - hangs after a reset if used */
157
+
158
+      ST7565_WRITE_BYTE(0x028 | 0x07);  /* power control: turn on voltage follower */
159
+      //U8G_ESC_DLY(50);                /* delay 50 ms - hangs after a reset if used */
160
+
161
+      ST7565_WRITE_BYTE(0x010);         /* Set V0 voltage resistor ratio. Setting for controlling brightness of Displaytech 64128N */
162
+
163
+      ST7565_WRITE_BYTE(0x0A6);         /* display normal, bit val 0: LCD pixel off. */
164
+
165
+      ST7565_WRITE_BYTE(0x081);         /* set contrast */
166
+      ST7565_WRITE_BYTE(0x01E);         /* Contrast value. Setting for controlling brightness of Displaytech 64128N */
167
+
168
+      ST7565_WRITE_BYTE(0x0AF);         /* display on */
169
+
170
+      U8G_ESC_DLY(100);                 /* delay 100 ms */
171
+      ST7565_WRITE_BYTE(0x0A5);         /* display all points; ST7565 */
172
+      U8G_ESC_DLY(100);                 /* delay 100 ms */
173
+      U8G_ESC_DLY(100);                 /* delay 100 ms */
174
+      ST7565_WRITE_BYTE(0x0A4);         /* normal display */
175
+      ST7565_CS();                      /* disable chip */
176
+    }                                   /* end of sequence */
177
+    break;
178
+
179
+    case U8G_DEV_MSG_STOP: break;
180
+
181
+    case U8G_DEV_MSG_PAGE_NEXT: {
182
+      u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
183
+      ST7565_CS();                      /* disable chip */
184
+      ST7565_NA0();                     /* instruction mode */
185
+      ST7565_NCS();                     /* enable chip */
186
+      ST7565_WRITE_BYTE(0x010);         /* set upper 4 bit of the col adr to 0x10 */
187
+      ST7565_WRITE_BYTE(0x000);         /* set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N */
188
+                                        /* end of sequence */
189
+      ST7565_WRITE_BYTE(0x0B0 | (2*pb->p.page));; /* select current page (ST7565R) */
190
+      ST7565_A0();                      /* data mode */
191
+      ST7560_WriteSequence( (uint8_t) pb->width, (uint8_t *)pb->buf);
192
+      ST7565_CS();                      /* disable chip */
193
+      ST7565_NA0();                     /* instruction mode */
194
+      ST7565_NCS();                     /* enable chip */
195
+      ST7565_WRITE_BYTE(0x010);         /* set upper 4 bit of the col adr to 0x10 */
196
+      ST7565_WRITE_BYTE(0x000);         /* set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N */
197
+                                        /* end of sequence */
198
+      ST7565_WRITE_BYTE(0x0B0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
199
+      ST7565_A0();                      /* data mode */
200
+      ST7560_WriteSequence( (uint8_t) pb->width, (uint8_t *)(pb->buf)+pb->width);
201
+      ST7565_CS();                      /* disable chip */
202
+    }
203
+    break;
204
+
205
+    case U8G_DEV_MSG_CONTRAST:
206
+      ST7565_NCS();
207
+      ST7565_NA0();                     /* instruction mode */
208
+      ST7565_WRITE_BYTE(0x081);
209
+      ST7565_WRITE_BYTE((*(uint8_t *)arg) >> 2);
210
+      ST7565_CS();                      /* disable chip */
211
+      return 1;
212
+
213
+    case U8G_DEV_MSG_SLEEP_ON:
214
+      ST7565_NA0();                     /* instruction mode */
215
+      ST7565_NCS();                     /* enable chip */
216
+      ST7565_WRITE_BYTE(0x0AC);         /* static indicator off */
217
+      ST7565_WRITE_BYTE(0x000);         /* indicator register set (not sure if this is required) */
218
+      ST7565_WRITE_BYTE(0x0AE);         /* display off */
219
+      ST7565_WRITE_BYTE(0x0A5);         /* all points on */
220
+      ST7565_CS();                      /* disable chip , bugfix 12 nov 2014 */
221
+                                        /* end of sequence */
222
+      return 1;
223
+
224
+    case U8G_DEV_MSG_SLEEP_OFF:
225
+      ST7565_NA0();                     /* instruction mode */
226
+      ST7565_NCS();                     /* enable chip */
227
+      ST7565_WRITE_BYTE(0x0A4);         /* all points off */
228
+      ST7565_WRITE_BYTE(0x0AF);         /* display on */
229
+      U8G_ESC_DLY(50);                  /* delay 50 ms */
230
+      ST7565_CS();                      /* disable chip ,  bugfix 12 nov 2014 */
231
+                                        /* end of sequence */
232
+      return 1;
233
+  }
234
+  return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
235
+}
236
+
237
+uint8_t u8g_dev_st7565_64128n_2x_VIKI_buf[LCD_PIXEL_WIDTH*2] U8G_NOCOMMON;
238
+u8g_pb_t u8g_dev_st7565_64128n_2x_VIKI_pb = {{16, LCD_PIXEL_HEIGHT, 0, 0, 0}, LCD_PIXEL_WIDTH, u8g_dev_st7565_64128n_2x_VIKI_buf};
239
+u8g_dev_t u8g_dev_st7565_64128n_2x_VIKI_sw_spi = {u8g_dev_st7565_64128n_2x_VIKI_fn, &u8g_dev_st7565_64128n_2x_VIKI_pb, &u8g_com_null_fn};
240
+
241
+class U8GLIB_ST7565_64128n_2x_VIKI : public U8GLIB {
242
+  public:
243
+  U8GLIB_ST7565_64128n_2x_VIKI(uint8_t dummy)
244
+    : U8GLIB(&u8g_dev_st7565_64128n_2x_VIKI_sw_spi)
245
+    {  }
246
+  U8GLIB_ST7565_64128n_2x_VIKI(uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset = U8G_PIN_NONE)
247
+    : U8GLIB(&u8g_dev_st7565_64128n_2x_VIKI_sw_spi)
248
+    {  }
249
+};
250
+
251
+#pragma GCC reset_options
252
+
253
+#endif // ULCDST7565_H

+ 4
- 8
Marlin/ultralcd_st7920_u8glib_rrd.h Просмотреть файл

@@ -23,9 +23,7 @@
23 23
 #ifndef ULCDST7920_H
24 24
 #define ULCDST7920_H
25 25
 
26
-#include "Marlin.h"
27
-
28
-#if ENABLED(U8GLIB_ST7920)
26
+#include <U8glib.h>
29 27
 
30 28
 #define ST7920_CLK_PIN  LCD_PINS_D4
31 29
 #define ST7920_DAT_PIN  LCD_PINS_ENABLE
@@ -38,8 +36,6 @@
38 36
 #define LCD_PIXEL_WIDTH 128
39 37
 #define LCD_PIXEL_HEIGHT 64
40 38
 
41
-#include <U8glib.h>
42
-
43 39
 //set optimization so ARDUINO optimizes this file
44 40
 #pragma GCC optimize (3)
45 41
 
@@ -139,8 +135,9 @@ uint8_t u8g_dev_rrd_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, vo
139 135
       ST7920_NCS();
140 136
     }
141 137
     break;
142
-    case U8G_DEV_MSG_STOP:
143
-      break;
138
+
139
+    case U8G_DEV_MSG_STOP: break;
140
+
144 141
     case U8G_DEV_MSG_PAGE_NEXT: {
145 142
       uint8_t* ptr;
146 143
       u8g_pb_t* pb = (u8g_pb_t*)(dev->dev_mem);
@@ -186,5 +183,4 @@ class U8GLIB_ST7920_128X64_RRD : public U8GLIB {
186 183
 
187 184
 #pragma GCC reset_options
188 185
 
189
-#endif // U8GLIB_ST7920
190 186
 #endif // ULCDST7920_H

Загрузка…
Отмена
Сохранить