add USBDevice setVersion(), update cdc for new tinyusb peek

This commit is contained in:
hathach committed 2019-07-31 20:32:43 +07:00
1 parent 5f5ac5871f
commit ebd624c7c0
4 files changed
+20 -15

No files matched your search

@@ -91,7 +91,8 @@ int Adafruit_USBD_CDC::available(void)
int Adafruit_USBD_CDC::peek(void)
{
return tud_cdc_peek(0);
uint8_t ch;
return tud_cdc_peek(0, &ch) ? (int) ch : -1;
}
int Adafruit_USBD_CDC::read(void)
@@ -41,16 +41,17 @@ public:
void begin(uint32_t baud, uint8_t config);
void end(void);
virtual int available(void);
virtual int peek(void);
virtual int read(void);
virtual void flush(void);
virtual int available(void);
virtual int peek(void);
virtual int read(void);
virtual void flush(void);
virtual size_t write(uint8_t);
virtual size_t write(const uint8_t *buffer, size_t size);
size_t write(const char *buffer, size_t size) {
return write((const uint8_t *)buffer, size);
}
size_t availableForWrite(void);
size_t availableForWrite(void);
operator bool();
};
@@ -40,7 +40,7 @@ Adafruit_USBD_Device USBDevice;
Adafruit_USBD_Device::Adafruit_USBD_Device(void)
{
tusb_desc_device_t desc_dev =
tusb_desc_device_t const desc_dev =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -57,17 +57,15 @@ Adafruit_USBD_Device::Adafruit_USBD_Device(void)
.idVendor = 0,
.idProduct = 0,
.bcdDevice = 0x0100,
.iManufacturer = 0x01,
.iProduct = 0x02,
.iSerialNumber = 0x03,
.bNumConfigurations = 0x01
};
_desc_device = desc_dev;
tusb_desc_configuration_t dev_cfg =
tusb_desc_configuration_t const dev_cfg =
{
.bLength = sizeof(tusb_desc_configuration_t),
.bDescriptorType = TUSB_DESC_CONFIGURATION,
@@ -75,7 +73,6 @@ Adafruit_USBD_Device::Adafruit_USBD_Device(void)
// Total Length & Interface Number will be updated later
.wTotalLength = 0,
.bNumInterfaces = 0,
.bConfigurationValue = 1,
.iConfiguration = 0x00,
.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)
_desc_device.idProduct = pid;
}
void Adafruit_USBD_Device::setVersion(uint16_t bcd)
{
_desc_device.bcdUSB = bcd;
}
bool Adafruit_USBD_Device::begin(void)
{
return true;
@@ -52,12 +52,13 @@ class Adafruit_USBD_Device
bool addInterface(Adafruit_USBD_Interface& itf);
void setID(uint16_t vid, uint16_t pid);
void setVersion(uint16_t bcd);
bool begin(void);
bool mounted(void) { return tud_mounted(); }
bool suspended(void) { return tud_suspended(); }
bool ready(void) { return tud_ready(); }
bool remoteWakeup(void) { return tud_remote_wakeup(); }
bool mounted (void) { return tud_mounted(); }
bool suspended (void) { return tud_suspended(); }
bool ready (void) { return tud_ready(); }
bool remoteWakeup (void) { return tud_remote_wakeup(); }
friend uint8_t const * tud_descriptor_device_cb(void);
friend uint8_t const * tud_descriptor_configuration_cb(uint8_t index);