diff --git a/examples/AbsoluteMouse/AbsoluteMouse.ino b/examples/AbsoluteMouse/AbsoluteMouse.ino index 872ee63..3cf052c 100644 --- a/examples/AbsoluteMouse/AbsoluteMouse.ino +++ b/examples/AbsoluteMouse/AbsoluteMouse.ino @@ -5,6 +5,8 @@ AbsoluteMouse example Press a button to click, moveTo the mouse. + You may also use SingleAbsoluteMouse to use a single report. + See HID Project documentation for more infos https://github.com/NicoHood/HID/wiki/Mouse-API https://github.com/NicoHood/HID/wiki/AbsoluteMouse-API diff --git a/keywords.txt b/keywords.txt index 977bcdb..a6e5bf0 100644 --- a/keywords.txt +++ b/keywords.txt @@ -76,6 +76,7 @@ TeensyKeyboard KEYWORD1 NKROKeyboard KEYWORD1 SingleNKROKeyboard KEYWORD1 AbsoluteMouse KEYWORD1 +SingleAbsoluteMouse KEYWORD1 ####################################### # Constants (LITERAL1) diff --git a/src/HID-Project.h b/src/HID-Project.h index cccc3ef..1e7414b 100644 --- a/src/HID-Project.h +++ b/src/HID-Project.h @@ -39,6 +39,7 @@ THE SOFTWARE. #endif // Include all HID libraries (.a linkage required to work) properly +#include "SingleReport/SingleAbsoluteMouse.h" #include "MultiReport/AbsoluteMouse.h" #include "SingleReport/BootMouse.h" #include "MultiReport/ImprovedMouse.h" diff --git a/src/SingleReport/SingleAbsoluteMouse.cpp b/src/SingleReport/SingleAbsoluteMouse.cpp new file mode 100644 index 0000000..bad902c --- /dev/null +++ b/src/SingleReport/SingleAbsoluteMouse.cpp @@ -0,0 +1,144 @@ +/* +Copyright (c) 2014-2015 NicoHood +See the readme for credit to other people. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include "SingleAbsoluteMouse.h" + +static const uint8_t _hidSingleReportDescriptorAbsoluteMouse[] PROGMEM = { + /* Mouse absolute */ + 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) 54 */ + 0x09, 0x02, /* USAGE (Mouse) */ + 0xA1, 0x01, /* COLLECTION (Application) */ + + /* 8 Buttons */ + 0x05, 0x09, /* USAGE_PAGE (Button) */ + 0x19, 0x01, /* USAGE_MINIMUM (Button 1) */ + 0x29, 0x08, /* USAGE_MAXIMUM (Button 8) */ + 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ + 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ + 0x95, 0x08, /* REPORT_COUNT (8) */ + 0x75, 0x01, /* REPORT_SIZE (1) */ + 0x81, 0x02, /* INPUT (Data,Var,Abs) */ + + /* X, Y */ + 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ + 0x09, 0x30, /* USAGE (X) */ + 0x09, 0x31, /* USAGE (Y) */ + 0x16, 0x00, 0x80, /* Logical Minimum (-32768) */ + 0x26, 0xFF, 0x7F, /* Logical Maximum (32767) */ + 0x75, 0x10, /* Report Size (16), */ + 0x95, 0x02, /* Report Count (2), */ + 0x81, 0x02, /* Input (Data, Variable, Absolute) */ + + /* Wheel */ + 0x09, 0x38, /* USAGE (Wheel) */ + 0x15, 0x81, /* LOGICAL_MINIMUM (-127) */ + 0x25, 0x7f, /* LOGICAL_MAXIMUM (127) */ + 0x75, 0x08, /* REPORT_SIZE (8) */ + 0x95, 0x01, /* REPORT_COUNT (1) */ + 0x81, 0x06, /* INPUT (Data,Var,Rel) */ + + /* End */ + 0xc0 /* END_COLLECTION */ +}; + + +SingleAbsoluteMouse_::SingleAbsoluteMouse_(void) : PluggableUSBModule(1, 1, epType), protocol(HID_REPORT_PROTOCOL), idle(1) +{ + epType[0] = EP_TYPE_INTERRUPT_IN; + PluggableUSB().plug(this); +} + +int SingleAbsoluteMouse_::getInterface(uint8_t* interfaceCount) +{ + *interfaceCount += 1; // uses 1 + HIDDescriptor hidInterface = { + D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE), + D_HIDREPORT(sizeof(_hidSingleReportDescriptorAbsoluteMouse)), + D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01) + }; + return USB_SendControl(0, &hidInterface, sizeof(hidInterface)); +} + +int SingleAbsoluteMouse_::getDescriptor(USBSetup& setup) +{ + // Check if this is a HID Class Descriptor request + if (setup.bmRequestType != REQUEST_DEVICETOHOST_STANDARD_INTERFACE) { return 0; } + if (setup.wValueH != HID_REPORT_DESCRIPTOR_TYPE) { return 0; } + + // In a HID Class Descriptor wIndex cointains the interface number + if (setup.wIndex != pluggedInterface) { return 0; } + + // Reset the protocol on reenumeration. Normally the host should not assume the state of the protocol + // due to the USB specs, but Windows and Linux just assumes its in report mode. + protocol = HID_REPORT_PROTOCOL; + + return USB_SendControl(TRANSFER_PGM, _hidSingleReportDescriptorAbsoluteMouse, sizeof(_hidSingleReportDescriptorAbsoluteMouse)); +} + +bool SingleAbsoluteMouse_::setup(USBSetup& setup) +{ + if (pluggedInterface != setup.wIndex) { + return false; + } + + uint8_t request = setup.bRequest; + uint8_t requestType = setup.bmRequestType; + + if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE) + { + if (request == HID_GET_REPORT) { + // TODO: HID_GetReport(); + return true; + } + if (request == HID_GET_PROTOCOL) { + // TODO: Send8(protocol); + return true; + } + } + + if (requestType == REQUEST_HOSTTODEVICE_CLASS_INTERFACE) + { + if (request == HID_SET_PROTOCOL) { + protocol = setup.wValueL; + return true; + } + if (request == HID_SET_IDLE) { + idle = setup.wValueL; + return true; + } + if (request == HID_SET_REPORT) + { + } + } + + return false; +} + +void SingleAbsoluteMouse_::SendReport(void* data, int length) +{ + USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, length); +} + +SingleAbsoluteMouse_ SingleAbsoluteMouse; + + diff --git a/src/SingleReport/SingleAbsoluteMouse.h b/src/SingleReport/SingleAbsoluteMouse.h new file mode 100644 index 0000000..2a13fe9 --- /dev/null +++ b/src/SingleReport/SingleAbsoluteMouse.h @@ -0,0 +1,55 @@ +/* +Copyright (c) 2014-2015 NicoHood +See the readme for credit to other people. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +// Include guard +#pragma once + +#include +#include "PluggableUSB.h" +#include "HID.h" +#include "HID-Settings.h" +#include "../HID-APIs/AbsoluteMouseAPI.h" + + +class SingleAbsoluteMouse_ : public PluggableUSBModule, public AbsoluteMouseAPI +{ +public: + SingleAbsoluteMouse_(void); + uint8_t getLeds(void); + uint8_t getProtocol(void); + +protected: + // Implementation of the PUSBListNode + int getInterface(uint8_t* interfaceCount); + int getDescriptor(USBSetup& setup); + bool setup(USBSetup& setup); + + uint8_t epType[1]; + uint8_t protocol; + uint8_t idle; + + virtual inline void SendReport(void* data, int length) override; +}; +extern SingleAbsoluteMouse_ SingleAbsoluteMouse; + +