lisa-m/usb_cdcacm: Coding-style/whitespace fixes.
This commit is contained in:
parent
f23d9d07b7
commit
b1819507b7
@ -24,25 +24,27 @@
|
|||||||
#include <libopencm3/usb/cdc.h>
|
#include <libopencm3/usb/cdc.h>
|
||||||
|
|
||||||
static const struct usb_device_descriptor dev = {
|
static const struct usb_device_descriptor dev = {
|
||||||
.bLength = USB_DT_DEVICE_SIZE,
|
.bLength = USB_DT_DEVICE_SIZE,
|
||||||
.bDescriptorType = USB_DT_DEVICE,
|
.bDescriptorType = USB_DT_DEVICE,
|
||||||
.bcdUSB = 0x0200,
|
.bcdUSB = 0x0200,
|
||||||
.bDeviceClass = USB_CLASS_CDC,
|
.bDeviceClass = USB_CLASS_CDC,
|
||||||
.bDeviceSubClass = 0,
|
.bDeviceSubClass = 0,
|
||||||
.bDeviceProtocol = 0,
|
.bDeviceProtocol = 0,
|
||||||
.bMaxPacketSize0 = 64,
|
.bMaxPacketSize0 = 64,
|
||||||
.idVendor = 0x0483,
|
.idVendor = 0x0483,
|
||||||
.idProduct = 0x5740,
|
.idProduct = 0x5740,
|
||||||
.bcdDevice = 0x0200,
|
.bcdDevice = 0x0200,
|
||||||
.iManufacturer = 1,
|
.iManufacturer = 1,
|
||||||
.iProduct = 2,
|
.iProduct = 2,
|
||||||
.iSerialNumber = 3,
|
.iSerialNumber = 3,
|
||||||
.bNumConfigurations = 1,
|
.bNumConfigurations = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* This notification endpoint isn't implemented. According to CDC spec its
|
/*
|
||||||
* optional, but its absence causes a NULL pointer dereference in Linux cdc_acm
|
* This notification endpoint isn't implemented. According to CDC spec it's
|
||||||
* driver. */
|
* optional, but its absence causes a NULL pointer dereference in the
|
||||||
|
* Linux cdc_acm driver.
|
||||||
|
*/
|
||||||
static const struct usb_endpoint_descriptor comm_endp[] = {{
|
static const struct usb_endpoint_descriptor comm_endp[] = {{
|
||||||
.bLength = USB_DT_ENDPOINT_SIZE,
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
||||||
.bDescriptorType = USB_DT_ENDPOINT,
|
.bDescriptorType = USB_DT_ENDPOINT,
|
||||||
@ -81,7 +83,7 @@ static const struct {
|
|||||||
.bcdCDC = 0x0110,
|
.bcdCDC = 0x0110,
|
||||||
},
|
},
|
||||||
.call_mgmt = {
|
.call_mgmt = {
|
||||||
.bFunctionLength =
|
.bFunctionLength =
|
||||||
sizeof(struct usb_cdc_call_management_descriptor),
|
sizeof(struct usb_cdc_call_management_descriptor),
|
||||||
.bDescriptorType = CS_INTERFACE,
|
.bDescriptorType = CS_INTERFACE,
|
||||||
.bDescriptorSubtype = USB_CDC_TYPE_CALL_MANAGEMENT,
|
.bDescriptorSubtype = USB_CDC_TYPE_CALL_MANAGEMENT,
|
||||||
@ -99,7 +101,7 @@ static const struct {
|
|||||||
.bDescriptorType = CS_INTERFACE,
|
.bDescriptorType = CS_INTERFACE,
|
||||||
.bDescriptorSubtype = USB_CDC_TYPE_UNION,
|
.bDescriptorSubtype = USB_CDC_TYPE_UNION,
|
||||||
.bControlInterface = 0,
|
.bControlInterface = 0,
|
||||||
.bSubordinateInterface0 = 1,
|
.bSubordinateInterface0 = 1,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -159,10 +161,10 @@ static const char *usb_strings[] = {
|
|||||||
"x",
|
"x",
|
||||||
"Black Sphere Technologies",
|
"Black Sphere Technologies",
|
||||||
"CDC-ACM Demo",
|
"CDC-ACM Demo",
|
||||||
"DEMO"
|
"DEMO",
|
||||||
};
|
};
|
||||||
|
|
||||||
static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
|
static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
|
||||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
u16 *len, void (**complete)(struct usb_setup_data *req))
|
||||||
{
|
{
|
||||||
(void)complete;
|
(void)complete;
|
||||||
@ -170,13 +172,15 @@ static int cdcacm_control_request(struct usb_setup_data *req, u8 **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
|
/*
|
||||||
* even though it's optional in the CDC spec, and we don't
|
* This Linux cdc_acm driver requires this to be implemented
|
||||||
* advertise it in the ACM functional descriptor. */
|
* even though it's optional in the CDC spec, and we don't
|
||||||
|
* advertise it in the ACM functional descriptor.
|
||||||
|
*/
|
||||||
char buf[10];
|
char buf[10];
|
||||||
struct usb_cdc_notification *notif = (void*)buf;
|
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;
|
||||||
notif->bNotification = USB_CDC_NOTIFY_SERIAL_STATE;
|
notif->bNotification = USB_CDC_NOTIFY_SERIAL_STATE;
|
||||||
notif->wValue = 0;
|
notif->wValue = 0;
|
||||||
@ -184,11 +188,11 @@ static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
|
|||||||
notif->wLength = 2;
|
notif->wLength = 2;
|
||||||
buf[8] = req->wValue & 3;
|
buf[8] = req->wValue & 3;
|
||||||
buf[9] = 0;
|
buf[9] = 0;
|
||||||
//usbd_ep_write_packet(0x83, buf, 10);
|
// usbd_ep_write_packet(0x83, buf, 10);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
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;
|
||||||
@ -202,8 +206,10 @@ static void cdcacm_data_rx_cb(u8 ep)
|
|||||||
|
|
||||||
char buf[64];
|
char buf[64];
|
||||||
int len = usbd_ep_read_packet(0x01, buf, 64);
|
int len = usbd_ep_read_packet(0x01, buf, 64);
|
||||||
if(len) {
|
|
||||||
while(usbd_ep_write_packet(0x82, buf, len) == 0);
|
if (len) {
|
||||||
|
while (usbd_ep_write_packet(0x82, buf, len) == 0)
|
||||||
|
;
|
||||||
buf[len] = 0;
|
buf[len] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,7 +225,7 @@ static void cdcacm_set_config(u16 wValue)
|
|||||||
usbd_ep_setup(0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
usbd_ep_setup(0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
||||||
|
|
||||||
usbd_register_control_callback(
|
usbd_register_control_callback(
|
||||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||||
cdcacm_control_request);
|
cdcacm_control_request);
|
||||||
}
|
}
|
||||||
@ -228,15 +234,15 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
rcc_clock_setup_in_hsi_out_48mhz();
|
rcc_clock_setup_in_hsi_out_48mhz();
|
||||||
|
|
||||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||||
|
|
||||||
gpio_set(GPIOC, GPIO2);
|
gpio_set(GPIOC, GPIO2);
|
||||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
||||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO2);
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO2);
|
||||||
gpio_set(GPIOC, GPIO5);
|
gpio_set(GPIOC, GPIO5);
|
||||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
||||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO5);
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO5);
|
||||||
|
|
||||||
usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
||||||
@ -246,6 +252,6 @@ int main(void)
|
|||||||
__asm__("nop");
|
__asm__("nop");
|
||||||
gpio_clear(GPIOC, GPIO2);
|
gpio_clear(GPIOC, GPIO2);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
usbd_poll();
|
usbd_poll();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user