1
0
Fork 0

Made Serial and I2C not include the Other

This saves 192 bytes
This commit is contained in:
IBNobody 2016-09-20 21:38:59 -05:00
parent f956802f29
commit 6631abc1cb
6 changed files with 36 additions and 14 deletions

View file

@ -41,6 +41,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// #define USE_I2C // #define USE_I2C
// Use serial if not using I2C
#ifndef USE_I2C
# define USE_SERIAL
#endif
// #define EE_HANDS // #define EE_HANDS
#define I2C_MASTER_LEFT #define I2C_MASTER_LEFT

View file

@ -6,6 +6,8 @@
#include <stdbool.h> #include <stdbool.h>
#include "i2c.h" #include "i2c.h"
#ifdef USE_I2C
// Limits the amount of we wait for any one i2c transaction. // Limits the amount of we wait for any one i2c transaction.
// Since were running SCL line 100kHz (=> 10μs/bit), and each transactions is // Since were running SCL line 100kHz (=> 10μs/bit), and each transactions is
// 9 bits, a single transaction will take around 90μs to complete. // 9 bits, a single transaction will take around 90μs to complete.
@ -157,3 +159,4 @@ ISR(TWI_vect) {
// Reset everything, so we are ready for the next TWI interrupt // Reset everything, so we are ready for the next TWI interrupt
TWCR |= (1<<TWIE) | (1<<TWINT) | (ack<<TWEA) | (1<<TWEN); TWCR |= (1<<TWIE) | (1<<TWINT) | (ack<<TWEA) | (1<<TWEN);
} }
#endif

View file

@ -28,14 +28,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "debug.h" #include "debug.h"
#include "util.h" #include "util.h"
#include "matrix.h" #include "matrix.h"
#include "i2c.h"
#include "serial.h"
#include "split_util.h" #include "split_util.h"
#include "pro_micro.h" #include "pro_micro.h"
#include "config.h" #include "config.h"
#ifdef USE_I2C
# include "i2c.h"
#else // USE_SERIAL
# include "serial.h"
#endif
#ifndef DEBOUNCE #ifndef DEBOUNCE
# define DEBOUNCE 5 # define DEBOUNCE 5
#endif #endif
#define ERROR_DISCONNECT_COUNT 5 #define ERROR_DISCONNECT_COUNT 5
@ -145,6 +149,8 @@ uint8_t _matrix_scan(void)
return 1; return 1;
} }
#ifdef USE_I2C
// Get rows from other half over i2c // Get rows from other half over i2c
int i2c_transaction(void) { int i2c_transaction(void) {
int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
@ -176,7 +182,8 @@ i2c_error: // the cable is disconnceted, or something else went wrong
return 0; return 0;
} }
#ifndef USE_I2C #else // USE_SERIAL
int serial_transaction(void) { int serial_transaction(void) {
int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
@ -199,7 +206,7 @@ uint8_t matrix_scan(void)
#ifdef USE_I2C #ifdef USE_I2C
if( i2c_transaction() ) { if( i2c_transaction() ) {
#else #else // USE_SERIAL
if( serial_transaction() ) { if( serial_transaction() ) {
#endif #endif
// turn on the indicator led when halves are disconnected // turn on the indicator led when halves are disconnected
@ -235,7 +242,7 @@ void matrix_slave_scan(void) {
/* i2c_slave_buffer[i] = matrix[offset+i]; */ /* i2c_slave_buffer[i] = matrix[offset+i]; */
i2c_slave_buffer[i] = matrix[offset+i]; i2c_slave_buffer[i] = matrix[offset+i];
} }
#else #else // USE_SERIAL
for (int i = 0; i < ROWS_PER_HAND; ++i) { for (int i = 0; i < ROWS_PER_HAND; ++i) {
serial_slave_buffer[i] = matrix[offset+i]; serial_slave_buffer[i] = matrix[offset+i];
} }

View file

@ -10,9 +10,10 @@
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <util/delay.h> #include <util/delay.h>
#include <stdbool.h> #include <stdbool.h>
#include "serial.h" #include "serial.h"
#ifdef USE_SERIAL
// Serial pulse period in microseconds. Its probably a bad idea to lower this // Serial pulse period in microseconds. Its probably a bad idea to lower this
// value. // value.
#define SERIAL_DELAY 24 #define SERIAL_DELAY 24
@ -223,3 +224,5 @@ int serial_update_buffers(void) {
sei(); sei();
return 0; return 0;
} }
#endif

View file

@ -6,11 +6,15 @@
#include <avr/eeprom.h> #include <avr/eeprom.h>
#include "split_util.h" #include "split_util.h"
#include "matrix.h" #include "matrix.h"
#include "i2c.h"
#include "serial.h"
#include "keyboard.h" #include "keyboard.h"
#include "config.h" #include "config.h"
#ifdef USE_I2C
# include "i2c.h"
#else
# include "serial.h"
#endif
volatile bool isLeftHand = true; volatile bool isLeftHand = true;
static void setup_handedness(void) { static void setup_handedness(void) {