diff options
Diffstat (limited to 'hid')
-rw-r--r-- | hid/Makefile | 2 | ||||
-rw-r--r-- | hid/platformio.ini | 10 | ||||
-rw-r--r-- | hid/src/main.cpp | 39 | ||||
-rw-r--r-- | hid/src/proto.h | 9 |
4 files changed, 55 insertions, 5 deletions
diff --git a/hid/Makefile b/hid/Makefile index 4d2d4763..a46a66d0 100644 --- a/hid/Makefile +++ b/hid/Makefile @@ -2,6 +2,8 @@ serial: make _build E=serial spi: make _build E=spi +aum: + make _build E=aum _build: rm -f .current platformio run --environment $(E) diff --git a/hid/platformio.ini b/hid/platformio.ini index 87d4fe39..206d22ca 100644 --- a/hid/platformio.ini +++ b/hid/platformio.ini @@ -83,3 +83,13 @@ upload_flags = -p $BOARD_MCU upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i + +[env:aum] +extends = + env:spi +lib_deps = + ${env:spi.lib_deps} +build_flags = + ${env:spi.build_flags} + -DAUM diff --git a/hid/src/main.cpp b/hid/src/main.cpp index 0442b448..28880d4b 100644 --- a/hid/src/main.cpp +++ b/hid/src/main.cpp @@ -36,6 +36,13 @@ # include <avr/eeprom.h> #endif +#if defined(AUM) && defined(HID_WITH_USB) +# include <digitalWriteFast.h> +# define AUM_IS_USB_POWERED_PIN A4 +# define AUM_SET_USB_VBUS_PIN 11 +# define AUM_SET_USB_PLUGGED_PIN A5 +#endif + #include "proto.h" #ifdef CMD_SPI # include "spi.h" @@ -158,6 +165,12 @@ static void _cmdSetMouse(const uint8_t *data) { // 1 bytes # endif } +static void _cmdSetUsbPlugged(const uint8_t *data) { // 1 byte +# if defined(AUM) && defined(HID_WITH_USB) + digitalWriteFast(AUM_SET_USB_PLUGGED_PIN, (bool)data[0]); +# endif +} + static void _cmdClearHid(const uint8_t *_) { // 0 bytes if (_usb_kbd) { _usb_kbd->clear(); @@ -230,6 +243,7 @@ static uint8_t _handleRequest(const uint8_t *data) { // 8 bytes case PROTO::CMD::PING: return PROTO::PONG::OK; case PROTO::CMD::SET_KEYBOARD: HANDLE(_cmdSetKeyboard); case PROTO::CMD::SET_MOUSE: HANDLE(_cmdSetMouse); + case PROTO::CMD::SET_USB_PLUGGED: HANDLE(_cmdSetUsbPlugged); case PROTO::CMD::CLEAR_HID: HANDLE(_cmdClearHid); case PROTO::CMD::KEYBOARD::KEY: HANDLE(_cmdKeyEvent); case PROTO::CMD::MOUSE::BUTTON: HANDLE(_cmdMouseButtonEvent); @@ -280,11 +294,17 @@ static void _sendResponse(uint8_t code) { response[1] |= _usb_mouse_rel->getOfflineAs(PROTO::PONG::MOUSE_OFFLINE); response[2] |= PROTO::OUTPUTS::MOUSE::USB_REL; } // TODO: ps2 +# if defined(AUM) && defined(HID_WITH_USB) + response[3] |= PROTO::PARAMS::USB_PLUGGABLE; + if (digitalReadFast(AUM_SET_USB_PLUGGED_PIN)) { + response[3] |= PROTO::PARAMS::USB_PLUGGED; + } +# endif # ifdef HID_WITH_USB - response[3] |= PROTO::FEATURES::HAS_USB; + response[3] |= PROTO::PARAMS::HAS_USB; # endif # ifdef HID_WITH_PS2 - response[3] |= PROTO::FEATURES::HAS_PS2; + response[3] |= PROTO::PARAMS::HAS_PS2; # endif } else { response[1] = code; @@ -303,6 +323,13 @@ int main() { initVariant(); // Arduino _initOutputs(); +# if defined(AUM) && defined(HID_WITH_USB) + pinModeFast(AUM_IS_USB_POWERED_PIN, INPUT); + pinModeFast(AUM_SET_USB_VBUS_PIN, OUTPUT); + pinModeFast(AUM_SET_USB_PLUGGED_PIN, OUTPUT); + digitalWriteFast(AUM_SET_USB_PLUGGED_PIN, HIGH); +# endif + # ifdef CMD_SERIAL CMD_SERIAL.begin(CMD_SERIAL_SPEED); unsigned long last = micros(); @@ -313,11 +340,19 @@ int main() { # endif while (true) { +# if defined(AUM) && defined(HID_WITH_USB) + bool vbus = digitalReadFast(AUM_IS_USB_POWERED_PIN); + if (digitalReadFast(AUM_SET_USB_VBUS_PIN) != vbus) { + digitalWriteFast(AUM_SET_USB_VBUS_PIN, vbus); + } +# endif + # ifdef HID_WITH_PS2 if (_ps2_kbd) { _ps2_kbd->periodic(); } # endif + # ifdef CMD_SERIAL if (CMD_SERIAL.available() > 0) { buffer[index] = (uint8_t)CMD_SERIAL.read(); diff --git a/hid/src/proto.h b/hid/src/proto.h index 38462ee5..cd0ab46b 100644 --- a/hid/src/proto.h +++ b/hid/src/proto.h @@ -60,9 +60,11 @@ namespace PROTO { }; }; - namespace FEATURES { - const uint8_t HAS_USB = 0b00000001; - const uint8_t HAS_PS2 = 0b00000010; + namespace PARAMS { + const uint8_t HAS_USB = 0b00000001; + const uint8_t HAS_PS2 = 0b00000010; + const uint8_t USB_PLUGGABLE = 0b10000000; + const uint8_t USB_PLUGGED = 0b01000000; } namespace CMD { @@ -70,6 +72,7 @@ namespace PROTO { const uint8_t REPEAT = 0x02; const uint8_t SET_KEYBOARD = 0x03; const uint8_t SET_MOUSE = 0x04; + const uint8_t SET_USB_PLUGGED = 0x05; const uint8_t CLEAR_HID = 0x10; namespace KEYBOARD { |