mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
check aum usb state
This commit is contained in:
parent
21e4cf86c8
commit
4b6d7605c5
48
hid/src/aum.h
Normal file
48
hid/src/aum.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*****************************************************************************
|
||||
# #
|
||||
# KVMD - The main Pi-KVM daemon. #
|
||||
# #
|
||||
# Copyright (C) 2018 Maxim Devaev <mdevaev@gmail.com> #
|
||||
# #
|
||||
# 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);
|
||||
}
|
||||
@ -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
|
||||
|
||||
@ -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(); \
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user