adapt to new usb interface
This commit is contained in:
parent
963588aba0
commit
586a4740d5
|
@ -171,7 +171,7 @@ static const char *usb_strings[] = {
|
||||||
"DEMO",
|
"DEMO",
|
||||||
};
|
};
|
||||||
|
|
||||||
static int hid_control_read(struct usb_setup_data *req, u8 **buf, u16 *len,
|
static int hid_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||||
void (**complete)(struct usb_setup_data *req))
|
void (**complete)(struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
(void)complete;
|
(void)complete;
|
||||||
|
@ -200,9 +200,12 @@ static void dfu_detach_complete(struct usb_setup_data *req)
|
||||||
scb_reset_core();
|
scb_reset_core();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dfu_control_command(struct usb_setup_data *req,
|
static int dfu_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||||
void (**complete)(struct usb_setup_data *req))
|
void (**complete)(struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
|
(void)buf;
|
||||||
|
(void)len;
|
||||||
|
|
||||||
if((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH))
|
if((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH))
|
||||||
return 0; /* Only accept class request */
|
return 0; /* Only accept class request */
|
||||||
|
|
||||||
|
@ -218,9 +221,15 @@ static void hid_set_config(u16 wValue)
|
||||||
|
|
||||||
usbd_ep_setup(0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL);
|
usbd_ep_setup(0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL);
|
||||||
|
|
||||||
usbd_register_control_read_callback(hid_control_read);
|
usbd_register_control_callback(
|
||||||
|
USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE,
|
||||||
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
|
hid_control_request);
|
||||||
#ifdef INCLUDE_DFU_INTERFACE
|
#ifdef INCLUDE_DFU_INTERFACE
|
||||||
usbd_register_control_command_callback(dfu_control_command);
|
usbd_register_control_callback(
|
||||||
|
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||||
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
|
dfu_control_request);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
|
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
|
||||||
|
|
|
@ -163,18 +163,19 @@ static const char *usb_strings[] = {
|
||||||
"DEMO"
|
"DEMO"
|
||||||
};
|
};
|
||||||
|
|
||||||
static int cdcacm_control_command(struct usb_setup_data *req,
|
static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
|
||||||
void (**complete)(struct usb_setup_data *req))
|
u16 *len, void (**complete)(struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
(void)complete;
|
(void)complete;
|
||||||
char buf[10];
|
(void)buf;
|
||||||
struct usb_cdc_notification *notif = (void*)buf;
|
|
||||||
|
|
||||||
switch(req->bRequest) {
|
switch(req->bRequest) {
|
||||||
case USB_CDC_REQ_SET_CONTROL_LINE_STATE:
|
case USB_CDC_REQ_SET_CONTROL_LINE_STATE: {
|
||||||
/* This Linux cdc_acm driver requires this to be implemented
|
/* This Linux cdc_acm driver requires this to be implemented
|
||||||
* even though it's optional in the CDC spec, and we don't
|
* even though it's optional in the CDC spec, and we don't
|
||||||
* advertise it in the ACM functional descriptor. */
|
* advertise it in the ACM functional descriptor. */
|
||||||
|
char buf[10];
|
||||||
|
struct usb_cdc_notification *notif = (void*)buf;
|
||||||
|
|
||||||
/* We echo signals back to host as notification */
|
/* We echo signals back to host as notification */
|
||||||
notif->bmRequestType = 0xA1;
|
notif->bmRequestType = 0xA1;
|
||||||
|
@ -186,19 +187,9 @@ static int cdcacm_control_command(struct usb_setup_data *req,
|
||||||
buf[9] = 0;
|
buf[9] = 0;
|
||||||
//usbd_ep_write_packet(0x83, buf, 10);
|
//usbd_ep_write_packet(0x83, buf, 10);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int cdcacm_control_write(struct usb_setup_data *req, u8 *buf, u16 len,
|
|
||||||
void (**complete)(struct usb_setup_data *req))
|
|
||||||
{
|
|
||||||
(void)complete;
|
|
||||||
(void)buf;
|
|
||||||
|
|
||||||
switch(req->bRequest) {
|
|
||||||
case USB_CDC_REQ_SET_LINE_CODING:
|
case USB_CDC_REQ_SET_LINE_CODING:
|
||||||
if(len < sizeof(struct usb_cdc_line_coding))
|
if(*len < sizeof(struct usb_cdc_line_coding))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -226,8 +217,10 @@ static void cdcacm_set_config(u16 wValue)
|
||||||
usbd_ep_setup(0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
|
usbd_ep_setup(0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
|
||||||
usbd_ep_setup(0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
usbd_ep_setup(0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
||||||
|
|
||||||
usbd_register_control_command_callback(cdcacm_control_command);
|
usbd_register_control_callback(
|
||||||
usbd_register_control_write_callback(cdcacm_control_write);
|
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||||
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
|
cdcacm_control_request);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
|
|
@ -171,7 +171,7 @@ static const char *usb_strings[] = {
|
||||||
"DEMO",
|
"DEMO",
|
||||||
};
|
};
|
||||||
|
|
||||||
static int hid_control_read(struct usb_setup_data *req, u8 **buf, u16 *len,
|
static int hid_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||||
void (**complete)(struct usb_setup_data *req))
|
void (**complete)(struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
(void)complete;
|
(void)complete;
|
||||||
|
@ -200,9 +200,12 @@ static void dfu_detach_complete(struct usb_setup_data *req)
|
||||||
scb_reset_core();
|
scb_reset_core();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dfu_control_command(struct usb_setup_data *req,
|
static int dfu_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||||
void (**complete)(struct usb_setup_data *req))
|
void (**complete)(struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
|
(void)buf;
|
||||||
|
(void)len;
|
||||||
|
|
||||||
if((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH))
|
if((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH))
|
||||||
return 0; /* Only accept class request */
|
return 0; /* Only accept class request */
|
||||||
|
|
||||||
|
@ -218,9 +221,15 @@ static void hid_set_config(u16 wValue)
|
||||||
|
|
||||||
usbd_ep_setup(0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL);
|
usbd_ep_setup(0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL);
|
||||||
|
|
||||||
usbd_register_control_read_callback(hid_control_read);
|
usbd_register_control_callback(
|
||||||
|
USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE,
|
||||||
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
|
hid_control_request);
|
||||||
#ifdef INCLUDE_DFU_INTERFACE
|
#ifdef INCLUDE_DFU_INTERFACE
|
||||||
usbd_register_control_command_callback(dfu_control_command);
|
usbd_register_control_callback(
|
||||||
|
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||||
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
|
dfu_control_request);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
|
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
|
||||||
|
|
Loading…
Reference in New Issue