dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pios_usb_board_data.c
Go to the documentation of this file.
1 
15 /*
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful, but
22  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24  * for more details.
25  *
26  * You should have received a copy of the GNU General Public License along
27  * with this program; if not, see <http://www.gnu.org/licenses/>
28  */
29 
30 #include "pios_usb_board_data.h" /* struct usb_*, USB_* */
31 #include "pios_sys.h" /* PIOS_SYS_SerialNumberGet */
32 #include "pios_usbhook.h" /* PIOS_USBHOOK_* */
33 #include "pios_usb_util.h" /* PIOS_USB_UTIL_AsciiToUtf8 */
34 
35 #define U16_CHARSEQ(val) val, 0,
36 
37 #define U16_CHARS1(val) U16_CHARSEQ(val)
38 #define U16_CHARS2(val, ...) U16_CHARSEQ(val) U16_CHARS1(__VA_ARGS__)
39 #define U16_CHARS3(val, ...) U16_CHARSEQ(val) U16_CHARS2(__VA_ARGS__)
40 #define U16_CHARS4(val, ...) U16_CHARSEQ(val) U16_CHARS3(__VA_ARGS__)
41 #define U16_CHARS5(val, ...) U16_CHARSEQ(val) U16_CHARS4(__VA_ARGS__)
42 #define U16_CHARS6(val, ...) U16_CHARSEQ(val) U16_CHARS5(__VA_ARGS__)
43 #define U16_CHARS7(val, ...) U16_CHARSEQ(val) U16_CHARS6(__VA_ARGS__)
44 #define U16_CHARS8(val, ...) U16_CHARSEQ(val) U16_CHARS7(__VA_ARGS__)
45 #define U16_CHARS9(val, ...) U16_CHARSEQ(val) U16_CHARS8(__VA_ARGS__)
46 #define U16_CHARS10(val, ...) U16_CHARSEQ(val) U16_CHARS9(__VA_ARGS__)
47 #define U16_CHARS11(val, ...) U16_CHARSEQ(val) U16_CHARS10(__VA_ARGS__)
48 #define U16_CHARS12(val, ...) U16_CHARSEQ(val) U16_CHARS11(__VA_ARGS__)
49 #define U16_CHARS13(val, ...) U16_CHARSEQ(val) U16_CHARS12(__VA_ARGS__)
50 #define U16_CHARS14(val, ...) U16_CHARSEQ(val) U16_CHARS13(__VA_ARGS__)
51 #define U16_CHARS15(val, ...) U16_CHARSEQ(val) U16_CHARS14(__VA_ARGS__)
52 #define U16_CHARS16(val, ...) U16_CHARSEQ(val) U16_CHARS15(__VA_ARGS__)
53 #define U16_CHARS17(val, ...) U16_CHARSEQ(val) U16_CHARS16(__VA_ARGS__)
54 
55 #define GENERATE_USB_STRING_IMPL(name, n, ...) static const uint8_t name[n*2+2] = { n*2+2, USB_DESC_TYPE_STRING, U16_CHARS##n(__VA_ARGS__) }
56 #define GENERATE_USB_STRING(name, n, v) GENERATE_USB_STRING_IMPL(name, n, v)
57 
58 GENERATE_USB_STRING(usb_product_id, USB_STR_PROD_LEN, USB_STR_PROD_VAL);
59 GENERATE_USB_STRING(usb_vendor_id, USB_STR_VEND_LEN, USB_STR_VEND_VAL);
60 
62  sizeof(usb_serial_number),
64 };
65 
66 static const struct usb_string_langid usb_lang_id = {
67  .bLength = sizeof(usb_lang_id),
70 };
71 
73 {
74  /* Load device serial number into serial number string */
75  uint8_t sn[PIOS_SYS_SERIAL_NUM_ASCII_LEN + 1];
76  PIOS_SYS_SerialNumberGet((char *)sn);
77 
78  /* Concatenate the device serial number and the appropriate suffix ("+BL" or "+FW") into the USB serial number */
79  uint8_t * utf8 = &(usb_serial_number[2]);
82 
83  PIOS_USBHOOK_RegisterString(USB_STRING_DESC_PRODUCT, (uint8_t *)&usb_product_id, sizeof(usb_product_id));
85 
86  PIOS_USBHOOK_RegisterString(USB_STRING_DESC_LANG, (uint8_t *)&usb_lang_id, sizeof(usb_lang_id));
87  PIOS_USBHOOK_RegisterString(USB_STRING_DESC_VENDOR, (uint8_t *)&usb_vendor_id, sizeof(usb_vendor_id));
88 
89  return 0;
90 }
91 
USB_DESC_TYPE_STRING
Definition: pios_usb_defs.h:43
#define GENERATE_USB_STRING(name, n, v)
static uint8_t usb_serial_number[2+PIOS_SYS_SERIAL_NUM_ASCII_LEN *2+(sizeof(PIOS_USB_BOARD_SN_SUFFIX)-1)*2]
APIs for PIOS_USBHOOK layer.
uint8_t bDescriptorType
Definition: pios_usb_defs.h:42
USB_STRING_DESC_VENDOR
Definition: pios_usbhook.h:37
uint16_t bLangID
Definition: pios_usb_defs.h:43
USB_STRING_DESC_SERIAL
Definition: pios_usbhook.h:39
#define PIOS_SYS_SERIAL_NUM_ASCII_LEN
Definition: pios_sys.h:37
USB_STRING_DESC_LANG
Definition: pios_usbhook.h:36
#define htousbs(v)
Definition: pios_usb_defs.h:77
int32_t PIOS_USB_BOARD_DATA_Init(void)
USB_STRING_DESC_PRODUCT
Definition: pios_usbhook.h:38
void PIOS_USBHOOK_RegisterString(enum usb_string_desc string_id, const uint8_t *desc, uint16_t desc_size)
Definition: pios_usbhook.c:60
static const struct usb_string_langid usb_lang_id
int32_t PIOS_SYS_SerialNumberGet(char str[PIOS_SYS_SERIAL_NUM_ASCII_LEN+1])
uint8_t * PIOS_USB_UTIL_AsciiToUtf8(uint8_t *dst, uint8_t *src, uint16_t srclen)
Definition: pios_usb_util.c:32
USB utility functions.
#define PIOS_USB_BOARD_SN_SUFFIX
#define USB_LANGID_ENGLISH_US