Merge branch 'master' of github.com:RT-Thread/rt-thread
This commit is contained in:
commit
2a3f223b4e
@ -166,7 +166,7 @@ struct udev_msg
|
|||||||
};
|
};
|
||||||
typedef struct udev_msg* udev_msg_t;
|
typedef struct udev_msg* udev_msg_t;
|
||||||
|
|
||||||
udevice_t rt_usbd_device_create(const char** str);
|
udevice_t rt_usbd_device_create(void);
|
||||||
uconfig_t rt_usbd_config_create(void);
|
uconfig_t rt_usbd_config_create(void);
|
||||||
uclass_t rt_usbd_class_create(udevice_t device, udev_desc_t dev_desc,
|
uclass_t rt_usbd_class_create(udevice_t device, udev_desc_t dev_desc,
|
||||||
uclass_ops_t ops);
|
uclass_ops_t ops);
|
||||||
@ -180,6 +180,7 @@ rt_err_t rt_usbd_post_event(struct udev_msg* msg, rt_size_t size);
|
|||||||
rt_err_t rt_usbd_free_device(udevice_t device);
|
rt_err_t rt_usbd_free_device(udevice_t device);
|
||||||
rt_err_t rt_usbd_device_set_controller(udevice_t device, udcd_t dcd);
|
rt_err_t rt_usbd_device_set_controller(udevice_t device, udcd_t dcd);
|
||||||
rt_err_t rt_usbd_device_set_descriptor(udevice_t device, udev_desc_t dev_desc);
|
rt_err_t rt_usbd_device_set_descriptor(udevice_t device, udev_desc_t dev_desc);
|
||||||
|
rt_err_t rt_usbd_device_set_string(udevice_t device, const char** ustring);
|
||||||
rt_err_t rt_usbd_device_add_config(udevice_t device, uconfig_t cfg);
|
rt_err_t rt_usbd_device_add_config(udevice_t device, uconfig_t cfg);
|
||||||
rt_err_t rt_usbd_config_add_class(uconfig_t cfg, uclass_t cls);
|
rt_err_t rt_usbd_config_add_class(uconfig_t cfg, uclass_t cls);
|
||||||
rt_err_t rt_usbd_class_add_interface(uclass_t cls, uintf_t intf);
|
rt_err_t rt_usbd_class_add_interface(uclass_t cls, uintf_t intf);
|
||||||
|
@ -45,7 +45,7 @@ static struct udevice_descriptor dev_desc =
|
|||||||
USB_STRING_MANU_INDEX, //iManufacturer;
|
USB_STRING_MANU_INDEX, //iManufacturer;
|
||||||
USB_STRING_PRODUCT_INDEX, //iProduct;
|
USB_STRING_PRODUCT_INDEX, //iProduct;
|
||||||
USB_STRING_SERIAL_INDEX, //iSerialNumber;
|
USB_STRING_SERIAL_INDEX, //iSerialNumber;
|
||||||
USB_DYNAMIC, //bNumConfigurations;
|
USB_DYNAMIC, //bNumConfigurations;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* communcation interface descriptor */
|
/* communcation interface descriptor */
|
||||||
@ -66,19 +66,19 @@ const static struct ucdc_comm_descriptor _comm_desc =
|
|||||||
USB_DESC_LENGTH_INTERFACE,
|
USB_DESC_LENGTH_INTERFACE,
|
||||||
USB_DESC_TYPE_INTERFACE,
|
USB_DESC_TYPE_INTERFACE,
|
||||||
USB_DYNAMIC,
|
USB_DYNAMIC,
|
||||||
0x00,
|
0x00,
|
||||||
0x01,
|
0x01,
|
||||||
USB_CDC_CLASS_COMM,
|
USB_CDC_CLASS_COMM,
|
||||||
USB_CDC_SUBCLASS_ACM,
|
USB_CDC_SUBCLASS_ACM,
|
||||||
USB_CDC_PROTOCOL_V25TER,
|
USB_CDC_PROTOCOL_V25TER,
|
||||||
0x00,
|
0x00,
|
||||||
/* Header Functional Descriptor */
|
/* Header Functional Descriptor */
|
||||||
0x05,
|
0x05,
|
||||||
USB_CDC_CS_INTERFACE,
|
USB_CDC_CS_INTERFACE,
|
||||||
USB_CDC_SCS_HEADER,
|
USB_CDC_SCS_HEADER,
|
||||||
0x0110,
|
0x0110,
|
||||||
/* Call Management Functional Descriptor */
|
/* Call Management Functional Descriptor */
|
||||||
0x05,
|
0x05,
|
||||||
USB_CDC_CS_INTERFACE,
|
USB_CDC_CS_INTERFACE,
|
||||||
USB_CDC_SCS_CALL_MGMT,
|
USB_CDC_SCS_CALL_MGMT,
|
||||||
0x00,
|
0x00,
|
||||||
@ -88,13 +88,13 @@ const static struct ucdc_comm_descriptor _comm_desc =
|
|||||||
USB_CDC_CS_INTERFACE,
|
USB_CDC_CS_INTERFACE,
|
||||||
USB_CDC_SCS_ACM,
|
USB_CDC_SCS_ACM,
|
||||||
0x02,
|
0x02,
|
||||||
/* Union Functional Descriptor */
|
/* Union Functional Descriptor */
|
||||||
0x05,
|
0x05,
|
||||||
USB_CDC_CS_INTERFACE,
|
USB_CDC_CS_INTERFACE,
|
||||||
USB_CDC_SCS_UNION,
|
USB_CDC_SCS_UNION,
|
||||||
USB_DYNAMIC,
|
USB_DYNAMIC,
|
||||||
USB_DYNAMIC,
|
USB_DYNAMIC,
|
||||||
/* Endpoint Descriptor */
|
/* Endpoint Descriptor */
|
||||||
USB_DESC_LENGTH_ENDPOINT,
|
USB_DESC_LENGTH_ENDPOINT,
|
||||||
USB_DESC_TYPE_ENDPOINT,
|
USB_DESC_TYPE_ENDPOINT,
|
||||||
USB_DYNAMIC | USB_DIR_IN,
|
USB_DYNAMIC | USB_DIR_IN,
|
||||||
@ -111,27 +111,37 @@ const static struct ucdc_data_descriptor _data_desc =
|
|||||||
USB_DESC_TYPE_INTERFACE,
|
USB_DESC_TYPE_INTERFACE,
|
||||||
USB_DYNAMIC,
|
USB_DYNAMIC,
|
||||||
0x00,
|
0x00,
|
||||||
0x02,
|
0x02,
|
||||||
USB_CDC_CLASS_DATA,
|
USB_CDC_CLASS_DATA,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
/* endpoint, bulk out */
|
/* endpoint, bulk out */
|
||||||
USB_DESC_LENGTH_ENDPOINT,
|
USB_DESC_LENGTH_ENDPOINT,
|
||||||
USB_DESC_TYPE_ENDPOINT,
|
USB_DESC_TYPE_ENDPOINT,
|
||||||
USB_DYNAMIC | USB_DIR_OUT,
|
USB_DYNAMIC | USB_DIR_OUT,
|
||||||
USB_EP_ATTR_BULK,
|
USB_EP_ATTR_BULK,
|
||||||
USB_CDC_BUFSIZE,
|
USB_CDC_BUFSIZE,
|
||||||
0x00,
|
0x00,
|
||||||
/* endpoint, bulk in */
|
/* endpoint, bulk in */
|
||||||
USB_DESC_LENGTH_ENDPOINT,
|
USB_DESC_LENGTH_ENDPOINT,
|
||||||
USB_DESC_TYPE_ENDPOINT,
|
USB_DESC_TYPE_ENDPOINT,
|
||||||
USB_DYNAMIC | USB_DIR_IN,
|
USB_DYNAMIC | USB_DIR_IN,
|
||||||
USB_EP_ATTR_BULK,
|
USB_EP_ATTR_BULK,
|
||||||
USB_CDC_BUFSIZE,
|
USB_CDC_BUFSIZE,
|
||||||
0x00,
|
0x00,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const static char* _ustring[] =
|
||||||
|
{
|
||||||
|
"Language",
|
||||||
|
"RT-Thread Team.",
|
||||||
|
"RTT Virtual Serial",
|
||||||
|
"1.1.0",
|
||||||
|
"Configuration",
|
||||||
|
"Interface",
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function will handle cdc bulk in endpoint request.
|
* This function will handle cdc bulk in endpoint request.
|
||||||
*
|
*
|
||||||
@ -151,7 +161,7 @@ static rt_err_t _ep_in_handler(udevice_t device, uclass_t cls, rt_size_t size)
|
|||||||
mps = eps->ep_in->ep_desc->wMaxPacketSize;
|
mps = eps->ep_in->ep_desc->wMaxPacketSize;
|
||||||
size = RT_RINGBUFFER_SIZE(&tx_ringbuffer);
|
size = RT_RINGBUFFER_SIZE(&tx_ringbuffer);
|
||||||
if(size == 0) return RT_EOK;
|
if(size == 0) return RT_EOK;
|
||||||
|
|
||||||
length = size > mps ? mps : size;
|
length = size > mps ? mps : size;
|
||||||
|
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
@ -178,7 +188,7 @@ static rt_err_t _ep_out_handler(udevice_t device, uclass_t cls, rt_size_t size)
|
|||||||
cdc_eps_t eps;
|
cdc_eps_t eps;
|
||||||
|
|
||||||
RT_ASSERT(device != RT_NULL);
|
RT_ASSERT(device != RT_NULL);
|
||||||
|
|
||||||
eps = (cdc_eps_t)cls->eps;
|
eps = (cdc_eps_t)cls->eps;
|
||||||
/* receive data from USB VCOM */
|
/* receive data from USB VCOM */
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
@ -188,8 +198,8 @@ static rt_err_t _ep_out_handler(udevice_t device, uclass_t cls, rt_size_t size)
|
|||||||
/* notify receive data */
|
/* notify receive data */
|
||||||
rt_hw_serial_isr(&vcom_serial);
|
rt_hw_serial_isr(&vcom_serial);
|
||||||
|
|
||||||
dcd_ep_read(device->dcd, eps->ep_out, eps->ep_out->buffer,
|
dcd_ep_read(device->dcd, eps->ep_out, eps->ep_out->buffer,
|
||||||
eps->ep_out->ep_desc->wMaxPacketSize);
|
eps->ep_out->ep_desc->wMaxPacketSize);
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
@ -223,18 +233,18 @@ static rt_err_t _cdc_get_line_coding(udevice_t device, ureq_t setup)
|
|||||||
{
|
{
|
||||||
struct ucdc_line_coding data;
|
struct ucdc_line_coding data;
|
||||||
rt_uint16_t size;
|
rt_uint16_t size;
|
||||||
|
|
||||||
RT_ASSERT(device != RT_NULL);
|
RT_ASSERT(device != RT_NULL);
|
||||||
RT_ASSERT(setup != RT_NULL);
|
RT_ASSERT(setup != RT_NULL);
|
||||||
|
|
||||||
data.dwDTERate = 115200;
|
data.dwDTERate = 115200;
|
||||||
data.bCharFormat = 0;
|
data.bCharFormat = 0;
|
||||||
data.bDataBits = 8;
|
data.bDataBits = 8;
|
||||||
data.bParityType = 0;
|
data.bParityType = 0;
|
||||||
size = setup->length > 7 ? 7 : setup->length;
|
size = setup->length > 7 ? 7 : setup->length;
|
||||||
|
|
||||||
dcd_ep_write(device->dcd, 0, (void*)&data, size);
|
dcd_ep_write(device->dcd, 0, (void*)&data, size);
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,14 +258,14 @@ static rt_err_t _cdc_get_line_coding(udevice_t device, ureq_t setup)
|
|||||||
*/
|
*/
|
||||||
static rt_err_t _cdc_set_line_coding(udevice_t device, ureq_t setup)
|
static rt_err_t _cdc_set_line_coding(udevice_t device, ureq_t setup)
|
||||||
{
|
{
|
||||||
struct ucdc_line_coding data;
|
struct ucdc_line_coding data;
|
||||||
rt_err_t ret;
|
rt_err_t ret;
|
||||||
|
|
||||||
RT_ASSERT(device != RT_NULL);
|
RT_ASSERT(device != RT_NULL);
|
||||||
RT_ASSERT(setup != RT_NULL);
|
RT_ASSERT(setup != RT_NULL);
|
||||||
|
|
||||||
rt_completion_init(&device->dcd->completion);
|
rt_completion_init(&device->dcd->completion);
|
||||||
|
|
||||||
dcd_ep_read(device->dcd, 0, (void*)&data, setup->length);
|
dcd_ep_read(device->dcd, 0, (void*)&data, setup->length);
|
||||||
|
|
||||||
ret = rt_completion_wait(&device->dcd->completion, 100);
|
ret = rt_completion_wait(&device->dcd->completion, 100);
|
||||||
@ -263,7 +273,7 @@ static rt_err_t _cdc_set_line_coding(udevice_t device, ureq_t setup)
|
|||||||
{
|
{
|
||||||
rt_kprintf("_cdc_set_line_coding timeout\n");
|
rt_kprintf("_cdc_set_line_coding timeout\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,7 +289,7 @@ static rt_err_t _interface_handler(udevice_t device, uclass_t cls, ureq_t setup)
|
|||||||
{
|
{
|
||||||
RT_ASSERT(device != RT_NULL);
|
RT_ASSERT(device != RT_NULL);
|
||||||
RT_ASSERT(setup != RT_NULL);
|
RT_ASSERT(setup != RT_NULL);
|
||||||
|
|
||||||
switch(setup->request)
|
switch(setup->request)
|
||||||
{
|
{
|
||||||
case CDC_SEND_ENCAPSULATED_COMMAND:
|
case CDC_SEND_ENCAPSULATED_COMMAND:
|
||||||
@ -294,13 +304,13 @@ static rt_err_t _interface_handler(udevice_t device, uclass_t cls, ureq_t setup)
|
|||||||
break;
|
break;
|
||||||
case CDC_SET_LINE_CODING:
|
case CDC_SET_LINE_CODING:
|
||||||
_cdc_set_line_coding(device, setup);
|
_cdc_set_line_coding(device, setup);
|
||||||
vcom_connected = RT_TRUE;
|
vcom_connected = RT_TRUE;
|
||||||
break;
|
break;
|
||||||
case CDC_GET_LINE_CODING:
|
case CDC_GET_LINE_CODING:
|
||||||
_cdc_get_line_coding(device, setup);
|
_cdc_get_line_coding(device, setup);
|
||||||
break;
|
break;
|
||||||
case CDC_SET_CONTROL_LINE_STATE:
|
case CDC_SET_CONTROL_LINE_STATE:
|
||||||
dcd_send_status(device->dcd);
|
dcd_send_status(device->dcd);
|
||||||
break;
|
break;
|
||||||
case CDC_SEND_BREAK:
|
case CDC_SEND_BREAK:
|
||||||
break;
|
break;
|
||||||
@ -330,9 +340,9 @@ static rt_err_t _class_run(udevice_t device, uclass_t cls)
|
|||||||
eps->ep_in->buffer=tx_pool;
|
eps->ep_in->buffer=tx_pool;
|
||||||
eps->ep_out->buffer=rx_pool;
|
eps->ep_out->buffer=rx_pool;
|
||||||
|
|
||||||
dcd_ep_read(device->dcd, eps->ep_out, eps->ep_out->buffer,
|
dcd_ep_read(device->dcd, eps->ep_out, eps->ep_out->buffer,
|
||||||
eps->ep_out->ep_desc->wMaxPacketSize);
|
eps->ep_out->ep_desc->wMaxPacketSize);
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,7 +377,7 @@ static rt_err_t _class_sof_handler(udevice_t device, uclass_t cls)
|
|||||||
cdc_eps_t eps;
|
cdc_eps_t eps;
|
||||||
|
|
||||||
if(vcom_connected != RT_TRUE) return -RT_ERROR;
|
if(vcom_connected != RT_TRUE) return -RT_ERROR;
|
||||||
|
|
||||||
eps = (cdc_eps_t)cls->eps;
|
eps = (cdc_eps_t)cls->eps;
|
||||||
if (frame_count ++ == 5)
|
if (frame_count ++ == 5)
|
||||||
{
|
{
|
||||||
@ -380,11 +390,11 @@ static rt_err_t _class_sof_handler(udevice_t device, uclass_t cls)
|
|||||||
if(size == 0) return -RT_EFULL;
|
if(size == 0) return -RT_EFULL;
|
||||||
|
|
||||||
size = size > mps ? mps : size;
|
size = size > mps ? mps : size;
|
||||||
|
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
rt_ringbuffer_get(&tx_ringbuffer, eps->ep_in->buffer, size);
|
rt_ringbuffer_get(&tx_ringbuffer, eps->ep_in->buffer, size);
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
/* send data to host */
|
/* send data to host */
|
||||||
dcd_ep_write(device->dcd, eps->ep_in, eps->ep_in->buffer, size);
|
dcd_ep_write(device->dcd, eps->ep_in, eps->ep_in->buffer, size);
|
||||||
}
|
}
|
||||||
@ -412,7 +422,7 @@ static rt_err_t _cdc_descriptor_config(ucdc_comm_desc_t comm, rt_uint8_t cintf_n
|
|||||||
comm->call_mgmt_desc.data_interface = dintf_nr;
|
comm->call_mgmt_desc.data_interface = dintf_nr;
|
||||||
comm->union_desc.master_interface = cintf_nr;
|
comm->union_desc.master_interface = cintf_nr;
|
||||||
comm->union_desc.slave_interface0 = dintf_nr;
|
comm->union_desc.slave_interface0 = dintf_nr;
|
||||||
#ifdef RT_USB_DEVICE_COMPOSITE
|
#ifdef RT_USB_DEVICE_COMPOSITE
|
||||||
comm->iad_desc.bFirstInterface = cintf_nr;
|
comm->iad_desc.bFirstInterface = cintf_nr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -437,7 +447,9 @@ uclass_t rt_usbd_class_cdc_create(udevice_t device)
|
|||||||
|
|
||||||
/* parameter check */
|
/* parameter check */
|
||||||
RT_ASSERT(device != RT_NULL);
|
RT_ASSERT(device != RT_NULL);
|
||||||
|
|
||||||
|
/* set usb device string description */
|
||||||
|
rt_usbd_device_set_string(device, _ustring);
|
||||||
/* create a cdc class */
|
/* create a cdc class */
|
||||||
cdc = rt_usbd_class_create(device, &dev_desc, &ops);
|
cdc = rt_usbd_class_create(device, &dev_desc, &ops);
|
||||||
/* create a cdc class endpoints collection */
|
/* create a cdc class endpoints collection */
|
||||||
@ -449,12 +461,12 @@ uclass_t rt_usbd_class_cdc_create(udevice_t device)
|
|||||||
intf_data = rt_usbd_interface_create(device, _interface_handler);
|
intf_data = rt_usbd_interface_create(device, _interface_handler);
|
||||||
|
|
||||||
/* create a communication alternate setting and a data alternate setting */
|
/* create a communication alternate setting and a data alternate setting */
|
||||||
comm_setting = rt_usbd_altsetting_create(sizeof(struct ucdc_comm_descriptor));
|
comm_setting = rt_usbd_altsetting_create(sizeof(struct ucdc_comm_descriptor));
|
||||||
data_setting = rt_usbd_altsetting_create(sizeof(struct ucdc_data_descriptor));
|
data_setting = rt_usbd_altsetting_create(sizeof(struct ucdc_data_descriptor));
|
||||||
|
|
||||||
/* config desc in alternate setting */
|
/* config desc in alternate setting */
|
||||||
rt_usbd_altsetting_config_descriptor(comm_setting, &_comm_desc,
|
rt_usbd_altsetting_config_descriptor(comm_setting, &_comm_desc,
|
||||||
(rt_off_t)&((ucdc_comm_desc_t)0)->intf_desc);
|
(rt_off_t)&((ucdc_comm_desc_t)0)->intf_desc);
|
||||||
rt_usbd_altsetting_config_descriptor(data_setting, &_data_desc, 0);
|
rt_usbd_altsetting_config_descriptor(data_setting, &_data_desc, 0);
|
||||||
/* configure the cdc interface descriptor */
|
/* configure the cdc interface descriptor */
|
||||||
_cdc_descriptor_config(comm_setting->desc, intf_comm->intf_num, data_setting->desc, intf_data->intf_num);
|
_cdc_descriptor_config(comm_setting->desc, intf_comm->intf_num, data_setting->desc, intf_data->intf_num);
|
||||||
@ -467,14 +479,14 @@ uclass_t rt_usbd_class_cdc_create(udevice_t device)
|
|||||||
/* add the bulk out and bulk in endpoints to the data alternate setting */
|
/* add the bulk out and bulk in endpoints to the data alternate setting */
|
||||||
rt_usbd_altsetting_add_endpoint(data_setting, eps->ep_in);
|
rt_usbd_altsetting_add_endpoint(data_setting, eps->ep_in);
|
||||||
rt_usbd_altsetting_add_endpoint(data_setting, eps->ep_out);
|
rt_usbd_altsetting_add_endpoint(data_setting, eps->ep_out);
|
||||||
|
|
||||||
/* add the data alternate setting to the data interface
|
/* add the data alternate setting to the data interface
|
||||||
then set default setting of the interface */
|
then set default setting of the interface */
|
||||||
rt_usbd_interface_add_altsetting(intf_data, data_setting);
|
rt_usbd_interface_add_altsetting(intf_data, data_setting);
|
||||||
rt_usbd_set_altsetting(intf_data, 0);
|
rt_usbd_set_altsetting(intf_data, 0);
|
||||||
|
|
||||||
/* add the cdc data interface to cdc class */
|
/* add the cdc data interface to cdc class */
|
||||||
rt_usbd_class_add_interface(cdc, intf_data);
|
rt_usbd_class_add_interface(cdc, intf_data);
|
||||||
|
|
||||||
/* create a command endpoint */
|
/* create a command endpoint */
|
||||||
comm_desc = (ucdc_comm_desc_t)comm_setting->desc;
|
comm_desc = (ucdc_comm_desc_t)comm_setting->desc;
|
||||||
@ -482,14 +494,14 @@ uclass_t rt_usbd_class_cdc_create(udevice_t device)
|
|||||||
|
|
||||||
/* add the command endpoint to the cdc communication interface */
|
/* add the command endpoint to the cdc communication interface */
|
||||||
rt_usbd_altsetting_add_endpoint(comm_setting, eps->ep_cmd);
|
rt_usbd_altsetting_add_endpoint(comm_setting, eps->ep_cmd);
|
||||||
|
|
||||||
/* add the communication alternate setting to the communication interface,
|
/* add the communication alternate setting to the communication interface,
|
||||||
then set default setting of the interface */
|
then set default setting of the interface */
|
||||||
rt_usbd_interface_add_altsetting(intf_comm, comm_setting);
|
rt_usbd_interface_add_altsetting(intf_comm, comm_setting);
|
||||||
rt_usbd_set_altsetting(intf_comm, 0);
|
rt_usbd_set_altsetting(intf_comm, 0);
|
||||||
|
|
||||||
/* add the communication interface to the cdc class */
|
/* add the communication interface to the cdc class */
|
||||||
rt_usbd_class_add_interface(cdc, intf_comm);
|
rt_usbd_class_add_interface(cdc, intf_comm);
|
||||||
|
|
||||||
return cdc;
|
return cdc;
|
||||||
}
|
}
|
||||||
@ -497,14 +509,14 @@ uclass_t rt_usbd_class_cdc_create(udevice_t device)
|
|||||||
/**
|
/**
|
||||||
* UART device in RT-Thread
|
* UART device in RT-Thread
|
||||||
*/
|
*/
|
||||||
static rt_err_t _vcom_configure(struct rt_serial_device *serial,
|
static rt_err_t _vcom_configure(struct rt_serial_device *serial,
|
||||||
struct serial_configure *cfg)
|
struct serial_configure *cfg)
|
||||||
{
|
{
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_err_t _vcom_control(struct rt_serial_device *serial,
|
static rt_err_t _vcom_control(struct rt_serial_device *serial,
|
||||||
int cmd, void *arg)
|
int cmd, void *arg)
|
||||||
{
|
{
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
@ -522,16 +534,16 @@ static rt_err_t _vcom_control(struct rt_serial_device *serial,
|
|||||||
static int _vcom_putc(struct rt_serial_device *serial, char c)
|
static int _vcom_putc(struct rt_serial_device *serial, char c)
|
||||||
{
|
{
|
||||||
rt_uint32_t level;
|
rt_uint32_t level;
|
||||||
|
|
||||||
if (vcom_connected != RT_TRUE) return 0;
|
if (vcom_connected != RT_TRUE) return 0;
|
||||||
|
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
if (RT_RINGBUFFER_EMPTY(&tx_ringbuffer))
|
if (RT_RINGBUFFER_EMPTY(&tx_ringbuffer))
|
||||||
{
|
{
|
||||||
rt_ringbuffer_putchar(&tx_ringbuffer, c);
|
rt_ringbuffer_putchar(&tx_ringbuffer, c);
|
||||||
}
|
}
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -583,8 +595,8 @@ void rt_usb_vcom_init(void)
|
|||||||
|
|
||||||
/* register vcom device */
|
/* register vcom device */
|
||||||
rt_hw_serial_register(&vcom_serial, "vcom",
|
rt_hw_serial_register(&vcom_serial, "vcom",
|
||||||
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
|
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
|
||||||
RT_NULL);
|
RT_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#define STATUS_CBW 0x00
|
#define STATUS_CBW 0x00
|
||||||
#define STATUS_CSW 0x01
|
#define STATUS_CSW 0x01
|
||||||
#define STATUS_RECEIVE 0x02
|
#define STATUS_RECEIVE 0x02
|
||||||
#define STATUS_SEND 0x03
|
#define STATUS_SEND 0x03
|
||||||
|
|
||||||
static int status = STATUS_CBW;
|
static int status = STATUS_CBW;
|
||||||
ALIGN(RT_ALIGN_SIZE)
|
ALIGN(RT_ALIGN_SIZE)
|
||||||
@ -79,6 +79,16 @@ const static struct umass_descriptor _mass_desc =
|
|||||||
0x00, //bInterval;
|
0x00, //bInterval;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const static char* _ustring[] =
|
||||||
|
{
|
||||||
|
"Language",
|
||||||
|
"RT-Thread Team.",
|
||||||
|
"RTT Mass Storage",
|
||||||
|
"1.1.0",
|
||||||
|
"Configuration",
|
||||||
|
"Interface",
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function will allocate an usb device instance from system.
|
* This function will allocate an usb device instance from system.
|
||||||
*
|
*
|
||||||
@ -301,7 +311,7 @@ static rt_err_t _ep_in_handler(udevice_t device, uclass_t cls, rt_size_t size)
|
|||||||
{
|
{
|
||||||
mass_eps_t eps;
|
mass_eps_t eps;
|
||||||
RT_ASSERT(device != RT_NULL);
|
RT_ASSERT(device != RT_NULL);
|
||||||
|
|
||||||
eps = cls->eps;
|
eps = cls->eps;
|
||||||
if(status == STATUS_CSW)
|
if(status == STATUS_CSW)
|
||||||
{
|
{
|
||||||
@ -312,7 +322,7 @@ static rt_err_t _ep_in_handler(udevice_t device, uclass_t cls, rt_size_t size)
|
|||||||
if(status == STATUS_SEND)
|
if(status == STATUS_SEND)
|
||||||
{
|
{
|
||||||
rt_device_read(disk, _block, eps->ep_in->buffer, 1);
|
rt_device_read(disk, _block, eps->ep_in->buffer, 1);
|
||||||
dcd_ep_write(device->dcd, eps->ep_in, eps->ep_in->buffer,
|
dcd_ep_write(device->dcd, eps->ep_in, eps->ep_in->buffer,
|
||||||
geometry.bytes_per_sector);
|
geometry.bytes_per_sector);
|
||||||
_count --;
|
_count --;
|
||||||
if (_count)
|
if (_count)
|
||||||
@ -356,7 +366,7 @@ static rt_err_t _ep_out_handler(udevice_t device, uclass_t cls, rt_size_t size)
|
|||||||
{
|
{
|
||||||
mass_eps_t eps;
|
mass_eps_t eps;
|
||||||
RT_ASSERT(device != RT_NULL);
|
RT_ASSERT(device != RT_NULL);
|
||||||
|
|
||||||
eps = (mass_eps_t)cls->eps;
|
eps = (mass_eps_t)cls->eps;
|
||||||
if(status == STATUS_CBW)
|
if(status == STATUS_CBW)
|
||||||
{
|
{
|
||||||
@ -372,7 +382,7 @@ static rt_err_t _ep_out_handler(udevice_t device, uclass_t cls, rt_size_t size)
|
|||||||
csw.data_reside = 0;
|
csw.data_reside = 0;
|
||||||
csw.status = 0;
|
csw.status = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return -RT_ERROR;
|
return -RT_ERROR;
|
||||||
|
|
||||||
switch(cbw->cb[0])
|
switch(cbw->cb[0])
|
||||||
@ -424,18 +434,18 @@ static rt_err_t _ep_out_handler(udevice_t device, uclass_t cls, rt_size_t size)
|
|||||||
|
|
||||||
_size -= size;
|
_size -= size;
|
||||||
csw.data_reside -= size;
|
csw.data_reside -= size;
|
||||||
|
|
||||||
rt_device_write(disk, _block, eps->ep_in->buffer, 1);
|
rt_device_write(disk, _block, eps->ep_in->buffer, 1);
|
||||||
_block ++;
|
_block ++;
|
||||||
if(_size == 0)
|
if(_size == 0)
|
||||||
{
|
{
|
||||||
dcd_ep_write(device->dcd, eps->ep_in, (rt_uint8_t*)&csw, SIZEOF_CSW);
|
dcd_ep_write(device->dcd, eps->ep_in, (rt_uint8_t*)&csw, SIZEOF_CSW);
|
||||||
dcd_ep_read(device->dcd, eps->ep_out, eps->ep_out->buffer, SIZEOF_CBW);
|
dcd_ep_read(device->dcd, eps->ep_out, eps->ep_out->buffer, SIZEOF_CBW);
|
||||||
status = STATUS_CBW;
|
status = STATUS_CBW;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dcd_ep_read(device->dcd, eps->ep_out, eps->ep_out->buffer,
|
dcd_ep_read(device->dcd, eps->ep_out, eps->ep_out->buffer,
|
||||||
geometry.bytes_per_sector);
|
geometry.bytes_per_sector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -501,7 +511,7 @@ static rt_err_t _class_run(udevice_t device, uclass_t cls)
|
|||||||
{
|
{
|
||||||
rt_kprintf("no disk named %s\n", RT_USB_MSTORAGE_DISK_NAME);
|
rt_kprintf("no disk named %s\n", RT_USB_MSTORAGE_DISK_NAME);
|
||||||
return -RT_ERROR;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
if(rt_device_control(disk, RT_DEVICE_CTRL_BLK_GETGEOME, (void*)&geometry) != RT_EOK)
|
if(rt_device_control(disk, RT_DEVICE_CTRL_BLK_GETGEOME, (void*)&geometry) != RT_EOK)
|
||||||
return -RT_ERROR;
|
return -RT_ERROR;
|
||||||
|
|
||||||
@ -562,24 +572,26 @@ uclass_t rt_usbd_class_mstorage_create(udevice_t device)
|
|||||||
/* parameter check */
|
/* parameter check */
|
||||||
RT_ASSERT(device != RT_NULL);
|
RT_ASSERT(device != RT_NULL);
|
||||||
|
|
||||||
|
/* set usb device string description */
|
||||||
|
rt_usbd_device_set_string(device, _ustring);
|
||||||
/* create a mass storage class */
|
/* create a mass storage class */
|
||||||
mstorage = rt_usbd_class_create(device, &dev_desc, &ops);
|
mstorage = rt_usbd_class_create(device, &dev_desc, &ops);
|
||||||
/* create a mass storage endpoints collection */
|
/* create a mass storage endpoints collection */
|
||||||
eps = (mass_eps_t)rt_malloc(sizeof(struct mass_eps));
|
eps = (mass_eps_t)rt_malloc(sizeof(struct mass_eps));
|
||||||
mstorage->eps = (void*)eps;
|
mstorage->eps = (void*)eps;
|
||||||
|
|
||||||
/* create an interface */
|
/* create an interface */
|
||||||
intf = rt_usbd_interface_create(device, _interface_handler);
|
intf = rt_usbd_interface_create(device, _interface_handler);
|
||||||
|
|
||||||
/* create an alternate setting */
|
/* create an alternate setting */
|
||||||
setting = rt_usbd_altsetting_create(sizeof(struct umass_descriptor));
|
setting = rt_usbd_altsetting_create(sizeof(struct umass_descriptor));
|
||||||
/* config desc in alternate setting */
|
/* config desc in alternate setting */
|
||||||
rt_usbd_altsetting_config_descriptor(setting, &_mass_desc, 0);
|
rt_usbd_altsetting_config_descriptor(setting, &_mass_desc, 0);
|
||||||
|
|
||||||
/* create a bulk out and a bulk in endpoint */
|
/* create a bulk out and a bulk in endpoint */
|
||||||
mass_desc = (umass_desc_t)setting->desc;
|
mass_desc = (umass_desc_t)setting->desc;
|
||||||
eps->ep_in = rt_usbd_endpoint_create(&mass_desc->ep_in_desc, _ep_in_handler);
|
eps->ep_in = rt_usbd_endpoint_create(&mass_desc->ep_in_desc, _ep_in_handler);
|
||||||
eps->ep_out = rt_usbd_endpoint_create(&mass_desc->ep_out_desc, _ep_out_handler);
|
eps->ep_out = rt_usbd_endpoint_create(&mass_desc->ep_out_desc, _ep_out_handler);
|
||||||
|
|
||||||
/* add the bulk out and bulk in endpoint to the alternate setting */
|
/* add the bulk out and bulk in endpoint to the alternate setting */
|
||||||
rt_usbd_altsetting_add_endpoint(setting, eps->ep_out);
|
rt_usbd_altsetting_add_endpoint(setting, eps->ep_out);
|
||||||
|
@ -612,13 +612,10 @@ rt_err_t _sof_notify(udevice_t device)
|
|||||||
*
|
*
|
||||||
* @return an usb device object on success, RT_NULL on fail.
|
* @return an usb device object on success, RT_NULL on fail.
|
||||||
*/
|
*/
|
||||||
udevice_t rt_usbd_device_create(const char** ustring)
|
udevice_t rt_usbd_device_create(void)
|
||||||
{
|
{
|
||||||
udevice_t udevice;
|
udevice_t udevice;
|
||||||
|
|
||||||
/* parameter check */
|
|
||||||
RT_ASSERT(ustring != RT_NULL);
|
|
||||||
|
|
||||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("rt_usbd_device_create\n"));
|
RT_DEBUG_LOG(RT_DEBUG_USB, ("rt_usbd_device_create\n"));
|
||||||
|
|
||||||
/* allocate memory for the object */
|
/* allocate memory for the object */
|
||||||
@ -630,9 +627,6 @@ udevice_t rt_usbd_device_create(const char** ustring)
|
|||||||
}
|
}
|
||||||
rt_memset(udevice, 0, sizeof(struct udevice));
|
rt_memset(udevice, 0, sizeof(struct udevice));
|
||||||
|
|
||||||
/* set string descriptor array to the device object */
|
|
||||||
udevice->str = ustring;
|
|
||||||
|
|
||||||
/* to initialize configuration list */
|
/* to initialize configuration list */
|
||||||
rt_list_init(&udevice->cfg_list);
|
rt_list_init(&udevice->cfg_list);
|
||||||
|
|
||||||
@ -642,6 +636,26 @@ udevice_t rt_usbd_device_create(const char** ustring)
|
|||||||
return udevice;
|
return udevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function will set usb device string description.
|
||||||
|
*
|
||||||
|
* @param device the usb device object.
|
||||||
|
* @param ustring pointer to string pointer array.
|
||||||
|
*
|
||||||
|
* @return RT_EOK.
|
||||||
|
*/
|
||||||
|
rt_err_t rt_usbd_device_set_string(udevice_t device, const char** ustring)
|
||||||
|
{
|
||||||
|
/* parameter check */
|
||||||
|
RT_ASSERT(device != RT_NULL);
|
||||||
|
RT_ASSERT(ustring != RT_NULL);
|
||||||
|
|
||||||
|
/* set string descriptor array to the device object */
|
||||||
|
device->str = ustring;
|
||||||
|
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function will set an usb controller driver to a device.
|
* This function will set an usb controller driver to a device.
|
||||||
*
|
*
|
||||||
|
@ -18,15 +18,17 @@
|
|||||||
|
|
||||||
#ifdef RT_USING_USB_DEVICE
|
#ifdef RT_USING_USB_DEVICE
|
||||||
|
|
||||||
const static char* ustring[] =
|
#ifdef RT_USB_DEVICE_COMPOSITE
|
||||||
|
const static char* ustring[] =
|
||||||
{
|
{
|
||||||
"Language",
|
"Language",
|
||||||
"RT-Thread Team.",
|
"RT-Thread Team.",
|
||||||
"RT-Thread Device",
|
"RTT Composite Device",
|
||||||
"1.1.0",
|
"1.1.0",
|
||||||
"Configuration",
|
"Configuration",
|
||||||
"Interface",
|
"Interface",
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef RT_USB_DEVICE_COMPOSITE
|
#ifdef RT_USB_DEVICE_COMPOSITE
|
||||||
static struct udevice_descriptor compsit_desc =
|
static struct udevice_descriptor compsit_desc =
|
||||||
@ -44,7 +46,7 @@ static struct udevice_descriptor compsit_desc =
|
|||||||
USB_STRING_MANU_INDEX, //iManufacturer;
|
USB_STRING_MANU_INDEX, //iManufacturer;
|
||||||
USB_STRING_PRODUCT_INDEX, //iProduct;
|
USB_STRING_PRODUCT_INDEX, //iProduct;
|
||||||
USB_STRING_SERIAL_INDEX, //iSerialNumber;
|
USB_STRING_SERIAL_INDEX, //iSerialNumber;
|
||||||
USB_DYNAMIC, //bNumConfigurations;
|
USB_DYNAMIC, //bNumConfigurations;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -53,7 +55,7 @@ rt_err_t rt_usb_device_init(const char* udc_name)
|
|||||||
rt_device_t udc;
|
rt_device_t udc;
|
||||||
udevice_t udevice;
|
udevice_t udevice;
|
||||||
uconfig_t cfg;
|
uconfig_t cfg;
|
||||||
uclass_t cls;
|
uclass_t cls;
|
||||||
|
|
||||||
RT_ASSERT(udc_name != RT_NULL);
|
RT_ASSERT(udc_name != RT_NULL);
|
||||||
|
|
||||||
@ -68,8 +70,8 @@ rt_err_t rt_usb_device_init(const char* udc_name)
|
|||||||
rt_usbd_core_init();
|
rt_usbd_core_init();
|
||||||
|
|
||||||
/* create a device object */
|
/* create a device object */
|
||||||
udevice = rt_usbd_device_create(ustring);
|
udevice = rt_usbd_device_create();
|
||||||
|
|
||||||
/* set usb controller driver to the device */
|
/* set usb controller driver to the device */
|
||||||
rt_usbd_device_set_controller(udevice, (udcd_t)udc);
|
rt_usbd_device_set_controller(udevice, (udcd_t)udc);
|
||||||
|
|
||||||
@ -78,7 +80,7 @@ rt_err_t rt_usb_device_init(const char* udc_name)
|
|||||||
|
|
||||||
#ifdef RT_USB_DEVICE_MSTORAGE
|
#ifdef RT_USB_DEVICE_MSTORAGE
|
||||||
/* create a mass storage class object */
|
/* create a mass storage class object */
|
||||||
cls = rt_usbd_class_mstorage_create(udevice);
|
cls = rt_usbd_class_mstorage_create(udevice);
|
||||||
|
|
||||||
/* add the class to the configuration */
|
/* add the class to the configuration */
|
||||||
rt_usbd_config_add_class(cfg, cls);
|
rt_usbd_config_add_class(cfg, cls);
|
||||||
@ -101,13 +103,14 @@ rt_err_t rt_usb_device_init(const char* udc_name)
|
|||||||
/* set device descriptor to the device */
|
/* set device descriptor to the device */
|
||||||
#ifdef RT_USB_DEVICE_COMPOSITE
|
#ifdef RT_USB_DEVICE_COMPOSITE
|
||||||
rt_usbd_device_set_descriptor(udevice, &compsit_desc);
|
rt_usbd_device_set_descriptor(udevice, &compsit_desc);
|
||||||
|
rt_usbd_device_set_string(udevice, ustring);
|
||||||
#else
|
#else
|
||||||
rt_usbd_device_set_descriptor(udevice, cls->dev_desc);
|
rt_usbd_device_set_descriptor(udevice, cls->dev_desc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* add the configuration to the device */
|
/* add the configuration to the device */
|
||||||
rt_usbd_device_add_config(udevice, cfg);
|
rt_usbd_device_add_config(udevice, cfg);
|
||||||
|
|
||||||
/* set default configuration to 1 */
|
/* set default configuration to 1 */
|
||||||
rt_usbd_set_config(udevice, 1);
|
rt_usbd_set_config(udevice, 1);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user