Made HID_ class members static inside the class, not global.

This commit is contained in:
NicoHood 2015-09-19 15:41:41 +02:00
parent 7f407fcb58
commit 67904276e5
4 changed files with 44 additions and 24 deletions

View file

@ -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;

View file

@ -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) \

View file

@ -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

View file

@ -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);
};