Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / flight / targets / boards / tinyfish / pios_usb_board_data.c
blobbe0bb584e4db7f3e6a957dfdd5ea632ba25a01a9
1 /**
2 ******************************************************************************
3 * @addtogroup PIOS PIOS Core hardware abstraction layer
4 * @{
5 * @addtogroup PIOS_USB_BOARD Board specific USB definitions
6 * @brief Board specific USB definitions
7 * @{
9 * @file pios_usb_board_data.c
10 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017.
11 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
12 * @brief Board specific USB definitions
13 * @see The GNU Public License (GPL) Version 3
15 *****************************************************************************/
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 * for more details.
27 * You should have received a copy of the GNU General Public License along
28 * with this program; if not, write to the Free Software Foundation, Inc.,
29 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include "inc/pios_usb_board_data.h" /* struct usb_*, USB_* */
33 #include <pios_sys.h> /* PIOS_SYS_SerialNumberGet */
34 #include <pios_usbhook.h> /* PIOS_USBHOOK_* */
35 #include <pios_usb_util.h> /* PIOS_USB_UTIL_AsciiToUtf8 */
37 static const uint8_t usb_product_id[18] = {
38 sizeof(usb_product_id),
39 USB_DESC_TYPE_STRING,
40 't', 0,
41 'i', 0,
42 'n', 0,
43 'y', 0,
44 'F', 0,
45 'I', 0,
46 'S', 0,
47 'H', 0,
50 static uint8_t usb_serial_number[2 + PIOS_SYS_SERIAL_NUM_ASCII_LEN * 2 + (sizeof(PIOS_USB_BOARD_SN_SUFFIX) - 1) * 2] = {
51 sizeof(usb_serial_number),
52 USB_DESC_TYPE_STRING,
55 static const struct usb_string_langid usb_lang_id = {
56 .bLength = sizeof(usb_lang_id),
57 .bDescriptorType = USB_DESC_TYPE_STRING,
58 .bLangID = htousbs(USB_LANGID_ENGLISH_US),
61 static const uint8_t usb_vendor_id[28] = {
62 sizeof(usb_vendor_id),
63 USB_DESC_TYPE_STRING,
64 'o', 0,
65 'p', 0,
66 'e', 0,
67 'n', 0,
68 'p', 0,
69 'i', 0,
70 'l', 0,
71 'o', 0,
72 't', 0,
73 '.', 0,
74 'o', 0,
75 'r', 0,
76 'g', 0
79 int32_t PIOS_USB_BOARD_DATA_Init(void)
81 /* Load device serial number into serial number string */
82 uint8_t sn[PIOS_SYS_SERIAL_NUM_ASCII_LEN + 1];
84 PIOS_SYS_SerialNumberGet((char *)sn);
86 /* Concatenate the device serial number and the appropriate suffix ("+BL" or "+FW") into the USB serial number */
87 uint8_t *utf8 = &(usb_serial_number[2]);
88 utf8 = PIOS_USB_UTIL_AsciiToUtf8(utf8, sn, PIOS_SYS_SERIAL_NUM_ASCII_LEN);
89 utf8 = PIOS_USB_UTIL_AsciiToUtf8(utf8, (uint8_t *)PIOS_USB_BOARD_SN_SUFFIX, sizeof(PIOS_USB_BOARD_SN_SUFFIX) - 1);
91 PIOS_USBHOOK_RegisterString(USB_STRING_DESC_PRODUCT, (uint8_t *)&usb_product_id, sizeof(usb_product_id));
92 PIOS_USBHOOK_RegisterString(USB_STRING_DESC_SERIAL, (uint8_t *)&usb_serial_number, sizeof(usb_serial_number));
94 PIOS_USBHOOK_RegisterString(USB_STRING_DESC_LANG, (uint8_t *)&usb_lang_id, sizeof(usb_lang_id));
95 PIOS_USBHOOK_RegisterString(USB_STRING_DESC_VENDOR, (uint8_t *)&usb_vendor_id, sizeof(usb_vendor_id));
97 return 0;