Commit | Line | Data |
---|---|---|
9772e697 FS |
1 | /* |
2 | Copyright 2016 Fred Sundvik <fsundvik@gmail.com> | |
3 | ||
4 | This program is free software: you can redistribute it and/or modify | |
5 | it under the terms of the GNU General Public License as published by | |
6 | the Free Software Foundation, either version 2 of the License, or | |
7 | (at your option) any later version. | |
8 | ||
9 | This program is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
15 | along 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 | ||
21 | static const I2CConfig i2ccfg = { | |
22 | 400000 // clock speed (Hz); 400kHz max for IS31 | |
23 | }; | |
24 | ||
9772e697 FS |
25 | static 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 | |
44 | static 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 | ||
65 | static 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 | ||
80 | static GFXINLINE void post_init_board(GDisplay *g) { | |
81 | (void) g; | |
82 | } | |
83 | ||
84 | static GFXINLINE const uint8_t* get_led_mask(GDisplay* g) { | |
85 | (void) g; | |
86 | return led_mask; | |
87 | } | |
88 | ||
89 | static 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 | ||
95 | static 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 | ||
105 | static GFXINLINE void write_data(GDisplay *g, uint8_t* data, uint16_t length) { | |
106 | (void) g; | |
26eef35f | 107 | i2cMasterTransmitTimeout(&I2CD1, IS31_ADDR_DEFAULT, data, length, 0, 0, TIME_US2I(IS31_TIMEOUT)); |
9772e697 FS |
108 | } |
109 | ||
110 | #endif /* _GDISP_LLD_BOARD_H */ |