Skip to content

Commit

Permalink
update USBComposite to 1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
arpruss committed Jan 4, 2023
1 parent dc35dd5 commit 3f57bae
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 79 deletions.
3 changes: 2 additions & 1 deletion STM32F1/libraries/USBComposite/Keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ uint8_t HIDKeyboard::getKeyCode(uint16_t k, uint8_t* modifiersP)
}
else { // shift key
*modifiersP = 1<<(k-0x80);
return 0;

return k-0x80+0xE0;
}
}

Expand Down
40 changes: 39 additions & 1 deletion STM32F1/libraries/USBComposite/USBHID.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ class USBHID {
bool autoRegister = true;
bool enabledHID = false;
uint32 txPacketSize = 64;
struct usb_chunk* chunkList;
struct usb_chunk* chunkList = nullptr;
// baseChunk holds any explicitly specified report descriptor that
// overrides any report descriptors from the chain of registered profiles
struct usb_chunk baseChunk = { 0, 0, 0 };
Expand Down Expand Up @@ -449,6 +449,12 @@ class USBHID {
USBHID(bool _autoRegister=true) {
autoRegister = _autoRegister;
}
void setTXInterval(uint8 t) {
usb_hid_setTXInterval(t);
}
void setRXInterval(uint8 t) {
usb_hid_setRXInterval(t);
}
};

class HIDReporter {
Expand Down Expand Up @@ -650,6 +656,38 @@ class HIDConsumer : public HIDReporter {
#define KEY_F10 0xCB
#define KEY_F11 0xCC
#define KEY_F12 0xCD
#define KEY_F13 (KEY_HID_OFFSET+0x68)
#define KEY_F14 (KEY_HID_OFFSET+0x69)
#define KEY_F15 (KEY_HID_OFFSET+0x6A)
#define KEY_KP_DOT (KEY_HID_OFFSET+0x63)
#define KEY_KP_ASTERISK (KEY_HID_OFFSET+0x55)
#define KEY_KP_PLUS (KEY_HID_OFFSET+0x57)
#define KEY_NUM_LOCK (KEY_HID_OFFSET+0x53)
#define KEY_KP_SLASH (KEY_HID_OFFSET+0x54)
#define KEY_KP_ENTER (KEY_HID_OFFSET+0x58)
#define KEY_KP_MINUS (KEY_HID_OFFSET+0x56)
#define KEY_KP_EQUAL (KEY_HID_OFFSET+0x86)
#define KEY_KP_0 (KEY_HID_OFFSET+0x62)
#define KEY_KP_1 (KEY_HID_OFFSET+0x59)
#define KEY_KP_2 (KEY_HID_OFFSET+0x5a)
#define KEY_KP_3 (KEY_HID_OFFSET+0x5b)
#define KEY_KP_4 (KEY_HID_OFFSET+0x5c)
#define KEY_KP_5 (KEY_HID_OFFSET+0x5d)
#define KEY_KP_6 (KEY_HID_OFFSET+0x5e)
#define KEY_KP_7 (KEY_HID_OFFSET+0x5f)
#define KEY_KP_8 (KEY_HID_OFFSET+0x60)
#define KEY_KP_9 (KEY_HID_OFFSET+0x61)
#define KEY_VOLUME_UP (KEY_HID_OFFSET+0x80)
#define KEY_VOLUME_DOWN (KEY_HID_OFFSET+0x81)
#define KEY_MUTE (KEY_HID_OFFSET+0x7f)
#define KEY_HELP (KEY_HID_OFFSET+0x75)
#define KEY_POWER (KEY_HID_OFFSET+0x66)
#define KEY_102ND (KEY_HID_OFFSET+0x64)
#define KEY_PRINT_SCREEN (KEY_HID_OFFSET+0x46)
#define KEY_SCROLL_LOCK (KEY_HID_OFFSET+0x47)
#define KEY_PAUSE (KEY_HID_OFFSET+0x48)



typedef struct{
uint8_t reportID;
Expand Down
2 changes: 1 addition & 1 deletion STM32F1/libraries/USBComposite/examples/mass/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ uint8 image[11776] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xF8,0xFF,0xFF,
};
};
139 changes: 69 additions & 70 deletions STM32F1/libraries/USBComposite/examples/mass/mass.ino
Original file line number Diff line number Diff line change
@@ -1,71 +1,70 @@
#include <USBComposite.h>

USBMassStorage MassStorage;
USBCompositeSerial CompositeSerial;

#define PRODUCT_ID 0x29

#include "image.h"

bool write(const uint8_t *writebuff, uint32_t memoryOffset, uint16_t transferLength) {
memcpy(image+SCSI_BLOCK_SIZE*memoryOffset, writebuff, SCSI_BLOCK_SIZE*transferLength);

return true;
}

bool read(uint8_t *readbuff, uint32_t memoryOffset, uint16_t transferLength) {
memcpy(readbuff, image+SCSI_BLOCK_SIZE*memoryOffset, SCSI_BLOCK_SIZE*transferLength);

return true;
}

char hexNibble(uint8 x) {
return x < 10 ? x + '0' : x + 'A' - 10;
}

char* format16(uint16 c) {
static char str[6];
str[5] = 0;
char *p = str+5;
do {
*--p = (c % 10) + '0';
c /= 10;
} while(c);
return p;
}

void dumpDrive() {
char hex[7] = "0x11,";
CompositeSerial.print("uint8 image[");
CompositeSerial.print(format16(sizeof(image)));
CompositeSerial.println("] = {");
int last;
for (last=sizeof(image)-1;last>=0 && image[last] == 0;last--);
if (last<0) last=0;

for (int i=0; i<=last; i++) {
if (i && i % 16 == 0)
CompositeSerial.println("");
hex[2] = hexNibble(image[i]>>4);
hex[3] = hexNibble(image[i]&0xF);
CompositeSerial.print(hex);
}
CompositeSerial.println("\n};\n");
}

void setup() {
USBComposite.setProductId(PRODUCT_ID);
MassStorage.setDriveData(0, sizeof(image)/SCSI_BLOCK_SIZE, read, write);
MassStorage.registerComponent();
CompositeSerial.registerComponent();
USBComposite.begin();
delay(2000);
}

void loop() {
MassStorage.loop();
if (CompositeSerial.available() && 'd' == CompositeSerial.read()) {
dumpDrive();
}
}
#include <USBComposite.h>

USBMassStorage MassStorage;
USBCompositeSerial CompositeSerial;

#define PRODUCT_ID 0x29

#include "image.h"

bool write(const uint8_t *writebuff, uint32_t memoryOffset, uint16_t transferLength) {
memcpy(image+SCSI_BLOCK_SIZE*memoryOffset, writebuff, SCSI_BLOCK_SIZE*transferLength);

return true;
}

bool read(uint8_t *readbuff, uint32_t memoryOffset, uint16_t transferLength) {
memcpy(readbuff, image+SCSI_BLOCK_SIZE*memoryOffset, SCSI_BLOCK_SIZE*transferLength);

return true;
}

char hexNibble(uint8 x) {
return x < 10 ? x + '0' : x + 'A' - 10;
}

char* format16(uint16 c) {
static char str[6];
str[5] = 0;
char *p = str+5;
do {
*--p = (c % 10) + '0';
c /= 10;
} while(c);
return p;
}

void dumpDrive() {
char hex[7] = "0x11,";
CompositeSerial.print("uint8 image[");
CompositeSerial.print(format16(sizeof(image)));
CompositeSerial.println("] = {");
int last;
for (last=sizeof(image)-1;last>=0 && image[last] == 0;last--);
if (last<0) last=0;

for (int i=0; i<=last; i++) {
if (i && i % 16 == 0)
CompositeSerial.println("");
hex[2] = hexNibble(image[i]>>4);
hex[3] = hexNibble(image[i]&0xF);
CompositeSerial.print(hex);
}
CompositeSerial.println("\n};\n");
}

void setup() {
USBComposite.setProductId(PRODUCT_ID);
MassStorage.setDriveData(0, sizeof(image)/SCSI_BLOCK_SIZE, read, write);
MassStorage.registerComponent();
CompositeSerial.registerComponent();
USBComposite.begin();
delay(2000);
}

void loop() {
MassStorage.loop();
if (CompositeSerial.available() && 'd' == CompositeSerial.read()) {
dumpDrive();
}
}
2 changes: 1 addition & 1 deletion STM32F1/libraries/USBComposite/library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=USBComposite for STM32F1
version=1.06
version=1.0.8
author=Various
email=arpruss@gmail.com
sentence=USB HID / MIDI / mass storage / Audio library for STM32F1
Expand Down
21 changes: 17 additions & 4 deletions STM32F1/libraries/USBComposite/usb_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ static uint8 IdleValue = 1;
static uint8 ProtocolValue = 0;
static uint32 txEPSize = 64;
static uint32 rxEPSize = 64;
static uint8 txInterval = 0x0A;
static uint8 rxInterval = 0x0A;
static volatile int8 transmitting;
static struct usb_chunk* reportDescriptorChunks = NULL;

Expand Down Expand Up @@ -121,15 +123,15 @@ static const hid_part_config hidPartConfigData = {
.bEndpointAddress = USB_DESCRIPTOR_ENDPOINT_IN | 0, // PATCH: USB_HID_TX_ENDP
.bmAttributes = USB_EP_TYPE_INTERRUPT,
.wMaxPacketSize = 64, //PATCH
.bInterval = 0x0A,
.bInterval = 0x0A, //PATCH
},
.HIDDataOutEndpoint = {
.bLength = sizeof(usb_descriptor_endpoint),
.bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT,
.bEndpointAddress = USB_DESCRIPTOR_ENDPOINT_OUT | 0, // PATCH: USB_HID_RX_ENDP
.bmAttributes = USB_EP_TYPE_INTERRUPT,
.wMaxPacketSize = 64, //PATCH
.bInterval = 0x0A,
.bInterval = 0x0A, //PATCH
},
};

Expand All @@ -141,6 +143,14 @@ static ONE_DESCRIPTOR HID_Hid_Descriptor = {
sizeof(hidPartConfigData.HID_Descriptor)
};

void usb_hid_setTXInterval(uint8_t t) {
txInterval = t;
}

void usb_hid_setRXInterval(uint8_t t) {
rxInterval = t;
}

static USBEndpointInfo hidEndpoints[2] = {
{
.callback = hidDataTxCb,
Expand Down Expand Up @@ -176,9 +186,12 @@ static void getHIDPartDescriptor(uint8* out) {
OUT_BYTE(hidPartConfigData, HID_Descriptor.descLenL) = (uint8)size;
OUT_BYTE(hidPartConfigData, HID_Descriptor.descLenH) = (uint8)(size>>8);
OUT_16(hidPartConfigData, HIDDataInEndpoint.wMaxPacketSize) = txEPSize;
OUT_16(hidPartConfigData, HIDDataOutEndpoint.wMaxPacketSize) = rxEPSize;
if (numEndpoints > 1)
OUT_BYTE(hidPartConfigData, HIDDataInEndpoint.bInterval) = txInterval;
if (numEndpoints > 1) {
OUT_BYTE(hidPartConfigData, HIDDataOutEndpoint.bEndpointAddress) += USB_HID_RX_ENDP;
OUT_BYTE(hidPartConfigData, HIDDataOutEndpoint.bInterval) = rxInterval;
OUT_16(hidPartConfigData, HIDDataOutEndpoint.wMaxPacketSize) = rxEPSize;
}
}

USBCompositePart usbHIDPart = {
Expand Down
3 changes: 2 additions & 1 deletion STM32F1/libraries/USBComposite/usb_hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ void usb_hid_set_feature(uint8_t reportID, uint8_t* data);
void usb_hid_setTXEPSize(uint32_t size);
uint32 usb_hid_get_pending(void);
void usb_hid_setDedicatedRXEndpoint(void* buffer, uint16_t size, USBHIDOutputEndpointReceiver receiver, void* extra);
void usb_hid_setTXInterval(uint8_t t);
void usb_hid_setRXInterval(uint8_t t);

/*
* HID Requests
Expand Down Expand Up @@ -138,7 +140,6 @@ typedef struct

uint32 usb_hid_tx(const uint8* buf, uint32 len);
uint32 usb_hid_tx_mod(const uint8* buf, uint32 len);

uint32 usb_hid_data_available(void); /* in RX buffer */


Expand Down

0 comments on commit 3f57bae

Please sign in to comment.