usb: make strings "const char * const *"

This allows the pointer table to be in Flash, by using
"static const char * const strings[] = { ... };"

See https://github.com/libopencm3/libopencm3/pull/924
This commit is contained in:
David Lamparter 2018-03-31 02:54:00 +02:00 committed by Karl Palsson
parent fa7a908027
commit 343cff4675
3 changed files with 13 additions and 4 deletions

View File

@ -77,17 +77,26 @@ extern const usbd_driver efm32hg_usb_driver;
* not be changed while the device is in use. The length of this
* array is determined by the bNumConfigurations field in the
* device descriptor.
* @param strings TODO
* @param strings Pointer to an array of strings for USB string descriptors.
* Referenced in @e iSomething fields, e.g. @a iManufacturer.
* Since a zero index means "no string", an iSomething value of
* 1 refers strings[0].
* @param num_strings Number of items in @a strings array.
* @param control_buffer Pointer to array that would hold the data
* received during control requests with DATA
* stage
* @param control_buffer_size Size of control_buffer
* @return the usb device initialized for use. (currently cannot fail).
*
* To place @a strings entirely into Flash/read-only memory, use
* @code static const * const strings[] = { ... }; @endcode
* (note the double @e const.) The first @e const refers to the strings
* while the second @e const refers to the array.
*/
extern usbd_device * usbd_init(const usbd_driver *driver,
const struct usb_device_descriptor *dev,
const struct usb_config_descriptor *conf,
const char **strings, int num_strings,
const char * const *strings, int num_strings,
uint8_t *control_buffer,
uint16_t control_buffer_size);

View File

@ -42,7 +42,7 @@ LGPL License Terms @ref lgpl_license
usbd_device *usbd_init(const usbd_driver *driver,
const struct usb_device_descriptor *dev,
const struct usb_config_descriptor *conf,
const char **strings, int num_strings,
const char * const *strings, int num_strings,
uint8_t *control_buffer, uint16_t control_buffer_size)
{
usbd_device *usbd_dev;

View File

@ -47,7 +47,7 @@ LGPL License Terms @ref lgpl_license
struct _usbd_device {
const struct usb_device_descriptor *desc;
const struct usb_config_descriptor *config;
const char **strings;
const char * const *strings;
int num_strings;
uint8_t *ctrl_buf; /**< Internal buffer used for control transfers */