Added new USE_INTERNAL_SERIAL define for using the unique serial numbers in some...
authorDean Camera <dean@fourwalledcubicle.com>
Sun, 21 Jun 2009 09:22:31 +0000 (09:22 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Sun, 21 Jun 2009 09:22:31 +0000 (09:22 +0000)
Demos/Device/ClassDriver/CDC/Descriptors.c
Demos/Device/ClassDriver/DualCDC/Descriptors.c
Demos/Device/ClassDriver/MassStorage/Descriptors.c
Demos/Device/ClassDriver/USBtoSerial/Descriptors.c
LUFA/Drivers/USB/HighLevel/StdDescriptors.h
LUFA/Drivers/USB/LowLevel/DevChapter9.c
LUFA/Drivers/USB/LowLevel/DevChapter9.h
LUFA/ManPages/ChangeLog.txt
LUFA/ManPages/CompileTimeTokens.txt

index 9a2fe5e..1cdad8e 100644 (file)
@@ -59,7 +59,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
 \r
        .ManufacturerStrIndex   = 0x01,\r
        .ProductStrIndex        = 0x02,\r
 \r
        .ManufacturerStrIndex   = 0x01,\r
        .ProductStrIndex        = 0x02,\r
-       .SerialNumStrIndex      = NO_DESCRIPTOR,\r
+       .SerialNumStrIndex      = USE_INTERNAL_SERIAL,\r
 \r
        .NumberOfConfigurations = 1\r
 };\r
 \r
        .NumberOfConfigurations = 1\r
 };\r
index 951a558..92b3eb9 100644 (file)
@@ -59,7 +59,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
        \r
        .ManufacturerStrIndex   = 0x01,\r
        .ProductStrIndex        = 0x02,\r
        \r
        .ManufacturerStrIndex   = 0x01,\r
        .ProductStrIndex        = 0x02,\r
-       .SerialNumStrIndex      = NO_DESCRIPTOR,\r
+       .SerialNumStrIndex      = USE_INTERNAL_SERIAL,\r
        \r
        .NumberOfConfigurations = 1\r
 };\r
        \r
        .NumberOfConfigurations = 1\r
 };\r
index 6c02a6c..13d18a6 100644 (file)
@@ -59,7 +59,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
                \r
        .ManufacturerStrIndex   = 0x01,\r
        .ProductStrIndex        = 0x02,\r
                \r
        .ManufacturerStrIndex   = 0x01,\r
        .ProductStrIndex        = 0x02,\r
-       .SerialNumStrIndex      = 0x03,\r
+       .SerialNumStrIndex      = USE_INTERNAL_SERIAL,\r
                \r
        .NumberOfConfigurations = 1\r
 };\r
                \r
        .NumberOfConfigurations = 1\r
 };\r
@@ -156,20 +156,6 @@ USB_Descriptor_String_t PROGMEM ProductString =
        .UnicodeString          = L"LUFA Mass Storage Demo"\r
 };\r
 \r
        .UnicodeString          = L"LUFA Mass Storage Demo"\r
 };\r
 \r
-/** Serial number descriptor string. This is a Unicode string containing a string of HEX characters at least 12\r
- *  digits in length to uniquely identify a device when concatenated with the device's Vendor and Product IDs. By\r
- *  using the unique serial number string to identify a device, the device drivers do not need to be reinstalled\r
- *  each time the device is inserted into a different USB port on the same system. <b>This should be unique between\r
- *  devices, or conflicts will occur if two devices sharing the same serial number are inserted into the same system\r
- *  at the same time.</b>\r
- */\r
-USB_Descriptor_String_t PROGMEM SerialNumberString =\r
-{\r
-       .Header                 = {.Size = USB_STRING_LEN(12), .Type = DTYPE_String},\r
-               \r
-       .UnicodeString          = L"000000000000"\r
-};\r
-\r
 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"\r
  *  documentation) by the application code so that the address and size of a requested descriptor can be given\r
  *  to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function\r
 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"\r
  *  documentation) by the application code so that the address and size of a requested descriptor can be given\r
  *  to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function\r
@@ -209,10 +195,6 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex,
                                        Address = (void*)&ProductString;\r
                                        Size    = pgm_read_byte(&ProductString.Header.Size);\r
                                        break;\r
                                        Address = (void*)&ProductString;\r
                                        Size    = pgm_read_byte(&ProductString.Header.Size);\r
                                        break;\r
-                               case 0x03: \r
-                                       Address = (void*)&SerialNumberString;\r
-                                       Size    = pgm_read_byte(&SerialNumberString.Header.Size);\r
-                                       break;\r
                        }\r
                        \r
                        break;\r
                        }\r
                        \r
                        break;\r
index d4db3a4..38f5689 100644 (file)
@@ -59,7 +59,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
                \r
        .ManufacturerStrIndex   = 0x01,\r
        .ProductStrIndex        = 0x02,\r
                \r
        .ManufacturerStrIndex   = 0x01,\r
        .ProductStrIndex        = 0x02,\r
-       .SerialNumStrIndex      = NO_DESCRIPTOR,\r
+       .SerialNumStrIndex      = USE_INTERNAL_SERIAL,\r
                \r
        .NumberOfConfigurations = 1\r
 };\r
                \r
        .NumberOfConfigurations = 1\r
 };\r
index 2ce75b2..274b84f 100644 (file)
                         *  descriptor does not exist.\r
                         */\r
                        #define NO_DESCRIPTOR                     0\r
                         *  descriptor does not exist.\r
                         */\r
                        #define NO_DESCRIPTOR                     0\r
+\r
+                       #if (!defined(NO_INTERNAL_SERIAL) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))) || defined(__DOXYGEN__)\r
+                               /** String descriptor index for the device's unique serial number string descriptor within the device.\r
+                                *  This unique serial number is used by the host to associate resources to the device (such as drivers or COM port\r
+                                *  number allocations) to a device regardless of the port it is plugged in to on the host. Some USB AVRs contain\r
+                                *  a unique serial number internally, and setting the device descriptors serial number string index to this value\r
+                                *  will cause it to use the internal serial number.\r
+                                *\r
+                                *  On unsupported devices, this will evaluate to NO_DESCRIPTOR and so will force the host to create a pseduo-serial\r
+                                *  number for the device.\r
+                                */\r
+                               #define USE_INTERNAL_SERIAL         0xDC\r
+                       #else\r
+                               #define USE_INTERNAL_SERIAL         NO_DESCRIPTOR\r
+                       #endif\r
                        \r
                        /** Macro to calculate the power value for the device descriptor, from a given number of milliamps. */\r
                        #define USB_CONFIG_POWER_MA(mA)            (mA >> 1)\r
                        \r
                        /** Macro to calculate the power value for the device descriptor, from a given number of milliamps. */\r
                        #define USB_CONFIG_POWER_MA(mA)            (mA >> 1)\r
                                                                          */\r
                                uint8_t                 SerialNumStrIndex; /**< String index for the product's globally unique hexadecimal\r
                                                                            *   serial number, in uppercase Unicode ASCII.\r
                                                                          */\r
                                uint8_t                 SerialNumStrIndex; /**< String index for the product's globally unique hexadecimal\r
                                                                            *   serial number, in uppercase Unicode ASCII.\r
-                                                                                                                       *\r
-                                                                                                                       *  \note On some AVR models, there is an embedded serial number\r
-                                                                                                                       *        in the chip which can be used for the device serial number.\r
-                                                                           *        To use this serial number, define USE_INTERNAL_SERIAL to a\r
-                                                                                                                       *        unique string index number in the project makefile and set\r
-                                                                                                                       *        this value to USE_INTERNAL_SERIAL.\r
-                                                                                                                       *\r
+                                                                           *\r
+                                                                           *  \note On some AVR models, there is an embedded serial number\r
+                                                                           *        in the chip which can be used for the device serial number.\r
+                                                                           *        To use this serial number, set this to USE_INTERNAL_SERIAL.\r
+                                                                           *        On unsupported devices, this will evaluate to 0 and will cause\r
+                                                                           *        the host to generate a pseudo-unique value for the device upon\r
+                                                                           *        insertion.\r
+                                                                           *\r
                                                                            *  \see ManufacturerStrIndex structure entry.\r
                                                                            */\r
 \r
                                                                            *  \see ManufacturerStrIndex structure entry.\r
                                                                            */\r
 \r
index 55b49b8..4014ed1 100644 (file)
@@ -179,7 +179,7 @@ static void USB_Device_GetDescriptor(void)
        void*    DescriptorPointer;\r
        uint16_t DescriptorSize;\r
        \r
        void*    DescriptorPointer;\r
        uint16_t DescriptorSize;\r
        \r
-       #if defined(USE_INTERNAL_SERIAL)\r
+       #if !defined(NO_INTERNAL_SERIAL) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))\r
        if (USB_ControlRequest.wValue == ((DTYPE_String << 8) | USE_INTERNAL_SERIAL))\r
        {\r
                uint8_t SignatureDescriptor[2 + (sizeof(int16_t) * 12)];\r
        if (USB_ControlRequest.wValue == ((DTYPE_String << 8) | USE_INTERNAL_SERIAL))\r
        {\r
                uint8_t SignatureDescriptor[2 + (sizeof(int16_t) * 12)];\r
index 65fa041..505256e 100644 (file)
                #include "../HighLevel/USBTask.h"\r
                #include "LowLevel.h"\r
 \r
                #include "../HighLevel/USBTask.h"\r
                #include "LowLevel.h"\r
 \r
-       /* Preprocessor Checks: */\r
-               #if defined(USE_INTERNAL_SERIAL) && !(defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))\r
-                       #error USE_INTERNAL_SERIAL invalid, the selected AVR model does not contain unique serial bytes.\r
-               #endif\r
-               \r
-               #if defined(USE_INTERNAL_SERIAL) && (USE_INTERNAL_SERIAL <= 1)\r
-                       #error USE_INTERNAL_SERIAL must be defined to the string descriptor index chosen for the serial number descriptor.\r
-               #endif\r
-\r
        /* Enable C linkage for C++ Compilers: */\r
                #if defined(__cplusplus)\r
                        extern "C" {\r
                #endif\r
 \r
        /* Enable C linkage for C++ Compilers: */\r
                #if defined(__cplusplus)\r
                        extern "C" {\r
                #endif\r
 \r
-       /* Public Interface - May be used in end-application: */\r
+       /* Public Interface - May be used in end-application: */                        \r
                /* Global Variables: */\r
                        /** Indicates the currently set configuration number of the device. USB devices may have several\r
                         *  different configurations which the host can select between; this indicates the currently selected\r
                /* Global Variables: */\r
                        /** Indicates the currently set configuration number of the device. USB devices may have several\r
                         *  different configurations which the host can select between; this indicates the currently selected\r
index f7ae4c6..6f116da 100644 (file)
@@ -28,7 +28,8 @@
   *    cleared to prevent endpoint type corruption\r
   *  - Fix documentation mentioning Pipe_GetCurrentToken() function when real name is Pipe_GetPipeToken()\r
   *  - Extend USB_GetDeviceConfigDescriptor() routine to require the configuration number within the device to fetch\r
   *    cleared to prevent endpoint type corruption\r
   *  - Fix documentation mentioning Pipe_GetCurrentToken() function when real name is Pipe_GetPipeToken()\r
   *  - Extend USB_GetDeviceConfigDescriptor() routine to require the configuration number within the device to fetch\r
-  *  - Added new USE_INTERNAL_SERIAL compile time option\r
+  *  - Added new USE_INTERNAL_SERIAL define for using the unique serial numbers in some AVR models as the USB device's serial number,\r
+  *    added NO_INTERNAL_SERIAL compile time option to turn off new serial number reading code\r
   *\r
   *  \section Sec_ChangeLog090605 Version 090605\r
   *\r
   *\r
   *  \section Sec_ChangeLog090605 Version 090605\r
   *\r
index e1f248d..bc49ba2 100644 (file)
  *  compatibility. If this token is defined, the structure element names are switched to the LUFA-specific but more descriptive\r
  *  names documented in the StdDescriptors.h source file.\r
  *\r
  *  compatibility. If this token is defined, the structure element names are switched to the LUFA-specific but more descriptive\r
  *  names documented in the StdDescriptors.h source file.\r
  *\r
- *  <b>USE_INTERNAL_SERIAL</b> - ( \ref Group_Descriptors ) \n\r
+ *  <b>NO_INTERNAL_SERIAL</b> - ( \ref Group_Descriptors ) \n\r
  *  Some AVR models contain a unique 20-digit serial number which can be used as the device serial number, while in device mode. This\r
  *  allows the host to uniquely identify the device regardless of if it is moved between USB ports on the same computer, allowing\r
  *  Some AVR models contain a unique 20-digit serial number which can be used as the device serial number, while in device mode. This\r
  *  allows the host to uniquely identify the device regardless of if it is moved between USB ports on the same computer, allowing\r
- *  allocated resources (such as drivers, COM Port number allocations) to be preserved. To make the library use this value for the\r
- *  device's serial number, define this token in the project makefile, set it to a unique string descriptor index (i.e. one not used\r
- *  elsewhere in the device for a string descriptor) and set the Device Descriptor's serial number descriptor index entry to the\r
- *  USE_INTERNAL_SERIAL value.\r
+ *  allocated resources (such as drivers, COM Port number allocations) to be preserved. This is not needed in many apps, and so the\r
+ *  code that performs this task can be disabled by defining this option and passing it to the compiler via the -D switch.\r
  *\r
  *  <b>FIXED_CONTROL_ENDPOINT_SIZE</b> - ( \ref Group_EndpointManagement ) \n\r
  *  By default, the library determines the size of the control endpoint (when in device mode) by reading the device descriptor.\r
  *\r
  *  <b>FIXED_CONTROL_ENDPOINT_SIZE</b> - ( \ref Group_EndpointManagement ) \n\r
  *  By default, the library determines the size of the control endpoint (when in device mode) by reading the device descriptor.\r