aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2016-02-28 21:46:29 +0200
committerFred Sundvik <fsundvik@gmail.com>2016-02-28 21:46:29 +0200
commitd8d4622802c1a50779830eade0f79a0680def34a (patch)
treefff844df024008f25e29504d60e62d2e42947242
parent46482460fa5ba7e1606656f651117cc30f643952 (diff)
downloadqmk_firmware-d8d4622802c1a50779830eade0f79a0680def34a.tar.gz
qmk_firmware-d8d4622802c1a50779830eade0f79a0680def34a.zip
Improve serial link initialization, and add driver
-rw-r--r--serial_link.mk4
-rw-r--r--serial_link/system/driver.h36
-rw-r--r--serial_link/system/system.c90
-rw-r--r--serial_link/system/system.h1
4 files changed, 129 insertions, 2 deletions
diff --git a/serial_link.mk b/serial_link.mk
index f0cd60b04..e164cc5ff 100644
--- a/serial_link.mk
+++ b/serial_link.mk
@@ -22,4 +22,6 @@
22 22
23UINCDIR += $(SERIAL_DIR) 23UINCDIR += $(SERIAL_DIR)
24SRC += $(wildcard $(SERIAL_DIR)/serial_link/protocol/*.c) 24SRC += $(wildcard $(SERIAL_DIR)/serial_link/protocol/*.c)
25SRC += $(wildcard $(SERIAL_DIR)/serial_link/system/*.c) \ No newline at end of file 25SRC += $(wildcard $(SERIAL_DIR)/serial_link/system/*.c)
26SRC += serial_link_hal.c
27OPT_DEFS += -DUSE_SERIAL_LINK
diff --git a/serial_link/system/driver.h b/serial_link/system/driver.h
new file mode 100644
index 000000000..76e2d682c
--- /dev/null
+++ b/serial_link/system/driver.h
@@ -0,0 +1,36 @@
1/*
2The MIT License (MIT)
3
4Copyright (c) 2016 Fred Sundvik
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23*/
24
25#ifndef SERIAL_LINK_DRIVER_H
26#define SERIAL_LINK_DRIVER_H
27
28#include "host_driver.h"
29
30void init_serial_link(void);
31void init_serial_link_hal(void);
32bool is_serial_link_connected(void);
33host_driver_t* get_serial_link_driver(void);
34void serial_link_update(void);
35
36#endif
diff --git a/serial_link/system/system.c b/serial_link/system/system.c
index e40a18cec..c38bcd87d 100644
--- a/serial_link/system/system.c
+++ b/serial_link/system/system.c
@@ -21,14 +21,33 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE. 22SOFTWARE.
23*/ 23*/
24#include "report.h"
25#include "host_driver.h"
24#include "serial_link/system/system.h" 26#include "serial_link/system/system.h"
27#include "serial_link/system/driver.h"
25#include "hal.h" 28#include "hal.h"
26#include "serial_link/protocol/byte_stuffer.h" 29#include "serial_link/protocol/byte_stuffer.h"
27#include "serial_link/protocol/transport.h" 30#include "serial_link/protocol/transport.h"
28#include "serial_link/protocol/frame_router.h" 31#include "serial_link/protocol/frame_router.h"
29#include <stdbool.h> 32#include <stdbool.h>
33#include "print.h"
30 34
31static event_source_t new_data_event; 35static event_source_t new_data_event;
36static bool serial_link_connected;
37
38static uint8_t keyboard_leds(void);
39static void send_keyboard(report_keyboard_t *report);
40static void send_mouse(report_mouse_t *report);
41static void send_system(uint16_t data);
42static void send_consumer(uint16_t data);
43
44host_driver_t serial_driver = {
45 keyboard_leds,
46 send_keyboard,
47 send_mouse,
48 send_system,
49 send_consumer
50};
32 51
33 52
34// Slow speed for testing 53// Slow speed for testing
@@ -89,8 +108,25 @@ void send_data(uint8_t link, const uint8_t* data, uint16_t size) {
89 } 108 }
90} 109}
91 110
111static systime_t last_update = 0;
112
113typedef struct {
114 uint32_t test;
115} test_object1_t;
116
117
118SLAVE_TO_MASTER_OBJECT(slave_to_master, test_object1_t);
119MASTER_TO_ALL_SLAVES_OBJECT(serial_link_connected, bool);
120
121remote_object_t* test_remote_objects[] = {
122 REMOTE_OBJECT(serial_link_connected),
123 REMOTE_OBJECT(slave_to_master),
124};
92 125
93void init_serial_link(void) { 126void init_serial_link(void) {
127 serial_link_connected = false;
128 init_serial_link_hal();
129 init_transport(test_remote_objects, sizeof(test_remote_objects)/sizeof(remote_object_t*));
94 init_byte_stuffer(); 130 init_byte_stuffer();
95 sdStart(&SD1, &config); 131 sdStart(&SD1, &config);
96 sdStart(&SD2, &config); 132 sdStart(&SD2, &config);
@@ -99,6 +135,60 @@ void init_serial_link(void) {
99 LOWPRIO, serialThread, NULL); 135 LOWPRIO, serialThread, NULL);
100} 136}
101 137
138void serial_link_update(void) {
139 systime_t current_time = chVTGetSystemTimeX();
140 if (current_time - last_update > 1000) {
141 *begin_write_serial_link_connected() = true;
142 end_write_serial_link_connected();
143 test_object1_t* obj = begin_write_slave_to_master();
144 obj->test = current_time;
145 end_write_slave_to_master();
146 xprintf("writing %d\n", current_time);
147 last_update = current_time;
148 }
149 test_object1_t* obj = read_slave_to_master(0);
150 if (obj) {
151 xprintf("%d\n", obj->test);
152 }
153 obj = read_slave_to_master(1);
154 if (obj) {
155 xprintf("%d\n", obj->test);
156 }
157
158 if (read_serial_link_connected()) {
159 serial_link_connected = true;
160 }
161}
162
102void signal_data_written(void) { 163void signal_data_written(void) {
103 chEvtBroadcast(&new_data_event); 164 chEvtBroadcast(&new_data_event);
104} 165}
166
167bool is_serial_link_connected(void) {
168 return serial_link_connected;
169}
170
171host_driver_t* get_serial_link_driver(void) {
172 return &serial_driver;
173}
174
175uint8_t keyboard_leds(void) {
176 return 0;
177}
178
179void send_keyboard(report_keyboard_t *report) {
180 (void)report;
181}
182
183void send_mouse(report_mouse_t *report) {
184 (void)report;
185}
186
187void send_system(uint16_t data) {
188 (void)data;
189}
190
191void send_consumer(uint16_t data) {
192 (void)data;
193}
194
diff --git a/serial_link/system/system.h b/serial_link/system/system.h
index e8c1caec0..fcc27425e 100644
--- a/serial_link/system/system.h
+++ b/serial_link/system/system.h
@@ -26,7 +26,6 @@ SOFTWARE.
26#define SERIAL_LINK_SYSTEM_H 26#define SERIAL_LINK_SYSTEM_H
27 27
28 28
29void init_serial_link(void);
30 29
31#if defined(PROTOCOL_CHIBIOS) 30#if defined(PROTOCOL_CHIBIOS)
32#include "ch.h" 31#include "ch.h"