diff options
author | tomaszduda23 <[email protected]> | 2022-07-15 16:22:26 +0900 |
---|---|---|
committer | GitHub <[email protected]> | 2022-07-15 10:22:26 +0300 |
commit | 48f479286170f3cf79304d9b89dd166dec5af834 (patch) | |
tree | c99ed8dee91921c6e39127a6af2dfafb5416849d /hid | |
parent | 4b87851119ea8b1529ac9d29a563c6823220bf46 (diff) |
commented kvmd/kvmd#80 (#102)
Co-authored-by: Maxim Devaev <[email protected]>
Diffstat (limited to 'hid')
-rw-r--r-- | hid/patch.py | 1 | ||||
-rw-r--r-- | hid/patches/arduino-no-main.patch | 35 | ||||
-rw-r--r-- | hid/src/main.cpp | 61 |
3 files changed, 51 insertions, 46 deletions
diff --git a/hid/patch.py b/hid/patch.py index 9c253295..0d080b49 100644 --- a/hid/patch.py +++ b/hid/patch.py @@ -28,6 +28,7 @@ def _patch(path: str, patch_path: str) -> None: assert exists(path) flag_path: str = join(path, f".{basename(patch_path)}.done") if not exists(flag_path): + # TODO check for failure env.Execute(f"patch -p1 -d {path} < {patch_path}") env.Execute(lambda *_, **__: open(flag_path, "w").close()) diff --git a/hid/patches/arduino-no-main.patch b/hid/patches/arduino-no-main.patch index 7dc1f81c..ab10c9a8 100644 --- a/hid/patches/arduino-no-main.patch +++ b/hid/patches/arduino-no-main.patch @@ -1,17 +1,24 @@ -diff -u -r a/cores/arduino/main.cpp b/cores/arduino/main.cpp ---- a/cores/arduino/main.cpp 2019-05-16 15:52:01.000000000 +0300 -+++ b/cores/arduino/main.cpp 2020-11-17 18:56:01.243474508 +0300 -@@ -30,6 +30,7 @@ - void setupUSB() __attribute__((weak)); - void setupUSB() { } +diff --git a/cores/arduino/main.cpp b/cores/arduino/main.cpp +index 434cd40..7aba76f 100644 +--- a/cores/arduino/main.cpp ++++ b/cores/arduino/main.cpp +@@ -36,15 +36,15 @@ int main(void) -+/* - int main(void) - { - init(); -@@ -49,4 +50,5 @@ + initVariant(); + +-#if defined(USBCON) +- USBDevice.attach(); +-#endif ++// #if defined(USBCON) ++// USBDevice.attach(); ++// #endif + + setup(); + + for (;;) { + loop(); +- if (serialEventRun) serialEventRun(); ++ // if (serialEventRun) serialEventRun(); + } return 0; - } -+*/ - diff --git a/hid/src/main.cpp b/hid/src/main.cpp index d02ca55c..c568d6c2 100644 --- a/hid/src/main.cpp +++ b/hid/src/main.cpp @@ -303,9 +303,7 @@ static void _sendResponse(uint8_t code) { # endif } -int main() { - init(); // Embedded - initVariant(); // Arduino +void setup() { _initOutputs(); # ifdef AUM @@ -314,41 +312,40 @@ int main() { # ifdef CMD_SERIAL CMD_SERIAL.begin(CMD_SERIAL_SPEED); - unsigned long last = micros(); - uint8_t buffer[8]; - uint8_t index = 0; # elif defined(CMD_SPI) spiBegin(); # endif +} - while (true) { -# ifdef AUM - aumProxyUsbVbus(); -# endif +void loop() { +# ifdef AUM + aumProxyUsbVbus(); +# endif - _kbd->periodic(); - -# ifdef CMD_SERIAL - if (CMD_SERIAL.available() > 0) { - buffer[index] = (uint8_t)CMD_SERIAL.read(); - if (index == 7) { - _sendResponse(_handleRequest(buffer)); - index = 0; - } else /*if (buffer[0] == PROTO::MAGIC)*/ { // FIXME: See kvmd/kvmd#80 - last = micros(); - ++index; - } - } else if (index > 0) { - if (is_micros_timed_out(last, CMD_SERIAL_TIMEOUT)) { - _sendResponse(PROTO::RESP::TIMEOUT_ERROR); - index = 0; - } + _kbd->periodic(); + +# ifdef CMD_SERIAL + static unsigned long last = micros(); + static uint8_t buffer[8]; + static uint8_t index = 0; + if (CMD_SERIAL.available() > 0) { + buffer[index] = (uint8_t)CMD_SERIAL.read(); + if (index == 7) { + _sendResponse(_handleRequest(buffer)); + index = 0; + } else /*if (buffer[0] == PROTO::MAGIC)*/ { // FIXME: See kvmd/kvmd#80 + last = micros(); + ++index; } -# elif defined(CMD_SPI) - if (spiReady()) { - _sendResponse(_handleRequest(spiGet())); + } else if (index > 0) { + if (is_micros_timed_out(last, CMD_SERIAL_TIMEOUT)) { + _sendResponse(PROTO::RESP::TIMEOUT_ERROR); + index = 0; } -# endif } - return 0; +# elif defined(CMD_SPI) + if (spiReady()) { + _sendResponse(_handleRequest(spiGet())); + } +# endif } |