From fe9c6f8d928c911127d32e71b88b6b9b53f379f0 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Fri, 8 Jun 2018 06:13:52 +0200 Subject: [PATCH] Implement a way to detach from / attach to the host These functions can be used to detach from the host, then re-attach, possibly with different properties, without having to reboot the device. Signed-off-by: Gergely Nagy --- src/Kaleidoscope-Hardware-Model01.cpp | 8 ++++++++ src/Kaleidoscope-Hardware-Model01.h | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Kaleidoscope-Hardware-Model01.cpp b/src/Kaleidoscope-Hardware-Model01.cpp index 2fc7df61..f699806f 100644 --- a/src/Kaleidoscope-Hardware-Model01.cpp +++ b/src/Kaleidoscope-Hardware-Model01.cpp @@ -251,4 +251,12 @@ void Model01::setKeyscanInterval(uint8_t interval) { rightHand.setKeyscanInterval(interval); } +void Model01::detachFromHost() { + UDCON |= (1 << DETACH); +} + +void Model01::attachToHost() { + UDCON &= ~(1 << DETACH); +} + HARDWARE_IMPLEMENTATION KeyboardHardware; diff --git a/src/Kaleidoscope-Hardware-Model01.h b/src/Kaleidoscope-Hardware-Model01.h index c8946265..976a54ce 100644 --- a/src/Kaleidoscope-Hardware-Model01.h +++ b/src/Kaleidoscope-Hardware-Model01.h @@ -29,6 +29,17 @@ class Model01 { void rebootBootloader(); + /** Detaching from / attaching to the host. + * + * These two functions should detach the device from (or attach it to) the + * host, preferably without rebooting the device. Their purpose is to allow + * one to do some configuration inbetween, so the re-attach happens with + * different properties. The device remains powered between these operations, + * only the connection to the host gets severed. + */ + void detachFromHost(); + void attachToHost(); + /* These public functions are things supported by the Model 01, but * aren't necessarily part of the Kaleidoscope API */