aboutsummaryrefslogtreecommitdiff
path: root/keyboards/ergodox_infinity/board_st7565.h
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/ergodox_infinity/board_st7565.h')
-rw-r--r--keyboards/ergodox_infinity/board_st7565.h107
1 files changed, 45 insertions, 62 deletions
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