Skip to content

[HID] Another small cleanup #3884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions hardware/arduino/avr/cores/arduino/PluggableUSB.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ typedef struct __attribute__((packed))
uint8_t *endpointType;
} PUSBCallbacks;

typedef struct
{
u8 interface;
u8 firstEndpoint;
} PUSBReturn;

class PUSBListNode {
public:
PUSBListNode *next = NULL;
Expand Down
19 changes: 10 additions & 9 deletions hardware/arduino/avr/libraries/HID/HID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

HID_ HID;

static u8 HID_ENDPOINT_INT;
static uint8_t HID_ENDPOINT_INT;

//================================================================================
//================================================================================
// HID Interface

static u8 HID_INTERFACE;
static uint8_t HID_INTERFACE;

HIDDescriptor _hidInterface;

Expand All @@ -40,10 +40,10 @@ static uint8_t modules_count = 0;
//================================================================================
// Driver

u8 _hid_protocol = 1;
u8 _hid_idle = 1;
uint8_t _hid_protocol = 1;
uint8_t _hid_idle = 1;

int HID_GetInterface(u8* interfaceNum)
int HID_GetInterface(uint8_t* interfaceNum)
{
interfaceNum[0] += 1; // uses 1
_hidInterface =
Expand Down Expand Up @@ -85,19 +85,19 @@ void HID_::AppendDescriptor(HIDDescriptorListNode *node)
sizeof_hidReportDescriptor += (uint16_t)node->length;
}

void HID_::SendReport(u8 id, const void* data, int len)
void HID_::SendReport(uint8_t id, const void* data, const uint16_t len)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be int or you should change all underlying APIs as well. I know that this is sometimes good or bad but in this case we should keep the int. 32k bytes is far enough anyways.

{
USB_Send(HID_TX, &id, 1);
USB_Send(HID_TX | TRANSFER_RELEASE,data,len);
}

bool HID_Setup(USBSetup& setup, u8 i)
bool HID_Setup(USBSetup& setup, uint8_t i)
{
if (HID_INTERFACE != i) {
return false;
} else {
u8 r = setup.bRequest;
u8 requestType = setup.bmRequestType;
uint8_t r = setup.bRequest;
uint8_t requestType = setup.bmRequestType;
if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType)
{
if (HID_GET_REPORT == r)
Expand Down Expand Up @@ -152,6 +152,7 @@ HID_::HID_(void)

int HID_::begin(void)
{
return 0;
}

#endif /* if defined(USBCON) */
26 changes: 13 additions & 13 deletions hardware/arduino/avr/libraries/HID/HID.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,28 @@ class HID_
public:
HID_(void);
int begin(void);
void SendReport(uint8_t id, const void* data, int len);
void SendReport(uint8_t id, const void* data, const uint16_t len);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int here as well

void AppendDescriptor(HIDDescriptorListNode* node);
};

typedef struct
{
u8 len; // 9
u8 dtype; // 0x21
u8 addr;
u8 versionL; // 0x101
u8 versionH; // 0x101
u8 country;
u8 desctype; // 0x22 report
u8 descLenL;
u8 descLenH;
uint8_t len; // 9
uint8_t dtype; // 0x21
uint8_t addr;
uint8_t versionL; // 0x101
uint8_t versionH; // 0x101
uint8_t country;
uint8_t desctype; // 0x22 report
uint8_t descLenL;
uint8_t descLenH;
} HIDDescDescriptor;

typedef struct
{
InterfaceDescriptor hid;
HIDDescDescriptor desc;
EndpointDescriptor in;
InterfaceDescriptor hid;
HIDDescDescriptor desc;
EndpointDescriptor in;
} HIDDescriptor;

#define HID_TX HID_ENDPOINT_INT
Expand Down
6 changes: 0 additions & 6 deletions hardware/arduino/sam/cores/arduino/USB/PluggableUSB.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ typedef struct __attribute__((packed))
uint32_t *endpointType;
} PUSBCallbacks;

typedef struct
{
uint8_t interface;
uint8_t firstEndpoint;
} PUSBReturn;

class PUSBListNode {
public:
PUSBListNode *next = NULL;
Expand Down
4 changes: 2 additions & 2 deletions hardware/arduino/sam/libraries/HID/HID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ void HID_::AppendDescriptor(HIDDescriptorListNode *node)
sizeof_hidReportDescriptor += node->length;
}

void HID_::SendReport(uint8_t id, const void* data, int len)
void HID_::SendReport(uint8_t id, const void* data, const uint16_t len)
{
uint8_t p[64];
const uint8_t *d = reinterpret_cast<const uint8_t *>(data);

p[0] = id;
for (uint32_t i=0; i<len; i++)
for (uint16_t i=0; i<len; i++)
p[i+1] = d[i];
USBD_Send(HID_TX, p, len+1);
}
Expand Down
5 changes: 3 additions & 2 deletions hardware/arduino/sam/libraries/HID/HID.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ class HIDDescriptorListNode {
public:
HIDDescriptorListNode *next = NULL;
HIDDescriptorListNode(const void *d, const uint16_t l) : data(d), length(l) { }
uint16_t length;

const void* data;
const uint16_t length;
};

class HID_
{
public:
HID_(void);
int begin(void);
void SendReport(uint8_t id, const void* data, int len);
void SendReport(uint8_t id, const void* data, const uint16_t len);
void AppendDescriptor(HIDDescriptorListNode* node);
};

Expand Down