SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
usb_descriptors.c File Reference
#include "bsp/board_api.h"
#include "tusb.h"
Include dependency graph for audio_mic/usb_descriptors.c:

Go to the source code of this file.

Macros

#define USB_PID   0x4004
#define CONFIG_TOTAL_LEN   (TUD_CONFIG_DESC_LEN + CFG_TUD_AUDIO * TUD_AUDIO20_MIC_ONE_CH_DESC_LEN)
#define EPNUM_AUDIO   0x03

Enumerations

enum  {
  ITF_NUM_AUDIO_CONTROL = 0 ,
  ITF_NUM_AUDIO_STREAMING ,
  ITF_NUM_TOTAL
}
enum  {
  STRID_LANGID = 0 ,
  STRID_MANUFACTURER ,
  STRID_PRODUCT ,
  STRID_SERIAL
}

Functions

uint8_t const * tud_descriptor_device_cb (void)
uint8_t const * tud_descriptor_configuration_cb (uint8_t index)
uint16_t const * tud_descriptor_string_cb (uint8_t index, uint16_t langid)

Variables

static tusb_desc_device_t const desc_device
uint8_t const desc_configuration []
char const * string_desc_arr []
static uint16_t _desc_str [32+1]

Macro Definition Documentation

◆ CONFIG_TOTAL_LEN

#define CONFIG_TOTAL_LEN   (TUD_CONFIG_DESC_LEN + CFG_TUD_AUDIO * TUD_AUDIO20_MIC_ONE_CH_DESC_LEN)

Definition at line 76 of file audio_mic/usb_descriptors.c.

◆ EPNUM_AUDIO

#define EPNUM_AUDIO   0x03

Definition at line 81 of file audio_mic/usb_descriptors.c.

◆ USB_PID

#define USB_PID   0x4004

Definition at line 30 of file audio_mic/usb_descriptors.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
ITF_NUM_AUDIO_CONTROL 
ITF_NUM_AUDIO_STREAMING 
ITF_NUM_TOTAL 

Definition at line 69 of file audio_mic/usb_descriptors.c.

◆ anonymous enum

anonymous enum
Enumerator
STRID_LANGID 
STRID_MANUFACTURER 
STRID_PRODUCT 
STRID_SERIAL 

Definition at line 118 of file audio_mic/usb_descriptors.c.

Function Documentation

◆ tud_descriptor_configuration_cb()

uint8_t const * tud_descriptor_configuration_cb ( uint8_t index)

Definition at line 107 of file audio_mic/usb_descriptors.c.

108{
109 (void) index; // for multiple configurations
110 return desc_configuration;
111}
uint8_t const desc_configuration[]

References desc_configuration.

◆ tud_descriptor_device_cb()

uint8_t const * tud_descriptor_device_cb ( void )

Definition at line 61 of file audio_mic/usb_descriptors.c.

62{
63 return (uint8_t const *) &desc_device;
64}
static tusb_desc_device_t const desc_device

References desc_device.

◆ tud_descriptor_string_cb()

uint16_t const * tud_descriptor_string_cb ( uint8_t index,
uint16_t langid )

Definition at line 140 of file audio_mic/usb_descriptors.c.

140 {
141 (void) langid;
142 size_t chr_count;
143
144 switch ( index ) {
145 case STRID_LANGID:
146 memcpy(&_desc_str[1], string_desc_arr[0], 2);
147 chr_count = 1;
148 break;
149
150 case STRID_SERIAL:
151 chr_count = board_usb_get_serial(_desc_str + 1, 32);
152 break;
153
154 default:
155 // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
156 // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
157
158 if (!(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0]))) {
159 return NULL;
160 }
161
162 const char *str = string_desc_arr[index];
163
164 // Cap at max char
165 chr_count = strlen(str);
166 size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
167 if (chr_count > max_count) {
168 chr_count = max_count;
169 }
170
171 // Convert ASCII string into UTF-16
172 for ( size_t i = 0; i < chr_count; i++ ) {
173 _desc_str[1 + i] = str[i];
174 }
175 break;
176 }
177
178 // first byte is length (including header), second byte is string type
179 _desc_str[0] = (uint16_t) ((TUSB_DESC_STRING << 8) | (2 * chr_count + 2));
180
181 return _desc_str;
182}
char const * string_desc_arr[]
static uint16_t _desc_str[32+1]

References _desc_str, STRID_LANGID, STRID_SERIAL, and string_desc_arr.

Variable Documentation

◆ _desc_str

uint16_t _desc_str[32+1]
static

Definition at line 136 of file audio_mic/usb_descriptors.c.

Referenced by tud_descriptor_string_cb().

◆ desc_configuration

uint8_t const desc_configuration[]
Initial value:
=
{
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, (TUD_CONFIG_DESC_LEN + CFG_TUD_AUDIO * TUD_AUDIO20_MIC_ONE_CH_DESC_LEN) , 0x00, 100),
}
#define CFG_TUD_AUDIO

Definition at line 95 of file audio_mic/usb_descriptors.c.

96{
97 // Config number, interface count, string index, total length, attribute, power in mA
98 TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
99
100 // Interface number, string index, EP Out & EP In address, EP size
101 TUD_AUDIO20_MIC_ONE_CH_DESCRIPTOR(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_stridx*/ 0, /*_nBytesPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, /*_nBitsUsedPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX*8, /*_epin*/ 0x80 | EPNUM_AUDIO, /*_epsize*/ CFG_TUD_AUDIO_EP_SZ_IN)
102};
#define CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX
#define CFG_TUD_AUDIO_EP_SZ_IN
#define CONFIG_TOTAL_LEN
#define EPNUM_AUDIO

Referenced by tud_descriptor_configuration_cb().

◆ desc_device

tusb_desc_device_t const desc_device
static
Initial value:
=
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = 0x0200,
.bDeviceClass = TUSB_CLASS_MISC,
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
.bDeviceProtocol = MISC_PROTOCOL_IAD,
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
.idVendor = 0xCafe,
.idProduct = 0x4004 ,
.bcdDevice = 0x0100,
.iManufacturer = 0x01,
.iProduct = 0x02,
.iSerialNumber = 0x03,
.bNumConfigurations = 0x01
}
#define CFG_TUD_ENDPOINT0_SIZE

Definition at line 35 of file audio_mic/usb_descriptors.c.

36{
37 .bLength = sizeof(tusb_desc_device_t),
38 .bDescriptorType = TUSB_DESC_DEVICE,
39 .bcdUSB = 0x0200,
40
41 // Use Interface Association Descriptor (IAD) for Audio
42 // As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
43 .bDeviceClass = TUSB_CLASS_MISC,
44 .bDeviceSubClass = MISC_SUBCLASS_COMMON,
45 .bDeviceProtocol = MISC_PROTOCOL_IAD,
46 .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
47
48 .idVendor = 0xCafe,
49 .idProduct = USB_PID,
50 .bcdDevice = 0x0100,
51
52 .iManufacturer = 0x01,
53 .iProduct = 0x02,
54 .iSerialNumber = 0x03,
55
56 .bNumConfigurations = 0x01
57};
#define USB_PID

Referenced by tud_descriptor_device_cb().

◆ string_desc_arr

char const* string_desc_arr[]
Initial value:
=
{
(const char[]) { 0x09, 0x04 },
"PaniRCorp",
"MicNode",
NULL,
"UAC2",
}

Definition at line 126 of file audio_mic/usb_descriptors.c.

127{
128 (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
129 "PaniRCorp", // 1: Manufacturer
130 "MicNode", // 2: Product
131 NULL, // 3: Serials will use unique ID if possible
132 "UAC2", // 4: Audio Interface
133
134};

Referenced by tud_descriptor_string_cb().