diff --git a/src/kaleidoscope/driver/hid/RCMComposite.cpp b/src/kaleidoscope/driver/hid/RCMComposite.cpp index 22302761..02bf46c8 100644 --- a/src/kaleidoscope/driver/hid/RCMComposite.cpp +++ b/src/kaleidoscope/driver/hid/RCMComposite.cpp @@ -26,6 +26,7 @@ USBHID RCMHID; HIDKeyboard RCMBootKeyboard(RCMHID, 0); HIDKeyboard RCMKeyboard(RCMHID); HIDConsumer RCMConsumer(RCMHID); +HIDMouse RCMMouse(RCMHID); USBCompositeSerial CompositeSerial; } // namespace rcmcomposite diff --git a/src/kaleidoscope/driver/hid/RCMComposite.h b/src/kaleidoscope/driver/hid/RCMComposite.h index 2b601d34..20eaaa7b 100644 --- a/src/kaleidoscope/driver/hid/RCMComposite.h +++ b/src/kaleidoscope/driver/hid/RCMComposite.h @@ -23,7 +23,7 @@ #include "kaleidoscope/driver/hid/Base.h" #include "rcmcomposite/Keyboard.h" -//#include "rcmcomposite/Mouse.h" +#include "rcmcomposite/Mouse.h" namespace kaleidoscope { namespace driver { @@ -38,7 +38,8 @@ extern USBCompositeSerial CompositeSerial; const uint8_t report_description_[] = { HID_BOOT_KEYBOARD_REPORT_DESCRIPTOR(), HID_KEYBOARD_REPORT_DESCRIPTOR(2), - HID_CONSUMER_REPORT_DESCRIPTOR(3) + HID_CONSUMER_REPORT_DESCRIPTOR(3), + HID_MOUSE_REPORT_DESCRIPTOR(4) }; } @@ -46,8 +47,8 @@ const uint8_t report_description_[] = { struct RCMCompositeProps: public BaseProps { typedef rcmcomposite::KeyboardProps KeyboardProps; typedef rcmcomposite::Keyboard Keyboard; - // typedef rcmcomposite::MouseProps MouseProps; - // typedef rcmcomposite::Mouse Mouse; + typedef rcmcomposite::MouseProps MouseProps; + typedef rcmcomposite::Mouse Mouse; }; template diff --git a/src/kaleidoscope/driver/hid/rcmcomposite/Mouse.h b/src/kaleidoscope/driver/hid/rcmcomposite/Mouse.h new file mode 100644 index 00000000..35bb1e0b --- /dev/null +++ b/src/kaleidoscope/driver/hid/rcmcomposite/Mouse.h @@ -0,0 +1,81 @@ +// -*- mode: c++ -*- +/* Kaleidoscope - Firmware for computer input devices + * Copyright (C) 2021 Keyboard.io, Inc. + * + * 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, version 3. + * + * 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 . + */ + +#pragma once +#include +#include + +#include "kaleidoscope/driver/hid/base/Mouse.h" + +namespace kaleidoscope { +namespace driver { +namespace hid { +namespace rcmcomposite { + +extern HIDMouse RCMMouse; + +/* + * We are wrapping `Mouse` here, instead of directly using the class in + * `MouseProps` below. We do this, because this lets the linker optimize this + * whole thing out if it is unused. It can do that because instantiating `Mouse` + * is in a separate compilation unit. + * + * While it would have been cleaner and shorter to instantiate them here, and + * drop the global objects, that prevents optimizing them out, and that's a cost + * we do not want to pay. + */ + +class MouseWrapper { + public: + MouseWrapper() {} + + void begin() {} + void sendReport() { + RCMMouse.sendReport(); + } + void move(int8_t x, int8_t y, int8_t vWheel, int8_t hWheel) { + RCMMouse.move(x, y, vWheel); + } + void stop(bool x, bool y, bool vWheel = false, bool hWheel = false) { + RCMMouse.stop(x, y, vWheel); + } + + void releaseAll() { + RCMMouse.releaseAll(); + } + void press(uint8_t buttons) { + RCMMouse.press(buttons); + } + void release(uint8_t buttons) { + RCMMouse.release(buttons); + } + void click(uint8_t buttons) { + RCMMouse.click(buttons); + } +}; + +struct MouseProps: public base::MouseProps { + typedef MouseWrapper Mouse; +}; + +template +class Mouse: public base::Mouse<_Props> {}; + +} +} +} +}