PER Firmware
Loading...
Searching...
No Matches
usb_descriptors.h
Go to the documentation of this file.
1
8#ifndef CANNECTOR_USB_DESCRIPTORS_H
9#define CANNECTOR_USB_DESCRIPTORS_H
10
11#include "phal_G4/usb/usb.h"
12#include "can_library/generated/can_version.h"
13
14static const char USB_PRODUCT_NAME[] = "CANnector27_" FIRMWARE_GIT_HASH_STRING;
15static constexpr uint8_t USB_PRODUCT_STRING_INDEX = 1U;
16static constexpr uint16_t USB_LANGUAGE_ID = 0x0409U; // English (United States)
17static const uint8_t LANGUAGE_DESCRIPTOR[] = {
18 4U, PHAL_USB_DESCRIPTOR_STRING, 0x09U, 0x04U,
19};
20// Keep the complete UTF-16LE descriptor within the HAL's single-packet limit.
21static_assert(2U + 2U * (sizeof(USB_PRODUCT_NAME) - 1U) <= PHAL_USB_PACKET_SIZE_BYTES);
22
23// IN/OUT are named from the host's perspective: endpoint 1
25static constexpr uint8_t BULK_OUT_ADDRESS = PHAL_USB_DATA_ENDPOINT;
26
38static const uint8_t DEVICE_DESCRIPTOR[] = {
41 0x00U, 0x02U, // bcdUSB: USB 2.0
43 0U, // Device subclass
44 0U, // Device protocol
45 PHAL_USB_PACKET_SIZE_BYTES, // EP0 maximum packet size
46 0x45U, 0x50U, // Vendor ID: 0x5045 ("PE")
47 0x71U, 0x02U, // Product ID: 0x0271
48 0x01U, 0x00U, // bcdDevice: 0.01
49 0U, // No manufacturer string
50 USB_PRODUCT_STRING_INDEX, // Product string
51 0U, // No serial-number string
52 1U, // Number of configurations
53};
54
60static const uint8_t CONFIGURATION_DESCRIPTOR[] = {
61 // Configuration descriptor: 9 bytes
64 32U, 0U, // Total length: 9 + 9 + 7 + 7 bytes
65 1U, // Number of interfaces
66 1U, // Configuration value selected by host
67 0U, // No configuration string
69 50U, // Maximum power: 50 * 2 mA = 100 mA
70
71 // Interface descriptor: 9 bytes
72 // One function with no alternate modes
75 0U, // Interface number
76 0U, // Alternate setting
77 2U, // Number of endpoints (excluding EP0)
79 0U, // Interface subclass
80 0U, // Interface protocol
81 0U, // No interface string
82
83 // Endpoint descriptor: 7 bytes (Bulk IN)
88 PHAL_USB_PACKET_SIZE_BYTES, 0U, // Maximum packet size: 64 bytes
89 0U, // Polling interval unused for bulk IN
90
91 // Endpoint descriptor: 7 bytes (Bulk OUT)
96 PHAL_USB_PACKET_SIZE_BYTES, 0U, // Maximum packet size: 64 bytes
97 0U, // Polling interval unused for bulk OUT
98};
99
101static_assert(sizeof(CONFIGURATION_DESCRIPTOR) == 32U);
102
103#endif
STM32G4 USB full-speed device API.
static constexpr uint8_t PHAL_USB_INTERFACE_DESCRIPTOR_LENGTH
Definition usb.h:63
static constexpr uint16_t PHAL_USB_PACKET_SIZE_BYTES
Definition usb.h:23
static constexpr uint8_t PHAL_USB_CONFIGURATION_ATTRIBUTES_BUS_POWERED
Definition usb.h:66
static constexpr uint8_t PHAL_USB_CONFIGURATION_DESCRIPTOR_LENGTH
Definition usb.h:62
static constexpr uint8_t PHAL_USB_ENDPOINT_DESCRIPTOR_LENGTH
Definition usb.h:64
@ PHAL_USB_DESCRIPTOR_STRING
Definition usb.h:42
@ PHAL_USB_DESCRIPTOR_ENDPOINT
Definition usb.h:44
@ PHAL_USB_DESCRIPTOR_DEVICE
Definition usb.h:40
@ PHAL_USB_DESCRIPTOR_INTERFACE
Definition usb.h:43
@ PHAL_USB_DESCRIPTOR_CONFIGURATION
Definition usb.h:41
static constexpr uint8_t PHAL_USB_ENDPOINT_TRANSFER_TYPE_BULK
Definition usb.h:67
static constexpr uint8_t PHAL_USB_DEVICE_CLASS_VENDOR_SPECIFIC
Definition usb.h:65
static constexpr uint8_t PHAL_USB_DATA_ENDPOINT
Definition usb.h:20
static constexpr uint8_t PHAL_USB_DEVICE_DESCRIPTOR_LENGTH
Definition usb.h:61
static constexpr uint8_t PHAL_USB_ENDPOINT_ADDRESS_IN
Definition usb.h:60
static constexpr uint8_t BULK_IN_ADDRESS
Definition usb_descriptors.h:24
static constexpr uint8_t BULK_OUT_ADDRESS
Definition usb_descriptors.h:25
static constexpr uint16_t USB_LANGUAGE_ID
Definition usb_descriptors.h:16
static const uint8_t DEVICE_DESCRIPTOR[]
Definition usb_descriptors.h:38
static const uint8_t CONFIGURATION_DESCRIPTOR[]
Definition usb_descriptors.h:60
static const char USB_PRODUCT_NAME[]
Definition usb_descriptors.h:14
static const uint8_t LANGUAGE_DESCRIPTOR[]
Definition usb_descriptors.h:17
static constexpr uint8_t USB_PRODUCT_STRING_INDEX
Definition usb_descriptors.h:15