Skip to content

Commit

Permalink
Merge pull request #868 from arpruss/master
Browse files Browse the repository at this point in the history
Update USBComposite library to 1.07
  • Loading branch information
stevstrong authored Nov 3, 2023
2 parents 9f32103 + 3f57bae commit 819ed8e
Show file tree
Hide file tree
Showing 25 changed files with 719 additions and 176 deletions.
1 change: 1 addition & 0 deletions STM32F1/libraries/USBComposite/HIDReports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ REPORT(Joystick, HID_JOYSTICK_REPORT_DESCRIPTOR());
REPORT(BootKeyboard, HID_BOOT_KEYBOARD_REPORT_DESCRIPTOR());
REPORT(Consumer, HID_CONSUMER_REPORT_DESCRIPTOR());
REPORT(Digitizer, HID_DIGITIZER_REPORT_DESCRIPTOR());
REPORT(SwitchController, HID_SWITCH_CONTROLLER_REPORT_DESCRIPTOR());
18 changes: 12 additions & 6 deletions STM32F1/libraries/USBComposite/Keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,13 @@ void HIDKeyboard::end(void) {
// shift -> 0x02
// modifiers: 128 --> bit shift

uint8_t HIDKeyboard::getKeyCode(uint8_t k, uint8_t* modifiersP)
uint8_t HIDKeyboard::getKeyCode(uint16_t k, uint8_t* modifiersP)
{
if (k & 0x8000u) {
// backwards compatibility in case a caller has passed a signed 8-bit value
k &= 0xFFu;
}

*modifiersP = 0;

if (adjustForHostCapsLock && (getLEDs() & 0x02)) { // capslock is down on host OS, so host will reverse
Expand All @@ -169,16 +174,17 @@ uint8_t HIDKeyboard::getKeyCode(uint8_t k, uint8_t* modifiersP)
}
return k;
}
if (k >= 0x88) { // non-printing key, Arduino format
return k - 0x88;
if (k >= KEY_HID_OFFSET) { // non-printing key, Arduino format
return k - KEY_HID_OFFSET;
}
else { // shift key
*modifiersP = 1<<(k-0x80);
return 0;

return k-0x80+0xE0;
}
}

size_t HIDKeyboard::press(uint8_t k) {
size_t HIDKeyboard::press(uint16_t k) {
uint8_t modifiers;

k = getKeyCode(k, &modifiers);
Expand Down Expand Up @@ -212,7 +218,7 @@ size_t HIDKeyboard::press(uint8_t k) {
// release() takes the specified key out of the persistent key report and
// sends the report. This tells the OS the key is no longer pressed and that
// it shouldn't be repeated any more.
size_t HIDKeyboard::release(uint8_t k)
size_t HIDKeyboard::release(uint16_t k)
{
uint8_t modifiers;
k = getKeyCode(k, &modifiers);
Expand Down
3 changes: 2 additions & 1 deletion STM32F1/libraries/USBComposite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ while(!USBComposite);
```

Finally, there are a number of classes that implement particular protocols for the `USBHID` class plugin.
These are:
These include:
```
HIDMouse
HIDKeyboard
HIDJoystick
HIDAbsMouse
HIDConsumer
HIDRaw<txSize,rxSize>
HIDSwitchController
```
And you can customize with more. Moreover, the `USBHID` plugin itself allows for compositing
multiple HID profiles, e.g., Mouse / Keyboard / three joysticks. Each of these has at least
Expand Down
2 changes: 1 addition & 1 deletion STM32F1/libraries/USBComposite/USBComposite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void USBCompositeDevice::setSerialString(const char* s) {
}

bool USBCompositeDevice::begin() {
if (enabled)
if (enabled)
return true;
for (uint32 i = 0 ; i < numParts ; i++) {
if (init[i] != NULL && !init[i](plugin[i]))
Expand Down
7 changes: 7 additions & 0 deletions STM32F1/libraries/USBComposite/USBCompositeSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <libmaple/usb.h>
#include <string.h>
#include <libmaple/iwdg.h>
#include <libmaple/bkp.h>

#include "usb_composite_serial.h"

Expand Down Expand Up @@ -239,6 +240,12 @@ static void rxHook(unsigned hook, void *ignored) {
}

// Got the magic sequence -> reset, presumably into the bootloader.
// Write 0x424C to backup register 0x0A to tell the bootloader to wait
bkp_init();
bkp_enable_writes();
bkp_write(0x0a,0x424c);
bkp_disable_writes();

// Return address is wait_reset, but we must set the thumb bit.
uintptr_t target = (uintptr_t)wait_reset | 0x1;
asm volatile("mov r0, %[stack_top] \n\t" // Reset stack
Expand Down
1 change: 1 addition & 0 deletions STM32F1/libraries/USBComposite/USBHID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ void HIDReporter::registerProfile(bool always) {
else {
reportChunks[0].data = reportDescriptor.descriptor;
reportChunks[0].dataLength = reportIDOffset;
reportID = reportDescriptor.descriptor[reportIDOffset];
reportChunks[1].data = &(reportID);
reportChunks[1].dataLength = 1;
reportChunks[2].data = reportDescriptor.descriptor+reportIDOffset+1;
Expand Down
Loading

0 comments on commit 819ed8e

Please sign in to comment.