Created
January 23, 2017 16:47
-
-
Save anonymous/f9a13bd0dcdbc23d82f439a3c4c5e94f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//here is descriptors | |
//needs interrupt endpoint 1 in, bulk endpoint 2 out, bulk endpoint 3 in | |
//info from pl2303hx datasheet | |
/* Device Descriptor */ | |
const USB_DEVICE_DESCRIPTOR device_dsc= | |
{ | |
0x12, // Size of this descriptor in bytes | |
USB_DESCRIPTOR_DEVICE, // DEVICE descriptor type | |
0x0200, // USB Spec Release Number in BCD format | |
0x00, // Class Code | |
0x00, // Subclass code | |
0x00, // Protocol code | |
USB_EP0_BUFF_SIZE, // Max packet size for EP0, see usb_config.h (8) | |
0x0557, // Vendor ID: ATEN UC232a | |
0x2008, // Product ID: ATEN UC232a | |
0x0000, // Device release number in BCD format | |
0x01, // Manufacturer string index | |
0x02, // Product string index | |
0x00, // Device serial number string index | |
0x01 // Number of possible configurations | |
}; | |
/* Configuration 1 Descriptor */ | |
const uint8_t configDescriptor1[]={ | |
/* Configuration Descriptor */ | |
0x09,//sizeof(USB_CFG_DSC), // Size of this descriptor in bytes | |
USB_DESCRIPTOR_CONFIGURATION, // CONFIGURATION descriptor type | |
DESC_CONFIG_WORD(0x0027), // Total length of data for this cfg | |
1, // Number of interfaces in this cfg | |
1, // Index value of this configuration | |
0, // Configuration string index | |
_DEFAULT, // Attributes, see usb_device.h | |
50, // Max power consumption (2X mA) | |
/* Interface Descriptor */ | |
0x09,//sizeof(USB_INTF_DSC), // Size of this descriptor in bytes | |
USB_DESCRIPTOR_INTERFACE, // INTERFACE descriptor type | |
0, // Interface Number | |
0, // Alternate Setting Number | |
3, // Number of endpoints in this intf | |
0xFF, // Class code | |
0xFF, // Subclass code | |
0xFF, // Protocol code | |
0, // Interface string index | |
/* Endpoint Descriptor */ | |
0x07, /*sizeof(USB_EP_DSC)*/ | |
USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor | |
_EP01_IN, //EndpointAddress | |
_INTERRUPT, //Attributes | |
DESC_CONFIG_WORD(USBGEN_INT_SIZE), //size | |
64, //Interval | |
0x07, /*sizeof(USB_EP_DSC)*/ | |
USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor | |
_EP02_OUT, //EndpointAddress | |
_BULK, //Attributes | |
DESC_CONFIG_WORD(USBGEN_EP_SIZE), //size | |
0, //Interval | |
0x07, /*sizeof(USB_EP_DSC)*/ | |
USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor | |
_EP03_IN, //EndpointAddress | |
_BULK, //Attributes | |
DESC_CONFIG_WORD(USBGEN_EP_SIZE), //size | |
0, //Interval | |
}; | |
//checking vendor requests not standard | |
void USBCheckVendorRequest(void) | |
{ | |
//cvm - defines from pl2303.c in linux kernel | |
#define SET_LINE_REQUEST_TYPE 0x21 | |
#define SET_LINE_REQUEST 0x20 | |
#define SET_LINE ((SET_LINE_REQUEST_TYPE<<8) + SET_LINE_REQUEST) | |
#define SET_CONTROL_REQUEST_TYPE 0x21 | |
#define SET_CONTROL_REQUEST 0x22 | |
#define SET_CONTROL ((SET_CONTROL_REQUEST_TYPE<<8) + SET_CONTROL_REQUEST) | |
#define BREAK_REQUEST_TYPE 0x21 | |
#define BREAK_REQUEST 0x23 | |
#define BREAK ((BREAK_REQUEST_TYPE<<8) + BREAK_REQUEST) | |
#define GET_LINE_REQUEST_TYPE 0xa1 | |
#define GET_LINE_REQUEST 0x21 | |
#define GET_LINE ((GET_LINE_REQUEST_TYPE<<8) + GET_LINE_REQUEST) | |
#define VENDOR_WRITE_REQUEST_TYPE 0x40 | |
#define VENDOR_WRITE_REQUEST 0x01 | |
#define VENDOR_WRITE ((VENDOR_WRITE_REQUEST_TYPE<<8) + VENDOR_WRITE_REQUEST) | |
#define VENDOR_READ_REQUEST_TYPE 0xc0 | |
#define VENDOR_READ_REQUEST 0x01 | |
#define VENDOR_READ ((VENDOR_READ_REQUEST_TYPE<<8) + VENDOR_READ_REQUEST) | |
extern struct {uint32_t; uint8_t; uint8_t; uint8_t;} line_settings; | |
extern void set_line(); | |
//combine request type and request for checking below | |
uint16_t req = (SetupPkt.bmRequestType<<8) + SetupPkt.bRequest; | |
if( req == VENDOR_READ ) | |
{ | |
extern uint8_t CtrlTrfData[USB_EP0_BUFF_SIZE]; | |
CtrlTrfData[0] = 0; | |
USBEP0SendRAMPtr(CtrlTrfData,1,USB_EP0_RAM); //just send 0 | |
} | |
if( req == VENDOR_WRITE || req == SET_CONTROL || req == BREAK ) | |
{ | |
USBEP0SendRAMPtr(NULL,0,USB_EP0_NO_DATA); // | |
} | |
//line settings (referred to as uint8_t buf[] below) | |
/* For reference buf[0]:buf[3] baud rate value */ | |
/* For reference buf[4]=stop bits 0=1,1=1.5,2=2 */ | |
/* For reference buf[5]=parity 0=none,1=odd,2=even,3=mark,4=space */ | |
/* buf[6]=data size bits 5,6,7,8 */ | |
if( req == GET_LINE ) | |
{ | |
USBEP0SendRAMPtr((uint8_t*)&line_settings,7,USB_EP0_RAM); //send my line settings | |
} | |
if( req == SET_LINE ) | |
{ | |
USBEP0Receive((uint8_t*)&line_settings,7,set_line); //get data, call set line | |
//set line only used when debug output to serial | |
//(can also just receive and ignore- if serial not used or debug serial used | |
//and want to just use our own line settings that cannot be changed) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment