kopia lustrzana https://github.com/skuep/AIOC
Cleaned up various files
rodzic
a0b3e0c968
commit
c9cf9b86ed
|
@ -14,10 +14,6 @@ static void SystemClock_Config(void)
|
||||||
.OscillatorType = RCC_OSCILLATORTYPE_HSE,
|
.OscillatorType = RCC_OSCILLATORTYPE_HSE,
|
||||||
.HSEState = RCC_HSE_ON,
|
.HSEState = RCC_HSE_ON,
|
||||||
.HSEPredivValue = RCC_HSE_PREDIV_DIV1,
|
.HSEPredivValue = RCC_HSE_PREDIV_DIV1,
|
||||||
.LSEState = RCC_LSE_OFF,
|
|
||||||
.HSIState = RCC_HSI_OFF,
|
|
||||||
.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT,
|
|
||||||
.LSIState = RCC_LSI_ON,
|
|
||||||
.PLL = {
|
.PLL = {
|
||||||
.PLLState = RCC_PLL_ON,
|
.PLLState = RCC_PLL_ON,
|
||||||
.PLLSource = RCC_CFGR_PLLSRC_HSE_PREDIV,
|
.PLLSource = RCC_CFGR_PLLSRC_HSE_PREDIV,
|
||||||
|
|
|
@ -42,55 +42,72 @@
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Device Descriptors
|
// Device Descriptors
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
tusb_desc_device_t const desc_device =
|
tusb_desc_device_t const desc_device = {
|
||||||
{
|
|
||||||
.bLength = sizeof(tusb_desc_device_t),
|
.bLength = sizeof(tusb_desc_device_t),
|
||||||
.bDescriptorType = TUSB_DESC_DEVICE,
|
.bDescriptorType = TUSB_DESC_DEVICE,
|
||||||
.bcdUSB = USB_BCD,
|
.bcdUSB = USB_BCD,
|
||||||
|
|
||||||
// Use Interface Association Descriptor (IAD) for CDC
|
|
||||||
// As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
|
|
||||||
.bDeviceClass = TUSB_CLASS_MISC,
|
.bDeviceClass = TUSB_CLASS_MISC,
|
||||||
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
|
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
|
||||||
.bDeviceProtocol = MISC_PROTOCOL_IAD,
|
.bDeviceProtocol = MISC_PROTOCOL_IAD,
|
||||||
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
|
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
|
||||||
|
|
||||||
.idVendor = USB_VID,
|
.idVendor = USB_VID,
|
||||||
.idProduct = USB_PID,
|
.idProduct = USB_PID,
|
||||||
.bcdDevice = 0x0100,
|
.bcdDevice = 0x0100,
|
||||||
|
|
||||||
.iManufacturer = STR_IDX_MANUFACTURER,
|
.iManufacturer = STR_IDX_MANUFACTURER,
|
||||||
.iProduct = STR_IDX_PRODUCT,
|
.iProduct = STR_IDX_PRODUCT,
|
||||||
.iSerialNumber = STR_IDX_SERIAL,
|
.iSerialNumber = STR_IDX_SERIAL,
|
||||||
|
|
||||||
.bNumConfigurations = 0x01
|
.bNumConfigurations = 0x01
|
||||||
};
|
};
|
||||||
|
|
||||||
// Invoked when received GET DEVICE DESCRIPTOR
|
// Invoked when received GET DEVICE DESCRIPTOR
|
||||||
// Application return pointer to descriptor
|
// Application return pointer to descriptor
|
||||||
uint8_t const * tud_descriptor_device_cb(void)
|
uint8_t const* tud_descriptor_device_cb(void) {
|
||||||
{
|
return (uint8_t const*) &desc_device;
|
||||||
return (uint8_t const *) &desc_device;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Configuration Descriptor
|
// Configuration Descriptor
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_CDC * TUD_CDC_DESC_LEN + 1 * TUD_AUDIO_IO_DESC_LEN)
|
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_CDC * TUD_CDC_DESC_LEN + CFG_TUD_AUDIO * TUD_AUDIO_IO_DESC_LEN)
|
||||||
|
|
||||||
uint8_t const desc_fs_configuration[] =
|
uint8_t const desc_fs_configuration[] = {
|
||||||
{
|
|
||||||
// Config number, interface count, string index, total length, attribute, power in mA
|
// Config number, interface count, string index, total length, attribute, power in mA
|
||||||
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
|
TUD_CONFIG_DESCRIPTOR(
|
||||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC_0, STR_IDX_CDCITF, EPNUM_CDC_0_NOTIF, 8, EPNUM_CDC_0_OUT, EPNUM_CDC_0_IN, CFG_TUD_CDC_EP_BUFSIZE),
|
/* config_num */ 1,
|
||||||
TUD_AUDIO_IO_DESCRIPTOR(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_stridx*/ STR_IDX_AUDIOITF, /*_nBytesPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE, /*_nBitsUsedPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE*8, /*_epin*/ EPNUM_AUDIO_IN, /*_epinsize*/ CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX, /*_epout*/ EPNUM_AUDIO_OUT, /*_epoutsize*/ CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX, /*_epfb*/ EPNUM_AUDIO_FB)
|
/* _itfcount */ ITF_NUM_TOTAL,
|
||||||
|
/* _stridx */ 0x00,
|
||||||
|
/* _total_len */ CONFIG_TOTAL_LEN,
|
||||||
|
/* _attribute */ 0x00,
|
||||||
|
/* _power_ma */ 100
|
||||||
|
),
|
||||||
|
|
||||||
|
TUD_CDC_DESCRIPTOR(
|
||||||
|
/* _itfnum */ ITF_NUM_CDC_0,
|
||||||
|
/* _stridx */ STR_IDX_CDCITF,
|
||||||
|
/* _ep_notif */ EPNUM_CDC_0_NOTIF,
|
||||||
|
/* _ep_notif_size */ 8,
|
||||||
|
/* _epout */ EPNUM_CDC_0_OUT,
|
||||||
|
/* _epin */ EPNUM_CDC_0_IN,
|
||||||
|
/* _epsize */ CFG_TUD_CDC_EP_BUFSIZE
|
||||||
|
),
|
||||||
|
|
||||||
|
TUD_AUDIO_IO_DESCRIPTOR(
|
||||||
|
/*_itfnum*/ ITF_NUM_AUDIO_CONTROL,
|
||||||
|
/*_stridx*/ STR_IDX_AUDIOITF,
|
||||||
|
/*_nBytesPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE,
|
||||||
|
/*_nBitsUsedPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE*8,
|
||||||
|
/*_epin*/ EPNUM_AUDIO_IN,
|
||||||
|
/*_epinsize*/ CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX,
|
||||||
|
/*_epout*/ EPNUM_AUDIO_OUT,
|
||||||
|
/*_epoutsize*/ CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX,
|
||||||
|
/*_epfb*/ EPNUM_AUDIO_FB
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
||||||
// Application return pointer to descriptor
|
// Application return pointer to descriptor
|
||||||
// Descriptor contents must exist long enough for transfer to complete
|
// Descriptor contents must exist long enough for transfer to complete
|
||||||
uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
|
uint8_t const* tud_descriptor_configuration_cb(uint8_t index) {
|
||||||
{
|
|
||||||
(void) index; // for multiple configurations
|
(void) index; // for multiple configurations
|
||||||
|
|
||||||
TU_ASSERT(!TUD_OPT_HIGH_SPEED);
|
TU_ASSERT(!TUD_OPT_HIGH_SPEED);
|
||||||
|
@ -100,31 +117,30 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// String Descriptors
|
// String Descriptors
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
static uint32_t crc32(const uint8_t * buf_ptr, uint32_t buf_len)
|
static uint32_t calc_crc32(const uint8_t *buf_ptr, uint32_t buf_len) {
|
||||||
{
|
|
||||||
/* Generate a serial number from processor UID using CRC32 */
|
/* Generate a serial number from processor UID using CRC32 */
|
||||||
const uint32_t crc32_init = 0xFFFFFFFFUL;
|
const uint32_t crc32_init = 0xFFFFFFFFUL;
|
||||||
const uint32_t crc32_poly = 0xEDB88320UL;
|
const uint32_t crc32_poly = 0xEDB88320UL;
|
||||||
|
const uint32_t crc32_final = 0xFFFFFFFFUL;
|
||||||
uint32_t serial = crc32_init; /* CRC32 Initial value */
|
uint32_t serial = crc32_init; /* CRC32 Initial value */
|
||||||
|
|
||||||
while (buf_len-- > 0) {
|
while (buf_len-- > 0) {
|
||||||
uint8_t byte = *buf_ptr++;
|
uint8_t byte = *buf_ptr++;
|
||||||
serial = serial ^ byte;
|
serial = serial ^ byte;
|
||||||
for (uint8_t j=0; j<8; j++) {
|
for (uint8_t j = 0; j < 8; j++) {
|
||||||
uint32_t mask = -(serial & 1);
|
uint32_t mask = -(serial & 1);
|
||||||
serial = (serial >> 1) ^ (crc32_poly & mask);
|
serial = (serial >> 1) ^ (crc32_poly & mask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ~serial;
|
return serial ^ crc32_final;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char * get_serial(void)
|
static const char * get_serial(void) {
|
||||||
{
|
|
||||||
static char serial_str[sizeof(uint32_t) * 2 + 1];
|
static char serial_str[sizeof(uint32_t) * 2 + 1];
|
||||||
uint32_t serial_num = crc32((uint8_t *) UID_BASE, 12);
|
uint32_t serial_num = calc_crc32((uint8_t *) UID_BASE, 12);
|
||||||
|
|
||||||
for (uint8_t i=0; i<(sizeof(uint32_t) * 2); i++) {
|
for (uint8_t i = 0; i < (sizeof(uint32_t) * 2); i++) {
|
||||||
uint8_t nibble = ((serial_num & 0xF0000000UL) >> 28);
|
uint8_t nibble = ((serial_num & 0xF0000000UL) >> 28);
|
||||||
serial_str[i] = nibble < 0xA ? nibble + '0' : nibble - 0xA + 'a';
|
serial_str[i] = nibble < 0xA ? nibble + '0' : nibble - 0xA + 'a';
|
||||||
serial_num <<= 4;
|
serial_num <<= 4;
|
||||||
|
@ -133,11 +149,10 @@ static const char * get_serial(void)
|
||||||
return serial_str;
|
return serial_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t ascii_to_utf16(uint8_t * buffer, uint32_t size, const char * str)
|
static uint8_t ascii_to_utf16(uint8_t *buffer, uint32_t size, const char *str) {
|
||||||
{
|
|
||||||
uint8_t len = 0;
|
uint8_t len = 0;
|
||||||
|
|
||||||
while ( (*str != '\0') && (size > 0) ) {
|
while ((*str != '\0') && (size > 0)) {
|
||||||
*buffer++ = *str++;
|
*buffer++ = *str++;
|
||||||
*buffer++ = 0x00;
|
*buffer++ = 0x00;
|
||||||
size -= 2;
|
size -= 2;
|
||||||
|
@ -149,16 +164,17 @@ static uint8_t ascii_to_utf16(uint8_t * buffer, uint32_t size, const char * str)
|
||||||
|
|
||||||
// Invoked when received GET STRING DESCRIPTOR request
|
// Invoked when received GET STRING DESCRIPTOR request
|
||||||
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
|
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
|
||||||
uint8_t const * tud_descriptor_string_cb(uint8_t index, uint16_t langid)
|
const uint8_t * tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
||||||
{
|
|
||||||
(void) langid;
|
|
||||||
static uint8_t buffer[64];
|
static uint8_t buffer[64];
|
||||||
uint8_t * ptr = &buffer[2];
|
uint8_t *ptr = &buffer[2];
|
||||||
uint8_t len = sizeof(buffer) - 2;
|
uint8_t len = sizeof(buffer) - 2;
|
||||||
|
|
||||||
|
(void) langid;
|
||||||
|
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case STR_IDX_LANGUAGE:
|
case STR_IDX_LANGUAGE:
|
||||||
ptr[0] = 0x09; ptr[1] = 0x04;
|
ptr[0] = 0x09;
|
||||||
|
ptr[1] = 0x04;
|
||||||
len = 2;
|
len = 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue