diff --git a/keyboards/helix/rev2/split_scomm.c b/keyboards/helix/rev2/split_scomm.c index 691ee9d41d..f37b783d8a 100644 --- a/keyboards/helix/rev2/split_scomm.c +++ b/keyboards/helix/rev2/split_scomm.c @@ -76,12 +76,10 @@ int serial_update_buffers(int master_update) else status = soft_serial_transaction(PUT_MASTER_GET_SLAVE_STATUS); need_retry = ( status == TRANSACTION_END ) ? 0 : 1; - if( need_retry ) debug_retry_on(); else debug_retry_off(); return status; #else int status; status = soft_serial_transaction(); - if( status != TRANSACTION_END ) debug_retry_on(); else debug_retry_off(); return status; #endif } diff --git a/keyboards/helix/serial.c b/keyboards/helix/serial.c index aef7051703..b030451248 100644 --- a/keyboards/helix/serial.c +++ b/keyboards/helix/serial.c @@ -85,7 +85,6 @@ void serial_delay_half2(void) { inline static void serial_output(void) ALWAYS_INLINE; inline static void serial_output(void) { - debug_output_mode(); SERIAL_PIN_DDR |= SERIAL_PIN_MASK; } @@ -93,7 +92,6 @@ void serial_output(void) { inline static void serial_input_with_pullup(void) ALWAYS_INLINE; inline static void serial_input_with_pullup(void) { - debug_input_mode(); SERIAL_PIN_DDR &= ~SERIAL_PIN_MASK; SERIAL_PIN_PORT |= SERIAL_PIN_MASK; } @@ -117,7 +115,6 @@ void serial_high(void) { void soft_serial_initiator_init(SSTD_t *sstd_table) { - serial_debug_init(); Transaction_table = sstd_table; serial_output(); serial_high(); @@ -125,7 +122,6 @@ void soft_serial_initiator_init(SSTD_t *sstd_table) void soft_serial_target_init(SSTD_t *sstd_table) { - serial_debug_init(); Transaction_table = sstd_table; serial_input_with_pullup(); @@ -148,25 +144,20 @@ void soft_serial_target_init(SSTD_t *sstd_table) static void sync_recv(void) NO_INLINE; static void sync_recv(void) { - debug_sync_start(); for (uint8_t i = 0; i < SERIAL_DELAY*5 && serial_read_pin(); i++ ) { - debug_sync_end(); debug_sync_start(); } // This shouldn't hang if the target disconnects because the // serial line will float to high if the target does disconnect. while (!serial_read_pin()); - debug_sync_end(); } // Used by the reciver to send a synchronization signal to the sender. static void sync_send(void)NO_INLINE; static void sync_send(void) { - debug_sync_start(); serial_low(); serial_delay(); serial_high(); - debug_sync_end(); } // Reads a byte from the serial line @@ -177,29 +168,21 @@ static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) { _delay_sub_us(READ_WRITE_START_ADJUST); for( i = 0, byte = 0, p = 0; i < bit; i++ ) { serial_delay_half1(); // read the middle of pulses - debug_recvsample(); if( serial_read_pin() ) { byte = (byte << 1) | 1; p ^= 1; } else { byte = (byte << 1) | 0; p ^= 0; } - debug_recvsample(); _delay_sub_us(READ_WRITE_WIDTH_ADJUST); serial_delay_half2(); - debug_dummy_delay_recv(); } /* recive parity bit */ serial_delay_half1(); // read the middle of pulses - debug_recvsample(); pb = serial_read_pin(); - debug_recvsample(); _delay_sub_us(READ_WRITE_WIDTH_ADJUST); serial_delay_half2(); - debug_dummy_delay_recv(); - if( p == pb ) debug_parity_on(); *pterrcount += (p != pb)? 1 : 0; - debug_parity_off(); return byte; } @@ -214,18 +197,12 @@ void serial_write_chunk(uint8_t data, uint8_t bit) { } else { serial_low(); p ^= 0; } - debug_recvsample(); serial_delay(); - debug_recvsample(); - debug_dummy_delay_send(); } /* send parity bit */ if(p & 1) { serial_high(); } else { serial_low(); } - debug_recvsample(); serial_delay(); - debug_recvsample(); - debug_dummy_delay_send(); serial_low(); // sync_send() / senc_recv() need raise edge } @@ -237,9 +214,7 @@ void serial_send_packet(uint8_t *buffer, uint8_t size) { uint8_t data; data = buffer[i]; sync_send(); - debug_bytewidth_start(); serial_write_chunk(data,8); - debug_bytewidth_end(); } } @@ -250,9 +225,7 @@ uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) { for (uint8_t i = 0; i < size; ++i) { uint8_t data; sync_recv(); - debug_bytewidth_start(); data = serial_read_chunk(&pecount, 8); - debug_bytewidth_end(); buffer[i] = data; } return pecount == 0; @@ -278,9 +251,6 @@ void change_reciver2sender(void) { // interrupt handle to be used by the target device ISR(SERIAL_PIN_INTERRUPT) { - debug_output_mode(); debug_input_mode(); // indicate intterupt entry - debug_recvsample(); debug_recvsample(); // indicate intterupt entry - debug_sync_start(); debug_sync_end(); // indicate intterupt entry #ifndef SERIAL_USE_MULTI_TRANSACTION serial_low(); @@ -291,9 +261,7 @@ ISR(SERIAL_PIN_INTERRUPT) { uint8_t tid; uint8_t pecount = 0; sync_recv(); - debug_bytewidth_start(); tid = serial_read_chunk(&pecount,4); - debug_bytewidth_end(); if(pecount> 0) return; serial_delay_half1(); @@ -318,16 +286,13 @@ ISR(SERIAL_PIN_INTERRUPT) { trans->initiator2target_buffer_size) ) { *trans->status = TRANSACTION_ACCEPTED; } else { - debug_parity_on(); *trans->status = TRANSACTION_DATA_ERROR; - debug_parity_off(); } } else { *trans->status = TRANSACTION_ACCEPTED; } sync_recv(); //weit initiator output to high - debug_output_mode(); debug_input_mode(); // indicate intterupt exit } ///////// @@ -372,21 +337,17 @@ int soft_serial_transaction(int sstd_index) { #else // send transaction table index sync_send(); - debug_bytewidth_start(); _delay_sub_us(TID_SEND_ADJUST); serial_write_chunk(sstd_index, 4); - debug_bytewidth_end(); serial_delay_half1(); // wait for the target response (step1 low->high) serial_input_with_pullup(); while( !serial_read_pin() ) { _delay_sub_us(2); - debug_output_mode(); debug_input_mode(); // indicate check pin timeing } // check if the target is present (step2 high->low) - debug_output_mode(); _delay_sub_us(1); debug_input_mode(); // indicate check pin timeing for( int i = 0; serial_read_pin(); i++ ) { if (i > SLAVE_INT_ACK_WIDTH + 1) { // slave failed to pull the line low, assume not present @@ -396,9 +357,7 @@ int soft_serial_transaction(int sstd_index) { sei(); return TRANSACTION_NO_RESPONSE; } - debug_output_mode(); _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT); - debug_input_mode(); // indicate check pin timeing } #endif @@ -407,10 +366,8 @@ int soft_serial_transaction(int sstd_index) { if( trans->target2initiator_buffer_size > 0 ) { if (!serial_recive_packet((uint8_t *)trans->target2initiator_buffer, trans->target2initiator_buffer_size) ) { - debug_parity_on(); serial_output(); serial_high(); - debug_parity_off(); *trans->status = TRANSACTION_DATA_ERROR; sei(); return TRANSACTION_DATA_ERROR; @@ -428,7 +385,6 @@ int soft_serial_transaction(int sstd_index) { // always, release the line when not in use sync_send(); - debug_input_mode(); debug_output_mode(); // indicate intterupt exit *trans->status = TRANSACTION_END; sei(); diff --git a/keyboards/helix/serial.h b/keyboards/helix/serial.h index bf002ee61a..d3cf1743a3 100644 --- a/keyboards/helix/serial.h +++ b/keyboards/helix/serial.h @@ -12,6 +12,9 @@ // #define SERIAL_PIN_INPUT PIND // #define SERIAL_PIN_MASK _BV(PD?) ?=0,2 // #define SERIAL_PIN_INTERRUPT INT?_vect ?=0,2 +// +// When using multi-type transaction function, define the following macro. +// #define SERIAL_USE_MULTI_TRANSACTION // Soft Serial Transaction Descriptor typedef struct _SSTD_t { @@ -51,108 +54,4 @@ int soft_serial_transaction(int sstd_index); int soft_serial_get_and_clean_status(int sstd_index); #endif - -// debug flags -#define SERIAL_DEBUG_MODE_WATCH_OUTMODE 0x1 -#define SERIAL_DEBUG_MODE_WATCH_RCVSAMPLE 0x2 -#define SERIAL_DEBUG_MODE_WATCH_BYTEWIDTH 0x4 -#define SERIAL_DEBUG_MODE_WATCH_SYNC 0x8 -#define SERIAL_DEBUG_MODE_WATCH_IOCHG 0x10 -#define SERIAL_DEBUG_MODE_WATCH_PARITY 0x20 -#define SERIAL_DEBUG_MODE_WATCH_RETRY 0x40 - -//#define SERIAL_DEBUG_MODE SERIAL_DEBUG_MODE_WATCH_OUTMODE -//#define SERIAL_DEBUG_MODE SERIAL_DEBUG_MODE_WATCH_RCVSAMPLE -//#define SERIAL_DEBUG_MODE SERIAL_DEBUG_MODE_WATCH_BYTEWIDTH -//#define SERIAL_DEBUG_MODE (SERIAL_DEBUG_MODE_WATCH_RCVSAMPLE|SERIAL_DEBUG_MODE_WATCH_BYTEWIDTH) -//#define SERIAL_DEBUG_MODE SERIAL_DEBUG_MODE_WATCH_SYNC -//#define SERIAL_DEBUG_MODE (SERIAL_DEBUG_MODE_WATCH_RCVSAMPLE|SERIAL_DEBUG_MODE_WATCH_SYNC) -//#define SERIAL_DEBUG_MODE SERIAL_DEBUG_MODE_WATCH_IOCHG -//#define SERIAL_DEBUG_MODE (SERIAL_DEBUG_MODE_WATCH_IOCHG|SERIAL_DEBUG_MODE_WATCH_SYNC) -//#define SERIAL_DEBUG_MODE SERIAL_DEBUG_MODE_WATCH_PARITY -//#define SERIAL_DEBUG_MODE SERIAL_DEBUG_MODE_WATCH_RETRY - -// Helix keyboard unused port (for Logic analyzer or oscilloscope) -#ifdef SERIAL_DEBUG_MODE -#define SERIAL_DBGPIN_DDR DDRB -#define SERIAL_DBGPIN_PORT PORTB -#define SERIAL_DBGPIN_MASK _BV(PB5) -#endif - -#ifdef SERIAL_DEBUG_MODE - #define serial_debug_init() SERIAL_DBGPIN_DDR |= SERIAL_DBGPIN_MASK -#else - #define serial_debug_init() -#endif - -#if SERIAL_DEBUG_MODE & SERIAL_DEBUG_MODE_WATCH_OUTMODE - #define debug_output_mode() SERIAL_DBGPIN_PORT |= SERIAL_DBGPIN_MASK - #define debug_input_mode() SERIAL_DBGPIN_PORT &= ~SERIAL_DBGPIN_MASK -#else - #define debug_output_mode() - #define debug_input_mode() -#endif - -#if SERIAL_DEBUG_MODE & SERIAL_DEBUG_MODE_WATCH_RCVSAMPLE - #define debug_recvsample() SERIAL_DBGPIN_PORT ^= SERIAL_DBGPIN_MASK -#else - #define debug_recvsample() -#endif - -#if SERIAL_DEBUG_MODE & SERIAL_DEBUG_MODE_WATCH_BYTEWIDTH - #define debug_bytewidth_start() SERIAL_DBGPIN_PORT |= SERIAL_DBGPIN_MASK - #define debug_bytewidth_end() SERIAL_DBGPIN_PORT &= ~SERIAL_DBGPIN_MASK -#else - #define debug_bytewidth_start() - #define debug_bytewidth_end() -#endif - -#if SERIAL_DEBUG_MODE & SERIAL_DEBUG_MODE_WATCH_SYNC - #define debug_sync_start() SERIAL_DBGPIN_PORT |= SERIAL_DBGPIN_MASK - #define debug_sync_end() SERIAL_DBGPIN_PORT &= ~SERIAL_DBGPIN_MASK -#else - #define debug_sync_start() - #define debug_sync_end() -#endif - -#if SERIAL_DEBUG_MODE & SERIAL_DEBUG_MODE_WATCH_IOCHG - #define debug_iochg_on() SERIAL_DBGPIN_PORT |= SERIAL_DBGPIN_MASK - #define debug_iochg_off() SERIAL_DBGPIN_PORT &= ~SERIAL_DBGPIN_MASK -#else - #define debug_iochg_on() - #define debug_iochg_off() -#endif - -#if SERIAL_DEBUG_MODE & SERIAL_DEBUG_MODE_WATCH_PARITY - #define debug_parity_on() SERIAL_DBGPIN_PORT |= SERIAL_DBGPIN_MASK - #define debug_parity_off() SERIAL_DBGPIN_PORT &= ~SERIAL_DBGPIN_MASK -#else - #define debug_parity_on() - #define debug_parity_off() -#endif - -#if SERIAL_DEBUG_MODE & SERIAL_DEBUG_MODE_WATCH_RETRY - #define debug_retry_on() SERIAL_DBGPIN_PORT |= SERIAL_DBGPIN_MASK - #define debug_retry_off() SERIAL_DBGPIN_PORT &= ~SERIAL_DBGPIN_MASK - #define debug_retry_chg() SERIAL_DBGPIN_PORT ^= SERIAL_DBGPIN_MASK -#else - #define debug_retry_on() - #define debug_retry_off() - #define debug_retry_chg() -#endif - -#define SYNC_DEBUG_MODE 0 -#if SYNC_DEBUG_MODE == 0 -#define debug_dummy_delay_recv() -#define debug_dummy_delay_send() -#endif -#if SYNC_DEBUG_MODE == 1 -#define debug_dummy_delay_recv() _delay_us(3); _delay_sub_us(2) -#define debug_dummy_delay_send() -#endif -#if SYNC_DEBUG_MODE == 2 -#define debug_dummy_delay_recv() -#define debug_dummy_delay_send() _delay_us(3); _delay_sub_us(2) -#endif - #endif /* SOFT_SERIAL_H */