Skip to content

Commit cfa9165

Browse files
committed
include needed librarys
1 parent 2e0e464 commit cfa9165

File tree

14 files changed

+1217
-6
lines changed

14 files changed

+1217
-6
lines changed

PedalBox/Pedal.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
#include "UtilLibrary.h"
55

6-
#include "Smoothed.h"
6+
#include "src/Smoothed/Smoothed.h"
77

8-
#include "HX711.h"
8+
#include "src/HX711/HX711.h"
99

10-
#include "ADS1X15.h"
10+
#include "src/ADS1X15/ADS1X15.h"
1111

1212
// init util library
1313
UtilLib utilLib;

PedalBox/Pedals.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#ifndef Pedals_h
22
#define Pedals_h
33

4-
#include <Joystick.h>
5-
#include "MultiMap.h"
6-
#include "SoftwareReset.h"
4+
#include "src/Joystick/Joystick.h"
5+
#include "src/MultiMap/MultiMap.h"
6+
#include "src/SoftwareReset/SoftwareReset.h"
77
#include <EEPROM.h>
88

99
#include "UtilLibrary.h"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/*
2+
Modified by Matthew Heironimus to support HID Report Descriptors to be in
3+
standard RAM in addition to program memory (PROGMEM).
4+
5+
Copyright (c) 2015, Arduino LLC
6+
Original code (pre-library): Copyright (c) 2011, Peter Barrett
7+
8+
Permission to use, copy, modify, and/or distribute this software for
9+
any purpose with or without fee is hereby granted, provided that the
10+
above copyright notice and this permission notice appear in all copies.
11+
12+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13+
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14+
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
15+
BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
16+
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17+
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
18+
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
19+
SOFTWARE.
20+
*/
21+
22+
#include "DynamicHID.h"
23+
24+
#if defined(USBCON)
25+
26+
#ifdef _VARIANT_ARDUINO_DUE_X_
27+
#define USB_SendControl USBD_SendControl
28+
#define USB_Send USBD_Send
29+
#endif
30+
31+
DynamicHID_& DynamicHID()
32+
{
33+
static DynamicHID_ obj;
34+
return obj;
35+
}
36+
37+
int DynamicHID_::getInterface(uint8_t* interfaceCount)
38+
{
39+
*interfaceCount += 1; // uses 1
40+
DYNAMIC_HIDDescriptor hidInterface = {
41+
D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, DYNAMIC_HID_SUBCLASS_NONE, DYNAMIC_HID_PROTOCOL_NONE),
42+
D_HIDREPORT(descriptorSize),
43+
D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01)
44+
};
45+
return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
46+
}
47+
48+
int DynamicHID_::getDescriptor(USBSetup& setup)
49+
{
50+
// Check if this is a HID Class Descriptor request
51+
if (setup.bmRequestType != REQUEST_DEVICETOHOST_STANDARD_INTERFACE) { return 0; }
52+
if (setup.wValueH != DYNAMIC_HID_REPORT_DESCRIPTOR_TYPE) { return 0; }
53+
54+
// In a HID Class Descriptor wIndex cointains the interface number
55+
if (setup.wIndex != pluggedInterface) { return 0; }
56+
57+
int total = 0;
58+
DynamicHIDSubDescriptor* node;
59+
for (node = rootNode; node; node = node->next) {
60+
int res = USB_SendControl((node->inProgMem ? TRANSFER_PGM : 0), node->data, node->length);
61+
if (res == -1)
62+
return -1;
63+
total += res;
64+
}
65+
66+
// Reset the protocol on reenumeration. Normally the host should not assume the state of the protocol
67+
// due to the USB specs, but Windows and Linux just assumes its in report mode.
68+
protocol = DYNAMIC_HID_REPORT_PROTOCOL;
69+
70+
return total;
71+
}
72+
73+
uint8_t DynamicHID_::getShortName(char *name)
74+
{
75+
name[0] = 'H';
76+
name[1] = 'I';
77+
name[2] = 'D';
78+
name[3] = 'A' + (descriptorSize & 0x0F);
79+
name[4] = 'A' + ((descriptorSize >> 4) & 0x0F);
80+
return 5;
81+
}
82+
83+
void DynamicHID_::AppendDescriptor(DynamicHIDSubDescriptor *node)
84+
{
85+
if (!rootNode) {
86+
rootNode = node;
87+
} else {
88+
DynamicHIDSubDescriptor *current = rootNode;
89+
while (current->next) {
90+
current = current->next;
91+
}
92+
current->next = node;
93+
}
94+
descriptorSize += node->length;
95+
}
96+
97+
int DynamicHID_::SendReport(uint8_t id, const void* data, int len)
98+
{
99+
uint8_t p[len + 1];
100+
p[0] = id;
101+
memcpy(&p[1], data, len);
102+
return USB_Send(pluggedEndpoint | TRANSFER_RELEASE, p, len + 1);
103+
}
104+
105+
bool DynamicHID_::setup(USBSetup& setup)
106+
{
107+
if (pluggedInterface != setup.wIndex) {
108+
return false;
109+
}
110+
111+
uint8_t request = setup.bRequest;
112+
uint8_t requestType = setup.bmRequestType;
113+
114+
if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE)
115+
{
116+
if (request == DYNAMIC_HID_GET_REPORT) {
117+
// TODO: DYNAMIC_HID_GetReport();
118+
return true;
119+
}
120+
if (request == DYNAMIC_HID_GET_PROTOCOL) {
121+
// TODO: Send8(protocol);
122+
return true;
123+
}
124+
if (request == DYNAMIC_HID_GET_IDLE) {
125+
// TODO: Send8(idle);
126+
}
127+
}
128+
129+
if (requestType == REQUEST_HOSTTODEVICE_CLASS_INTERFACE)
130+
{
131+
if (request == DYNAMIC_HID_SET_PROTOCOL) {
132+
// The USB Host tells us if we are in boot or report mode.
133+
// This only works with a real boot compatible device.
134+
protocol = setup.wValueL;
135+
return true;
136+
}
137+
if (request == DYNAMIC_HID_SET_IDLE) {
138+
idle = setup.wValueL;
139+
return true;
140+
}
141+
if (request == DYNAMIC_HID_SET_REPORT)
142+
{
143+
//uint8_t reportID = setup.wValueL;
144+
//uint16_t length = setup.wLength;
145+
//uint8_t data[length];
146+
// Make sure to not read more data than USB_EP_SIZE.
147+
// You can read multiple times through a loop.
148+
// The first byte (may!) contain the reportID on a multreport.
149+
//USB_RecvControl(data, length);
150+
}
151+
}
152+
153+
return false;
154+
}
155+
156+
DynamicHID_::DynamicHID_(void) : PluggableUSBModule(1, 1, epType),
157+
rootNode(NULL), descriptorSize(0),
158+
protocol(DYNAMIC_HID_REPORT_PROTOCOL), idle(1)
159+
{
160+
epType[0] = EP_TYPE_INTERRUPT_IN;
161+
PluggableUSB().plug(this);
162+
}
163+
164+
int DynamicHID_::begin(void)
165+
{
166+
return 0;
167+
}
168+
169+
#endif /* if defined(USBCON) */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
Modified by Matthew Heironimus to support HID Report Descriptors to be in
3+
standard RAM in addition to program memory (PROGMEM).
4+
5+
Copyright (c) 2015, Arduino LLC
6+
Original code (pre-library): Copyright (c) 2011, Peter Barrett
7+
8+
Permission to use, copy, modify, and/or distribute this software for
9+
any purpose with or without fee is hereby granted, provided that the
10+
above copyright notice and this permission notice appear in all copies.
11+
12+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13+
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14+
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
15+
BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
16+
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17+
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
18+
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
19+
SOFTWARE.
20+
*/
21+
22+
#ifndef DYNAMIC_HID_h
23+
#define DYNAMIC_HID_h
24+
25+
#include <stdint.h>
26+
#include <Arduino.h>
27+
28+
#ifdef _VARIANT_ARDUINO_DUE_X_
29+
// The following values are the same as AVR's USBAPI.h
30+
// Reproduced here because SAM doesn't have these in
31+
// its own USBAPI.H
32+
#define USB_EP_SIZE 64
33+
#define TRANSFER_PGM 0x80
34+
35+
#include "USB/PluggableUSB.h"
36+
#else
37+
#include "PluggableUSB.h"
38+
#endif
39+
40+
#if defined(USBCON)
41+
42+
#define _USING_DYNAMIC_HID
43+
44+
// DYNAMIC_HID 'Driver'
45+
// ------------
46+
#define DYNAMIC_HID_GET_REPORT 0x01
47+
#define DYNAMIC_HID_GET_IDLE 0x02
48+
#define DYNAMIC_HID_GET_PROTOCOL 0x03
49+
#define DYNAMIC_HID_SET_REPORT 0x09
50+
#define DYNAMIC_HID_SET_IDLE 0x0A
51+
#define DYNAMIC_HID_SET_PROTOCOL 0x0B
52+
53+
#define DYNAMIC_HID_DESCRIPTOR_TYPE 0x21
54+
#define DYNAMIC_HID_REPORT_DESCRIPTOR_TYPE 0x22
55+
#define DYNAMIC_HID_PHYSICAL_DESCRIPTOR_TYPE 0x23
56+
57+
// HID subclass HID1.11 Page 8 4.2 Subclass
58+
#define DYNAMIC_HID_SUBCLASS_NONE 0
59+
#define DYNAMIC_HID_SUBCLASS_BOOT_INTERFACE 1
60+
61+
// HID Keyboard/Mouse bios compatible protocols HID1.11 Page 9 4.3 Protocols
62+
#define DYNAMIC_HID_PROTOCOL_NONE 0
63+
#define DYNAMIC_HID_PROTOCOL_KEYBOARD 1
64+
#define DYNAMIC_HID_PROTOCOL_MOUSE 2
65+
66+
// Normal or bios protocol (Keyboard/Mouse) HID1.11 Page 54 7.2.5 Get_Protocol Request
67+
// "protocol" variable is used for this purpose.
68+
#define DYNAMIC_HID_BOOT_PROTOCOL 0
69+
#define DYNAMIC_HID_REPORT_PROTOCOL 1
70+
71+
// HID Request Type HID1.11 Page 51 7.2.1 Get_Report Request
72+
#define DYNAMIC_HID_REPORT_TYPE_INPUT 1
73+
#define DYNAMIC_HID_REPORT_TYPE_OUTPUT 2
74+
#define DYNAMIC_HID_REPORT_TYPE_FEATURE 3
75+
76+
typedef struct
77+
{
78+
uint8_t len; // 9
79+
uint8_t dtype; // 0x21
80+
uint8_t addr;
81+
uint8_t versionL; // 0x101
82+
uint8_t versionH; // 0x101
83+
uint8_t country;
84+
uint8_t desctype; // 0x22 report
85+
uint8_t descLenL;
86+
uint8_t descLenH;
87+
} DYNAMIC_HIDDescDescriptor;
88+
89+
typedef struct
90+
{
91+
InterfaceDescriptor hid;
92+
DYNAMIC_HIDDescDescriptor desc;
93+
EndpointDescriptor in;
94+
} DYNAMIC_HIDDescriptor;
95+
96+
class DynamicHIDSubDescriptor {
97+
public:
98+
DynamicHIDSubDescriptor *next = NULL;
99+
DynamicHIDSubDescriptor(const void *d, const uint16_t l, const bool ipm = true) : data(d), length(l), inProgMem(ipm) { }
100+
101+
const void* data;
102+
const uint16_t length;
103+
const bool inProgMem;
104+
};
105+
106+
class DynamicHID_ : public PluggableUSBModule
107+
{
108+
public:
109+
DynamicHID_(void);
110+
int begin(void);
111+
int SendReport(uint8_t id, const void* data, int len);
112+
void AppendDescriptor(DynamicHIDSubDescriptor* node);
113+
114+
protected:
115+
// Implementation of the PluggableUSBModule
116+
int getInterface(uint8_t* interfaceCount);
117+
int getDescriptor(USBSetup& setup);
118+
bool setup(USBSetup& setup);
119+
uint8_t getShortName(char* name);
120+
121+
private:
122+
#ifdef _VARIANT_ARDUINO_DUE_X_
123+
uint32_t epType[1];
124+
#else
125+
uint8_t epType[1];
126+
#endif
127+
128+
DynamicHIDSubDescriptor* rootNode;
129+
uint16_t descriptorSize;
130+
131+
uint8_t protocol;
132+
uint8_t idle;
133+
};
134+
135+
// Replacement for global singleton.
136+
// This function prevents static-initialization-order-fiasco
137+
// https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use
138+
DynamicHID_& DynamicHID();
139+
140+
#define D_HIDREPORT(length) { 9, 0x21, 0x01, 0x01, 0, 1, 0x22, lowByte(length), highByte(length) }
141+
142+
#endif // USBCON
143+
144+
#endif // DYNAMIC_HID_h

0 commit comments

Comments
 (0)