Skip to content

Commit 42022d4

Browse files
Merge branch 'arpruss-master'
2 parents 97b9c44 + 2785a48 commit 42022d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+5359
-1294
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "USBComposite.h"
2+
3+
//================================================================================
4+
//================================================================================
5+
// Mouse
6+
7+
void HIDDigitizer::begin(void){
8+
}
9+
10+
void HIDDigitizer::end(void){
11+
}
12+
13+
void HIDDigitizer::move(uint16 x, uint16 y)
14+
{
15+
report.x = x;
16+
report.y = y;
17+
18+
sendReport();
19+
}
20+
21+
void HIDDigitizer::buttons(uint8_t b)
22+
{
23+
if (b != report.buttons)
24+
{
25+
report.buttons = b;
26+
sendReport();
27+
}
28+
}
29+
30+
void HIDDigitizer::click(uint8_t b)
31+
{
32+
press(b);
33+
release(b);
34+
}
35+
36+
void HIDDigitizer::press(uint8_t b)
37+
{
38+
buttons(report.buttons | b);
39+
}
40+
41+
void HIDDigitizer::release(uint8_t b)
42+
{
43+
buttons(report.buttons & ~b);
44+
}
45+
46+
bool HIDDigitizer::isPressed(uint8_t b)
47+
{
48+
if ((b & report.buttons) == b)
49+
return true;
50+
return false;
51+
}

STM32F1/libraries/USBComposite/HIDReports.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ REPORT(KeyboardMouseJoystick, HID_MOUSE_REPORT_DESCRIPTOR(), HID_KEYBOARD_REPORT
99
REPORT(KeyboardMouse, HID_MOUSE_REPORT_DESCRIPTOR(), HID_KEYBOARD_REPORT_DESCRIPTOR());
1010
REPORT(Keyboard, HID_KEYBOARD_REPORT_DESCRIPTOR());
1111
REPORT(Mouse, HID_MOUSE_REPORT_DESCRIPTOR());
12+
REPORT(AbsMouse, HID_ABS_MOUSE_REPORT_DESCRIPTOR());
1213
REPORT(KeyboardJoystick, HID_KEYBOARD_REPORT_DESCRIPTOR(), HID_JOYSTICK_REPORT_DESCRIPTOR());
1314
REPORT(Joystick, HID_JOYSTICK_REPORT_DESCRIPTOR());
1415
REPORT(BootKeyboard, HID_BOOT_KEYBOARD_REPORT_DESCRIPTOR());
16+
REPORT(Consumer, HID_CONSUMER_REPORT_DESCRIPTOR());
17+
REPORT(Digitizer, HID_DIGITIZER_REPORT_DESCRIPTOR());

STM32F1/libraries/USBComposite/MinSysex.c

-37
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#define STANDARD_ID_RESPONSE_LENGTH 7
4040

4141
#include "usb_midi_device.h"
42-
#include <libmaple/nvic.h>
4342
#include <libmaple/delay.h>
4443
#include <MinSysex.h>
4544
//#include <wirish/wirish.h>
@@ -129,12 +128,6 @@ volatile int sysexFinger=0;
129128
#define EXC_RETURN 0xFFFFFFF9
130129
#define DEFAULT_CPSR 0x61000000
131130
#define RESET_DELAY 100000
132-
#if 0
133-
static void wait_reset(void) {
134-
delay_us(RESET_DELAY);
135-
nvic_sys_reset();
136-
}
137-
#endif
138131

139132
/* -----------------------------------------------------------------------------dealWithItQuickly()
140133
* Note: at this point we have established that the sysex belongs to us.
@@ -154,36 +147,6 @@ void dealWithItQuickly(){
154147
}
155148
case USYSEX_REAL_TIME:
156149
break;
157-
#if 0
158-
case LEAFLABS_MMA_VENDOR_1:
159-
if (sysexBuffer[5]==LGL_RESET_CMD) {
160-
uintptr_t target = (uintptr_t)wait_reset | 0x1;
161-
asm volatile("mov r0, %[stack_top] \n\t" // Reset stack
162-
"mov sp, r0 \n\t"
163-
"mov r0, #1 \n\t"
164-
"mov r1, %[target_addr] \n\t"
165-
"mov r2, %[cpsr] \n\t"
166-
"push {r2} \n\t" // Fake xPSR
167-
"push {r1} \n\t" // PC target addr
168-
"push {r0} \n\t" // Fake LR
169-
"push {r0} \n\t" // Fake R12
170-
"push {r0} \n\t" // Fake R3
171-
"push {r0} \n\t" // Fake R2
172-
"push {r0} \n\t" // Fake R1
173-
"push {r0} \n\t" // Fake R0
174-
"mov lr, %[exc_return] \n\t"
175-
"bx lr"
176-
:
177-
: [stack_top] "r" (STACK_TOP),
178-
[target_addr] "r" (target),
179-
[exc_return] "r" (EXC_RETURN),
180-
[cpsr] "r" (DEFAULT_CPSR)
181-
: "r0", "r1", "r2");
182-
/* Can't happen. */
183-
ASSERT_FAULT(0);
184-
185-
}
186-
#endif
187150
default:
188151
break;
189152
}

STM32F1/libraries/USBComposite/README.md

+66-18
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
# USB Composite library for STM32F1
1+
# USB Composite library for Roger's Melbourne's STM32F1 core: https://github.com/rogerclarkmelbourne/Arduino_STM32/
22

33
## Protocols supported
44

55
- standard USB HID, with many built-in profiles, and customizable with more
66

77
- MIDI over USB
88

9-
- XBox360 controller (only controller-to-host is currently supported)
9+
- XBox360 wired/wireless controllers
1010

1111
- Mass storage
1212

13+
- USB Audio (unidirectional, but both directions are supported)
14+
1315
## Basic concepts
1416

1517
Start with:
@@ -30,12 +32,16 @@ Plugin classes included in the library:
3032
```
3133
USBHID
3234
USBMIDI
33-
USBXBox360
35+
USBMultiXBox360<n> / USBXBox360 / USBXBox360W<n>
3436
USBMassStorage
3537
USBCompositeSerial
38+
USBMultiSerial<n>
3639
```
3740

38-
To use them, you need to create instances of them. Currently, only one instance of each plugin class
41+
**NOTE:** Only one of USBMultiXBox360<n> / USBXBox360 / USBXBox360W<n> can be registered at a time:
42+
they cannot be composited together.
43+
44+
To use the plugins, you need to create instances of them. NOTE: Only one instance of each plugin class
3945
can be created.
4046

4147
If you want to make a simple (non-composite) USB device, you can create an instance of the plugin class
@@ -50,9 +56,15 @@ plugin2.registerComponent();
5056
USBComposite.begin();
5157
```
5258

53-
Of course, you may need to do some further configuring of the plugins or the `USBComposite` device
59+
Of course, you may need to do some further configuring of the plugins (e.g., if plugin1 is USBHID, then
60+
you may want to do `USBHID.setReportDescriptor(HID_KEYBOARD)`) or of the `USBComposite` device
5461
before the `USBComposite.begin()` call.
5562

63+
After starting up USBComposite, it's a good idea to wait for it to become ready before sending any data:
64+
```
65+
while(!USBComposite);
66+
```
67+
5668
Finally, there are a number of classes that implement particular protocols for the `USBHID` class plugin.
5769
These are:
5870
```
@@ -73,6 +85,19 @@ combinations will be supported by all operating systems.
7385
I recommend calling `USBComposite.setDeviceId(device)` with a different device number for each combination
7486
of plugins and profiles to prevent problems with cached configurations on the host computer.
7587

88+
## Uploading with STM32duino bootloader
89+
90+
Normally, the STM32duino bootloader upload method in the Roger Melbourne STM32F1 core sends a command
91+
to reset the board via the USB serial port, and thereby put it in bootloader mode, just prior to uploading.
92+
If you have installed a sketch that includes a USB serial port in the composite device, this should still
93+
work. But if the sketch you've installed doesn't include a USB serial port, then you need to manually activate
94+
the bootloader mode next time you want to upload a sketch.
95+
96+
The bootloader mode is active for a short period after the board powers up or resets. So just initiate
97+
the upload in the Arduino IDE as usual, but when "Searching for DFU device [1EAF:0003]" is displayed,
98+
hit the reset button (or if the device is USB-powered, keep it unplugged from USB and plug it in when you
99+
get this message).
100+
76101
## Simple USB device configuration
77102

78103
A simple USB device uses a single plugin. You need to create an instance of the plugin class,
@@ -83,21 +108,37 @@ to inject keyboard data, you should do:
83108
USBHID HID; // create instance of USBHID plugin
84109
HIDKeyboard Keyboard(HID); // create a profile
85110
86-
HID.begin(HID_KEYBOARD);
111+
HID.begin();
87112
```
88113

89114
and then call `Keyboard.print("TextToInject")` to inject keyboard data. Some plugin configurations
90115
may require further initialization code or further code that needs to be called inside the Arduino
91116
`loop()` function.
92117

93-
See the `BootKeyboard`, `midiout` and `x360` example code for this procedure.
118+
See the `BootKeyboard`, `midiout` and `x360` example code for variants on this procedure.
94119

95120
(Additionally, the `USBHID` plugin has a convenience `begin()` method that lets you include an
96121
instance of a `USBCompositeSerial` plugin class, and that creates a composite HID-Serial device.)
97122

98123
However, if you want a USB device using more than one plugin, then you will NOT call the plugin's
99124
`begin()` method.
100125

126+
Note that a single HID plugin can support a device with multiple report profiles including a keyboard, several joysticks,
127+
a mouse, etc.:
128+
```
129+
USBHID HID; // create instance of USBHID plugin
130+
HIDKeyboard Keyboard(HID); // create a profile
131+
HIDJoystick Joystick1(HID); // create a profile
132+
HIDJoystick Joystick2(HID); // create a profile
133+
HIDMouse Mouse(HID); // create a profile
134+
135+
HID.begin();
136+
```
137+
138+
Each of the profiles (e.g., Joystick1) contributes a part of the HID report descriptor to USBHID which automatically stitches
139+
them together and assigns report IDs. However, you can also make a single overarching custom HID report descriptor and include
140+
it in the HID.begin() call. The `softjoystick` example does this.
141+
101142
## Memory limitations
102143

103144
There are 320 bytes of hardware buffer memory available after endpoint 0 is taken into account. The following
@@ -132,25 +173,32 @@ MIDI.setTXPacketSize(size);
132173
```
133174
The maximum and default packet size is 64. Smaller packet sizes have not been thoroughly tested and may slow things down. In
134175
particular, for HID you should make sure your packet size is sufficient for your largest HID report. The CompositeSerial
135-
device also has a control channel whose 16 byte packet size is not adjustable.
176+
device also has a control channel whose 16 byte packet size is not adjustable. Note that for reasons that I do not currently
177+
understand, CompositeSerial RX packets must be a power of two in size.
136178

137-
Note that in the above, RX and TX are from the point of view of the MCU, not the host (i.e., RX corresponds to USB Out and TX
179+
Note also that in the above, RX and TX are from the point of view of the MCU, not the host (i.e., RX corresponds to USB Out and TX
138180
to USB In).
139181

140182
## Endpoint limitations
141183

142-
There is one bidirectional endpoint 0 that all endpoints share, and the hardware allows for seven more. Here are
143-
how many endpoints besides endpoint 0 are needed for each plugin:
184+
There is one bidirectional endpoint 0 that all endpoints share, and the hardware allows for seven more in each direction,
185+
but there are some complications in that the same endpoint number when used in different directions must have some
186+
of the same parameters. The USBComposite library takes care of these complications when allocating endpoints, but if you
187+
have too many plugins, you USBComposite.begin() will return `false` to indicate that you've used up too many.
188+
189+
This is pretty complicated, but a rule of thumb for having enough endpoints is to make sure that when you add up the
190+
following contributions for the plugins you use, your total is at most seven.
191+
192+
* USB Serial: 2 (= 2 TX, 1 RX)
144193

145-
* USB Serial: 3
194+
* USB HID: 1 (= 1 TX)
146195

147-
* USB HID: 1
196+
* USB Mass Storage: 1 (= 1 TX, 1 RX)
148197

149-
* USB Mass Storage: 2
198+
* USB MIDI: 1 (= 1 TX, 1 RX)
150199

151-
* USB MIDI: 2
200+
* XBox360 Controller: 1 per controller (= 1 TX, 1 RX)
152201

153-
* XBox360 Controller: 2
202+
* USB Audio: 1 (= 1 TX or 1 RX depending on mode)
154203

155-
When combining plugins, make sure the count of these endpoints does not exceed 7. For instance, USB Serial + USB Mass Storage +
156-
USB MIDI + USB HID adds up to 8, which is too much.
204+
* USB Multi Serial: 2 per port (= 2 TX, 1 RX)
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
Version 0.90 of the library has changed the API significantly in order to save flash and RAM.
2-
The main change is that other than USBComposite, all pre-declared object instances have been
3-
removed.
4-
5-
When upgrading to 0.90 or higher, you will have to make a number of changes to your code.
6-
7-
1. Use a single include file instead of USBHID.h, USBMIDI.h, etc.:
8-
#include <USBComposite.h>
9-
10-
2. Declare all instances other than USBComposite. This includes instances of plugin classes
11-
like USBHID as well as of HID profiles like HIDKeyboard (which need an instance of USBHID).
12-
13-
3. Note that USBHID is now a class (for consistency with other class names) and there is no
14-
USBHID instance. You need to declare an instance, e.g.:
15-
USBHID HID;
16-
and replace calls to USBHID.* with calls to HID.*.
17-
18-
4. Replace USBHID_begin_with_serial(...) with HID.begin(CompositeSerial,...) where HID is your
1+
Version 0.90 of the library has changed the API significantly in order to save flash and RAM.
2+
The main change is that other than USBComposite, all pre-declared object instances have been
3+
removed.
4+
5+
When upgrading to 0.90 or higher, you will have to make a number of changes to your code.
6+
7+
1. Use a single include file instead of USBHID.h, USBMIDI.h, etc.:
8+
#include <USBComposite.h>
9+
10+
2. Declare all instances other than USBComposite. This includes instances of plugin classes
11+
like USBHID as well as of HID profiles like HIDKeyboard (which need an instance of USBHID).
12+
13+
3. Note that USBHID is now a class (for consistency with other class names) and there is no
14+
USBHID instance. You need to declare an instance, e.g.:
15+
USBHID HID;
16+
and replace calls to USBHID.* with calls to HID.*.
17+
18+
4. Replace USBHID_begin_with_serial(...) with HID.begin(CompositeSerial,...) where HID is your
1919
instance of USBHID.

0 commit comments

Comments
 (0)