Create a #define/constant for the usb_descriptor_string_serial_number length.

Clean up a compilation warning, libusb headers do not like the 'const'.
This commit is contained in:
Heikki Hannikainen
2015-02-23 20:29:22 +02:00
committed by Heikki Hannikainen
parent 9e92adda79
commit 35b9e0bea0
3 changed files with 9 additions and 4 deletions

View File

@ -195,10 +195,11 @@ void usb_set_descriptor_by_serial_number(void)
iap_cmd_call(&iap_cmd_res); iap_cmd_call(&iap_cmd_res);
if (iap_cmd_res.status_res.status_ret == CMD_SUCCESS) { if (iap_cmd_res.status_res.status_ret == CMD_SUCCESS) {
usb_descriptor_string_serial_number[0] = 66; usb_descriptor_string_serial_number[0] = USB_DESCRIPTOR_STRING_SERIAL_BUF_LEN;
usb_descriptor_string_serial_number[1] = USB_DESCRIPTOR_TYPE_STRING; usb_descriptor_string_serial_number[1] = USB_DESCRIPTOR_TYPE_STRING;
for (size_t i=0; i<32; i++) { /* 32 characters of serial number, convert to UTF-16LE */
for (size_t i=0; i<USB_DESCRIPTOR_STRING_SERIAL_LEN; i++) {
const uint_fast8_t nibble = (iap_cmd_res.status_res.iap_result[i >> 3] >> (28 - (i & 7) * 4)) & 0xf; const uint_fast8_t nibble = (iap_cmd_res.status_res.iap_result[i >> 3] >> (28 - (i & 7) * 4)) & 0xf;
const char c = (nibble > 9) ? ('a' + nibble - 10) : ('0' + nibble); const char c = (nibble > 9) ? ('a' + nibble - 10) : ('0' + nibble);
usb_descriptor_string_serial_number[2 + i * 2] = c; usb_descriptor_string_serial_number[2 + i * 2] = c;

View File

@ -22,6 +22,7 @@
#include <stdint.h> #include <stdint.h>
#include "usb_type.h" #include "usb_type.h"
#include "usb_descriptor.h"
#define USB_VENDOR_ID (0x1D50) #define USB_VENDOR_ID (0x1D50)
@ -329,9 +330,9 @@ uint8_t usb_descriptor_string_config2_description[] = {
'e', 0x00, 'e', 0x00,
}; };
uint8_t usb_descriptor_string_serial_number[66]; uint8_t usb_descriptor_string_serial_number[USB_DESCRIPTOR_STRING_SERIAL_BUF_LEN];
uint8_t* const usb_descriptor_strings[] = { uint8_t* usb_descriptor_strings[] = {
usb_descriptor_string_languages, usb_descriptor_string_languages,
usb_descriptor_string_manufacturer, usb_descriptor_string_manufacturer,
usb_descriptor_string_product, usb_descriptor_string_product,

View File

@ -30,6 +30,9 @@ extern uint8_t usb_descriptor_configuration_cpld_update_high_speed[];
extern uint8_t usb_descriptor_string_languages[]; extern uint8_t usb_descriptor_string_languages[];
extern uint8_t usb_descriptor_string_manufacturer[]; extern uint8_t usb_descriptor_string_manufacturer[];
extern uint8_t usb_descriptor_string_product[]; extern uint8_t usb_descriptor_string_product[];
#define USB_DESCRIPTOR_STRING_SERIAL_LEN 32
#define USB_DESCRIPTOR_STRING_SERIAL_BUF_LEN (USB_DESCRIPTOR_STRING_SERIAL_LEN*2 + 2) /* UTF-16LE */
extern uint8_t usb_descriptor_string_serial_number[]; extern uint8_t usb_descriptor_string_serial_number[];
extern uint8_t* usb_descriptor_strings[]; extern uint8_t* usb_descriptor_strings[];