Skip to content

Allow USB descriptor strings to be defined in boards.txt #1421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions hardware/arduino/avr/boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,11 @@ leonardo.build.mcu=atmega32u4
leonardo.build.f_cpu=16000000L
leonardo.build.vid=0x2341
leonardo.build.pid=0x8036
leonardo.build.usb_product='A','r','d','u','i','n','o',32,'L','e','o','n','a','r','d','o'
leonardo.build.board=AVR_LEONARDO
leonardo.build.core=arduino
leonardo.build.variant=leonardo
leonardo.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid}
leonardo.build.extra_flags={build.usb_flags}

##############################################################

Expand All @@ -217,10 +218,11 @@ micro.build.mcu=atmega32u4
micro.build.f_cpu=16000000L
micro.build.vid=0x2341
micro.build.pid=0x8037
micro.build.usb_product='A','r','d','u','i','n','o',32,'M','i','c','r','o'
micro.build.board=AVR_MICRO
micro.build.core=arduino
micro.build.variant=micro
micro.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid}
micro.build.extra_flags={build.usb_flags}

##############################################################

Expand All @@ -246,10 +248,11 @@ esplora.build.mcu=atmega32u4
esplora.build.f_cpu=16000000L
esplora.build.vid=0x2341
esplora.build.pid=0x803c
esplora.build.usb_product='A','r','d','u','i','n','o',32,'E','s','p','l','o','r','a'
esplora.build.board=AVR_ESPLORA
esplora.build.core=arduino
esplora.build.variant=leonardo
esplora.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid}
esplora.build.extra_flags={build.usb_flags}

##############################################################

Expand Down Expand Up @@ -407,15 +410,15 @@ LilyPadUSB.bootloader.extended_fuses=0xce
LilyPadUSB.bootloader.file=caterina-LilyPadUSB/Caterina-LilyPadUSB.hex
LilyPadUSB.bootloader.unlock_bits=0x3F
LilyPadUSB.bootloader.lock_bits=0x2F

LilyPadUSB.build.mcu=atmega32u4
LilyPadUSB.build.f_cpu=8000000L
LilyPadUSB.build.vid=0x1B4F
LilyPadUSB.build.pid=0x9208
LilyPadUSB.build.usb_product='L','i','l','y','P','a','d','U','S','B'
LilyPadUSB.build.board=AVR_LILYPAD_USB
LilyPadUSB.build.core=arduino
LilyPadUSB.build.variant=leonardo
LilyPadUSB.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid}
LilyPadUSB.build.extra_flags={build.usb_flags}

##############################################################

Expand Down
50 changes: 28 additions & 22 deletions hardware/arduino/avr/cores/arduino/USBCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,39 @@ const u16 STRING_LANGUAGE[2] = {
0x0409 // English
};

const u16 STRING_IPRODUCT[17] = {
(3<<8) | (2+2*16),
#if USB_PID == 0x8036
'A','r','d','u','i','n','o',' ','L','e','o','n','a','r','d','o'
#elif USB_PID == 0x8037
'A','r','d','u','i','n','o',' ','M','i','c','r','o',' ',' ',' '
#elif USB_PID == 0x803C
'A','r','d','u','i','n','o',' ','E','s','p','l','o','r','a',' '
#elif USB_PID == 0x9208
'L','i','l','y','P','a','d','U','S','B',' ',' ',' ',' ',' ',' '
#else
'U','S','B',' ','I','O',' ','B','o','a','r','d',' ',' ',' ',' '
/*
* Some gotchas when setting USB_MANUFACTURER & USB_PRODUCT from boards.txt:
*
* - Must be specified in the character format shown
* - Must not contain spaces, or spaces must be escaped as numeric 32
*
* See provided boards.txt for examples.
*/

#ifndef USB_PRODUCT
#define USB_PRODUCT 'U','S','B',' ','I','O',' ','B','o','a','r','d'
#endif
};

const u16 STRING_IMANUFACTURER[12] = {
(3<<8) | (2+2*11),
static const u8 _IPRODUCT[] = { USB_PRODUCT };
static const u8 _IPRODUCT_LEN = 2 + sizeof(_IPRODUCT)*2;
// Product name descriptor payload
const u16 STRING_IPRODUCT[_IPRODUCT_LEN] = { (3<<8) | _IPRODUCT_LEN, USB_PRODUCT };

#if USB_VID == 0x2341
'A','r','d','u','i','n','o',' ','L','L','C'
#define USB_MANUFACTURER 'A','r','d','u','i','n','o',' ','L','L','C'
#elif USB_VID == 0x1b4f
'S','p','a','r','k','F','u','n',' ',' ',' '
#define USB_IMANUFACTUTER 'S','p','a','r','k','F','u','n'
#else
'U','n','k','n','o','w','n',' ',' ',' ',' '
#ifndef USB_MANUFACTURER
// Fall through to unknown if no manufacturer name was provided in a macro
#define USB_MANUFACTURER 'U','n','k','n','o','w','n'
#endif
};
#endif

static const u8 _IMANUFACTURER[] = { USB_MANUFACTURER };
static const u8 _IMANUFACTURER_LEN = 2 + sizeof(_IMANUFACTURER)*2;
// Manufacturer name descriptor payload
const u16 STRING_IMANUFACTURER[_IMANUFACTURER_LEN] = { (3<<8) | _IMANUFACTURER_LEN, USB_MANUFACTURER };

#ifdef CDC_ENABLED
#define DEVICE_CLASS 0x02
Expand Down Expand Up @@ -476,7 +484,6 @@ bool SendDescriptor(Setup& setup)
return HID_GetDescriptor(t);
#endif

u8 desc_length = 0;
const u8* desc_addr = 0;
if (USB_DEVICE_DESCRIPTOR_TYPE == t)
{
Expand All @@ -498,8 +505,7 @@ bool SendDescriptor(Setup& setup)

if (desc_addr == 0)
return false;
if (desc_length == 0)
desc_length = pgm_read_byte(desc_addr);
u8 desc_length = pgm_read_byte(desc_addr);

USB_SendControl(TRANSFER_PGM,desc_addr,desc_length);
return true;
Expand Down
6 changes: 6 additions & 0 deletions hardware/arduino/avr/platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@ tools.avrdude.bootloader.params.verbose=-v -v -v -v
tools.avrdude.bootloader.params.quiet=-q -q
tools.avrdude.bootloader.pattern="{cmd.path}" "-C{config.path}" {bootloader.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{runtime.ide.path}/hardware/arduino/avr/bootloaders/{bootloader.file}:i" -Ulock:w:{bootloader.lock_bits}:m


# USB Default Flags
# Default blank usb manufacturer will be filled it at compile time
# - from numeric vendor ID, set to Unknown otherwise
build.usb_manufacturer=
build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSB_MANUFACTURER={build.usb_manufacturer} -DUSB_PRODUCT={build.usb_product}