|
@@ -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
|