aboutsummaryrefslogtreecommitdiff
path: root/serial_link/system/system.c
diff options
context:
space:
mode:
Diffstat (limited to 'serial_link/system/system.c')
-rw-r--r--serial_link/system/system.c90
1 files changed, 90 insertions, 0 deletions
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