subsys: usb: configure Interface descriptor at runtime
Introduce function to configure interface descriptor at runtime. It is simple to leave the corresponding function to configure the interface descriptor and fix bInterfaceNumber and iInterface values, for example. Signed-off-by: Johann Fischer <j.fischer@phytec.de>
This commit is contained in:
parent
bf332d0004
commit
1237549082
3 changed files with 45 additions and 0 deletions
|
@ -105,6 +105,11 @@ typedef void (*usb_ep_callback)(u8_t ep,
|
||||||
typedef int (*usb_request_handler) (struct usb_setup_packet *detup,
|
typedef int (*usb_request_handler) (struct usb_setup_packet *detup,
|
||||||
s32_t *transfer_len, u8_t **payload_data);
|
s32_t *transfer_len, u8_t **payload_data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function for interface runtime configuration
|
||||||
|
*/
|
||||||
|
typedef void (*usb_interface_config)(u8_t bInterfaceNumber);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* USB Endpoint Configuration
|
* USB Endpoint Configuration
|
||||||
*/
|
*/
|
||||||
|
@ -169,6 +174,8 @@ struct usb_cfg_data {
|
||||||
const u8_t *usb_device_description;
|
const u8_t *usb_device_description;
|
||||||
/** Pointer to interface descriptor */
|
/** Pointer to interface descriptor */
|
||||||
const void *interface_descriptor;
|
const void *interface_descriptor;
|
||||||
|
/** Function for interface runtime configuration */
|
||||||
|
usb_interface_config interface_config;
|
||||||
/** Callback to be notified on USB connection status change */
|
/** Callback to be notified on USB connection status change */
|
||||||
usb_status_callback cb_usb_status;
|
usb_status_callback cb_usb_status;
|
||||||
/** USB interface (Class) handler and storage space */
|
/** USB interface (Class) handler and storage space */
|
||||||
|
|
|
@ -174,6 +174,37 @@ static void ascii7_to_utf16le(void *descriptor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Look for the bString that has the address equal to the ptr and
|
||||||
|
* return its index. Use it to determine the index of the bString and
|
||||||
|
* assign it to the interfaces iInterface variable.
|
||||||
|
*/
|
||||||
|
int usb_get_str_descriptor_idx(void *ptr)
|
||||||
|
{
|
||||||
|
struct usb_desc_header *head = __usb_descriptor_start;
|
||||||
|
struct usb_string_descriptor *str = ptr;
|
||||||
|
int str_descr_idx = 0;
|
||||||
|
|
||||||
|
while (head->bLength != 0) {
|
||||||
|
switch (head->bDescriptorType) {
|
||||||
|
case USB_STRING_DESC:
|
||||||
|
if (head == (struct usb_desc_header *)str) {
|
||||||
|
return str_descr_idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
str_descr_idx += 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* move to next descriptor */
|
||||||
|
head = (struct usb_desc_header *)((u8_t *)head + head->bLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Validate endpoint address and Update the endpoint descriptors at runtime,
|
* Validate endpoint address and Update the endpoint descriptors at runtime,
|
||||||
* the result depends on the capabilities of the driver and the number and
|
* the result depends on the capabilities of the driver and the number and
|
||||||
|
@ -294,6 +325,11 @@ static int usb_fix_descriptor(struct usb_desc_header *head)
|
||||||
"for %p", head);
|
"for %p", head);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cfg_data->interface_config) {
|
||||||
|
cfg_data->interface_config(
|
||||||
|
numof_ifaces);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
numof_ifaces++;
|
numof_ifaces++;
|
||||||
|
|
|
@ -120,6 +120,8 @@
|
||||||
*/
|
*/
|
||||||
#define USB_STRING_DESCRIPTOR_LENGTH(s) (sizeof(s) * 2)
|
#define USB_STRING_DESCRIPTOR_LENGTH(s) (sizeof(s) * 2)
|
||||||
|
|
||||||
|
int usb_get_str_descriptor_idx(void *ptr);
|
||||||
|
|
||||||
u8_t *usb_get_device_descriptor(void);
|
u8_t *usb_get_device_descriptor(void);
|
||||||
|
|
||||||
#endif /* __USB_DESCRIPTOR_H__ */
|
#endif /* __USB_DESCRIPTOR_H__ */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue