Broke everything

pull/2559/head
Mikkel Jeppesen 7 years ago
parent 548766d0a5
commit feeee4e40d

@ -6,7 +6,7 @@
#include <stdbool.h>
#include "i2c.h"
#ifdef USE_I2C
#ifndef USE_I2C
// Limits the amount of we wait for any one i2c transaction.
// Since were running SCL line 100kHz (=> 10μs/bit), and each transactions is
@ -36,6 +36,9 @@ void i2c_delay(void) {
// Setup twi to run at 100kHz
void i2c_master_init(void) {
// Reset the registers set by slave mode
TWAR = 0xFE;
TWCR = 0;
// no prescaler
TWSR = 0;
// Set TWI clock frequency to SCL_CLOCK. Need TWBR>10.

@ -40,6 +40,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# include "serial.h"
#endif
// Seconds to keep checking if USB has been enumearted, before settling for being slave half.
#define USBTIMEOUT 3
#ifndef DEBOUNCING_DELAY
# define DEBOUNCING_DELAY 5
#endif
@ -128,7 +131,21 @@ uint8_t matrix_cols(void)
}
bool has_usb(void) {
return UDADDR & _BV(ADDEN); // This will return true of a USB connection has been established
return UDADDR & _BV(ADDEN); // This will return true if a USB connection has been established
}
void timer_reset(void) {
#ifndef __AVR_ATmega32A__
TCCR0A = 0;
TCCR0B = 0;
OCR0A = 0;
TIMSK0 = 0;
#else
// Timer0 CTC mode
TCCR0 = 0;
OCR0 = 0;
TIMSK = 0;
#endif
}
void matrix_init(void)
@ -156,28 +173,34 @@ void matrix_init(void)
matrix_debouncing[i] = 0;
}
_delay_ms(2000); // Give USB 2 seconds to establish a connection
// initialize as slave
timer_init();
#ifdef USE_I2C
i2c_slave_init(SLAVE_I2C_ADDRESS);
#else
serial_slave_init();
#endif
sei();
matrix_init_quantum();
/* Wait USBTIMEOUT for USB
uint32_t timeout_start = timer_count;
while(!has_usb() && USBTIMEOUT > timer_count - timeout_start) {
matrix_slave_scan();
}*/
if (has_usb()) { // Set up as master
// If we have USB, switch to master
if(has_usb()) {
//timer_reset();
#ifdef USE_I2C
i2c_master_init();
#else
serial_master_init();
#endif
} else { // Set up as slave
timer_init();
#ifdef USE_I2C
i2c_slave_init(SLAVE_I2C_ADDRESS);
#else
serial_slave_init();
#endif
}
sei();
matrix_init_quantum();
if(!has_usb()){
else{
while (1) {
matrix_slave_scan();
}

@ -38,6 +38,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define MATRIX_ROW_PINS { F5, F6, C7, F7 }
#define MATRIX_COL_PINS { F1, F4, E2, B6, D7, D6}
/* define if matrix uses jtag pins */
#define DISABLE_JTAG
/* define if matrix has ghost */
//#define MATRIX_HAS_GHOST

Loading…
Cancel
Save