1
0
Fork 0
forked from forks/qmk_firmware

Broke everything

This commit is contained in:
Mikkel Jeppesen 2018-03-18 01:01:50 +01:00
parent 548766d0a5
commit feeee4e40d
3 changed files with 46 additions and 17 deletions

View file

@ -6,7 +6,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "i2c.h" #include "i2c.h"
#ifdef USE_I2C #ifndef 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
@ -36,6 +36,9 @@ void i2c_delay(void) {
// Setup twi to run at 100kHz // Setup twi to run at 100kHz
void i2c_master_init(void) { void i2c_master_init(void) {
// Reset the registers set by slave mode
TWAR = 0xFE;
TWCR = 0;
// no prescaler // no prescaler
TWSR = 0; TWSR = 0;
// Set TWI clock frequency to SCL_CLOCK. Need TWBR>10. // Set TWI clock frequency to SCL_CLOCK. Need TWBR>10.

View file

@ -40,6 +40,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# include "serial.h" # include "serial.h"
#endif #endif
// Seconds to keep checking if USB has been enumearted, before settling for being slave half.
#define USBTIMEOUT 3
#ifndef DEBOUNCING_DELAY #ifndef DEBOUNCING_DELAY
# define DEBOUNCING_DELAY 5 # define DEBOUNCING_DELAY 5
#endif #endif
@ -128,7 +131,21 @@ uint8_t matrix_cols(void)
} }
bool has_usb(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) void matrix_init(void)
@ -156,28 +173,34 @@ void matrix_init(void)
matrix_debouncing[i] = 0; 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
if (has_usb()) { // Set up as master 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 we have USB, switch to master
if(has_usb()) {
//timer_reset();
#ifdef USE_I2C #ifdef USE_I2C
i2c_master_init(); i2c_master_init();
#else #else
serial_master_init(); serial_master_init();
#endif #endif
} else { // Set up as slave
timer_init();
#ifdef USE_I2C
i2c_slave_init(SLAVE_I2C_ADDRESS);
#else
serial_slave_init();
#endif
} }
sei(); else{
matrix_init_quantum();
if(!has_usb()){
while (1) { while (1) {
matrix_slave_scan(); matrix_slave_scan();
} }

View file

@ -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_ROW_PINS { F5, F6, C7, F7 }
#define MATRIX_COL_PINS { F1, F4, E2, B6, D7, D6} #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 if matrix has ghost */
//#define MATRIX_HAS_GHOST //#define MATRIX_HAS_GHOST