ACwing FC firmware
STM32WB55: attitude IEKF, altitude Kalman filter, flight core, protocol v2
Loading...
Searching...
No Matches
usbd_desc.c
Go to the documentation of this file.
1
10#include "usbd_core.h"
11#include "usbd_conf.h"
12#include "usbd_desc.h"
13
14#define USBD_VID 0x0483u
15#define USBD_PID 0x5740u
16#define USBD_LANGID 0x0409u
17#define STR_MANUFACTURER "ACwing"
18#define STR_PRODUCT "ACwing FC"
19#define STR_CONFIG "CDC Config"
20#define STR_INTERFACE "CDC Interface"
21#define USB_SIZ_STRING_SERIAL 0x1Au
22
23static uint8_t *dev_desc(USBD_SpeedTypeDef s, uint16_t *len);
24static uint8_t *lang_desc(USBD_SpeedTypeDef s, uint16_t *len);
25static uint8_t *mfr_desc(USBD_SpeedTypeDef s, uint16_t *len);
26static uint8_t *prod_desc(USBD_SpeedTypeDef s, uint16_t *len);
27static uint8_t *serial_desc(USBD_SpeedTypeDef s, uint16_t *len);
28static uint8_t *config_desc(USBD_SpeedTypeDef s, uint16_t *len);
29static uint8_t *itf_desc(USBD_SpeedTypeDef s, uint16_t *len);
30
31USBD_DescriptorsTypeDef ACW_FS_Desc = {
33#if (USBD_LPM_ENABLED == 1U)
34 NULL,
35#endif
36};
37
38static uint8_t s_dev[USB_LEN_DEV_DESC] __attribute__((aligned(4))) = {
39 0x12, USB_DESC_TYPE_DEVICE, 0x00, 0x02,
40 0x02, 0x02, 0x00, /* class CDC, subclass ACM */
41 USB_MAX_EP0_SIZE,
42 LOBYTE(USBD_VID), HIBYTE(USBD_VID), LOBYTE(USBD_PID), HIBYTE(USBD_PID),
43 0x00, 0x02, /* bcdDevice 2.00 */
44 USBD_IDX_MFC_STR, USBD_IDX_PRODUCT_STR, USBD_IDX_SERIAL_STR,
46};
47
48static uint8_t s_lang[USB_LEN_LANGID_STR_DESC] __attribute__((aligned(4))) = {
49 USB_LEN_LANGID_STR_DESC, USB_DESC_TYPE_STRING, LOBYTE(USBD_LANGID), HIBYTE(USBD_LANGID)
50};
51
52static uint8_t s_str[USBD_MAX_STR_DESC_SIZ] __attribute__((aligned(4)));
53static uint8_t s_serial[USB_SIZ_STRING_SERIAL] __attribute__((aligned(4))) = { USB_SIZ_STRING_SERIAL, USB_DESC_TYPE_STRING };
54
55static uint8_t *dev_desc(USBD_SpeedTypeDef s, uint16_t *len) { (void)s; *len = sizeof s_dev; return s_dev; }
56static uint8_t *lang_desc(USBD_SpeedTypeDef s, uint16_t *len) { (void)s; *len = sizeof s_lang; return s_lang; }
57static uint8_t *mfr_desc(USBD_SpeedTypeDef s, uint16_t *len) { (void)s; USBD_GetString((uint8_t *)STR_MANUFACTURER, s_str, len); return s_str; }
58static uint8_t *prod_desc(USBD_SpeedTypeDef s, uint16_t *len) { (void)s; USBD_GetString((uint8_t *)STR_PRODUCT, s_str, len); return s_str; }
59static uint8_t *config_desc(USBD_SpeedTypeDef s, uint16_t *len) { (void)s; USBD_GetString((uint8_t *)STR_CONFIG, s_str, len); return s_str; }
60static uint8_t *itf_desc(USBD_SpeedTypeDef s, uint16_t *len) { (void)s; USBD_GetString((uint8_t *)STR_INTERFACE, s_str, len); return s_str; }
61
62static void hex_unicode(uint32_t v, uint8_t *p, uint8_t n)
63{
64 for (uint8_t i = 0; i < n; ++i) {
65 const uint8_t d = (uint8_t)(v >> 28);
66 p[2u * i] = (uint8_t)(d < 10u ? '0' + d : 'A' + d - 10u);
67 p[2u * i + 1u] = 0;
68 v <<= 4;
69 }
70}
71
72/* serial: 12 hex digits from the MCU unique id */
73static uint8_t *serial_desc(USBD_SpeedTypeDef s, uint16_t *len)
74{
75 (void)s;
76 const uint32_t w0 = HAL_GetUIDw0() + HAL_GetUIDw2(), w1 = HAL_GetUIDw1();
77 hex_unicode(w0, &s_serial[2], 8);
78 hex_unicode(w1, &s_serial[18], 4);
80 return s_serial;
81}
static batt_state_t s
Definition battery.c:21
uint32_t n
Definition calib_mgr.c:35
Configuration of the ST USB device library (third_party/st_usb) for the ACwing FC firmware: one CDC i...
#define USBD_MAX_STR_DESC_SIZ
Definition usbd_conf.h:18
#define USBD_MAX_NUM_CONFIGURATION
Definition usbd_conf.h:17
static uint8_t s_lang[USB_LEN_LANGID_STR_DESC]
Definition usbd_desc.c:48
#define USBD_PID
Definition usbd_desc.c:15
#define STR_MANUFACTURER
Definition usbd_desc.c:17
#define STR_CONFIG
Definition usbd_desc.c:19
static uint8_t * itf_desc(USBD_SpeedTypeDef s, uint16_t *len)
Definition usbd_desc.c:60
#define STR_PRODUCT
Definition usbd_desc.c:18
#define STR_INTERFACE
Definition usbd_desc.c:20
static uint8_t * mfr_desc(USBD_SpeedTypeDef s, uint16_t *len)
Definition usbd_desc.c:57
static uint8_t * serial_desc(USBD_SpeedTypeDef s, uint16_t *len)
Definition usbd_desc.c:73
#define USB_SIZ_STRING_SERIAL
Definition usbd_desc.c:21
static uint8_t * dev_desc(USBD_SpeedTypeDef s, uint16_t *len)
Definition usbd_desc.c:55
USBD_DescriptorsTypeDef ACW_FS_Desc
Definition usbd_desc.c:31
#define USBD_LANGID
Definition usbd_desc.c:16
static uint8_t * config_desc(USBD_SpeedTypeDef s, uint16_t *len)
Definition usbd_desc.c:59
#define USBD_VID
Definition usbd_desc.c:14
static uint8_t * prod_desc(USBD_SpeedTypeDef s, uint16_t *len)
Definition usbd_desc.c:58
static uint8_t s_str[USBD_MAX_STR_DESC_SIZ]
Definition usbd_desc.c:52
static void hex_unicode(uint32_t v, uint8_t *p, uint8_t n)
Definition usbd_desc.c:62
static uint8_t * lang_desc(USBD_SpeedTypeDef s, uint16_t *len)
Definition usbd_desc.c:56
static uint8_t s_dev[USB_LEN_DEV_DESC]
Definition usbd_desc.c:38
static uint8_t s_serial[USB_SIZ_STRING_SERIAL]
Definition usbd_desc.c:53
USB descriptors of the ACwing FC (see usbd_desc.c).