diff options
Diffstat (limited to 'keyboards/zinc/rev1/split_scomm.c')
| -rw-r--r-- | keyboards/zinc/rev1/split_scomm.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/keyboards/zinc/rev1/split_scomm.c b/keyboards/zinc/rev1/split_scomm.c new file mode 100644 index 000000000..50d233ce9 --- /dev/null +++ b/keyboards/zinc/rev1/split_scomm.c | |||
| @@ -0,0 +1,95 @@ | |||
| 1 | #ifdef USE_SERIAL | ||
| 2 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 3 | /* --- USE flexible API (using multi-type transaction function) --- */ | ||
| 4 | |||
| 5 | #include <stdbool.h> | ||
| 6 | #include <stdint.h> | ||
| 7 | #include <stddef.h> | ||
| 8 | #include <split_scomm.h> | ||
| 9 | #include "serial.h" | ||
| 10 | #ifdef SERIAL_DEBUG_MODE | ||
| 11 | #include <avr/io.h> | ||
| 12 | #endif | ||
| 13 | #ifdef CONSOLE_ENABLE | ||
| 14 | #include <print.h> | ||
| 15 | #endif | ||
| 16 | |||
| 17 | uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0}; | ||
| 18 | uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0}; | ||
| 19 | uint8_t volatile status_com = 0; | ||
| 20 | uint8_t volatile status1 = 0; | ||
| 21 | uint8_t slave_buffer_change_count = 0; | ||
| 22 | uint8_t s_change_old = 0xff; | ||
| 23 | uint8_t s_change_new = 0xff; | ||
| 24 | |||
| 25 | SSTD_t transactions[] = { | ||
| 26 | #define GET_SLAVE_STATUS 0 | ||
| 27 | /* master buffer not changed, only recive slave_buffer_change_count */ | ||
| 28 | { (uint8_t *)&status_com, | ||
| 29 | 0, NULL, | ||
| 30 | sizeof(slave_buffer_change_count), &slave_buffer_change_count, | ||
| 31 | }, | ||
| 32 | #define PUT_MASTER_GET_SLAVE_STATUS 1 | ||
| 33 | /* master buffer changed need send, and recive slave_buffer_change_count */ | ||
| 34 | { (uint8_t *)&status_com, | ||
| 35 | sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer, | ||
| 36 | sizeof(slave_buffer_change_count), &slave_buffer_change_count, | ||
| 37 | }, | ||
| 38 | #define GET_SLAVE_BUFFER 2 | ||
| 39 | /* recive serial_slave_buffer */ | ||
| 40 | { (uint8_t *)&status1, | ||
| 41 | 0, NULL, | ||
| 42 | sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer | ||
| 43 | } | ||
| 44 | }; | ||
| 45 | |||
| 46 | void serial_master_init(void) | ||
| 47 | { | ||
| 48 | soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); | ||
| 49 | } | ||
| 50 | |||
| 51 | void serial_slave_init(void) | ||
| 52 | { | ||
| 53 | soft_serial_target_init(transactions, TID_LIMIT(transactions)); | ||
| 54 | } | ||
| 55 | |||
| 56 | // 0 => no error | ||
| 57 | // 1 => slave did not respond | ||
| 58 | // 2 => checksum error | ||
| 59 | int serial_update_buffers(int master_update) | ||
| 60 | { | ||
| 61 | int status, smatstatus; | ||
| 62 | static int need_retry = 0; | ||
| 63 | |||
| 64 | if( s_change_old != s_change_new ) { | ||
| 65 | smatstatus = soft_serial_transaction(GET_SLAVE_BUFFER); | ||
| 66 | if( smatstatus == TRANSACTION_END ) { | ||
| 67 | s_change_old = s_change_new; | ||
| 68 | #ifdef CONSOLE_ENABLE | ||
| 69 | uprintf("slave matrix = %b %b %b %b %b\n", | ||
| 70 | serial_slave_buffer[0], serial_slave_buffer[1], | ||
| 71 | serial_slave_buffer[2], serial_slave_buffer[3], | ||
| 72 | serial_slave_buffer[4] ); | ||
| 73 | #endif | ||
| 74 | } | ||
| 75 | } else { | ||
| 76 | // serial_slave_buffer dosen't change | ||
| 77 | smatstatus = TRANSACTION_END; // dummy status | ||
| 78 | } | ||
| 79 | |||
| 80 | if( !master_update && !need_retry) { | ||
| 81 | status = soft_serial_transaction(GET_SLAVE_STATUS); | ||
| 82 | } else { | ||
| 83 | status = soft_serial_transaction(PUT_MASTER_GET_SLAVE_STATUS); | ||
| 84 | } | ||
| 85 | if( status == TRANSACTION_END ) { | ||
| 86 | s_change_new = slave_buffer_change_count; | ||
| 87 | need_retry = 0; | ||
| 88 | } else { | ||
| 89 | need_retry = 1; | ||
| 90 | } | ||
| 91 | return smatstatus; | ||
| 92 | } | ||
| 93 | |||
| 94 | #endif // SERIAL_USE_MULTI_TRANSACTION | ||
| 95 | #endif /* USE_SERIAL */ | ||
