update usb stack from Gnuk development branch
This commit is contained in:
@@ -20,7 +20,7 @@ static struct stream stream;
|
|||||||
/* USB Device Descriptor */
|
/* USB Device Descriptor */
|
||||||
static const uint8_t vcom_device_desc[18] = {
|
static const uint8_t vcom_device_desc[18] = {
|
||||||
18, /* bLength */
|
18, /* bLength */
|
||||||
USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */
|
DEVICE_DESCRIPTOR, /* bDescriptorType */
|
||||||
0x10, 0x01, /* bcdUSB = 1.1 */
|
0x10, 0x01, /* bcdUSB = 1.1 */
|
||||||
0x02, /* bDeviceClass (CDC). */
|
0x02, /* bDeviceClass (CDC). */
|
||||||
0x00, /* bDeviceSubClass. */
|
0x00, /* bDeviceSubClass. */
|
||||||
@@ -38,7 +38,7 @@ static const uint8_t vcom_device_desc[18] = {
|
|||||||
/* Configuration Descriptor tree for a CDC.*/
|
/* Configuration Descriptor tree for a CDC.*/
|
||||||
static const uint8_t vcom_config_desc[67] = {
|
static const uint8_t vcom_config_desc[67] = {
|
||||||
9,
|
9,
|
||||||
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
|
CONFIG_DESCRIPTOR, /* bDescriptorType: Configuration */
|
||||||
/* Configuration Descriptor.*/
|
/* Configuration Descriptor.*/
|
||||||
67, 0x00, /* wTotalLength. */
|
67, 0x00, /* wTotalLength. */
|
||||||
0x02, /* bNumInterfaces. */
|
0x02, /* bNumInterfaces. */
|
||||||
@@ -48,7 +48,7 @@ static const uint8_t vcom_config_desc[67] = {
|
|||||||
50, /* bMaxPower (100mA). */
|
50, /* bMaxPower (100mA). */
|
||||||
/* Interface Descriptor.*/
|
/* Interface Descriptor.*/
|
||||||
9,
|
9,
|
||||||
USB_INTERFACE_DESCRIPTOR_TYPE,
|
INTERFACE_DESCRIPTOR,
|
||||||
0x00, /* bInterfaceNumber. */
|
0x00, /* bInterfaceNumber. */
|
||||||
0x00, /* bAlternateSetting. */
|
0x00, /* bAlternateSetting. */
|
||||||
0x01, /* bNumEndpoints. */
|
0x01, /* bNumEndpoints. */
|
||||||
@@ -87,14 +87,14 @@ static const uint8_t vcom_config_desc[67] = {
|
|||||||
0x01, /* bSlaveInterface0 (Data Class Interface). */
|
0x01, /* bSlaveInterface0 (Data Class Interface). */
|
||||||
/* Endpoint 2 Descriptor.*/
|
/* Endpoint 2 Descriptor.*/
|
||||||
7,
|
7,
|
||||||
USB_ENDPOINT_DESCRIPTOR_TYPE,
|
ENDPOINT_DESCRIPTOR,
|
||||||
ENDP2|0x80, /* bEndpointAddress. */
|
ENDP2|0x80, /* bEndpointAddress. */
|
||||||
0x03, /* bmAttributes (Interrupt). */
|
0x03, /* bmAttributes (Interrupt). */
|
||||||
0x08, 0x00, /* wMaxPacketSize. */
|
0x08, 0x00, /* wMaxPacketSize. */
|
||||||
0xFF, /* bInterval. */
|
0xFF, /* bInterval. */
|
||||||
/* Interface Descriptor.*/
|
/* Interface Descriptor.*/
|
||||||
9,
|
9,
|
||||||
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: */
|
INTERFACE_DESCRIPTOR, /* bDescriptorType: */
|
||||||
0x01, /* bInterfaceNumber. */
|
0x01, /* bInterfaceNumber. */
|
||||||
0x00, /* bAlternateSetting. */
|
0x00, /* bAlternateSetting. */
|
||||||
0x02, /* bNumEndpoints. */
|
0x02, /* bNumEndpoints. */
|
||||||
@@ -104,14 +104,14 @@ static const uint8_t vcom_config_desc[67] = {
|
|||||||
0x00, /* iInterface. */
|
0x00, /* iInterface. */
|
||||||
/* Endpoint 3 Descriptor.*/
|
/* Endpoint 3 Descriptor.*/
|
||||||
7,
|
7,
|
||||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
ENDPOINT_DESCRIPTOR, /* bDescriptorType: Endpoint */
|
||||||
ENDP3, /* bEndpointAddress. */
|
ENDP3, /* bEndpointAddress. */
|
||||||
0x02, /* bmAttributes (Bulk). */
|
0x02, /* bmAttributes (Bulk). */
|
||||||
0x40, 0x00, /* wMaxPacketSize. */
|
0x40, 0x00, /* wMaxPacketSize. */
|
||||||
0x00, /* bInterval. */
|
0x00, /* bInterval. */
|
||||||
/* Endpoint 1 Descriptor.*/
|
/* Endpoint 1 Descriptor.*/
|
||||||
7,
|
7,
|
||||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
ENDPOINT_DESCRIPTOR, /* bDescriptorType: Endpoint */
|
||||||
ENDP1|0x80, /* bEndpointAddress. */
|
ENDP1|0x80, /* bEndpointAddress. */
|
||||||
0x02, /* bmAttributes (Bulk). */
|
0x02, /* bmAttributes (Bulk). */
|
||||||
0x40, 0x00, /* wMaxPacketSize. */
|
0x40, 0x00, /* wMaxPacketSize. */
|
||||||
@@ -124,13 +124,13 @@ static const uint8_t vcom_config_desc[67] = {
|
|||||||
*/
|
*/
|
||||||
static const uint8_t vcom_string0[4] = {
|
static const uint8_t vcom_string0[4] = {
|
||||||
4, /* bLength */
|
4, /* bLength */
|
||||||
USB_STRING_DESCRIPTOR_TYPE,
|
STRING_DESCRIPTOR,
|
||||||
0x09, 0x04 /* LangID = 0x0409: US-English */
|
0x09, 0x04 /* LangID = 0x0409: US-English */
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t vcom_string1[] = {
|
static const uint8_t vcom_string1[] = {
|
||||||
23*2+2, /* bLength */
|
23*2+2, /* bLength */
|
||||||
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
|
STRING_DESCRIPTOR, /* bDescriptorType */
|
||||||
/* Manufacturer: "Flying Stone Technology" */
|
/* Manufacturer: "Flying Stone Technology" */
|
||||||
'F', 0, 'l', 0, 'y', 0, 'i', 0, 'n', 0, 'g', 0, ' ', 0, 'S', 0,
|
'F', 0, 'l', 0, 'y', 0, 'i', 0, 'n', 0, 'g', 0, ' ', 0, 'S', 0,
|
||||||
't', 0, 'o', 0, 'n', 0, 'e', 0, ' ', 0, 'T', 0, 'e', 0, 'c', 0,
|
't', 0, 'o', 0, 'n', 0, 'e', 0, ' ', 0, 'T', 0, 'e', 0, 'c', 0,
|
||||||
@@ -139,7 +139,7 @@ static const uint8_t vcom_string1[] = {
|
|||||||
|
|
||||||
static const uint8_t vcom_string2[] = {
|
static const uint8_t vcom_string2[] = {
|
||||||
14*2+2, /* bLength */
|
14*2+2, /* bLength */
|
||||||
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
|
STRING_DESCRIPTOR, /* bDescriptorType */
|
||||||
/* Product name: "Chopstx Sample" */
|
/* Product name: "Chopstx Sample" */
|
||||||
'C', 0, 'h', 0, 'o', 0, 'p', 0, 's', 0, 't', 0, 'x', 0, ' ', 0,
|
'C', 0, 'h', 0, 'o', 0, 'p', 0, 's', 0, 't', 0, 'x', 0, ' ', 0,
|
||||||
'S', 0, 'a', 0, 'm', 0, 'p', 0, 'l', 0, 'e', 0,
|
'S', 0, 'a', 0, 'm', 0, 'p', 0, 'l', 0, 'e', 0,
|
||||||
@@ -150,7 +150,7 @@ static const uint8_t vcom_string2[] = {
|
|||||||
*/
|
*/
|
||||||
static const uint8_t vcom_string3[28] = {
|
static const uint8_t vcom_string3[28] = {
|
||||||
28, /* bLength */
|
28, /* bLength */
|
||||||
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
|
STRING_DESCRIPTOR, /* bDescriptorType */
|
||||||
'0', 0, '.', 0, '0', 0, '0', 0, /* Version number */
|
'0', 0, '.', 0, '0', 0, '0', 0, /* Version number */
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ usb_cb_device_reset (void)
|
|||||||
#define CDC_CTRL_DTR 0x0001
|
#define CDC_CTRL_DTR 0x0001
|
||||||
|
|
||||||
void
|
void
|
||||||
usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no, uint16_t value)
|
usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t type_rcp = req & (REQUEST_TYPE|RECIPIENT);
|
uint8_t type_rcp = req & (REQUEST_TYPE|RECIPIENT);
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no, uint16_t value)
|
|||||||
/* Open/close the connection. */
|
/* Open/close the connection. */
|
||||||
chopstx_mutex_lock (&stream.mtx);
|
chopstx_mutex_lock (&stream.mtx);
|
||||||
stream.flags &= ~FLAG_CONNECTED;
|
stream.flags &= ~FLAG_CONNECTED;
|
||||||
stream.flags |= ((value & CDC_CTRL_DTR) != 0)? FLAG_CONNECTED : 0;
|
stream.flags |= ((arg->value & CDC_CTRL_DTR) != 0)? FLAG_CONNECTED : 0;
|
||||||
chopstx_cond_signal (&stream.cnd);
|
chopstx_cond_signal (&stream.cnd);
|
||||||
chopstx_mutex_unlock (&stream.mtx);
|
chopstx_mutex_unlock (&stream.mtx);
|
||||||
}
|
}
|
||||||
@@ -217,17 +217,17 @@ static struct line_coding line_coding = {
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vcom_port_data_setup (uint8_t req, uint8_t req_no, struct control_info *detail)
|
vcom_port_data_setup (uint8_t req, uint8_t req_no, struct req_args *arg)
|
||||||
{
|
{
|
||||||
if (USB_SETUP_GET (req))
|
if (USB_SETUP_GET (req))
|
||||||
{
|
{
|
||||||
if (req_no == USB_CDC_REQ_GET_LINE_CODING)
|
if (req_no == USB_CDC_REQ_GET_LINE_CODING)
|
||||||
return usb_lld_reply_request (&line_coding, sizeof(line_coding), detail);
|
return usb_lld_reply_request (&line_coding, sizeof(line_coding), arg);
|
||||||
}
|
}
|
||||||
else /* USB_SETUP_SET (req) */
|
else /* USB_SETUP_SET (req) */
|
||||||
{
|
{
|
||||||
if (req_no == USB_CDC_REQ_SET_LINE_CODING
|
if (req_no == USB_CDC_REQ_SET_LINE_CODING
|
||||||
&& detail->len == sizeof (line_coding))
|
&& arg->len == sizeof (line_coding))
|
||||||
{
|
{
|
||||||
usb_lld_set_data_to_recv (&line_coding, sizeof (line_coding));
|
usb_lld_set_data_to_recv (&line_coding, sizeof (line_coding));
|
||||||
return USB_SUCCESS;
|
return USB_SUCCESS;
|
||||||
@@ -240,29 +240,29 @@ vcom_port_data_setup (uint8_t req, uint8_t req_no, struct control_info *detail)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
usb_cb_setup (uint8_t req, uint8_t req_no, struct control_info *detail)
|
usb_cb_setup (uint8_t req, uint8_t req_no, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t type_rcp = req & (REQUEST_TYPE|RECIPIENT);
|
uint8_t type_rcp = req & (REQUEST_TYPE|RECIPIENT);
|
||||||
|
|
||||||
if (type_rcp == (CLASS_REQUEST | INTERFACE_RECIPIENT) && detail->index == 0)
|
if (type_rcp == (CLASS_REQUEST | INTERFACE_RECIPIENT) && arg->index == 0)
|
||||||
return vcom_port_data_setup (req, req_no, detail);
|
return vcom_port_data_setup (req, req_no, arg);
|
||||||
|
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
||||||
struct control_info *detail)
|
struct req_args *arg)
|
||||||
{
|
{
|
||||||
if (rcp != DEVICE_RECIPIENT)
|
if (rcp != DEVICE_RECIPIENT)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (desc_type == DEVICE_DESCRIPTOR)
|
if (desc_type == DEVICE_DESCRIPTOR)
|
||||||
return usb_lld_reply_request (vcom_device_desc, sizeof (vcom_device_desc),
|
return usb_lld_reply_request (vcom_device_desc, sizeof (vcom_device_desc),
|
||||||
detail);
|
arg);
|
||||||
else if (desc_type == CONFIG_DESCRIPTOR)
|
else if (desc_type == CONFIG_DESCRIPTOR)
|
||||||
return usb_lld_reply_request (vcom_config_desc, sizeof (vcom_config_desc),
|
return usb_lld_reply_request (vcom_config_desc, sizeof (vcom_config_desc),
|
||||||
detail);
|
arg);
|
||||||
else if (desc_type == STRING_DESCRIPTOR)
|
else if (desc_type == STRING_DESCRIPTOR)
|
||||||
{
|
{
|
||||||
const uint8_t *str;
|
const uint8_t *str;
|
||||||
@@ -290,7 +290,7 @@ usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
|||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return usb_lld_reply_request (str, size, detail);
|
return usb_lld_reply_request (str, size, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
@@ -369,11 +369,11 @@ usb_cb_handle_event (uint8_t event_type, uint16_t value)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
usb_cb_interface (uint8_t cmd, struct control_info *detail)
|
usb_cb_interface (uint8_t cmd, struct req_args *arg)
|
||||||
{
|
{
|
||||||
const uint8_t zero = 0;
|
const uint8_t zero = 0;
|
||||||
uint16_t interface = detail->index;
|
uint16_t interface = arg->index;
|
||||||
uint16_t alt = detail->value;
|
uint16_t alt = arg->value;
|
||||||
|
|
||||||
if (interface >= NUM_INTERFACES)
|
if (interface >= NUM_INTERFACES)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
@@ -390,7 +390,7 @@ usb_cb_interface (uint8_t cmd, struct control_info *detail)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case USB_GET_INTERFACE:
|
case USB_GET_INTERFACE:
|
||||||
return usb_lld_reply_request (&zero, 1, detail);
|
return usb_lld_reply_request (&zero, 1, arg);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
case USB_QUERY_INTERFACE:
|
case USB_QUERY_INTERFACE:
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
#define USB_DEVICE_DESCRIPTOR_TYPE 0x01
|
|
||||||
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02
|
|
||||||
#define USB_STRING_DESCRIPTOR_TYPE 0x03
|
|
||||||
#define USB_INTERFACE_DESCRIPTOR_TYPE 0x04
|
|
||||||
#define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05
|
|
||||||
|
|
||||||
#define STANDARD_ENDPOINT_DESC_SIZE 0x09
|
#define STANDARD_ENDPOINT_DESC_SIZE 0x09
|
||||||
|
|
||||||
/* endpoints enumeration */
|
/* endpoints enumeration */
|
||||||
@@ -24,7 +18,7 @@
|
|||||||
|
|
||||||
enum RECIPIENT_TYPE
|
enum RECIPIENT_TYPE
|
||||||
{
|
{
|
||||||
DEVICE_RECIPIENT, /* Recipient device */
|
DEVICE_RECIPIENT = 0, /* Recipient device */
|
||||||
INTERFACE_RECIPIENT, /* Recipient interface */
|
INTERFACE_RECIPIENT, /* Recipient interface */
|
||||||
ENDPOINT_RECIPIENT, /* Recipient endpoint */
|
ENDPOINT_RECIPIENT, /* Recipient endpoint */
|
||||||
OTHER_RECIPIENT
|
OTHER_RECIPIENT
|
||||||
@@ -55,19 +49,20 @@ enum
|
|||||||
USB_SUCCESS = 1,
|
USB_SUCCESS = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct control_info {
|
struct req_args {
|
||||||
uint16_t value;
|
uint16_t value;
|
||||||
uint16_t index;
|
uint16_t index;
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
};
|
};
|
||||||
|
|
||||||
void usb_cb_device_reset (void);
|
void usb_cb_device_reset (void);
|
||||||
int usb_cb_setup (uint8_t req, uint8_t req_no, struct control_info *detail);
|
int usb_cb_setup (uint8_t req, uint8_t req_no, struct req_args *arg);
|
||||||
int usb_cb_interface (uint8_t cmd, struct control_info *detail);
|
int usb_cb_interface (uint8_t cmd, struct req_args *arg);
|
||||||
int usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
int usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
||||||
struct control_info *detail);
|
struct req_args *arg);
|
||||||
int usb_cb_handle_event (uint8_t event_type, uint16_t value);
|
int usb_cb_handle_event (uint8_t event_type, uint16_t value);
|
||||||
void usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no, uint16_t value);
|
void usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no,
|
||||||
|
struct req_args *arg);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
USB_EVENT_ADDRESS,
|
USB_EVENT_ADDRESS,
|
||||||
@@ -103,7 +98,7 @@ void usb_lld_txcpy (const void *src, int ep_num, int offset, size_t len);
|
|||||||
void usb_lld_tx_enable (int ep_num, size_t len);
|
void usb_lld_tx_enable (int ep_num, size_t len);
|
||||||
void usb_lld_write (uint8_t ep_num, const void *buf, size_t len);
|
void usb_lld_write (uint8_t ep_num, const void *buf, size_t len);
|
||||||
int usb_lld_reply_request (const void *buf, size_t buflen,
|
int usb_lld_reply_request (const void *buf, size_t buflen,
|
||||||
struct control_info *ctrl);
|
struct req_args *arg);
|
||||||
void usb_lld_rx_enable (int ep_num);
|
void usb_lld_rx_enable (int ep_num);
|
||||||
int usb_lld_rx_data_len (int ep_num);
|
int usb_lld_rx_data_len (int ep_num);
|
||||||
void usb_lld_rxcpy (uint8_t *dst, int ep_num, int offset, size_t len);
|
void usb_lld_rxcpy (uint8_t *dst, int ep_num, int offset, size_t len);
|
||||||
@@ -114,7 +109,7 @@ void usb_lld_setup_endpoint (int ep_num, int ep_type, int ep_kind,
|
|||||||
void usb_lld_set_configuration (uint8_t config);
|
void usb_lld_set_configuration (uint8_t config);
|
||||||
uint8_t usb_lld_current_configuration (void);
|
uint8_t usb_lld_current_configuration (void);
|
||||||
void usb_lld_set_feature (uint8_t feature);
|
void usb_lld_set_feature (uint8_t feature);
|
||||||
void usb_lld_set_data_to_recv (const void *p, size_t len);
|
void usb_lld_set_data_to_recv (void *p, size_t len);
|
||||||
|
|
||||||
void usb_lld_prepare_shutdown (void);
|
void usb_lld_prepare_shutdown (void);
|
||||||
void usb_lld_shutdown (void);
|
void usb_lld_shutdown (void);
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ struct DEVICE_INFO
|
|||||||
uint8_t bRequest;
|
uint8_t bRequest;
|
||||||
/**/
|
/**/
|
||||||
uint16_t value;
|
uint16_t value;
|
||||||
|
uint16_t index;
|
||||||
|
uint16_t len;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct DEVICE_INFO device_info;
|
static struct DEVICE_INFO device_info;
|
||||||
@@ -462,26 +464,26 @@ static void handle_datastage_in (void)
|
|||||||
st103_ep_set_tx_status (ENDP0, EP_TX_VALID);
|
st103_ep_set_tx_status (ENDP0, EP_TX_VALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef int (*HANDLER) (uint8_t req, struct control_info *detail);
|
typedef int (*HANDLER) (uint8_t req, struct req_args *arg);
|
||||||
|
|
||||||
static int std_none (uint8_t req, struct control_info *detail)
|
static int std_none (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
(void)req; (void)detail;
|
(void)req; (void)arg;
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int std_get_status (uint8_t req, struct control_info *detail)
|
static int std_get_status (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t rcp = req & RECIPIENT;
|
uint8_t rcp = req & RECIPIENT;
|
||||||
uint16_t status_info = 0;
|
uint16_t status_info = 0;
|
||||||
|
|
||||||
if (detail->value != 0 || detail->len != 2 || (detail->index >> 8) != 0
|
if (arg->value != 0 || arg->len != 2 || (arg->index >> 8) != 0
|
||||||
|| (req & REQUEST_DIR) == 0)
|
|| (req & REQUEST_DIR) == 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (rcp == DEVICE_RECIPIENT)
|
if (rcp == DEVICE_RECIPIENT)
|
||||||
{
|
{
|
||||||
if (detail->index == 0)
|
if (arg->index == 0)
|
||||||
{
|
{
|
||||||
/* Get Device Status */
|
/* Get Device Status */
|
||||||
uint8_t feature = dev_p->current_feature;
|
uint8_t feature = dev_p->current_feature;
|
||||||
@@ -498,7 +500,7 @@ static int std_get_status (uint8_t req, struct control_info *detail)
|
|||||||
else /* Self-powered */
|
else /* Self-powered */
|
||||||
status_info &= ~1;
|
status_info &= ~1;
|
||||||
|
|
||||||
return usb_lld_reply_request (&status_info, 2, detail);
|
return usb_lld_reply_request (&status_info, 2, arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (rcp == INTERFACE_RECIPIENT)
|
else if (rcp == INTERFACE_RECIPIENT)
|
||||||
@@ -508,21 +510,21 @@ static int std_get_status (uint8_t req, struct control_info *detail)
|
|||||||
if (dev_p->current_configuration == 0)
|
if (dev_p->current_configuration == 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
r = usb_cb_interface (USB_QUERY_INTERFACE, detail);
|
r = usb_cb_interface (USB_QUERY_INTERFACE, arg);
|
||||||
if (r != USB_SUCCESS)
|
if (r != USB_SUCCESS)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
return usb_lld_reply_request (&status_info, 2, detail);
|
return usb_lld_reply_request (&status_info, 2, arg);
|
||||||
}
|
}
|
||||||
else if (rcp == ENDPOINT_RECIPIENT)
|
else if (rcp == ENDPOINT_RECIPIENT)
|
||||||
{
|
{
|
||||||
uint8_t endpoint = (detail->index & 0x0f);
|
uint8_t endpoint = (arg->index & 0x0f);
|
||||||
uint16_t status;
|
uint16_t status;
|
||||||
|
|
||||||
if ((detail->index & 0x70) || endpoint == ENDP0)
|
if ((arg->index & 0x70) || endpoint == ENDP0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if ((detail->index & 0x80))
|
if ((arg->index & 0x80))
|
||||||
{
|
{
|
||||||
status = st103_ep_get_tx_status (endpoint);
|
status = st103_ep_get_tx_status (endpoint);
|
||||||
if (status == 0) /* Disabled */
|
if (status == 0) /* Disabled */
|
||||||
@@ -539,13 +541,13 @@ static int std_get_status (uint8_t req, struct control_info *detail)
|
|||||||
status_info |= 1; /* OUT Endpoint stalled */
|
status_info |= 1; /* OUT Endpoint stalled */
|
||||||
}
|
}
|
||||||
|
|
||||||
return usb_lld_reply_request (&status_info, 2, detail);
|
return usb_lld_reply_request (&status_info, 2, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int std_clear_feature (uint8_t req, struct control_info *detail)
|
static int std_clear_feature (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t rcp = req & RECIPIENT;
|
uint8_t rcp = req & RECIPIENT;
|
||||||
|
|
||||||
@@ -554,10 +556,10 @@ static int std_clear_feature (uint8_t req, struct control_info *detail)
|
|||||||
|
|
||||||
if (rcp == DEVICE_RECIPIENT)
|
if (rcp == DEVICE_RECIPIENT)
|
||||||
{
|
{
|
||||||
if (detail->len != 0 || detail->index != 0)
|
if (arg->len != 0 || arg->index != 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (detail->value == DEVICE_REMOTE_WAKEUP)
|
if (arg->value == DEVICE_REMOTE_WAKEUP)
|
||||||
{
|
{
|
||||||
dev_p->current_feature &= ~(1 << 5);
|
dev_p->current_feature &= ~(1 << 5);
|
||||||
return USB_SUCCESS;
|
return USB_SUCCESS;
|
||||||
@@ -565,17 +567,17 @@ static int std_clear_feature (uint8_t req, struct control_info *detail)
|
|||||||
}
|
}
|
||||||
else if (rcp == ENDPOINT_RECIPIENT)
|
else if (rcp == ENDPOINT_RECIPIENT)
|
||||||
{
|
{
|
||||||
uint8_t endpoint = (detail->index & 0x0f);
|
uint8_t endpoint = (arg->index & 0x0f);
|
||||||
uint16_t status;
|
uint16_t status;
|
||||||
|
|
||||||
if (dev_p->current_configuration == 0)
|
if (dev_p->current_configuration == 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (detail->len != 0 || (detail->index >> 8) != 0
|
if (arg->len != 0 || (arg->index >> 8) != 0
|
||||||
|| detail->value != ENDPOINT_STALL || endpoint == ENDP0)
|
|| arg->value != ENDPOINT_STALL || endpoint == ENDP0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if ((detail->index & 0x80))
|
if ((arg->index & 0x80))
|
||||||
status = st103_ep_get_tx_status (endpoint);
|
status = st103_ep_get_tx_status (endpoint);
|
||||||
else
|
else
|
||||||
status = st103_ep_get_rx_status (endpoint);
|
status = st103_ep_get_rx_status (endpoint);
|
||||||
@@ -583,7 +585,7 @@ static int std_clear_feature (uint8_t req, struct control_info *detail)
|
|||||||
if (status == 0) /* Disabled */
|
if (status == 0) /* Disabled */
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (detail->index & 0x80) /* IN endpoint */
|
if (arg->index & 0x80) /* IN endpoint */
|
||||||
st103_ep_clear_dtog_tx (endpoint);
|
st103_ep_clear_dtog_tx (endpoint);
|
||||||
else /* OUT endpoint */
|
else /* OUT endpoint */
|
||||||
st103_ep_clear_dtog_rx (endpoint);
|
st103_ep_clear_dtog_rx (endpoint);
|
||||||
@@ -595,7 +597,7 @@ static int std_clear_feature (uint8_t req, struct control_info *detail)
|
|||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int std_set_feature (uint8_t req, struct control_info *detail)
|
static int std_set_feature (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t rcp = req & RECIPIENT;
|
uint8_t rcp = req & RECIPIENT;
|
||||||
|
|
||||||
@@ -604,10 +606,10 @@ static int std_set_feature (uint8_t req, struct control_info *detail)
|
|||||||
|
|
||||||
if (rcp == DEVICE_RECIPIENT)
|
if (rcp == DEVICE_RECIPIENT)
|
||||||
{
|
{
|
||||||
if (detail->len != 0 || detail->index != 0)
|
if (arg->len != 0 || arg->index != 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (detail->value == DEVICE_REMOTE_WAKEUP)
|
if (arg->value == DEVICE_REMOTE_WAKEUP)
|
||||||
{
|
{
|
||||||
dev_p->current_feature |= 1 << 5;
|
dev_p->current_feature |= 1 << 5;
|
||||||
// event??
|
// event??
|
||||||
@@ -616,17 +618,17 @@ static int std_set_feature (uint8_t req, struct control_info *detail)
|
|||||||
}
|
}
|
||||||
else if (rcp == ENDPOINT_RECIPIENT)
|
else if (rcp == ENDPOINT_RECIPIENT)
|
||||||
{
|
{
|
||||||
uint8_t endpoint = (detail->index & 0x0f);
|
uint8_t endpoint = (arg->index & 0x0f);
|
||||||
uint32_t status;
|
uint32_t status;
|
||||||
|
|
||||||
if (dev_p->current_configuration == 0)
|
if (dev_p->current_configuration == 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (detail->len != 0 || (detail->index >> 8) != 0
|
if (arg->len != 0 || (arg->index >> 8) != 0
|
||||||
|| detail->value != 0 || endpoint == ENDP0)
|
|| arg->value != 0 || endpoint == ENDP0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if ((detail->index & 0x80))
|
if ((arg->index & 0x80))
|
||||||
status = st103_ep_get_tx_status (endpoint);
|
status = st103_ep_get_tx_status (endpoint);
|
||||||
else
|
else
|
||||||
status = st103_ep_get_rx_status (endpoint);
|
status = st103_ep_get_rx_status (endpoint);
|
||||||
@@ -634,7 +636,7 @@ static int std_set_feature (uint8_t req, struct control_info *detail)
|
|||||||
if (status == 0) /* Disabled */
|
if (status == 0) /* Disabled */
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (detail->index & 0x80)
|
if (arg->index & 0x80)
|
||||||
/* IN endpoint */
|
/* IN endpoint */
|
||||||
st103_ep_set_tx_status (endpoint, EP_TX_STALL);
|
st103_ep_set_tx_status (endpoint, EP_TX_STALL);
|
||||||
else
|
else
|
||||||
@@ -648,59 +650,58 @@ static int std_set_feature (uint8_t req, struct control_info *detail)
|
|||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int std_set_address (uint8_t req, struct control_info *detail)
|
static int std_set_address (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t rcp = req & RECIPIENT;
|
uint8_t rcp = req & RECIPIENT;
|
||||||
|
|
||||||
if ((req & REQUEST_DIR) == 1)
|
if ((req & REQUEST_DIR) == 1)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (rcp == DEVICE_RECIPIENT && detail->len == 0 && detail->value <= 127
|
if (rcp == DEVICE_RECIPIENT && arg->len == 0 && arg->value <= 127
|
||||||
&& detail->index == 0 && dev_p->current_configuration == 0)
|
&& arg->index == 0 && dev_p->current_configuration == 0)
|
||||||
return USB_SUCCESS;
|
return USB_SUCCESS;
|
||||||
|
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int std_get_descriptor (uint8_t req, struct control_info *detail)
|
static int std_get_descriptor (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t rcp = req & RECIPIENT;
|
uint8_t rcp = req & RECIPIENT;
|
||||||
|
|
||||||
if ((req & REQUEST_DIR) == 0)
|
if ((req & REQUEST_DIR) == 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
return usb_cb_get_descriptor (rcp, (detail->value >> 8),
|
return usb_cb_get_descriptor (rcp, (arg->value >> 8),
|
||||||
(detail->value & 0xff), detail);
|
(arg->value & 0xff), arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int std_get_configuration (uint8_t req, struct control_info *detail)
|
static int std_get_configuration (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t rcp = req & RECIPIENT;
|
uint8_t rcp = req & RECIPIENT;
|
||||||
|
|
||||||
(void)detail;
|
|
||||||
if ((req & REQUEST_DIR) == 0)
|
if ((req & REQUEST_DIR) == 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (rcp == DEVICE_RECIPIENT)
|
if (rcp == DEVICE_RECIPIENT)
|
||||||
return usb_lld_reply_request (&dev_p->current_configuration, 1, detail);
|
return usb_lld_reply_request (&dev_p->current_configuration, 1, arg);
|
||||||
|
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int std_set_configuration (uint8_t req, struct control_info *detail)
|
static int std_set_configuration (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t rcp = req & RECIPIENT;
|
uint8_t rcp = req & RECIPIENT;
|
||||||
|
|
||||||
if ((req & REQUEST_DIR) == 1)
|
if ((req & REQUEST_DIR) == 1)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (rcp == DEVICE_RECIPIENT && detail->index == 0 && detail->len == 0)
|
if (rcp == DEVICE_RECIPIENT && arg->index == 0 && arg->len == 0)
|
||||||
return usb_cb_handle_event (USB_EVENT_CONFIG, detail->value);
|
return usb_cb_handle_event (USB_EVENT_CONFIG, arg->value);
|
||||||
|
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int std_get_interface (uint8_t req, struct control_info *detail)
|
static int std_get_interface (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t rcp = req & RECIPIENT;
|
uint8_t rcp = req & RECIPIENT;
|
||||||
|
|
||||||
@@ -709,35 +710,34 @@ static int std_get_interface (uint8_t req, struct control_info *detail)
|
|||||||
|
|
||||||
if (rcp == INTERFACE_RECIPIENT)
|
if (rcp == INTERFACE_RECIPIENT)
|
||||||
{
|
{
|
||||||
if (detail->value != 0 || (detail->index >> 8) != 0 || detail->len != 1)
|
if (arg->value != 0 || (arg->index >> 8) != 0 || arg->len != 1)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (dev_p->current_configuration == 0)
|
if (dev_p->current_configuration == 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
return usb_cb_interface (USB_GET_INTERFACE, detail);
|
return usb_cb_interface (USB_GET_INTERFACE, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int std_set_interface (uint8_t req, struct control_info *detail)
|
static int std_set_interface (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t rcp = req & RECIPIENT;
|
uint8_t rcp = req & RECIPIENT;
|
||||||
|
|
||||||
if ((req & REQUEST_DIR) == 1 || rcp != INTERFACE_RECIPIENT
|
if ((req & REQUEST_DIR) == 1 || rcp != INTERFACE_RECIPIENT
|
||||||
|| detail->len != 0 || (detail->index >> 8) != 0
|
|| arg->len != 0 || (arg->index >> 8) != 0
|
||||||
|| (detail->value >> 8) != 0 || dev_p->current_configuration == 0)
|
|| (arg->value >> 8) != 0 || dev_p->current_configuration == 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
return usb_cb_interface (USB_SET_INTERFACE, detail);
|
return usb_cb_interface (USB_SET_INTERFACE, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void handle_setup0 (void)
|
static void handle_setup0 (void)
|
||||||
{
|
{
|
||||||
const uint16_t *pw;
|
const uint16_t *pw;
|
||||||
struct control_info ctrl;
|
|
||||||
uint16_t w;
|
uint16_t w;
|
||||||
uint8_t req_no;
|
uint8_t req_no;
|
||||||
int r = USB_UNSUPPORT;
|
int r = USB_UNSUPPORT;
|
||||||
@@ -749,11 +749,11 @@ static void handle_setup0 (void)
|
|||||||
dev_p->bmRequestType = w & 0xff;
|
dev_p->bmRequestType = w & 0xff;
|
||||||
dev_p->bRequest = req_no = w >> 8;
|
dev_p->bRequest = req_no = w >> 8;
|
||||||
pw++;
|
pw++;
|
||||||
ctrl.value = *pw++;
|
dev_p->value = *pw++;
|
||||||
pw++;
|
pw++;
|
||||||
ctrl.index = *pw++;
|
dev_p->index = *pw++;
|
||||||
pw++;
|
pw++;
|
||||||
ctrl.len = *pw;
|
dev_p->len = *pw;
|
||||||
|
|
||||||
data_p->addr = NULL;
|
data_p->addr = NULL;
|
||||||
data_p->len = 0;
|
data_p->len = 0;
|
||||||
@@ -777,11 +777,13 @@ static void handle_setup0 (void)
|
|||||||
default: handler = std_none; break;
|
default: handler = std_none; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = (*handler) (dev_p->bmRequestType, &ctrl);
|
r = (*handler) (dev_p->bmRequestType,
|
||||||
|
(struct req_args *)&dev_p->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
r = usb_cb_setup (dev_p->bmRequestType, req_no, &ctrl);
|
r = usb_cb_setup (dev_p->bmRequestType, req_no,
|
||||||
|
(struct req_args *)&dev_p->value);
|
||||||
|
|
||||||
if (r != USB_SUCCESS)
|
if (r != USB_SUCCESS)
|
||||||
dev_p->state = STALLED;
|
dev_p->state = STALLED;
|
||||||
@@ -789,8 +791,7 @@ static void handle_setup0 (void)
|
|||||||
{
|
{
|
||||||
if (USB_SETUP_SET (dev_p->bmRequestType))
|
if (USB_SETUP_SET (dev_p->bmRequestType))
|
||||||
{
|
{
|
||||||
dev_p->value = ctrl.value;
|
if (dev_p->len == 0)
|
||||||
if (ctrl.len == 0)
|
|
||||||
{
|
{
|
||||||
dev_p->state = WAIT_STATUS_IN;
|
dev_p->state = WAIT_STATUS_IN;
|
||||||
st103_set_tx_count (ENDP0, 0);
|
st103_set_tx_count (ENDP0, 0);
|
||||||
@@ -820,7 +821,7 @@ static void handle_in0 (void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
usb_cb_ctrl_write_finish (dev_p->bmRequestType, dev_p->bRequest,
|
usb_cb_ctrl_write_finish (dev_p->bmRequestType, dev_p->bRequest,
|
||||||
dev_p->value);
|
(struct req_args *)&dev_p->value);
|
||||||
|
|
||||||
dev_p->state = STALLED;
|
dev_p->state = STALLED;
|
||||||
}
|
}
|
||||||
@@ -1042,9 +1043,9 @@ void usb_lld_set_feature (uint8_t feature)
|
|||||||
dev_p->current_feature = feature;
|
dev_p->current_feature = feature;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_lld_set_data_to_recv (const void *p, size_t len)
|
void usb_lld_set_data_to_recv (void *p, size_t len)
|
||||||
{
|
{
|
||||||
data_p->addr = (uint8_t *)p;
|
data_p->addr = p;
|
||||||
data_p->len = len;
|
data_p->len = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1129,7 +1130,7 @@ void usb_lld_from_pmabuf (void *dst, uint16_t addr, size_t n)
|
|||||||
* BUFLEN: size of the data.
|
* BUFLEN: size of the data.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
usb_lld_reply_request (const void *buf, size_t buflen, struct control_info *ctl)
|
usb_lld_reply_request (const void *buf, size_t buflen, struct req_args *ctl)
|
||||||
{
|
{
|
||||||
uint32_t len_asked = ctl->len;
|
uint32_t len_asked = ctl->len;
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
|
|||||||
Reference in New Issue
Block a user