1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-10 21:24:12 +01:00

Allow USB product and manufacturer strings to be supplied in boards.txt

This commit is contained in:
Angus Gratton 2013-05-17 14:34:06 +10:00 committed by Cristian Maglie
parent ee8110e731
commit 15e73e8daa
2 changed files with 54 additions and 31 deletions

View File

@ -188,10 +188,11 @@ leonardo.build.mcu=atmega32u4
leonardo.build.f_cpu=16000000L leonardo.build.f_cpu=16000000L
leonardo.build.vid=0x2341 leonardo.build.vid=0x2341
leonardo.build.pid=0x8036 leonardo.build.pid=0x8036
leonardo.build.usb_product="Arduino Leonardo"
leonardo.build.board=AVR_LEONARDO leonardo.build.board=AVR_LEONARDO
leonardo.build.core=arduino leonardo.build.core=arduino
leonardo.build.variant=leonardo leonardo.build.variant=leonardo
leonardo.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} leonardo.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSB_MANUFACTURER={build.usb_manufacturer} -DUSB_PRODUCT={build.usb_product}
############################################################## ##############################################################
@ -217,10 +218,11 @@ micro.build.mcu=atmega32u4
micro.build.f_cpu=16000000L micro.build.f_cpu=16000000L
micro.build.vid=0x2341 micro.build.vid=0x2341
micro.build.pid=0x8037 micro.build.pid=0x8037
micro.build.usb_product=Arduino Micro
micro.build.board=AVR_MICRO micro.build.board=AVR_MICRO
micro.build.core=arduino micro.build.core=arduino
micro.build.variant=micro micro.build.variant=micro
micro.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} micro.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSB_MANUFACTURER={build.usb_manufacturer} -DUSB_PRODUCT={build.usb_product}
############################################################## ##############################################################
@ -246,10 +248,11 @@ esplora.build.mcu=atmega32u4
esplora.build.f_cpu=16000000L esplora.build.f_cpu=16000000L
esplora.build.vid=0x2341 esplora.build.vid=0x2341
esplora.build.pid=0x803c esplora.build.pid=0x803c
esplora.build.usb_product=Arduino Esplora
esplora.build.board=AVR_ESPLORA esplora.build.board=AVR_ESPLORA
esplora.build.core=arduino esplora.build.core=arduino
esplora.build.variant=leonardo esplora.build.variant=leonardo
esplora.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} esplora.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSB_MANUFACTURER={build.usb_manufacturer} -DUSB_PRODUCT={build.usb_product}
############################################################## ##############################################################
@ -407,15 +410,15 @@ LilyPadUSB.bootloader.extended_fuses=0xce
LilyPadUSB.bootloader.file=caterina-LilyPadUSB/Caterina-LilyPadUSB.hex LilyPadUSB.bootloader.file=caterina-LilyPadUSB/Caterina-LilyPadUSB.hex
LilyPadUSB.bootloader.unlock_bits=0x3F LilyPadUSB.bootloader.unlock_bits=0x3F
LilyPadUSB.bootloader.lock_bits=0x2F LilyPadUSB.bootloader.lock_bits=0x2F
LilyPadUSB.build.mcu=atmega32u4 LilyPadUSB.build.mcu=atmega32u4
LilyPadUSB.build.f_cpu=8000000L LilyPadUSB.build.f_cpu=8000000L
LilyPadUSB.build.vid=0x1B4F LilyPadUSB.build.vid=0x1B4F
LilyPadUSB.build.pid=0x9208 LilyPadUSB.build.pid=0x9208
LilyPadUSB.build.usb_product=LilyPad USB
LilyPadUSB.build.board=AVR_LILYPAD_USB LilyPadUSB.build.board=AVR_LILYPAD_USB
LilyPadUSB.build.core=arduino LilyPadUSB.build.core=arduino
LilyPadUSB.build.variant=leonardo LilyPadUSB.build.variant=leonardo
LilyPadUSB.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} LilyPadUSB.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSB_MANUFACTURER={build.usb_manufacturer} -DUSB_PRODUCT={build.usb_product}
############################################################## ##############################################################

View File

@ -39,8 +39,8 @@ volatile u8 RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */
//================================================================== //==================================================================
extern const u16 STRING_LANGUAGE[] PROGMEM; extern const u16 STRING_LANGUAGE[] PROGMEM;
extern const u16 STRING_IPRODUCT[] PROGMEM; extern const u8 STRING_PRODUCT[] PROGMEM;
extern const u16 STRING_IMANUFACTURER[] PROGMEM; extern const u8 STRING_MANUFACTURER[] PROGMEM;
extern const DeviceDescriptor USB_DeviceDescriptor PROGMEM; extern const DeviceDescriptor USB_DeviceDescriptor PROGMEM;
extern const DeviceDescriptor USB_DeviceDescriptorA PROGMEM; extern const DeviceDescriptor USB_DeviceDescriptorA PROGMEM;
@ -49,31 +49,34 @@ const u16 STRING_LANGUAGE[2] = {
0x0409 // English 0x0409 // English
}; };
const u16 STRING_IPRODUCT[17] = { #ifndef USB_PRODUCT
(3<<8) | (2+2*16), // Use a hardcoded product name if none is provided
#if USB_PID == 0x8036 #if USB_PID == 0x8036
'A','r','d','u','i','n','o',' ','L','e','o','n','a','r','d','o' #define USB_PRODUCT "Arduino Leonardo"
#elif USB_PID == 0x8037 #elif USB_PID == 0x8037
'A','r','d','u','i','n','o',' ','M','i','c','r','o',' ',' ',' ' #define USB_PRODUCT "Arduino Micro"
#elif USB_PID == 0x803C #elif USB_PID == 0x803C
'A','r','d','u','i','n','o',' ','E','s','p','l','o','r','a',' ' #define USB_PRODUCT "Arduino Esplora"
#elif USB_PID == 0x9208 #elif USB_PID == 0x9208
'L','i','l','y','P','a','d','U','S','B',' ',' ',' ',' ',' ',' ' #define USB_PRODUCT "LilyPad USB"
#else #else
'U','S','B',' ','I','O',' ','B','o','a','r','d',' ',' ',' ',' ' #define USB_PRODUCT "USB IO Board"
#endif
#endif #endif
};
const u16 STRING_IMANUFACTURER[12] = { const u8 STRING_PRODUCT[] PROGMEM = USB_PRODUCT;
(3<<8) | (2+2*11),
#if USB_VID == 0x2341 #if USB_VID == 0x2341
'A','r','d','u','i','n','o',' ','L','L','C' #define USB_MANUFACTURER "Arduino LLC"
#elif USB_VID == 0x1b4f #elif USB_VID == 0x1b4f
'S','p','a','r','k','F','u','n',' ',' ',' ' #define USB_MANUFACTURER "SparkFun"
#else #elif !defined(USB_MANUFACTURER)
'U','n','k','n','o','w','n',' ',' ',' ',' ' // Fall through to unknown if no manufacturer name was provided in a macro
#define USB_MANUFACTURER "Unknown"
#endif #endif
};
const u8 STRING_MANUFACTURER[] PROGMEM = USB_MANUFACTURER;
#ifdef CDC_ENABLED #ifdef CDC_ENABLED
#define DEVICE_CLASS 0x02 #define DEVICE_CLASS 0x02
@ -416,6 +419,22 @@ int USB_SendControl(u8 flags, const void* d, int len)
return sent; return sent;
} }
// Send a USB descriptor string. The string is stored in PROGMEM as a
// plain ASCII string but is sent out as UTF-16 with the correct 2-byte
// prefix
static bool USB_SendStringDescriptor(const u8*string_P, u8 string_len) {
SendControl(2 + string_len * 2);
SendControl(3);
for(u8 i = 0; i < string_len; i++) {
bool r = SendControl(pgm_read_byte(&string_P[i]));
r &= SendControl(0); // high byte
if(!r) {
return false;
}
}
return true;
}
// Does not timeout or cross fifo boundaries // Does not timeout or cross fifo boundaries
// Will only work for transfers <= 64 bytes // Will only work for transfers <= 64 bytes
// TODO // TODO
@ -476,7 +495,6 @@ bool SendDescriptor(Setup& setup)
return HID_GetDescriptor(t); return HID_GetDescriptor(t);
#endif #endif
u8 desc_length = 0;
const u8* desc_addr = 0; const u8* desc_addr = 0;
if (USB_DEVICE_DESCRIPTOR_TYPE == t) if (USB_DEVICE_DESCRIPTOR_TYPE == t)
{ {
@ -486,20 +504,22 @@ bool SendDescriptor(Setup& setup)
} }
else if (USB_STRING_DESCRIPTOR_TYPE == t) else if (USB_STRING_DESCRIPTOR_TYPE == t)
{ {
if (setup.wValueL == 0) if (setup.wValueL == 0) {
desc_addr = (const u8*)&STRING_LANGUAGE; desc_addr = (const u8*)&STRING_LANGUAGE;
else if (setup.wValueL == IPRODUCT) }
desc_addr = (const u8*)&STRING_IPRODUCT; else if (setup.wValueL == IPRODUCT) {
else if (setup.wValueL == IMANUFACTURER) return USB_SendStringDescriptor(STRING_PRODUCT, strlen(USB_PRODUCT));
desc_addr = (const u8*)&STRING_IMANUFACTURER; }
else if (setup.wValueL == IMANUFACTURER) {
return USB_SendStringDescriptor(STRING_MANUFACTURER, strlen(USB_MANUFACTURER));
}
else else
return false; return false;
} }
if (desc_addr == 0) if (desc_addr == 0)
return false; return false;
if (desc_length == 0) u8 desc_length = pgm_read_byte(desc_addr);
desc_length = pgm_read_byte(desc_addr);
USB_SendControl(TRANSFER_PGM,desc_addr,desc_length); USB_SendControl(TRANSFER_PGM,desc_addr,desc_length);
return true; return true;