diff --git a/keyboards/lets_split_vitamins/matrix.c b/keyboards/lets_split_vitamins/matrix.c index 56f73b54a9..c4a20e106b 100644 --- a/keyboards/lets_split_vitamins/matrix.c +++ b/keyboards/lets_split_vitamins/matrix.c @@ -32,6 +32,8 @@ along with this program. If not, see . #include "pro_micro.h" #include "config.h" #include "timer.h" +#include "Device.h" +#include "pincontrol.h" #ifdef USE_I2C @@ -41,7 +43,7 @@ along with this program. If not, see . #endif // Seconds to keep checking if USB has been enumearted, before settling for being slave half. -#define USBTIMEOUT 3 +volatile bool is_slave = false; #ifndef DEBOUNCING_DELAY # define DEBOUNCING_DELAY 5 @@ -131,7 +133,7 @@ uint8_t matrix_cols(void) } bool has_usb(void) { - return UDADDR & _BV(ADDEN); // This will return true if a USB connection has been established + return USB_DeviceState == DEVICE_STATE_Configured; } void timer_reset(void) { @@ -150,20 +152,20 @@ void timer_reset(void) { void matrix_init(void) { -#ifdef DISABLE_JTAG - // JTAG disable for PORT F. write JTD bit twice within four cycles. - MCUCR |= (1< timer_count - timeout_start) { - matrix_slave_scan(); - }*/ - // If we have USB, switch to master + if(has_usb()) { - //timer_reset(); + timer_reset(); #ifdef USE_I2C i2c_master_init(); #else serial_master_init(); #endif } - else{ + else { while (1) { matrix_slave_scan(); } diff --git a/keyboards/lets_split_vitamins/serial.c b/keyboards/lets_split_vitamins/serial.c index 74bcbb6bf6..62d148d103 100644 --- a/keyboards/lets_split_vitamins/serial.c +++ b/keyboards/lets_split_vitamins/serial.c @@ -122,6 +122,7 @@ void serial_write_byte(uint8_t data) { // interrupt handle to be used by the slave device ISR(SERIAL_PIN_INTERRUPT) { + is_slave = true; sync_send(); uint8_t checksum = 0; diff --git a/keyboards/lets_split_vitamins/serial.h b/keyboards/lets_split_vitamins/serial.h index 15fe4db7b4..44c7d439d6 100644 --- a/keyboards/lets_split_vitamins/serial.h +++ b/keyboards/lets_split_vitamins/serial.h @@ -18,6 +18,9 @@ extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH]; extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH]; +// Variable used to exit whileloop if the half is the slave +extern volatile bool is_slave; + void serial_master_init(void); void serial_slave_init(void); int serial_update_buffers(void);