Skip to content

Commit 2e328ba

Browse files
committed
[HID] Code cleanup (no semantic changes)
1 parent 0b3244c commit 2e328ba

File tree

3 files changed

+86
-96
lines changed

3 files changed

+86
-96
lines changed

cores/arduino/USBDesc.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
2-
3-
/* Copyright (c) 2011, Peter Barrett
4-
**
5-
** Permission to use, copy, modify, and/or distribute this software for
6-
** any purpose with or without fee is hereby granted, provided that the
7-
** above copyright notice and this permission notice appear in all copies.
8-
**
9-
** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10-
** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11-
** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
12-
** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
13-
** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
14-
** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
15-
** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
16-
** SOFTWARE.
17-
*/
1+
/*
2+
Copyright (c) 2011, Peter Barrett
3+
Copyright (c) 2015, Arduino LLC
4+
5+
Permission to use, copy, modify, and/or distribute this software for
6+
any purpose with or without fee is hereby granted, provided that the
7+
above copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10+
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11+
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
12+
BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
13+
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
14+
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
15+
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
16+
SOFTWARE.
17+
*/
1818

1919
#define PLUGGABLE_USB_ENABLED
2020

libraries/HID/HID.cpp

Lines changed: 54 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
/* Copyright (c) 2015, Arduino LLC
2-
**
3-
** Original code (pre-library): Copyright (c) 2011, Peter Barrett
4-
**
5-
** Permission to use, copy, modify, and/or distribute this software for
6-
** any purpose with or without fee is hereby granted, provided that the
7-
** above copyright notice and this permission notice appear in all copies.
8-
**
9-
** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10-
** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11-
** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
12-
** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
13-
** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
14-
** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
15-
** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
16-
** SOFTWARE.
17-
*/
1+
/*
2+
Copyright (c) 2015, Arduino LLC
3+
Original code (pre-library): Copyright (c) 2011, Peter Barrett
4+
5+
Permission to use, copy, modify, and/or distribute this software for
6+
any purpose with or without fee is hereby granted, provided that the
7+
above copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10+
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11+
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
12+
BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
13+
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
14+
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
15+
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
16+
SOFTWARE.
17+
*/
1818

1919
#include "PluggableUSB.h"
2020
#include "HID.h"
@@ -25,11 +25,10 @@ HID_ HID;
2525

2626
int HID_::getInterface(uint8_t* interfaceNum)
2727
{
28-
interfaceNum[0] += 1; // uses 1
29-
hidInterface =
30-
{
28+
*interfaceNum += 1; // uses 1
29+
hidInterface = {
3130
D_INTERFACE(interface(), 1, 3, 0, 0),
32-
D_HIDREPORT(sizeof_hidReportDescriptor),
31+
D_HIDREPORT(descriptorSize),
3332
D_ENDPOINT(USB_ENDPOINT_IN(endpoint()), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01)
3433
};
3534
return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
@@ -38,14 +37,13 @@ int HID_::getInterface(uint8_t* interfaceNum)
3837
int HID_::getDescriptor(int8_t type)
3938
{
4039
if (HID_REPORT_DESCRIPTOR_TYPE == type) {
41-
HIDDescriptorListNode* current = rootNode;
4240
int total = 0;
43-
while (current != NULL) {
44-
int res = USB_SendControl(TRANSFER_PGM, current->data, current->length);
41+
HIDDescriptorListNode* node;
42+
for (node = rootNode; node; node = node->next) {
43+
int res = USB_SendControl(TRANSFER_PGM, node->data, node->length);
4544
if (res == -1)
4645
return -1;
4746
total += res;
48-
current = current->next;
4947
}
5048
return total;
5149
}
@@ -60,61 +58,58 @@ void HID_::AppendDescriptor(HIDDescriptorListNode *node)
6058
rootNode = node;
6159
} else {
6260
HIDDescriptorListNode *current = rootNode;
63-
while(current->next != NULL) {
61+
while (current->next) {
6462
current = current->next;
6563
}
6664
current->next = node;
6765
}
68-
sizeof_hidReportDescriptor += (uint16_t)node->length;
66+
descriptorSize += node->length;
6967
}
7068

7169
void HID_::SendReport(uint8_t id, const void* data, int len)
7270
{
7371
USB_Send(endpoint(), &id, 1);
74-
USB_Send(endpoint() | TRANSFER_RELEASE,data,len);
72+
USB_Send(endpoint() | TRANSFER_RELEASE, data, len);
7573
}
7674

7775
bool HID_::setup(USBSetup& setup, uint8_t interfaceNum)
7876
{
7977
if (interface() != interfaceNum) {
8078
return false;
81-
} else {
82-
uint8_t r = setup.bRequest;
83-
uint8_t requestType = setup.bmRequestType;
84-
if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType)
85-
{
86-
if (HID_GET_REPORT == r)
87-
{
88-
//HID_GetReport();
89-
return true;
90-
}
91-
if (HID_GET_PROTOCOL == r)
92-
{
93-
//Send8(protocol); // TODO
94-
return true;
95-
}
79+
}
80+
81+
uint8_t request = setup.bRequest;
82+
uint8_t requestType = setup.bmRequestType;
83+
84+
if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE)
85+
{
86+
if (request == HID_GET_REPORT) {
87+
// TODO: HID_GetReport();
88+
return true;
9689
}
97-
98-
if (REQUEST_HOSTTODEVICE_CLASS_INTERFACE == requestType)
99-
{
100-
if (HID_SET_PROTOCOL == r)
101-
{
102-
protocol = setup.wValueL;
103-
return true;
104-
}
105-
106-
if (HID_SET_IDLE == r)
107-
{
108-
idle = setup.wValueL;
109-
return true;
110-
}
90+
if (request == HID_GET_PROTOCOL) {
91+
// TODO: Send8(protocol);
92+
return true;
93+
}
94+
}
95+
96+
if (requestType == REQUEST_HOSTTODEVICE_CLASS_INTERFACE)
97+
{
98+
if (request == HID_SET_PROTOCOL) {
99+
protocol = setup.wValueL;
100+
return true;
101+
}
102+
if (request == HID_SET_IDLE) {
103+
idle = setup.wValueL;
104+
return true;
111105
}
112-
return false;
113106
}
107+
108+
return false;
114109
}
115110

116111
HID_::HID_(void) : PUSBListNode(1, 1, epType),
117-
rootNode(NULL), sizeof_hidReportDescriptor(0),
112+
rootNode(NULL), descriptorSize(0),
118113
protocol(1), idle(1)
119114
{
120115
epType[0] = EP_TYPE_INTERRUPT_IN;

libraries/HID/HID.h

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
/*
2-
HID.h
3-
42
Copyright (c) 2015, Arduino LLC
53
Original code (pre-library): Copyright (c) 2011, Peter Barrett
64
7-
This library is free software; you can redistribute it and/or
8-
modify it under the terms of the GNU Lesser General Public
9-
License as published by the Free Software Foundation; either
10-
version 2.1 of the License, or (at your option) any later version.
11-
12-
This library is distributed in the hope that it will be useful,
13-
but WITHOUT ANY WARRANTY; without even the implied warranty of
14-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15-
Lesser General Public License for more details.
5+
Permission to use, copy, modify, and/or distribute this software for
6+
any purpose with or without fee is hereby granted, provided that the
7+
above copyright notice and this permission notice appear in all copies.
168
17-
You should have received a copy of the GNU Lesser General Public
18-
License along with this library; if not, write to the Free Software
19-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20-
*/
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10+
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11+
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
12+
BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
13+
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
14+
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
15+
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
16+
SOFTWARE.
17+
*/
2118

2219
#ifndef HID_h
2320
#define HID_h
@@ -91,16 +88,14 @@ class HID_ : public PUSBListNode
9188
uint8_t epType[1];
9289

9390
HIDDescriptorListNode* rootNode;
94-
uint16_t sizeof_hidReportDescriptor;
91+
uint16_t descriptorSize;
9592

9693
uint8_t protocol;
9794
uint8_t idle;
9895
};
9996

10097
#define D_HIDREPORT(length) { 9, 0x21, 0x01, 0x01, 0, 1, 0x22, lowByte(length), highByte(length) }
10198

102-
#define WEAK __attribute__ ((weak))
103-
104-
#endif
99+
#endif // USBCON
105100

106-
#endif
101+
#endif // HID_h

0 commit comments

Comments
 (0)