aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2017-07-10 10:49:50 +0300
committerJack Humbert <jack.humb@gmail.com>2017-07-10 09:01:59 -0400
commit551924f8a02b374201f7d0066755fa183a45accf (patch)
tree6d088f5b752380fcbd44d961e34025d43ca13ce5
parent190b90892bf1b17f5cb24a1e7bd88c63047c3eb0 (diff)
downloadqmk_firmware-551924f8a02b374201f7d0066755fa183a45accf.tar.gz
qmk_firmware-551924f8a02b374201f7d0066755fa183a45accf.zip
Add template board files
-rw-r--r--drivers/ugfx/gdisp/is31fl3731c/board_is31fl3731c_template.h110
-rw-r--r--drivers/ugfx/gdisp/st7565/board_st7565_template.h113
2 files changed, 223 insertions, 0 deletions
diff --git a/drivers/ugfx/gdisp/is31fl3731c/board_is31fl3731c_template.h b/drivers/ugfx/gdisp/is31fl3731c/board_is31fl3731c_template.h
new file mode 100644
index 000000000..f248cc25b
--- /dev/null
+++ b/drivers/ugfx/gdisp/is31fl3731c/board_is31fl3731c_template.h
@@ -0,0 +1,110 @@
1/*
2Copyright 2016 Fred Sundvik <fsundvik@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef _GDISP_LLD_BOARD_H
19#define _GDISP_LLD_BOARD_H
20
21static const I2CConfig i2ccfg = {
22 400000 // clock speed (Hz); 400kHz max for IS31
23};
24
25static const uint8_t led_mask[] = {
26 0xFF, 0x00, /* C1-1 -> C1-16 */
27 0xFF, 0x00, /* C2-1 -> C2-16 */
28 0xFF, 0x00, /* C3-1 -> C3-16 */
29 0xFF, 0x00, /* C4-1 -> C4-16 */
30 0x3F, 0x00, /* C5-1 -> C5-16 */
31 0x00, 0x00, /* C6-1 -> C6-16 */
32 0x00, 0x00, /* C7-1 -> C7-16 */
33 0x00, 0x00, /* C8-1 -> C8-16 */
34 0x00, 0x00, /* C9-1 -> C9-16 */
35};
36
37// The address of the LED
38#define LA(c, r) (c + r * 16 )
39// Need to be an address that is not mapped, but inside the range of the controller matrix
40#define NA LA(8, 8)
41
42// The numbers in the comments are the led numbers DXX on the PCB
43// The mapping is taken from the schematic of left hand side
44static const uint8_t led_mapping[GDISP_SCREEN_HEIGHT][GDISP_SCREEN_WIDTH] = {
45// 45 44 43 42 41 40 39
46 { LA(1, 1), LA(1, 0), LA(0, 4), LA(0, 3), LA(0, 2), LA(0, 1), LA(0, 0)},
47// 52 51 50 49 48 47 46
48 { LA(2, 3), LA(2, 2), LA(2, 1), LA(2, 0), LA(1, 4), LA(1, 3), LA(1, 2) },
49// 58 57 56 55 54 53 N/A
50 { LA(3, 4), LA(3, 3), LA(3, 2), LA(3, 1), LA(3, 0), LA(2, 4), NA },
51// 67 66 65 64 63 62 61
52 { LA(5, 3), LA(5, 2), LA(5, 1), LA(5, 0), LA(4, 4), LA(4, 3), LA(4, 2) },
53// 76 75 74 73 72 60 59
54 { LA(7, 3), LA(7, 2), LA(7, 1), LA(7, 0), LA(6, 3), LA(4, 1), LA(4, 0) },
55// N/A N/A N/A N/A N/A N/A 68
56 { NA, NA, NA, NA, NA, NA, LA(5, 4) },
57// N/A N/A N/A N/A 71 70 69
58 { NA, NA, NA, NA, LA(6, 2), LA(6, 1), LA(6, 0) },
59};
60
61
62#define IS31_ADDR_DEFAULT 0x74 // AD connected to GND
63#define IS31_TIMEOUT 5000
64
65static GFXINLINE void init_board(GDisplay *g) {
66 (void) g;
67 /* I2C pins */
68 palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATIVE_2); // PTB0/I2C0/SCL
69 palSetPadMode(GPIOB, 1, PAL_MODE_ALTERNATIVE_2); // PTB1/I2C0/SDA
70 palSetPadMode(GPIOB, 16, PAL_MODE_OUTPUT_PUSHPULL);
71 palClearPad(GPIOB, 16);
72 /* start I2C */
73 i2cStart(&I2CD1, &i2ccfg);
74 // try high drive (from kiibohd)
75 I2CD1.i2c->C2 |= I2Cx_C2_HDRS;
76 // try glitch fixing (from kiibohd)
77 I2CD1.i2c->FLT = 4;
78}
79
80static GFXINLINE void post_init_board(GDisplay *g) {
81 (void) g;
82}
83
84static GFXINLINE const uint8_t* get_led_mask(GDisplay* g) {
85 (void) g;
86 return led_mask;
87}
88
89static GFXINLINE uint8_t get_led_address(GDisplay* g, uint16_t x, uint16_t y)
90{
91 (void) g;
92 return led_mapping[y][x];
93}
94
95static GFXINLINE void set_hardware_shutdown(GDisplay* g, bool shutdown) {
96 (void) g;
97 if(!shutdown) {
98 palSetPad(GPIOB, 16);
99 }
100 else {
101 palClearPad(GPIOB, 16);
102 }
103}
104
105static GFXINLINE void write_data(GDisplay *g, uint8_t* data, uint16_t length) {
106 (void) g;
107 i2cMasterTransmitTimeout(&I2CD1, IS31_ADDR_DEFAULT, data, length, 0, 0, US2ST(IS31_TIMEOUT));
108}
109
110#endif /* _GDISP_LLD_BOARD_H */
diff --git a/drivers/ugfx/gdisp/st7565/board_st7565_template.h b/drivers/ugfx/gdisp/st7565/board_st7565_template.h
new file mode 100644
index 000000000..9ab636c95
--- /dev/null
+++ b/drivers/ugfx/gdisp/st7565/board_st7565_template.h
@@ -0,0 +1,113 @@
1/*
2 * This file is subject to the terms of the GFX License. If a copy of
3 * the license was not distributed with this file, you can obtain one at:
4 *
5 * http://ugfx.org/license.html
6 */
7
8#ifndef _GDISP_LLD_BOARD_H
9#define _GDISP_LLD_BOARD_H
10
11#define ST7565_LCD_BIAS ST7565_LCD_BIAS_9 // actually 6
12#define ST7565_ADC ST7565_ADC_NORMAL
13#define ST7565_COM_SCAN ST7565_COM_SCAN_DEC
14#define ST7565_PAGE_ORDER 0,1,2,3
15/*
16 * 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 */
19
20#define ST7565_GPIOPORT GPIOC
21#define ST7565_PORT PORTC
22#define ST7565_A0_PIN 7
23#define ST7565_RST_PIN 8
24#define ST7565_MOSI_PIN 6
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
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
36// Frame Size: 8 bits
37// MSB First
38// CLK Low by default
39static const SPIConfig spi1config = {
40 // Operation complete callback or @p NULL.
41 .end_cb = NULL,
42 //The chip select line port - when not using pcs.
43 .ssport = ST7565_GPIOPORT,
44 // brief The chip select line pad number - when not using pcs.
45 .sspad=ST7565_SS_PIN,
46 // SPI initialization data.
47 .tar0 =
48 SPIx_CTARn_FMSZ(7) // Frame size = 8 bytes
49 | SPIx_CTARn_ASC(1) // After SCK Delay Scaler (min 50 ns) = 55.56ns
50 | SPIx_CTARn_DT(0) // Delay After Transfer Scaler (no minimum)= 27.78ns
51 | SPIx_CTARn_CSSCK(0) // PCS to SCK Delay Scaler (min 20 ns) = 27.78ns
52 | SPIx_CTARn_PBR(0) // Baud Rate Prescaler = 2
53 | SPIx_CTARn_BR(0) // Baud rate (min 50ns) = 55.56ns
54};
55
56static GFXINLINE void acquire_bus(GDisplay *g) {
57 (void) g;
58 // Only the LCD is using the SPI bus, so no need to acquire
59 // spiAcquireBus(&SPID1);
60 spiSelect(&SPID1);
61}
62
63static GFXINLINE void release_bus(GDisplay *g) {
64 (void) g;
65 // Only the LCD is using the SPI bus, so no need to release
66 //spiReleaseBus(&SPID1);
67 spiUnselect(&SPID1);
68}
69
70static GFXINLINE void init_board(GDisplay *g) {
71 (void) g;
72 palSetPadModeNamed(A0, PAL_MODE_OUTPUT_PUSHPULL);
73 palSetPad(ST7565_GPIOPORT, ST7565_A0_PIN);
74 palSetPadModeNamed(RST, PAL_MODE_OUTPUT_PUSHPULL);
75 palSetPad(ST7565_GPIOPORT, ST7565_RST_PIN);
76 palSetPadModeRaw(MOSI, ST7565_SPI_MODE);
77 palSetPadModeRaw(SLCK, ST7565_SPI_MODE);
78 palSetPadModeNamed(SS, PAL_MODE_OUTPUT_PUSHPULL);
79
80 spiInit();
81 spiStart(&SPID1, &spi1config);
82 release_bus(g);
83}
84
85static GFXINLINE void post_init_board(GDisplay *g) {
86 (void) g;
87}
88
89static GFXINLINE void setpin_reset(GDisplay *g, bool_t state) {
90 (void) g;
91 if (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}
102
103static GFXINLINE void enter_cmd_mode(GDisplay *g) {
104 palClearPad(ST7565_GPIOPORT, ST7565_A0_PIN);
105}
106
107
108static GFXINLINE void write_data(GDisplay *g, uint8_t* data, uint16_t length) {
109 (void) g;
110 spiSend(&SPID1, length, data);
111}
112
113#endif /* _GDISP_LLD_BOARD_H */