From 69ff9091a97a4f076e80aaca917ad1387fd3a907 Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Sat, 14 Jul 2018 17:33:24 +0900
Subject: [PATCH 01/25] txled, rxled off in matrix_init()
---
keyboards/helix/rev2/matrix.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/keyboards/helix/rev2/matrix.c b/keyboards/helix/rev2/matrix.c
index 8a1ce3af1e57..aba55da7c8c0 100644
--- a/keyboards/helix/rev2/matrix.c
+++ b/keyboards/helix/rev2/matrix.c
@@ -102,6 +102,8 @@ void matrix_init(void)
init_cols();
TX_RX_LED_INIT;
+ TXLED0;
+ RXLED0;
// initialize matrix state: all keys off
for (uint8_t i=0; i < MATRIX_ROWS; i++) {
@@ -185,7 +187,7 @@ int serial_transaction(void) {
if(ret==2)RXLED1;
return 1;
}
-RXLED0;
+ RXLED0;
for (int i = 0; i < ROWS_PER_HAND; ++i) {
matrix[slaveOffset+i] = serial_slave_buffer[i];
}
From fc0813614489cf85bdfbbfa243e2606e236893be Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Mon, 9 Jul 2018 01:12:30 +0900
Subject: [PATCH 02/25] add change_reciver2sender()/change_sender2reciver()
This is a change to improve readability.
---
keyboards/helix/serial.c | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/keyboards/helix/serial.c b/keyboards/helix/serial.c
index 591941587789..312dd03d3ebb 100644
--- a/keyboards/helix/serial.c
+++ b/keyboards/helix/serial.c
@@ -173,6 +173,24 @@ void serial_write_byte(uint8_t data) {
serial_low(); // sync_send() / senc_recv() need raise edge
}
+inline static
+void change_sender2reciver(void) {
+ sync_send(); //0
+ serial_delay_half1(); //1
+ serial_low(); //2
+ serial_input_with_pullup(); //2
+ serial_delay_half1(); //3
+}
+
+inline static
+void change_reciver2sender(void) {
+ sync_recv(); //0
+ serial_delay(); //1
+ serial_low(); //3
+ serial_output(); //3
+ serial_delay_half1(); //4
+}
+
// interrupt handle to be used by the slave device
ISR(SERIAL_PIN_INTERRUPT) {
serial_output();
@@ -188,11 +206,7 @@ ISR(SERIAL_PIN_INTERRUPT) {
serial_write_byte(checksum);
// slave switch to input
- sync_send(); //0
- serial_delay_half1(); //1
- serial_low(); //2
- serial_input_with_pullup(); //2
- serial_delay_half1(); //3
+ change_sender2reciver();
// slave recive phase
uint8_t checksum_computed = 0;
@@ -268,11 +282,7 @@ int serial_update_buffers(void) {
}
// master switch to output
- sync_recv(); //0
- serial_delay(); //1
- serial_low(); //3
- serial_output(); // 3
- serial_delay_half1(); //4
+ change_reciver2sender();
// master send phase
uint8_t checksum = 0;
From 54e0f083530c0e33ab2a4d85928793114e4c5399 Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Thu, 19 Jul 2018 04:20:08 +0900
Subject: [PATCH 03/25] add serial_send_packet() / serial_recive_packet()
This is a change to reduce object size.
---
keyboards/helix/serial.c | 69 +++++++++++++++++-----------------------
1 file changed, 30 insertions(+), 39 deletions(-)
diff --git a/keyboards/helix/serial.c b/keyboards/helix/serial.c
index 312dd03d3ebb..588cf583b345 100644
--- a/keyboards/helix/serial.c
+++ b/keyboards/helix/serial.c
@@ -173,6 +173,32 @@ void serial_write_byte(uint8_t data) {
serial_low(); // sync_send() / senc_recv() need raise edge
}
+static
+void serial_send_packet(uint8_t *buffer, uint8_t size) {
+ uint8_t checksum = 0;
+ for (uint8_t i = 0; i < size; ++i) {
+ sync_send();
+ serial_write_byte(buffer[i]);
+ checksum += buffer[i];
+ }
+ sync_send();
+ serial_write_byte(checksum);
+}
+
+static
+uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) {
+ uint8_t checksum_computed = 0;
+ for (uint8_t i = 0; i < size; ++i) {
+ sync_recv();
+ buffer[i] = serial_read_byte();
+ checksum_computed += buffer[i];
+ }
+ sync_recv();
+ uint8_t checksum_received = serial_read_byte();
+
+ return checksum_computed != checksum_received;
+}
+
inline static
void change_sender2reciver(void) {
sync_send(); //0
@@ -196,29 +222,13 @@ ISR(SERIAL_PIN_INTERRUPT) {
serial_output();
// slave send phase
- uint8_t checksum = 0;
- for (int i = 0; i < SERIAL_SLAVE_BUFFER_LENGTH; ++i) {
- sync_send();
- serial_write_byte(serial_slave_buffer[i]);
- checksum += serial_slave_buffer[i];
- }
- sync_send();
- serial_write_byte(checksum);
+ serial_send_packet((uint8_t *)serial_slave_buffer, SERIAL_SLAVE_BUFFER_LENGTH);
// slave switch to input
change_sender2reciver();
// slave recive phase
- uint8_t checksum_computed = 0;
- for (int i = 0; i < SERIAL_MASTER_BUFFER_LENGTH; ++i) {
- sync_recv();
- serial_master_buffer[i] = serial_read_byte();
- checksum_computed += serial_master_buffer[i];
- }
- sync_recv();
- uint8_t checksum_received = serial_read_byte();
-
- if ( checksum_computed != checksum_received ) {
+ if (serial_recive_packet((uint8_t *)serial_master_buffer,SERIAL_MASTER_BUFFER_LENGTH) ) {
status |= SLAVE_DATA_CORRUPT;
} else {
status &= ~SLAVE_DATA_CORRUPT;
@@ -263,18 +273,7 @@ int serial_update_buffers(void) {
// master recive phase
// if the slave is present syncronize with it
-
- uint8_t checksum_computed = 0;
- // receive data from the slave
- for (int i = 0; i < SERIAL_SLAVE_BUFFER_LENGTH; ++i) {
- sync_recv();
- serial_slave_buffer[i] = serial_read_byte();
- checksum_computed += serial_slave_buffer[i];
- }
- sync_recv();
- uint8_t checksum_received = serial_read_byte();
-
- if (checksum_computed != checksum_received) {
+ if (serial_recive_packet((uint8_t *)serial_slave_buffer, SERIAL_SLAVE_BUFFER_LENGTH) ) {
serial_output();
serial_high();
sei();
@@ -285,15 +284,7 @@ int serial_update_buffers(void) {
change_reciver2sender();
// master send phase
- uint8_t checksum = 0;
-
- for (int i = 0; i < SERIAL_MASTER_BUFFER_LENGTH; ++i) {
- sync_send();
- serial_write_byte(serial_master_buffer[i]);
- checksum += serial_master_buffer[i];
- }
- sync_send();
- serial_write_byte(checksum);
+ serial_send_packet((uint8_t *)serial_master_buffer, SERIAL_MASTER_BUFFER_LENGTH);
// always, release the line when not in use
sync_send();
From 04b552f28b91284dcab81fcf672ff4d96fe838cf Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Thu, 19 Jul 2018 04:51:49 +0900
Subject: [PATCH 04/25] add serial_low() at ISR() top
---
keyboards/helix/serial.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/keyboards/helix/serial.c b/keyboards/helix/serial.c
index 588cf583b345..0bda0513664f 100644
--- a/keyboards/helix/serial.c
+++ b/keyboards/helix/serial.c
@@ -128,7 +128,7 @@ void serial_slave_init(void) {
// Used by the sender to synchronize timing with the reciver.
static
void sync_recv(void) {
- for (int i = 0; i < SERIAL_DELAY*5 && serial_read_pin(); i++ ) {
+ for (uint8_t i = 0; i < SERIAL_DELAY*5 && serial_read_pin(); i++ ) {
}
// This shouldn't hang if the slave disconnects because the
// serial line will float to high if the slave does disconnect.
@@ -219,6 +219,7 @@ void change_reciver2sender(void) {
// interrupt handle to be used by the slave device
ISR(SERIAL_PIN_INTERRUPT) {
+ serial_low();
serial_output();
// slave send phase
From d26fce792da93749ae3b50fc2fcd1dbabad6129d Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Thu, 19 Jul 2018 18:08:01 +0900
Subject: [PATCH 05/25] add __attribute__((always_inline)) to some functions
---
keyboards/helix/serial.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/keyboards/helix/serial.c b/keyboards/helix/serial.c
index 0bda0513664f..a4fd012bf8b3 100644
--- a/keyboards/helix/serial.c
+++ b/keyboards/helix/serial.c
@@ -14,6 +14,7 @@
#ifdef USE_SERIAL
+#define ALWAYS_INLINE __attribute__((always_inline))
#define _delay_sub_us(x) __builtin_avr_delay_cycles(x)
// Serial pulse period in microseconds.
@@ -75,12 +76,14 @@ void serial_delay_half2(void) {
_delay_us(SERIAL_DELAY_HALF2);
}
+inline static void serial_output(void) ALWAYS_INLINE;
inline static
void serial_output(void) {
SERIAL_PIN_DDR |= SERIAL_PIN_MASK;
}
// make the serial pin an input with pull-up resistor
+inline static void serial_input_with_pullup(void) ALWAYS_INLINE;
inline static
void serial_input_with_pullup(void) {
SERIAL_PIN_DDR &= ~SERIAL_PIN_MASK;
@@ -92,11 +95,13 @@ uint8_t serial_read_pin(void) {
return !!(SERIAL_PIN_INPUT & SERIAL_PIN_MASK);
}
+inline static void serial_low(void) ALWAYS_INLINE;
inline static
void serial_low(void) {
SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK;
}
+inline static void serial_high(void) ALWAYS_INLINE;
inline static
void serial_high(void) {
SERIAL_PIN_PORT |= SERIAL_PIN_MASK;
From 518e6134b59aa4521803aa701968376ed7e2957a Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Thu, 19 Jul 2018 19:12:01 +0900
Subject: [PATCH 06/25] modify serial_send_packet()/serial_recive_packet()
A little, object size reduction.
A little, speedup.
---
keyboards/helix/serial.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/keyboards/helix/serial.c b/keyboards/helix/serial.c
index a4fd012bf8b3..f2652c20bc71 100644
--- a/keyboards/helix/serial.c
+++ b/keyboards/helix/serial.c
@@ -182,9 +182,11 @@ static
void serial_send_packet(uint8_t *buffer, uint8_t size) {
uint8_t checksum = 0;
for (uint8_t i = 0; i < size; ++i) {
+ uint8_t data;
+ data = buffer[i];
sync_send();
- serial_write_byte(buffer[i]);
- checksum += buffer[i];
+ serial_write_byte(data);
+ checksum += data;
}
sync_send();
serial_write_byte(checksum);
@@ -194,9 +196,11 @@ static
uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) {
uint8_t checksum_computed = 0;
for (uint8_t i = 0; i < size; ++i) {
+ uint8_t data;
sync_recv();
- buffer[i] = serial_read_byte();
- checksum_computed += buffer[i];
+ data = serial_read_byte();
+ buffer[i] = data;
+ checksum_computed += data;
}
sync_recv();
uint8_t checksum_received = serial_read_byte();
From 7f5e5c4563e069cbafc03b10d66b48d6e42b3b23 Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Fri, 20 Jul 2018 01:33:54 +0900
Subject: [PATCH 07/25] add debug code to helix/serial.c
---
keyboards/helix/serial.c | 27 ++++++++++++
keyboards/helix/serial.h | 94 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 121 insertions(+)
diff --git a/keyboards/helix/serial.c b/keyboards/helix/serial.c
index f2652c20bc71..ec7da520eba7 100644
--- a/keyboards/helix/serial.c
+++ b/keyboards/helix/serial.c
@@ -79,6 +79,7 @@ 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;
}
@@ -86,6 +87,7 @@ 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;
}
@@ -108,11 +110,13 @@ void serial_high(void) {
}
void serial_master_init(void) {
+ serial_debug_init();
serial_output();
serial_high();
}
void serial_slave_init(void) {
+ serial_debug_init();
serial_input_with_pullup();
#if SERIAL_PIN_MASK == _BV(PD0)
@@ -133,19 +137,24 @@ void serial_slave_init(void) {
// Used by the sender to synchronize timing with the reciver.
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 slave disconnects because the
// serial line will float to high if the slave 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) {
+ debug_sync_start();
serial_low();
serial_delay();
serial_high();
+ debug_sync_end();
}
// Reads a byte from the serial line
@@ -155,9 +164,12 @@ uint8_t serial_read_byte(void) {
_delay_sub_us(READ_WRITE_START_ADJUST);
for ( uint8_t i = 0; i < 8; ++i) {
serial_delay_half1(); // read the middle of pulses
+ debug_recvsample();
byte = (byte << 1) | serial_read_pin();
+ debug_recvsample();
_delay_sub_us(READ_WRITE_WIDTH_ADJUST);
serial_delay_half2();
+ debug_dummy_delay_recv();
}
return byte;
}
@@ -173,7 +185,10 @@ void serial_write_byte(uint8_t data) {
serial_low();
}
b >>= 1;
+ debug_recvsample();
serial_delay();
+ debug_recvsample();
+ debug_dummy_delay_send();
}
serial_low(); // sync_send() / senc_recv() need raise edge
}
@@ -185,11 +200,15 @@ void serial_send_packet(uint8_t *buffer, uint8_t size) {
uint8_t data;
data = buffer[i];
sync_send();
+ debug_bytewidth_start();
serial_write_byte(data);
+ debug_bytewidth_end();
checksum += data;
}
sync_send();
+ debug_bytewidth_start();
serial_write_byte(checksum);
+ debug_bytewidth_end();
}
static
@@ -198,12 +217,16 @@ 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_byte();
+ debug_bytewidth_end();
buffer[i] = data;
checksum_computed += data;
}
sync_recv();
+ debug_bytewidth_start();
uint8_t checksum_received = serial_read_byte();
+ debug_bytewidth_end();
return checksum_computed != checksum_received;
}
@@ -228,6 +251,8 @@ void change_reciver2sender(void) {
// interrupt handle to be used by the slave device
ISR(SERIAL_PIN_INTERRUPT) {
+ debug_output_mode(); debug_input_mode(); // indicate intterupt entry
+
serial_low();
serial_output();
@@ -245,6 +270,7 @@ ISR(SERIAL_PIN_INTERRUPT) {
}
sync_recv(); //weit master output to high
+ debug_output_mode(); debug_input_mode(); // indicate intterupt exit
}
inline
@@ -298,6 +324,7 @@ int serial_update_buffers(void) {
// always, release the line when not in use
sync_send();
+ debug_input_mode(); debug_output_mode(); // indicate intterupt exit
sei();
return 0;
diff --git a/keyboards/helix/serial.h b/keyboards/helix/serial.h
index c3c9569b2c4a..0c8be44fa8f4 100644
--- a/keyboards/helix/serial.h
+++ b/keyboards/helix/serial.h
@@ -24,4 +24,98 @@ void serial_slave_init(void);
int serial_update_buffers(void);
bool serial_slave_data_corrupt(void);
+
+
+
+// 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 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
+
+// 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
+
+#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 */
From 4b945ac358427d5ae06bd878ab33f2f8e8f75806 Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Fri, 20 Jul 2018 03:29:27 +0900
Subject: [PATCH 08/25] Adjust sampling timing of serial signal being received
---
keyboards/helix/serial.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/keyboards/helix/serial.c b/keyboards/helix/serial.c
index ec7da520eba7..8cc390973d84 100644
--- a/keyboards/helix/serial.c
+++ b/keyboards/helix/serial.c
@@ -22,28 +22,28 @@
#if SELECT_SERIAL_SPEED == 0
// Very High speed
#define SERIAL_DELAY 4 // micro sec
- #define READ_WRITE_START_ADJUST 30 // cycles
- #define READ_WRITE_WIDTH_ADJUST 10 // cycles
+ #define READ_WRITE_START_ADJUST 5 // cycles
+ #define READ_WRITE_WIDTH_ADJUST 2 // cycles
#elif SELECT_SERIAL_SPEED == 1
// High speed
#define SERIAL_DELAY 6 // micro sec
- #define READ_WRITE_START_ADJUST 23 // cycles
- #define READ_WRITE_WIDTH_ADJUST 10 // cycles
+ #define READ_WRITE_START_ADJUST 5 // cycles
+ #define READ_WRITE_WIDTH_ADJUST 2 // cycles
#elif SELECT_SERIAL_SPEED == 2
// Middle speed
#define SERIAL_DELAY 12 // micro sec
- #define READ_WRITE_START_ADJUST 25 // cycles
- #define READ_WRITE_WIDTH_ADJUST 10 // cycles
+ #define READ_WRITE_START_ADJUST 5 // cycles
+ #define READ_WRITE_WIDTH_ADJUST 2 // cycles
#elif SELECT_SERIAL_SPEED == 3
// Low speed
#define SERIAL_DELAY 24 // micro sec
- #define READ_WRITE_START_ADJUST 25 // cycles
- #define READ_WRITE_WIDTH_ADJUST 10 // cycles
+ #define READ_WRITE_START_ADJUST 5 // cycles
+ #define READ_WRITE_WIDTH_ADJUST 2 // cycles
#elif SELECT_SERIAL_SPEED == 4
// Very Low speed
#define SERIAL_DELAY 50 // micro sec
- #define READ_WRITE_START_ADJUST 25 // cycles
- #define READ_WRITE_WIDTH_ADJUST 10 // cycles
+ #define READ_WRITE_START_ADJUST 5 // cycles
+ #define READ_WRITE_WIDTH_ADJUST 2 // cycles
#else
#error Illegal Serial Speed
#endif
From 8804993a89e8b418b64596f4e4411d0eedf4071c Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Sat, 21 Jul 2018 18:37:53 +0900
Subject: [PATCH 09/25] add split_scomm.c/split_scomm.h and change
serial.c/serial.h
serial.c was divided into 2 layers, split_scom.c and serial.c.
The upper layer split_scomm.c is called from matrix.c.
The lower layer serial.c accesses the hardware.
---
keyboards/helix/rev2/matrix.c | 4 +-
keyboards/helix/rev2/rules.mk | 7 ++-
keyboards/helix/rev2/serial_config.h | 3 -
keyboards/helix/rev2/split_scomm.c | 36 ++++++++++++
keyboards/helix/rev2/split_scomm.h | 15 +++++
keyboards/helix/rev2/split_util.c | 2 +-
keyboards/helix/rules.mk | 9 ++-
keyboards/helix/serial.c | 82 +++++++++++++++-------------
keyboards/helix/serial.h | 35 ++++++++----
9 files changed, 131 insertions(+), 62 deletions(-)
create mode 100644 keyboards/helix/rev2/split_scomm.c
create mode 100644 keyboards/helix/rev2/split_scomm.h
diff --git a/keyboards/helix/rev2/matrix.c b/keyboards/helix/rev2/matrix.c
index aba55da7c8c0..40678adae2ab 100644
--- a/keyboards/helix/rev2/matrix.c
+++ b/keyboards/helix/rev2/matrix.c
@@ -34,7 +34,7 @@ along with this program. If not, see .
#ifdef USE_MATRIX_I2C
# include "i2c.h"
#else // USE_SERIAL
-# include "serial.h"
+# include "split_scomm.h"
#endif
#ifndef DEBOUNCE
@@ -182,7 +182,7 @@ int i2c_transaction(void) {
int serial_transaction(void) {
int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
- int ret=serial_update_buffers();
+ int ret=serial_update_buffers(1);
if (ret ) {
if(ret==2)RXLED1;
return 1;
diff --git a/keyboards/helix/rev2/rules.mk b/keyboards/helix/rev2/rules.mk
index 6ab01f44b484..4ea623c43689 100644
--- a/keyboards/helix/rev2/rules.mk
+++ b/keyboards/helix/rev2/rules.mk
@@ -1,3 +1,4 @@
-SRC += rev2/matrix.c \
- rev2/split_util.c \
- ws2812.c
+SRC += rev2/matrix.c
+SRC += rev2/split_util.c
+SRC += rev2/split_scomm.c
+SRC += ws2812.c
diff --git a/keyboards/helix/rev2/serial_config.h b/keyboards/helix/rev2/serial_config.h
index 82c6e4e836e3..d93419e4a359 100644
--- a/keyboards/helix/rev2/serial_config.h
+++ b/keyboards/helix/rev2/serial_config.h
@@ -8,9 +8,6 @@
#define SERIAL_PIN_MASK _BV(PD2)
#define SERIAL_PIN_INTERRUPT INT2_vect
-#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
-#define SERIAL_MASTER_BUFFER_LENGTH MATRIX_ROWS/2
-
//// #error rev2 serial config
#endif /* SOFT_SERIAL_CONFIG_H */
diff --git a/keyboards/helix/rev2/split_scomm.c b/keyboards/helix/rev2/split_scomm.c
new file mode 100644
index 000000000000..e7d97310edb8
--- /dev/null
+++ b/keyboards/helix/rev2/split_scomm.c
@@ -0,0 +1,36 @@
+#ifdef USE_SERIAL
+#include
+#include
+#include
+#include
+#include "serial.h"
+
+uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
+uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
+uint8_t volatile status0 = 0;
+
+SSTD_t transactions[] = {
+ { (uint8_t *)&status0,
+ sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer,
+ sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer
+ }
+};
+
+void serial_master_init(void)
+{
+ soft_serial_initiator_init(transactions);
+}
+
+void serial_slave_init(void)
+{
+ soft_serial_target_init(transactions);
+}
+
+// 0 => no error
+// 1 => slave did not respond
+// 2 => checksum error
+int serial_update_buffers(int master_update)
+{
+ return soft_serial_transaction(0);
+}
+#endif /* USE_SERIAL */
diff --git a/keyboards/helix/rev2/split_scomm.h b/keyboards/helix/rev2/split_scomm.h
new file mode 100644
index 000000000000..902de0213256
--- /dev/null
+++ b/keyboards/helix/rev2/split_scomm.h
@@ -0,0 +1,15 @@
+#ifndef SPLIT_COMM_H
+#define SPLIT_COMM_H
+
+// Buffers for master - slave communication
+#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
+#define SERIAL_MASTER_BUFFER_LENGTH MATRIX_ROWS/2
+
+extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH];
+extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH];
+
+void serial_master_init(void);
+void serial_slave_init(void);
+int serial_update_buffers(int master_changed);
+
+#endif /* SPLIT_COMM_H */
diff --git a/keyboards/helix/rev2/split_util.c b/keyboards/helix/rev2/split_util.c
index beb39fa00591..e1ff8b4379dc 100644
--- a/keyboards/helix/rev2/split_util.c
+++ b/keyboards/helix/rev2/split_util.c
@@ -11,7 +11,7 @@
#ifdef USE_MATRIX_I2C
# include "i2c.h"
#else
-# include "serial.h"
+# include "split_scomm.h"
#endif
volatile bool isLeftHand = true;
diff --git a/keyboards/helix/rules.mk b/keyboards/helix/rules.mk
index c35f93fb07e3..e42f92cf8a7f 100644
--- a/keyboards/helix/rules.mk
+++ b/keyboards/helix/rules.mk
@@ -1,6 +1,9 @@
-SRC += i2c.c \
- serial.c \
- ssd1306.c
+SRC += i2c.c
+SRC += serial.c
+SRC += ssd1306.c
+
+# if firmware size over limit, try this option
+# CFLAGS += -flto
# MCU name
#MCU = at90usb1287
diff --git a/keyboards/helix/serial.c b/keyboards/helix/serial.c
index 8cc390973d84..17de0c792bb6 100644
--- a/keyboards/helix/serial.c
+++ b/keyboards/helix/serial.c
@@ -9,8 +9,10 @@
#include
#include
#include
+#include
#include
#include "serial.h"
+//#include
#ifdef USE_SERIAL
@@ -55,11 +57,7 @@
#define SLAVE_INT_WIDTH 1
#define SLAVE_INT_RESPONSE_TIME SERIAL_DELAY
-uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
-uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
-
-#define SLAVE_DATA_CORRUPT (1<<0)
-volatile uint8_t status = 0;
+static SSTD_t *Transaction_table = NULL;
inline static
void serial_delay(void) {
@@ -109,26 +107,30 @@ void serial_high(void) {
SERIAL_PIN_PORT |= SERIAL_PIN_MASK;
}
-void serial_master_init(void) {
- serial_debug_init();
- serial_output();
- serial_high();
+void soft_serial_initiator_init(SSTD_t *sstd_table)
+{
+ serial_debug_init();
+ Transaction_table = sstd_table;
+ serial_output();
+ serial_high();
}
-void serial_slave_init(void) {
- serial_debug_init();
- serial_input_with_pullup();
+void soft_serial_target_init(SSTD_t *sstd_table)
+{
+ serial_debug_init();
+ Transaction_table = sstd_table;
+ serial_input_with_pullup();
#if SERIAL_PIN_MASK == _BV(PD0)
- // Enable INT0
- EIMSK |= _BV(INT0);
- // Trigger on falling edge of INT0
- EICRA &= ~(_BV(ISC00) | _BV(ISC01));
+ // Enable INT0
+ EIMSK |= _BV(INT0);
+ // Trigger on falling edge of INT0
+ EICRA &= ~(_BV(ISC00) | _BV(ISC01));
#elif SERIAL_PIN_MASK == _BV(PD2)
- // Enable INT2
- EIMSK |= _BV(INT2);
- // Trigger on falling edge of INT2
- EICRA &= ~(_BV(ISC20) | _BV(ISC21));
+ // Enable INT2
+ EIMSK |= _BV(INT2);
+ // Trigger on falling edge of INT2
+ EICRA &= ~(_BV(ISC20) | _BV(ISC21));
#else
#error unknown SERIAL_PIN_MASK value
#endif
@@ -228,7 +230,7 @@ uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) {
uint8_t checksum_received = serial_read_byte();
debug_bytewidth_end();
- return checksum_computed != checksum_received;
+ return checksum_computed == checksum_received;
}
inline static
@@ -255,38 +257,38 @@ ISR(SERIAL_PIN_INTERRUPT) {
serial_low();
serial_output();
+ SSTD_t *trans = Transaction_table;
// slave send phase
- serial_send_packet((uint8_t *)serial_slave_buffer, SERIAL_SLAVE_BUFFER_LENGTH);
-
+ serial_send_packet((uint8_t *)trans->target2initiator_buffer,
+ trans->target2initiator_buffer_size);
// slave switch to input
change_sender2reciver();
// slave recive phase
- if (serial_recive_packet((uint8_t *)serial_master_buffer,SERIAL_MASTER_BUFFER_LENGTH) ) {
- status |= SLAVE_DATA_CORRUPT;
+ if (serial_recive_packet((uint8_t *)trans->initiator2target_buffer,
+ trans->initiator2target_buffer_size) ) {
+ *trans->status = RECIVE_ACCEPTED;
} else {
- status &= ~SLAVE_DATA_CORRUPT;
+ *trans->status = RECIVE_DATA_ERROR;
}
sync_recv(); //weit master output to high
debug_output_mode(); debug_input_mode(); // indicate intterupt exit
}
-inline
-bool serial_slave_DATA_CORRUPT(void) {
- return status & SLAVE_DATA_CORRUPT;
-}
-
-// Copies the serial_slave_buffer to the master and sends the
-// serial_master_buffer to the slave.
+/////////
+// start transaction by initiator
+//
+// int soft_serial_transaction(int sstd_index)
//
// Returns:
-// 0 => no error
-// 1 => slave did not respond
-// 2 => checksum error
-int serial_update_buffers(void) {
+// TRANSACTION_END
+// TRANSACTION_NO_RESPONSE
+// TRANSACTION_DATA_ERROR
+int soft_serial_transaction(int sstd_index) {
// this code is very time dependent, so we need to disable interrupts
+ SSTD_t *trans = &Transaction_table[sstd_index];
cli();
// signal to the slave that we want to start a transaction
@@ -309,7 +311,8 @@ int serial_update_buffers(void) {
// master recive phase
// if the slave is present syncronize with it
- if (serial_recive_packet((uint8_t *)serial_slave_buffer, SERIAL_SLAVE_BUFFER_LENGTH) ) {
+ if (!serial_recive_packet((uint8_t *)trans->target2initiator_buffer,
+ trans->target2initiator_buffer_size) ) {
serial_output();
serial_high();
sei();
@@ -320,7 +323,8 @@ int serial_update_buffers(void) {
change_reciver2sender();
// master send phase
- serial_send_packet((uint8_t *)serial_master_buffer, SERIAL_MASTER_BUFFER_LENGTH);
+ serial_send_packet((uint8_t *)trans->initiator2target_buffer,
+ trans->initiator2target_buffer_size);
// always, release the line when not in use
sync_send();
diff --git a/keyboards/helix/serial.h b/keyboards/helix/serial.h
index 0c8be44fa8f4..2f94f14efac2 100644
--- a/keyboards/helix/serial.h
+++ b/keyboards/helix/serial.h
@@ -12,18 +12,31 @@
// #define SERIAL_PIN_INPUT PIND
// #define SERIAL_PIN_MASK _BV(PD?) ?=0,2
// #define SERIAL_PIN_INTERRUPT INT?_vect ?=0,2
-// #define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
-// #define SERIAL_MASTER_BUFFER_LENGTH MATRIX_ROWS/2
-
-// Buffers for master - slave communication
-extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH];
-extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH];
-
-void serial_master_init(void);
-void serial_slave_init(void);
-int serial_update_buffers(void);
-bool serial_slave_data_corrupt(void);
+// Soft Serial Transaction Descriptor
+typedef struct _SSTD_t {
+ uint8_t *status;
+ uint8_t initiator2target_buffer_size;
+ uint8_t *initiator2target_buffer;
+ uint8_t target2initiator_buffer_size;
+ uint8_t *target2initiator_buffer;
+} SSTD_t;
+
+// initiator is transaction start side
+void soft_serial_initiator_init(SSTD_t *sstd_table);
+// target is interrupt accept side
+void soft_serial_target_init(SSTD_t *sstd_table);
+
+// initiator resullt
+#define TRANSACTION_END 0
+#define TRANSACTION_NO_RESPONSE 1
+#define TRANSACTION_DATA_ERROR 2
+int soft_serial_transaction(int sstd_index);
+
+// target status
+#define RECIVE_ACCEPTED 1
+#define RECIVE_DATA_ERROR 2
+int soft_serial_get_and_clean_target_status(int sstd_index);
From bae4bfe9d7f99b4374ca55638e047704051fa142 Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Sat, 21 Jul 2018 19:05:15 +0900
Subject: [PATCH 10/25] add split_scomm.c/split_scomm.h into helix/rev1
---
keyboards/helix/rev1/matrix.c | 4 +--
keyboards/helix/rev1/rules.mk | 5 ++--
keyboards/helix/rev1/serial_config.h | 3 ---
keyboards/helix/rev1/split_scomm.c | 38 ++++++++++++++++++++++++++++
keyboards/helix/rev1/split_scomm.h | 15 +++++++++++
keyboards/helix/rev1/split_util.c | 2 +-
keyboards/helix/rev2/split_scomm.c | 4 ++-
7 files changed, 62 insertions(+), 9 deletions(-)
create mode 100644 keyboards/helix/rev1/split_scomm.c
create mode 100644 keyboards/helix/rev1/split_scomm.h
diff --git a/keyboards/helix/rev1/matrix.c b/keyboards/helix/rev1/matrix.c
index f2506868eaf5..6613c02b00e8 100644
--- a/keyboards/helix/rev1/matrix.c
+++ b/keyboards/helix/rev1/matrix.c
@@ -35,7 +35,7 @@ along with this program. If not, see .
#ifdef USE_MATRIX_I2C
# include "i2c.h"
#else // USE_SERIAL
-# include "serial.h"
+# include "split_scomm.h"
#endif
#ifndef DEBOUNCE
@@ -178,7 +178,7 @@ int i2c_transaction(void) {
int serial_transaction(void) {
int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
- if (serial_update_buffers()) {
+ if (serial_update_buffers(1)) {
return 1;
}
diff --git a/keyboards/helix/rev1/rules.mk b/keyboards/helix/rev1/rules.mk
index daba80eaea83..5ecfa33a2ab8 100644
--- a/keyboards/helix/rev1/rules.mk
+++ b/keyboards/helix/rev1/rules.mk
@@ -1,4 +1,5 @@
-SRC += rev1/matrix.c \
- rev1/split_util.c
+SRC += rev1/matrix.c
+SRC += rev1/split_util.c
+SRC += rev1/split_scomm.c
BACKLIGHT_ENABLE = no
diff --git a/keyboards/helix/rev1/serial_config.h b/keyboards/helix/rev1/serial_config.h
index 2b668a6afc18..f021d6e04b65 100644
--- a/keyboards/helix/rev1/serial_config.h
+++ b/keyboards/helix/rev1/serial_config.h
@@ -8,9 +8,6 @@
#define SERIAL_PIN_MASK _BV(PD0)
#define SERIAL_PIN_INTERRUPT INT0_vect
-#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
-#define SERIAL_MASTER_BUFFER_LENGTH 1
-
/// #error rev1 serial config
#endif /* SOFT_SERIAL_CONFIG_H */
diff --git a/keyboards/helix/rev1/split_scomm.c b/keyboards/helix/rev1/split_scomm.c
new file mode 100644
index 000000000000..14491abe8464
--- /dev/null
+++ b/keyboards/helix/rev1/split_scomm.c
@@ -0,0 +1,38 @@
+#ifdef USE_SERIAL
+#include
+#include
+#include
+#include
+#include "serial.h"
+
+uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
+uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
+uint8_t volatile status0 = 0;
+
+SSTD_t transactions[] = {
+
+#define WHOLE_MATRIX_EXCHANGE 0
+ { (uint8_t *)&status0,
+ sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer,
+ sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer
+ }
+};
+
+void serial_master_init(void)
+{
+ soft_serial_initiator_init(transactions);
+}
+
+void serial_slave_init(void)
+{
+ soft_serial_target_init(transactions);
+}
+
+// 0 => no error
+// 1 => slave did not respond
+// 2 => checksum error
+int serial_update_buffers(int master_update)
+{
+ return soft_serial_transaction(WHOLE_MATRIX_EXCHANGE);
+}
+#endif /* USE_SERIAL */
diff --git a/keyboards/helix/rev1/split_scomm.h b/keyboards/helix/rev1/split_scomm.h
new file mode 100644
index 000000000000..c81eff4ffe7b
--- /dev/null
+++ b/keyboards/helix/rev1/split_scomm.h
@@ -0,0 +1,15 @@
+#ifndef SPLIT_COMM_H
+#define SPLIT_COMM_H
+
+// Buffers for master - slave communication
+#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
+#define SERIAL_MASTER_BUFFER_LENGTH 1
+
+extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH];
+extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH];
+
+void serial_master_init(void);
+void serial_slave_init(void);
+int serial_update_buffers(int master_changed);
+
+#endif /* SPLIT_COMM_H */
diff --git a/keyboards/helix/rev1/split_util.c b/keyboards/helix/rev1/split_util.c
index 5debd6e00bd2..fe17e14f844b 100644
--- a/keyboards/helix/rev1/split_util.c
+++ b/keyboards/helix/rev1/split_util.c
@@ -12,7 +12,7 @@
#ifdef USE_MATRIX_I2C
# include "i2c.h"
#else
-# include "serial.h"
+# include "split_scomm.h"
#endif
volatile bool isLeftHand = true;
diff --git a/keyboards/helix/rev2/split_scomm.c b/keyboards/helix/rev2/split_scomm.c
index e7d97310edb8..14491abe8464 100644
--- a/keyboards/helix/rev2/split_scomm.c
+++ b/keyboards/helix/rev2/split_scomm.c
@@ -10,6 +10,8 @@ uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
uint8_t volatile status0 = 0;
SSTD_t transactions[] = {
+
+#define WHOLE_MATRIX_EXCHANGE 0
{ (uint8_t *)&status0,
sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer,
sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer
@@ -31,6 +33,6 @@ void serial_slave_init(void)
// 2 => checksum error
int serial_update_buffers(int master_update)
{
- return soft_serial_transaction(0);
+ return soft_serial_transaction(WHOLE_MATRIX_EXCHANGE);
}
#endif /* USE_SERIAL */
From 8ec5499b5a515f7d64f2517d54da7ddcdaeecc6a Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Sat, 21 Jul 2018 19:46:45 +0900
Subject: [PATCH 11/25] reduce object size helix/rev2/matrix.c
---
keyboards/helix/rev2/matrix.c | 27 ++++++++-------------------
1 file changed, 8 insertions(+), 19 deletions(-)
diff --git a/keyboards/helix/rev2/matrix.c b/keyboards/helix/rev2/matrix.c
index 40678adae2ab..763f97d4ba00 100644
--- a/keyboards/helix/rev2/matrix.c
+++ b/keyboards/helix/rev2/matrix.c
@@ -20,6 +20,7 @@ along with this program. If not, see .
*/
#include
#include
+#include
#include
#include
#include
@@ -188,9 +189,8 @@ int serial_transaction(void) {
return 1;
}
RXLED0;
- for (int i = 0; i < ROWS_PER_HAND; ++i) {
- matrix[slaveOffset+i] = serial_slave_buffer[i];
- }
+ memcpy(&matrix[slaveOffset],
+ (void *)serial_slave_buffer, sizeof(serial_slave_buffer));
return 0;
}
#endif
@@ -201,19 +201,9 @@ uint8_t matrix_scan(void)
matrix_master_scan();
}else{
matrix_slave_scan();
-
-// if(serial_slave_DATA_CORRUPT()){
-// TXLED0;
- int offset = (isLeftHand) ? ROWS_PER_HAND : 0;
-
- for (int i = 0; i < ROWS_PER_HAND; ++i) {
- matrix[offset+i] = serial_master_buffer[i];
- }
-
-// }else{
-// TXLED1;
-// }
-
+ int offset = (isLeftHand) ? ROWS_PER_HAND : 0;
+ memcpy(&matrix[offset],
+ (void *)serial_master_buffer, sizeof(serial_master_buffer));
matrix_scan_quantum();
}
return 1;
@@ -233,9 +223,8 @@ uint8_t matrix_master_scan(void) {
// i2c_slave_buffer[i] = matrix[offset+i];
// }
#else // USE_SERIAL
- for (int i = 0; i < ROWS_PER_HAND; ++i) {
- serial_master_buffer[i] = matrix[offset+i];
- }
+ memcpy((void *)serial_master_buffer,
+ &matrix[offset], sizeof(serial_master_buffer));
#endif
#endif
From f8370ac02e2d79a9f1a1ee36b4eef75d0e6fd8a3 Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Sat, 21 Jul 2018 23:54:47 +0900
Subject: [PATCH 12/25] remove checksum check, add parity check
---
keyboards/helix/serial.c | 112 ++++++++++++++++++++++-----------------
1 file changed, 64 insertions(+), 48 deletions(-)
diff --git a/keyboards/helix/serial.c b/keyboards/helix/serial.c
index 17de0c792bb6..d0a273805fb2 100644
--- a/keyboards/helix/serial.c
+++ b/keyboards/helix/serial.c
@@ -17,6 +17,7 @@
#ifdef USE_SERIAL
#define ALWAYS_INLINE __attribute__((always_inline))
+#define NO_INLINE __attribute__((noinline))
#define _delay_sub_us(x) __builtin_avr_delay_cycles(x)
// Serial pulse period in microseconds.
@@ -24,28 +25,28 @@
#if SELECT_SERIAL_SPEED == 0
// Very High speed
#define SERIAL_DELAY 4 // micro sec
- #define READ_WRITE_START_ADJUST 5 // cycles
- #define READ_WRITE_WIDTH_ADJUST 2 // cycles
+ #define READ_WRITE_START_ADJUST 33 // cycles
+ #define READ_WRITE_WIDTH_ADJUST 3 // cycles
#elif SELECT_SERIAL_SPEED == 1
// High speed
#define SERIAL_DELAY 6 // micro sec
- #define READ_WRITE_START_ADJUST 5 // cycles
- #define READ_WRITE_WIDTH_ADJUST 2 // cycles
+ #define READ_WRITE_START_ADJUST 30 // cycles
+ #define READ_WRITE_WIDTH_ADJUST 3 // cycles
#elif SELECT_SERIAL_SPEED == 2
// Middle speed
#define SERIAL_DELAY 12 // micro sec
- #define READ_WRITE_START_ADJUST 5 // cycles
- #define READ_WRITE_WIDTH_ADJUST 2 // cycles
+ #define READ_WRITE_START_ADJUST 30 // cycles
+ #define READ_WRITE_WIDTH_ADJUST 3 // cycles
#elif SELECT_SERIAL_SPEED == 3
// Low speed
#define SERIAL_DELAY 24 // micro sec
- #define READ_WRITE_START_ADJUST 5 // cycles
- #define READ_WRITE_WIDTH_ADJUST 2 // cycles
+ #define READ_WRITE_START_ADJUST 30 // cycles
+ #define READ_WRITE_WIDTH_ADJUST 3 // cycles
#elif SELECT_SERIAL_SPEED == 4
// Very Low speed
#define SERIAL_DELAY 50 // micro sec
- #define READ_WRITE_START_ADJUST 5 // cycles
- #define READ_WRITE_WIDTH_ADJUST 2 // cycles
+ #define READ_WRITE_START_ADJUST 30 // cycles
+ #define READ_WRITE_WIDTH_ADJUST 3 // cycles
#else
#error Illegal Serial Speed
#endif
@@ -160,77 +161,92 @@ void sync_send(void) {
}
// Reads a byte from the serial line
-static
-uint8_t serial_read_byte(void) {
- uint8_t byte = 0;
+static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) NO_INLINE;
+static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) {
+ uint8_t byte, i, p, pb;
+
_delay_sub_us(READ_WRITE_START_ADJUST);
- for ( uint8_t i = 0; i < 8; ++i) {
- serial_delay_half1(); // read the middle of pulses
- debug_recvsample();
- byte = (byte << 1) | serial_read_pin();
- debug_recvsample();
- _delay_sub_us(READ_WRITE_WIDTH_ADJUST);
- serial_delay_half2();
- debug_dummy_delay_recv();
+ 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;
}
// Sends a byte with MSB ordering
-static
-void serial_write_byte(uint8_t data) {
- uint8_t b = 1<<7;
- while( b ) {
- if(data & b) {
- serial_high();
- } else {
- serial_low();
+void serial_write_chunk(uint8_t data, uint8_t bit) NO_INLINE;
+void serial_write_chunk(uint8_t data, uint8_t bit) {
+ uint8_t b, p;
+ for( p = 0, b = 1<<(bit-1); b ; b >>= 1) {
+ if(data & b) {
+ serial_high(); p ^= 1;
+ } else {
+ serial_low(); p ^= 0;
+ }
+ debug_recvsample();
+ serial_delay();
+ debug_recvsample();
+ debug_dummy_delay_send();
}
- b >>= 1;
+ /* 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
+
+ serial_low(); // sync_send() / senc_recv() need raise edge
}
+static void serial_send_packet(uint8_t *buffer, uint8_t size) NO_INLINE;
static
void serial_send_packet(uint8_t *buffer, uint8_t size) {
- uint8_t checksum = 0;
for (uint8_t i = 0; i < size; ++i) {
uint8_t data;
data = buffer[i];
sync_send();
debug_bytewidth_start();
- serial_write_byte(data);
+ serial_write_chunk(data,8);
debug_bytewidth_end();
- checksum += data;
}
- sync_send();
- debug_bytewidth_start();
- serial_write_byte(checksum);
- debug_bytewidth_end();
}
+static uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) NO_INLINE;
static
uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) {
- uint8_t checksum_computed = 0;
+ uint8_t pecount = 0;
for (uint8_t i = 0; i < size; ++i) {
uint8_t data;
sync_recv();
debug_bytewidth_start();
- data = serial_read_byte();
+ data = serial_read_chunk(&pecount, 8);
debug_bytewidth_end();
buffer[i] = data;
- checksum_computed += data;
}
- sync_recv();
- debug_bytewidth_start();
- uint8_t checksum_received = serial_read_byte();
- debug_bytewidth_end();
-
- return checksum_computed == checksum_received;
+ return pecount == 0;
}
inline static
From a7e41fe2224f20aec08ef30fdad1671a43aaeb68 Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Sun, 22 Jul 2018 00:22:52 +0900
Subject: [PATCH 13/25] force occur parity error for test
---
keyboards/helix/serial.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/keyboards/helix/serial.c b/keyboards/helix/serial.c
index d0a273805fb2..515794eac864 100644
--- a/keyboards/helix/serial.c
+++ b/keyboards/helix/serial.c
@@ -199,6 +199,7 @@ static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) {
void serial_write_chunk(uint8_t data, uint8_t bit) NO_INLINE;
void serial_write_chunk(uint8_t data, uint8_t bit) {
uint8_t b, p;
+ int perr = 0; if( data & 0x10 ) perr = 1; /// test parity check!!!
for( p = 0, b = 1<<(bit-1); b ; b >>= 1) {
if(data & b) {
serial_high(); p ^= 1;
@@ -210,6 +211,7 @@ void serial_write_chunk(uint8_t data, uint8_t bit) {
debug_recvsample();
debug_dummy_delay_send();
}
+ p ^= perr;/// test parity check!!!
/* send parity bit */
if(p & 1) { serial_high(); }
else { serial_low(); }
@@ -286,7 +288,9 @@ ISR(SERIAL_PIN_INTERRUPT) {
trans->initiator2target_buffer_size) ) {
*trans->status = RECIVE_ACCEPTED;
} else {
+ debug_parity_on();
*trans->status = RECIVE_DATA_ERROR;
+ debug_parity_off();
}
sync_recv(); //weit master output to high
@@ -329,8 +333,10 @@ int soft_serial_transaction(int sstd_index) {
// if the slave is present syncronize with it
if (!serial_recive_packet((uint8_t *)trans->target2initiator_buffer,
trans->target2initiator_buffer_size) ) {
+ debug_parity_on();
serial_output();
serial_high();
+ debug_parity_off();
sei();
return 2;
}
From 1947f3d36801969efb4a8a10cab8ae6a6580d9b6 Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Sun, 22 Jul 2018 00:24:48 +0900
Subject: [PATCH 14/25] parity test ok. remove test code
---
keyboards/helix/serial.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/keyboards/helix/serial.c b/keyboards/helix/serial.c
index 515794eac864..145453d9790a 100644
--- a/keyboards/helix/serial.c
+++ b/keyboards/helix/serial.c
@@ -199,7 +199,6 @@ static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) {
void serial_write_chunk(uint8_t data, uint8_t bit) NO_INLINE;
void serial_write_chunk(uint8_t data, uint8_t bit) {
uint8_t b, p;
- int perr = 0; if( data & 0x10 ) perr = 1; /// test parity check!!!
for( p = 0, b = 1<<(bit-1); b ; b >>= 1) {
if(data & b) {
serial_high(); p ^= 1;
@@ -211,7 +210,6 @@ void serial_write_chunk(uint8_t data, uint8_t bit) {
debug_recvsample();
debug_dummy_delay_send();
}
- p ^= perr;/// test parity check!!!
/* send parity bit */
if(p & 1) { serial_high(); }
else { serial_low(); }
From 7da9081fb18eea1e518fc1aa4b173be222b4175b Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Sun, 22 Jul 2018 13:26:53 +0900
Subject: [PATCH 15/25] change some comment & add skip code when buffer_size ==
0
---
keyboards/helix/serial.c | 83 ++++++++++++++++++++++------------------
1 file changed, 46 insertions(+), 37 deletions(-)
diff --git a/keyboards/helix/serial.c b/keyboards/helix/serial.c
index 145453d9790a..930c975d27c0 100644
--- a/keyboards/helix/serial.c
+++ b/keyboards/helix/serial.c
@@ -138,19 +138,21 @@ void soft_serial_target_init(SSTD_t *sstd_table)
}
// Used by the sender to synchronize timing with the reciver.
+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 slave disconnects because the
- // serial line will float to high if the slave does disconnect.
+ // 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();
@@ -267,7 +269,7 @@ void change_reciver2sender(void) {
serial_delay_half1(); //4
}
-// interrupt handle to be used by the slave device
+// interrupt handle to be used by the target device
ISR(SERIAL_PIN_INTERRUPT) {
debug_output_mode(); debug_input_mode(); // indicate intterupt entry
@@ -275,23 +277,26 @@ ISR(SERIAL_PIN_INTERRUPT) {
serial_output();
SSTD_t *trans = Transaction_table;
- // slave send phase
- serial_send_packet((uint8_t *)trans->target2initiator_buffer,
- trans->target2initiator_buffer_size);
- // slave switch to input
+ // target send phase
+ if( trans->target2initiator_buffer_size > 0 )
+ serial_send_packet((uint8_t *)trans->target2initiator_buffer,
+ trans->target2initiator_buffer_size);
+ // target switch to input
change_sender2reciver();
- // slave recive phase
- if (serial_recive_packet((uint8_t *)trans->initiator2target_buffer,
- trans->initiator2target_buffer_size) ) {
- *trans->status = RECIVE_ACCEPTED;
- } else {
- debug_parity_on();
- *trans->status = RECIVE_DATA_ERROR;
- debug_parity_off();
+ // target recive phase
+ if( trans->initiator2target_buffer_size > 0 ) {
+ if (serial_recive_packet((uint8_t *)trans->initiator2target_buffer,
+ trans->initiator2target_buffer_size) ) {
+ *trans->status = RECIVE_ACCEPTED;
+ } else {
+ debug_parity_on();
+ *trans->status = RECIVE_DATA_ERROR;
+ debug_parity_off();
+ }
}
- sync_recv(); //weit master output to high
+ sync_recv(); //weit initiator output to high
debug_output_mode(); debug_input_mode(); // indicate intterupt exit
}
@@ -309,49 +314,53 @@ int soft_serial_transaction(int sstd_index) {
SSTD_t *trans = &Transaction_table[sstd_index];
cli();
- // signal to the slave that we want to start a transaction
+ // signal to the target that we want to start a transaction
serial_output();
serial_low();
_delay_us(SLAVE_INT_WIDTH);
- // wait for the slaves response
+ // wait for the target response
serial_input_with_pullup();
_delay_us(SLAVE_INT_RESPONSE_TIME);
- // check if the slave is present
+ // check if the target is present
if (serial_read_pin()) {
- // slave failed to pull the line low, assume not present
+ // target failed to pull the line low, assume not present
serial_output();
serial_high();
sei();
- return 1;
+ return TRANSACTION_NO_RESPONSE;
}
- // master recive phase
- // if the slave is present syncronize with it
- if (!serial_recive_packet((uint8_t *)trans->target2initiator_buffer,
- trans->target2initiator_buffer_size) ) {
- debug_parity_on();
- serial_output();
- serial_high();
- debug_parity_off();
- sei();
- return 2;
- }
+ // initiator recive phase
+ // if the target is present syncronize with it
+ 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();
+ sei();
+ return TRANSACTION_DATA_ERROR;
+ }
+ }
- // master switch to output
+ // initiator switch to output
change_reciver2sender();
- // master send phase
- serial_send_packet((uint8_t *)trans->initiator2target_buffer,
- trans->initiator2target_buffer_size);
+ // initiator send phase
+ if( trans->initiator2target_buffer_size > 0 ) {
+ serial_send_packet((uint8_t *)trans->initiator2target_buffer,
+ trans->initiator2target_buffer_size);
+ }
// always, release the line when not in use
sync_send();
debug_input_mode(); debug_output_mode(); // indicate intterupt exit
sei();
- return 0;
+ return TRANSACTION_END;
}
#endif
From 2b4f7d3400e156b971ed53d8561c63fc60893c1b Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Sun, 22 Jul 2018 18:03:33 +0900
Subject: [PATCH 16/25] serial.c: multiple types of transaction support
Add 4 bits transaction-type field at packet top.
Select Transaction Descriptor Table entry by transaction-type.
---
.../rev1/keymaps/OLED_sample/serial_config.h | 3 +-
keyboards/helix/rev1/serial_config.h | 2 +
keyboards/helix/rev1/split_scomm.c | 4 +-
keyboards/helix/rev2/serial_config.h | 3 +
keyboards/helix/rev2/split_scomm.c | 14 ++-
keyboards/helix/serial.c | 93 +++++++++++++++++--
keyboards/helix/serial.h | 24 +++--
7 files changed, 125 insertions(+), 18 deletions(-)
diff --git a/keyboards/helix/rev1/keymaps/OLED_sample/serial_config.h b/keyboards/helix/rev1/keymaps/OLED_sample/serial_config.h
index be2e7cb8b16c..009052fa8a11 100644
--- a/keyboards/helix/rev1/keymaps/OLED_sample/serial_config.h
+++ b/keyboards/helix/rev1/keymaps/OLED_sample/serial_config.h
@@ -8,8 +8,7 @@
#define SERIAL_PIN_MASK _BV(PD2)
#define SERIAL_PIN_INTERRUPT INT2_vect
-#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
-#define SERIAL_MASTER_BUFFER_LENGTH 1
+#define SERIAL_USE_SIMPLE_TRANSACTION
//// #error rev1/keymaps/OLED_sample serial config
diff --git a/keyboards/helix/rev1/serial_config.h b/keyboards/helix/rev1/serial_config.h
index f021d6e04b65..36e60305e2af 100644
--- a/keyboards/helix/rev1/serial_config.h
+++ b/keyboards/helix/rev1/serial_config.h
@@ -8,6 +8,8 @@
#define SERIAL_PIN_MASK _BV(PD0)
#define SERIAL_PIN_INTERRUPT INT0_vect
+#define SERIAL_USE_SIMPLE_TRANSACTION
+
/// #error rev1 serial config
#endif /* SOFT_SERIAL_CONFIG_H */
diff --git a/keyboards/helix/rev1/split_scomm.c b/keyboards/helix/rev1/split_scomm.c
index 14491abe8464..a5c0485e3072 100644
--- a/keyboards/helix/rev1/split_scomm.c
+++ b/keyboards/helix/rev1/split_scomm.c
@@ -10,8 +10,6 @@ uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
uint8_t volatile status0 = 0;
SSTD_t transactions[] = {
-
-#define WHOLE_MATRIX_EXCHANGE 0
{ (uint8_t *)&status0,
sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer,
sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer
@@ -33,6 +31,6 @@ void serial_slave_init(void)
// 2 => checksum error
int serial_update_buffers(int master_update)
{
- return soft_serial_transaction(WHOLE_MATRIX_EXCHANGE);
+ return soft_serial_transaction();
}
#endif /* USE_SERIAL */
diff --git a/keyboards/helix/rev2/serial_config.h b/keyboards/helix/rev2/serial_config.h
index d93419e4a359..9664ba159f99 100644
--- a/keyboards/helix/rev2/serial_config.h
+++ b/keyboards/helix/rev2/serial_config.h
@@ -8,6 +8,9 @@
#define SERIAL_PIN_MASK _BV(PD2)
#define SERIAL_PIN_INTERRUPT INT2_vect
+// if you need more program area, use this macro
+// #define SERIAL_USE_SIMPLE_TRANSACTION
+
//// #error rev2 serial config
#endif /* SOFT_SERIAL_CONFIG_H */
diff --git a/keyboards/helix/rev2/split_scomm.c b/keyboards/helix/rev2/split_scomm.c
index 14491abe8464..1ddd9b8b7d57 100644
--- a/keyboards/helix/rev2/split_scomm.c
+++ b/keyboards/helix/rev2/split_scomm.c
@@ -9,14 +9,22 @@ uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
uint8_t volatile status0 = 0;
+#ifdef SERIAL_USE_SIMPLE_TRANSACTION
+SSTD_t transactions[] = {
+ { (uint8_t *)&status0,
+ sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer,
+ sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer
+ }
+};
+#else
SSTD_t transactions[] = {
-
#define WHOLE_MATRIX_EXCHANGE 0
{ (uint8_t *)&status0,
sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer,
sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer
}
};
+#endif
void serial_master_init(void)
{
@@ -33,6 +41,10 @@ void serial_slave_init(void)
// 2 => checksum error
int serial_update_buffers(int master_update)
{
+#ifdef SERIAL_USE_SIMPLE_TRANSACTION
+ return soft_serial_transaction();
+#else
return soft_serial_transaction(WHOLE_MATRIX_EXCHANGE);
+#endif
}
#endif /* USE_SERIAL */
diff --git a/keyboards/helix/serial.c b/keyboards/helix/serial.c
index 930c975d27c0..0870ddf10668 100644
--- a/keyboards/helix/serial.c
+++ b/keyboards/helix/serial.c
@@ -21,6 +21,8 @@
#define _delay_sub_us(x) __builtin_avr_delay_cycles(x)
// Serial pulse period in microseconds.
+#define TID_SEND_ADJUST 14
+
#define SELECT_SERIAL_SPEED 1
#if SELECT_SERIAL_SPEED == 0
// Very High speed
@@ -55,8 +57,13 @@
#define SERIAL_DELAY_HALF1 (SERIAL_DELAY/2)
#define SERIAL_DELAY_HALF2 (SERIAL_DELAY - SERIAL_DELAY/2)
-#define SLAVE_INT_WIDTH 1
-#define SLAVE_INT_RESPONSE_TIME SERIAL_DELAY
+#define SLAVE_INT_WIDTH_US 1
+#ifdef SERIAL_USE_SIMPLE_TRANSACTION
+ #define SLAVE_INT_RESPONSE_TIME SERIAL_DELAY
+#else
+ #define SLAVE_INT_ACK_WIDTH_UNIT 2
+ #define SLAVE_INT_ACK_WIDTH 4
+#endif
static SSTD_t *Transaction_table = NULL;
@@ -272,10 +279,31 @@ 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
+#ifdef SERIAL_USE_SIMPLE_TRANSACTION
serial_low();
serial_output();
SSTD_t *trans = Transaction_table;
+#else
+ // recive transaction table index
+ 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();
+
+ serial_high(); // response step1 low->high
+ serial_output();
+ _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT*SLAVE_INT_ACK_WIDTH);
+ SSTD_t *trans = &Transaction_table[tid];
+ serial_low(); // response step2 ack high->low
+#endif
// target send phase
if( trans->target2initiator_buffer_size > 0 )
@@ -288,10 +316,10 @@ ISR(SERIAL_PIN_INTERRUPT) {
if( trans->initiator2target_buffer_size > 0 ) {
if (serial_recive_packet((uint8_t *)trans->initiator2target_buffer,
trans->initiator2target_buffer_size) ) {
- *trans->status = RECIVE_ACCEPTED;
+ *trans->status = TRANSACTION_ACCEPTED;
} else {
debug_parity_on();
- *trans->status = RECIVE_DATA_ERROR;
+ *trans->status = TRANSACTION_DATA_ERROR;
debug_parity_off();
}
}
@@ -309,16 +337,22 @@ ISR(SERIAL_PIN_INTERRUPT) {
// TRANSACTION_END
// TRANSACTION_NO_RESPONSE
// TRANSACTION_DATA_ERROR
+// this code is very time dependent, so we need to disable interrupts
+#ifdef SERIAL_USE_SIMPLE_TRANSACTION
+int soft_serial_transaction(void) {
+ SSTD_t *trans = Transaction_table;
+#else
int soft_serial_transaction(int sstd_index) {
- // this code is very time dependent, so we need to disable interrupts
SSTD_t *trans = &Transaction_table[sstd_index];
+#endif
cli();
// signal to the target that we want to start a transaction
serial_output();
serial_low();
- _delay_us(SLAVE_INT_WIDTH);
+ _delay_us(SLAVE_INT_WIDTH_US);
+#ifdef SERIAL_USE_SIMPLE_TRANSACTION
// wait for the target response
serial_input_with_pullup();
_delay_us(SLAVE_INT_RESPONSE_TIME);
@@ -328,10 +362,44 @@ int soft_serial_transaction(int sstd_index) {
// target failed to pull the line low, assume not present
serial_output();
serial_high();
+ *trans->status = TRANSACTION_NO_RESPONSE;
sei();
return TRANSACTION_NO_RESPONSE;
}
+#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
+ serial_output();
+ serial_high();
+ *trans->status = TRANSACTION_NO_RESPONSE;
+ sei();
+ return TRANSACTION_NO_RESPONSE;
+ }
+ debug_output_mode();
+ _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT);
+ debug_input_mode(); // indicate check pin timeing
+ }
+#endif
+
// initiator recive phase
// if the target is present syncronize with it
if( trans->target2initiator_buffer_size > 0 ) {
@@ -341,6 +409,7 @@ int soft_serial_transaction(int sstd_index) {
serial_output();
serial_high();
debug_parity_off();
+ *trans->status = TRANSACTION_DATA_ERROR;
sei();
return TRANSACTION_DATA_ERROR;
}
@@ -359,8 +428,20 @@ int soft_serial_transaction(int sstd_index) {
sync_send();
debug_input_mode(); debug_output_mode(); // indicate intterupt exit
+ *trans->status = TRANSACTION_END;
sei();
return TRANSACTION_END;
}
+#ifndef SERIAL_USE_SIMPLE_TRANSACTION
+int soft_serial_get_and_clean_status(int sstd_index) {
+ SSTD_t *trans = &Transaction_table[sstd_index];
+ cli();
+ int retval = *trans->status;
+ *trans->status = 0;;
+ sei();
+ return retval;
+}
+#endif
+
#endif
diff --git a/keyboards/helix/serial.h b/keyboards/helix/serial.h
index 2f94f14efac2..8664f12eb98c 100644
--- a/keyboards/helix/serial.h
+++ b/keyboards/helix/serial.h
@@ -29,15 +29,27 @@ void soft_serial_target_init(SSTD_t *sstd_table);
// initiator resullt
#define TRANSACTION_END 0
-#define TRANSACTION_NO_RESPONSE 1
-#define TRANSACTION_DATA_ERROR 2
+#define TRANSACTION_NO_RESPONSE 0x1
+#define TRANSACTION_DATA_ERROR 0x2
+#ifdef SERIAL_USE_SIMPLE_TRANSACTION
+int soft_serial_transaction(void);
+#else
int soft_serial_transaction(int sstd_index);
+#endif
// target status
-#define RECIVE_ACCEPTED 1
-#define RECIVE_DATA_ERROR 2
-int soft_serial_get_and_clean_target_status(int sstd_index);
-
+// *SSTD_t.status has
+// initiator:
+// TRANSACTION_END
+// or TRANSACTION_NO_RESPONSE
+// or TRANSACTION_DATA_ERROR
+// target:
+// TRANSACTION_DATA_ERROR
+// or TRANSACTION_ACCEPTED
+#define TRANSACTION_ACCEPTED 0x4
+#ifndef SERIAL_USE_SIMPLE_TRANSACTION
+int soft_serial_get_and_clean_status(int sstd_index);
+#endif
// debug flags
From 3f4cef6c84cc6ae9f28efe31b3b9fcd038ece541 Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Sun, 22 Jul 2018 22:11:44 +0900
Subject: [PATCH 17/25] helix serial master-slave transaction optimize
Using multi-type transaction feature of serial.c, communication contents between master slaves were optimized.
---
.../rev1/keymaps/OLED_sample/serial_config.h | 2 -
keyboards/helix/rev1/serial_config.h | 2 -
keyboards/helix/rev2/matrix.c | 23 +++++++++--
keyboards/helix/rev2/serial_config.h | 4 +-
keyboards/helix/rev2/split_scomm.c | 40 ++++++++++++++++---
keyboards/helix/rev2/split_scomm.h | 3 ++
keyboards/helix/serial.c | 10 ++---
keyboards/helix/serial.h | 4 +-
8 files changed, 66 insertions(+), 22 deletions(-)
diff --git a/keyboards/helix/rev1/keymaps/OLED_sample/serial_config.h b/keyboards/helix/rev1/keymaps/OLED_sample/serial_config.h
index 009052fa8a11..289a165fa3f4 100644
--- a/keyboards/helix/rev1/keymaps/OLED_sample/serial_config.h
+++ b/keyboards/helix/rev1/keymaps/OLED_sample/serial_config.h
@@ -8,8 +8,6 @@
#define SERIAL_PIN_MASK _BV(PD2)
#define SERIAL_PIN_INTERRUPT INT2_vect
-#define SERIAL_USE_SIMPLE_TRANSACTION
-
//// #error rev1/keymaps/OLED_sample serial config
#endif /* SOFT_SERIAL_CONFIG_H */
diff --git a/keyboards/helix/rev1/serial_config.h b/keyboards/helix/rev1/serial_config.h
index 36e60305e2af..f021d6e04b65 100644
--- a/keyboards/helix/rev1/serial_config.h
+++ b/keyboards/helix/rev1/serial_config.h
@@ -8,8 +8,6 @@
#define SERIAL_PIN_MASK _BV(PD0)
#define SERIAL_PIN_INTERRUPT INT0_vect
-#define SERIAL_USE_SIMPLE_TRANSACTION
-
/// #error rev1 serial config
#endif /* SOFT_SERIAL_CONFIG_H */
diff --git a/keyboards/helix/rev2/matrix.c b/keyboards/helix/rev2/matrix.c
index 763f97d4ba00..fd64c37ab138 100644
--- a/keyboards/helix/rev2/matrix.c
+++ b/keyboards/helix/rev2/matrix.c
@@ -181,11 +181,11 @@ int i2c_transaction(void) {
#else // USE_SERIAL
-int serial_transaction(void) {
+int serial_transaction(int master_changed) {
int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
- int ret=serial_update_buffers(1);
+ int ret=serial_update_buffers(master_changed);
if (ret ) {
- if(ret==2)RXLED1;
+ if(ret==2) RXLED1;
return 1;
}
RXLED0;
@@ -213,6 +213,7 @@ uint8_t matrix_scan(void)
uint8_t matrix_master_scan(void) {
int ret = _matrix_scan();
+ int mchanged = 1;
#ifndef KEYBOARD_helix_rev1
int offset = (isLeftHand) ? 0 : ROWS_PER_HAND;
@@ -223,6 +224,10 @@ uint8_t matrix_master_scan(void) {
// i2c_slave_buffer[i] = matrix[offset+i];
// }
#else // USE_SERIAL
+ #ifdef SERIAL_USE_MULTI_TRANSACTION
+ mchanged = memcmp((void *)serial_master_buffer,
+ &matrix[offset], sizeof(serial_master_buffer));
+ #endif
memcpy((void *)serial_master_buffer,
&matrix[offset], sizeof(serial_master_buffer));
#endif
@@ -231,7 +236,7 @@ uint8_t matrix_master_scan(void) {
#ifdef USE_MATRIX_I2C
if( i2c_transaction() ) {
#else // USE_SERIAL
- if( serial_transaction() ) {
+ if( serial_transaction(mchanged) ) {
#endif
// turn on the indicator led when halves are disconnected
TXLED1;
@@ -265,9 +270,19 @@ void matrix_slave_scan(void) {
i2c_slave_buffer[i] = matrix[offset+i];
}
#else // USE_SERIAL
+ #ifdef SERIAL_USE_MULTI_TRANSACTION
+ int change = 0;
+ #endif
for (int i = 0; i < ROWS_PER_HAND; ++i) {
+ #ifdef SERIAL_USE_MULTI_TRANSACTION
+ if( serial_slave_buffer[i] != matrix[offset+i] )
+ change = 1;
+ #endif
serial_slave_buffer[i] = matrix[offset+i];
}
+ #ifdef SERIAL_USE_MULTI_TRANSACTION
+ slave_buffer_change_count += change;
+ #endif
#endif
}
diff --git a/keyboards/helix/rev2/serial_config.h b/keyboards/helix/rev2/serial_config.h
index 9664ba159f99..d19dbea1ecbb 100644
--- a/keyboards/helix/rev2/serial_config.h
+++ b/keyboards/helix/rev2/serial_config.h
@@ -8,8 +8,8 @@
#define SERIAL_PIN_MASK _BV(PD2)
#define SERIAL_PIN_INTERRUPT INT2_vect
-// if you need more program area, use this macro
-// #define SERIAL_USE_SIMPLE_TRANSACTION
+// if you need more program area, comment out this macro
+#define SERIAL_USE_MULTI_TRANSACTION
//// #error rev2 serial config
diff --git a/keyboards/helix/rev2/split_scomm.c b/keyboards/helix/rev2/split_scomm.c
index 1ddd9b8b7d57..ba02a14eac3f 100644
--- a/keyboards/helix/rev2/split_scomm.c
+++ b/keyboards/helix/rev2/split_scomm.c
@@ -8,8 +8,12 @@
uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
uint8_t volatile status0 = 0;
+#ifdef SERIAL_USE_MULTI_TRANSACTION
+uint8_t slave_buffer_change_count = 0;
+uint8_t s_change_old = 0xff;
+#endif
-#ifdef SERIAL_USE_SIMPLE_TRANSACTION
+#ifndef SERIAL_USE_MULTI_TRANSACTION
SSTD_t transactions[] = {
{ (uint8_t *)&status0,
sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer,
@@ -17,10 +21,24 @@ SSTD_t transactions[] = {
}
};
#else
+
SSTD_t transactions[] = {
-#define WHOLE_MATRIX_EXCHANGE 0
+#define GET_SLAVE_STATUS 0
+ /* master buffer not changed, only recive slave_buffer_change_count */
+ { (uint8_t *)&status0,
+ 0, NULL,
+ sizeof(slave_buffer_change_count), &slave_buffer_change_count,
+ },
+#define PUT_MASTER_GET_SLAVE_STATUS 1
+ /* master buffer changed need send, and recive slave_buffer_change_count */
{ (uint8_t *)&status0,
sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer,
+ sizeof(slave_buffer_change_count), &slave_buffer_change_count,
+ },
+#define GET_SLAVE_BUFFER 2
+ /* recive serial_slave_buffer */
+ { (uint8_t *)&status0,
+ 0, NULL,
sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer
}
};
@@ -41,10 +59,22 @@ void serial_slave_init(void)
// 2 => checksum error
int serial_update_buffers(int master_update)
{
-#ifdef SERIAL_USE_SIMPLE_TRANSACTION
- return soft_serial_transaction();
+#ifdef SERIAL_USE_MULTI_TRANSACTION
+ int status;
+ static int need_retry = 0;
+ if( s_change_old != slave_buffer_change_count ) {
+ status = soft_serial_transaction(GET_SLAVE_BUFFER);
+ if( status == TRANSACTION_END )
+ s_change_old = slave_buffer_change_count;
+ }
+ if( !master_update && !need_retry)
+ status = soft_serial_transaction(GET_SLAVE_STATUS);
+ else
+ status = soft_serial_transaction(PUT_MASTER_GET_SLAVE_STATUS);
+ need_retry = ( status == TRANSACTION_END ) ? 0 : 1;
+ return status;
#else
- return soft_serial_transaction(WHOLE_MATRIX_EXCHANGE);
+ return soft_serial_transaction();
#endif
}
#endif /* USE_SERIAL */
diff --git a/keyboards/helix/rev2/split_scomm.h b/keyboards/helix/rev2/split_scomm.h
index 902de0213256..daa680f8d26a 100644
--- a/keyboards/helix/rev2/split_scomm.h
+++ b/keyboards/helix/rev2/split_scomm.h
@@ -7,6 +7,9 @@
extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH];
extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH];
+#ifdef SERIAL_USE_MULTI_TRANSACTION
+extern uint8_t slave_buffer_change_count;
+#endif
void serial_master_init(void);
void serial_slave_init(void);
diff --git a/keyboards/helix/serial.c b/keyboards/helix/serial.c
index 0870ddf10668..09f7c6c0f063 100644
--- a/keyboards/helix/serial.c
+++ b/keyboards/helix/serial.c
@@ -58,7 +58,7 @@
#define SERIAL_DELAY_HALF2 (SERIAL_DELAY - SERIAL_DELAY/2)
#define SLAVE_INT_WIDTH_US 1
-#ifdef SERIAL_USE_SIMPLE_TRANSACTION
+#ifndef SERIAL_USE_MULTI_TRANSACTION
#define SLAVE_INT_RESPONSE_TIME SERIAL_DELAY
#else
#define SLAVE_INT_ACK_WIDTH_UNIT 2
@@ -282,7 +282,7 @@ ISR(SERIAL_PIN_INTERRUPT) {
debug_recvsample(); debug_recvsample(); // indicate intterupt entry
debug_sync_start(); debug_sync_end(); // indicate intterupt entry
-#ifdef SERIAL_USE_SIMPLE_TRANSACTION
+#ifndef SERIAL_USE_MULTI_TRANSACTION
serial_low();
serial_output();
SSTD_t *trans = Transaction_table;
@@ -338,7 +338,7 @@ ISR(SERIAL_PIN_INTERRUPT) {
// TRANSACTION_NO_RESPONSE
// TRANSACTION_DATA_ERROR
// this code is very time dependent, so we need to disable interrupts
-#ifdef SERIAL_USE_SIMPLE_TRANSACTION
+#ifndef SERIAL_USE_MULTI_TRANSACTION
int soft_serial_transaction(void) {
SSTD_t *trans = Transaction_table;
#else
@@ -352,7 +352,7 @@ int soft_serial_transaction(int sstd_index) {
serial_low();
_delay_us(SLAVE_INT_WIDTH_US);
-#ifdef SERIAL_USE_SIMPLE_TRANSACTION
+#ifndef SERIAL_USE_MULTI_TRANSACTION
// wait for the target response
serial_input_with_pullup();
_delay_us(SLAVE_INT_RESPONSE_TIME);
@@ -433,7 +433,7 @@ int soft_serial_transaction(int sstd_index) {
return TRANSACTION_END;
}
-#ifndef SERIAL_USE_SIMPLE_TRANSACTION
+#ifdef SERIAL_USE_MULTI_TRANSACTION
int soft_serial_get_and_clean_status(int sstd_index) {
SSTD_t *trans = &Transaction_table[sstd_index];
cli();
diff --git a/keyboards/helix/serial.h b/keyboards/helix/serial.h
index 8664f12eb98c..67d6472205a3 100644
--- a/keyboards/helix/serial.h
+++ b/keyboards/helix/serial.h
@@ -31,7 +31,7 @@ void soft_serial_target_init(SSTD_t *sstd_table);
#define TRANSACTION_END 0
#define TRANSACTION_NO_RESPONSE 0x1
#define TRANSACTION_DATA_ERROR 0x2
-#ifdef SERIAL_USE_SIMPLE_TRANSACTION
+#ifndef SERIAL_USE_MULTI_TRANSACTION
int soft_serial_transaction(void);
#else
int soft_serial_transaction(int sstd_index);
@@ -47,7 +47,7 @@ int soft_serial_transaction(int sstd_index);
// TRANSACTION_DATA_ERROR
// or TRANSACTION_ACCEPTED
#define TRANSACTION_ACCEPTED 0x4
-#ifndef SERIAL_USE_SIMPLE_TRANSACTION
+#ifdef SERIAL_USE_MULTI_TRANSACTION
int soft_serial_get_and_clean_status(int sstd_index);
#endif
From d6540fd530ae2fbbf03ca856e627b24cd213dadc Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Mon, 23 Jul 2018 15:31:29 +0900
Subject: [PATCH 18/25] add debug code for retry
---
keyboards/helix/rev2/split_scomm.c | 20 ++++++++++++++------
keyboards/helix/serial.h | 10 ++++++++++
2 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/keyboards/helix/rev2/split_scomm.c b/keyboards/helix/rev2/split_scomm.c
index ba02a14eac3f..691ee9d41d29 100644
--- a/keyboards/helix/rev2/split_scomm.c
+++ b/keyboards/helix/rev2/split_scomm.c
@@ -4,10 +4,14 @@
#include
#include
#include "serial.h"
+#ifdef SERIAL_DEBUG_MODE
+#include
+#endif
uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
-uint8_t volatile status0 = 0;
+uint8_t volatile status_com = 0;
+uint8_t volatile status1 = 0;
#ifdef SERIAL_USE_MULTI_TRANSACTION
uint8_t slave_buffer_change_count = 0;
uint8_t s_change_old = 0xff;
@@ -15,7 +19,7 @@ uint8_t s_change_old = 0xff;
#ifndef SERIAL_USE_MULTI_TRANSACTION
SSTD_t transactions[] = {
- { (uint8_t *)&status0,
+ { (uint8_t *)&status_com,
sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer,
sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer
}
@@ -25,19 +29,19 @@ SSTD_t transactions[] = {
SSTD_t transactions[] = {
#define GET_SLAVE_STATUS 0
/* master buffer not changed, only recive slave_buffer_change_count */
- { (uint8_t *)&status0,
+ { (uint8_t *)&status_com,
0, NULL,
sizeof(slave_buffer_change_count), &slave_buffer_change_count,
},
#define PUT_MASTER_GET_SLAVE_STATUS 1
/* master buffer changed need send, and recive slave_buffer_change_count */
- { (uint8_t *)&status0,
+ { (uint8_t *)&status_com,
sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer,
sizeof(slave_buffer_change_count), &slave_buffer_change_count,
},
#define GET_SLAVE_BUFFER 2
/* recive serial_slave_buffer */
- { (uint8_t *)&status0,
+ { (uint8_t *)&status1,
0, NULL,
sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer
}
@@ -72,9 +76,13 @@ 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
- return soft_serial_transaction();
+ int status;
+ status = soft_serial_transaction();
+ if( status != TRANSACTION_END ) debug_retry_on(); else debug_retry_off();
+ return status;
#endif
}
#endif /* USE_SERIAL */
diff --git a/keyboards/helix/serial.h b/keyboards/helix/serial.h
index 67d6472205a3..b1becbfb245b 100644
--- a/keyboards/helix/serial.h
+++ b/keyboards/helix/serial.h
@@ -59,6 +59,7 @@ int soft_serial_get_and_clean_status(int sstd_index);
#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
@@ -69,6 +70,7 @@ int soft_serial_get_and_clean_status(int sstd_index);
//#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
@@ -129,6 +131,14 @@ int soft_serial_get_and_clean_status(int sstd_index);
#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
+#else
+ #define debug_retry_on()
+ #define debug_retry_off()
+#endif
+
#define SYNC_DEBUG_MODE 0
#if SYNC_DEBUG_MODE == 0
#define debug_dummy_delay_recv()
From 55bacb84995dffc54b2b96caaa66ef2ca045373e Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Tue, 24 Jul 2018 01:16:25 +0900
Subject: [PATCH 19/25] add comment into each config.h
---
keyboards/helix/rev2/keymaps/default/config.h | 3 +++
keyboards/helix/rev2/keymaps/edvorakjp/config.h | 3 +++
keyboards/helix/rev2/keymaps/five_rows/config.h | 3 +++
keyboards/helix/rev2/keymaps/five_rows_jis/config.h | 3 +++
keyboards/helix/rev2/keymaps/froggy/config.h | 3 +++
keyboards/helix/rev2/keymaps/led_test/config.h | 3 +++
keyboards/helix/rev2/serial_config.h | 1 -
7 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/keyboards/helix/rev2/keymaps/default/config.h b/keyboards/helix/rev2/keymaps/default/config.h
index 6da6849a1d26..cf9c8e5e3922 100644
--- a/keyboards/helix/rev2/keymaps/default/config.h
+++ b/keyboards/helix/rev2/keymaps/default/config.h
@@ -21,6 +21,9 @@ along with this program. If not, see .
#ifndef CONFIG_USER_H
#define CONFIG_USER_H
+// if you need more program area, try uncomment follow line
+//#undef SERIAL_USE_MULTI_TRANSACTION
+
// place overrides here
#endif /* CONFIG_USER_H */
diff --git a/keyboards/helix/rev2/keymaps/edvorakjp/config.h b/keyboards/helix/rev2/keymaps/edvorakjp/config.h
index a7a5f8360006..51cd1d6417ca 100644
--- a/keyboards/helix/rev2/keymaps/edvorakjp/config.h
+++ b/keyboards/helix/rev2/keymaps/edvorakjp/config.h
@@ -1,6 +1,9 @@
#ifndef CONFIG_USER_H
#define CONFIG_USER_H
+// if you need more program area, try uncomment follow line
+//#undef SERIAL_USE_MULTI_TRANSACTION
+
#undef TAPPING_FORCE_HOLD
#undef TAPPING_TERM
#define TAPPING_TERM 120
diff --git a/keyboards/helix/rev2/keymaps/five_rows/config.h b/keyboards/helix/rev2/keymaps/five_rows/config.h
index 6da6849a1d26..cf9c8e5e3922 100644
--- a/keyboards/helix/rev2/keymaps/five_rows/config.h
+++ b/keyboards/helix/rev2/keymaps/five_rows/config.h
@@ -21,6 +21,9 @@ along with this program. If not, see .
#ifndef CONFIG_USER_H
#define CONFIG_USER_H
+// if you need more program area, try uncomment follow line
+//#undef SERIAL_USE_MULTI_TRANSACTION
+
// place overrides here
#endif /* CONFIG_USER_H */
diff --git a/keyboards/helix/rev2/keymaps/five_rows_jis/config.h b/keyboards/helix/rev2/keymaps/five_rows_jis/config.h
index 34650b99a6a2..8cdfdb4e72f8 100644
--- a/keyboards/helix/rev2/keymaps/five_rows_jis/config.h
+++ b/keyboards/helix/rev2/keymaps/five_rows_jis/config.h
@@ -23,6 +23,9 @@ along with this program. If not, see .
// place overrides here
+// if you need more program area, try uncomment follow line
+//#undef SERIAL_USE_MULTI_TRANSACTION
+
#ifdef MOUSEKEY_ENABLE
#undef MOUSEKEY_INTERVAL
#define MOUSEKEY_INTERVAL 0
diff --git a/keyboards/helix/rev2/keymaps/froggy/config.h b/keyboards/helix/rev2/keymaps/froggy/config.h
index df72aef123fb..a1fea1506732 100644
--- a/keyboards/helix/rev2/keymaps/froggy/config.h
+++ b/keyboards/helix/rev2/keymaps/froggy/config.h
@@ -21,6 +21,9 @@ along with this program. If not, see .
#ifndef CONFIG_USER_H
#define CONFIG_USER_H
+// if you need more program area, try uncomment follow line
+//#undef SERIAL_USE_MULTI_TRANSACTION
+
#undef TAPPING_TERM
#define TAPPING_TERM 200
#define ONESHOT_TAP_TOGGLE 5 /* Tapping this number of times holds the key until tapped this number of times again. */
diff --git a/keyboards/helix/rev2/keymaps/led_test/config.h b/keyboards/helix/rev2/keymaps/led_test/config.h
index 6da6849a1d26..cf9c8e5e3922 100644
--- a/keyboards/helix/rev2/keymaps/led_test/config.h
+++ b/keyboards/helix/rev2/keymaps/led_test/config.h
@@ -21,6 +21,9 @@ along with this program. If not, see .
#ifndef CONFIG_USER_H
#define CONFIG_USER_H
+// if you need more program area, try uncomment follow line
+//#undef SERIAL_USE_MULTI_TRANSACTION
+
// place overrides here
#endif /* CONFIG_USER_H */
diff --git a/keyboards/helix/rev2/serial_config.h b/keyboards/helix/rev2/serial_config.h
index d19dbea1ecbb..8d7e6283783c 100644
--- a/keyboards/helix/rev2/serial_config.h
+++ b/keyboards/helix/rev2/serial_config.h
@@ -8,7 +8,6 @@
#define SERIAL_PIN_MASK _BV(PD2)
#define SERIAL_PIN_INTERRUPT INT2_vect
-// if you need more program area, comment out this macro
#define SERIAL_USE_MULTI_TRANSACTION
//// #error rev2 serial config
From 06d0f8a28243cd92b062ddf761718f1b8721a5ad Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Wed, 25 Jul 2018 01:23:39 +0900
Subject: [PATCH 20/25] fix ISR status drop
---
keyboards/helix/serial.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/keyboards/helix/serial.c b/keyboards/helix/serial.c
index 09f7c6c0f063..aef7051703ec 100644
--- a/keyboards/helix/serial.c
+++ b/keyboards/helix/serial.c
@@ -322,6 +322,8 @@ ISR(SERIAL_PIN_INTERRUPT) {
*trans->status = TRANSACTION_DATA_ERROR;
debug_parity_off();
}
+ } else {
+ *trans->status = TRANSACTION_ACCEPTED;
}
sync_recv(); //weit initiator output to high
From 0ccb3c7c8868fc8ea3ba08d421c8bec06c78657d Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Wed, 25 Jul 2018 01:24:28 +0900
Subject: [PATCH 21/25] add a debug macro 'debug_retry_chg()'
---
keyboards/helix/serial.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/keyboards/helix/serial.h b/keyboards/helix/serial.h
index b1becbfb245b..bf002ee61aeb 100644
--- a/keyboards/helix/serial.h
+++ b/keyboards/helix/serial.h
@@ -134,9 +134,11 @@ int soft_serial_get_and_clean_status(int sstd_index);
#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
From fcb74de2d8eb275ae38e364396851c87d73e4569 Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Wed, 25 Jul 2018 02:57:08 +0900
Subject: [PATCH 22/25] reduce led_test size
---
keyboards/helix/rev2/keymaps/led_test/config.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/keyboards/helix/rev2/keymaps/led_test/config.h b/keyboards/helix/rev2/keymaps/led_test/config.h
index cf9c8e5e3922..56d5f9134514 100644
--- a/keyboards/helix/rev2/keymaps/led_test/config.h
+++ b/keyboards/helix/rev2/keymaps/led_test/config.h
@@ -22,7 +22,7 @@ along with this program. If not, see .
#define CONFIG_USER_H
// if you need more program area, try uncomment follow line
-//#undef SERIAL_USE_MULTI_TRANSACTION
+#undef SERIAL_USE_MULTI_TRANSACTION
// place overrides here
From 9a1b3aded2a5989b9fbe8ab1e0bac9397b201e35 Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Wed, 25 Jul 2018 04:25:57 +0900
Subject: [PATCH 23/25] remove debug code from helix/serial.c and etc.
---
keyboards/helix/rev2/split_scomm.c | 2 -
keyboards/helix/serial.c | 44 ------------
keyboards/helix/serial.h | 107 +----------------------------
3 files changed, 3 insertions(+), 150 deletions(-)
diff --git a/keyboards/helix/rev2/split_scomm.c b/keyboards/helix/rev2/split_scomm.c
index 691ee9d41d29..f37b783d8a79 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 aef7051703ec..b0304512482a 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 bf002ee61aeb..d3cf1743a387 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 */
From 7299d961b67e2706851ab0306b16ce7c1b7ec32c Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Wed, 25 Jul 2018 04:31:27 +0900
Subject: [PATCH 24/25] helix:five_rows change TAPPING_TERM value 140
---
keyboards/helix/rev2/keymaps/five_rows/config.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/keyboards/helix/rev2/keymaps/five_rows/config.h b/keyboards/helix/rev2/keymaps/five_rows/config.h
index cf9c8e5e3922..7e7daf0f64a1 100644
--- a/keyboards/helix/rev2/keymaps/five_rows/config.h
+++ b/keyboards/helix/rev2/keymaps/five_rows/config.h
@@ -24,6 +24,9 @@ along with this program. If not, see .
// if you need more program area, try uncomment follow line
//#undef SERIAL_USE_MULTI_TRANSACTION
+#undef TAPPING_TERM
+#define TAPPING_TERM 140
+
// place overrides here
#endif /* CONFIG_USER_H */
From 8142a3c7403e6a598400ae94360fced6bba14b5a Mon Sep 17 00:00:00 2001
From: mtei <2170248+mtei@users.noreply.github.com>
Date: Fri, 10 Aug 2018 00:17:05 +0900
Subject: [PATCH 25/25] Improved compatibility with let's split of serial.c.
Finish helix/serial.c improvement.
- The difference with the original let's split's serial.c
- It's high-speed about 4 times.
- Stable bi-directional data transfer. (Helix need master to slave transfer)
- serial.h was divided 2 files, serial_config.h and sereial.h
- With multiple types of transaction support, communication contents can be optimized. (NEW flexible API)
- USE OLD Simple APIs (compatible with let's split serial.c)
- files :
- serial_config.h -- hardware configuration (need include by config.h)
- serial.c/serial.h -- serial communication
- USE NEW flexible APIs. (Support multi-type transaction function.)
serial.c was divided into 2 layers, split_scom.c and serial.c.
The upper layer split_scomm.c is called from matrix.c.
The lower layer serial.c accesses the hardware.
- files
- split_scomm.c -- communication buffer is defined in here. call by matrix.c.
- split_scomm.h -- buffer size is defined in here. include by matrix.c, split_util.c
- serial_config.h -- hardware configuration (need include by config.h)
To use the NEW API, specify #define SERIAL_USE_MULTI_TRANSACTION
- serial.c/serial.h -- serial communication lower layer
- NEW APIs for serial.c / serial.h (The lower layer)
// Soft Serial Transaction Descriptor
typedef struct _SSTD_t {
uint8_t *status;
uint8_t initiator2target_buffer_size;
uint8_t *initiator2target_buffer;
uint8_t target2initiator_buffer_size;
uint8_t *target2initiator_buffer;
} SSTD_t;
// initiator is transaction start side
void soft_serial_initiator_init(SSTD_t *sstd_table);
// target is interrupt accept side
void soft_serial_target_init(SSTD_t *sstd_table);
int soft_serial_transaction(int sstd_index);
int soft_serial_get_and_clean_target_status(int sstd_index);
- NEW APIs for split_scomm.c / split_scomm.h (The upper layer)
move from old serial.c the following buffer and functions
serial_slave_buffer[]
serial_master_buffer[]
void serial_master_init(void)
void serial_slave_init(void)
int serial_update_buffers(void)
define SERIAL_xxxxx_BUFFER_LENGTH move from serial_config.h to split_scomm.h
---
.../rev1/keymaps/OLED_sample/serial_config.h | 3 ++
keyboards/helix/rev1/matrix.c | 4 +-
keyboards/helix/rev1/rules.mk | 1 -
keyboards/helix/rev1/serial_config.h | 3 ++
keyboards/helix/rev1/split_scomm.c | 36 -----------------
keyboards/helix/rev1/split_scomm.h | 15 -------
keyboards/helix/rev1/split_util.c | 2 +-
keyboards/helix/rev2/keymaps/default/config.h | 2 +-
.../helix/rev2/keymaps/edvorakjp/config.h | 2 +-
.../helix/rev2/keymaps/five_rows/config.h | 2 +-
.../helix/rev2/keymaps/five_rows_jis/config.h | 2 +-
keyboards/helix/rev2/keymaps/froggy/config.h | 2 +-
.../helix/rev2/keymaps/led_test/config.h | 2 +-
keyboards/helix/rev2/matrix.c | 4 ++
.../helix/rev2/serial_config_simpleapi.h | 8 ++++
keyboards/helix/rev2/split_scomm.c | 23 +++--------
keyboards/helix/rev2/split_scomm.h | 10 ++++-
keyboards/helix/serial.c | 39 +++++++++++++++++++
keyboards/helix/serial.h | 31 +++++++++++++--
19 files changed, 106 insertions(+), 85 deletions(-)
delete mode 100644 keyboards/helix/rev1/split_scomm.c
delete mode 100644 keyboards/helix/rev1/split_scomm.h
create mode 100644 keyboards/helix/rev2/serial_config_simpleapi.h
diff --git a/keyboards/helix/rev1/keymaps/OLED_sample/serial_config.h b/keyboards/helix/rev1/keymaps/OLED_sample/serial_config.h
index 289a165fa3f4..b991b874b73c 100644
--- a/keyboards/helix/rev1/keymaps/OLED_sample/serial_config.h
+++ b/keyboards/helix/rev1/keymaps/OLED_sample/serial_config.h
@@ -8,6 +8,9 @@
#define SERIAL_PIN_MASK _BV(PD2)
#define SERIAL_PIN_INTERRUPT INT2_vect
+#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
+#define SERIAL_MASTER_BUFFER_LENGTH 0
+
//// #error rev1/keymaps/OLED_sample serial config
#endif /* SOFT_SERIAL_CONFIG_H */
diff --git a/keyboards/helix/rev1/matrix.c b/keyboards/helix/rev1/matrix.c
index 6613c02b00e8..f2506868eaf5 100644
--- a/keyboards/helix/rev1/matrix.c
+++ b/keyboards/helix/rev1/matrix.c
@@ -35,7 +35,7 @@ along with this program. If not, see .
#ifdef USE_MATRIX_I2C
# include "i2c.h"
#else // USE_SERIAL
-# include "split_scomm.h"
+# include "serial.h"
#endif
#ifndef DEBOUNCE
@@ -178,7 +178,7 @@ int i2c_transaction(void) {
int serial_transaction(void) {
int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
- if (serial_update_buffers(1)) {
+ if (serial_update_buffers()) {
return 1;
}
diff --git a/keyboards/helix/rev1/rules.mk b/keyboards/helix/rev1/rules.mk
index 5ecfa33a2ab8..13834f5da10e 100644
--- a/keyboards/helix/rev1/rules.mk
+++ b/keyboards/helix/rev1/rules.mk
@@ -1,5 +1,4 @@
SRC += rev1/matrix.c
SRC += rev1/split_util.c
-SRC += rev1/split_scomm.c
BACKLIGHT_ENABLE = no
diff --git a/keyboards/helix/rev1/serial_config.h b/keyboards/helix/rev1/serial_config.h
index f021d6e04b65..51c6aa3750ad 100644
--- a/keyboards/helix/rev1/serial_config.h
+++ b/keyboards/helix/rev1/serial_config.h
@@ -8,6 +8,9 @@
#define SERIAL_PIN_MASK _BV(PD0)
#define SERIAL_PIN_INTERRUPT INT0_vect
+#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
+#define SERIAL_MASTER_BUFFER_LENGTH 0
+
/// #error rev1 serial config
#endif /* SOFT_SERIAL_CONFIG_H */
diff --git a/keyboards/helix/rev1/split_scomm.c b/keyboards/helix/rev1/split_scomm.c
deleted file mode 100644
index a5c0485e3072..000000000000
--- a/keyboards/helix/rev1/split_scomm.c
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifdef USE_SERIAL
-#include
-#include
-#include
-#include
-#include "serial.h"
-
-uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
-uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
-uint8_t volatile status0 = 0;
-
-SSTD_t transactions[] = {
- { (uint8_t *)&status0,
- sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer,
- sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer
- }
-};
-
-void serial_master_init(void)
-{
- soft_serial_initiator_init(transactions);
-}
-
-void serial_slave_init(void)
-{
- soft_serial_target_init(transactions);
-}
-
-// 0 => no error
-// 1 => slave did not respond
-// 2 => checksum error
-int serial_update_buffers(int master_update)
-{
- return soft_serial_transaction();
-}
-#endif /* USE_SERIAL */
diff --git a/keyboards/helix/rev1/split_scomm.h b/keyboards/helix/rev1/split_scomm.h
deleted file mode 100644
index c81eff4ffe7b..000000000000
--- a/keyboards/helix/rev1/split_scomm.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef SPLIT_COMM_H
-#define SPLIT_COMM_H
-
-// Buffers for master - slave communication
-#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
-#define SERIAL_MASTER_BUFFER_LENGTH 1
-
-extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH];
-extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH];
-
-void serial_master_init(void);
-void serial_slave_init(void);
-int serial_update_buffers(int master_changed);
-
-#endif /* SPLIT_COMM_H */
diff --git a/keyboards/helix/rev1/split_util.c b/keyboards/helix/rev1/split_util.c
index fe17e14f844b..5debd6e00bd2 100644
--- a/keyboards/helix/rev1/split_util.c
+++ b/keyboards/helix/rev1/split_util.c
@@ -12,7 +12,7 @@
#ifdef USE_MATRIX_I2C
# include "i2c.h"
#else
-# include "split_scomm.h"
+# include "serial.h"
#endif
volatile bool isLeftHand = true;
diff --git a/keyboards/helix/rev2/keymaps/default/config.h b/keyboards/helix/rev2/keymaps/default/config.h
index cf9c8e5e3922..185e6783856e 100644
--- a/keyboards/helix/rev2/keymaps/default/config.h
+++ b/keyboards/helix/rev2/keymaps/default/config.h
@@ -22,7 +22,7 @@ along with this program. If not, see .
#define CONFIG_USER_H
// if you need more program area, try uncomment follow line
-//#undef SERIAL_USE_MULTI_TRANSACTION
+//#include "serial_config_simpleapi.h"
// place overrides here
diff --git a/keyboards/helix/rev2/keymaps/edvorakjp/config.h b/keyboards/helix/rev2/keymaps/edvorakjp/config.h
index 51cd1d6417ca..ead31605b248 100644
--- a/keyboards/helix/rev2/keymaps/edvorakjp/config.h
+++ b/keyboards/helix/rev2/keymaps/edvorakjp/config.h
@@ -2,7 +2,7 @@
#define CONFIG_USER_H
// if you need more program area, try uncomment follow line
-//#undef SERIAL_USE_MULTI_TRANSACTION
+//#include "serial_config_simpleapi.h"
#undef TAPPING_FORCE_HOLD
#undef TAPPING_TERM
diff --git a/keyboards/helix/rev2/keymaps/five_rows/config.h b/keyboards/helix/rev2/keymaps/five_rows/config.h
index 7e7daf0f64a1..8372194604b4 100644
--- a/keyboards/helix/rev2/keymaps/five_rows/config.h
+++ b/keyboards/helix/rev2/keymaps/five_rows/config.h
@@ -22,7 +22,7 @@ along with this program. If not, see .
#define CONFIG_USER_H
// if you need more program area, try uncomment follow line
-//#undef SERIAL_USE_MULTI_TRANSACTION
+//#include "serial_config_simpleapi.h"
#undef TAPPING_TERM
#define TAPPING_TERM 140
diff --git a/keyboards/helix/rev2/keymaps/five_rows_jis/config.h b/keyboards/helix/rev2/keymaps/five_rows_jis/config.h
index 8cdfdb4e72f8..c380b7db4e26 100644
--- a/keyboards/helix/rev2/keymaps/five_rows_jis/config.h
+++ b/keyboards/helix/rev2/keymaps/five_rows_jis/config.h
@@ -24,7 +24,7 @@ along with this program. If not, see .
// place overrides here
// if you need more program area, try uncomment follow line
-//#undef SERIAL_USE_MULTI_TRANSACTION
+//#include "serial_config_simpleapi.h"
#ifdef MOUSEKEY_ENABLE
#undef MOUSEKEY_INTERVAL
diff --git a/keyboards/helix/rev2/keymaps/froggy/config.h b/keyboards/helix/rev2/keymaps/froggy/config.h
index a1fea1506732..dad248303471 100644
--- a/keyboards/helix/rev2/keymaps/froggy/config.h
+++ b/keyboards/helix/rev2/keymaps/froggy/config.h
@@ -22,7 +22,7 @@ along with this program. If not, see .
#define CONFIG_USER_H
// if you need more program area, try uncomment follow line
-//#undef SERIAL_USE_MULTI_TRANSACTION
+//#include "serial_config_simpleapi.h"
#undef TAPPING_TERM
#define TAPPING_TERM 200
diff --git a/keyboards/helix/rev2/keymaps/led_test/config.h b/keyboards/helix/rev2/keymaps/led_test/config.h
index 56d5f9134514..0438254528c8 100644
--- a/keyboards/helix/rev2/keymaps/led_test/config.h
+++ b/keyboards/helix/rev2/keymaps/led_test/config.h
@@ -22,7 +22,7 @@ along with this program. If not, see .
#define CONFIG_USER_H
// if you need more program area, try uncomment follow line
-#undef SERIAL_USE_MULTI_TRANSACTION
+#include "serial_config_simpleapi.h"
// place overrides here
diff --git a/keyboards/helix/rev2/matrix.c b/keyboards/helix/rev2/matrix.c
index fd64c37ab138..322959dbbb1a 100644
--- a/keyboards/helix/rev2/matrix.c
+++ b/keyboards/helix/rev2/matrix.c
@@ -183,7 +183,11 @@ int i2c_transaction(void) {
int serial_transaction(int master_changed) {
int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
+#ifdef SERIAL_USE_MULTI_TRANSACTION
int ret=serial_update_buffers(master_changed);
+#else
+ int ret=serial_update_buffers();
+#endif
if (ret ) {
if(ret==2) RXLED1;
return 1;
diff --git a/keyboards/helix/rev2/serial_config_simpleapi.h b/keyboards/helix/rev2/serial_config_simpleapi.h
new file mode 100644
index 000000000000..e2d22a41e7bc
--- /dev/null
+++ b/keyboards/helix/rev2/serial_config_simpleapi.h
@@ -0,0 +1,8 @@
+#ifndef SERIAL_CONFIG_SIMPLEAPI_H
+#define SERIAL_CONFIG_SIMPLEAPI_H
+
+#undef SERIAL_USE_MULTI_TRANSACTION
+#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
+#define SERIAL_MASTER_BUFFER_LENGTH MATRIX_ROWS/2
+
+#endif // SERIAL_CONFIG_SIMPLEAPI_H
diff --git a/keyboards/helix/rev2/split_scomm.c b/keyboards/helix/rev2/split_scomm.c
index f37b783d8a79..9719eb22ea19 100644
--- a/keyboards/helix/rev2/split_scomm.c
+++ b/keyboards/helix/rev2/split_scomm.c
@@ -1,4 +1,7 @@
#ifdef USE_SERIAL
+#ifdef SERIAL_USE_MULTI_TRANSACTION
+/* --- USE flexible API (using multi-type transaction function) --- */
+
#include
#include
#include
@@ -12,19 +15,8 @@ uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
uint8_t volatile status_com = 0;
uint8_t volatile status1 = 0;
-#ifdef SERIAL_USE_MULTI_TRANSACTION
uint8_t slave_buffer_change_count = 0;
uint8_t s_change_old = 0xff;
-#endif
-
-#ifndef SERIAL_USE_MULTI_TRANSACTION
-SSTD_t transactions[] = {
- { (uint8_t *)&status_com,
- sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer,
- sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer
- }
-};
-#else
SSTD_t transactions[] = {
#define GET_SLAVE_STATUS 0
@@ -46,7 +38,6 @@ SSTD_t transactions[] = {
sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer
}
};
-#endif
void serial_master_init(void)
{
@@ -63,7 +54,6 @@ void serial_slave_init(void)
// 2 => checksum error
int serial_update_buffers(int master_update)
{
-#ifdef SERIAL_USE_MULTI_TRANSACTION
int status;
static int need_retry = 0;
if( s_change_old != slave_buffer_change_count ) {
@@ -77,10 +67,7 @@ int serial_update_buffers(int master_update)
status = soft_serial_transaction(PUT_MASTER_GET_SLAVE_STATUS);
need_retry = ( status == TRANSACTION_END ) ? 0 : 1;
return status;
-#else
- int status;
- status = soft_serial_transaction();
- return status;
-#endif
}
+
+#endif // SERIAL_USE_MULTI_TRANSACTION
#endif /* USE_SERIAL */
diff --git a/keyboards/helix/rev2/split_scomm.h b/keyboards/helix/rev2/split_scomm.h
index daa680f8d26a..873d8939d81f 100644
--- a/keyboards/helix/rev2/split_scomm.h
+++ b/keyboards/helix/rev2/split_scomm.h
@@ -1,18 +1,24 @@
#ifndef SPLIT_COMM_H
#define SPLIT_COMM_H
+#ifndef SERIAL_USE_MULTI_TRANSACTION
+/* --- USE Simple API (OLD API, compatible with let's split serial.c) --- */
+#include "serial.h"
+
+#else
+/* --- USE flexible API (using multi-type transaction function) --- */
// Buffers for master - slave communication
#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
#define SERIAL_MASTER_BUFFER_LENGTH MATRIX_ROWS/2
extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH];
extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH];
-#ifdef SERIAL_USE_MULTI_TRANSACTION
extern uint8_t slave_buffer_change_count;
-#endif
void serial_master_init(void);
void serial_slave_init(void);
int serial_update_buffers(int master_changed);
+#endif
+
#endif /* SPLIT_COMM_H */
diff --git a/keyboards/helix/serial.c b/keyboards/helix/serial.c
index b0304512482a..11ceff0b37cd 100644
--- a/keyboards/helix/serial.c
+++ b/keyboards/helix/serial.c
@@ -16,6 +16,45 @@
#ifdef USE_SERIAL
+#ifndef SERIAL_USE_MULTI_TRANSACTION
+/* --- USE Simple API (OLD API, compatible with let's split serial.c) */
+ #if SERIAL_SLAVE_BUFFER_LENGTH > 0
+ uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
+ #endif
+ #if SERIAL_MASTER_BUFFER_LENGTH > 0
+ uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
+ #endif
+ uint8_t volatile status0 = 0;
+
+SSTD_t transactions[] = {
+ { (uint8_t *)&status0,
+ #if SERIAL_MASTER_BUFFER_LENGTH > 0
+ sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer,
+ #else
+ 0, (uint8_t *)NULL,
+ #endif
+ #if SERIAL_SLAVE_BUFFER_LENGTH > 0
+ sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer
+ #else
+ 0, (uint8_t *)NULL,
+ #endif
+ }
+};
+
+void serial_master_init(void)
+{ soft_serial_initiator_init(transactions); }
+
+void serial_slave_init(void)
+{ soft_serial_target_init(transactions); }
+
+// 0 => no error
+// 1 => slave did not respond
+// 2 => checksum error
+int serial_update_buffers()
+{ return soft_serial_transaction(); }
+
+#endif // Simple API (OLD API, compatible with let's split serial.c)
+
#define ALWAYS_INLINE __attribute__((always_inline))
#define NO_INLINE __attribute__((noinline))
#define _delay_sub_us(x) __builtin_avr_delay_cycles(x)
diff --git a/keyboards/helix/serial.h b/keyboards/helix/serial.h
index d3cf1743a387..d2b7fd8e60be 100644
--- a/keyboards/helix/serial.h
+++ b/keyboards/helix/serial.h
@@ -3,9 +3,9 @@
#include
-// ////////////////////////////////////////////
+// /////////////////////////////////////////////////////////////////
// Need Soft Serial defines in serial_config.h
-// ////////////////////////////////////////////
+// /////////////////////////////////////////////////////////////////
// ex.
// #define SERIAL_PIN_DDR DDRD
// #define SERIAL_PIN_PORT PORTD
@@ -13,8 +13,31 @@
// #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
+// //// USE Simple API (OLD API, compatible with let's split serial.c)
+// ex.
+// #define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
+// #define SERIAL_MASTER_BUFFER_LENGTH 1
+//
+// //// USE flexible API (using multi-type transaction function)
+// #define SERIAL_USE_MULTI_TRANSACTION
+//
+// /////////////////////////////////////////////////////////////////
+
+
+#ifndef SERIAL_USE_MULTI_TRANSACTION
+/* --- USE Simple API (OLD API, compatible with let's split serial.c) */
+#if SERIAL_SLAVE_BUFFER_LENGTH > 0
+extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH];
+#endif
+#if SERIAL_MASTER_BUFFER_LENGTH > 0
+extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH];
+#endif
+
+void serial_master_init(void);
+void serial_slave_init(void);
+int serial_update_buffers(void);
+
+#endif // USE Simple API
// Soft Serial Transaction Descriptor
typedef struct _SSTD_t {