diff options
author | Devaev Maxim <[email protected]> | 2020-12-24 15:30:49 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-12-24 15:30:49 +0300 |
commit | 4b6d7605c515adb6b14875f48e7066b1ddcc8948 (patch) | |
tree | a5df883b45af364f6104aaa08c30918cb4a3fbfa /hid | |
parent | 21e4cf86c8b1e5380c28848daa539a3fa86d4c6e (diff) |
check aum usb state
Diffstat (limited to 'hid')
-rw-r--r-- | hid/src/aum.h | 48 | ||||
-rw-r--r-- | hid/src/main.cpp | 30 | ||||
-rw-r--r-- | hid/src/usb/hid.h | 9 |
3 files changed, 68 insertions, 19 deletions
diff --git a/hid/src/aum.h b/hid/src/aum.h new file mode 100644 index 00000000..85a3699b --- /dev/null +++ b/hid/src/aum.h @@ -0,0 +1,48 @@ +/***************************************************************************** +# # +# KVMD - The main Pi-KVM daemon. # +# # +# Copyright (C) 2018 Maxim Devaev <[email protected]> # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see <https://www.gnu.org/licenses/>. # +# # +*****************************************************************************/ + + +#pragma once + +#include <digitalWriteFast.h> + + +inline void aumInit() { + pinModeFast(AUM_IS_USB_POWERED_PIN, INPUT); + pinModeFast(AUM_SET_USB_VBUS_PIN, OUTPUT); + pinModeFast(AUM_SET_USB_CONNECTED_PIN, OUTPUT); + digitalWriteFast(AUM_SET_USB_CONNECTED_PIN, HIGH); +} + +inline void aumProxyUsbVbus() { + bool vbus = digitalReadFast(AUM_IS_USB_POWERED_PIN); + if (digitalReadFast(AUM_SET_USB_VBUS_PIN) != vbus) { + digitalWriteFast(AUM_SET_USB_VBUS_PIN, vbus); + } +} + +inline void aumSetUsbConnected(bool connected) { + digitalWriteFast(AUM_SET_USB_CONNECTED_PIN, connected); +} + +inline bool aumIsUsbConnected() { + return digitalReadFast(AUM_SET_USB_CONNECTED_PIN); +} diff --git a/hid/src/main.cpp b/hid/src/main.cpp index f0c44966..6a97d609 100644 --- a/hid/src/main.cpp +++ b/hid/src/main.cpp @@ -36,15 +36,13 @@ # include <avr/eeprom.h> #endif -#if defined(AUM) && defined(HID_WITH_USB) -# include <digitalWriteFast.h> -// #define bla-bla-bla AUM_* pins -#endif - #include "proto.h" #ifdef CMD_SPI # include "spi.h" #endif +#ifdef AUM +# include "aum.h" +#endif #include "usb/hid.h" #include "ps2/hid.h" @@ -164,8 +162,8 @@ static void _cmdSetMouse(const uint8_t *data) { // 1 bytes } static void _cmdSetConnected(const uint8_t *data) { // 1 byte -# if defined(AUM) && defined(HID_WITH_USB) - digitalWriteFast(AUM_SET_USB_CONNECTED_PIN, (bool)data[0]); +# ifdef AUM + aumSetUsbConnected(data[0]); # endif } @@ -292,9 +290,9 @@ static void _sendResponse(uint8_t code) { response[1] |= _usb_mouse_rel->getOfflineAs(PROTO::PONG::MOUSE_OFFLINE); response[2] |= PROTO::OUTPUTS1::MOUSE::USB_REL; } // TODO: ps2 -# if defined(AUM) && defined(HID_WITH_USB) +# ifdef AUM response[3] |= PROTO::OUTPUTS2::CONNECTABLE; - if (digitalReadFast(AUM_SET_USB_CONNECTED_PIN)) { + if (aumIsUsbConnected()) { response[3] |= PROTO::OUTPUTS2::CONNECTED; } # endif @@ -321,11 +319,8 @@ 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_CONNECTED_PIN, OUTPUT); - digitalWriteFast(AUM_SET_USB_CONNECTED_PIN, HIGH); +# ifdef AUM + aumInit(); # endif # ifdef CMD_SERIAL @@ -338,11 +333,8 @@ 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); - } +# ifdef AUM + aumProxyUsbVbus(); # endif # ifdef HID_WITH_PS2 diff --git a/hid/src/usb/hid.h b/hid/src/usb/hid.h index 7a102eab..bd7ba966 100644 --- a/hid/src/usb/hid.h +++ b/hid/src/usb/hid.h @@ -25,6 +25,9 @@ #include <Arduino.h> #include <HID-Project.h> +#ifdef AUM +# include "../aum.h" +#endif #include "keymap.h" @@ -32,8 +35,14 @@ #ifdef HID_USB_CHECK_ENDPOINT // https://github.com/arduino/ArduinoCore-avr/blob/2f67c916f6ab6193c404eebe22efe901e0f9542d/cores/arduino/USBCore.cpp#L249 // https://sourceforge.net/p/arduinomidilib/svn/41/tree/branch/3.1/Teensy/teensy_core/usb_midi/usb_api.cpp#l103 +# ifdef AUM +# define CHECK_AUM_USB { if (!aumIsUsbConnected()) { return offline; } } +# else +# define CHECK_AUM_USB +# endif # define CLS_GET_OFFLINE_AS(_hid) \ uint8_t getOfflineAs(uint8_t offline) { \ + CHECK_AUM_USB; \ uint8_t ep = _hid.getPluggedEndpoint(); \ uint8_t intr_state = SREG; \ cli(); \ |