Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/thirdpin/libopencm3.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2018-03-31 03:54:00 +0300
committerKarl Palsson <karlp@tweak.net.au>2018-08-27 16:34:52 +0300
commit343cff467513759e1fdaa28deff0879350ad9c44 (patch)
tree8902ae68abb25d7047722040f30ecbafc7341082
parentfa7a908027370282af163d22a1c426936dd2b6f2 (diff)
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
-rw-r--r--include/libopencm3/usb/usbd.h13
-rw-r--r--lib/usb/usb.c2
-rw-r--r--lib/usb/usb_private.h2
3 files changed, 13 insertions, 4 deletions
diff --git a/include/libopencm3/usb/usbd.h b/include/libopencm3/usb/usbd.h
index 96d2c1d5..fa9af67c 100644
--- a/include/libopencm3/usb/usbd.h
+++ b/include/libopencm3/usb/usbd.h
@@ -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);
diff --git a/lib/usb/usb.c b/lib/usb/usb.c
index a073bc76..cca6dde1 100644
--- a/lib/usb/usb.c
+++ b/lib/usb/usb.c
@@ -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;
diff --git a/lib/usb/usb_private.h b/lib/usb/usb_private.h
index bec2280a..3aa3f9ee 100644
--- a/lib/usb/usb_private.h
+++ b/lib/usb/usb_private.h
@@ -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 */