diff options
| author | Kosuke Adachi <ks@fstn.jp> | 2018-11-05 03:46:26 +0900 |
|---|---|---|
| committer | Drashna Jaelre <drashna@live.com> | 2018-11-04 10:46:26 -0800 |
| commit | 756d92c1a071b6c481b67a44671308fc9d680afe (patch) | |
| tree | da31f7ef36eb2566ab6eca7af2932cd4377f70ed /keyboards/crkbd/rev1 | |
| parent | e9fd42df71ebc367fccbbf918a1794498aa57914 (diff) | |
| download | qmk_firmware-756d92c1a071b6c481b67a44671308fc9d680afe.tar.gz qmk_firmware-756d92c1a071b6c481b67a44671308fc9d680afe.zip | |
Keyboard: Update the serial.c of crkbd based on the helix-serial.c (#4349)
Diffstat (limited to 'keyboards/crkbd/rev1')
| -rw-r--r-- | keyboards/crkbd/rev1/serial_config.h | 12 | ||||
| -rw-r--r-- | keyboards/crkbd/rev1/split_scomm.c | 49 | ||||
| -rw-r--r-- | keyboards/crkbd/rev1/split_scomm.h | 5 | ||||
| -rw-r--r-- | keyboards/crkbd/rev1/split_util.h | 5 |
4 files changed, 45 insertions, 26 deletions
diff --git a/keyboards/crkbd/rev1/serial_config.h b/keyboards/crkbd/rev1/serial_config.h index 671ed821d..4fab8e8dd 100644 --- a/keyboards/crkbd/rev1/serial_config.h +++ b/keyboards/crkbd/rev1/serial_config.h | |||
| @@ -1,10 +1,4 @@ | |||
| 1 | #pragma once | 1 | #ifndef SOFT_SERIAL_PIN |
| 2 | 2 | #define SOFT_SERIAL_PIN D2 | |
| 3 | /* Soft Serial defines */ | ||
| 4 | #define SERIAL_PIN_DDR DDRD | ||
| 5 | #define SERIAL_PIN_PORT PORTD | ||
| 6 | #define SERIAL_PIN_INPUT PIND | ||
| 7 | #define SERIAL_PIN_MASK _BV(PD2) | ||
| 8 | #define SERIAL_PIN_INTERRUPT INT2_vect | ||
| 9 | |||
| 10 | #define SERIAL_USE_MULTI_TRANSACTION | 3 | #define SERIAL_USE_MULTI_TRANSACTION |
| 4 | #endif | ||
diff --git a/keyboards/crkbd/rev1/split_scomm.c b/keyboards/crkbd/rev1/split_scomm.c index 9719eb22e..ada786796 100644 --- a/keyboards/crkbd/rev1/split_scomm.c +++ b/keyboards/crkbd/rev1/split_scomm.c | |||
| @@ -7,8 +7,8 @@ | |||
| 7 | #include <stddef.h> | 7 | #include <stddef.h> |
| 8 | #include <split_scomm.h> | 8 | #include <split_scomm.h> |
| 9 | #include "serial.h" | 9 | #include "serial.h" |
| 10 | #ifdef SERIAL_DEBUG_MODE | 10 | #ifdef CONSOLE_ENABLE |
| 11 | #include <avr/io.h> | 11 | #include <print.h> |
| 12 | #endif | 12 | #endif |
| 13 | 13 | ||
| 14 | uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0}; | 14 | uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0}; |
| @@ -17,6 +17,7 @@ uint8_t volatile status_com = 0; | |||
| 17 | uint8_t volatile status1 = 0; | 17 | uint8_t volatile status1 = 0; |
| 18 | uint8_t slave_buffer_change_count = 0; | 18 | uint8_t slave_buffer_change_count = 0; |
| 19 | uint8_t s_change_old = 0xff; | 19 | uint8_t s_change_old = 0xff; |
| 20 | uint8_t s_change_new = 0xff; | ||
| 20 | 21 | ||
| 21 | SSTD_t transactions[] = { | 22 | SSTD_t transactions[] = { |
| 22 | #define GET_SLAVE_STATUS 0 | 23 | #define GET_SLAVE_STATUS 0 |
| @@ -41,12 +42,12 @@ SSTD_t transactions[] = { | |||
| 41 | 42 | ||
| 42 | void serial_master_init(void) | 43 | void serial_master_init(void) |
| 43 | { | 44 | { |
| 44 | soft_serial_initiator_init(transactions); | 45 | soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); |
| 45 | } | 46 | } |
| 46 | 47 | ||
| 47 | void serial_slave_init(void) | 48 | void serial_slave_init(void) |
| 48 | { | 49 | { |
| 49 | soft_serial_target_init(transactions); | 50 | soft_serial_target_init(transactions, TID_LIMIT(transactions)); |
| 50 | } | 51 | } |
| 51 | 52 | ||
| 52 | // 0 => no error | 53 | // 0 => no error |
| @@ -54,19 +55,37 @@ void serial_slave_init(void) | |||
| 54 | // 2 => checksum error | 55 | // 2 => checksum error |
| 55 | int serial_update_buffers(int master_update) | 56 | int serial_update_buffers(int master_update) |
| 56 | { | 57 | { |
| 57 | int status; | 58 | int status, smatstatus; |
| 58 | static int need_retry = 0; | 59 | static int need_retry = 0; |
| 59 | if( s_change_old != slave_buffer_change_count ) { | 60 | |
| 60 | status = soft_serial_transaction(GET_SLAVE_BUFFER); | 61 | if( s_change_old != s_change_new ) { |
| 61 | if( status == TRANSACTION_END ) | 62 | smatstatus = soft_serial_transaction(GET_SLAVE_BUFFER); |
| 62 | s_change_old = slave_buffer_change_count; | 63 | if( smatstatus == TRANSACTION_END ) { |
| 64 | s_change_old = s_change_new; | ||
| 65 | #ifdef CONSOLE_ENABLE | ||
| 66 | uprintf("slave matrix = %b %b %b %b %b\n", | ||
| 67 | serial_slave_buffer[0], serial_slave_buffer[1], | ||
| 68 | serial_slave_buffer[2], serial_slave_buffer[3], | ||
| 69 | serial_slave_buffer[4] ); | ||
| 70 | #endif | ||
| 71 | } | ||
| 72 | } else { | ||
| 73 | // serial_slave_buffer dosen't change | ||
| 74 | smatstatus = TRANSACTION_END; // dummy status | ||
| 75 | } | ||
| 76 | |||
| 77 | if( !master_update && !need_retry) { | ||
| 78 | status = soft_serial_transaction(GET_SLAVE_STATUS); | ||
| 79 | } else { | ||
| 80 | status = soft_serial_transaction(PUT_MASTER_GET_SLAVE_STATUS); | ||
| 81 | } | ||
| 82 | if( status == TRANSACTION_END ) { | ||
| 83 | s_change_new = slave_buffer_change_count; | ||
| 84 | need_retry = 0; | ||
| 85 | } else { | ||
| 86 | need_retry = 1; | ||
| 63 | } | 87 | } |
| 64 | if( !master_update && !need_retry) | 88 | return smatstatus; |
| 65 | status = soft_serial_transaction(GET_SLAVE_STATUS); | ||
| 66 | else | ||
| 67 | status = soft_serial_transaction(PUT_MASTER_GET_SLAVE_STATUS); | ||
| 68 | need_retry = ( status == TRANSACTION_END ) ? 0 : 1; | ||
| 69 | return status; | ||
| 70 | } | 89 | } |
| 71 | 90 | ||
| 72 | #endif // SERIAL_USE_MULTI_TRANSACTION | 91 | #endif // SERIAL_USE_MULTI_TRANSACTION |
diff --git a/keyboards/crkbd/rev1/split_scomm.h b/keyboards/crkbd/rev1/split_scomm.h index 16887eb74..873d8939d 100644 --- a/keyboards/crkbd/rev1/split_scomm.h +++ b/keyboards/crkbd/rev1/split_scomm.h | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | #pragma once | 1 | #ifndef SPLIT_COMM_H |
| 2 | #define SPLIT_COMM_H | ||
| 2 | 3 | ||
| 3 | #ifndef SERIAL_USE_MULTI_TRANSACTION | 4 | #ifndef SERIAL_USE_MULTI_TRANSACTION |
| 4 | /* --- USE Simple API (OLD API, compatible with let's split serial.c) --- */ | 5 | /* --- USE Simple API (OLD API, compatible with let's split serial.c) --- */ |
| @@ -19,3 +20,5 @@ void serial_slave_init(void); | |||
| 19 | int serial_update_buffers(int master_changed); | 20 | int serial_update_buffers(int master_changed); |
| 20 | 21 | ||
| 21 | #endif | 22 | #endif |
| 23 | |||
| 24 | #endif /* SPLIT_COMM_H */ | ||
diff --git a/keyboards/crkbd/rev1/split_util.h b/keyboards/crkbd/rev1/split_util.h index f59304756..687ca19bd 100644 --- a/keyboards/crkbd/rev1/split_util.h +++ b/keyboards/crkbd/rev1/split_util.h | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | #pragma once | 1 | #ifndef SPLIT_KEYBOARD_UTIL_H |
| 2 | #define SPLIT_KEYBOARD_UTIL_H | ||
| 2 | 3 | ||
| 3 | #include <stdbool.h> | 4 | #include <stdbool.h> |
| 4 | #include "eeconfig.h" | 5 | #include "eeconfig.h" |
| @@ -14,3 +15,5 @@ void split_keyboard_setup(void); | |||
| 14 | bool has_usb(void); | 15 | bool has_usb(void); |
| 15 | 16 | ||
| 16 | void matrix_master_OLED_init (void); | 17 | void matrix_master_OLED_init (void); |
| 18 | |||
| 19 | #endif | ||
