From 67904276e50423d5f3bd6b14f30942e1b1769b08 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 19 Sep 2015 15:41:41 +0200 Subject: [PATCH] Made HID_ class members static inside the class, not global. --- src/PluggableHID/HID.cpp | 24 ++++++++++----------- src/PluggableHID/HID.h | 39 ++++++++++++++++++++++++---------- src/PluggableHID/HIDDevice.cpp | 4 ++++ src/PluggableHID/HIDDevice.h | 1 + 4 files changed, 44 insertions(+), 24 deletions(-) diff --git a/src/PluggableHID/HID.cpp b/src/PluggableHID/HID.cpp index 3470caa..96ffb39 100644 --- a/src/PluggableHID/HID.cpp +++ b/src/PluggableHID/HID.cpp @@ -25,8 +25,6 @@ HID_ HID; -static u8 HID_ENDPOINT_INT; - //================================================================================ //================================================================================ @@ -40,21 +38,21 @@ static u8 HID_ENDPOINT_INT; #define RAWHID_TX_SIZE 64 #define RAWHID_RX_SIZE 64 -static u8 HID_INTERFACE; +// Static variables +uint8_t HID_::HID_ENDPOINT_INT; +uint8_t HID_::HID_INTERFACE; +HIDDescriptor HID_::_hidInterface; +HIDDevice* HID_::rootDevice = NULL; +uint16_t HID_::sizeof_hidReportDescriptor = 0; +uint8_t HID_::modules_count = 0; +uint8_t HID_::_hid_protocol = 1; +uint8_t HID_::_hid_idle = 1; -HIDDescriptor _hidInterface; - -static HIDDevice* rootDevice = NULL; -static uint16_t sizeof_hidReportDescriptor = 0; -static uint8_t modules_count = 0; //================================================================================ //================================================================================ // Driver -u8 _hid_protocol = 1; -u8 _hid_idle = 1; - -int HID_GetInterface(u8* interfaceNum) +int HID_::HID_GetInterface(u8* interfaceNum) { interfaceNum[0] += 1; // uses 1 _hidInterface = @@ -70,7 +68,7 @@ int HID_GetInterface(u8* interfaceNum) return USB_SendControl(0,&_hidInterface,sizeof(_hidInterface)); } -int HID_GetDescriptor(int8_t t) +int HID_::HID_GetDescriptor(int8_t t) { if (HID_REPORT_DESCRIPTOR_TYPE == t) { HIDDevice* current = rootDevice; diff --git a/src/PluggableHID/HID.h b/src/PluggableHID/HID.h index e15c858..e53a4df 100644 --- a/src/PluggableHID/HID.h +++ b/src/PluggableHID/HID.h @@ -46,17 +46,6 @@ class HIDDevice; -class HID_ -{ -public: - HID_(void); - int begin(void); - void SendReport(uint8_t id, const void* data, int len); - void AppendDescriptor(HIDDevice* device); -private: - static bool HID_Setup(USBSetup& setup, u8 i); -}; - typedef struct { u8 len; // 9 @@ -77,6 +66,34 @@ typedef struct EndpointDescriptor in; } HIDDescriptor; +class HID_ +{ +public: + HID_(void); + + // Only access this class via the HIDDevice +private: + friend HIDDevice; + int begin(void); + void SendReport(uint8_t id, const void* data, int len); + void AppendDescriptor(HIDDevice* device); + + // Static functions + static int HID_GetInterface(u8* interfaceNum); + static int HID_GetDescriptor(int8_t t); + static bool HID_Setup(USBSetup& setup, u8 i); + + // Static variables + static uint8_t HID_ENDPOINT_INT; + static uint8_t HID_INTERFACE; + static HIDDescriptor _hidInterface; + static HIDDevice* rootDevice; + static uint16_t sizeof_hidReportDescriptor; + static uint8_t modules_count; + static uint8_t _hid_protocol; + static uint8_t _hid_idle; +}; + #define HID_TX HID_ENDPOINT_INT #define D_HIDREPORT(_descriptorLength) \ diff --git a/src/PluggableHID/HIDDevice.cpp b/src/PluggableHID/HIDDevice.cpp index b29295d..d697f40 100644 --- a/src/PluggableHID/HIDDevice.cpp +++ b/src/PluggableHID/HIDDevice.cpp @@ -22,5 +22,9 @@ void HIDDevice::SendReport(const void* data, int len){ void HIDDevice::setReportData(const void* data, int len){ // Discard this information if its not implemented by the HIDDevice } + +uint8_t HIDDevice::getProtocol(void){ + return HID._hid_protocol; +} #endif diff --git a/src/PluggableHID/HIDDevice.h b/src/PluggableHID/HIDDevice.h index 6663263..ef2fcf5 100644 --- a/src/PluggableHID/HIDDevice.h +++ b/src/PluggableHID/HIDDevice.h @@ -55,6 +55,7 @@ protected: // Could be used and inherited public for custom, professional usage, like raw Keyboard // As an alternative you may still call the HID singleton. void SendReport(const void* data, int len); + uint8_t getProtocol(void); };