aboutsummaryrefslogtreecommitdiff
path: root/keyboards/naked60/rev1/split_scomm.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/naked60/rev1/split_scomm.c')
-rw-r--r--keyboards/naked60/rev1/split_scomm.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/keyboards/naked60/rev1/split_scomm.c b/keyboards/naked60/rev1/split_scomm.c
new file mode 100644
index 000000000..ada786796
--- /dev/null
+++ b/keyboards/naked60/rev1/split_scomm.c
@@ -0,0 +1,92 @@
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 CONSOLE_ENABLE
11 #include <print.h>
12#endif
13
14uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
15uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
16uint8_t volatile status_com = 0;
17uint8_t volatile status1 = 0;
18uint8_t slave_buffer_change_count = 0;
19uint8_t s_change_old = 0xff;
20uint8_t s_change_new = 0xff;
21
22SSTD_t transactions[] = {
23#define GET_SLAVE_STATUS 0
24 /* master buffer not changed, only recive slave_buffer_change_count */
25 { (uint8_t *)&status_com,
26 0, NULL,
27 sizeof(slave_buffer_change_count), &slave_buffer_change_count,
28 },
29#define PUT_MASTER_GET_SLAVE_STATUS 1
30 /* master buffer changed need send, and recive slave_buffer_change_count */
31 { (uint8_t *)&status_com,
32 sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer,
33 sizeof(slave_buffer_change_count), &slave_buffer_change_count,
34 },
35#define GET_SLAVE_BUFFER 2
36 /* recive serial_slave_buffer */
37 { (uint8_t *)&status1,
38 0, NULL,
39 sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer
40 }
41};
42
43void serial_master_init(void)
44{
45 soft_serial_initiator_init(transactions, TID_LIMIT(transactions));
46}
47
48void serial_slave_init(void)
49{
50 soft_serial_target_init(transactions, TID_LIMIT(transactions));
51}
52
53// 0 => no error
54// 1 => slave did not respond
55// 2 => checksum error
56int serial_update_buffers(int master_update)
57{
58 int status, smatstatus;
59 static int need_retry = 0;
60
61 if( s_change_old != s_change_new ) {
62 smatstatus = soft_serial_transaction(GET_SLAVE_BUFFER);
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;
87 }
88 return smatstatus;
89}
90
91#endif // SERIAL_USE_MULTI_TRANSACTION
92#endif /* USE_SERIAL */