Standardized function parameter with xxx_class
This commit is contained in:
@@ -35,7 +35,7 @@ static uint32_t g_devinuse = 0;
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int usbh_cdc_acm_devno_alloc(struct usbh_cdc_acm *priv)
|
||||
static int usbh_cdc_acm_devno_alloc(struct usbh_cdc_acm *cdc_acm_class)
|
||||
{
|
||||
size_t flags;
|
||||
int devno;
|
||||
@@ -45,7 +45,7 @@ static int usbh_cdc_acm_devno_alloc(struct usbh_cdc_acm *priv)
|
||||
uint32_t bitno = 1 << devno;
|
||||
if ((g_devinuse & bitno) == 0) {
|
||||
g_devinuse |= bitno;
|
||||
priv->minor = devno;
|
||||
cdc_acm_class->minor = devno;
|
||||
usb_osal_leave_critical_section(flags);
|
||||
return 0;
|
||||
}
|
||||
@@ -63,9 +63,9 @@ static int usbh_cdc_acm_devno_alloc(struct usbh_cdc_acm *priv)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void usbh_cdc_acm_devno_free(struct usbh_cdc_acm *priv)
|
||||
static void usbh_cdc_acm_devno_free(struct usbh_cdc_acm *cdc_acm_class)
|
||||
{
|
||||
int devno = priv->minor;
|
||||
int devno = cdc_acm_class->minor;
|
||||
|
||||
if (devno >= 0 && devno < 32) {
|
||||
size_t flags = usb_osal_enter_critical_section();
|
||||
@@ -74,25 +74,18 @@ static void usbh_cdc_acm_devno_free(struct usbh_cdc_acm *priv)
|
||||
}
|
||||
}
|
||||
|
||||
int usbh_cdc_acm_set_line_coding(struct usbh_hubport *hport, uint8_t intf, struct cdc_line_coding *line_coding)
|
||||
int usbh_cdc_acm_set_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_line_coding *line_coding)
|
||||
{
|
||||
struct usb_setup_packet *setup = cdc_acm_class->hport->setup;
|
||||
int ret;
|
||||
struct usb_setup_packet *setup;
|
||||
struct usbh_cdc_acm *cdc_acm_class = (struct usbh_cdc_acm *)hport->config.intf[intf].priv;
|
||||
|
||||
setup = hport->setup;
|
||||
|
||||
if (cdc_acm_class->ctrl_intf != intf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = CDC_REQUEST_SET_LINE_CODING;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = intf;
|
||||
setup->wIndex = cdc_acm_class->ctrl_intf;
|
||||
setup->wLength = 7;
|
||||
|
||||
ret = usbh_control_transfer(hport->ep0, setup, (uint8_t *)line_coding);
|
||||
ret = usbh_control_transfer(cdc_acm_class->hport->ep0, setup, (uint8_t *)line_coding);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
@@ -100,25 +93,18 @@ int usbh_cdc_acm_set_line_coding(struct usbh_hubport *hport, uint8_t intf, struc
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbh_cdc_acm_get_line_coding(struct usbh_hubport *hport, uint8_t intf, struct cdc_line_coding *line_coding)
|
||||
int usbh_cdc_acm_get_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_line_coding *line_coding)
|
||||
{
|
||||
struct usb_setup_packet *setup = cdc_acm_class->hport->setup;
|
||||
int ret;
|
||||
struct usb_setup_packet *setup;
|
||||
struct usbh_cdc_acm *cdc_acm_class = (struct usbh_cdc_acm *)hport->config.intf[intf].priv;
|
||||
|
||||
setup = hport->setup;
|
||||
|
||||
if (cdc_acm_class->ctrl_intf != intf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = CDC_REQUEST_GET_LINE_CODING;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = intf;
|
||||
setup->wIndex = cdc_acm_class->ctrl_intf;
|
||||
setup->wLength = 7;
|
||||
|
||||
ret = usbh_control_transfer(hport->ep0, setup, (uint8_t *)line_coding);
|
||||
ret = usbh_control_transfer(cdc_acm_class->hport->ep0, setup, (uint8_t *)line_coding);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
@@ -126,25 +112,18 @@ int usbh_cdc_acm_get_line_coding(struct usbh_hubport *hport, uint8_t intf, struc
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbh_cdc_acm_set_line_state(struct usbh_hubport *hport, uint8_t intf, bool dtr, bool rts)
|
||||
int usbh_cdc_acm_set_line_state(struct usbh_cdc_acm *cdc_acm_class, bool dtr, bool rts)
|
||||
{
|
||||
struct usb_setup_packet *setup = cdc_acm_class->hport->setup;
|
||||
int ret;
|
||||
struct usb_setup_packet *setup;
|
||||
struct usbh_cdc_acm *cdc_acm_class = (struct usbh_cdc_acm *)hport->config.intf[intf].priv;
|
||||
|
||||
setup = hport->setup;
|
||||
|
||||
if (cdc_acm_class->ctrl_intf != intf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = CDC_REQUEST_SET_CONTROL_LINE_STATE;
|
||||
setup->wValue = (dtr << 0) | (rts << 1);
|
||||
setup->wIndex = intf;
|
||||
setup->wIndex = cdc_acm_class->ctrl_intf;
|
||||
setup->wLength = 0;
|
||||
|
||||
ret = usbh_control_transfer(hport->ep0, setup, NULL);
|
||||
ret = usbh_control_transfer(cdc_acm_class->hport->ep0, setup, NULL);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
@@ -155,7 +134,7 @@ int usbh_cdc_acm_set_line_state(struct usbh_hubport *hport, uint8_t intf, bool d
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbh_cdc_acm_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
static int usbh_cdc_acm_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
struct usbh_endpoint_cfg ep_cfg = { 0 };
|
||||
struct usb_endpoint_descriptor *ep_desc;
|
||||
@@ -169,6 +148,8 @@ int usbh_cdc_acm_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
|
||||
memset(cdc_acm_class, 0, sizeof(struct usbh_cdc_acm));
|
||||
cdc_acm_class->hport = hport;
|
||||
cdc_acm_class->ctrl_intf = intf;
|
||||
cdc_acm_class->data_intf = intf + 1;
|
||||
|
||||
usbh_cdc_acm_devno_alloc(cdc_acm_class);
|
||||
snprintf(hport->config.intf[intf].devname, CONFIG_USBHOST_DEV_NAMELEN, DEV_FORMAT, cdc_acm_class->minor);
|
||||
@@ -181,19 +162,17 @@ int usbh_cdc_acm_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
USB_LOG_ERR("Fail to alloc linecoding\r\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
cdc_acm_class->ctrl_intf = intf;
|
||||
cdc_acm_class->data_intf = intf + 1;
|
||||
|
||||
cdc_acm_class->linecoding->dwDTERate = 115200;
|
||||
cdc_acm_class->linecoding->bDataBits = 8;
|
||||
cdc_acm_class->linecoding->bParityType = 0;
|
||||
cdc_acm_class->linecoding->bCharFormat = 0;
|
||||
ret = usbh_cdc_acm_set_line_coding(hport, intf, cdc_acm_class->linecoding);
|
||||
ret = usbh_cdc_acm_set_line_coding(cdc_acm_class, cdc_acm_class->linecoding);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = usbh_cdc_acm_set_line_state(hport, intf, true, true);
|
||||
ret = usbh_cdc_acm_set_line_state(cdc_acm_class, true, true);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
@@ -230,7 +209,7 @@ int usbh_cdc_acm_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int usbh_cdc_acm_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
static int usbh_cdc_acm_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
|
||||
@@ -45,6 +45,10 @@ struct usbh_cdc_acm {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int usbh_cdc_acm_set_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_line_coding *line_coding);
|
||||
int usbh_cdc_acm_get_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_line_coding *line_coding);
|
||||
int usbh_cdc_acm_set_line_state(struct usbh_cdc_acm *cdc_acm_class, bool dtr, bool rts);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user