aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2020-11-26 23:44:17 +1100
committerGitHub <noreply@github.com>2020-11-26 23:44:17 +1100
commit3afe0ea9b9f67ae33f54c1393b15d988764241a2 (patch)
treeeb2c1527bd7ed3e4f06d8b742afab564bd8168e8
parent1c0e8a6bb4718c693e24d87c19ccca435d2f1f58 (diff)
downloadqmk_firmware-3afe0ea9b9f67ae33f54c1393b15d988764241a2.tar.gz
qmk_firmware-3afe0ea9b9f67ae33f54c1393b15d988764241a2.zip
ST7565 tidyup (#10907)
-rw-r--r--drivers/ugfx/gdisp/st7565/board_st7565_template.h58
-rw-r--r--drivers/ugfx/gdisp/st7565/driver.mk2
-rw-r--r--drivers/ugfx/gdisp/st7565/gdisp_lld_ST7565.c76
-rw-r--r--keyboards/ergodox_infinity/board_st7565.h107
-rw-r--r--quantum/quantum.h2
-rw-r--r--quantum/visualizer/lcd_keyframes.c4
-rw-r--r--quantum/visualizer/resources/lcd_logo.c24
-rw-r--r--quantum/visualizer/resources/lcd_logo.pngbin490 -> 271 bytes
-rw-r--r--quantum/visualizer/visualizer.mk10
9 files changed, 130 insertions, 153 deletions
diff --git a/drivers/ugfx/gdisp/st7565/board_st7565_template.h b/drivers/ugfx/gdisp/st7565/board_st7565_template.h
index 194f8ea24..875ed9e65 100644
--- a/drivers/ugfx/gdisp/st7565/board_st7565_template.h
+++ b/drivers/ugfx/gdisp/st7565/board_st7565_template.h
@@ -8,8 +8,9 @@
8#ifndef _GDISP_LLD_BOARD_H 8#ifndef _GDISP_LLD_BOARD_H
9#define _GDISP_LLD_BOARD_H 9#define _GDISP_LLD_BOARD_H
10 10
11#define ST7565_LCD_BIAS ST7565_LCD_BIAS_9 // actually 6 11#include "quantum.h"
12#define ST7565_ADC ST7565_ADC_NORMAL 12
13#define ST7565_LCD_BIAS ST7565_LCD_BIAS_7
13#define ST7565_COM_SCAN ST7565_COM_SCAN_DEC 14#define ST7565_COM_SCAN ST7565_COM_SCAN_DEC
14#define ST7565_PAGE_ORDER 0, 1, 2, 3 15#define ST7565_PAGE_ORDER 0, 1, 2, 3
15/* 16/*
@@ -17,19 +18,12 @@
17 * #define ST7565_PAGE_ORDER 4,5,6,7,0,1,2,3 18 * #define ST7565_PAGE_ORDER 4,5,6,7,0,1,2,3
18 */ 19 */
19 20
20#define ST7565_GPIOPORT GPIOC 21#define ST7565_A0_PIN C7
21#define ST7565_PORT PORTC 22#define ST7565_RST_PIN C8
22#define ST7565_A0_PIN 7 23#define ST7565_MOSI_PIN C6
23#define ST7565_RST_PIN 8 24#define ST7565_SCLK_PIN C5
24#define ST7565_MOSI_PIN 6 25#define ST7565_SS_PIN C4
25#define ST7565_SLCK_PIN 5
26#define ST7565_SS_PIN 4
27
28#define palSetPadModeRaw(portname, bits) ST7565_PORT->PCR[ST7565_##portname##_PIN] = bits
29 26
30#define palSetPadModeNamed(portname, portmode) palSetPadMode(ST7565_GPIOPORT, ST7565_##portname##_PIN, portmode)
31
32#define ST7565_SPI_MODE PORTx_PCRn_DSE | PORTx_PCRn_MUX(2)
33// DSPI Clock and Transfer Attributes 27// DSPI Clock and Transfer Attributes
34// Frame Size: 8 bits 28// Frame Size: 8 bits
35// MSB First 29// MSB First
@@ -38,9 +32,9 @@ static const SPIConfig spi1config = {
38 // Operation complete callback or @p NULL. 32 // Operation complete callback or @p NULL.
39 .end_cb = NULL, 33 .end_cb = NULL,
40 // The chip select line port - when not using pcs. 34 // The chip select line port - when not using pcs.
41 .ssport = ST7565_GPIOPORT, 35 .ssport = PAL_PORT(ST7565_SS_PIN),
42 // brief The chip select line pad number - when not using pcs. 36 // brief The chip select line pad number - when not using pcs.
43 .sspad = ST7565_SS_PIN, 37 .sspad = PAL_PAD(ST7565_SS_PIN),
44 // SPI initialization data. 38 // SPI initialization data.
45 .tar0 = SPIx_CTARn_FMSZ(7) // Frame size = 8 bytes 39 .tar0 = SPIx_CTARn_FMSZ(7) // Frame size = 8 bytes
46 | SPIx_CTARn_ASC(1) // After SCK Delay Scaler (min 50 ns) = 55.56ns 40 | SPIx_CTARn_ASC(1) // After SCK Delay Scaler (min 50 ns) = 55.56ns
@@ -66,13 +60,14 @@ static GFXINLINE void release_bus(GDisplay *g) {
66 60
67static GFXINLINE void init_board(GDisplay *g) { 61static GFXINLINE void init_board(GDisplay *g) {
68 (void)g; 62 (void)g;
69 palSetPadModeNamed(A0, PAL_MODE_OUTPUT_PUSHPULL); 63 setPinOutput(ST7565_A0_PIN);
70 palSetPad(ST7565_GPIOPORT, ST7565_A0_PIN); 64 writePinHigh(ST7565_A0_PIN);
71 palSetPadModeNamed(RST, PAL_MODE_OUTPUT_PUSHPULL); 65 setPinOutput(ST7565_RST_PIN);
72 palSetPad(ST7565_GPIOPORT, ST7565_RST_PIN); 66 writePinHigh(ST7565_RST_PIN);
73 palSetPadModeRaw(MOSI, ST7565_SPI_MODE); 67 setPinOutput(ST7565_SS_PIN);
74 palSetPadModeRaw(SLCK, ST7565_SPI_MODE); 68
75 palSetPadModeNamed(SS, PAL_MODE_OUTPUT_PUSHPULL); 69 palSetPadMode(PAL_PORT(ST7565_MOSI_PIN), PAL_PAD(ST7565_MOSI_PIN), PAL_MODE_ALTERNATIVE_2);
70 palSetPadMode(PAL_PORT(ST7565_SCLK_PIN), PAL_PAD(ST7565_SCLK_PIN), PAL_MODE_ALTERNATIVE_2);
76 71
77 spiInit(); 72 spiInit();
78 spiStart(&SPID1, &spi1config); 73 spiStart(&SPID1, &spi1config);
@@ -83,19 +78,18 @@ static GFXINLINE void post_init_board(GDisplay *g) { (void)g; }
83 78
84static GFXINLINE void setpin_reset(GDisplay *g, bool_t state) { 79static GFXINLINE void setpin_reset(GDisplay *g, bool_t state) {
85 (void)g; 80 (void)g;
86 if (state) { 81 writePin(ST7565_RST_PIN, !state);
87 palClearPad(ST7565_GPIOPORT, ST7565_RST_PIN);
88 } else {
89 palSetPad(ST7565_GPIOPORT, ST7565_RST_PIN);
90 }
91} 82}
92 83
93static GFXINLINE void enter_data_mode(GDisplay *g) { palSetPad(ST7565_GPIOPORT, ST7565_A0_PIN); } 84static GFXINLINE void write_cmd(GDisplay *g, gU8 cmd) {
94 85 (void)g;
95static GFXINLINE void enter_cmd_mode(GDisplay *g) { palClearPad(ST7565_GPIOPORT, ST7565_A0_PIN); } 86 writePinLow(ST7565_A0_PIN);
87 spiSend(&SPID1, 1, &cmd);
88}
96 89
97static GFXINLINE void write_data(GDisplay *g, uint8_t *data, uint16_t length) { 90static GFXINLINE void write_data(GDisplay *g, gU8 *data, gU16 length) {
98 (void)g; 91 (void)g;
92 writePinHigh(ST7565_A0_PIN);
99 spiSend(&SPID1, length, data); 93 spiSend(&SPID1, length, data);
100} 94}
101 95
diff --git a/drivers/ugfx/gdisp/st7565/driver.mk b/drivers/ugfx/gdisp/st7565/driver.mk
index 31fc8f1c7..799a986b0 100644
--- a/drivers/ugfx/gdisp/st7565/driver.mk
+++ b/drivers/ugfx/gdisp/st7565/driver.mk
@@ -1,3 +1,3 @@
1GFXINC += drivers/ugfx/gdisp/st7565 1GFXINC += drivers/ugfx/gdisp/st7565
2GFXSRC += drivers/ugfx/gdisp/st7565/gdisp_lld_ST7565.c 2GFXSRC += drivers/ugfx/gdisp/st7565/gdisp_lld_ST7565.c
3GDISP_DRIVER_LIST += GDISPVMT_ST7565_QMK \ No newline at end of file 3GDISP_DRIVER_LIST += GDISPVMT_ST7565_QMK
diff --git a/drivers/ugfx/gdisp/st7565/gdisp_lld_ST7565.c b/drivers/ugfx/gdisp/st7565/gdisp_lld_ST7565.c
index fde320981..f586f97e3 100644
--- a/drivers/ugfx/gdisp/st7565/gdisp_lld_ST7565.c
+++ b/drivers/ugfx/gdisp/st7565/gdisp_lld_ST7565.c
@@ -49,31 +49,15 @@
49# define ST7565_COM_SCAN ST7565_COM_SCAN_INC 49# define ST7565_COM_SCAN ST7565_COM_SCAN_INC
50# endif 50# endif
51# ifndef ST7565_PAGE_ORDER 51# ifndef ST7565_PAGE_ORDER
52# define ST7565_PAGE_ORDER 0, 1, 2, 3 52# define ST7565_PAGE_ORDER 0, 1, 2, 3, 4, 5, 6, 7
53# endif 53# endif
54 54
55/*===========================================================================*/ 55/*===========================================================================*/
56/* Driver local functions. */ 56/* Driver local functions. */
57/*===========================================================================*/ 57/*===========================================================================*/
58 58
59typedef struct {
60 bool_t buffer2;
61 uint8_t data_pos;
62 uint8_t data[16];
63 uint8_t ram[GDISP_SCREEN_HEIGHT * GDISP_SCREEN_WIDTH / 8];
64} PrivData;
65
66// Some common routines and macros 59// Some common routines and macros
67# define PRIV(g) ((PrivData *)g->priv) 60# define RAM(g) ((gU8 *)g->priv)
68# define RAM(g) (PRIV(g)->ram)
69
70static GFXINLINE void write_cmd(GDisplay *g, uint8_t cmd) { PRIV(g)->data[PRIV(g)->data_pos++] = cmd; }
71
72static GFXINLINE void flush_cmd(GDisplay *g) {
73 write_data(g, PRIV(g)->data, PRIV(g)->data_pos);
74 PRIV(g)->data_pos = 0;
75}
76
77# define write_cmd2(g, cmd1, cmd2) \ 61# define write_cmd2(g, cmd1, cmd2) \
78 { \ 62 { \
79 write_cmd(g, cmd1); \ 63 write_cmd(g, cmd1); \
@@ -106,9 +90,10 @@ static GFXINLINE void flush_cmd(GDisplay *g) {
106 90
107LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { 91LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
108 // The private area is the display surface. 92 // The private area is the display surface.
109 g->priv = gfxAlloc(sizeof(PrivData)); 93 g->priv = gfxAlloc(GDISP_SCREEN_HEIGHT * GDISP_SCREEN_WIDTH / 8);
110 PRIV(g)->buffer2 = false; 94 if (!g->priv) {
111 PRIV(g)->data_pos = 0; 95 return gFalse;
96 }
112 97
113 // Initialise the board interface 98 // Initialise the board interface
114 init_board(g); 99 init_board(g);
@@ -119,25 +104,33 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
119 setpin_reset(g, FALSE); 104 setpin_reset(g, FALSE);
120 gfxSleepMilliseconds(20); 105 gfxSleepMilliseconds(20);
121 acquire_bus(g); 106 acquire_bus(g);
122 enter_cmd_mode(g);
123 107
124 write_cmd(g, ST7565_RESET);
125 write_cmd(g, ST7565_LCD_BIAS); 108 write_cmd(g, ST7565_LCD_BIAS);
126 write_cmd(g, ST7565_ADC); 109 write_cmd(g, ST7565_ADC);
127 write_cmd(g, ST7565_COM_SCAN); 110 write_cmd(g, ST7565_COM_SCAN);
128 111
112 write_cmd(g, ST7565_START_LINE | 0);
113
114 write_cmd2(g, ST7565_CONTRAST, GDISP_INITIAL_CONTRAST * 64 / 101);
129 write_cmd(g, ST7565_RESISTOR_RATIO | 0x1); 115 write_cmd(g, ST7565_RESISTOR_RATIO | 0x1);
130 write_cmd2(g, ST7565_CONTRAST, GDISP_INITIAL_CONTRAST);
131 116
132 // turn on internal power supply (VC=1, VR=1, VF=1) 117 // turn on voltage converter (VC=1, VR=0, VF=0)
118 write_cmd(g, ST7565_POWER_CONTROL | 0x04);
119 delay_ms(50);
120
121 // turn on voltage regulator (VC=1, VR=1, VF=0)
122 write_cmd(g, ST7565_POWER_CONTROL | 0x06);
123 delay_ms(50);
124
125 // turn on voltage follower (VC=1, VR=1, VF=1)
133 write_cmd(g, ST7565_POWER_CONTROL | 0x07); 126 write_cmd(g, ST7565_POWER_CONTROL | 0x07);
127 delay_ms(50);
134 128
135 write_cmd(g, ST7565_INVERT_DISPLAY); 129 write_cmd(g, ST7565_DISPLAY_ON);
136 write_cmd(g, ST7565_ALLON_NORMAL); 130 write_cmd(g, ST7565_ALLON_NORMAL);
131 write_cmd(g, ST7565_INVERT_DISPLAY); // Disable Inversion of display.
137 132
138 write_cmd(g, ST7565_START_LINE | 0);
139 write_cmd(g, ST7565_RMW); 133 write_cmd(g, ST7565_RMW);
140 flush_cmd(g);
141 134
142 // Finish Init 135 // Finish Init
143 post_init_board(g); 136 post_init_board(g);
@@ -163,22 +156,14 @@ LLDSPEC void gdisp_lld_flush(GDisplay *g) {
163 if (!(g->flags & GDISP_FLG_NEEDFLUSH)) return; 156 if (!(g->flags & GDISP_FLG_NEEDFLUSH)) return;
164 157
165 acquire_bus(g); 158 acquire_bus(g);
166 enter_cmd_mode(g); 159 gU8 pagemap[] = {ST7565_PAGE_ORDER};
167 unsigned dstOffset = (PRIV(g)->buffer2 ? 4 : 0); 160 for (p = 0; p < sizeof(pagemap); p++) {
168 for (p = 0; p < 4; p++) { 161 write_cmd(g, ST7565_PAGE | pagemap[p]);
169 write_cmd(g, ST7565_PAGE | (p + dstOffset));
170 write_cmd(g, ST7565_COLUMN_MSB | 0); 162 write_cmd(g, ST7565_COLUMN_MSB | 0);
171 write_cmd(g, ST7565_COLUMN_LSB | 0); 163 write_cmd(g, ST7565_COLUMN_LSB | 0);
172 write_cmd(g, ST7565_RMW); 164 write_cmd(g, ST7565_RMW);
173 flush_cmd(g);
174 enter_data_mode(g);
175 write_data(g, RAM(g) + (p * GDISP_SCREEN_WIDTH), GDISP_SCREEN_WIDTH); 165 write_data(g, RAM(g) + (p * GDISP_SCREEN_WIDTH), GDISP_SCREEN_WIDTH);
176 enter_cmd_mode(g);
177 } 166 }
178 unsigned line = (PRIV(g)->buffer2 ? 32 : 0);
179 write_cmd(g, ST7565_START_LINE | line);
180 flush_cmd(g);
181 PRIV(g)->buffer2 = !PRIV(g)->buffer2;
182 release_bus(g); 167 release_bus(g);
183 168
184 g->flags &= ~GDISP_FLG_NEEDFLUSH; 169 g->flags &= ~GDISP_FLG_NEEDFLUSH;
@@ -243,6 +228,7 @@ LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) {
243} 228}
244# endif 229# endif
245 230
231# if GDISP_HARDWARE_BITFILLS
246LLDSPEC void gdisp_lld_blit_area(GDisplay *g) { 232LLDSPEC void gdisp_lld_blit_area(GDisplay *g) {
247 uint8_t *buffer = (uint8_t *)g->p.ptr; 233 uint8_t *buffer = (uint8_t *)g->p.ptr;
248 int linelength = g->p.cx; 234 int linelength = g->p.cx;
@@ -268,6 +254,7 @@ LLDSPEC void gdisp_lld_blit_area(GDisplay *g) {
268 } 254 }
269 g->flags |= GDISP_FLG_NEEDFLUSH; 255 g->flags |= GDISP_FLG_NEEDFLUSH;
270} 256}
257# endif
271 258
272# if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL 259# if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
273LLDSPEC void gdisp_lld_control(GDisplay *g) { 260LLDSPEC void gdisp_lld_control(GDisplay *g) {
@@ -279,16 +266,12 @@ LLDSPEC void gdisp_lld_control(GDisplay *g) {
279 case powerSleep: 266 case powerSleep:
280 case powerDeepSleep: 267 case powerDeepSleep:
281 acquire_bus(g); 268 acquire_bus(g);
282 enter_cmd_mode(g);
283 write_cmd(g, ST7565_DISPLAY_OFF); 269 write_cmd(g, ST7565_DISPLAY_OFF);
284 flush_cmd(g);
285 release_bus(g); 270 release_bus(g);
286 break; 271 break;
287 case powerOn: 272 case powerOn:
288 acquire_bus(g); 273 acquire_bus(g);
289 enter_cmd_mode(g);
290 write_cmd(g, ST7565_DISPLAY_ON); 274 write_cmd(g, ST7565_DISPLAY_ON);
291 flush_cmd(g);
292 release_bus(g); 275 release_bus(g);
293 break; 276 break;
294 default: 277 default:
@@ -318,12 +301,11 @@ LLDSPEC void gdisp_lld_control(GDisplay *g) {
318 return; 301 return;
319 302
320 case GDISP_CONTROL_CONTRAST: 303 case GDISP_CONTROL_CONTRAST:
321 g->g.Contrast = (unsigned)g->p.ptr & 63; 304 if ((unsigned)g->p.ptr > 100) g->p.ptr = (void *)100;
322 acquire_bus(g); 305 acquire_bus(g);
323 enter_cmd_mode(g); 306 write_cmd2(g, ST7565_CONTRAST, ((((unsigned)g->p.ptr) << 6) / 101) & 0x3F);
324 write_cmd2(g, ST7565_CONTRAST, g->g.Contrast);
325 flush_cmd(g);
326 release_bus(g); 307 release_bus(g);
308 g->g.Contrast = (unsigned)g->p.ptr;
327 return; 309 return;
328 } 310 }
329} 311}
diff --git a/keyboards/ergodox_infinity/board_st7565.h b/keyboards/ergodox_infinity/board_st7565.h
index 9ab636c95..875ed9e65 100644
--- a/keyboards/ergodox_infinity/board_st7565.h
+++ b/keyboards/ergodox_infinity/board_st7565.h
@@ -8,105 +8,88 @@
8#ifndef _GDISP_LLD_BOARD_H 8#ifndef _GDISP_LLD_BOARD_H
9#define _GDISP_LLD_BOARD_H 9#define _GDISP_LLD_BOARD_H
10 10
11#define ST7565_LCD_BIAS ST7565_LCD_BIAS_9 // actually 6 11#include "quantum.h"
12#define ST7565_ADC ST7565_ADC_NORMAL 12
13#define ST7565_COM_SCAN ST7565_COM_SCAN_DEC 13#define ST7565_LCD_BIAS ST7565_LCD_BIAS_7
14#define ST7565_PAGE_ORDER 0,1,2,3 14#define ST7565_COM_SCAN ST7565_COM_SCAN_DEC
15#define ST7565_PAGE_ORDER 0, 1, 2, 3
15/* 16/*
16 * Custom page order for several LCD boards, e.g. HEM12864-99 17 * Custom page order for several LCD boards, e.g. HEM12864-99
17 * #define ST7565_PAGE_ORDER 4,5,6,7,0,1,2,3 18 * #define ST7565_PAGE_ORDER 4,5,6,7,0,1,2,3
18 */ 19 */
19 20
20#define ST7565_GPIOPORT GPIOC 21#define ST7565_A0_PIN C7
21#define ST7565_PORT PORTC 22#define ST7565_RST_PIN C8
22#define ST7565_A0_PIN 7 23#define ST7565_MOSI_PIN C6
23#define ST7565_RST_PIN 8 24#define ST7565_SCLK_PIN C5
24#define ST7565_MOSI_PIN 6 25#define ST7565_SS_PIN C4
25#define ST7565_SLCK_PIN 5
26#define ST7565_SS_PIN 4
27
28#define palSetPadModeRaw(portname, bits) \
29 ST7565_PORT->PCR[ST7565_##portname##_PIN] = bits
30 26
31#define palSetPadModeNamed(portname, portmode) \
32 palSetPadMode(ST7565_GPIOPORT, ST7565_##portname##_PIN, portmode)
33
34#define ST7565_SPI_MODE PORTx_PCRn_DSE | PORTx_PCRn_MUX(2)
35// DSPI Clock and Transfer Attributes 27// DSPI Clock and Transfer Attributes
36// Frame Size: 8 bits 28// Frame Size: 8 bits
37// MSB First 29// MSB First
38// CLK Low by default 30// CLK Low by default
39static const SPIConfig spi1config = { 31static const SPIConfig spi1config = {
40 // Operation complete callback or @p NULL. 32 // Operation complete callback or @p NULL.
41 .end_cb = NULL, 33 .end_cb = NULL,
42 //The chip select line port - when not using pcs. 34 // The chip select line port - when not using pcs.
43 .ssport = ST7565_GPIOPORT, 35 .ssport = PAL_PORT(ST7565_SS_PIN),
44 // brief The chip select line pad number - when not using pcs. 36 // brief The chip select line pad number - when not using pcs.
45 .sspad=ST7565_SS_PIN, 37 .sspad = PAL_PAD(ST7565_SS_PIN),
46 // SPI initialization data. 38 // SPI initialization data.
47 .tar0 = 39 .tar0 = SPIx_CTARn_FMSZ(7) // Frame size = 8 bytes
48 SPIx_CTARn_FMSZ(7) // Frame size = 8 bytes 40 | SPIx_CTARn_ASC(1) // After SCK Delay Scaler (min 50 ns) = 55.56ns
49 | SPIx_CTARn_ASC(1) // After SCK Delay Scaler (min 50 ns) = 55.56ns 41 | SPIx_CTARn_DT(0) // Delay After Transfer Scaler (no minimum)= 27.78ns
50 | SPIx_CTARn_DT(0) // Delay After Transfer Scaler (no minimum)= 27.78ns 42 | SPIx_CTARn_CSSCK(0) // PCS to SCK Delay Scaler (min 20 ns) = 27.78ns
51 | SPIx_CTARn_CSSCK(0) // PCS to SCK Delay Scaler (min 20 ns) = 27.78ns 43 | SPIx_CTARn_PBR(0) // Baud Rate Prescaler = 2
52 | SPIx_CTARn_PBR(0) // Baud Rate Prescaler = 2 44 | SPIx_CTARn_BR(0) // Baud rate (min 50ns) = 55.56ns
53 | SPIx_CTARn_BR(0) // Baud rate (min 50ns) = 55.56ns
54}; 45};
55 46
56static GFXINLINE void acquire_bus(GDisplay *g) { 47static GFXINLINE void acquire_bus(GDisplay *g) {
57 (void) g; 48 (void)g;
58 // Only the LCD is using the SPI bus, so no need to acquire 49 // Only the LCD is using the SPI bus, so no need to acquire
59 // spiAcquireBus(&SPID1); 50 // spiAcquireBus(&SPID1);
60 spiSelect(&SPID1); 51 spiSelect(&SPID1);
61} 52}
62 53
63static GFXINLINE void release_bus(GDisplay *g) { 54static GFXINLINE void release_bus(GDisplay *g) {
64 (void) g; 55 (void)g;
65 // Only the LCD is using the SPI bus, so no need to release 56 // Only the LCD is using the SPI bus, so no need to release
66 //spiReleaseBus(&SPID1); 57 // spiReleaseBus(&SPID1);
67 spiUnselect(&SPID1); 58 spiUnselect(&SPID1);
68} 59}
69 60
70static GFXINLINE void init_board(GDisplay *g) { 61static GFXINLINE void init_board(GDisplay *g) {
71 (void) g; 62 (void)g;
72 palSetPadModeNamed(A0, PAL_MODE_OUTPUT_PUSHPULL); 63 setPinOutput(ST7565_A0_PIN);
73 palSetPad(ST7565_GPIOPORT, ST7565_A0_PIN); 64 writePinHigh(ST7565_A0_PIN);
74 palSetPadModeNamed(RST, PAL_MODE_OUTPUT_PUSHPULL); 65 setPinOutput(ST7565_RST_PIN);
75 palSetPad(ST7565_GPIOPORT, ST7565_RST_PIN); 66 writePinHigh(ST7565_RST_PIN);
76 palSetPadModeRaw(MOSI, ST7565_SPI_MODE); 67 setPinOutput(ST7565_SS_PIN);
77 palSetPadModeRaw(SLCK, ST7565_SPI_MODE); 68
78 palSetPadModeNamed(SS, PAL_MODE_OUTPUT_PUSHPULL); 69 palSetPadMode(PAL_PORT(ST7565_MOSI_PIN), PAL_PAD(ST7565_MOSI_PIN), PAL_MODE_ALTERNATIVE_2);
70 palSetPadMode(PAL_PORT(ST7565_SCLK_PIN), PAL_PAD(ST7565_SCLK_PIN), PAL_MODE_ALTERNATIVE_2);
79 71
80 spiInit(); 72 spiInit();
81 spiStart(&SPID1, &spi1config); 73 spiStart(&SPID1, &spi1config);
82 release_bus(g); 74 release_bus(g);
83} 75}
84 76
85static GFXINLINE void post_init_board(GDisplay *g) { 77static GFXINLINE void post_init_board(GDisplay *g) { (void)g; }
86 (void) g;
87}
88 78
89static GFXINLINE void setpin_reset(GDisplay *g, bool_t state) { 79static GFXINLINE void setpin_reset(GDisplay *g, bool_t state) {
90 (void) g; 80 (void)g;
91 if (state) { 81 writePin(ST7565_RST_PIN, !state);
92 palClearPad(ST7565_GPIOPORT, ST7565_RST_PIN);
93 }
94 else {
95 palSetPad(ST7565_GPIOPORT, ST7565_RST_PIN);
96 }
97}
98
99static GFXINLINE void enter_data_mode(GDisplay *g) {
100 palSetPad(ST7565_GPIOPORT, ST7565_A0_PIN);
101} 82}
102 83
103static GFXINLINE void enter_cmd_mode(GDisplay *g) { 84static GFXINLINE void write_cmd(GDisplay *g, gU8 cmd) {
104 palClearPad(ST7565_GPIOPORT, ST7565_A0_PIN); 85 (void)g;
86 writePinLow(ST7565_A0_PIN);
87 spiSend(&SPID1, 1, &cmd);
105} 88}
106 89
107 90static GFXINLINE void write_data(GDisplay *g, gU8 *data, gU16 length) {
108static GFXINLINE void write_data(GDisplay *g, uint8_t* data, uint16_t length) { 91 (void)g;
109 (void) g; 92 writePinHigh(ST7565_A0_PIN);
110 spiSend(&SPID1, length, data); 93 spiSend(&SPID1, length, data);
111} 94}
112 95
diff --git a/quantum/quantum.h b/quantum/quantum.h
index a2c0ec9a2..0e452a062 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -213,7 +213,7 @@ typedef ioline_t pin_t;
213 213
214# define writePinHigh(pin) palSetLine(pin) 214# define writePinHigh(pin) palSetLine(pin)
215# define writePinLow(pin) palClearLine(pin) 215# define writePinLow(pin) palClearLine(pin)
216# define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin)) 216# define writePin(pin, level) ((level) ? (writePinHigh(pin)) : (writePinLow(pin)))
217 217
218# define readPin(pin) palReadLine(pin) 218# define readPin(pin) palReadLine(pin)
219 219
diff --git a/quantum/visualizer/lcd_keyframes.c b/quantum/visualizer/lcd_keyframes.c
index c7d9841df..1d6f3dca1 100644
--- a/quantum/visualizer/lcd_keyframes.c
+++ b/quantum/visualizer/lcd_keyframes.c
@@ -157,14 +157,14 @@ bool lcd_keyframe_draw_logo(keyframe_animation_t* animation, visualizer_state_t*
157 (void)animation; 157 (void)animation;
158 // Read the uGFX documentation for information how to use the displays 158 // Read the uGFX documentation for information how to use the displays
159 // http://wiki.ugfx.org/index.php/Main_Page 159 // http://wiki.ugfx.org/index.php/Main_Page
160 gdispClear(White); 160 gdispClear(Black);
161 161
162 // You can use static variables for things that can't be found in the animation 162 // You can use static variables for things that can't be found in the animation
163 // or state structs, here we use the image 163 // or state structs, here we use the image
164 164
165 // gdispGBlitArea is a tricky function to use since it supports blitting part of the image 165 // gdispGBlitArea is a tricky function to use since it supports blitting part of the image
166 // if you have full screen image, then just use LCD_WIDTH and LCD_HEIGHT for both source and target dimensions 166 // if you have full screen image, then just use LCD_WIDTH and LCD_HEIGHT for both source and target dimensions
167 gdispGBlitArea(GDISP, 0, 0, LCD_WIDTH, LCD_HEIGHT, 0, 0, LCD_WIDTH, (pixel_t*)resource_lcd_logo); 167 gdispGBlitArea(GDISP, 0, 0, 128, 32, 0, 0, LCD_WIDTH, (pixel_t*)resource_lcd_logo);
168 168
169 return false; 169 return false;
170} 170}
diff --git a/quantum/visualizer/resources/lcd_logo.c b/quantum/visualizer/resources/lcd_logo.c
index 165e6d1f5..13bf734cb 100644
--- a/quantum/visualizer/resources/lcd_logo.c
+++ b/quantum/visualizer/resources/lcd_logo.c
@@ -16,6 +16,8 @@
16 16
17#include "resources.h" 17#include "resources.h"
18 18
19// clang-format off
20
19// To generate an image array like this 21// To generate an image array like this
20// Ensure the image is 128 x 32 or smaller 22// Ensure the image is 128 x 32 or smaller
21// Convert the bitmap to a C array using a program like http://www.riuson.com/lcd-image-converter/ 23// Convert the bitmap to a C array using a program like http://www.riuson.com/lcd-image-converter/
@@ -23,7 +25,21 @@
23// Update array in the source code with the C array produced by the conversion program 25// Update array in the source code with the C array produced by the conversion program
24 26
25// The image below is generated from lcd_logo.png 27// The image below is generated from lcd_logo.png
26__attribute__((weak)) const uint8_t resource_lcd_logo[512] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xfe, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 28__attribute__((weak)) const uint8_t resource_lcd_logo[512] = {
27 0x00, 0x38, 0x38, 0x38, 0x06, 0x29, 0x41, 0x24, 0x52, 0x24, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x42, 0xaa, 0xaa, 0xaa, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x82, 0x28, 0xaa, 0xae, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x43, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x38, 0x38, 0x0a, 0x55, 0x42, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x38, 0x38, 0x05, 0x45, 0x42, 0x28, 0x89, 0x4a, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x38, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 29 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
28 0x00, 0x0e, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0x80, 0x04, 0x45, 0x14, 0xa4, 0x92, 0x83, 0x52, 0x22, 0x22, 0x36, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0xba, 0x84, 0x55, 0x55, 0x57, 0x45, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0xb2, 0x55, 0x55, 0x42, 0x65, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x56, 0x65, 0x42, 0x45, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x54, 0x45, 0x42, 0x45, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x04, 0x48, 0xa2, 0x4a, 0x89, 0x06, 0x24, 0x42, 0x41, 0x36, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 30 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
29 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 31 0x00, 0x02, 0x92, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x92, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
32 0x00, 0x02, 0x92, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33 0x00, 0x1F, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34 0x00, 0xFE, 0xEE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0xEE, 0xF0, 0x01, 0xC6, 0x0D, 0x8C, 0x1F, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
35 0x00, 0xFE, 0xEE, 0xFE, 0x03, 0xE7, 0x1D, 0x9C, 0x1F, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0xEE, 0xF0, 0x06, 0x37, 0x1D, 0xB8, 0x18, 0x0B, 0x59, 0xC8, 0x09, 0xE5, 0x9E, 0x00,
36 0x00, 0x1E, 0xEE, 0xF0, 0x06, 0x37, 0xBD, 0xF0, 0x18, 0x6F, 0x7F, 0xEC, 0x9B, 0x37, 0xB3, 0x00, 0x00, 0xFE, 0xEE, 0xFE, 0x06, 0x37, 0xBD, 0xE0, 0x1F, 0x6C, 0x66, 0x6D, 0xD8, 0x36, 0x33, 0x00,
37 0x00, 0x1E, 0xEE, 0xF0, 0x06, 0x36, 0xED, 0xF0, 0x1F, 0x6C, 0x66, 0x6D, 0x59, 0xF6, 0x3E, 0x00, 0x00, 0x1F, 0x6D, 0xF0, 0x06, 0x36, 0xED, 0xB8, 0x18, 0x6C, 0x66, 0x67, 0x73, 0x36, 0x30, 0x00,
38 0x00, 0xFF, 0x83, 0xFE, 0x03, 0xE6, 0x4D, 0x9C, 0x18, 0x6C, 0x66, 0x67, 0x73, 0x36, 0x1F, 0x00, 0x00, 0x1F, 0xEF, 0xF0, 0x01, 0xC6, 0x0D, 0x8C, 0x18, 0x6C, 0x66, 0x62, 0x21, 0xD6, 0x0E, 0x00,
39 0x00, 0xFF, 0xEF, 0xFE, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xF0, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40 0x00, 0x1F, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
41 0x00, 0x02, 0x92, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x92, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42 0x00, 0x02, 0x92, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
45};
diff --git a/quantum/visualizer/resources/lcd_logo.png b/quantum/visualizer/resources/lcd_logo.png
index 6cf26fc67..178ef65f1 100644
--- a/quantum/visualizer/resources/lcd_logo.png
+++ b/quantum/visualizer/resources/lcd_logo.png
Binary files differ
diff --git a/quantum/visualizer/visualizer.mk b/quantum/visualizer/visualizer.mk
index 3bf3f7de6..4c961ac59 100644
--- a/quantum/visualizer/visualizer.mk
+++ b/quantum/visualizer/visualizer.mk
@@ -58,12 +58,14 @@ ULIBS += -lm
58endif 58endif
59 59
60ifeq ($(strip $(LCD_ENABLE)), yes) 60ifeq ($(strip $(LCD_ENABLE)), yes)
61SRC += $(VISUALIZER_DIR)/lcd_backlight.c 61 SRC += $(VISUALIZER_DIR)/lcd_keyframes.c
62SRC += $(VISUALIZER_DIR)/lcd_keyframes.c 62 ifeq ($(strip $(LCD_BACKLIGHT_ENABLE)), yes)
63SRC += $(VISUALIZER_DIR)/lcd_backlight_keyframes.c 63 OPT_DEFS += -DLCD_BACKLIGHT_ENABLE
64 SRC += $(VISUALIZER_DIR)/lcd_backlight.c
65 SRC += $(VISUALIZER_DIR)/lcd_backlight_keyframes.c
66 endif
64# Note, that the linker will strip out any resources that are not actually in use 67# Note, that the linker will strip out any resources that are not actually in use
65SRC += $(VISUALIZER_DIR)/resources/lcd_logo.c 68SRC += $(VISUALIZER_DIR)/resources/lcd_logo.c
66OPT_DEFS += -DLCD_BACKLIGHT_ENABLE
67$(eval $(call ADD_DRIVER,LCD)) 69$(eval $(call ADD_DRIVER,LCD))
68endif 70endif
69 71