|
@@ -23,21 +23,20 @@
|
23
|
23
|
#ifndef ULCDST7565_H
|
24
|
24
|
#define ULCDST7565_H
|
25
|
25
|
|
26
|
|
-#include "Marlin.h"
|
27
|
|
-
|
28
|
|
-#if ENABLED(U8GLIB_ST7565_64128N)
|
|
26
|
+#include "../../inc/MarlinConfig.h"
|
29
|
27
|
|
|
28
|
+#if !( defined(DOGLCD_SCK) && DOGLCD_SCK >= 0 \
|
|
29
|
+ && defined(DOGLCD_MOSI) && DOGLCD_MOSI >= 0 \
|
|
30
|
+ && defined(DOGLCD_CS) && DOGLCD_CS >= 0 \
|
|
31
|
+ && defined(DOGLCD_A0) && DOGLCD_A0 >= 0 )
|
|
32
|
+ #error "DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, and DOGLCD_A0 are required for VIKI."
|
|
33
|
+#endif
|
30
|
34
|
|
31
|
35
|
#define ST7565_CLK_PIN DOGLCD_SCK
|
32
|
36
|
#define ST7565_DAT_PIN DOGLCD_MOSI
|
33
|
37
|
#define ST7565_CS_PIN DOGLCD_CS
|
34
|
38
|
#define ST7565_A0_PIN DOGLCD_A0
|
35
|
39
|
|
36
|
|
-
|
37
|
|
-
|
38
|
|
-
|
39
|
|
-
|
40
|
|
-
|
41
|
40
|
#include <U8glib.h>
|
42
|
41
|
|
43
|
42
|
#define WIDTH 128
|
|
@@ -116,119 +115,116 @@ static void ST7565_SWSPI_SND_8BIT(uint8_t val) {
|
116
|
115
|
#define U8G_DELAY u8g_10MicroDelay()
|
117
|
116
|
#endif
|
118
|
117
|
|
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
|
|
-#define ST7565_WRITE_BYTE(a) { ST7565_SWSPI_SND_8BIT((uint8_t)a); U8G_DELAY; }
|
124
|
|
-#define ST7560_WriteSequence(count, pointer) { uint8_t *ptr = pointer; for (uint8_t i = 0; i < count; i++) {ST7565_SWSPI_SND_8BIT( *ptr++);} DELAY_10US; }
|
|
118
|
+#define ST7565_CS() do{ WRITE(ST7565_CS_PIN, HIGH); U8G_DELAY; }while(0)
|
|
119
|
+#define ST7565_NCS() WRITE(ST7565_CS_PIN, LOW)
|
|
120
|
+#define ST7565_A0() do{ WRITE(ST7565_A0_PIN, HIGH); U8G_DELAY; }while(0)
|
|
121
|
+#define ST7565_NA0() WRITE(ST7565_A0_PIN, LOW)
|
|
122
|
+#define ST7565_WRITE_BYTE(a) do{ ST7565_SWSPI_SND_8BIT((uint8_t)a); U8G_DELAY; }while(0)
|
|
123
|
+#define ST7560_WriteSequence(count, pointer) do{ uint8_t *ptr = pointer; for (uint8_t i = 0; i < count; ++i) { ST7565_SWSPI_SND_8BIT(*ptr++); } DELAY_10US; }while(0)
|
125
|
124
|
|
126
|
125
|
|
127
|
126
|
uint8_t u8g_dev_st7565_64128n_2x_VIKI_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
|
128
|
127
|
switch (msg) {
|
129
|
|
- case U8G_DEV_MSG_INIT:
|
130
|
|
- { OUT_WRITE(ST7565_CS_PIN, LOW);
|
|
128
|
+ case U8G_DEV_MSG_INIT: {
|
|
129
|
+ OUT_WRITE(ST7565_CS_PIN, LOW);
|
131
|
130
|
OUT_WRITE(ST7565_DAT_PIN, LOW);
|
132
|
131
|
OUT_WRITE(ST7565_CLK_PIN, LOW);
|
133
|
132
|
OUT_WRITE(ST7565_A0_PIN, LOW);
|
134
|
133
|
|
135
|
|
- ST7565_CS(); /* disable chip */
|
136
|
|
- ST7565_NA0(); /* instruction mode */
|
137
|
|
- ST7565_NCS(); /* enable chip */
|
138
|
|
-
|
139
|
|
-
|
140
|
|
- ST7565_WRITE_BYTE(0x0A2); /* 0x0a2: LCD bias 1/9 (according to Displaytech 64128N datasheet) */
|
141
|
|
- ST7565_WRITE_BYTE(0x0A0); /* Normal ADC Select (according to Displaytech 64128N datasheet) */
|
|
134
|
+ ST7565_CS(); // disable chip
|
|
135
|
+ ST7565_NA0(); // instruction mode
|
|
136
|
+ ST7565_NCS(); // enable chip
|
142
|
137
|
|
143
|
|
- ST7565_WRITE_BYTE(0x0c8); /* common output mode: set scan direction normal operation/SHL Select; 0x0c0 --> SHL = 0; normal; 0x0c8 --> SHL = 1 */
|
144
|
|
- ST7565_WRITE_BYTE(0x040); /* Display start line for Displaytech 64128N */
|
|
138
|
+ ST7565_WRITE_BYTE(0xA2); // 0xA2: LCD bias 1/9 (according to Displaytech 64128N datasheet)
|
|
139
|
+ ST7565_WRITE_BYTE(0xA0); // Normal ADC Select (according to Displaytech 64128N datasheet)
|
145
|
140
|
|
146
|
|
- ST7565_WRITE_BYTE(0x028 | 0x04); /* power control: turn on voltage converter */
|
147
|
|
-// U8G_ESC_DLY(50); /* delay 50 ms - hangs after a reset if used */
|
|
141
|
+ ST7565_WRITE_BYTE(0xC8); // common output mode: set scan direction normal operation/SHL Select; 0xC0 --> SHL = 0; normal; 0xC8 --> SHL = 1
|
|
142
|
+ ST7565_WRITE_BYTE(0x40); // Display start line for Displaytech 64128N
|
148
|
143
|
|
149
|
|
- ST7565_WRITE_BYTE(0x028 | 0x06); /* power control: turn on voltage regulator */
|
150
|
|
-// U8G_ESC_DLY(50); /* delay 50 ms - hangs after a reset if used */
|
|
144
|
+ ST7565_WRITE_BYTE(0x28 | 0x04); // power control: turn on voltage converter
|
|
145
|
+ //U8G_ESC_DLY(50); // delay 50 ms - hangs after a reset if used
|
151
|
146
|
|
152
|
|
- ST7565_WRITE_BYTE(0x028 | 0x07); /* power control: turn on voltage follower */
|
153
|
|
-// U8G_ESC_DLY(50); /* delay 50 ms - hangs after a reset if used */
|
|
147
|
+ ST7565_WRITE_BYTE(0x28 | 0x06); // power control: turn on voltage regulator
|
|
148
|
+ //U8G_ESC_DLY(50); // delay 50 ms - hangs after a reset if used
|
154
|
149
|
|
155
|
|
- ST7565_WRITE_BYTE(0x010); /* Set V0 voltage resistor ratio. Setting for controlling brightness of Displaytech 64128N */
|
|
150
|
+ ST7565_WRITE_BYTE(0x28 | 0x07); // power control: turn on voltage follower
|
|
151
|
+ //U8G_ESC_DLY(50); // delay 50 ms - hangs after a reset if used
|
156
|
152
|
|
157
|
|
- ST7565_WRITE_BYTE(0x0a6); /* display normal, bit val 0: LCD pixel off. */
|
|
153
|
+ ST7565_WRITE_BYTE(0x10); // Set V0 voltage resistor ratio. Setting for controlling brightness of Displaytech 64128N
|
158
|
154
|
|
159
|
|
- ST7565_WRITE_BYTE(0x081); /* set contrast */
|
160
|
|
- ST7565_WRITE_BYTE(0x01e); /* Contrast value. Setting for controlling brightness of Displaytech 64128N */
|
|
155
|
+ ST7565_WRITE_BYTE(0xA6); // display normal, bit val 0: LCD pixel off.
|
161
|
156
|
|
|
157
|
+ ST7565_WRITE_BYTE(0x81); // set contrast
|
|
158
|
+ ST7565_WRITE_BYTE(0x1E); // Contrast value. Setting for controlling brightness of Displaytech 64128N
|
162
|
159
|
|
163
|
|
- ST7565_WRITE_BYTE(0x0af); /* display on */
|
|
160
|
+ ST7565_WRITE_BYTE(0xAF); // display on
|
164
|
161
|
|
165
|
|
- U8G_ESC_DLY(100); /* delay 100 ms */
|
166
|
|
- ST7565_WRITE_BYTE(0x0a5); /* display all points; ST7565 */
|
167
|
|
- U8G_ESC_DLY(100); /* delay 100 ms */
|
168
|
|
- U8G_ESC_DLY(100); /* delay 100 ms */
|
169
|
|
- ST7565_WRITE_BYTE(0x0a4); /* normal display */
|
170
|
|
- ST7565_CS(); /* disable chip */
|
171
|
|
- } /* end of sequence */
|
|
162
|
+ U8G_ESC_DLY(100); // delay 100 ms
|
|
163
|
+ ST7565_WRITE_BYTE(0xA5); // display all points; ST7565
|
|
164
|
+ U8G_ESC_DLY(100); // delay 100 ms
|
|
165
|
+ U8G_ESC_DLY(100); // delay 100 ms
|
|
166
|
+ ST7565_WRITE_BYTE(0xA4); // normal display
|
|
167
|
+ ST7565_CS(); // disable chip
|
|
168
|
+ } // end of sequence
|
172
|
169
|
break;
|
173
|
170
|
case U8G_DEV_MSG_STOP:
|
174
|
171
|
break;
|
175
|
|
- case U8G_DEV_MSG_PAGE_NEXT:
|
176
|
|
- { u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
177
|
|
- ST7565_CS(); /* disable chip */
|
178
|
|
- ST7565_NA0(); /* instruction mode */
|
179
|
|
- ST7565_NCS(); /* enable chip */
|
180
|
|
- ST7565_WRITE_BYTE(0x010); /* set upper 4 bit of the col adr to 0x10 */
|
181
|
|
- ST7565_WRITE_BYTE(0x000); /* set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N */
|
182
|
|
- /* end of sequence */
|
183
|
|
- ST7565_WRITE_BYTE(0x0b0 | (2*pb->p.page));; /* select current page (ST7565R) */
|
184
|
|
- ST7565_A0(); /* data mode */
|
185
|
|
- ST7560_WriteSequence( (uint8_t) pb->width, (uint8_t *)pb->buf);
|
186
|
|
- ST7565_CS(); /* disable chip */
|
187
|
|
- ST7565_NA0(); /* instruction mode */
|
188
|
|
- ST7565_NCS(); /* enable chip */
|
189
|
|
- ST7565_WRITE_BYTE(0x010); /* set upper 4 bit of the col adr to 0x10 */
|
190
|
|
- ST7565_WRITE_BYTE(0x000); /* set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N */
|
191
|
|
- /* end of sequence */
|
192
|
|
- ST7565_WRITE_BYTE(0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
|
193
|
|
- ST7565_A0(); /* data mode */
|
194
|
|
- ST7560_WriteSequence( (uint8_t) pb->width, (uint8_t *)(pb->buf)+pb->width);
|
195
|
|
- ST7565_CS(); /* disable chip */
|
|
172
|
+ case U8G_DEV_MSG_PAGE_NEXT: {
|
|
173
|
+ u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
|
174
|
+ ST7565_CS(); // disable chip
|
|
175
|
+ ST7565_NA0(); // instruction mode
|
|
176
|
+ ST7565_NCS(); // enable chip
|
|
177
|
+ ST7565_WRITE_BYTE(0x10); // set upper 4 bit of the col adr to 0x10
|
|
178
|
+ ST7565_WRITE_BYTE(0x00); // set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N
|
|
179
|
+ // end of sequence
|
|
180
|
+ ST7565_WRITE_BYTE(0xB0 | (2 * pb->p.page)); // select current page (ST7565R)
|
|
181
|
+ ST7565_A0(); // data mode
|
|
182
|
+ ST7560_WriteSequence((uint8_t)pb->width, (uint8_t*)pb->buf);
|
|
183
|
+ ST7565_CS(); // disable chip
|
|
184
|
+ ST7565_NA0(); // instruction mode
|
|
185
|
+ ST7565_NCS(); // enable chip
|
|
186
|
+ ST7565_WRITE_BYTE(0x10); // set upper 4 bit of the col adr to 0x10
|
|
187
|
+ ST7565_WRITE_BYTE(0x00); // set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N
|
|
188
|
+ // end of sequence
|
|
189
|
+ ST7565_WRITE_BYTE(0xB0 | (2 * pb->p.page + 1)); // select current page (ST7565R)
|
|
190
|
+ ST7565_A0(); // data mode
|
|
191
|
+ ST7560_WriteSequence((uint8_t)pb->width, (uint8_t*)(pb->buf)+pb->width);
|
|
192
|
+ ST7565_CS(); // disable chip
|
196
|
193
|
}
|
197
|
194
|
break;
|
198
|
195
|
case U8G_DEV_MSG_CONTRAST:
|
199
|
196
|
ST7565_NCS();
|
200
|
|
- ST7565_NA0(); /* instruction mode */
|
201
|
|
- ST7565_WRITE_BYTE(0x081);
|
|
197
|
+ ST7565_NA0(); // instruction mode
|
|
198
|
+ ST7565_WRITE_BYTE(0x81);
|
202
|
199
|
ST7565_WRITE_BYTE((*(uint8_t *)arg) >> 2);
|
203
|
|
- ST7565_CS(); /* disable chip */
|
|
200
|
+ ST7565_CS(); // disable chip
|
204
|
201
|
return 1;
|
205
|
202
|
case U8G_DEV_MSG_SLEEP_ON:
|
206
|
|
- ST7565_NA0(); /* instruction mode */
|
207
|
|
- ST7565_NCS(); /* enable chip */
|
208
|
|
- ST7565_WRITE_BYTE(0x0ac); /* static indicator off */
|
209
|
|
- ST7565_WRITE_BYTE(0x000); /* indicator register set (not sure if this is required) */
|
210
|
|
- ST7565_WRITE_BYTE(0x0ae); /* display off */
|
211
|
|
- ST7565_WRITE_BYTE(0x0a5); /* all points on */
|
212
|
|
- ST7565_CS(); /* disable chip , bugfix 12 nov 2014 */
|
213
|
|
- /* end of sequence */
|
|
203
|
+ ST7565_NA0(); // instruction mode
|
|
204
|
+ ST7565_NCS(); // enable chip
|
|
205
|
+ ST7565_WRITE_BYTE(0xAC); // static indicator off
|
|
206
|
+ ST7565_WRITE_BYTE(0x00); // indicator register set (not sure if this is required)
|
|
207
|
+ ST7565_WRITE_BYTE(0xAE); // display off
|
|
208
|
+ ST7565_WRITE_BYTE(0xA5); // all points on
|
|
209
|
+ ST7565_CS(); // disable chip , bugfix 12 nov 2014
|
|
210
|
+ // end of sequence
|
214
|
211
|
return 1;
|
215
|
212
|
case U8G_DEV_MSG_SLEEP_OFF:
|
216
|
|
- ST7565_NA0(); /* instruction mode */
|
217
|
|
- ST7565_NCS(); /* enable chip */
|
218
|
|
- ST7565_WRITE_BYTE(0x0a4); /* all points off */
|
219
|
|
- ST7565_WRITE_BYTE(0x0af); /* display on */
|
220
|
|
- U8G_ESC_DLY(50); /* delay 50 ms */
|
221
|
|
- ST7565_CS(); /* disable chip , bugfix 12 nov 2014 */
|
222
|
|
- /* end of sequence */
|
|
213
|
+ ST7565_NA0(); // instruction mode
|
|
214
|
+ ST7565_NCS(); // enable chip
|
|
215
|
+ ST7565_WRITE_BYTE(0xA4); // all points off
|
|
216
|
+ ST7565_WRITE_BYTE(0xAF); // display on
|
|
217
|
+ U8G_ESC_DLY(50); // delay 50 ms
|
|
218
|
+ ST7565_CS(); // disable chip , bugfix 12 nov 2014
|
|
219
|
+ // end of sequence
|
223
|
220
|
return 1;
|
224
|
221
|
}
|
225
|
222
|
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
|
226
|
223
|
}
|
227
|
224
|
|
228
|
|
-uint8_t u8g_dev_st7565_64128n_2x_VIKI_buf[WIDTH*2] U8G_NOCOMMON ;
|
229
|
|
-u8g_pb_t u8g_dev_st7565_64128n_2x_VIKI_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7565_64128n_2x_VIKI_buf};
|
230
|
|
-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};
|
231
|
|
-
|
|
225
|
+uint8_t u8g_dev_st7565_64128n_2x_VIKI_buf[WIDTH*2] U8G_NOCOMMON;
|
|
226
|
+u8g_pb_t u8g_dev_st7565_64128n_2x_VIKI_pb = { { 16, HEIGHT, 0, 0, 0 }, WIDTH, u8g_dev_st7565_64128n_2x_VIKI_buf };
|
|
227
|
+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 };
|
232
|
228
|
|
233
|
229
|
class U8GLIB_ST7565_64128n_2x_VIKI : public U8GLIB {
|
234
|
230
|
public:
|
|
@@ -240,9 +236,6 @@ class U8GLIB_ST7565_64128n_2x_VIKI : public U8GLIB {
|
240
|
236
|
{ }
|
241
|
237
|
};
|
242
|
238
|
|
243
|
|
-
|
244
|
|
-
|
245
|
239
|
#pragma GCC reset_options
|
246
|
240
|
|
247
|
|
-#endif // U8GLIB_ST7565
|
248
|
241
|
#endif // ULCDST7565_H
|