@@ -65,12 +65,21 @@ along with Hoodloader2. If not, see <http://www.gnu.org/licenses/>.
6565#define ARDUINO_MEGA_PID 0x0042 // R3 (0010 R1)
6666#define ARDUINO_MEGA_ADK_PID 0x0044 // R3 (003F R1)
6767
68+ // Only use RAM Descriptors if we have enough ram
69+ #ifdef USE_RAM_DESCRIPTORS
70+ #define DESCRIPTOR_PROGMEM
71+ #define STRING_PROGMEM (x ) (x)
72+ #else // PROGMEM descriptors
73+ #define DESCRIPTOR_PROGMEM PROGMEM
74+ #define STRING_PROGMEM (x ) pgm_read_byte(x)
75+ #endif
76+
6877/** Device descriptor structure. This descriptor, located in SRAM memory, describes the overall
6978 * device characteristics, including the supported USB version, control endpoint size and the
7079 * number of device configurations. The descriptor is read out by the USB host when the enumeration
7180 * process begins.
7281 */
73- const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
82+ const USB_Descriptor_Device_t DESCRIPTOR_PROGMEM DeviceDescriptor =
7483{
7584 .Header = {.Size = sizeof (USB_Descriptor_Device_t ), .Type = DTYPE_Device },
7685
@@ -98,7 +107,7 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
98107 * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
99108 * a configuration so that the host may correctly communicate with the USB device.
100109 */
101- const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
110+ const USB_Descriptor_Configuration_t DESCRIPTOR_PROGMEM ConfigurationDescriptor =
102111{
103112 .Config =
104113 {
@@ -207,26 +216,26 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
207216 * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
208217 * via the language ID table available at USB.org what languages the device supports for its string descriptors.
209218 */
210- const USB_Descriptor_String_t PROGMEM LanguageString = USB_STRING_DESCRIPTOR_ARRAY (LANGUAGE_ID_ENG );
219+ const USB_Descriptor_String_t DESCRIPTOR_PROGMEM LanguageString = USB_STRING_DESCRIPTOR_ARRAY (LANGUAGE_ID_ENG );
211220
212221/** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
213222 * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
214223 * Descriptor.
215224 */
216- const USB_Descriptor_String_t PROGMEM ManufacturerString = USB_STRING_DESCRIPTOR (L"NicoHood" );
225+ const USB_Descriptor_String_t DESCRIPTOR_PROGMEM ManufacturerString = USB_STRING_DESCRIPTOR (L"NicoHood" );
217226
218227/** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
219228 * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
220229 * Descriptor.
221230 */
222231#if (PRODUCTID == ARDUINO_UNO_PID )
223- const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR (L"HoodLoader2 Uno" );
232+ const USB_Descriptor_String_t DESCRIPTOR_PROGMEM ProductString = USB_STRING_DESCRIPTOR (L"HoodLoader2 Uno" );
224233#elif (PRODUCTID == ARDUINO_MEGA_PID )
225- const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR (L"HoodLoader2 Mega" );
234+ const USB_Descriptor_String_t DESCRIPTOR_PROGMEM ProductString = USB_STRING_DESCRIPTOR (L"HoodLoader2 Mega" );
226235#elif (PRODUCTID == ARDUINO_ADK_PID )
227- const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR (L"HoodLoader2 ADK" );
236+ const USB_Descriptor_String_t DESCRIPTOR_PROGMEM ProductString = USB_STRING_DESCRIPTOR (L"HoodLoader2 ADK" );
228237#else
229- const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR (L"HoodLoader2 Lufa" );
238+ const USB_Descriptor_String_t DESCRIPTOR_PROGMEM ProductString = USB_STRING_DESCRIPTOR (L"HoodLoader2 Lufa" );
230239#endif
231240
232241/** This function is called by the library when in device mode, and must be overridden (see LUFA library "USB Descriptors"
@@ -259,17 +268,17 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
259268 if (DescriptorNumber == STRING_ID_Language )
260269 {
261270 Address = & LanguageString ;
262- Size = pgm_read_byte (& LanguageString .Header .Size );
271+ Size = STRING_PROGMEM (& LanguageString .Header .Size );
263272 }
264273 else if (DescriptorNumber == STRING_ID_Manufacturer )
265274 {
266275 Address = & ManufacturerString ;
267- Size = pgm_read_byte (& ManufacturerString .Header .Size );
276+ Size = STRING_PROGMEM (& ManufacturerString .Header .Size );
268277 }
269278 else if (DescriptorNumber == STRING_ID_Product )
270279 {
271280 Address = & ProductString ;
272- Size = pgm_read_byte (& ProductString .Header .Size );
281+ Size = STRING_PROGMEM (& ProductString .Header .Size );
273282 }
274283
275284 break ;
0 commit comments