aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino
diff options
context:
space:
mode:
authorDavid Madison <dmadison@users.noreply.github.com>2019-02-15 14:44:45 -0500
committerDavid Madison <dmadison@users.noreply.github.com>2019-02-17 17:06:52 -0500
commit3364c6f736a77e60f26273af0bb021f4507dd1b9 (patch)
tree9b94c85506ed829a0deede10f9cdd220bf888699 /cores/arduino
parent2307486942f246aca947d770849b5d05822d7d17 (diff)
Removed USB CDC Serial
This will compile but will NOT enumerate properly without a config descriptor. You've been warned...
Diffstat (limited to 'cores/arduino')
-rw-r--r--cores/arduino/CDC.cpp143
-rw-r--r--cores/arduino/USBAPI.h17
-rw-r--r--cores/arduino/USBCore.cpp54
-rw-r--r--cores/arduino/USBCore.h107
-rw-r--r--cores/arduino/USBDesc.h17
5 files changed, 7 insertions, 331 deletions
diff --git a/cores/arduino/CDC.cpp b/cores/arduino/CDC.cpp
index 9fea948..a6bce17 100644
--- a/cores/arduino/CDC.cpp
+++ b/cores/arduino/CDC.cpp
@@ -17,152 +17,9 @@
*/
#include "USBAPI.h"
-#include <avr/wdt.h>
-#include <util/atomic.h>
#if defined(USBCON)
-typedef struct
-{
- u32 dwDTERate;
- u8 bCharFormat;
- u8 bParityType;
- u8 bDataBits;
- u8 lineState;
-} LineInfo;
-
-static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
-static volatile int32_t breakValue = -1;
-
-static u8 wdtcsr_save;
-
-#define WEAK __attribute__ ((weak))
-
-extern const CDCDescriptor _cdcInterface PROGMEM;
-const CDCDescriptor _cdcInterface =
-{
- D_IAD(0,2,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,1),
-
- // CDC communication interface
- D_INTERFACE(CDC_ACM_INTERFACE,1,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,0),
- D_CDCCS(CDC_HEADER,0x10,0x01), // Header (1.10 bcd)
- D_CDCCS(CDC_CALL_MANAGEMENT,1,1), // Device handles call management (not)
- D_CDCCS4(CDC_ABSTRACT_CONTROL_MANAGEMENT,6), // SET_LINE_CODING, GET_LINE_CODING, SET_CONTROL_LINE_STATE supported
- D_CDCCS(CDC_UNION,CDC_ACM_INTERFACE,CDC_DATA_INTERFACE), // Communication interface is master, data interface is slave 0
- D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_ACM),USB_ENDPOINT_TYPE_INTERRUPT,0x10,0x40),
-
- // CDC data interface
- D_INTERFACE(CDC_DATA_INTERFACE,2,CDC_DATA_INTERFACE_CLASS,0,0),
- D_ENDPOINT(USB_ENDPOINT_OUT(CDC_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,USB_EP_SIZE,0),
- D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE_BULK,USB_EP_SIZE,0)
-};
-
-bool isLUFAbootloader()
-{
- return pgm_read_word(FLASHEND - 1) == NEW_LUFA_SIGNATURE;
-}
-
-int CDC_GetInterface(u8* interfaceNum)
-{
- interfaceNum[0] += 2; // uses 2
- return USB_SendControl(TRANSFER_PGM,&_cdcInterface,sizeof(_cdcInterface));
-}
-
-bool CDC_Setup(USBSetup& setup)
-{
- u8 r = setup.bRequest;
- u8 requestType = setup.bmRequestType;
-
- if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType)
- {
- if (CDC_GET_LINE_CODING == r)
- {
- USB_SendControl(0,(void*)&_usbLineInfo,7);
- return true;
- }
- }
-
- if (REQUEST_HOSTTODEVICE_CLASS_INTERFACE == requestType)
- {
- if (CDC_SEND_BREAK == r)
- {
- breakValue = ((uint16_t)setup.wValueH << 8) | setup.wValueL;
- }
-
- if (CDC_SET_LINE_CODING == r)
- {
- USB_RecvControl((void*)&_usbLineInfo,7);
- }
-
- if (CDC_SET_CONTROL_LINE_STATE == r)
- {
- _usbLineInfo.lineState = setup.wValueL;
-
- // auto-reset into the bootloader is triggered when the port, already
- // open at 1200 bps, is closed. this is the signal to start the watchdog
- // with a relatively long period so it can finish housekeeping tasks
- // like servicing endpoints before the sketch ends
-
- uint16_t magic_key_pos = MAGIC_KEY_POS;
-
-// If we don't use the new RAMEND directly, check manually if we have a newer bootloader.
-// This is used to keep compatible with the old leonardo bootloaders.
-// You are still able to set the magic key position manually to RAMEND-1 to save a few bytes for this check.
-#if MAGIC_KEY_POS != (RAMEND-1)
- // For future boards save the key in the inproblematic RAMEND
- // Which is reserved for the main() return value (which will never return)
- if (isLUFAbootloader()) {
- // horray, we got a new bootloader!
- magic_key_pos = (RAMEND-1);
- }
-#endif
-
- // We check DTR state to determine if host port is open (bit 0 of lineState).
- if (1200 == _usbLineInfo.dwDTERate && (_usbLineInfo.lineState & 0x01) == 0)
- {
-#if MAGIC_KEY_POS != (RAMEND-1)
- // Backup ram value if its not a newer bootloader and it hasn't already been saved.
- // This should avoid memory corruption at least a bit, not fully
- if (magic_key_pos != (RAMEND-1) && *(uint16_t *)magic_key_pos != MAGIC_KEY) {
- *(uint16_t *)(RAMEND-1) = *(uint16_t *)magic_key_pos;
- }
-#endif
- // Store boot key
- *(uint16_t *)magic_key_pos = MAGIC_KEY;
- // Save the watchdog state in case the reset is aborted.
- wdtcsr_save = WDTCSR;
- wdt_enable(WDTO_120MS);
- }
- else if (*(uint16_t *)magic_key_pos == MAGIC_KEY)
- {
- // Most OSs do some intermediate steps when configuring ports and DTR can
- // twiggle more than once before stabilizing.
- // To avoid spurious resets we set the watchdog to 120ms and eventually
- // cancel if DTR goes back high.
- // Cancellation is only done if an auto-reset was started, which is
- // indicated by the magic key having been set.
-
- wdt_reset();
- // Restore the watchdog state in case the sketch was using it.
- WDTCSR |= (1<<WDCE) | (1<<WDE);
- WDTCSR = wdtcsr_save;
-#if MAGIC_KEY_POS != (RAMEND-1)
- // Restore backed up (old bootloader) magic key data
- if (magic_key_pos != (RAMEND-1)) {
- *(uint16_t *)magic_key_pos = *(uint16_t *)(RAMEND-1);
- } else
-#endif
- {
- // Clean up RAMEND key
- *(uint16_t *)magic_key_pos = 0x0000;
- }
- }
- }
- return true;
- }
- return false;
-}
-
Serial_ Serial;
#endif /* if defined(USBCON) */
diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h
index 06dd737..04e3dd9 100644
--- a/cores/arduino/USBAPI.h
+++ b/cores/arduino/USBAPI.h
@@ -163,23 +163,6 @@ typedef struct
//================================================================================
//================================================================================
-// MSC 'Driver'
-
-int MSC_GetInterface(uint8_t* interfaceNum);
-int MSC_GetDescriptor(int i);
-bool MSC_Setup(USBSetup& setup);
-bool MSC_Data(uint8_t rx,uint8_t tx);
-
-//================================================================================
-//================================================================================
-// CSC 'Driver'
-
-int CDC_GetInterface(uint8_t* interfaceNum);
-int CDC_GetDescriptor(int i);
-bool CDC_Setup(USBSetup& setup);
-
-//================================================================================
-//================================================================================
#define TRANSFER_PGM 0x80
#define TRANSFER_RELEASE 0x40
diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp
index b5a2be3..6146954 100644
--- a/cores/arduino/USBCore.cpp
+++ b/cores/arduino/USBCore.cpp
@@ -327,12 +327,10 @@ int USB_Send(u8 ep, const void* d, int len)
u8 _initEndpoints[USB_ENDPOINTS] =
{
- 0, // Control Endpoint
-
- EP_TYPE_INTERRUPT_IN, // CDC_ENDPOINT_ACM
- EP_TYPE_BULK_OUT, // CDC_ENDPOINT_OUT
- EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN
-
+ 0, // Control Endpoint
+ // EP_TYPE_INTERRUPT_IN, // CDC_ENDPOINT_ACM
+ // EP_TYPE_BULK_OUT, // CDC_ENDPOINT_OUT
+ // EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN
// Following endpoints are automatically initialized to 0
};
@@ -369,21 +367,6 @@ void InitEndpoints()
UERST = 0;
}
-// Handle CLASS_INTERFACE requests
-static
-bool ClassInterfaceRequest(USBSetup& setup)
-{
- u8 i = setup.wIndex;
-
- if (CDC_ACM_INTERFACE == i)
- return CDC_Setup(setup);
-
-#ifdef PLUGGABLE_USB_ENABLED
- return PluggableUSB().setup(setup);
-#endif
- return false;
-}
-
static int _cmark;
static int _cend;
void InitControl(int end)
@@ -462,34 +445,14 @@ int USB_RecvControl(void* d, int len)
return len;
}
-static u8 SendInterfaces()
-{
- u8 interfaces = 0;
-
- CDC_GetInterface(&interfaces);
-
-#ifdef PLUGGABLE_USB_ENABLED
- PluggableUSB().getInterface(&interfaces);
-#endif
-
- return interfaces;
-}
-
// Construct a dynamic configuration descriptor
// This really needs dynamic endpoint allocation etc
// TODO
static
bool SendConfiguration(int maxlen)
{
- // Count and measure interfaces
- InitControl(0);
- u8 interfaces = SendInterfaces();
- ConfigDescriptor config = D_CONFIG(_cmark + sizeof(ConfigDescriptor),interfaces);
-
- // Now send them
- InitControl(maxlen);
- USB_SendControl(0,&config,sizeof(ConfigDescriptor));
- SendInterfaces();
+ // InitControl(maxlen);
+ // USB_SendControl( * Config Descriptor Here * );
return true;
}
@@ -632,8 +595,7 @@ ISR(USB_COM_vect)
}
else
{
- InitControl(setup.wLength); // Max length of transfer
- ok = ClassInterfaceRequest(setup);
+ ok = true;
}
if (ok)
@@ -754,8 +716,6 @@ ISR(USB_GEN_vect)
// Start of Frame - happens every millisecond so we use it for TX and RX LED one-shot timing, too
if (udint & (1<<SOFI))
{
- USB_Flush(CDC_TX); // Send a tx frame if found
-
// check whether the one-shot period has elapsed. if so, turn off the LED
if (TxLEDPulse && !(--TxLEDPulse))
TXLED0;
diff --git a/cores/arduino/USBCore.h b/cores/arduino/USBCore.h
index 4210ced..eafdbe5 100644
--- a/cores/arduino/USBCore.h
+++ b/cores/arduino/USBCore.h
@@ -53,16 +53,6 @@
#define REQUEST_HOSTTODEVICE_CLASS_INTERFACE (REQUEST_HOSTTODEVICE | REQUEST_CLASS | REQUEST_INTERFACE)
#define REQUEST_DEVICETOHOST_STANDARD_INTERFACE (REQUEST_DEVICETOHOST | REQUEST_STANDARD | REQUEST_INTERFACE)
-// Class requests
-
-#define CDC_SET_LINE_CODING 0x20
-#define CDC_GET_LINE_CODING 0x21
-#define CDC_SET_CONTROL_LINE_STATE 0x22
-#define CDC_SEND_BREAK 0x23
-
-#define MSC_RESET 0xFF
-#define MSC_GET_MAX_LUN 0xFE
-
// Descriptors
#define USB_DEVICE_DESC_SIZE 18
@@ -111,21 +101,6 @@
#define TOBYTES(x) ((x) & 0xFF),(((x) >> 8) & 0xFF)
-#define CDC_V1_10 0x0110
-#define CDC_COMMUNICATION_INTERFACE_CLASS 0x02
-
-#define CDC_CALL_MANAGEMENT 0x01
-#define CDC_ABSTRACT_CONTROL_MODEL 0x02
-#define CDC_HEADER 0x00
-#define CDC_ABSTRACT_CONTROL_MANAGEMENT 0x02
-#define CDC_UNION 0x06
-#define CDC_CS_INTERFACE 0x24
-#define CDC_CS_ENDPOINT 0x25
-#define CDC_DATA_INTERFACE_CLASS 0x0A
-
-#define MSC_SUBCLASS_SCSI 0x06
-#define MSC_PROTOCOL_BULK_ONLY 0x50
-
#ifndef USB_VERSION
#define USB_VERSION 0x200
#endif
@@ -187,82 +162,6 @@ typedef struct
u8 interval;
} EndpointDescriptor;
-// Interface Association Descriptor
-// Used to bind 2 interfaces together in CDC compostite device
-typedef struct
-{
- u8 len; // 8
- u8 dtype; // 11
- u8 firstInterface;
- u8 interfaceCount;
- u8 functionClass;
- u8 funtionSubClass;
- u8 functionProtocol;
- u8 iInterface;
-} IADDescriptor;
-
-// CDC CS interface descriptor
-typedef struct
-{
- u8 len; // 5
- u8 dtype; // 0x24
- u8 subtype;
- u8 d0;
- u8 d1;
-} CDCCSInterfaceDescriptor;
-
-typedef struct
-{
- u8 len; // 4
- u8 dtype; // 0x24
- u8 subtype;
- u8 d0;
-} CDCCSInterfaceDescriptor4;
-
-typedef struct
-{
- u8 len;
- u8 dtype; // 0x24
- u8 subtype; // 1
- u8 bmCapabilities;
- u8 bDataInterface;
-} CMFunctionalDescriptor;
-
-typedef struct
-{
- u8 len;
- u8 dtype; // 0x24
- u8 subtype; // 1
- u8 bmCapabilities;
-} ACMFunctionalDescriptor;
-
-typedef struct
-{
- // IAD
- IADDescriptor iad; // Only needed on compound device
-
- // Control
- InterfaceDescriptor cif; //
- CDCCSInterfaceDescriptor header;
- CMFunctionalDescriptor callManagement; // Call Management
- ACMFunctionalDescriptor controlManagement; // ACM
- CDCCSInterfaceDescriptor functionalDescriptor; // CDC_UNION
- EndpointDescriptor cifin;
-
- // Data
- InterfaceDescriptor dif;
- EndpointDescriptor in;
- EndpointDescriptor out;
-} CDCDescriptor;
-
-typedef struct
-{
- InterfaceDescriptor msc;
- EndpointDescriptor in;
- EndpointDescriptor out;
-} MSCDescriptor;
-
-
#define D_DEVICE(_class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs) \
{ 18, 1, USB_VERSION, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs }
@@ -275,12 +174,6 @@ typedef struct
#define D_ENDPOINT(_addr,_attr,_packetSize, _interval) \
{ 7, 5, _addr,_attr,_packetSize, _interval }
-#define D_IAD(_firstInterface, _count, _class, _subClass, _protocol) \
- { 8, 11, _firstInterface, _count, _class, _subClass, _protocol, 0 }
-
-#define D_CDCCS(_subtype,_d0,_d1) { 5, 0x24, _subtype, _d0, _d1 }
-#define D_CDCCS4(_subtype,_d0) { 4, 0x24, _subtype, _d0 }
-
// Bootloader related fields
// Old Caterina bootloader places the MAGIC key into unsafe RAM locations (it can be rewritten
// by the running sketch before to actual reboot).
diff --git a/cores/arduino/USBDesc.h b/cores/arduino/USBDesc.h
index cc00a21..fe1af92 100644
--- a/cores/arduino/USBDesc.h
+++ b/cores/arduino/USBDesc.h
@@ -24,23 +24,6 @@
#define USB_ENDPOINTS 5 // AtMegaxxU2
#endif
-#define ISERIAL_MAX_LEN 20
-
-#define CDC_INTERFACE_COUNT 2
-#define CDC_ENPOINT_COUNT 3
-
-#define CDC_ACM_INTERFACE 0 // CDC ACM
-#define CDC_DATA_INTERFACE 1 // CDC Data
-#define CDC_FIRST_ENDPOINT 1
-#define CDC_ENDPOINT_ACM (CDC_FIRST_ENDPOINT) // CDC First
-#define CDC_ENDPOINT_OUT (CDC_FIRST_ENDPOINT+1)
-#define CDC_ENDPOINT_IN (CDC_FIRST_ENDPOINT+2)
-
-#define INTERFACE_COUNT (MSC_INTERFACE + MSC_INTERFACE_COUNT)
-
-#define CDC_RX CDC_ENDPOINT_OUT
-#define CDC_TX CDC_ENDPOINT_IN
-
#define IMANUFACTURER 1
#define IPRODUCT 2
#define ISERIAL 3 \ No newline at end of file