aboutsummaryrefslogtreecommitdiff
path: root/keyboards/chidori/board.h
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/chidori/board.h')
-rw-r--r--keyboards/chidori/board.h190
1 files changed, 190 insertions, 0 deletions
diff --git a/keyboards/chidori/board.h b/keyboards/chidori/board.h
new file mode 100644
index 000000000..892ea6c0f
--- /dev/null
+++ b/keyboards/chidori/board.h
@@ -0,0 +1,190 @@
1/* Copyright 2019 ENDO Katsuhiro <[email protected]>
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#pragma once
17
18#define NUM_ROWS 4
19#define NUM_COLS 6
20#define NUM_LEDS 2
21
22#define LED_GREEN 0
23#define LED_YELLOW 1
24
25typedef struct board_info_t board_info_t;
26typedef struct board_interface_t board_interface_t;
27
28struct board_info_t {
29 bool master;
30 bool initialized;
31 uint8_t i2c_address;
32 pin_t row_pins[NUM_ROWS];
33 pin_t col_pins[NUM_COLS];
34 pin_t led_pins[NUM_LEDS];
35 bool led_status[NUM_LEDS];
36 board_interface_t* interface;
37};
38
39struct board_interface_t {
40 void (*select_row)(board_info_t* board, uint8_t row);
41 void (*unselect_row)(board_info_t* board, uint8_t row);
42 void (*unselect_rows)(board_info_t* board);
43 bool (*read_cols_on_row)(board_info_t* board, matrix_row_t current_matrix[], uint8_t row);
44 void (*set_led)(board_info_t* board, uint8_t led_index, bool status);
45};
46
47#define BOARD_I2C_TIMEOUT 20
48
49#define GPA0 0x00
50#define GPA1 0x01
51#define GPA2 0x02
52#define GPA3 0x03
53#define GPA4 0x04
54#define GPA5 0x05
55#define GPA6 0x06
56#define GPA7 0x07
57#define GPB0 0x08
58#define GPB1 0x09
59#define GPB2 0x0A
60#define GPB3 0x0B
61#define GPB4 0x0C
62#define GPB5 0x0D
63#define GPB6 0x0E
64#define GPB7 0x0F
65
66//#define PORTA 0x00
67//#define PORTB 0x01
68#define PORT_MASK 0x08
69#define PIN_MASK 0x07
70
71#define PIN2REGISTER(reg, pin) (reg & ((pin & PORT_MASK) >> 3))
72#define PIN2PORT(pin) ((pin & PORT_MASK) >> 3)
73#define PIN2MASK(pin) (~(1 << PIN2INDEX(pin)))
74#define PIN2INDEX(pin) (pin & ~PORT_MASK)
75#define PIN2BIT(pin) (1 << PIN2INDEX(pin))
76
77#define EXPANDER_ADDR(addr) (addr << 1)
78
79#define EXPANDER_IODIR(pin) (0x00 | PIN2PORT(pin))
80#define EXPANDER_IPOL(pin) (0x02 | PIN2PORT(pin))
81#define EXPANDER_GPINTEN(pin) (0x04 | PIN2PORT(pin))
82#define EXPANDER_DEFVAL(pin) (0x06 | PIN2PORT(pin))
83#define EXPANDER_INTCON(pin) (0x08 | PIN2PORT(pin))
84#define EXPANDER_IOCON(pin) (0x0A | PIN2PORT(pin))
85#define EXPANDER_GPPU(pin) (0x0C | PIN2PORT(pin))
86#define EXPANDER_INTF(pin) (0x0E | PIN2PORT(pin))
87#define EXPANDER_INTCAP(pin) (0x10 | PIN2PORT(pin))
88#define EXPANDER_GPIO(pin) (0x12 | PIN2PORT(pin))
89#define EXPANDER_OLAT(pin) (0x14 | PIN2PORT(pin))
90
91#define EXPANDER_IODIRA 0x00
92#define EXPANDER_IODIRB 0x01
93#define EXPANDER_IPOLA 0x02
94#define EXPANDER_IPOLB 0x03
95#define EXPANDER_GPINTENA 0x04
96#define EXPANDER_GPINTENB 0x05
97#define EXPANDER_DEFVALA 0x06
98#define EXPANDER_DEFVALB 0x07
99#define EXPANDER_INTCONA 0x08
100#define EXPANDER_INTCONB 0x09
101#define EXPANDER_IOCONA 0x0A
102#define EXPANDER_IOCONB 0x0B
103#define EXPANDER_GPPUA 0x0C
104#define EXPANDER_GPPUB 0x0D
105#define EXPANDER_INTFA 0x0E
106#define EXPANDER_INTFB 0x0F
107#define EXPANDER_INTCAPA 0x10
108#define EXPANDER_INTCAPB 0x11
109#define EXPANDER_GPIOA 0x12
110#define EXPANDER_GPIOB 0x13
111#define EXPANDER_OLATA 0x14
112#define EXPANDER_OLATB 0x15
113
114//
115// Default board config
116//
117#ifndef NUM_BOARDS
118# define NUM_BOARDS 2
119#endif
120
121// clang-format off
122#ifndef BOARD_INFOS
123#if NUM_BOARDS == 2
124#define BOARD_INFOS \
125{ \
126 { \
127 true, \
128 false, \
129 0x00, \
130 { D4, D5, D6, D7 }, \
131 { D1, D0, C3, C2, C1, C0 }, \
132 { B1, B2 }, \
133 { false, false }, \
134 NULL \
135 }, \
136 { \
137 false, \
138 false, \
139 0x20, \
140 { GPB4, GPB5, GPB6, GPB7 }, \
141 { GPA7, GPA6, GPA5, GPA4, GPA3, GPA2 }, \
142 { GPB0, GPB1 }, \
143 { false, false }, \
144 NULL \
145 }, \
146}
147#elif NUM_BOARDS == 3
148#define BOARD_INFOS \
149{ \
150 { \
151 true, \
152 false, \
153 0x00, \
154 { D4, D5, D6, D7 }, \
155 { D1, D0, C3, C2, C1, C0 }, \
156 { B1, B2 }, \
157 { false, false }, \
158 NULL \
159 }, \
160 { \
161 false, \
162 false, \
163 0x20, \
164 { GPB4, GPB5, GPB6, GPB7 }, \
165 { GPA7, GPA6, GPA5, GPA4, GPA3, GPA2 }, \
166 { GPB0, GPB1 }, \
167 { false, false }, \
168 NULL \
169 }, \
170 { \
171 false, \
172 false, \
173 0x21, \
174 { GPB4, GPB5, GPB6, GPB7 }, \
175 { GPA7, GPA6, GPA5, GPA4, GPA3, GPA2 }, \
176 { GPB0, GPB1 }, \
177 { false, false }, \
178 NULL \
179 }, \
180}
181#endif
182#endif
183// clang-format on
184
185void board_set_led_by_index(uint8_t board_index, uint8_t led_index, bool status);
186bool board_read_cols_on_row(matrix_row_t current_matrix[], uint8_t row);
187void board_select_row(uint8_t row);
188void board_unselect_row(uint8_t row);
189void board_unselect_rows(void);
190void board_init(void);