aboutsummaryrefslogtreecommitdiff
path: root/keyboards/deltasplit75
diff options
context:
space:
mode:
authorZeal Jagannatha <zealjagannatha@gmail.com>2017-08-01 13:36:44 -0700
committerJack Humbert <jack.humb@gmail.com>2017-08-01 16:44:29 -0400
commitdd3803f334eced4feaf3d25ff7cff9303d9a26f2 (patch)
treed958b6de4ab988cef1aaa706216bd1e70a5284f3 /keyboards/deltasplit75
parentbd0a888133d7f7c701574ac467c0f4be71221cc7 (diff)
downloadqmk_firmware-dd3803f334eced4feaf3d25ff7cff9303d9a26f2.tar.gz
qmk_firmware-dd3803f334eced4feaf3d25ff7cff9303d9a26f2.zip
Normalize all line endings
Diffstat (limited to 'keyboards/deltasplit75')
-rw-r--r--keyboards/deltasplit75/i2c.c324
-rw-r--r--keyboards/deltasplit75/i2c.h62
-rw-r--r--keyboards/deltasplit75/keymaps/default/config.h62
-rw-r--r--keyboards/deltasplit75/matrix.c636
-rw-r--r--keyboards/deltasplit75/serial.c456
-rw-r--r--keyboards/deltasplit75/serial.h52
-rw-r--r--keyboards/deltasplit75/split_util.c162
-rw-r--r--keyboards/deltasplit75/split_util.h44
8 files changed, 899 insertions, 899 deletions
diff --git a/keyboards/deltasplit75/i2c.c b/keyboards/deltasplit75/i2c.c
index af806c75b..084c890c4 100644
--- a/keyboards/deltasplit75/i2c.c
+++ b/keyboards/deltasplit75/i2c.c
@@ -1,162 +1,162 @@
1#include <util/twi.h> 1#include <util/twi.h>
2#include <avr/io.h> 2#include <avr/io.h>
3#include <stdlib.h> 3#include <stdlib.h>
4#include <avr/interrupt.h> 4#include <avr/interrupt.h>
5#include <util/twi.h> 5#include <util/twi.h>
6#include <stdbool.h> 6#include <stdbool.h>
7#include "i2c.h" 7#include "i2c.h"
8 8
9#ifdef USE_I2C 9#ifdef USE_I2C
10 10
11// Limits the amount of we wait for any one i2c transaction. 11// Limits the amount of we wait for any one i2c transaction.
12// Since were running SCL line 100kHz (=> 10μs/bit), and each transactions is 12// Since were running SCL line 100kHz (=> 10μs/bit), and each transactions is
13// 9 bits, a single transaction will take around 90μs to complete. 13// 9 bits, a single transaction will take around 90μs to complete.
14// 14//
15// (F_CPU/SCL_CLOCK) => # of μC cycles to transfer a bit 15// (F_CPU/SCL_CLOCK) => # of μC cycles to transfer a bit
16// poll loop takes at least 8 clock cycles to execute 16// poll loop takes at least 8 clock cycles to execute
17#define I2C_LOOP_TIMEOUT (9+1)*(F_CPU/SCL_CLOCK)/8 17#define I2C_LOOP_TIMEOUT (9+1)*(F_CPU/SCL_CLOCK)/8
18 18
19#define BUFFER_POS_INC() (slave_buffer_pos = (slave_buffer_pos+1)%SLAVE_BUFFER_SIZE) 19#define BUFFER_POS_INC() (slave_buffer_pos = (slave_buffer_pos+1)%SLAVE_BUFFER_SIZE)
20 20
21volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE]; 21volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE];
22 22
23static volatile uint8_t slave_buffer_pos; 23static volatile uint8_t slave_buffer_pos;
24static volatile bool slave_has_register_set = false; 24static volatile bool slave_has_register_set = false;
25 25
26// Wait for an i2c operation to finish 26// Wait for an i2c operation to finish
27inline static 27inline static
28void i2c_delay(void) { 28void i2c_delay(void) {
29 uint16_t lim = 0; 29 uint16_t lim = 0;
30 while(!(TWCR & (1<<TWINT)) && lim < I2C_LOOP_TIMEOUT) 30 while(!(TWCR & (1<<TWINT)) && lim < I2C_LOOP_TIMEOUT)
31 lim++; 31 lim++;
32 32
33 // easier way, but will wait slightly longer 33 // easier way, but will wait slightly longer
34 // _delay_us(100); 34 // _delay_us(100);
35} 35}
36 36
37// Setup twi to run at 100kHz 37// Setup twi to run at 100kHz
38void i2c_master_init(void) { 38void i2c_master_init(void) {
39 // no prescaler 39 // no prescaler
40 TWSR = 0; 40 TWSR = 0;
41 // Set TWI clock frequency to SCL_CLOCK. Need TWBR>10. 41 // Set TWI clock frequency to SCL_CLOCK. Need TWBR>10.
42 // Check datasheets for more info. 42 // Check datasheets for more info.
43 TWBR = ((F_CPU/SCL_CLOCK)-16)/2; 43 TWBR = ((F_CPU/SCL_CLOCK)-16)/2;
44} 44}
45 45
46// Start a transaction with the given i2c slave address. The direction of the 46// Start a transaction with the given i2c slave address. The direction of the
47// transfer is set with I2C_READ and I2C_WRITE. 47// transfer is set with I2C_READ and I2C_WRITE.
48// returns: 0 => success 48// returns: 0 => success
49// 1 => error 49// 1 => error
50uint8_t i2c_master_start(uint8_t address) { 50uint8_t i2c_master_start(uint8_t address) {
51 TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTA); 51 TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTA);
52 52
53 i2c_delay(); 53 i2c_delay();
54 54
55 // check that we started successfully 55 // check that we started successfully
56 if ( (TW_STATUS != TW_START) && (TW_STATUS != TW_REP_START)) 56 if ( (TW_STATUS != TW_START) && (TW_STATUS != TW_REP_START))
57 return 1; 57 return 1;
58 58
59 TWDR = address; 59 TWDR = address;
60 TWCR = (1<<TWINT) | (1<<TWEN); 60 TWCR = (1<<TWINT) | (1<<TWEN);
61 61
62 i2c_delay(); 62 i2c_delay();
63 63
64 if ( (TW_STATUS != TW_MT_SLA_ACK) && (TW_STATUS != TW_MR_SLA_ACK) ) 64 if ( (TW_STATUS != TW_MT_SLA_ACK) && (TW_STATUS != TW_MR_SLA_ACK) )
65 return 1; // slave did not acknowledge 65 return 1; // slave did not acknowledge
66 else 66 else
67 return 0; // success 67 return 0; // success
68} 68}
69 69
70 70
71// Finish the i2c transaction. 71// Finish the i2c transaction.
72void i2c_master_stop(void) { 72void i2c_master_stop(void) {
73 TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); 73 TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
74 74
75 uint16_t lim = 0; 75 uint16_t lim = 0;
76 while(!(TWCR & (1<<TWSTO)) && lim < I2C_LOOP_TIMEOUT) 76 while(!(TWCR & (1<<TWSTO)) && lim < I2C_LOOP_TIMEOUT)
77 lim++; 77 lim++;
78} 78}
79 79
80// Write one byte to the i2c slave. 80// Write one byte to the i2c slave.
81// returns 0 => slave ACK 81// returns 0 => slave ACK
82// 1 => slave NACK 82// 1 => slave NACK
83uint8_t i2c_master_write(uint8_t data) { 83uint8_t i2c_master_write(uint8_t data) {
84 TWDR = data; 84 TWDR = data;
85 TWCR = (1<<TWINT) | (1<<TWEN); 85 TWCR = (1<<TWINT) | (1<<TWEN);
86 86
87 i2c_delay(); 87 i2c_delay();
88 88
89 // check if the slave acknowledged us 89 // check if the slave acknowledged us
90 return (TW_STATUS == TW_MT_DATA_ACK) ? 0 : 1; 90 return (TW_STATUS == TW_MT_DATA_ACK) ? 0 : 1;
91} 91}
92 92
93// Read one byte from the i2c slave. If ack=1 the slave is acknowledged, 93// Read one byte from the i2c slave. If ack=1 the slave is acknowledged,
94// if ack=0 the acknowledge bit is not set. 94// if ack=0 the acknowledge bit is not set.
95// returns: byte read from i2c device 95// returns: byte read from i2c device
96uint8_t i2c_master_read(int ack) { 96uint8_t i2c_master_read(int ack) {
97 TWCR = (1<<TWINT) | (1<<TWEN) | (ack<<TWEA); 97 TWCR = (1<<TWINT) | (1<<TWEN) | (ack<<TWEA);
98 98
99 i2c_delay(); 99 i2c_delay();
100 return TWDR; 100 return TWDR;
101} 101}
102 102
103void i2c_reset_state(void) { 103void i2c_reset_state(void) {
104 TWCR = 0; 104 TWCR = 0;
105} 105}
106 106
107void i2c_slave_init(uint8_t address) { 107void i2c_slave_init(uint8_t address) {
108 TWAR = address << 0; // slave i2c address 108 TWAR = address << 0; // slave i2c address
109 // TWEN - twi enable 109 // TWEN - twi enable
110 // TWEA - enable address acknowledgement 110 // TWEA - enable address acknowledgement
111 // TWINT - twi interrupt flag 111 // TWINT - twi interrupt flag
112 // TWIE - enable the twi interrupt 112 // TWIE - enable the twi interrupt
113 TWCR = (1<<TWIE) | (1<<TWEA) | (1<<TWINT) | (1<<TWEN); 113 TWCR = (1<<TWIE) | (1<<TWEA) | (1<<TWINT) | (1<<TWEN);
114} 114}
115 115
116ISR(TWI_vect); 116ISR(TWI_vect);
117 117
118ISR(TWI_vect) { 118ISR(TWI_vect) {
119 uint8_t ack = 1; 119 uint8_t ack = 1;
120 switch(TW_STATUS) { 120 switch(TW_STATUS) {
121 case TW_SR_SLA_ACK: 121 case TW_SR_SLA_ACK:
122 // this device has been addressed as a slave receiver 122 // this device has been addressed as a slave receiver
123 slave_has_register_set = false; 123 slave_has_register_set = false;
124 break; 124 break;
125 125
126 case TW_SR_DATA_ACK: 126 case TW_SR_DATA_ACK:
127 // this device has received data as a slave receiver 127 // this device has received data as a slave receiver
128 // The first byte that we receive in this transaction sets the location 128 // The first byte that we receive in this transaction sets the location
129 // of the read/write location of the slaves memory that it exposes over 129 // of the read/write location of the slaves memory that it exposes over
130 // i2c. After that, bytes will be written at slave_buffer_pos, incrementing 130 // i2c. After that, bytes will be written at slave_buffer_pos, incrementing
131 // slave_buffer_pos after each write. 131 // slave_buffer_pos after each write.
132 if(!slave_has_register_set) { 132 if(!slave_has_register_set) {
133 slave_buffer_pos = TWDR; 133 slave_buffer_pos = TWDR;
134 // don't acknowledge the master if this memory loctaion is out of bounds 134 // don't acknowledge the master if this memory loctaion is out of bounds
135 if ( slave_buffer_pos >= SLAVE_BUFFER_SIZE ) { 135 if ( slave_buffer_pos >= SLAVE_BUFFER_SIZE ) {
136 ack = 0; 136 ack = 0;
137 slave_buffer_pos = 0; 137 slave_buffer_pos = 0;
138 } 138 }
139 slave_has_register_set = true; 139 slave_has_register_set = true;
140 } else { 140 } else {
141 i2c_slave_buffer[slave_buffer_pos] = TWDR; 141 i2c_slave_buffer[slave_buffer_pos] = TWDR;
142 BUFFER_POS_INC(); 142 BUFFER_POS_INC();
143 } 143 }
144 break; 144 break;
145 145
146 case TW_ST_SLA_ACK: 146 case TW_ST_SLA_ACK:
147 case TW_ST_DATA_ACK: 147 case TW_ST_DATA_ACK:
148 // master has addressed this device as a slave transmitter and is 148 // master has addressed this device as a slave transmitter and is
149 // requesting data. 149 // requesting data.
150 TWDR = i2c_slave_buffer[slave_buffer_pos]; 150 TWDR = i2c_slave_buffer[slave_buffer_pos];
151 BUFFER_POS_INC(); 151 BUFFER_POS_INC();
152 break; 152 break;
153 153
154 case TW_BUS_ERROR: // something went wrong, reset twi state 154 case TW_BUS_ERROR: // something went wrong, reset twi state
155 TWCR = 0; 155 TWCR = 0;
156 default: 156 default:
157 break; 157 break;
158 } 158 }
159 // Reset everything, so we are ready for the next TWI interrupt 159 // Reset everything, so we are ready for the next TWI interrupt
160 TWCR |= (1<<TWIE) | (1<<TWINT) | (ack<<TWEA) | (1<<TWEN); 160 TWCR |= (1<<TWIE) | (1<<TWINT) | (ack<<TWEA) | (1<<TWEN);
161} 161}
162#endif 162#endif
diff --git a/keyboards/deltasplit75/i2c.h b/keyboards/deltasplit75/i2c.h
index cc3910806..08ce4b009 100644
--- a/keyboards/deltasplit75/i2c.h
+++ b/keyboards/deltasplit75/i2c.h
@@ -1,31 +1,31 @@
1#ifndef I2C_H 1#ifndef I2C_H
2#define I2C_H 2#define I2C_H
3 3
4#include <stdint.h> 4#include <stdint.h>
5 5
6#ifndef F_CPU 6#ifndef F_CPU
7#define F_CPU 16000000UL 7#define F_CPU 16000000UL
8#endif 8#endif
9 9
10#define I2C_READ 1 10#define I2C_READ 1
11#define I2C_WRITE 0 11#define I2C_WRITE 0
12 12
13#define I2C_ACK 1 13#define I2C_ACK 1
14#define I2C_NACK 0 14#define I2C_NACK 0
15 15
16#define SLAVE_BUFFER_SIZE 0x10 16#define SLAVE_BUFFER_SIZE 0x10
17 17
18// i2c SCL clock frequency 18// i2c SCL clock frequency
19#define SCL_CLOCK 100000L 19#define SCL_CLOCK 100000L
20 20
21extern volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE]; 21extern volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE];
22 22
23void i2c_master_init(void); 23void i2c_master_init(void);
24uint8_t i2c_master_start(uint8_t address); 24uint8_t i2c_master_start(uint8_t address);
25void i2c_master_stop(void); 25void i2c_master_stop(void);
26uint8_t i2c_master_write(uint8_t data); 26uint8_t i2c_master_write(uint8_t data);
27uint8_t i2c_master_read(int); 27uint8_t i2c_master_read(int);
28void i2c_reset_state(void); 28void i2c_reset_state(void);
29void i2c_slave_init(uint8_t address); 29void i2c_slave_init(uint8_t address);
30 30
31#endif 31#endif
diff --git a/keyboards/deltasplit75/keymaps/default/config.h b/keyboards/deltasplit75/keymaps/default/config.h
index c72c00e68..4fb2554e0 100644
--- a/keyboards/deltasplit75/keymaps/default/config.h
+++ b/keyboards/deltasplit75/keymaps/default/config.h
@@ -1,31 +1,31 @@
1/* 1/*
2Copyright 2012 Jun Wako <wakojun@gmail.com> 2Copyright 2012 Jun Wako <wakojun@gmail.com>
3 3
4This program is free software: you can redistribute it and/or modify 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 5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or 6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version. 7(at your option) any later version.
8 8
9This program is distributed in the hope that it will be useful, 9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of 10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details. 12GNU General Public License for more details.
13 13
14You should have received a copy of the GNU General Public License 14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>. 15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17 17
18 18
19#define USE_SERIAL 19#define USE_SERIAL
20 20
21#define MASTER_LEFT 21#define MASTER_LEFT
22// #define _MASTER_RIGHT 22// #define _MASTER_RIGHT
23// #define EE_HANDS 23// #define EE_HANDS
24 24
25 25
26#ifdef SUBPROJECT_v2 26#ifdef SUBPROJECT_v2
27 #include "../../v2/config.h" 27 #include "../../v2/config.h"
28#endif 28#endif
29#ifdef SUBPROJECT_protosplit 29#ifdef SUBPROJECT_protosplit
30 #include "../../protosplit/config.h" 30 #include "../../protosplit/config.h"
31#endif 31#endif
diff --git a/keyboards/deltasplit75/matrix.c b/keyboards/deltasplit75/matrix.c
index c3bb0b058..138969004 100644
--- a/keyboards/deltasplit75/matrix.c
+++ b/keyboards/deltasplit75/matrix.c
@@ -1,318 +1,318 @@
1/* 1/*
2Copyright 2012 Jun Wako <wakojun@gmail.com> 2Copyright 2012 Jun Wako <wakojun@gmail.com>
3 3
4This program is free software: you can redistribute it and/or modify 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 5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or 6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version. 7(at your option) any later version.
8 8
9This program is distributed in the hope that it will be useful, 9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of 10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details. 12GNU General Public License for more details.
13 13
14You should have received a copy of the GNU General Public License 14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>. 15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17 17
18/* 18/*
19 * scan matrix 19 * scan matrix
20 */ 20 */
21#include <stdint.h> 21#include <stdint.h>
22#include <stdbool.h> 22#include <stdbool.h>
23#include <avr/io.h> 23#include <avr/io.h>
24#include <avr/wdt.h> 24#include <avr/wdt.h>
25#include <avr/interrupt.h> 25#include <avr/interrupt.h>
26#include <util/delay.h> 26#include <util/delay.h>
27#include "print.h" 27#include "print.h"
28#include "debug.h" 28#include "debug.h"
29#include "util.h" 29#include "util.h"
30#include "matrix.h" 30#include "matrix.h"
31#include "split_util.h" 31#include "split_util.h"
32#include "pro_micro.h" 32#include "pro_micro.h"
33#include "config.h" 33#include "config.h"
34 34
35#ifdef USE_I2C 35#ifdef USE_I2C
36# include "i2c.h" 36# include "i2c.h"
37#else // USE_SERIAL 37#else // USE_SERIAL
38# include "serial.h" 38# include "serial.h"
39#endif 39#endif
40 40
41#ifndef DEBOUNCE 41#ifndef DEBOUNCE
42# define DEBOUNCE 5 42# define DEBOUNCE 5
43#endif 43#endif
44 44
45#define ERROR_DISCONNECT_COUNT 5 45#define ERROR_DISCONNECT_COUNT 5
46 46
47static uint8_t debouncing = DEBOUNCE; 47static uint8_t debouncing = DEBOUNCE;
48static const int ROWS_PER_HAND = MATRIX_ROWS/2; 48static const int ROWS_PER_HAND = MATRIX_ROWS/2;
49static uint8_t error_count = 0; 49static uint8_t error_count = 0;
50 50
51static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; 51static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
52static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; 52static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
53 53
54/* matrix state(1:on, 0:off) */ 54/* matrix state(1:on, 0:off) */
55static matrix_row_t matrix[MATRIX_ROWS]; 55static matrix_row_t matrix[MATRIX_ROWS];
56static matrix_row_t matrix_debouncing[MATRIX_ROWS]; 56static matrix_row_t matrix_debouncing[MATRIX_ROWS];
57 57
58static matrix_row_t read_cols(void); 58static matrix_row_t read_cols(void);
59static void init_cols(void); 59static void init_cols(void);
60static void unselect_rows(void); 60static void unselect_rows(void);
61static void select_row(uint8_t row); 61static void select_row(uint8_t row);
62 62
63__attribute__ ((weak)) 63__attribute__ ((weak))
64void matrix_init_quantum(void) { 64void matrix_init_quantum(void) {
65 matrix_init_kb(); 65 matrix_init_kb();
66} 66}
67 67
68__attribute__ ((weak)) 68__attribute__ ((weak))
69void matrix_scan_quantum(void) { 69void matrix_scan_quantum(void) {
70 matrix_scan_kb(); 70 matrix_scan_kb();
71} 71}
72 72
73__attribute__ ((weak)) 73__attribute__ ((weak))
74void matrix_init_kb(void) { 74void matrix_init_kb(void) {
75 matrix_init_user(); 75 matrix_init_user();
76} 76}
77 77
78__attribute__ ((weak)) 78__attribute__ ((weak))
79void matrix_scan_kb(void) { 79void matrix_scan_kb(void) {
80 matrix_scan_user(); 80 matrix_scan_user();
81} 81}
82 82
83__attribute__ ((weak)) 83__attribute__ ((weak))
84void matrix_init_user(void) { 84void matrix_init_user(void) {
85} 85}
86 86
87__attribute__ ((weak)) 87__attribute__ ((weak))
88void matrix_scan_user(void) { 88void matrix_scan_user(void) {
89} 89}
90 90
91inline 91inline
92uint8_t matrix_rows(void) 92uint8_t matrix_rows(void)
93{ 93{
94 return MATRIX_ROWS; 94 return MATRIX_ROWS;
95} 95}
96 96
97inline 97inline
98uint8_t matrix_cols(void) 98uint8_t matrix_cols(void)
99{ 99{
100 return MATRIX_COLS; 100 return MATRIX_COLS;
101} 101}
102 102
103void matrix_init(void) 103void matrix_init(void)
104{ 104{
105 debug_enable = true; 105 debug_enable = true;
106 debug_matrix = true; 106 debug_matrix = true;
107 debug_mouse = true; 107 debug_mouse = true;
108 // initialize row and col 108 // initialize row and col
109 unselect_rows(); 109 unselect_rows();
110 init_cols(); 110 init_cols();
111 111
112 TX_RX_LED_INIT; 112 TX_RX_LED_INIT;
113 113
114 // initialize matrix state: all keys off 114 // initialize matrix state: all keys off
115 for (uint8_t i=0; i < MATRIX_ROWS; i++) { 115 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
116 matrix[i] = 0; 116 matrix[i] = 0;
117 matrix_debouncing[i] = 0; 117 matrix_debouncing[i] = 0;
118 } 118 }
119 119
120 matrix_init_quantum(); 120 matrix_init_quantum();
121} 121}
122 122
123uint8_t _matrix_scan(void) 123uint8_t _matrix_scan(void)
124{ 124{
125 // Right hand is stored after the left in the matirx so, we need to offset it 125 // Right hand is stored after the left in the matirx so, we need to offset it
126 int offset = isLeftHand ? 0 : (ROWS_PER_HAND); 126 int offset = isLeftHand ? 0 : (ROWS_PER_HAND);
127 127
128 for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { 128 for (uint8_t i = 0; i < ROWS_PER_HAND; i++) {
129 select_row(i); 129 select_row(i);
130 _delay_us(30); // without this wait read unstable value. 130 _delay_us(30); // without this wait read unstable value.
131 matrix_row_t cols = read_cols(); 131 matrix_row_t cols = read_cols();
132 if (matrix_debouncing[i+offset] != cols) { 132 if (matrix_debouncing[i+offset] != cols) {
133 matrix_debouncing[i+offset] = cols; 133 matrix_debouncing[i+offset] = cols;
134 debouncing = DEBOUNCE; 134 debouncing = DEBOUNCE;
135 } 135 }
136 unselect_rows(); 136 unselect_rows();
137 } 137 }
138 138
139 if (debouncing) { 139 if (debouncing) {
140 if (--debouncing) { 140 if (--debouncing) {
141 _delay_ms(1); 141 _delay_ms(1);
142 } else { 142 } else {
143 for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { 143 for (uint8_t i = 0; i < ROWS_PER_HAND; i++) {
144 matrix[i+offset] = matrix_debouncing[i+offset]; 144 matrix[i+offset] = matrix_debouncing[i+offset];
145 } 145 }
146 } 146 }
147 } 147 }
148 148
149 return 1; 149 return 1;
150} 150}
151 151
152#ifdef USE_I2C 152#ifdef USE_I2C
153 153
154// Get rows from other half over i2c 154// Get rows from other half over i2c
155int i2c_transaction(void) { 155int i2c_transaction(void) {
156 int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; 156 int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
157 157
158 int err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE); 158 int err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE);
159 if (err) goto i2c_error; 159 if (err) goto i2c_error;
160 160
161 // start of matrix stored at 0x00 161 // start of matrix stored at 0x00
162 err = i2c_master_write(0x00); 162 err = i2c_master_write(0x00);
163 if (err) goto i2c_error; 163 if (err) goto i2c_error;
164 164
165 // Start read 165 // Start read
166 err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_READ); 166 err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_READ);
167 if (err) goto i2c_error; 167 if (err) goto i2c_error;
168 168
169 if (!err) { 169 if (!err) {
170 int i; 170 int i;
171 for (i = 0; i < ROWS_PER_HAND-1; ++i) { 171 for (i = 0; i < ROWS_PER_HAND-1; ++i) {
172 matrix[slaveOffset+i] = i2c_master_read(I2C_ACK); 172 matrix[slaveOffset+i] = i2c_master_read(I2C_ACK);
173 } 173 }
174 matrix[slaveOffset+i] = i2c_master_read(I2C_NACK); 174 matrix[slaveOffset+i] = i2c_master_read(I2C_NACK);
175 i2c_master_stop(); 175 i2c_master_stop();
176 } else { 176 } else {
177i2c_error: // the cable is disconnceted, or something else went wrong 177i2c_error: // the cable is disconnceted, or something else went wrong
178 i2c_reset_state(); 178 i2c_reset_state();
179 return err; 179 return err;
180 } 180 }
181 181
182 return 0; 182 return 0;
183} 183}
184 184
185#else // USE_SERIAL 185#else // USE_SERIAL
186 186
187int serial_transaction(void) { 187int serial_transaction(void) {
188 int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; 188 int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
189 189
190 if (serial_update_buffers()) { 190 if (serial_update_buffers()) {
191 return 1; 191 return 1;
192 } 192 }
193 193
194 for (int i = 0; i < ROWS_PER_HAND; ++i) { 194 for (int i = 0; i < ROWS_PER_HAND; ++i) {
195 matrix[slaveOffset+i] = serial_slave_buffer[i]; 195 matrix[slaveOffset+i] = serial_slave_buffer[i];
196 } 196 }
197 return 0; 197 return 0;
198} 198}
199#endif 199#endif
200 200
201uint8_t matrix_scan(void) 201uint8_t matrix_scan(void)
202{ 202{
203 int ret = _matrix_scan(); 203 int ret = _matrix_scan();
204 204
205 205
206 206
207#ifdef USE_I2C 207#ifdef USE_I2C
208 if( i2c_transaction() ) { 208 if( i2c_transaction() ) {
209#else // USE_SERIAL 209#else // USE_SERIAL
210 if( serial_transaction() ) { 210 if( serial_transaction() ) {
211#endif 211#endif
212 // turn on the indicator led when halves are disconnected 212 // turn on the indicator led when halves are disconnected
213 TXLED1; 213 TXLED1;
214 214
215 error_count++; 215 error_count++;
216 216
217 if (error_count > ERROR_DISCONNECT_COUNT) { 217 if (error_count > ERROR_DISCONNECT_COUNT) {
218 // reset other half if disconnected 218 // reset other half if disconnected
219 int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; 219 int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
220 for (int i = 0; i < ROWS_PER_HAND; ++i) { 220 for (int i = 0; i < ROWS_PER_HAND; ++i) {
221 matrix[slaveOffset+i] = 0; 221 matrix[slaveOffset+i] = 0;
222 } 222 }
223 } 223 }
224 } else { 224 } else {
225 // turn off the indicator led on no error 225 // turn off the indicator led on no error
226 TXLED0; 226 TXLED0;
227 error_count = 0; 227 error_count = 0;
228 } 228 }
229 229
230 matrix_scan_quantum(); 230 matrix_scan_quantum();
231 231
232 return ret; 232 return ret;
233} 233}
234 234
235void matrix_slave_scan(void) { 235void matrix_slave_scan(void) {
236 _matrix_scan(); 236 _matrix_scan();
237 237
238 int offset = (isLeftHand) ? 0 : (MATRIX_ROWS / 2); 238 int offset = (isLeftHand) ? 0 : (MATRIX_ROWS / 2);
239 239
240#ifdef USE_I2C 240#ifdef USE_I2C
241 for (int i = 0; i < ROWS_PER_HAND; ++i) { 241 for (int i = 0; i < ROWS_PER_HAND; ++i) {
242 /* i2c_slave_buffer[i] = matrix[offset+i]; */ 242 /* i2c_slave_buffer[i] = matrix[offset+i]; */
243 i2c_slave_buffer[i] = matrix[offset+i]; 243 i2c_slave_buffer[i] = matrix[offset+i];
244 } 244 }
245#else // USE_SERIAL 245#else // USE_SERIAL
246 for (int i = 0; i < ROWS_PER_HAND; ++i) { 246 for (int i = 0; i < ROWS_PER_HAND; ++i) {
247 serial_slave_buffer[i] = matrix[offset+i]; 247 serial_slave_buffer[i] = matrix[offset+i];
248 } 248 }
249#endif 249#endif
250} 250}
251 251
252bool matrix_is_modified(void) 252bool matrix_is_modified(void)
253{ 253{
254 if (debouncing) return false; 254 if (debouncing) return false;
255 return true; 255 return true;
256} 256}
257 257
258inline 258inline
259bool matrix_is_on(uint8_t row, uint8_t col) 259bool matrix_is_on(uint8_t row, uint8_t col)
260{ 260{
261 return (matrix[row] & ((matrix_row_t)1<<col)); 261 return (matrix[row] & ((matrix_row_t)1<<col));
262} 262}
263 263
264inline 264inline
265matrix_row_t matrix_get_row(uint8_t row) 265matrix_row_t matrix_get_row(uint8_t row)
266{ 266{
267 return matrix[row]; 267 return matrix[row];
268} 268}
269 269
270void matrix_print(void) 270void matrix_print(void)
271{ 271{
272 print("\nr/c 0123456789ABCDEF\n"); 272 print("\nr/c 0123456789ABCDEF\n");
273 for (uint8_t row = 0; row < MATRIX_ROWS; row++) { 273 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
274 phex(row); print(": "); 274 phex(row); print(": ");
275 pbin_reverse16(matrix_get_row(row)); 275 pbin_reverse16(matrix_get_row(row));
276 print("\n"); 276 print("\n");
277 } 277 }
278} 278}
279 279
280uint8_t matrix_key_count(void) 280uint8_t matrix_key_count(void)
281{ 281{
282 uint8_t count = 0; 282 uint8_t count = 0;
283 for (uint8_t i = 0; i < MATRIX_ROWS; i++) { 283 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
284 count += bitpop16(matrix[i]); 284 count += bitpop16(matrix[i]);
285 } 285 }
286 return count; 286 return count;
287} 287}
288 288
289static void init_cols(void) 289static void init_cols(void)
290{ 290{
291 for(int x = 0; x < MATRIX_COLS; x++) { 291 for(int x = 0; x < MATRIX_COLS; x++) {
292 _SFR_IO8((col_pins[x] >> 4) + 1) &= ~_BV(col_pins[x] & 0xF); 292 _SFR_IO8((col_pins[x] >> 4) + 1) &= ~_BV(col_pins[x] & 0xF);
293 _SFR_IO8((col_pins[x] >> 4) + 2) |= _BV(col_pins[x] & 0xF); 293 _SFR_IO8((col_pins[x] >> 4) + 2) |= _BV(col_pins[x] & 0xF);
294 } 294 }
295} 295}
296 296
297static matrix_row_t read_cols(void) 297static matrix_row_t read_cols(void)
298{ 298{
299 matrix_row_t result = 0; 299 matrix_row_t result = 0;
300 for(int x = 0; x < MATRIX_COLS; x++) { 300 for(int x = 0; x < MATRIX_COLS; x++) {
301 result |= (_SFR_IO8(col_pins[x] >> 4) & _BV(col_pins[x] & 0xF)) ? 0 : (1 << x); 301 result |= (_SFR_IO8(col_pins[x] >> 4) & _BV(col_pins[x] & 0xF)) ? 0 : (1 << x);
302 } 302 }
303 return result; 303 return result;
304} 304}
305 305
306static void unselect_rows(void) 306static void unselect_rows(void)
307{ 307{
308 for(int x = 0; x < ROWS_PER_HAND; x++) { 308 for(int x = 0; x < ROWS_PER_HAND; x++) {
309 _SFR_IO8((row_pins[x] >> 4) + 1) &= ~_BV(row_pins[x] & 0xF); 309 _SFR_IO8((row_pins[x] >> 4) + 1) &= ~_BV(row_pins[x] & 0xF);
310 _SFR_IO8((row_pins[x] >> 4) + 2) |= _BV(row_pins[x] & 0xF); 310 _SFR_IO8((row_pins[x] >> 4) + 2) |= _BV(row_pins[x] & 0xF);
311 } 311 }
312} 312}
313 313
314static void select_row(uint8_t row) 314static void select_row(uint8_t row)
315{ 315{
316 _SFR_IO8((row_pins[row] >> 4) + 1) |= _BV(row_pins[row] & 0xF); 316 _SFR_IO8((row_pins[row] >> 4) + 1) |= _BV(row_pins[row] & 0xF);
317 _SFR_IO8((row_pins[row] >> 4) + 2) &= ~_BV(row_pins[row] & 0xF); 317 _SFR_IO8((row_pins[row] >> 4) + 2) &= ~_BV(row_pins[row] & 0xF);
318} 318}
diff --git a/keyboards/deltasplit75/serial.c b/keyboards/deltasplit75/serial.c
index 898ef7d42..6faed09ce 100644
--- a/keyboards/deltasplit75/serial.c
+++ b/keyboards/deltasplit75/serial.c
@@ -1,228 +1,228 @@
1/* 1/*
2 * WARNING: be careful changing this code, it is very timing dependent 2 * WARNING: be careful changing this code, it is very timing dependent
3 */ 3 */
4 4
5#ifndef F_CPU 5#ifndef F_CPU
6#define F_CPU 16000000 6#define F_CPU 16000000
7#endif 7#endif
8 8
9#include <avr/io.h> 9#include <avr/io.h>
10#include <avr/interrupt.h> 10#include <avr/interrupt.h>
11#include <util/delay.h> 11#include <util/delay.h>
12#include <stdbool.h> 12#include <stdbool.h>
13#include "serial.h" 13#include "serial.h"
14 14
15#ifdef USE_SERIAL 15#ifdef USE_SERIAL
16 16
17// Serial pulse period in microseconds. Its probably a bad idea to lower this 17// Serial pulse period in microseconds. Its probably a bad idea to lower this
18// value. 18// value.
19#define SERIAL_DELAY 24 19#define SERIAL_DELAY 24
20 20
21uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0}; 21uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
22uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0}; 22uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
23 23
24#define SLAVE_DATA_CORRUPT (1<<0) 24#define SLAVE_DATA_CORRUPT (1<<0)
25volatile uint8_t status = 0; 25volatile uint8_t status = 0;
26 26
27inline static 27inline static
28void serial_delay(void) { 28void serial_delay(void) {
29 _delay_us(SERIAL_DELAY); 29 _delay_us(SERIAL_DELAY);
30} 30}
31 31
32inline static 32inline static
33void serial_output(void) { 33void serial_output(void) {
34 SERIAL_PIN_DDR |= SERIAL_PIN_MASK; 34 SERIAL_PIN_DDR |= SERIAL_PIN_MASK;
35} 35}
36 36
37// make the serial pin an input with pull-up resistor 37// make the serial pin an input with pull-up resistor
38inline static 38inline static
39void serial_input(void) { 39void serial_input(void) {
40 SERIAL_PIN_DDR &= ~SERIAL_PIN_MASK; 40 SERIAL_PIN_DDR &= ~SERIAL_PIN_MASK;
41 SERIAL_PIN_PORT |= SERIAL_PIN_MASK; 41 SERIAL_PIN_PORT |= SERIAL_PIN_MASK;
42} 42}
43 43
44inline static 44inline static
45uint8_t serial_read_pin(void) { 45uint8_t serial_read_pin(void) {
46 return !!(SERIAL_PIN_INPUT & SERIAL_PIN_MASK); 46 return !!(SERIAL_PIN_INPUT & SERIAL_PIN_MASK);
47} 47}
48 48
49inline static 49inline static
50void serial_low(void) { 50void serial_low(void) {
51 SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK; 51 SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK;
52} 52}
53 53
54inline static 54inline static
55void serial_high(void) { 55void serial_high(void) {
56 SERIAL_PIN_PORT |= SERIAL_PIN_MASK; 56 SERIAL_PIN_PORT |= SERIAL_PIN_MASK;
57} 57}
58 58
59void serial_master_init(void) { 59void serial_master_init(void) {
60 serial_output(); 60 serial_output();
61 serial_high(); 61 serial_high();
62} 62}
63 63
64void serial_slave_init(void) { 64void serial_slave_init(void) {
65 serial_input(); 65 serial_input();
66 66
67 // Enable INT0 67 // Enable INT0
68 EIMSK |= _BV(INT0); 68 EIMSK |= _BV(INT0);
69 // Trigger on falling edge of INT0 69 // Trigger on falling edge of INT0
70 EICRA &= ~(_BV(ISC00) | _BV(ISC01)); 70 EICRA &= ~(_BV(ISC00) | _BV(ISC01));
71} 71}
72 72
73// Used by the master to synchronize timing with the slave. 73// Used by the master to synchronize timing with the slave.
74static 74static
75void sync_recv(void) { 75void sync_recv(void) {
76 serial_input(); 76 serial_input();
77 // This shouldn't hang if the slave disconnects because the 77 // This shouldn't hang if the slave disconnects because the
78 // serial line will float to high if the slave does disconnect. 78 // serial line will float to high if the slave does disconnect.
79 while (!serial_read_pin()); 79 while (!serial_read_pin());
80 serial_delay(); 80 serial_delay();
81} 81}
82 82
83// Used by the slave to send a synchronization signal to the master. 83// Used by the slave to send a synchronization signal to the master.
84static 84static
85void sync_send(void) { 85void sync_send(void) {
86 serial_output(); 86 serial_output();
87 87
88 serial_low(); 88 serial_low();
89 serial_delay(); 89 serial_delay();
90 90
91 serial_high(); 91 serial_high();
92} 92}
93 93
94// Reads a byte from the serial line 94// Reads a byte from the serial line
95static 95static
96uint8_t serial_read_byte(void) { 96uint8_t serial_read_byte(void) {
97 uint8_t byte = 0; 97 uint8_t byte = 0;
98 serial_input(); 98 serial_input();
99 for ( uint8_t i = 0; i < 8; ++i) { 99 for ( uint8_t i = 0; i < 8; ++i) {
100 byte = (byte << 1) | serial_read_pin(); 100 byte = (byte << 1) | serial_read_pin();
101 serial_delay(); 101 serial_delay();
102 _delay_us(1); 102 _delay_us(1);
103 } 103 }
104 104
105 return byte; 105 return byte;
106} 106}
107 107
108// Sends a byte with MSB ordering 108// Sends a byte with MSB ordering
109static 109static
110void serial_write_byte(uint8_t data) { 110void serial_write_byte(uint8_t data) {
111 uint8_t b = 8; 111 uint8_t b = 8;
112 serial_output(); 112 serial_output();
113 while( b-- ) { 113 while( b-- ) {
114 if(data & (1 << b)) { 114 if(data & (1 << b)) {
115 serial_high(); 115 serial_high();
116 } else { 116 } else {
117 serial_low(); 117 serial_low();
118 } 118 }
119 serial_delay(); 119 serial_delay();
120 } 120 }
121} 121}
122 122
123// interrupt handle to be used by the slave device 123// interrupt handle to be used by the slave device
124ISR(SERIAL_PIN_INTERRUPT) { 124ISR(SERIAL_PIN_INTERRUPT) {
125 sync_send(); 125 sync_send();
126 126
127 uint8_t checksum = 0; 127 uint8_t checksum = 0;
128 for (int i = 0; i < SERIAL_SLAVE_BUFFER_LENGTH; ++i) { 128 for (int i = 0; i < SERIAL_SLAVE_BUFFER_LENGTH; ++i) {
129 serial_write_byte(serial_slave_buffer[i]); 129 serial_write_byte(serial_slave_buffer[i]);
130 sync_send(); 130 sync_send();
131 checksum += serial_slave_buffer[i]; 131 checksum += serial_slave_buffer[i];
132 } 132 }
133 serial_write_byte(checksum); 133 serial_write_byte(checksum);
134 sync_send(); 134 sync_send();
135 135
136 // wait for the sync to finish sending 136 // wait for the sync to finish sending
137 serial_delay(); 137 serial_delay();
138 138
139 // read the middle of pulses 139 // read the middle of pulses
140 _delay_us(SERIAL_DELAY/2); 140 _delay_us(SERIAL_DELAY/2);
141 141
142 uint8_t checksum_computed = 0; 142 uint8_t checksum_computed = 0;
143 for (int i = 0; i < SERIAL_MASTER_BUFFER_LENGTH; ++i) { 143 for (int i = 0; i < SERIAL_MASTER_BUFFER_LENGTH; ++i) {
144 serial_master_buffer[i] = serial_read_byte(); 144 serial_master_buffer[i] = serial_read_byte();
145 sync_send(); 145 sync_send();
146 checksum_computed += serial_master_buffer[i]; 146 checksum_computed += serial_master_buffer[i];
147 } 147 }
148 uint8_t checksum_received = serial_read_byte(); 148 uint8_t checksum_received = serial_read_byte();
149 sync_send(); 149 sync_send();
150 150
151 serial_input(); // end transaction 151 serial_input(); // end transaction
152 152
153 if ( checksum_computed != checksum_received ) { 153 if ( checksum_computed != checksum_received ) {
154 status |= SLAVE_DATA_CORRUPT; 154 status |= SLAVE_DATA_CORRUPT;
155 } else { 155 } else {
156 status &= ~SLAVE_DATA_CORRUPT; 156 status &= ~SLAVE_DATA_CORRUPT;
157 } 157 }
158} 158}
159 159
160inline 160inline
161bool serial_slave_DATA_CORRUPT(void) { 161bool serial_slave_DATA_CORRUPT(void) {
162 return status & SLAVE_DATA_CORRUPT; 162 return status & SLAVE_DATA_CORRUPT;
163} 163}
164 164
165// Copies the serial_slave_buffer to the master and sends the 165// Copies the serial_slave_buffer to the master and sends the
166// serial_master_buffer to the slave. 166// serial_master_buffer to the slave.
167// 167//
168// Returns: 168// Returns:
169// 0 => no error 169// 0 => no error
170// 1 => slave did not respond 170// 1 => slave did not respond
171int serial_update_buffers(void) { 171int serial_update_buffers(void) {
172 // this code is very time dependent, so we need to disable interrupts 172 // this code is very time dependent, so we need to disable interrupts
173 cli(); 173 cli();
174 174
175 // signal to the slave that we want to start a transaction 175 // signal to the slave that we want to start a transaction
176 serial_output(); 176 serial_output();
177 serial_low(); 177 serial_low();
178 _delay_us(1); 178 _delay_us(1);
179 179
180 // wait for the slaves response 180 // wait for the slaves response
181 serial_input(); 181 serial_input();
182 serial_high(); 182 serial_high();
183 _delay_us(SERIAL_DELAY); 183 _delay_us(SERIAL_DELAY);
184 184
185 // check if the slave is present 185 // check if the slave is present
186 if (serial_read_pin()) { 186 if (serial_read_pin()) {
187 // slave failed to pull the line low, assume not present 187 // slave failed to pull the line low, assume not present
188 sei(); 188 sei();
189 return 1; 189 return 1;
190 } 190 }
191 191
192 // if the slave is present syncronize with it 192 // if the slave is present syncronize with it
193 sync_recv(); 193 sync_recv();
194 194
195 uint8_t checksum_computed = 0; 195 uint8_t checksum_computed = 0;
196 // receive data from the slave 196 // receive data from the slave
197 for (int i = 0; i < SERIAL_SLAVE_BUFFER_LENGTH; ++i) { 197 for (int i = 0; i < SERIAL_SLAVE_BUFFER_LENGTH; ++i) {
198 serial_slave_buffer[i] = serial_read_byte(); 198 serial_slave_buffer[i] = serial_read_byte();
199 sync_recv(); 199 sync_recv();
200 checksum_computed += serial_slave_buffer[i]; 200 checksum_computed += serial_slave_buffer[i];
201 } 201 }
202 uint8_t checksum_received = serial_read_byte(); 202 uint8_t checksum_received = serial_read_byte();
203 sync_recv(); 203 sync_recv();
204 204
205 if (checksum_computed != checksum_received) { 205 if (checksum_computed != checksum_received) {
206 sei(); 206 sei();
207 return 1; 207 return 1;
208 } 208 }
209 209
210 uint8_t checksum = 0; 210 uint8_t checksum = 0;
211 // send data to the slave 211 // send data to the slave
212 for (int i = 0; i < SERIAL_MASTER_BUFFER_LENGTH; ++i) { 212 for (int i = 0; i < SERIAL_MASTER_BUFFER_LENGTH; ++i) {
213 serial_write_byte(serial_master_buffer[i]); 213 serial_write_byte(serial_master_buffer[i]);
214 sync_recv(); 214 sync_recv();
215 checksum += serial_master_buffer[i]; 215 checksum += serial_master_buffer[i];
216 } 216 }
217 serial_write_byte(checksum); 217 serial_write_byte(checksum);
218 sync_recv(); 218 sync_recv();
219 219
220 // always, release the line when not in use 220 // always, release the line when not in use
221 serial_output(); 221 serial_output();
222 serial_high(); 222 serial_high();
223 223
224 sei(); 224 sei();
225 return 0; 225 return 0;
226} 226}
227 227
228#endif 228#endif
diff --git a/keyboards/deltasplit75/serial.h b/keyboards/deltasplit75/serial.h
index ab2ea0a09..6ef52019a 100644
--- a/keyboards/deltasplit75/serial.h
+++ b/keyboards/deltasplit75/serial.h
@@ -1,26 +1,26 @@
1#ifndef MY_SERIAL_H 1#ifndef MY_SERIAL_H
2#define MY_SERIAL_H 2#define MY_SERIAL_H
3 3
4#include "config.h" 4#include "config.h"
5#include <stdbool.h> 5#include <stdbool.h>
6 6
7/* TODO: some defines for interrupt setup */ 7/* TODO: some defines for interrupt setup */
8#define SERIAL_PIN_DDR DDRD 8#define SERIAL_PIN_DDR DDRD
9#define SERIAL_PIN_PORT PORTD 9#define SERIAL_PIN_PORT PORTD
10#define SERIAL_PIN_INPUT PIND 10#define SERIAL_PIN_INPUT PIND
11#define SERIAL_PIN_MASK _BV(PD0) 11#define SERIAL_PIN_MASK _BV(PD0)
12#define SERIAL_PIN_INTERRUPT INT0_vect 12#define SERIAL_PIN_INTERRUPT INT0_vect
13 13
14#define SERIAL_SLAVE_BUFFER_LENGTH ((MATRIX_COLS+7)/8 *MATRIX_ROWS/2) 14#define SERIAL_SLAVE_BUFFER_LENGTH ((MATRIX_COLS+7)/8 *MATRIX_ROWS/2)
15#define SERIAL_MASTER_BUFFER_LENGTH 1 15#define SERIAL_MASTER_BUFFER_LENGTH 1
16 16
17// Buffers for master - slave communication 17// Buffers for master - slave communication
18extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH]; 18extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH];
19extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH]; 19extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH];
20 20
21void serial_master_init(void); 21void serial_master_init(void);
22void serial_slave_init(void); 22void serial_slave_init(void);
23int serial_update_buffers(void); 23int serial_update_buffers(void);
24bool serial_slave_data_corrupt(void); 24bool serial_slave_data_corrupt(void);
25 25
26#endif 26#endif
diff --git a/keyboards/deltasplit75/split_util.c b/keyboards/deltasplit75/split_util.c
index a636f60db..226dc1881 100644
--- a/keyboards/deltasplit75/split_util.c
+++ b/keyboards/deltasplit75/split_util.c
@@ -1,81 +1,81 @@
1#include <avr/io.h> 1#include <avr/io.h>
2#include <avr/wdt.h> 2#include <avr/wdt.h>
3#include <avr/power.h> 3#include <avr/power.h>
4#include <avr/interrupt.h> 4#include <avr/interrupt.h>
5#include <util/delay.h> 5#include <util/delay.h>
6#include <avr/eeprom.h> 6#include <avr/eeprom.h>
7#include "split_util.h" 7#include "split_util.h"
8#include "matrix.h" 8#include "matrix.h"
9#include "keyboard.h" 9#include "keyboard.h"
10#include "config.h" 10#include "config.h"
11 11
12#ifdef USE_I2C 12#ifdef USE_I2C
13# include "i2c.h" 13# include "i2c.h"
14#else 14#else
15# include "serial.h" 15# include "serial.h"
16#endif 16#endif
17 17
18volatile bool isLeftHand = true; 18volatile bool isLeftHand = true;
19 19
20static void setup_handedness(void) { 20static void setup_handedness(void) {
21 #ifdef EE_HANDS 21 #ifdef EE_HANDS
22 isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS); 22 isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS);
23 #else 23 #else
24 // I2C_MASTER_RIGHT is deprecated use MASTER_RIGHT instead since this works for both serial and i2c 24 // I2C_MASTER_RIGHT is deprecated use MASTER_RIGHT instead since this works for both serial and i2c
25 #if defined(I2C_MASTER_RIGHT) || defined(MASTER_RIGHT) 25 #if defined(I2C_MASTER_RIGHT) || defined(MASTER_RIGHT)
26 isLeftHand = !has_usb(); 26 isLeftHand = !has_usb();
27 #else 27 #else
28 isLeftHand = has_usb(); 28 isLeftHand = has_usb();
29 #endif 29 #endif
30 #endif 30 #endif
31} 31}
32 32
33static void keyboard_master_setup(void) { 33static void keyboard_master_setup(void) {
34#ifdef USE_I2C 34#ifdef USE_I2C
35 i2c_master_init(); 35 i2c_master_init();
36#else 36#else
37 serial_master_init(); 37 serial_master_init();
38#endif 38#endif
39} 39}
40 40
41static void keyboard_slave_setup(void) { 41static void keyboard_slave_setup(void) {
42#ifdef USE_I2C 42#ifdef USE_I2C
43 i2c_slave_init(SLAVE_I2C_ADDRESS); 43 i2c_slave_init(SLAVE_I2C_ADDRESS);
44#else 44#else
45 serial_slave_init(); 45 serial_slave_init();
46#endif 46#endif
47} 47}
48 48
49bool has_usb(void) { 49bool has_usb(void) {
50 USBCON |= (1 << OTGPADE); //enables VBUS pad 50 USBCON |= (1 << OTGPADE); //enables VBUS pad
51 _delay_us(5); 51 _delay_us(5);
52 return (USBSTA & (1<<VBUS)); //checks state of VBUS 52 return (USBSTA & (1<<VBUS)); //checks state of VBUS
53} 53}
54 54
55void split_keyboard_setup(void) { 55void split_keyboard_setup(void) {
56 setup_handedness(); 56 setup_handedness();
57 57
58 if (has_usb()) { 58 if (has_usb()) {
59 keyboard_master_setup(); 59 keyboard_master_setup();
60 } else { 60 } else {
61 keyboard_slave_setup(); 61 keyboard_slave_setup();
62 } 62 }
63 sei(); 63 sei();
64} 64}
65 65
66void keyboard_slave_loop(void) { 66void keyboard_slave_loop(void) {
67 matrix_init(); 67 matrix_init();
68 68
69 while (1) { 69 while (1) {
70 matrix_slave_scan(); 70 matrix_slave_scan();
71 } 71 }
72} 72}
73 73
74// this code runs before the usb and keyboard is initialized 74// this code runs before the usb and keyboard is initialized
75void matrix_setup(void) { 75void matrix_setup(void) {
76 split_keyboard_setup(); 76 split_keyboard_setup();
77 77
78 if (!has_usb()) { 78 if (!has_usb()) {
79 keyboard_slave_loop(); 79 keyboard_slave_loop();
80 } 80 }
81} 81}
diff --git a/keyboards/deltasplit75/split_util.h b/keyboards/deltasplit75/split_util.h
index a1b0447bb..6b896679c 100644
--- a/keyboards/deltasplit75/split_util.h
+++ b/keyboards/deltasplit75/split_util.h
@@ -1,22 +1,22 @@
1#ifndef SPLIT_KEYBOARD_UTIL_H 1#ifndef SPLIT_KEYBOARD_UTIL_H
2#define SPLIT_KEYBOARD_UTIL_H 2#define SPLIT_KEYBOARD_UTIL_H
3 3
4#include <stdbool.h> 4#include <stdbool.h>
5 5
6#ifdef EE_HANDS 6#ifdef EE_HANDS
7 #define EECONFIG_BOOTMAGIC_END (uint8_t *)10 7 #define EECONFIG_BOOTMAGIC_END (uint8_t *)10
8 #define EECONFIG_HANDEDNESS EECONFIG_BOOTMAGIC_END 8 #define EECONFIG_HANDEDNESS EECONFIG_BOOTMAGIC_END
9#endif 9#endif
10 10
11#define SLAVE_I2C_ADDRESS 0x32 11#define SLAVE_I2C_ADDRESS 0x32
12 12
13extern volatile bool isLeftHand; 13extern volatile bool isLeftHand;
14 14
15// slave version of matix scan, defined in matrix.c 15// slave version of matix scan, defined in matrix.c
16void matrix_slave_scan(void); 16void matrix_slave_scan(void);
17 17
18void split_keyboard_setup(void); 18void split_keyboard_setup(void);
19bool has_usb(void); 19bool has_usb(void);
20void keyboard_slave_loop(void); 20void keyboard_slave_loop(void);
21 21
22#endif 22#endif