-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lpc176x: Initial support for serial over usb
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
- Loading branch information
1 parent
c812a40
commit c381d03
Showing
8 changed files
with
961 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef __GENERIC_USB_CDC_H | ||
#define __GENERIC_USB_CDC_H | ||
|
||
#include <stdint.h> // uint_fast8_t | ||
|
||
enum { | ||
USB_CDC_EP0_SIZE = 16, | ||
|
||
// XXX - endpoint ids may need to changed per-board | ||
USB_CDC_EP_ACM = 1, | ||
USB_CDC_EP_ACM_SIZE = 8, | ||
|
||
USB_CDC_EP_BULK_OUT = 2, | ||
USB_CDC_EP_BULK_OUT_SIZE = 64, | ||
|
||
USB_CDC_EP_BULK_IN = 5, | ||
USB_CDC_EP_BULK_IN_SIZE = 64, | ||
}; | ||
|
||
// callbacks provided by board specific code | ||
int_fast8_t usb_read_bulk_out(void *data, uint_fast8_t max_len); | ||
int_fast8_t usb_send_bulk_in(void *data, uint_fast8_t len); | ||
int_fast8_t usb_read_setup(void *data, uint_fast8_t max_len); | ||
int_fast8_t usb_send_setup(const void *data, uint_fast8_t len); | ||
void usb_send_pgm_setup(void *data, uint_fast8_t len); | ||
void usb_set_stall(void); | ||
void usb_set_address(uint_fast8_t addr); | ||
void usb_set_configure(void); | ||
|
||
// usb_cdc.c | ||
void usb_notify_bulk_in(void); | ||
void usb_notify_bulk_out(void); | ||
void usb_notify_setup(void); | ||
|
||
#endif // usb_cdc.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Standard definitions for USB commands and data structures | ||
#ifndef __GENERIC_USBSTD_H | ||
#define __GENERIC_USBSTD_H | ||
|
||
#include <stdint.h> // uint8_t | ||
#include "compiler.h" // PACKED | ||
|
||
#define USB_DIR_OUT 0 /* to device */ | ||
#define USB_DIR_IN 0x80 /* to host */ | ||
|
||
#define USB_REQ_GET_STATUS 0x00 | ||
#define USB_REQ_CLEAR_FEATURE 0x01 | ||
#define USB_REQ_SET_FEATURE 0x03 | ||
#define USB_REQ_SET_ADDRESS 0x05 | ||
#define USB_REQ_GET_DESCRIPTOR 0x06 | ||
#define USB_REQ_SET_DESCRIPTOR 0x07 | ||
#define USB_REQ_GET_CONFIGURATION 0x08 | ||
#define USB_REQ_SET_CONFIGURATION 0x09 | ||
#define USB_REQ_GET_INTERFACE 0x0A | ||
#define USB_REQ_SET_INTERFACE 0x0B | ||
#define USB_REQ_SYNCH_FRAME 0x0C | ||
|
||
struct usb_ctrlrequest { | ||
uint8_t bRequestType; | ||
uint8_t bRequest; | ||
uint16_t wValue; | ||
uint16_t wIndex; | ||
uint16_t wLength; | ||
} PACKED; | ||
|
||
#define USB_DT_DEVICE 0x01 | ||
#define USB_DT_CONFIG 0x02 | ||
#define USB_DT_STRING 0x03 | ||
#define USB_DT_INTERFACE 0x04 | ||
#define USB_DT_ENDPOINT 0x05 | ||
#define USB_DT_DEVICE_QUALIFIER 0x06 | ||
#define USB_DT_OTHER_SPEED_CONFIG 0x07 | ||
#define USB_DT_ENDPOINT_COMPANION 0x30 | ||
|
||
struct usb_device_descriptor { | ||
uint8_t bLength; | ||
uint8_t bDescriptorType; | ||
|
||
uint16_t bcdUSB; | ||
uint8_t bDeviceClass; | ||
uint8_t bDeviceSubClass; | ||
uint8_t bDeviceProtocol; | ||
uint8_t bMaxPacketSize0; | ||
uint16_t idVendor; | ||
uint16_t idProduct; | ||
uint16_t bcdDevice; | ||
uint8_t iManufacturer; | ||
uint8_t iProduct; | ||
uint8_t iSerialNumber; | ||
uint8_t bNumConfigurations; | ||
} PACKED; | ||
|
||
#define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */ | ||
#define USB_CLASS_AUDIO 1 | ||
#define USB_CLASS_COMM 2 | ||
#define USB_CLASS_HID 3 | ||
#define USB_CLASS_PHYSICAL 5 | ||
#define USB_CLASS_STILL_IMAGE 6 | ||
#define USB_CLASS_PRINTER 7 | ||
#define USB_CLASS_MASS_STORAGE 8 | ||
#define USB_CLASS_HUB 9 | ||
|
||
struct usb_config_descriptor { | ||
uint8_t bLength; | ||
uint8_t bDescriptorType; | ||
|
||
uint16_t wTotalLength; | ||
uint8_t bNumInterfaces; | ||
uint8_t bConfigurationValue; | ||
uint8_t iConfiguration; | ||
uint8_t bmAttributes; | ||
uint8_t bMaxPower; | ||
} PACKED; | ||
|
||
struct usb_interface_descriptor { | ||
uint8_t bLength; | ||
uint8_t bDescriptorType; | ||
|
||
uint8_t bInterfaceNumber; | ||
uint8_t bAlternateSetting; | ||
uint8_t bNumEndpoints; | ||
uint8_t bInterfaceClass; | ||
uint8_t bInterfaceSubClass; | ||
uint8_t bInterfaceProtocol; | ||
uint8_t iInterface; | ||
} PACKED; | ||
|
||
struct usb_endpoint_descriptor { | ||
uint8_t bLength; | ||
uint8_t bDescriptorType; | ||
|
||
uint8_t bEndpointAddress; | ||
uint8_t bmAttributes; | ||
uint16_t wMaxPacketSize; | ||
uint8_t bInterval; | ||
} PACKED; | ||
|
||
#define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */ | ||
#define USB_ENDPOINT_DIR_MASK 0x80 | ||
|
||
#define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */ | ||
#define USB_ENDPOINT_XFER_CONTROL 0 | ||
#define USB_ENDPOINT_XFER_ISOC 1 | ||
#define USB_ENDPOINT_XFER_BULK 2 | ||
#define USB_ENDPOINT_XFER_INT 3 | ||
#define USB_ENDPOINT_MAX_ADJUSTABLE 0x80 | ||
|
||
struct usb_string_descriptor { | ||
uint8_t bLength; | ||
uint8_t bDescriptorType; | ||
uint16_t data[]; | ||
} PACKED; | ||
|
||
#define USB_LANGID_ENGLISH_US 0x0409 | ||
|
||
#endif // usbstd.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Standard definitions for USB CDC devices | ||
#ifndef __GENERIC_USBSTD_CDC_H | ||
#define __GENERIC_USBSTD_CDC_H | ||
|
||
#define USB_CDC_SUBCLASS_ACM 0x02 | ||
|
||
#define USB_CDC_ACM_PROTO_AT_V25TER 1 | ||
|
||
struct usb_cdc_header_descriptor { | ||
uint8_t bLength; | ||
uint8_t bDescriptorType; | ||
uint8_t bDescriptorSubType; | ||
uint16_t bcdCDC; | ||
} PACKED; | ||
|
||
#define USB_CDC_HEADER_TYPE 0x00 | ||
#define USB_CDC_ACM_TYPE 0x02 | ||
#define USB_CDC_UNION_TYPE 0x06 | ||
|
||
#define USB_CDC_CS_INTERFACE 0x24 | ||
#define USB_CDC_CS_ENDPOINT 0x25 | ||
|
||
struct usb_cdc_acm_descriptor { | ||
uint8_t bLength; | ||
uint8_t bDescriptorType; | ||
uint8_t bDescriptorSubType; | ||
uint8_t bmCapabilities; | ||
} PACKED; | ||
|
||
struct usb_cdc_union_descriptor { | ||
uint8_t bLength; | ||
uint8_t bDescriptorType; | ||
uint8_t bDescriptorSubType; | ||
uint8_t bMasterInterface0; | ||
uint8_t bSlaveInterface0; | ||
} PACKED; | ||
|
||
#define USB_CDC_REQ_SET_LINE_CODING 0x20 | ||
#define USB_CDC_REQ_GET_LINE_CODING 0x21 | ||
#define USB_CDC_REQ_SET_CONTROL_LINE_STATE 0x22 | ||
|
||
struct usb_cdc_line_coding { | ||
uint32_t dwDTERate; | ||
uint8_t bCharFormat; | ||
uint8_t bParityType; | ||
uint8_t bDataBits; | ||
} PACKED; | ||
|
||
#endif // usbstd_cdc.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.