Tighten up the HID class bootloader code slightly, document that it currently exceeds 2KB of bootloader space for all models other than the Series 2 USB AVRs.
/** Contains the current baud rate and other settings of the first virtual serial port. This must be retained as some
* operating systems will not open the port unless the settings can be set successfully.
*/
-CDC_Line_Coding_t LineEncoding = { .BaudRateBPS = 0,
- .CharFormat = OneStopBit,
- .ParityType = Parity_None,
- .DataBits = 8 };
+static CDC_LineEncoding_t LineEncoding = { .BaudRateBPS = 0,
+ .CharFormat = CDC_LINEENCODING_OneStopBit,
+ .ParityType = CDC_PARITY_None,
+ .DataBits = 8 };
/** Current address counter. This stores the current address of the FLASH or EEPROM as set by the host,
* and is used when reading or writing to the AVRs memory (either FLASH or EEPROM depending on the issued
* command.)
*/
-uint32_t CurrAddress;
+static uint32_t CurrAddress;
/** Flag to indicate if the bootloader should be running, or should exit and allow the application code to run
* via a watchdog reset. When cleared the bootloader will exit, starting the watchdog and entering an infinite
* loop until the AVR restarts and the application runs.
*/
-bool RunBootloader = true;
+static bool RunBootloader = true;
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously
/* Process CDC specific control requests */
switch (USB_ControlRequest.bRequest)
{
- case REQ_GetLineEncoding:
+ case CDC_REQ_GetLineEncoding:
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
{
Endpoint_ClearSETUP();
/* Write the line coding data to the control endpoint */
- Endpoint_Write_Control_Stream_LE(&LineEncoding, sizeof(CDC_Line_Coding_t));
+ Endpoint_Write_Control_Stream_LE(&LineEncoding, sizeof(CDC_LineEncoding_t));
Endpoint_ClearOUT();
}
break;
- case REQ_SetLineEncoding:
+ case CDC_REQ_SetLineEncoding:
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
{
Endpoint_ClearSETUP();
/* Read the line coding data in from the host into the global struct */
- Endpoint_Read_Control_Stream_LE(&LineEncoding, sizeof(CDC_Line_Coding_t));
+ Endpoint_Read_Control_Stream_LE(&LineEncoding, sizeof(CDC_LineEncoding_t));
Endpoint_ClearIN();
}
/** Eight character bootloader firmware identifier reported to the host when requested */
#define SOFTWARE_IDENTIFIER "LUFACDC"
- /** CDC Class specific request to get the current virtual serial port configuration settings. */
- #define REQ_GetLineEncoding 0x21
-
- /** CDC Class specific request to set the current virtual serial port configuration settings. */
- #define REQ_SetLineEncoding 0x20
-
/* Type Defines: */
- /** Type define for the virtual serial port line encoding settings, for storing the current USART configuration
- * as set by the host via a class specific request.
- */
- typedef struct
- {
- uint32_t BaudRateBPS; /**< Baud rate of the virtual serial port, in bits per second */
- uint8_t CharFormat; /**< Character format of the virtual serial port, a value from the
- * CDCDevice_CDC_LineCodingFormats_t enum
- */
- uint8_t ParityType; /**< Parity setting of the virtual serial port, a value from the
- * CDCDevice_LineCodingParity_t enum
- */
- uint8_t DataBits; /**< Bits of data per character of the virtual serial port */
- } CDC_Line_Coding_t;
-
/** Type define for a non-returning pointer to the start of the loaded application in flash memory. */
typedef void (*AppPtr_t)(void) ATTR_NO_RETURN;
- /* Enums: */
- /** Enum for the possible line encoding formats of a virtual serial port. */
- enum CDCDevice_CDC_LineCodingFormats_t
- {
- OneStopBit = 0, /**< Each frame contains one stop bit */
- OneAndAHalfStopBits = 1, /**< Each frame contains one and a half stop bits */
- TwoStopBits = 2, /**< Each frame contains two stop bits */
- };
-
- /** Enum for the possible line encoding parity settings of a virtual serial port. */
- enum CDCDevice_LineCodingParity_t
- {
- Parity_None = 0, /**< No parity bit mode on each frame */
- Parity_Odd = 1, /**< Odd parity bit mode on each frame */
- Parity_Even = 2, /**< Even parity bit mode on each frame */
- Parity_Mark = 3, /**< Mark parity bit mode on each frame */
- Parity_Space = 4, /**< Space parity bit mode on each frame */
- };
-
/* Function Prototypes: */
void CDC_Task(void);
void SetupHardware(void);
* other than erase. This is initially set to the value set by SECURE_MODE, and cleared by the bootloader
* once a memory erase has completed in a bootloader session.
*/
-bool IsSecure = SECURE_MODE;
+static bool IsSecure = SECURE_MODE;
/** Flag to indicate if the bootloader should be running, or should exit and allow the application code to run
* via a soft reset. When cleared, the bootloader will abort, the USB interface will shut down and the application
* jumped to via an indirect jump to location 0x0000 (or other location specified by the host).
*/
-bool RunBootloader = true;
+static bool RunBootloader = true;
/** Flag to indicate if the bootloader is waiting to exit. When the host requests the bootloader to exit and
* jump to the application address it specifies, it sends two sequential commands which must be properly
* acknowledged. Upon reception of the first the RunBootloader flag is cleared and the WaitForExit flag is set,
* causing the bootloader to wait for the final exit command before shutting down.
*/
-bool WaitForExit = false;
+static bool WaitForExit = false;
/** Current DFU state machine state, one of the values in the DFU_State_t enum. */
-uint8_t DFU_State = dfuIDLE;
+static uint8_t DFU_State = dfuIDLE;
/** Status code of the last executed DFU command. This is set to one of the values in the DFU_Status_t enum after
* each operation, and returned to the host when a Get Status DFU request is issued.
*/
-uint8_t DFU_Status = OK;
+static uint8_t DFU_Status = OK;
/** Data containing the DFU command sent from the host. */
-DFU_Command_t SentCommand;
+static DFU_Command_t SentCommand;
/** Response to the last issued Read Data DFU command. Unlike other DFU commands, the read command
* requires a single byte response from the bootloader containing the read data when the next DFU_UPLOAD command
* is issued by the host.
*/
-uint8_t ResponseByte;
+static uint8_t ResponseByte;
/** Pointer to the start of the user application. By default this is 0x0000 (the reset vector), however the host
* may specify an alternate address when issuing the application soft-start command.
*/
-AppPtr_t AppStartPtr = (AppPtr_t)0x0000;
+static AppPtr_t AppStartPtr = (AppPtr_t)0x0000;
/** 64-bit flash page number. This is concatenated with the current 16-bit address on USB AVRs containing more than
* 64KB of flash memory.
*/
-uint8_t Flash64KBPage = 0;
+static uint8_t Flash64KBPage = 0;
/** Memory start address, indicating the current address in the memory being addressed (either FLASH or EEPROM
* depending on the issued command from the host).
*/
-uint16_t StartAddr = 0x0000;
+static uint16_t StartAddr = 0x0000;
/** Memory end address, indicating the end address to read to/write from in the memory being addressed (either FLASH
* of EEPROM depending on the issued command from the host).
*/
-uint16_t EndAddr = 0x0000;
+static uint16_t EndAddr = 0x0000;
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously
switch (USB_ControlRequest.bRequest)
{
- case REQ_DFU_DNLOAD:
+ case DFU_REQ_DNLOAD:
Endpoint_ClearSETUP();
/* Check if bootloader is waiting to terminate */
Endpoint_ClearStatusStage();
break;
- case REQ_DFU_UPLOAD:
+ case DFU_REQ_UPLOAD:
Endpoint_ClearSETUP();
while (!(Endpoint_IsINReady()))
Endpoint_ClearStatusStage();
break;
- case REQ_DFU_GETSTATUS:
+ case DFU_REQ_GETSTATUS:
Endpoint_ClearSETUP();
/* Write 8-bit status value */
Endpoint_ClearStatusStage();
break;
- case REQ_DFU_CLRSTATUS:
+ case DFU_REQ_CLRSTATUS:
Endpoint_ClearSETUP();
/* Reset the status value variable to the default OK status */
Endpoint_ClearStatusStage();
break;
- case REQ_DFU_GETSTATE:
+ case DFU_REQ_GETSTATE:
Endpoint_ClearSETUP();
/* Write the current device state to the endpoint */
Endpoint_ClearStatusStage();
break;
- case REQ_DFU_ABORT:
+ case DFU_REQ_ABORT:
Endpoint_ClearSETUP();
/* Reset the current state variable to the default idle state */
#define DFU_FILLER_BYTES_SIZE 26
/** DFU class command request to detach from the host. */
- #define REQ_DFU_DETATCH 0x00
+ #define DFU_REQ_DETATCH 0x00
/** DFU class command request to send data from the host to the bootloader. */
- #define REQ_DFU_DNLOAD 0x01
+ #define DFU_REQ_DNLOAD 0x01
/** DFU class command request to send data from the bootloader to the host. */
- #define REQ_DFU_UPLOAD 0x02
+ #define DFU_REQ_UPLOAD 0x02
/** DFU class command request to get the current DFU status and state from the bootloader. */
- #define REQ_DFU_GETSTATUS 0x03
+ #define DFU_REQ_GETSTATUS 0x03
/** DFU class command request to reset the current DFU status and state variables to their defaults. */
- #define REQ_DFU_CLRSTATUS 0x04
+ #define DFU_REQ_CLRSTATUS 0x04
/** DFU class command request to get the current DFU state of the bootloader. */
- #define REQ_DFU_GETSTATE 0x05
+ #define DFU_REQ_GETSTATE 0x05
/** DFU class command request to abort the current multi-request transfer and return to the dfuIDLE state. */
- #define REQ_DFU_ABORT 0x06
+ #define DFU_REQ_ABORT 0x06
/** DFU command to begin programming the device's memory. */
#define COMMAND_PROG_START 0x01
* via a soft reset. When cleared, the bootloader will abort, the USB interface will shut down and the application\r
* started via a forced watchdog reset.\r
*/\r
-bool RunBootloader = true;\r
+static bool RunBootloader = true;\r
\r
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously \r
* runs the bootloader processing routine until instructed to soft-exit.\r
boot_spm_busy_wait();\r
\r
/* Write each of the FLASH page's bytes in sequence */\r
- for (uint16_t PageByte = 0; PageByte < SPM_PAGESIZE; PageByte += 2) \r
+ for (uint8_t PageWord = 0; PageWord < (SPM_PAGESIZE / 2); PageWord++) \r
{\r
/* Check if endpoint is empty - if so clear it and wait until ready for next packet */\r
if (!(Endpoint_BytesInEndpoint()))\r
}\r
\r
/* Write the next data word to the FLASH page */\r
- boot_page_fill(PageAddress + PageByte, Endpoint_Read_Word_LE());\r
+ boot_page_fill(PageAddress + ((uint16_t)PageWord << 1), Endpoint_Read_Word_LE());\r
}\r
\r
/* Write the filled FLASH page to memory */\r
* from PJRC, used with permission. This bootloader is delibertely non-compatible with the properietary HalfKay\r
* bootloader GUI; only the command line interface software accompanying this bootloader will work with it.\r
* \r
- * Out of the box this bootloader builds for the USB1287, and will fit into 4KB of bootloader space. If\r
- * you wish to enlarge this space and/or change the AVR model, you will need to edit the BOOT_START and MCU\r
- * values in the accompanying makefile.\r
+ * Out of the box this bootloader builds for the USB1287, and will fit into 2KB of bootloader space for the\r
+ * Series 2 USB AVRs (ATMEGAxxU2, AT90USBxx2) or 4KB of bootloader space for all other models. If you wish to\r
+ * enlarge this space and/or change the AVR model, you will need to edit the BOOT_START and MCU values in the\r
+ * accompanying makefile.\r
*\r
* \section SSec_Options Project Options\r
*\r
* the device will send, and what it may be sent back from the host. Refer to the HID specification for\r
* more details on HID report descriptors.\r
*/\r
-USB_Descriptor_HIDReport_Datatype_t HIDReport[] =\r
+const USB_Descriptor_HIDReport_Datatype_t HIDReport[] =\r
{\r
- HID_RI_USAGE_PAGE(16, 0xFF00), /* Vendor Page 1 */\r
- HID_RI_USAGE(8, 0x01), /* Vendor Usage 1 */\r
+ HID_RI_USAGE_PAGE(16, 0xFFDC), /* Vendor Page 0xDC */\r
+ HID_RI_USAGE(8, 0xFB), /* Vendor Usage 0xFB */\r
HID_RI_COLLECTION(8, 0x01), /* Vendor Usage 1 */\r
- HID_RI_USAGE(8, 0x03), /* Vendor Usage 3 */\r
+ HID_RI_USAGE(8, 0x02), /* Vendor Usage 2 */\r
HID_RI_LOGICAL_MINIMUM(8, 0x00),\r
HID_RI_LOGICAL_MAXIMUM(8, 0xFF),\r
HID_RI_REPORT_SIZE(8, 0x08),\r
* number of device configurations. The descriptor is read out by the USB host when the enumeration\r
* process begins.\r
*/\r
-USB_Descriptor_Device_t DeviceDescriptor =\r
+const USB_Descriptor_Device_t DeviceDescriptor =\r
{\r
.Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},\r
\r
* and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting\r
* a configuration so that the host may correctly communicate with the USB device.\r
*/\r
-USB_Descriptor_Configuration_t ConfigurationDescriptor =\r
+const USB_Descriptor_Configuration_t ConfigurationDescriptor =\r
{\r
.Config = \r
{\r
const uint8_t wIndex,\r
const void** const DescriptorAddress)\r
{\r
- const uint8_t DescriptorType = (wValue >> 8);\r
+ const uint8_t DescriptorType = (wValue >> 8);\r
\r
const void* Address = NULL;\r
uint16_t Size = NO_DESCRIPTOR;\r
\r
- /* If/Else If chain compiles slightly smaller than a switch case */\r
if (DescriptorType == DTYPE_Device)\r
- {\r
- Address = &DeviceDescriptor;\r
- Size = sizeof(USB_Descriptor_Device_t); \r
- }\r
+ Address = &DeviceDescriptor;\r
else if (DescriptorType == DTYPE_Configuration)\r
- {\r
- Address = &ConfigurationDescriptor;\r
- Size = sizeof(USB_Descriptor_Configuration_t); \r
- }\r
+ Address = &ConfigurationDescriptor;\r
else if (DescriptorType == HID_DTYPE_HID)\r
- {\r
- Address = &ConfigurationDescriptor.HID_VendorHID;\r
- Size = sizeof(USB_HID_Descriptor_HID_t);\r
- }\r
+ Address = &ConfigurationDescriptor.HID_VendorHID;\r
else\r
- {\r
- Address = &HIDReport;\r
- Size = sizeof(HIDReport);\r
- }\r
+ Address = &HIDReport;\r
\r
+ if (Address != NULL)\r
+ Size = (Address == &HIDReport) ? sizeof(HIDReport) : ((USB_Descriptor_Header_t*)Address)->Size;\r
+ \r
*DescriptorAddress = Address;\r
return Size;\r
}\r
# Note that the bootloader size and start address given in AVRStudio is in words and not\r
# bytes, and so will need to be doubled to obtain the byte address needed by AVR-GCC.\r
FLASH_SIZE_KB = 128\r
-BOOT_SECTION_SIZE_KB = 2\r
+BOOT_SECTION_SIZE_KB = 4\r
BOOT_START = 0x$(shell echo "obase=16; ($(FLASH_SIZE_KB) - $(BOOT_SECTION_SIZE_KB)) * 1024" | bc)\r
\r
\r
LUFA_OPTS += -D NO_INTERNAL_SERIAL\r
LUFA_OPTS += -D NO_DEVICE_SELF_POWER\r
LUFA_OPTS += -D NO_DEVICE_REMOTE_WAKEUP\r
+LUFA_OPTS += -D NO_SOF_EVENTS\r
\r
\r
# Create the LUFA source path variables by including the LUFA root makefile\r
},
};
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
},
};
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
},
};
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
#include "GenericHID.h"
/** Buffer to hold the previously generated HID report, for comparison purposes inside the HID class driver. */
-uint8_t PrevHIDReportBuffer[GENERIC_REPORT_SIZE];
+static uint8_t PrevHIDReportBuffer[GENERIC_REPORT_SIZE];
/** Structure to contain reports from the host, so that they can be echoed back upon request */
-struct
+static struct
{
uint8_t ReportID;
uint16_t ReportSize;
},
};
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
#include "Joystick.h"
/** Buffer to hold the previously generated HID report, for comparison purposes inside the HID class driver. */
-uint8_t PrevJoystickHIDReportBuffer[sizeof(USB_JoystickReport_Data_t)];
+static uint8_t PrevJoystickHIDReportBuffer[sizeof(USB_JoystickReport_Data_t)];
/** LUFA HID Class driver interface configuration and state information. This structure is
* passed to all HID Class driver functions, so that multiple instances of the same class
},
};
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
#include "Keyboard.h"
/** Buffer to hold the previously generated Keyboard HID report, for comparison purposes inside the HID class driver. */
-uint8_t PrevKeyboardHIDReportBuffer[sizeof(USB_KeyboardReport_Data_t)];
+static uint8_t PrevKeyboardHIDReportBuffer[sizeof(USB_KeyboardReport_Data_t)];
/** LUFA HID Class driver interface configuration and state information. This structure is
* passed to all HID Class driver functions, so that multiple instances of the same class
},
};
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
#include "KeyboardMouse.h"
/** Buffer to hold the previously generated Keyboard HID report, for comparison purposes inside the HID class driver. */
-uint8_t PrevKeyboardHIDReportBuffer[sizeof(USB_KeyboardReport_Data_t)];
+static uint8_t PrevKeyboardHIDReportBuffer[sizeof(USB_KeyboardReport_Data_t)];
/** Buffer to hold the previously generated Mouse HID report, for comparison purposes inside the HID class driver. */
-uint8_t PrevMouseHIDReportBuffer[sizeof(USB_MouseReport_Data_t)];
+static uint8_t PrevMouseHIDReportBuffer[sizeof(USB_MouseReport_Data_t)];
/** LUFA HID Class driver interface configuration and state information. This structure is
* passed to all HID Class driver functions, so that multiple instances of the same class
},
};
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
#include "KeyboardMouseMultiReport.h"
/** Buffer to hold the previously generated HID report, for comparison purposes inside the HID class driver. */
-uint8_t PrevHIDReportBuffer[MAX(sizeof(USB_KeyboardReport_Data_t), sizeof(USB_MouseReport_Data_t))];
+static uint8_t PrevHIDReportBuffer[MAX(sizeof(USB_KeyboardReport_Data_t), sizeof(USB_MouseReport_Data_t))];
/** LUFA HID Class driver interface configuration and state information. This structure is
* passed to all HID Class driver functions, so that multiple instances of the same class
},
};
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
},
};
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
/** Structure to hold the SCSI response data to a SCSI INQUIRY command. This gives information about the device's
* features and capabilities.
*/
-SCSI_Inquiry_Response_t InquiryData =
+static const SCSI_Inquiry_Response_t InquiryData =
{
.DeviceType = DEVICE_TYPE_BLOCK,
.PeripheralQualifier = 0,
/** Structure to hold the sense data for the last issued SCSI command, which is returned to the host after a SCSI REQUEST SENSE
* command is issued. This gives information on exactly why the last command failed to complete.
*/
-SCSI_Request_Sense_Response_t SenseData =
+static SCSI_Request_Sense_Response_t SenseData =
{
.ResponseCode = 0x70,
.AdditionalLength = 0x0A,
},
};
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
/** Structure to hold the SCSI response data to a SCSI INQUIRY command. This gives information about the device's
* features and capabilities.
*/
-SCSI_Inquiry_Response_t InquiryData =
+static const SCSI_Inquiry_Response_t InquiryData =
{
.DeviceType = DEVICE_TYPE_BLOCK,
.PeripheralQualifier = 0,
/** Structure to hold the sense data for the last issued SCSI command, which is returned to the host after a SCSI REQUEST SENSE
* command is issued. This gives information on exactly why the last command failed to complete.
*/
-SCSI_Request_Sense_Response_t SenseData =
+static SCSI_Request_Sense_Response_t SenseData =
{
.ResponseCode = 0x70,
.AdditionalLength = 0x0A,
};
/** Buffer to hold the previously generated Keyboard HID report, for comparison purposes inside the HID class driver. */
-uint8_t PrevKeyboardHIDReportBuffer[sizeof(USB_KeyboardReport_Data_t)];
+static uint8_t PrevKeyboardHIDReportBuffer[sizeof(USB_KeyboardReport_Data_t)];
/** LUFA HID Class driver interface configuration and state information. This structure is
* passed to all HID Class driver functions, so that multiple instances of the same class
#include "Mouse.h"
/** Buffer to hold the previously generated Mouse HID report, for comparison purposes inside the HID class driver. */
-uint8_t PrevMouseHIDReportBuffer[sizeof(USB_MouseReport_Data_t)];
+static uint8_t PrevMouseHIDReportBuffer[sizeof(USB_MouseReport_Data_t)];
/** LUFA HID Class driver interface configuration and state information. This structure is
* passed to all HID Class driver functions, so that multiple instances of the same class
},
};
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
},
};
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
*/
static FILE USBSerialStream;
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
};
/** Buffer to hold the previously generated Mouse HID report, for comparison purposes inside the HID class driver. */
-uint8_t PrevMouseHIDReportBuffer[sizeof(USB_MouseReport_Data_t)];
+static uint8_t PrevMouseHIDReportBuffer[sizeof(USB_MouseReport_Data_t)];
/** LUFA HID Class driver interface configuration and state information. This structure is
* passed to all HID Class driver functions, so that multiple instances of the same class
},
};
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
};\r
\r
/** Current TMC control request that is being processed */\r
-uint8_t RequestInProgress = 0;\r
+static uint8_t RequestInProgress = 0;\r
\r
/** Stream callback abort flag for bulk IN data */\r
-bool IsTMCBulkINReset = false;\r
+static bool IsTMCBulkINReset = false;\r
\r
/** Stream callback abort flag for bulk OUT data */\r
-bool IsTMCBulkOUTReset = false;\r
+static bool IsTMCBulkOUTReset = false;\r
\r
/** Last used tag value for data transfers */\r
-uint8_t CurrentTransferTag = 0;\r
+static uint8_t CurrentTransferTag = 0;\r
\r
/** Length of last data transfer, for reporting to the host in case an in-progress transfer is aborted */\r
-uint32_t LastTransferLength = 0;\r
+static uint32_t LastTransferLength = 0;\r
\r
/** Main program entry point. This routine contains the overall program flow, including initial\r
* setup of all components and the main program loop.\r
#include "AudioInput.h"
/** Flag to indicate if the streaming audio alternative interface has been selected by the host. */
-bool StreamingAudioInterfaceSelected = false;
+static bool StreamingAudioInterfaceSelected = false;
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
#include "AudioOutput.h"
/** Flag to indicate if the streaming audio alternative interface has been selected by the host. */
-bool StreamingAudioInterfaceSelected = false;
+static bool StreamingAudioInterfaceSelected = false;
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
* It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical
* serial link characteristics and instead sends and receives data in endpoint streams.
*/
-CDC_LineEncoding_t LineEncoding1 = { .BaudRateBPS = 0,
- .CharFormat = CDC_LINEENCODING_OneStopBit,
- .ParityType = CDC_PARITY_None,
- .DataBits = 8 };
+static CDC_LineEncoding_t LineEncoding1 = { .BaudRateBPS = 0,
+ .CharFormat = CDC_LINEENCODING_OneStopBit,
+ .ParityType = CDC_PARITY_None,
+ .DataBits = 8 };
/** Contains the current baud rate and other settings of the second virtual serial port. While this demo does not use
* the physical USART and thus does not use these settings, they must still be retained and returned to the host
* It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical
* serial link characteristics and instead sends and receives data in endpoint streams.
*/
-CDC_LineEncoding_t LineEncoding2 = { .BaudRateBPS = 0,
- .CharFormat = CDC_LINEENCODING_OneStopBit,
- .ParityType = CDC_PARITY_None,
- .DataBits = 8 };
+static CDC_LineEncoding_t LineEncoding2 = { .BaudRateBPS = 0,
+ .CharFormat = CDC_LINEENCODING_OneStopBit,
+ .ParityType = CDC_PARITY_None,
+ .DataBits = 8 };
/** Main program entry point. This routine configures the hardware required by the application, then
/** Indicates what report mode the host has requested, true for normal HID reporting mode, false for special boot
* protocol reporting mode.
*/
-bool UsingReportProtocol = true;
+static bool UsingReportProtocol = true;
/** Current Idle period. This is set by the host via a Set Idle HID class request to silence the device's reports
* for either the entire idle duration, or until the report status changes (e.g. the user presses a key).
*/
-uint16_t IdleCount = 500;
+static uint16_t IdleCount = 500;
/** Current Idle period remaining. When the IdleCount value is set, this tracks the remaining number of idle
* milliseconds. This is separate to the IdleCount timer and is incremented and compared as the host may request
* the current idle period via a Get Idle HID class request, thus its value must be preserved.
*/
-uint16_t IdleMSRemaining = 0;
+static uint16_t IdleMSRemaining = 0;
/** Main program entry point. This routine configures the hardware required by the application, then
#include "KeyboardMouse.h"
/** Global structure to hold the current keyboard interface HID report, for transmission to the host */
-USB_KeyboardReport_Data_t KeyboardReportData;
+static USB_KeyboardReport_Data_t KeyboardReportData;
/** Global structure to hold the current mouse interface HID report, for transmission to the host */
-USB_MouseReport_Data_t MouseReportData;
+static USB_MouseReport_Data_t MouseReportData;
/** Main program entry point. This routine configures the hardware required by the application, then
/** Structure to hold the SCSI response data to a SCSI INQUIRY command. This gives information about the device's
* features and capabilities.
*/
-SCSI_Inquiry_Response_t InquiryData =
+static const SCSI_Inquiry_Response_t InquiryData =
{
.DeviceType = DEVICE_TYPE_BLOCK,
.PeripheralQualifier = 0,
/** Structure to hold the sense data for the last issued SCSI command, which is returned to the host after a SCSI REQUEST SENSE
* command is issued. This gives information on exactly why the last command failed to complete.
*/
-SCSI_Request_Sense_Response_t SenseData =
+static SCSI_Request_Sense_Response_t SenseData =
{
.ResponseCode = 0x70,
.AdditionalLength = 0x0A,
/** Indicates what report mode the host has requested, true for normal HID reporting mode, false for special boot
* protocol reporting mode.
*/
-bool UsingReportProtocol = true;
+static bool UsingReportProtocol = true;
/** Current Idle period. This is set by the host via a Set Idle HID class request to silence the device's reports
* for either the entire idle duration, or until the report status changes (e.g. the user moves the mouse).
*/
-uint16_t IdleCount = 0;
+static uint16_t IdleCount = 0;
/** Current Idle period remaining. When the IdleCount value is set, this tracks the remaining number of idle
* milliseconds. This is separate to the IdleCount timer and is incremented and compared as the host may request
* the current idle period via a Get Idle HID class request, thus its value must be preserved.
*/
-uint16_t IdleMSRemaining = 0;
+static uint16_t IdleMSRemaining = 0;
/** Main program entry point. This routine configures the hardware required by the application, then
* It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical
* serial link characteristics and instead sends and receives data in endpoint streams.
*/
-CDC_LineEncoding_t LineEncoding = { .BaudRateBPS = 0,
- .CharFormat = CDC_LINEENCODING_OneStopBit,
- .ParityType = CDC_PARITY_None,
- .DataBits = 8 };
+static CDC_LineEncoding_t LineEncoding = { .BaudRateBPS = 0,
+ .CharFormat = CDC_LINEENCODING_OneStopBit,
+ .ParityType = CDC_PARITY_None,
+ .DataBits = 8 };
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
#include "DeviceFunctions.h"
/** Buffer to hold the previously generated Mouse Device HID report, for comparison purposes inside the HID class driver. */
-uint8_t PrevMouseHIDReportBuffer[sizeof(USB_MouseReport_Data_t)];
+static uint8_t PrevMouseHIDReportBuffer[sizeof(USB_MouseReport_Data_t)];
/** LUFA HID Class driver interface configuration and state information. This structure is
* passed to all HID Class driver functions, so that multiple instances of the same class
#include "JoystickHostWithParser.h"
/** Processed HID report descriptor items structure, containing information on each HID report element */
-HID_ReportInfo_t HIDReportInfo;
+static HID_ReportInfo_t HIDReportInfo;
/** LUFA HID Class driver interface configuration and state information. This structure is
* passed to all HID Class driver functions, so that multiple instances of the same class
#include "KeyboardHostWithParser.h"
/** Processed HID report descriptor items structure, containing information on each HID report element */
-HID_ReportInfo_t HIDReportInfo;
+static HID_ReportInfo_t HIDReportInfo;
/** LUFA HID Class driver interface configuration and state information. This structure is
* passed to all HID Class driver functions, so that multiple instances of the same class
#include "MouseHostWithParser.h"
/** Processed HID report descriptor items structure, containing information on each HID report element */
-HID_ReportInfo_t HIDReportInfo;
+static HID_ReportInfo_t HIDReportInfo;
/** LUFA HID Class driver interface configuration and state information. This structure is
* passed to all HID Class driver functions, so that multiple instances of the same class
},
};
+
/** Main program entry point. This routine configures the hardware required by the application, then
* enters a loop to run the application tasks in sequence.
*/
#include "RNDISEthernetHost.h"
/** Buffer to hold incoming and outgoing Ethernet packets. */
-uint8_t PacketBuffer[1024];
+static int8_t PacketBuffer[1024];
/** LUFA RNDIS Class driver interface configuration and state information. This structure is
* passed to all RNDIS Class driver functions, so that multiple instances of the same class
},
};
+
/** Main program entry point. This routine configures the hardware required by the application, then
* enters a loop to run the application tasks in sequence.
*/
},
};
+
/** Main program entry point. This routine configures the hardware required by the application, then
* enters a loop to run the application tasks in sequence.
*/
},
};
+
/** Main program entry point. This routine configures the hardware required by the application, then
* enters a loop to run the application tasks in sequence.
*/
void USB_Device_ProcessControlRequest(void)
{
- uint8_t* RequestHeader = (uint8_t*)&USB_ControlRequest;
+ uint8_t* RequestHeader = (uint8_t*)&USB_ControlRequest;
for (uint8_t RequestHeaderByte = 0; RequestHeaderByte < sizeof(USB_Request_Header_t); RequestHeaderByte++)
*(RequestHeader++) = Endpoint_Read_Byte();
while (!(Endpoint_IsINReady()));
- USB_DeviceState = (DeviceAddress) ? DEVICE_STATE_Addressed : DEVICE_STATE_Default;
-
USB_Device_SetDeviceAddress(DeviceAddress);
}
+
+ USB_DeviceState = (DeviceAddress) ? DEVICE_STATE_Addressed : DEVICE_STATE_Default;
}
static void USB_Device_SetConfiguration(void)
void USB_INT_ClearAllInterrupts(void)
{
#if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
- USBINT = 0;
+ USBINT = 0;
#endif
#if defined(USB_CAN_BE_BOTH)
- OTGINT = 0;
+ OTGINT = 0;
#endif
#if defined(USB_CAN_BE_HOST)
- UHINT = 0;
+ UHINT = 0;
#endif
#if defined(USB_CAN_BE_DEVICE)
- UDINT = 0;
+ UDINT = 0;
#endif
}
bool HardwareSPIMode = true;
/** Software SPI data register for sending and receiving */
-volatile uint8_t SoftSPI_Data;
+static volatile uint8_t SoftSPI_Data;
/** Number of bits left to transfer in the software SPI driver */
-volatile uint8_t SoftSPI_BitsRemaining;
+static volatile uint8_t SoftSPI_BitsRemaining;
/** ISR to handle software SPI transmission and reception */
#include "V2ProtocolParams.h"
/* Non-Volatile Parameter Values for EEPROM storage */
-uint8_t EEMEM EEPROM_Rest_Polarity = 0x00;
+static uint8_t EEMEM EEPROM_Rest_Polarity = 0x00;
/* Volatile Parameter Values for RAM storage */
static ParameterItem_t ParameterTable[] =
#include "Benito.h"
/** Circular buffer to hold data from the serial port before it is sent to the host. */
-RingBuffer_t USARTtoUSB_Buffer;
+static RingBuffer_t USARTtoUSB_Buffer;
/** Underlying data buffer for \ref USARTtoUSB_Buffer, where the stored bytes are located. */
-uint8_t USARTtoUSB_Buffer_Data[128];
+static uint8_t USARTtoUSB_Buffer_Data[128];
/** Pulse generation counters to keep track of the number of milliseconds remaining for each pulse type */
volatile struct
},
};
+
void DiskDevice_USBTask(void)
{
MS_Device_USBTask(&DiskDevice_MS_Interface);
},
};
+
void DiskHost_USBTask(void)
{
if (USB_HostState == HOST_STATE_Addressed)
/** Structure to hold the SCSI response data to a SCSI INQUIRY command. This gives information about the device's
* features and capabilities.
*/
-SCSI_Inquiry_Response_t InquiryData =
+static const SCSI_Inquiry_Response_t InquiryData =
{
.DeviceType = DEVICE_TYPE_BLOCK,
.PeripheralQualifier = 0,
/** Structure to hold the sense data for the last issued SCSI command, which is returned to the host after a SCSI REQUEST SENSE
* command is issued. This gives information on exactly why the last command failed to complete.
*/
-SCSI_Request_Sense_Response_t SenseData =
+static SCSI_Request_Sense_Response_t SenseData =
{
.ResponseCode = 0x70,
.AdditionalLength = 0x0A,
/** Petite FAT Fs structure to hold the internal state of the FAT driver for the Dataflash contents. */
FATFS DiskFATState;
+
/** Stream character fetching routine for the FAT driver so that characters from the currently open file can be
* read in sequence when applied to a stdio stream.
*/
};\r
\r
/** 8-bit 256 entry Sine Wave lookup table */\r
-const uint8_t SineTable[256] =\r
+static const uint8_t SineTable[256] =\r
{\r
128, 131, 134, 137, 140, 143, 146, 149, 152, 156, 159, 162, 165, 168, 171, 174,\r
176, 179, 182, 185, 188, 191, 193, 196, 199, 201, 204, 206, 209, 211, 213, 216,\r
};\r
\r
/** Array of structures describing each note being generated */\r
-DDSNoteData NoteData[MAX_SIMULTANEOUS_NOTES];\r
+static DDSNoteData NoteData[MAX_SIMULTANEOUS_NOTES];\r
+\r
\r
/** Main program entry point. This routine contains the overall program flow, including initial\r
* setup of all components and the main program loop.\r
/** Bit buffers to hold the read bits for each of the three magnetic card tracks before they are transmitted
* to the host as keyboard presses.
*/
-BitBuffer_t TrackDataBuffers[TOTAL_TRACKS];
+static BitBuffer_t TrackDataBuffers[TOTAL_TRACKS];
/** Pointer to the current track buffer being sent to the host. */
-BitBuffer_t* CurrentTrackBuffer = &TrackDataBuffers[TOTAL_TRACKS];
+static BitBuffer_t* CurrentTrackBuffer = &TrackDataBuffers[TOTAL_TRACKS];
/** Buffer to hold the previously generated Keyboard HID report, for comparison purposes inside the HID class driver. */
-uint8_t PrevKeyboardHIDReportBuffer[sizeof(USB_KeyboardReport_Data_t)];
+static uint8_t PrevKeyboardHIDReportBuffer[sizeof(USB_KeyboardReport_Data_t)];
/** LUFA HID Class driver interface configuration and state information. This structure is
* passed to all HID Class driver functions, so that multiple instances of the same class
},
};
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
#include "MissileLauncher.h"
/** Launcher first init command report data sequence */
-uint8_t CMD_INITA[8] = { 85, 83, 66, 67, 0, 0, 4, 0 };
+static const uint8_t CMD_INITA[8] = { 85, 83, 66, 67, 0, 0, 4, 0 };
/** Launcher second init command report data sequence */
-uint8_t CMD_INITB[8] = { 85, 83, 66, 67, 0, 64, 2, 0 };
+static const uint8_t CMD_INITB[8] = { 85, 83, 66, 67, 0, 64, 2, 0 };
/** Launcher command report data sequence to stop all movement */
-uint8_t CMD_STOP[8] = { 0, 0, 0, 0, 0, 0, 8, 8 };
+static const uint8_t CMD_STOP[8] = { 0, 0, 0, 0, 0, 0, 8, 8 };
/** Launcher command report data sequence to move left */
-uint8_t CMD_LEFT[8] = { 0, 1, 0, 0, 0, 0, 8, 8 };
+static const uint8_t CMD_LEFT[8] = { 0, 1, 0, 0, 0, 0, 8, 8 };
/** Launcher command report data sequence to move right */
-uint8_t CMD_RIGHT[8] = { 0, 0, 1, 0, 0, 0, 8, 8 };
+static const uint8_t CMD_RIGHT[8] = { 0, 0, 1, 0, 0, 0, 8, 8 };
/** Launcher command report data sequence to move up */
-uint8_t CMD_UP[8] = { 0, 0, 0, 1, 0, 0, 8, 8 };
+static const uint8_t CMD_UP[8] = { 0, 0, 0, 1, 0, 0, 8, 8 };
/** Launcher command report data sequence to move down */
-uint8_t CMD_DOWN[8] = { 0, 0, 0, 0, 1, 0, 8, 8 };
+static const uint8_t CMD_DOWN[8] = { 0, 0, 0, 0, 1, 0, 8, 8 };
/** Launcher command report data sequence to move left and up */
-uint8_t CMD_LEFTUP[8] = { 0, 1, 0, 1, 0, 0, 8, 8 };
+static const uint8_t CMD_LEFTUP[8] = { 0, 1, 0, 1, 0, 0, 8, 8 };
/** Launcher command report data sequence to move right and up */
-uint8_t CMD_RIGHTUP[8] = { 0, 0, 1, 1, 0, 0, 8, 8 };
+static const uint8_t CMD_RIGHTUP[8] = { 0, 0, 1, 1, 0, 0, 8, 8 };
/** Launcher command report data sequence to move left and down */
-uint8_t CMD_LEFTDOWN[8] = { 0, 1, 0, 0, 1, 0, 8, 8 };
+static const uint8_t CMD_LEFTDOWN[8] = { 0, 1, 0, 0, 1, 0, 8, 8 };
/** Launcher command report data sequence to move right and down */
-uint8_t CMD_RIGHTDOWN[8] = { 0, 0, 1, 0, 1, 0, 8, 8 };
+static const uint8_t CMD_RIGHTDOWN[8] = { 0, 0, 1, 0, 1, 0, 8, 8 };
/** Launcher command report data sequence to fire a missile */
-uint8_t CMD_FIRE[8] = { 0, 0, 0, 0, 0, 1, 8, 8 };
+static const uint8_t CMD_FIRE[8] = { 0, 0, 0, 0, 0, 1, 8, 8 };
/** Last command sent to the launcher, to determine what new command (if any) must be sent */
-uint8_t* CmdState;
+static const uint8_t* CmdState;
/** Buffer to hold a command to send to the launcher */
-uint8_t CmdBuffer[LAUNCHER_CMD_BUFFER_SIZE];
+static uint8_t CmdBuffer[LAUNCHER_CMD_BUFFER_SIZE];
/** Main program entry point. This routine configures the hardware required by the application, then
* \param[in] Report Report data to send.
* \param[in] ReportSize Report length in bytes.
*/
-void Send_Command_Report(uint8_t* const Report,
+void Send_Command_Report(const uint8_t* const Report,
const uint16_t ReportSize)
{
memcpy(CmdBuffer, Report, 8);
*
* \param[in] Command One of the command constants.
*/
-void Send_Command(uint8_t* const Command)
+void Send_Command(const uint8_t* const Command)
{
if ((CmdState == CMD_STOP && Command != CMD_STOP) ||
(CmdState != CMD_STOP && Command == CMD_STOP))
void SetupHardware(void);
void Read_Joystick_Status(void);
- void Send_Command_Report(uint8_t* const Report,
+ void Send_Command_Report(const uint8_t* const Report,
const uint16_t ReportSize);
- void Send_Command(uint8_t* const Command);
+ void Send_Command(const uint8_t* const Command);
void HID_Host_Task(void);
/** Structure to hold the SCSI response data to a SCSI INQUIRY command. This gives information about the device's
* features and capabilities.
*/
-SCSI_Inquiry_Response_t InquiryData =
+static const SCSI_Inquiry_Response_t InquiryData =
{
.DeviceType = DEVICE_TYPE_BLOCK,
.PeripheralQualifier = 0,
/** Structure to hold the sense data for the last issued SCSI command, which is returned to the host after a SCSI REQUEST SENSE
* command is issued. This gives information on exactly why the last command failed to complete.
*/
-SCSI_Request_Sense_Response_t SenseData =
+static SCSI_Request_Sense_Response_t SenseData =
{
.ResponseCode = 0x70,
.AdditionalLength = 0x0A,
};
/** Buffer to hold the previously generated HID report, for comparison purposes inside the HID class driver. */
-uint8_t PrevHIDReportBuffer[GENERIC_REPORT_SIZE];
+static uint8_t PrevHIDReportBuffer[GENERIC_REPORT_SIZE];
/** LUFA HID Class driver interface configuration and state information. This structure is
* passed to all HID Class driver functions, so that multiple instances of the same class
};
/** Non-volatile Logging Interval value in EEPROM, stored as a number of 500ms ticks */
-uint8_t EEMEM LoggingInterval500MS_EEPROM = DEFAULT_LOG_INTERVAL;
+static uint8_t EEMEM LoggingInterval500MS_EEPROM = DEFAULT_LOG_INTERVAL;
/** SRAM Logging Interval value fetched from EEPROM, stored as a number of 500ms ticks */
-uint8_t LoggingInterval500MS_SRAM;
+static uint8_t LoggingInterval500MS_SRAM;
/** Total number of 500ms logging ticks elapsed since the last log value was recorded */
-uint16_t CurrentLoggingTicks;
+static uint16_t CurrentLoggingTicks;
/** FAT Fs structure to hold the internal state of the FAT driver for the Dataflash contents. */
-FATFS DiskFATState;
+static FATFS DiskFATState;
/** FAT Fs structure to hold a FAT file handle for the log data write destination. */
-FIL TempLogFile;
+static FIL TempLogFile;
/** ISR to handle the 500ms ticks for sampling and data logging */
#include "USBtoSerial.h"
/** Circular buffer to hold data from the host before it is sent to the device via the serial port. */
-RingBuffer_t USBtoUSART_Buffer;
+static RingBuffer_t USBtoUSART_Buffer;
/** Underlying data buffer for \ref USBtoUSART_Buffer, where the stored bytes are located. */
-uint8_t USBtoUSART_Buffer_Data[128];
+static uint8_t USBtoUSART_Buffer_Data[128];
/** Circular buffer to hold data from the serial port before it is sent to the host. */
-RingBuffer_t USARTtoUSB_Buffer;
+static RingBuffer_t USARTtoUSB_Buffer;
/** Underlying data buffer for \ref USARTtoUSB_Buffer, where the stored bytes are located. */
-uint8_t USARTtoUSB_Buffer_Data[128];
-
+static uint8_t USARTtoUSB_Buffer_Data[128];
/** LUFA CDC Class driver interface configuration and state information. This structure is
* passed to all CDC Class driver functions, so that multiple instances of the same class
},
};
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
/** Structure to hold the SCSI response data to a SCSI INQUIRY command. This gives information about the device's
* features and capabilities.
*/
-SCSI_Inquiry_Response_t InquiryData =
+static const SCSI_Inquiry_Response_t InquiryData =
{
.DeviceType = DEVICE_TYPE_BLOCK,
.PeripheralQualifier = 0,
/** Structure to hold the sense data for the last issued SCSI command, which is returned to the host after a SCSI REQUEST SENSE
* command is issued. This gives information on exactly why the last command failed to complete.
*/
-SCSI_Request_Sense_Response_t SenseData =
+static SCSI_Request_Sense_Response_t SenseData =
{
.ResponseCode = 0x70,
.AdditionalLength = 0x0A,
#include "uIPManagement.h"
/** Connection timer, to retain the time elapsed since the last time the uIP connections were managed. */
-struct timer ConnectionTimer;
+static struct timer ConnectionTimer;
/** ARP timer, to retain the time elapsed since the ARP cache was last updated. */
-struct timer ARPTimer;
+static struct timer ARPTimer;
-/** MAC address of the RNDIS device, when enumerated */
+/** MAC address of the RNDIS device, when enumerated. */
struct uip_eth_addr MACAddress;
+/** Indicates if an IP configuration has been set in the device. */
bool HaveIPConfiguration;
-/** Configures the uIP stack ready for network traffic. */
+
+/** Configures the uIP stack ready for network traffic processing. */
void uIPManagement_Init(void)
{
/* uIP Timing Initialization */
/** Temporary data variable to hold the byte being received as it is shifted in */
static uint8_t RX_Data;
+
/** Initialises the software UART, ready for data transmission and reception into the global ring buffers. */
void SoftUART_Init(void)
{
RingBuffer_t USBtoUART_Buffer;
/** Underlying data buffer for \ref USBtoUART_Buffer, where the stored bytes are located. */
-uint8_t USBtoUART_Buffer_Data[128];
+static uint8_t USBtoUART_Buffer_Data[128];
/** Circular buffer to hold data from the serial port before it is sent to the host. */
RingBuffer_t UARTtoUSB_Buffer;
/** Underlying data buffer for \ref UARTtoUSB_Buffer, where the stored bytes are located. */
-uint8_t UARTtoUSB_Buffer_Data[128];
+static uint8_t UARTtoUSB_Buffer_Data[128];
/** Main program entry point. This routine contains the overall program flow, including initial