aboutsummaryrefslogtreecommitdiff
path: root/keyboards/wheatfield/split75/matrix.c
diff options
context:
space:
mode:
authorartjomsR <artjomsR@users.noreply.github.com>2020-04-07 09:36:54 +0100
committerGitHub <noreply@github.com>2020-04-07 01:36:54 -0700
commit3349a8b49bdfad5c6ec33090bc898cd49446f34e (patch)
tree3e4e6903cf0a6816e5acee8ddf1fb368926c26ba /keyboards/wheatfield/split75/matrix.c
parentb4ef72423ea2b2d314e4373f82bdc955b8d6ec10 (diff)
downloadqmk_firmware-3349a8b49bdfad5c6ec33090bc898cd49446f34e.tar.gz
qmk_firmware-3349a8b49bdfad5c6ec33090bc898cd49446f34e.zip
[Keyboard] Wheatfield Split75 (#8511)
* Added split75 keyboard * tidy up commented out code + removed default * added visual map * proper led functions. more layers for keymap * led functions. moved mod keys to numbers * double tapping toggle + leds on power on * media keys fix * clean up of commented out code and unnecessary functions. readme update. default keymap * removed bootloadHID file * Update keyboards/split75/config.h * Update keyboards/split75/config.h * Update keyboards/split75/config.h * Update keyboards/split75/config.h * removed python flashing script * Update keyboards/split75/keymaps/default/keymap.c * Update keyboards/split75/split75.h * Update keyboards/split75/keymaps/art/keymap.c * Update keyboards/split75/keymaps/art/keymap.c * Update keyboards/split75/keymaps/art/keymap.c * Update keyboards/split75/keymaps/default/keymap.c * reintroduced empty matrix_scan_user to default keymap * Update keyboards/split75/keymaps/art/keymap.c * Update keyboards/split75/keymaps/art/keymap.c * Update keyboards/split75/usbconfig.h * Update keyboards/ergodone/config.h * Update keyboards/split75/keymaps/art/keymap.c * updated readme file * Update keyboards/split75/usbconfig.h * Update keyboards/split75/rules.mk * Update keyboards/split75/split75.c * code fix after suggestions * defined tapping toggle as double tap * added info.json * Update keyboards/split75/config.h * fix for leds not displaying properly when initialising * Update keyboards/split75/README.md * Update keyboards/split75/keymaps/default/keymap.c * Update keyboards/split75/keymaps/art/keymap.c * changed product description fields * renamed user functions * indentation fix * Update keyboards/split75/usbconfig.h * Update keyboards/split75/usbconfig.h * Update keyboards/split75/usbconfig.h * Update keyboards/split75/usbconfig.h * Update keyboards/split75/usbconfig.h * Update keyboards/split75/split75.c * Update keyboards/split75/split75.c * art keymap update * Update keyboards/split75/config.h * Update keyboards/split75/keymaps/art/keymap.c * Update keyboards/split75/keymaps/art/keymap.c * Update keyboards/split75/keymaps/art/keymap.c * Update keyboards/split75/keymaps/art/keymap.c * Update keyboards/split75/keymaps/art/keymap.c * Update keyboards/split75/split75.c * Update keyboards/split75/keymaps/art/keymap.c * Update keyboards/split75/keymaps/default/keymap.c * Update keyboards/split75/split75.c * Update keyboards/split75/matrix.c * Update keyboards/split75/rules.mk * Update keyboards/split75/split75.c * Update keyboards/split75/split75.c * Update keyboards/split75/split75.c * Update keyboards/split75/config.h * Update keyboards/split75/split75.c * disable underglow on sleep and enabled backlighting * Update keyboards/split75/usbconfig.h * Update keyboards/split75/usbconfig.h * Update keyboards/split75/usbconfig.h * Update keyboards/split75/usbconfig.h * Update keyboards/split75/usbconfig.h * Update keyboards/split75/usbconfig.h * personal keymap update * changed boot animation * consistent whitespace * Tidied up default notes and unnecessary comments * Unique Vendor ID * remove usb config file * corrected manufacturer * Update keyboards/split75/config.h * Update keyboards/split75/README.md * Update keyboards/split75/split75.c * Update keyboards/split75/split75.c * Update keyboards/split75/split75.c * Update keyboards/split75/split75.c * Update keyboards/split75/split75.c * Update keyboards/split75/split75.c * Update keyboards/split75/split75.h * Update keyboards/split75/split75.h * Update keyboards/split75/split75.h * Update keyboards/split75/split75.c * Update keyboards/split75/matrix.c * Update keyboards/split75/matrix.c * Update keyboards/split75/matrix.c * Update keyboards/split75/matrix.c * Update keyboards/split75/split75.h * Personal keymap restore after refactor * Moved to wheatfield folder + updated readme
Diffstat (limited to 'keyboards/wheatfield/split75/matrix.c')
-rw-r--r--keyboards/wheatfield/split75/matrix.c155
1 files changed, 155 insertions, 0 deletions
diff --git a/keyboards/wheatfield/split75/matrix.c b/keyboards/wheatfield/split75/matrix.c
new file mode 100644
index 000000000..9e86bfc37
--- /dev/null
+++ b/keyboards/wheatfield/split75/matrix.c
@@ -0,0 +1,155 @@
1/*
2Copyright 2017 Luiz Ribeiro <luizribeiro@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#include <string.h>
19#include <stdio.h>
20#include "quantum.h"
21#include "i2c_master.h"
22#include "split75.h"
23
24#define RIGHT_HALF
25
26
27void matrix_set_row_status(uint8_t row);
28
29
30#if defined(RIGHT_HALF)
31#define I2C_TIMEOUT 10
32#define MCP23018_TWI_ADDRESS 0b0100000
33#define TW_READ 1
34#define TW_WRITE 0
35#define TWI_ADDR_WRITE ( (MCP23018_TWI_ADDRESS<<1) | TW_WRITE )
36#define TWI_ADDR_READ ( (MCP23018_TWI_ADDRESS<<1) | TW_READ )
37#define IODIRA 0x00 // i/o direction register
38#define IODIRB 0x01
39#define IODIRA 0x00 // i/o direction register
40#define IODIRB 0x01
41#define GPPUA 0x0C // GPIO pull-up resistor register
42#define GPPUB 0x0D
43#define GPIOA 0x12 // general purpose i/o port register (write modifies OLAT)
44#define GPIOB 0x13
45#define OLATA 0x14 // output latch register
46#define OLATB 0x15
47#define MCP_ROWS_START 8
48
49static uint8_t mcp23018_init(void) {
50 uint8_t ret;
51 uint8_t data[3];
52 // set pin direction
53 // - unused : input : 1
54 // - input : input : 1
55 // - driving : output : 0
56 data[0] = IODIRA;
57 data[1] = 0b00000000; // IODIRA
58 data[2] = (0b11111111); // IODIRB
59
60 ret = i2c_transmit(TWI_ADDR_WRITE, (uint8_t *)data, 3, I2C_TIMEOUT);
61 if (ret) goto out; // make sure we got an ACK
62
63 // set pull-up
64 // - unused : on : 1
65 // - input : on : 1
66 // - driving : off : 0
67 data[0] = GPPUA;
68 data[1] = 0b00000000; // IODIRA
69 data[2] = (0b11111111); // IODIRB
70
71 ret = i2c_transmit(TWI_ADDR_WRITE, (uint8_t *)data, 3, I2C_TIMEOUT);
72 if (ret) goto out; // make sure we got an ACK
73
74 // set logical value (doesn't matter on inputs)
75 // - unused : hi-Z : 1
76 // - input : hi-Z : 1
77 // - driving : hi-Z : 1
78 data[0] = OLATA;
79 data[1] = 0b11111111; // IODIRA
80 data[2] = (0b11111111); // IODIRB
81
82 ret = i2c_transmit(TWI_ADDR_WRITE, (uint8_t *)data, 3, I2C_TIMEOUT);
83
84out:
85 return ret;
86}
87#endif
88
89void matrix_init_custom(void) {
90 // Set rows as output starting high
91 DDRB = 0xFF;
92 PORTB = 0xFF;
93
94 // Set columns as inputs with pull-up enabled
95 DDRA = 0x00;
96 PORTA = 0xFF;
97
98 // Initialize i2c communication
99 i2c_init();
100
101#if defined(RIGHT_HALF)
102 // Initialize the chip on the other half
103 mcp23018_init();
104#endif
105
106}
107
108bool matrix_scan_custom(matrix_row_t current_matrix[]) {
109 bool matrix_has_changed = false;
110
111 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
112 // Store last value of row prior to reading
113 matrix_row_t last_row_value = current_matrix[row];
114
115 matrix_row_t cols = 0;
116 // Select the row to scan
117 matrix_set_row_status(row);
118
119 matrix_io_delay();
120 //Set the local row
121
122#if defined(RIGHT_HALF)
123 // Initialize to 0x7F in case I2C read fails,
124 // as 0x75 would be no keys pressed
125 uint8_t data = 0x7F;
126 // Receive the columns from right half
127 i2c_receive(TWI_ADDR_WRITE, &data, 1, I2C_TIMEOUT);
128#endif
129
130 cols |= ((~(PINA | 0x80)) & 0x7F);
131#if defined(RIGHT_HALF)
132 cols |= (((~(data | 0x80)) & 0x7F) << 7);
133#endif
134
135 current_matrix[row] = cols;
136 matrix_has_changed |= (last_row_value != current_matrix[row]);
137 }
138
139 return matrix_has_changed;
140}
141
142void matrix_set_row_status(uint8_t row) {
143#if defined(RIGHT_HALF)
144 uint8_t txdata[3];
145
146 //Set the remote row on port A
147 txdata[0] = (GPIOA);
148 txdata[1] = ( 0xFF & ~(1<<row) );
149 i2c_transmit(TWI_ADDR_WRITE, (uint8_t *)txdata, 2, I2C_TIMEOUT);
150#endif
151
152 //Set the local row on port B
153 DDRB = (1 << row);
154 PORTB = ~(1 << row);
155}