Skip to content

Commit ebd624c

Browse files
committed
add USBDevice setVersion(), update cdc for new tinyusb peek
1 parent 5f5ac58 commit ebd624c

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ int Adafruit_USBD_CDC::available(void)
9191

9292
int Adafruit_USBD_CDC::peek(void)
9393
{
94-
return tud_cdc_peek(0);
94+
uint8_t ch;
95+
return tud_cdc_peek(0, &ch) ? (int) ch : -1;
9596
}
9697

9798
int Adafruit_USBD_CDC::read(void)

cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,17 @@ class Adafruit_USBD_CDC : public Stream, Adafruit_USBD_Interface
4141
void begin(uint32_t baud, uint8_t config);
4242
void end(void);
4343

44-
virtual int available(void);
45-
virtual int peek(void);
46-
virtual int read(void);
47-
virtual void flush(void);
44+
virtual int available(void);
45+
virtual int peek(void);
46+
virtual int read(void);
47+
virtual void flush(void);
4848
virtual size_t write(uint8_t);
49+
4950
virtual size_t write(const uint8_t *buffer, size_t size);
5051
size_t write(const char *buffer, size_t size) {
5152
return write((const uint8_t *)buffer, size);
5253
}
53-
size_t availableForWrite(void);
54+
size_t availableForWrite(void);
5455
operator bool();
5556
};
5657

cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_Device.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Adafruit_USBD_Device USBDevice;
4040

4141
Adafruit_USBD_Device::Adafruit_USBD_Device(void)
4242
{
43-
tusb_desc_device_t desc_dev =
43+
tusb_desc_device_t const desc_dev =
4444
{
4545
.bLength = sizeof(tusb_desc_device_t),
4646
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -57,25 +57,22 @@ Adafruit_USBD_Device::Adafruit_USBD_Device(void)
5757
.idVendor = 0,
5858
.idProduct = 0,
5959
.bcdDevice = 0x0100,
60-
6160
.iManufacturer = 0x01,
6261
.iProduct = 0x02,
6362
.iSerialNumber = 0x03,
64-
6563
.bNumConfigurations = 0x01
6664
};
6765

6866
_desc_device = desc_dev;
6967

70-
tusb_desc_configuration_t dev_cfg =
68+
tusb_desc_configuration_t const dev_cfg =
7169
{
7270
.bLength = sizeof(tusb_desc_configuration_t),
7371
.bDescriptorType = TUSB_DESC_CONFIGURATION,
7472

7573
// Total Length & Interface Number will be updated later
7674
.wTotalLength = 0,
7775
.bNumInterfaces = 0,
78-
7976
.bConfigurationValue = 1,
8077
.iConfiguration = 0x00,
8178
.bmAttributes = TU_BIT(7) | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP,
@@ -132,6 +129,11 @@ void Adafruit_USBD_Device::setID(uint16_t vid, uint16_t pid)
132129
_desc_device.idProduct = pid;
133130
}
134131

132+
void Adafruit_USBD_Device::setVersion(uint16_t bcd)
133+
{
134+
_desc_device.bcdUSB = bcd;
135+
}
136+
135137
bool Adafruit_USBD_Device::begin(void)
136138
{
137139
return true;

cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_Device.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ class Adafruit_USBD_Device
5252
bool addInterface(Adafruit_USBD_Interface& itf);
5353

5454
void setID(uint16_t vid, uint16_t pid);
55+
void setVersion(uint16_t bcd);
5556
bool begin(void);
5657

57-
bool mounted(void) { return tud_mounted(); }
58-
bool suspended(void) { return tud_suspended(); }
59-
bool ready(void) { return tud_ready(); }
60-
bool remoteWakeup(void) { return tud_remote_wakeup(); }
58+
bool mounted (void) { return tud_mounted(); }
59+
bool suspended (void) { return tud_suspended(); }
60+
bool ready (void) { return tud_ready(); }
61+
bool remoteWakeup (void) { return tud_remote_wakeup(); }
6162

6263
friend uint8_t const * tud_descriptor_device_cb(void);
6364
friend uint8_t const * tud_descriptor_configuration_cb(uint8_t index);

0 commit comments

Comments
 (0)