diff options
| -rw-r--r-- | serial_link.mk | 4 | ||||
| -rw-r--r-- | serial_link/system/driver.h | 36 | ||||
| -rw-r--r-- | serial_link/system/system.c | 90 | ||||
| -rw-r--r-- | serial_link/system/system.h | 1 |
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 | ||
| 23 | UINCDIR += $(SERIAL_DIR) | 23 | UINCDIR += $(SERIAL_DIR) |
| 24 | SRC += $(wildcard $(SERIAL_DIR)/serial_link/protocol/*.c) | 24 | SRC += $(wildcard $(SERIAL_DIR)/serial_link/protocol/*.c) |
| 25 | SRC += $(wildcard $(SERIAL_DIR)/serial_link/system/*.c) \ No newline at end of file | 25 | SRC += $(wildcard $(SERIAL_DIR)/serial_link/system/*.c) |
| 26 | SRC += serial_link_hal.c | ||
| 27 | OPT_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 | /* | ||
| 2 | The MIT License (MIT) | ||
| 3 | |||
| 4 | Copyright (c) 2016 Fred Sundvik | ||
| 5 | |||
| 6 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 7 | of this software and associated documentation files (the "Software"), to deal | ||
| 8 | in the Software without restriction, including without limitation the rights | ||
| 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 10 | copies of the Software, and to permit persons to whom the Software is | ||
| 11 | furnished to do so, subject to the following conditions: | ||
| 12 | |||
| 13 | The above copyright notice and this permission notice shall be included in all | ||
| 14 | copies or substantial portions of the Software. | ||
| 15 | |||
| 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| 22 | SOFTWARE. | ||
| 23 | */ | ||
| 24 | |||
| 25 | #ifndef SERIAL_LINK_DRIVER_H | ||
| 26 | #define SERIAL_LINK_DRIVER_H | ||
| 27 | |||
| 28 | #include "host_driver.h" | ||
| 29 | |||
| 30 | void init_serial_link(void); | ||
| 31 | void init_serial_link_hal(void); | ||
| 32 | bool is_serial_link_connected(void); | ||
| 33 | host_driver_t* get_serial_link_driver(void); | ||
| 34 | void 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, | |||
| 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | SOFTWARE. | 22 | SOFTWARE. |
| 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 | ||
| 31 | static event_source_t new_data_event; | 35 | static event_source_t new_data_event; |
| 36 | static bool serial_link_connected; | ||
| 37 | |||
| 38 | static uint8_t keyboard_leds(void); | ||
| 39 | static void send_keyboard(report_keyboard_t *report); | ||
| 40 | static void send_mouse(report_mouse_t *report); | ||
| 41 | static void send_system(uint16_t data); | ||
| 42 | static void send_consumer(uint16_t data); | ||
| 43 | |||
| 44 | host_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 | ||
| 111 | static systime_t last_update = 0; | ||
| 112 | |||
| 113 | typedef struct { | ||
| 114 | uint32_t test; | ||
| 115 | } test_object1_t; | ||
| 116 | |||
| 117 | |||
| 118 | SLAVE_TO_MASTER_OBJECT(slave_to_master, test_object1_t); | ||
| 119 | MASTER_TO_ALL_SLAVES_OBJECT(serial_link_connected, bool); | ||
| 120 | |||
| 121 | remote_object_t* test_remote_objects[] = { | ||
| 122 | REMOTE_OBJECT(serial_link_connected), | ||
| 123 | REMOTE_OBJECT(slave_to_master), | ||
| 124 | }; | ||
| 92 | 125 | ||
| 93 | void init_serial_link(void) { | 126 | void 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 | ||
| 138 | void 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 | |||
| 102 | void signal_data_written(void) { | 163 | void signal_data_written(void) { |
| 103 | chEvtBroadcast(&new_data_event); | 164 | chEvtBroadcast(&new_data_event); |
| 104 | } | 165 | } |
| 166 | |||
| 167 | bool is_serial_link_connected(void) { | ||
| 168 | return serial_link_connected; | ||
| 169 | } | ||
| 170 | |||
| 171 | host_driver_t* get_serial_link_driver(void) { | ||
| 172 | return &serial_driver; | ||
| 173 | } | ||
| 174 | |||
| 175 | uint8_t keyboard_leds(void) { | ||
| 176 | return 0; | ||
| 177 | } | ||
| 178 | |||
| 179 | void send_keyboard(report_keyboard_t *report) { | ||
| 180 | (void)report; | ||
| 181 | } | ||
| 182 | |||
| 183 | void send_mouse(report_mouse_t *report) { | ||
| 184 | (void)report; | ||
| 185 | } | ||
| 186 | |||
| 187 | void send_system(uint16_t data) { | ||
| 188 | (void)data; | ||
| 189 | } | ||
| 190 | |||
| 191 | void 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 | ||
| 29 | void init_serial_link(void); | ||
| 30 | 29 | ||
| 31 | #if defined(PROTOCOL_CHIBIOS) | 30 | #if defined(PROTOCOL_CHIBIOS) |
| 32 | #include "ch.h" | 31 | #include "ch.h" |
