Converted device mode low-level demos to schedulerless.

pull/1469/head
Dean Camera 16 years ago
parent 2793c88fc6
commit 33a0184749

@ -36,18 +36,27 @@
#include "AudioInput.h" #include "AudioInput.h"
/* Scheduler Task List */ /** Flag to indicate if the streaming audio alternative interface has been selected by the host. */
TASK_LIST bool StreamingAudioInterfaceSelected = false;
{
{ .Task = USB_USBTask , .TaskStatus = TASK_STOP },
{ .Task = USB_Audio_Task , .TaskStatus = TASK_STOP },
};
/** Main program entry point. This routine configures the hardware required by the application, then /** Main program entry point. This routine contains the overall program flow, including initial
* starts the scheduler to run the application tasks. * setup of all components and the main program loop.
*/ */
int main(void) int main(void)
{
SetupHardware();
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
for (;;)
{
USB_Audio_Task();
USB_USBTask();
}
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{ {
/* Disable watchdog if enabled by bootloader/fuses */ /* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF); MCUSR &= ~(1 << WDRF);
@ -60,21 +69,10 @@ int main(void)
LEDs_Init(); LEDs_Init();
ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32); ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32);
ADC_SetupChannel(MIC_IN_ADC_CHANNEL); ADC_SetupChannel(MIC_IN_ADC_CHANNEL);
USB_Init();
/* Start the ADC conversion in free running mode */ /* Start the ADC conversion in free running mode */
ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | MIC_IN_ADC_CHANNEL); ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | MIC_IN_ADC_CHANNEL);
/* Indicate USB not ready */
UpdateStatus(Status_USBNotReady);
/* Initialize Scheduler so that it can be used */
Scheduler_Init();
/* Initialize USB Subsystem */
USB_Init();
/* Scheduling - routine never returns, so put this last in the main function */
Scheduler_Start();
} }
/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs, and /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs, and
@ -82,11 +80,8 @@ int main(void)
*/ */
void EVENT_USB_Connect(void) void EVENT_USB_Connect(void)
{ {
/* Start USB management task */
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
/* Indicate USB enumerating */ /* Indicate USB enumerating */
UpdateStatus(Status_USBEnumerating); LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
/* Sample reload timer initialization */ /* Sample reload timer initialization */
OCR0A = (F_CPU / AUDIO_SAMPLE_FREQUENCY) - 1; OCR0A = (F_CPU / AUDIO_SAMPLE_FREQUENCY) - 1;
@ -102,12 +97,11 @@ void EVENT_USB_Disconnect(void)
/* Stop the sample reload timer */ /* Stop the sample reload timer */
TCCR0B = 0; TCCR0B = 0;
/* Stop running audio and USB management tasks */ /* Indicate streaming audio interface not selected */
Scheduler_SetTaskMode(USB_Audio_Task, TASK_STOP); StreamingAudioInterfaceSelected = false;
Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);
/* Indicate USB not ready */ /* Indicate USB not ready */
UpdateStatus(Status_USBNotReady); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
} }
/** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration /** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration
@ -121,7 +115,7 @@ void EVENT_USB_ConfigurationChanged(void)
ENDPOINT_BANK_DOUBLE); ENDPOINT_BANK_DOUBLE);
/* Indicate USB connected and ready */ /* Indicate USB connected and ready */
UpdateStatus(Status_USBReady); LEDs_SetAllLEDs(LEDMASK_USB_READY);
} }
/** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific /** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific
@ -140,16 +134,7 @@ void EVENT_USB_UnhandledControlPacket(void)
Endpoint_ClearSETUP(); Endpoint_ClearSETUP();
/* Check if the host is enabling the audio interface (setting AlternateSetting to 1) */ /* Check if the host is enabling the audio interface (setting AlternateSetting to 1) */
if (USB_ControlRequest.wValue) StreamingAudioInterfaceSelected = ((USB_ControlRequest.wValue) != 0);
{
/* Start audio task */
Scheduler_SetTaskMode(USB_Audio_Task, TASK_RUN);
}
else
{
/* Stop audio task */
Scheduler_SetTaskMode(USB_Audio_Task, TASK_STOP);
}
/* Acknowledge status stage */ /* Acknowledge status stage */
while (!(Endpoint_IsINReady())); while (!(Endpoint_IsINReady()));
@ -160,36 +145,13 @@ void EVENT_USB_UnhandledControlPacket(void)
} }
} }
/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to
* log to a serial port, or anything else that is suitable for status updates.
*
* \param CurrentStatus Current status of the system, from the AudioInput_StatusCodes_t enum
*/
void UpdateStatus(uint8_t CurrentStatus)
{
uint8_t LEDMask = LEDS_NO_LEDS;
/* Set the LED mask to the appropriate LED mask based on the given status code */
switch (CurrentStatus)
{
case Status_USBNotReady:
LEDMask = (LEDS_LED1);
break;
case Status_USBEnumerating:
LEDMask = (LEDS_LED1 | LEDS_LED2);
break;
case Status_USBReady:
LEDMask = (LEDS_LED2 | LEDS_LED4);
break;
}
/* Set the board LEDs to the new LED mask */
LEDs_SetAllLEDs(LEDMask);
}
/** Task to manage the Audio interface, reading in ADC samples from the microphone, and them to the host. */ /** Task to manage the Audio interface, reading in ADC samples from the microphone, and them to the host. */
TASK(USB_Audio_Task) void USB_Audio_Task(void)
{ {
/* Check to see if the streaming interface is selected, if not the host is not receiving audio */
if (!(StreamingAudioInterfaceSelected))
return;
/* Select the audio stream endpoint */ /* Select the audio stream endpoint */
Endpoint_SelectEndpoint(AUDIO_STREAM_EPNUM); Endpoint_SelectEndpoint(AUDIO_STREAM_EPNUM);

@ -43,11 +43,10 @@
#include "Descriptors.h" #include "Descriptors.h"
#include <LUFA/Version.h> // Library Version Information #include <LUFA/Version.h>
#include <LUFA/Drivers/USB/USB.h> // USB Functionality #include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver #include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Drivers/Peripheral/ADC.h> // ADC driver #include <LUFA/Drivers/Peripheral/ADC.h>
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
/* Macros: */ /* Macros: */
/** ADC channel number for the microphone input. */ /** ADC channel number for the microphone input. */
@ -59,24 +58,25 @@
/** Maximum ADC range for the microphone input. */ /** Maximum ADC range for the microphone input. */
#define ADC_MAX_RANGE 0x3FF #define ADC_MAX_RANGE 0x3FF
/* Enums: */ /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
/** Enum for the possible status codes for passing to the UpdateStatus() function. */ #define LEDMASK_USB_NOTREADY LEDS_LED1
enum AudioInput_StatusCodes_t
{
Status_USBNotReady = 0, /**< USB is not ready (disconnected from a USB host) */
Status_USBEnumerating = 1, /**< USB interface is enumerating */
Status_USBReady = 2, /**< USB interface is connected and ready */
};
/* Task Definitions: */ /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
TASK(USB_Audio_Task); #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
#define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
/* Function Prototypes: */ /* Function Prototypes: */
void SetupHardware(void);
void USB_Audio_Task(void);
void EVENT_USB_Connect(void); void EVENT_USB_Connect(void);
void EVENT_USB_Disconnect(void); void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void); void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void); void EVENT_USB_UnhandledControlPacket(void);
void UpdateStatus(uint8_t CurrentStatus);
#endif #endif

@ -119,13 +119,12 @@ OBJDIR = .
# Path to the LUFA library # Path to the LUFA library
LUFA_PATH = ../../.. LUFA_PATH = ../../../..
# List C source files here. (C dependencies are automatically generated.) # List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c \ SRC = $(TARGET).c \
Descriptors.c \ Descriptors.c \
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \
@ -136,7 +135,6 @@ SRC = $(TARGET).c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \
$(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c \
# List C++ source files here. (C dependencies are automatically generated.) # List C++ source files here. (C dependencies are automatically generated.)

@ -36,18 +36,27 @@
#include "AudioOutput.h" #include "AudioOutput.h"
/* Scheduler Task List */ /** Flag to indicate if the streaming audio alternative interface has been selected by the host. */
TASK_LIST bool StreamingAudioInterfaceSelected = false;
{
{ .Task = USB_USBTask , .TaskStatus = TASK_STOP },
{ .Task = USB_Audio_Task , .TaskStatus = TASK_STOP },
};
/** Main program entry point. This routine configures the hardware required by the application, then /** Main program entry point. This routine contains the overall program flow, including initial
* starts the scheduler to run the application tasks. * setup of all components and the main program loop.
*/ */
int main(void) int main(void)
{
SetupHardware();
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
for (;;)
{
USB_Audio_Task();
USB_USBTask();
}
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{ {
/* Disable watchdog if enabled by bootloader/fuses */ /* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF); MCUSR &= ~(1 << WDRF);
@ -58,18 +67,7 @@ int main(void)
/* Hardware Initialization */ /* Hardware Initialization */
LEDs_Init(); LEDs_Init();
/* Indicate USB not ready */
UpdateStatus(Status_USBNotReady);
/* Initialize Scheduler so that it can be used */
Scheduler_Init();
/* Initialize USB Subsystem */
USB_Init(); USB_Init();
/* Scheduling - routine never returns, so put this last in the main function */
Scheduler_Start();
} }
/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs, and /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs, and
@ -77,11 +75,8 @@ int main(void)
*/ */
void EVENT_USB_Connect(void) void EVENT_USB_Connect(void)
{ {
/* Start USB management task */
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
/* Indicate USB enumerating */ /* Indicate USB enumerating */
UpdateStatus(Status_USBEnumerating); LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
/* Sample reload timer initialization */ /* Sample reload timer initialization */
OCR0A = (F_CPU / AUDIO_SAMPLE_FREQUENCY) - 1; OCR0A = (F_CPU / AUDIO_SAMPLE_FREQUENCY) - 1;
@ -129,12 +124,11 @@ void EVENT_USB_Disconnect(void)
PORTC = 0x00; PORTC = 0x00;
#endif #endif
/* Stop running audio and USB management tasks */ /* Indicate streaming audio interface not selected */
Scheduler_SetTaskMode(USB_Audio_Task, TASK_STOP); StreamingAudioInterfaceSelected = false;
Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);
/* Indicate USB not ready */ /* Indicate USB not ready */
UpdateStatus(Status_USBNotReady); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
} }
/** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration /** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration
@ -148,7 +142,7 @@ void EVENT_USB_ConfigurationChanged(void)
ENDPOINT_BANK_DOUBLE); ENDPOINT_BANK_DOUBLE);
/* Indicate USB connected and ready */ /* Indicate USB connected and ready */
UpdateStatus(Status_USBReady); LEDs_SetAllLEDs(LEDMASK_USB_READY);
} }
/** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific /** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific
@ -167,16 +161,7 @@ void EVENT_USB_UnhandledControlPacket(void)
Endpoint_ClearSETUP(); Endpoint_ClearSETUP();
/* Check if the host is enabling the audio interface (setting AlternateSetting to 1) */ /* Check if the host is enabling the audio interface (setting AlternateSetting to 1) */
if (USB_ControlRequest.wValue) StreamingAudioInterfaceSelected = ((USB_ControlRequest.wValue) != 0);
{
/* Start audio task */
Scheduler_SetTaskMode(USB_Audio_Task, TASK_RUN);
}
else
{
/* Stop audio task */
Scheduler_SetTaskMode(USB_Audio_Task, TASK_STOP);
}
/* Acknowledge status stage */ /* Acknowledge status stage */
while (!(Endpoint_IsINReady())); while (!(Endpoint_IsINReady()));
@ -187,38 +172,15 @@ void EVENT_USB_UnhandledControlPacket(void)
} }
} }
/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to
* log to a serial port, or anything else that is suitable for status updates.
*
* \param CurrentStatus Current status of the system, from the AudioOutput_StatusCodes_t enum
*/
void UpdateStatus(uint8_t CurrentStatus)
{
uint8_t LEDMask = LEDS_NO_LEDS;
/* Set the LED mask to the appropriate LED mask based on the given status code */
switch (CurrentStatus)
{
case Status_USBNotReady:
LEDMask = (LEDS_LED1);
break;
case Status_USBEnumerating:
LEDMask = (LEDS_LED1 | LEDS_LED2);
break;
case Status_USBReady:
LEDMask = (LEDS_LED2 | LEDS_LED4);
break;
}
/* Set the board LEDs to the new LED mask */
LEDs_SetAllLEDs(LEDMask);
}
/** Task to manage the Audio interface, reading in audio samples from the host, and outputting them to the speakers/LEDs as /** Task to manage the Audio interface, reading in audio samples from the host, and outputting them to the speakers/LEDs as
* desired. * desired.
*/ */
TASK(USB_Audio_Task) void USB_Audio_Task(void)
{ {
/* Check to see if the streaming interface is selected, if not the host is not receiving audio */
if (!(StreamingAudioInterfaceSelected))
return;
/* Select the audio stream endpoint */ /* Select the audio stream endpoint */
Endpoint_SelectEndpoint(AUDIO_STREAM_EPNUM); Endpoint_SelectEndpoint(AUDIO_STREAM_EPNUM);

@ -43,10 +43,9 @@
#include "Descriptors.h" #include "Descriptors.h"
#include <LUFA/Version.h> // Library Version Information #include <LUFA/Version.h>
#include <LUFA/Drivers/USB/USB.h> // USB Functionality #include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver #include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
/* Macros: */ /* Macros: */
#if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER)
@ -96,24 +95,25 @@
#define CSx0 CS10 #define CSx0 CS10
#endif #endif
/* Enums: */ /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
/** Enum for the possible status codes for passing to the UpdateStatus() function. */ #define LEDMASK_USB_NOTREADY LEDS_LED1
enum AudioOutput_StatusCodes_t
{
Status_USBNotReady = 0, /**< USB is not ready (disconnected from a USB host) */
Status_USBEnumerating = 1, /**< USB interface is enumerating */
Status_USBReady = 2, /**< USB interface is connected and ready */
};
/* Task Definitions: */ /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
TASK(USB_Audio_Task); #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
#define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
/* Function Prototypes: */ /* Function Prototypes: */
void SetupHardware(void);
void USB_Audio_Task(void);
void EVENT_USB_Connect(void); void EVENT_USB_Connect(void);
void EVENT_USB_Disconnect(void); void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void); void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void); void EVENT_USB_UnhandledControlPacket(void);
void UpdateStatus(uint8_t CurrentStatus);
#endif #endif

@ -119,13 +119,12 @@ OBJDIR = .
# Path to the LUFA library # Path to the LUFA library
LUFA_PATH = ../../.. LUFA_PATH = ../../../..
# List C source files here. (C dependencies are automatically generated.) # List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c \ SRC = $(TARGET).c \
Descriptors.c \ Descriptors.c \
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \
@ -136,7 +135,6 @@ SRC = $(TARGET).c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \
$(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c \
# List C++ source files here. (C dependencies are automatically generated.) # List C++ source files here. (C dependencies are automatically generated.)

@ -36,13 +36,6 @@
#include "CDC.h" #include "CDC.h"
/* Scheduler Task List */
TASK_LIST
{
{ .Task = USB_USBTask , .TaskStatus = TASK_STOP },
{ .Task = CDC_Task , .TaskStatus = TASK_STOP },
};
/* Globals: */ /* Globals: */
/** Contains the current baud rate and other settings of the virtual serial port. While this demo does not use /** Contains the current baud rate and other settings of the 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 * the physical USART and thus does not use these settings, they must still be retained and returned to the host
@ -57,25 +50,24 @@ CDC_Line_Coding_t LineCoding = { .BaudRateBPS = 9600,
.ParityType = Parity_None, .ParityType = Parity_None,
.DataBits = 8 }; .DataBits = 8 };
/** String to print through the virtual serial port when the joystick is pressed upwards. */ /** Main program entry point. This routine contains the overall program flow, including initial
char JoystickUpString[] = "Joystick Up\r\n"; * setup of all components and the main program loop.
*/
/** String to print through the virtual serial port when the joystick is pressed downward. */ int main(void)
char JoystickDownString[] = "Joystick Down\r\n"; {
SetupHardware();
/** String to print through the virtual serial port when the joystick is pressed left. */
char JoystickLeftString[] = "Joystick Left\r\n";
/** String to print through the virtual serial port when the joystick is pressed right. */ LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
char JoystickRightString[] = "Joystick Right\r\n";
/** String to print through the virtual serial port when the joystick is pressed inwards. */ for (;;)
char JoystickPressedString[] = "Joystick Pressed\r\n"; {
CDC_Task();
USB_USBTask();
}
}
/** Main program entry point. This routine configures the hardware required by the application, then /** Configures the board hardware and chip peripherals for the demo's functionality. */
* starts the scheduler to run the application tasks. void SetupHardware(void)
*/
int main(void)
{ {
/* Disable watchdog if enabled by bootloader/fuses */ /* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF); MCUSR &= ~(1 << WDRF);
@ -87,18 +79,7 @@ int main(void)
/* Hardware Initialization */ /* Hardware Initialization */
Joystick_Init(); Joystick_Init();
LEDs_Init(); LEDs_Init();
/* Indicate USB not ready */
UpdateStatus(Status_USBNotReady);
/* Initialize Scheduler so that it can be used */
Scheduler_Init();
/* Initialize USB Subsystem */
USB_Init(); USB_Init();
/* Scheduling - routine never returns, so put this last in the main function */
Scheduler_Start();
} }
/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and
@ -106,11 +87,8 @@ int main(void)
*/ */
void EVENT_USB_Connect(void) void EVENT_USB_Connect(void)
{ {
/* Start USB management task */
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
/* Indicate USB enumerating */ /* Indicate USB enumerating */
UpdateStatus(Status_USBEnumerating); LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
} }
/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via /** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via
@ -118,12 +96,8 @@ void EVENT_USB_Connect(void)
*/ */
void EVENT_USB_Disconnect(void) void EVENT_USB_Disconnect(void)
{ {
/* Stop running CDC and USB management tasks */
Scheduler_SetTaskMode(CDC_Task, TASK_STOP);
Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);
/* Indicate USB not ready */ /* Indicate USB not ready */
UpdateStatus(Status_USBNotReady); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
} }
/** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration /** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration
@ -145,10 +119,7 @@ void EVENT_USB_ConfigurationChanged(void)
ENDPOINT_BANK_SINGLE); ENDPOINT_BANK_SINGLE);
/* Indicate USB connected and ready */ /* Indicate USB connected and ready */
UpdateStatus(Status_USBReady); LEDs_SetAllLEDs(LEDMASK_USB_READY);
/* Start CDC task */
Scheduler_SetTaskMode(CDC_Task, TASK_RUN);
} }
/** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific /** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific
@ -210,40 +181,22 @@ void EVENT_USB_UnhandledControlPacket(void)
} }
} }
/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to
* log to a serial port, or anything else that is suitable for status updates.
*
* \param CurrentStatus Current status of the system, from the CDC_StatusCodes_t enum
*/
void UpdateStatus(uint8_t CurrentStatus)
{
uint8_t LEDMask = LEDS_NO_LEDS;
/* Set the LED mask to the appropriate LED mask based on the given status code */
switch (CurrentStatus)
{
case Status_USBNotReady:
LEDMask = (LEDS_LED1);
break;
case Status_USBEnumerating:
LEDMask = (LEDS_LED1 | LEDS_LED2);
break;
case Status_USBReady:
LEDMask = (LEDS_LED2 | LEDS_LED4);
break;
}
/* Set the board LEDs to the new LED mask */
LEDs_SetAllLEDs(LEDMask);
}
/** Function to manage CDC data transmission and reception to and from the host. */ /** Function to manage CDC data transmission and reception to and from the host. */
TASK(CDC_Task) void CDC_Task(void)
{ {
char* ReportString = NULL; char* ReportString = NULL;
uint8_t JoyStatus_LCL = Joystick_GetStatus(); uint8_t JoyStatus_LCL = Joystick_GetStatus();
static bool ActionSent = false; static bool ActionSent = false;
char* JoystickStrings[] =
{
"Joystick Up\r\n",
"Joystick Down\r\n",
"Joystick Left\r\n",
"Joystick Right\r\n",
"Joystick Pressed\r\n",
};
#if 0 #if 0
/* NOTE: Here you can use the notification endpoint to send back line state changes to the host, for the special RS-232 /* NOTE: Here you can use the notification endpoint to send back line state changes to the host, for the special RS-232
handshake signal lines (and some error states), via the CONTROL_LINE_IN_* masks and the following code: handshake signal lines (and some error states), via the CONTROL_LINE_IN_* masks and the following code:
@ -269,15 +222,15 @@ TASK(CDC_Task)
/* Determine if a joystick action has occurred */ /* Determine if a joystick action has occurred */
if (JoyStatus_LCL & JOY_UP) if (JoyStatus_LCL & JOY_UP)
ReportString = JoystickUpString; ReportString = JoystickStrings[0];
else if (JoyStatus_LCL & JOY_DOWN) else if (JoyStatus_LCL & JOY_DOWN)
ReportString = JoystickDownString; ReportString = JoystickStrings[1];
else if (JoyStatus_LCL & JOY_LEFT) else if (JoyStatus_LCL & JOY_LEFT)
ReportString = JoystickLeftString; ReportString = JoystickStrings[2];
else if (JoyStatus_LCL & JOY_RIGHT) else if (JoyStatus_LCL & JOY_RIGHT)
ReportString = JoystickRightString; ReportString = JoystickStrings[3];
else if (JoyStatus_LCL & JOY_PRESS) else if (JoyStatus_LCL & JOY_PRESS)
ReportString = JoystickPressedString; ReportString = JoystickStrings[4];
/* Flag management - Only allow one string to be sent per action */ /* Flag management - Only allow one string to be sent per action */
if (ReportString == NULL) if (ReportString == NULL)

@ -44,11 +44,10 @@
#include "Descriptors.h" #include "Descriptors.h"
#include <LUFA/Version.h> // Library Version Information #include <LUFA/Version.h>
#include <LUFA/Drivers/USB/USB.h> // USB Functionality #include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Board/Joystick.h> // Joystick driver #include <LUFA/Drivers/Board/Joystick.h>
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver #include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
/* Macros: */ /* Macros: */
/** CDC Class specific request to get the current virtual serial port configuration settings. */ /** CDC Class specific request to get the current virtual serial port configuration settings. */
@ -111,6 +110,18 @@
*/ */
#define CONTROL_LINE_IN_OVERRUNERROR (1 << 6) #define CONTROL_LINE_IN_OVERRUNERROR (1 << 6)
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
#define LEDMASK_USB_NOTREADY LEDS_LED1
/** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
#define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
#define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
/* Type Defines: */ /* Type Defines: */
/** Type define for the virtual serial port line encoding settings, for storing the current USART configuration /** 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. * as set by the host via a class specific request.
@ -160,18 +171,10 @@
Parity_Space = 4, /**< Space parity bit mode on each frame */ Parity_Space = 4, /**< Space parity bit mode on each frame */
}; };
/** Enum for the possible status codes for passing to the UpdateStatus() function. */
enum CDC_StatusCodes_t
{
Status_USBNotReady = 0, /**< USB is not ready (disconnected from a USB host) */
Status_USBEnumerating = 1, /**< USB interface is enumerating */
Status_USBReady = 2, /**< USB interface is connected and ready */
};
/* Tasks: */
TASK(CDC_Task);
/* Function Prototypes: */ /* Function Prototypes: */
void SetupHardware(void);
void CDC_Task(void);
void EVENT_USB_Connect(void); void EVENT_USB_Connect(void);
void EVENT_USB_Disconnect(void); void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void); void EVENT_USB_ConfigurationChanged(void);

@ -119,13 +119,12 @@ OBJDIR = .
# Path to the LUFA library # Path to the LUFA library
LUFA_PATH = ../../.. LUFA_PATH = ../../../..
# List C source files here. (C dependencies are automatically generated.) # List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c \ SRC = $(TARGET).c \
Descriptors.c \ Descriptors.c \
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \
@ -136,7 +135,6 @@ SRC = $(TARGET).c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \
$(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c \
# List C++ source files here. (C dependencies are automatically generated.) # List C++ source files here. (C dependencies are automatically generated.)

@ -36,14 +36,6 @@
#include "DualCDC.h" #include "DualCDC.h"
/* Scheduler Task List */
TASK_LIST
{
{ .Task = USB_USBTask , .TaskStatus = TASK_STOP },
{ .Task = CDC1_Task , .TaskStatus = TASK_STOP },
{ .Task = CDC2_Task , .TaskStatus = TASK_STOP },
};
/* Globals: */ /* Globals: */
/** Contains the current baud rate and other settings of the first virtual serial port. While this demo does not use /** Contains the current baud rate and other settings of the first 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 * the physical USART and thus does not use these settings, they must still be retained and returned to the host
@ -71,25 +63,23 @@ CDC_Line_Coding_t LineCoding2 = { .BaudRateBPS = 9600,
.ParityType = Parity_None, .ParityType = Parity_None,
.DataBits = 8 }; .DataBits = 8 };
/** String to print through the first virtual serial port when the joystick is pressed upwards. */
char JoystickUpString[] = "Joystick Up\r\n";
/** String to print through the first virtual serial port when the joystick is pressed downward. */
char JoystickDownString[] = "Joystick Down\r\n";
/** String to print through the first virtual serial port when the joystick is pressed left. */
char JoystickLeftString[] = "Joystick Left\r\n";
/** String to print through the first virtual serial port when the joystick is pressed right. */
char JoystickRightString[] = "Joystick Right\r\n";
/** String to print through the first virtual serial port when the joystick is pressed inwards. */
char JoystickPressedString[] = "Joystick Pressed\r\n";
/** Main program entry point. This routine configures the hardware required by the application, then /** Main program entry point. This routine configures the hardware required by the application, then
* starts the scheduler to run the application tasks. * starts the scheduler to run the application tasks.
*/ */
int main(void) int main(void)
{
SetupHardware();
for (;;)
{
CDC1_Task();
CDC2_Task();
USB_USBTask();
}
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{ {
/* Disable watchdog if enabled by bootloader/fuses */ /* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF); MCUSR &= ~(1 << WDRF);
@ -101,18 +91,7 @@ int main(void)
/* Hardware Initialization */ /* Hardware Initialization */
Joystick_Init(); Joystick_Init();
LEDs_Init(); LEDs_Init();
/* Indicate USB not ready */
UpdateStatus(Status_USBNotReady);
/* Initialize Scheduler so that it can be used */
Scheduler_Init();
/* Initialize USB Subsystem */
USB_Init(); USB_Init();
/* Scheduling - routine never returns, so put this last in the main function */
Scheduler_Start();
} }
/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and
@ -120,11 +99,8 @@ int main(void)
*/ */
void EVENT_USB_Connect(void) void EVENT_USB_Connect(void)
{ {
/* Start USB management task */
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
/* Indicate USB enumerating */ /* Indicate USB enumerating */
UpdateStatus(Status_USBEnumerating); LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
} }
/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via /** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via
@ -132,13 +108,8 @@ void EVENT_USB_Connect(void)
*/ */
void EVENT_USB_Disconnect(void) void EVENT_USB_Disconnect(void)
{ {
/* Stop running CDC and USB management tasks */
Scheduler_SetTaskMode(CDC1_Task, TASK_STOP);
Scheduler_SetTaskMode(CDC2_Task, TASK_STOP);
Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);
/* Indicate USB not ready */ /* Indicate USB not ready */
UpdateStatus(Status_USBNotReady); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
} }
/** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration /** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration
@ -173,11 +144,7 @@ void EVENT_USB_ConfigurationChanged(void)
ENDPOINT_BANK_SINGLE); ENDPOINT_BANK_SINGLE);
/* Indicate USB connected and ready */ /* Indicate USB connected and ready */
UpdateStatus(Status_USBReady); LEDs_SetAllLEDs(LEDMASK_USB_READY);
/* Start CDC tasks */
Scheduler_SetTaskMode(CDC1_Task, TASK_RUN);
Scheduler_SetTaskMode(CDC2_Task, TASK_RUN);
} }
/** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific /** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific
@ -235,53 +202,35 @@ void EVENT_USB_UnhandledControlPacket(void)
} }
} }
/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to
* log to a serial port, or anything else that is suitable for status updates.
*
* \param CurrentStatus Current status of the system, from the DualCDC_StatusCodes_t enum
*/
void UpdateStatus(uint8_t CurrentStatus)
{
uint8_t LEDMask = LEDS_NO_LEDS;
/* Set the LED mask to the appropriate LED mask based on the given status code */
switch (CurrentStatus)
{
case Status_USBNotReady:
LEDMask = (LEDS_LED1);
break;
case Status_USBEnumerating:
LEDMask = (LEDS_LED1 | LEDS_LED2);
break;
case Status_USBReady:
LEDMask = (LEDS_LED2 | LEDS_LED4);
break;
}
/* Set the board LEDs to the new LED mask */
LEDs_SetAllLEDs(LEDMask);
}
/** Function to manage CDC data transmission and reception to and from the host for the first CDC interface, which sends joystick /** Function to manage CDC data transmission and reception to and from the host for the first CDC interface, which sends joystick
* movements to the host as ASCII strings. * movements to the host as ASCII strings.
*/ */
TASK(CDC1_Task) void CDC1_Task(void)
{ {
char* ReportString = NULL; char* ReportString = NULL;
uint8_t JoyStatus_LCL = Joystick_GetStatus(); uint8_t JoyStatus_LCL = Joystick_GetStatus();
static bool ActionSent = false; static bool ActionSent = false;
char* JoystickStrings[] =
{
"Joystick Up\r\n",
"Joystick Down\r\n",
"Joystick Left\r\n",
"Joystick Right\r\n",
"Joystick Pressed\r\n",
};
/* Determine if a joystick action has occurred */ /* Determine if a joystick action has occurred */
if (JoyStatus_LCL & JOY_UP) if (JoyStatus_LCL & JOY_UP)
ReportString = JoystickUpString; ReportString = JoystickStrings[0];
else if (JoyStatus_LCL & JOY_DOWN) else if (JoyStatus_LCL & JOY_DOWN)
ReportString = JoystickDownString; ReportString = JoystickStrings[1];
else if (JoyStatus_LCL & JOY_LEFT) else if (JoyStatus_LCL & JOY_LEFT)
ReportString = JoystickLeftString; ReportString = JoystickStrings[2];
else if (JoyStatus_LCL & JOY_RIGHT) else if (JoyStatus_LCL & JOY_RIGHT)
ReportString = JoystickRightString; ReportString = JoystickStrings[3];
else if (JoyStatus_LCL & JOY_PRESS) else if (JoyStatus_LCL & JOY_PRESS)
ReportString = JoystickPressedString; ReportString = JoystickStrings[4];
/* Flag management - Only allow one string to be sent per action */ /* Flag management - Only allow one string to be sent per action */
if (ReportString == NULL) if (ReportString == NULL)
@ -319,7 +268,7 @@ TASK(CDC1_Task)
/** Function to manage CDC data transmission and reception to and from the host for the second CDC interface, which echoes back /** Function to manage CDC data transmission and reception to and from the host for the second CDC interface, which echoes back
* all data sent to it from the host. * all data sent to it from the host.
*/ */
TASK(CDC2_Task) void CDC2_Task(void)
{ {
/* Select the Serial Rx Endpoint */ /* Select the Serial Rx Endpoint */
Endpoint_SelectEndpoint(CDC2_RX_EPNUM); Endpoint_SelectEndpoint(CDC2_RX_EPNUM);

@ -44,11 +44,10 @@
#include "Descriptors.h" #include "Descriptors.h"
#include <LUFA/Version.h> // Library Version Information #include <LUFA/Version.h>
#include <LUFA/Drivers/USB/USB.h> // USB Functionality #include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Board/Joystick.h> // Joystick driver #include <LUFA/Drivers/Board/Joystick.h>
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver #include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
/* Macros: */ /* Macros: */
/** CDC Class specific request to get the current virtual serial port configuration settings. */ /** CDC Class specific request to get the current virtual serial port configuration settings. */
@ -60,6 +59,18 @@
/** CDC Class specific request to set the current virtual serial port handshake line states. */ /** CDC Class specific request to set the current virtual serial port handshake line states. */
#define REQ_SetControlLineState 0x22 #define REQ_SetControlLineState 0x22
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
#define LEDMASK_USB_NOTREADY LEDS_LED1
/** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
#define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
#define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
/* Type Defines: */ /* Type Defines: */
/** Type define for the virtual serial port line encoding settings, for storing the current USART configuration /** 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. * as set by the host via a class specific request.
@ -95,24 +106,14 @@
Parity_Space = 4, /**< Space parity bit mode on each frame */ Parity_Space = 4, /**< Space parity bit mode on each frame */
}; };
/** Enum for the possible status codes for passing to the UpdateStatus() function. */
enum DualCDC_StatusCodes_t
{
Status_USBNotReady = 0, /**< USB is not ready (disconnected from a USB host) */
Status_USBEnumerating = 1, /**< USB interface is enumerating */
Status_USBReady = 2, /**< USB interface is connected and ready */
};
/* Tasks: */
TASK(CDC1_Task);
TASK(CDC2_Task);
/* Function Prototypes: */ /* Function Prototypes: */
void CDC1_Task(void);
void CDC2_Task(void);
void SetupHardware(void);
void EVENT_USB_Connect(void); void EVENT_USB_Connect(void);
void EVENT_USB_Disconnect(void); void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void); void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void); void EVENT_USB_UnhandledControlPacket(void);
void UpdateStatus(uint8_t CurrentStatus);
#endif #endif

@ -119,13 +119,12 @@ OBJDIR = .
# Path to the LUFA library # Path to the LUFA library
LUFA_PATH = ../../.. LUFA_PATH = ../../../..
# List C source files here. (C dependencies are automatically generated.) # List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c \ SRC = $(TARGET).c \
Descriptors.c \ Descriptors.c \
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \
@ -136,7 +135,6 @@ SRC = $(TARGET).c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \
$(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c \
# List C++ source files here. (C dependencies are automatically generated.) # List C++ source files here. (C dependencies are automatically generated.)

@ -36,13 +36,6 @@
#include "GenericHID.h" #include "GenericHID.h"
/* Scheduler Task List */
TASK_LIST
{
{ .Task = USB_USBTask , .TaskStatus = TASK_STOP },
{ .Task = USB_HID_Report , .TaskStatus = TASK_STOP },
};
/** Static buffer to hold the last received report from the host, so that it can be echoed back in the next sent report */ /** Static buffer to hold the last received report from the host, so that it can be echoed back in the next sent report */
static uint8_t LastReceived[GENERIC_REPORT_SIZE]; static uint8_t LastReceived[GENERIC_REPORT_SIZE];
@ -51,6 +44,20 @@ static uint8_t LastReceived[GENERIC_REPORT_SIZE];
* starts the scheduler to run the USB management task. * starts the scheduler to run the USB management task.
*/ */
int main(void) int main(void)
{
SetupHardware();
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
for (;;)
{
HID_Task();
USB_USBTask();
}
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{ {
/* Disable watchdog if enabled by bootloader/fuses */ /* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF); MCUSR &= ~(1 << WDRF);
@ -61,18 +68,7 @@ int main(void)
/* Hardware Initialization */ /* Hardware Initialization */
LEDs_Init(); LEDs_Init();
/* Indicate USB not ready */
UpdateStatus(Status_USBNotReady);
/* Initialize Scheduler so that it can be used */
Scheduler_Init();
/* Initialize USB Subsystem */
USB_Init(); USB_Init();
/* Scheduling - routine never returns, so put this last in the main function */
Scheduler_Start();
} }
/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and
@ -80,11 +76,8 @@ int main(void)
*/ */
void EVENT_USB_Connect(void) void EVENT_USB_Connect(void)
{ {
/* Start USB management task */
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
/* Indicate USB enumerating */ /* Indicate USB enumerating */
UpdateStatus(Status_USBEnumerating); LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
} }
/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via /** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via
@ -92,12 +85,8 @@ void EVENT_USB_Connect(void)
*/ */
void EVENT_USB_Disconnect(void) void EVENT_USB_Disconnect(void)
{ {
/* Stop running HID reporting and USB management tasks */
Scheduler_SetTaskMode(USB_HID_Report, TASK_STOP);
Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);
/* Indicate USB not ready */ /* Indicate USB not ready */
UpdateStatus(Status_USBNotReady); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
} }
/** Event handler for the USB_ConfigurationChanged event. This is fired when the host sets the current configuration /** Event handler for the USB_ConfigurationChanged event. This is fired when the host sets the current configuration
@ -116,7 +105,7 @@ void EVENT_USB_ConfigurationChanged(void)
ENDPOINT_BANK_SINGLE); ENDPOINT_BANK_SINGLE);
/* Indicate USB connected and ready */ /* Indicate USB connected and ready */
UpdateStatus(Status_USBReady); LEDs_SetAllLEDs(LEDMASK_USB_READY);
} }
/** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific /** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific
@ -173,33 +162,6 @@ void EVENT_USB_UnhandledControlPacket(void)
} }
} }
/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to
* log to a serial port, or anything else that is suitable for status updates.
*
* \param CurrentStatus Current status of the system, from the GenericHID_StatusCodes_t enum
*/
void UpdateStatus(uint8_t CurrentStatus)
{
uint8_t LEDMask = LEDS_NO_LEDS;
/* Set the LED mask to the appropriate LED mask based on the given status code */
switch (CurrentStatus)
{
case Status_USBNotReady:
LEDMask = (LEDS_LED1);
break;
case Status_USBEnumerating:
LEDMask = (LEDS_LED1 | LEDS_LED2);
break;
case Status_USBReady:
LEDMask = (LEDS_LED2 | LEDS_LED4);
break;
}
/* Set the board LEDs to the new LED mask */
LEDs_SetAllLEDs(LEDMask);
}
/** Function to process the lest received report from the host. /** Function to process the lest received report from the host.
* *
* \param DataArray Pointer to a buffer where the last report data is stored * \param DataArray Pointer to a buffer where the last report data is stored
@ -232,7 +194,7 @@ void CreateGenericHIDReport(uint8_t* DataArray)
DataArray[i] = LastReceived[i]; DataArray[i] = LastReceived[i];
} }
TASK(USB_HID_Report) void HID_Task(void)
{ {
/* Check if the USB system is connected to a host */ /* Check if the USB system is connected to a host */
if (USB_IsConnected) if (USB_IsConnected)

@ -46,10 +46,9 @@
#include "Descriptors.h" #include "Descriptors.h"
#include <LUFA/Version.h> // Library Version Information #include <LUFA/Version.h>
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management #include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/USB/USB.h> // USB Functionality #include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver
/* Macros: */ /* Macros: */
/** HID Class specific request to get the next HID report from the device. */ /** HID Class specific request to get the next HID report from the device. */
@ -58,6 +57,18 @@
/** HID Class specific request to send the next HID report to the device. */ /** HID Class specific request to send the next HID report to the device. */
#define REQ_SetReport 0x09 #define REQ_SetReport 0x09
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
#define LEDMASK_USB_NOTREADY LEDS_LED1
/** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
#define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
#define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
/* Enums: */ /* Enums: */
/** Enum for the possible status codes for passing to the UpdateStatus() function. */ /** Enum for the possible status codes for passing to the UpdateStatus() function. */
enum GenericHID_StatusCodes_t enum GenericHID_StatusCodes_t
@ -67,16 +78,15 @@
Status_USBReady = 2, /**< USB interface is connected and ready */ Status_USBReady = 2, /**< USB interface is connected and ready */
}; };
/* Task Definitions: */
TASK(USB_HID_Report);
/* Function Prototypes: */ /* Function Prototypes: */
void SetupHardware(void);
void HID_Task(void);
void EVENT_USB_Connect(void); void EVENT_USB_Connect(void);
void EVENT_USB_Disconnect(void); void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void); void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void); void EVENT_USB_UnhandledControlPacket(void);
void UpdateStatus(uint8_t CurrentStatus);
void ProcessGenericHIDReport(uint8_t* DataArray); void ProcessGenericHIDReport(uint8_t* DataArray);
void CreateGenericHIDReport(uint8_t* DataArray); void CreateGenericHIDReport(uint8_t* DataArray);

@ -119,13 +119,12 @@ OBJDIR = .
# Path to the LUFA library # Path to the LUFA library
LUFA_PATH = ../../.. LUFA_PATH = ../../../..
# List C source files here. (C dependencies are automatically generated.) # List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c \ SRC = $(TARGET).c \
Descriptors.c \ Descriptors.c \
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \
@ -136,7 +135,6 @@ SRC = $(TARGET).c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \
$(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c \
# List C++ source files here. (C dependencies are automatically generated.) # List C++ source files here. (C dependencies are automatically generated.)

@ -36,17 +36,24 @@
#include "Joystick.h" #include "Joystick.h"
/* Scheduler Task List */
TASK_LIST
{
{ .Task = USB_USBTask , .TaskStatus = TASK_STOP },
{ .Task = USB_Joystick_Report , .TaskStatus = TASK_STOP },
};
/** Main program entry point. This routine configures the hardware required by the application, then /** Main program entry point. This routine configures the hardware required by the application, then
* starts the scheduler to run the application tasks. * starts the scheduler to run the application tasks.
*/ */
int main(void) int main(void)
{
SetupHardware();
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
for (;;)
{
HID_Task();
USB_USBTask();
}
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{ {
/* Disable watchdog if enabled by bootloader/fuses */ /* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF); MCUSR &= ~(1 << WDRF);
@ -59,18 +66,7 @@ int main(void)
Joystick_Init(); Joystick_Init();
LEDs_Init(); LEDs_Init();
Buttons_Init(); Buttons_Init();
/* Indicate USB not ready */
UpdateStatus(Status_USBNotReady);
/* Initialize Scheduler so that it can be used */
Scheduler_Init();
/* Initialize USB Subsystem */
USB_Init(); USB_Init();
/* Scheduling - routine never returns, so put this last in the main function */
Scheduler_Start();
} }
/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and
@ -78,11 +74,8 @@ int main(void)
*/ */
void EVENT_USB_Connect(void) void EVENT_USB_Connect(void)
{ {
/* Start USB management task */
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
/* Indicate USB enumerating */ /* Indicate USB enumerating */
UpdateStatus(Status_USBEnumerating); LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
} }
/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via /** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via
@ -90,12 +83,8 @@ void EVENT_USB_Connect(void)
*/ */
void EVENT_USB_Disconnect(void) void EVENT_USB_Disconnect(void)
{ {
/* Stop running joystick reporting and USB management tasks */
Scheduler_SetTaskMode(USB_Joystick_Report, TASK_STOP);
Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);
/* Indicate USB not ready */ /* Indicate USB not ready */
UpdateStatus(Status_USBNotReady); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
} }
/** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration /** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration
@ -109,10 +98,7 @@ void EVENT_USB_ConfigurationChanged(void)
ENDPOINT_BANK_SINGLE); ENDPOINT_BANK_SINGLE);
/* Indicate USB connected and ready */ /* Indicate USB connected and ready */
UpdateStatus(Status_USBReady); LEDs_SetAllLEDs(LEDMASK_USB_READY);
/* Start joystick reporting task */
Scheduler_SetTaskMode(USB_Joystick_Report, TASK_RUN);
} }
/** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific /** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific
@ -189,35 +175,8 @@ bool GetNextReport(USB_JoystickReport_Data_t* ReportData)
return InputChanged; return InputChanged;
} }
/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to
* log to a serial port, or anything else that is suitable for status updates.
*
* \param CurrentStatus Current status of the system, from the Joystick_StatusCodes_t enum
*/
void UpdateStatus(uint8_t CurrentStatus)
{
uint8_t LEDMask = LEDS_NO_LEDS;
/* Set the LED mask to the appropriate LED mask based on the given status code */
switch (CurrentStatus)
{
case Status_USBNotReady:
LEDMask = (LEDS_LED1);
break;
case Status_USBEnumerating:
LEDMask = (LEDS_LED1 | LEDS_LED2);
break;
case Status_USBReady:
LEDMask = (LEDS_LED2 | LEDS_LED4);
break;
}
/* Set the board LEDs to the new LED mask */
LEDs_SetAllLEDs(LEDMask);
}
/** Function to manage HID report generation and transmission to the host. */ /** Function to manage HID report generation and transmission to the host. */
TASK(USB_Joystick_Report) void HID_Task(void)
{ {
/* Check if the USB System is connected to a Host */ /* Check if the USB System is connected to a Host */
if (USB_IsConnected) if (USB_IsConnected)

@ -44,20 +44,28 @@
#include "Descriptors.h" #include "Descriptors.h"
#include <LUFA/Version.h> // Library Version Information #include <LUFA/Version.h>
#include <LUFA/Drivers/USB/USB.h> // USB Functionality #include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Board/Joystick.h> // Joystick driver #include <LUFA/Drivers/Board/Joystick.h>
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver #include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Drivers/Board/Buttons.h> // Board Buttons driver #include <LUFA/Drivers/Board/Buttons.h>
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
/* Task Definitions: */
TASK(USB_Joystick_Report);
/* Macros: */ /* Macros: */
/** HID Class specific request to get the next HID report from the device. */ /** HID Class specific request to get the next HID report from the device. */
#define REQ_GetReport 0x01 #define REQ_GetReport 0x01
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
#define LEDMASK_USB_NOTREADY LEDS_LED1
/** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
#define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
#define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
/* Type Defines: */ /* Type Defines: */
/** Type define for the joystick HID report structure, for creating and sending HID reports to the host PC. /** Type define for the joystick HID report structure, for creating and sending HID reports to the host PC.
* This mirrors the layout described to the host in the HID report descriptor, in Descriptors.c. * This mirrors the layout described to the host in the HID report descriptor, in Descriptors.c.
@ -69,22 +77,15 @@
uint8_t Button; /**< Bit mask of the currently pressed joystick buttons */ uint8_t Button; /**< Bit mask of the currently pressed joystick buttons */
} USB_JoystickReport_Data_t; } USB_JoystickReport_Data_t;
/* Enums: */
/** Enum for the possible status codes for passing to the UpdateStatus() function. */
enum Joystick_StatusCodes_t
{
Status_USBNotReady = 0, /**< USB is not ready (disconnected from a USB host) */
Status_USBEnumerating = 1, /**< USB interface is enumerating */
Status_USBReady = 2, /**< USB interface is connected and ready */
};
/* Function Prototypes: */ /* Function Prototypes: */
void SetupHardware(void);
void HID_Task(void);
void EVENT_USB_Connect(void); void EVENT_USB_Connect(void);
void EVENT_USB_Disconnect(void); void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void); void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void); void EVENT_USB_UnhandledControlPacket(void);
bool GetNextReport(USB_JoystickReport_Data_t* ReportData); bool GetNextReport(USB_JoystickReport_Data_t* ReportData);
void UpdateStatus(uint8_t CurrentStatus);
#endif #endif

@ -119,13 +119,12 @@ OBJDIR = .
# Path to the LUFA library # Path to the LUFA library
LUFA_PATH = ../../.. LUFA_PATH = ../../../..
# List C source files here. (C dependencies are automatically generated.) # List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c \ SRC = $(TARGET).c \
Descriptors.c \ Descriptors.c \
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \
@ -136,7 +135,6 @@ SRC = $(TARGET).c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \
$(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c \
# List C++ source files here. (C dependencies are automatically generated.) # List C++ source files here. (C dependencies are automatically generated.)

@ -37,13 +37,6 @@
#include "Keyboard.h" #include "Keyboard.h"
/* Scheduler Task List */
TASK_LIST
{
{ .Task = USB_USBTask , .TaskStatus = TASK_STOP },
{ .Task = USB_Keyboard_Report , .TaskStatus = TASK_STOP },
};
/* Global Variables */ /* Global Variables */
/** Indicates what report mode the host has requested, true for normal HID reporting mode, false for special boot /** Indicates what report mode the host has requested, true for normal HID reporting mode, false for special boot
* protocol reporting mode. * protocol reporting mode.
@ -66,6 +59,20 @@ uint16_t IdleMSRemaining = 0;
* starts the scheduler to run the USB management task. * starts the scheduler to run the USB management task.
*/ */
int main(void) int main(void)
{
SetupHardware();
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
for (;;)
{
HID_Task();
USB_USBTask();
}
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{ {
/* Disable watchdog if enabled by bootloader/fuses */ /* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF); MCUSR &= ~(1 << WDRF);
@ -77,24 +84,13 @@ int main(void)
/* Hardware Initialization */ /* Hardware Initialization */
Joystick_Init(); Joystick_Init();
LEDs_Init(); LEDs_Init();
USB_Init();
/* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */ /* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */
OCR0A = 0x7D; OCR0A = 0x7D;
TCCR0A = (1 << WGM01); TCCR0A = (1 << WGM01);
TCCR0B = ((1 << CS01) | (1 << CS00)); TCCR0B = ((1 << CS01) | (1 << CS00));
TIMSK0 = (1 << OCIE0A); TIMSK0 = (1 << OCIE0A);
/* Indicate USB not ready */
UpdateStatus(Status_USBNotReady);
/* Initialize Scheduler so that it can be used */
Scheduler_Init();
/* Initialize USB Subsystem */
USB_Init();
/* Scheduling - routine never returns, so put this last in the main function */
Scheduler_Start();
} }
/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and
@ -102,11 +98,8 @@ int main(void)
*/ */
void EVENT_USB_Connect(void) void EVENT_USB_Connect(void)
{ {
/* Start USB management task */
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
/* Indicate USB enumerating */ /* Indicate USB enumerating */
UpdateStatus(Status_USBEnumerating); LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
/* Default to report protocol on connect */ /* Default to report protocol on connect */
UsingReportProtocol = true; UsingReportProtocol = true;
@ -117,12 +110,8 @@ void EVENT_USB_Connect(void)
*/ */
void EVENT_USB_Disconnect(void) void EVENT_USB_Disconnect(void)
{ {
/* Stop running keyboard reporting and USB management tasks */
Scheduler_SetTaskMode(USB_Keyboard_Report, TASK_STOP);
Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);
/* Indicate USB not ready */ /* Indicate USB not ready */
UpdateStatus(Status_USBNotReady); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
} }
/** Event handler for the USB_ConfigurationChanged event. This is fired when the host sets the current configuration /** Event handler for the USB_ConfigurationChanged event. This is fired when the host sets the current configuration
@ -141,10 +130,7 @@ void EVENT_USB_ConfigurationChanged(void)
ENDPOINT_BANK_SINGLE); ENDPOINT_BANK_SINGLE);
/* Indicate USB connected and ready */ /* Indicate USB connected and ready */
UpdateStatus(Status_USBReady); LEDs_SetAllLEDs(LEDMASK_USB_READY);
/* Start running keyboard reporting task */
Scheduler_SetTaskMode(USB_Keyboard_Report, TASK_RUN);
} }
/** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific /** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific
@ -382,35 +368,8 @@ void ReceiveNextReport(void)
} }
} }
/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to
* log to a serial port, or anything else that is suitable for status updates.
*
* \param CurrentStatus Current status of the system, from the Keyboard_StatusCodes_t enum
*/
void UpdateStatus(uint8_t CurrentStatus)
{
uint8_t LEDMask = LEDS_NO_LEDS;
/* Set the LED mask to the appropriate LED mask based on the given status code */
switch (CurrentStatus)
{
case Status_USBNotReady:
LEDMask = (LEDS_LED1);
break;
case Status_USBEnumerating:
LEDMask = (LEDS_LED1 | LEDS_LED2);
break;
case Status_USBReady:
LEDMask = (LEDS_LED2 | LEDS_LED4);
break;
}
/* Set the board LEDs to the new LED mask */
LEDs_SetAllLEDs(LEDMask);
}
/** Function to manage HID report generation and transmission to the host, when in report mode. */ /** Function to manage HID report generation and transmission to the host, when in report mode. */
TASK(USB_Keyboard_Report) void HID_Task(void)
{ {
/* Check if the USB system is connected to a host */ /* Check if the USB system is connected to a host */
if (USB_IsConnected) if (USB_IsConnected)

@ -47,11 +47,10 @@
#include "Descriptors.h" #include "Descriptors.h"
#include <LUFA/Version.h> // Library Version Information #include <LUFA/Version.h>
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management #include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/USB/USB.h> // USB Functionality #include <LUFA/Drivers/Board/Joystick.h>
#include <LUFA/Drivers/Board/Joystick.h> // Joystick driver #include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver
/* Macros: */ /* Macros: */
/** Idle period indicating that reports should be sent only when the inputs have changed */ /** Idle period indicating that reports should be sent only when the inputs have changed */
@ -75,8 +74,17 @@
/** HID Class specific request to set the current HID protocol in use, either report or boot. */ /** HID Class specific request to set the current HID protocol in use, either report or boot. */
#define REQ_SetProtocol 0x0B #define REQ_SetProtocol 0x0B
/* Task Definitions: */ /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
TASK(USB_Keyboard_Report); #define LEDMASK_USB_NOTREADY LEDS_LED1
/** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
#define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
#define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
/* Type Defines: */ /* Type Defines: */
/** Type define for the keyboard HID report structure, for creating and sending HID reports to the host PC. /** Type define for the keyboard HID report structure, for creating and sending HID reports to the host PC.
@ -89,16 +97,10 @@
uint8_t KeyCode[6]; /**< Array of up to six simultaneous key codes of pressed keys */ uint8_t KeyCode[6]; /**< Array of up to six simultaneous key codes of pressed keys */
} USB_KeyboardReport_Data_t; } USB_KeyboardReport_Data_t;
/* Enums: */
/** Enum for the possible status codes for passing to the UpdateStatus() function. */
enum Keyboard_StatusCodes_t
{
Status_USBNotReady = 0, /**< USB is not ready (disconnected from a USB host) */
Status_USBEnumerating = 1, /**< USB interface is enumerating */
Status_USBReady = 2, /**< USB interface is connected and ready */
};
/* Function Prototypes: */ /* Function Prototypes: */
void SetupHardware(void);
void HID_Task(void);
void EVENT_USB_Connect(void); void EVENT_USB_Connect(void);
void EVENT_USB_Disconnect(void); void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void); void EVENT_USB_ConfigurationChanged(void);
@ -108,6 +110,5 @@
void ProcessLEDReport(uint8_t LEDReport); void ProcessLEDReport(uint8_t LEDReport);
void SendNextReport(void); void SendNextReport(void);
void ReceiveNextReport(void); void ReceiveNextReport(void);
void UpdateStatus(uint8_t CurrentStatus);
#endif #endif

@ -119,13 +119,12 @@ OBJDIR = .
# Path to the LUFA library # Path to the LUFA library
LUFA_PATH = ../../.. LUFA_PATH = ../../../..
# List C source files here. (C dependencies are automatically generated.) # List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c \ SRC = $(TARGET).c \
Descriptors.c \ Descriptors.c \
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \
@ -136,7 +135,6 @@ SRC = $(TARGET).c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \
$(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c \
# List C++ source files here. (C dependencies are automatically generated.) # List C++ source files here. (C dependencies are automatically generated.)

@ -37,14 +37,6 @@
#include "KeyboardMouse.h" #include "KeyboardMouse.h"
/* Scheduler Task List */
TASK_LIST
{
{ .Task = USB_USBTask , .TaskStatus = TASK_STOP },
{ .Task = USB_Mouse , .TaskStatus = TASK_RUN },
{ .Task = USB_Keyboard , .TaskStatus = TASK_RUN },
};
/* Global Variables */ /* Global Variables */
/** Global structure to hold the current keyboard interface HID report, for transmission to the host */ /** Global structure to hold the current keyboard interface HID report, for transmission to the host */
USB_KeyboardReport_Data_t KeyboardReportData; USB_KeyboardReport_Data_t KeyboardReportData;
@ -56,6 +48,21 @@ USB_MouseReport_Data_t MouseReportData;
* starts the scheduler to run the USB management task. * starts the scheduler to run the USB management task.
*/ */
int main(void) int main(void)
{
SetupHardware();
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
for (;;)
{
Keyboard_HID_Task();
Mouse_HID_Task();
USB_USBTask();
}
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{ {
/* Disable watchdog if enabled by bootloader/fuses */ /* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF); MCUSR &= ~(1 << WDRF);
@ -67,18 +74,7 @@ int main(void)
/* Hardware Initialization */ /* Hardware Initialization */
Joystick_Init(); Joystick_Init();
LEDs_Init(); LEDs_Init();
/* Indicate USB not ready */
UpdateStatus(Status_USBNotReady);
/* Initialize Scheduler so that it can be used */
Scheduler_Init();
/* Initialize USB Subsystem */
USB_Init(); USB_Init();
/* Scheduling - routine never returns, so put this last in the main function */
Scheduler_Start();
} }
/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and
@ -86,11 +82,8 @@ int main(void)
*/ */
void EVENT_USB_Connect(void) void EVENT_USB_Connect(void)
{ {
/* Start USB management task */
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
/* Indicate USB enumerating */ /* Indicate USB enumerating */
UpdateStatus(Status_USBEnumerating); LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
} }
/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via /** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via
@ -98,11 +91,8 @@ void EVENT_USB_Connect(void)
*/ */
void EVENT_USB_Disconnect(void) void EVENT_USB_Disconnect(void)
{ {
/* Stop running HID reporting and USB management tasks */
Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);
/* Indicate USB not ready */ /* Indicate USB not ready */
UpdateStatus(Status_USBNotReady); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
} }
/** Event handler for the USB_ConfigurationChanged event. This is fired when the host sets the current configuration /** Event handler for the USB_ConfigurationChanged event. This is fired when the host sets the current configuration
@ -126,7 +116,7 @@ void EVENT_USB_ConfigurationChanged(void)
ENDPOINT_BANK_SINGLE); ENDPOINT_BANK_SINGLE);
/* Indicate USB connected and ready */ /* Indicate USB connected and ready */
UpdateStatus(Status_USBReady); LEDs_SetAllLEDs(LEDMASK_USB_READY);
} }
/** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific /** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific
@ -205,38 +195,11 @@ void EVENT_USB_UnhandledControlPacket(void)
} }
} }
/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to
* log to a serial port, or anything else that is suitable for status updates.
*
* \param CurrentStatus Current status of the system, from the KeyboardMouse_StatusCodes_t enum
*/
void UpdateStatus(uint8_t CurrentStatus)
{
uint8_t LEDMask = LEDS_NO_LEDS;
/* Set the LED mask to the appropriate LED mask based on the given status code */
switch (CurrentStatus)
{
case Status_USBNotReady:
LEDMask = (LEDS_LED1);
break;
case Status_USBEnumerating:
LEDMask = (LEDS_LED1 | LEDS_LED2);
break;
case Status_USBReady:
LEDMask = (LEDS_LED2 | LEDS_LED4);
break;
}
/* Set the board LEDs to the new LED mask */
LEDs_SetAllLEDs(LEDMask);
}
/** Keyboard task. This generates the next keyboard HID report for the host, and transmits it via the /** Keyboard task. This generates the next keyboard HID report for the host, and transmits it via the
* keyboard IN endpoint when the host is ready for more data. Additionally, it processes host LED status * keyboard IN endpoint when the host is ready for more data. Additionally, it processes host LED status
* reports sent to the device via the keyboard OUT reporting endpoint. * reports sent to the device via the keyboard OUT reporting endpoint.
*/ */
TASK(USB_Keyboard) void Keyboard_HID_Task(void)
{ {
uint8_t JoyStatus_LCL = Joystick_GetStatus(); uint8_t JoyStatus_LCL = Joystick_GetStatus();
@ -307,7 +270,7 @@ TASK(USB_Keyboard)
/** Mouse task. This generates the next mouse HID report for the host, and transmits it via the /** Mouse task. This generates the next mouse HID report for the host, and transmits it via the
* mouse IN endpoint when the host is ready for more data. * mouse IN endpoint when the host is ready for more data.
*/ */
TASK(USB_Mouse) void Mouse_HID_Task(void)
{ {
uint8_t JoyStatus_LCL = Joystick_GetStatus(); uint8_t JoyStatus_LCL = Joystick_GetStatus();

@ -41,25 +41,11 @@
#include "Descriptors.h" #include "Descriptors.h"
#include <LUFA/Version.h> // Library Version Information #include <LUFA/Version.h>
#include <LUFA/Drivers/USB/USB.h> // USB Functionality #include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Board/Joystick.h> // Joystick driver #include <LUFA/Drivers/Board/Joystick.h>
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver #include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Drivers/Board/Buttons.h> // Board Buttons driver #include <LUFA/Drivers/Board/Buttons.h>
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
/* Task Definitions: */
TASK(USB_Keyboard);
TASK(USB_Mouse);
/* Enums: */
/** Enum for the possible status codes for passing to the UpdateStatus() function. */
enum KeyboardMouse_StatusCodes_t
{
Status_USBNotReady = 0, /**< USB is not ready (disconnected from a USB host) */
Status_USBEnumerating = 1, /**< USB interface is enumerating */
Status_USBReady = 2, /**< USB interface is connected and ready */
};
/* Macros: */ /* Macros: */
/** HID Class specific request to get the next HID report from the device. */ /** HID Class specific request to get the next HID report from the device. */
@ -74,6 +60,18 @@
/** HID Class specific request to set the current HID protocol in use, either report or boot. */ /** HID Class specific request to set the current HID protocol in use, either report or boot. */
#define REQ_SetProtocol 0x0B #define REQ_SetProtocol 0x0B
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
#define LEDMASK_USB_NOTREADY LEDS_LED1
/** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
#define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
#define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
/* Type Defines: */ /* Type Defines: */
/** Type define for the keyboard HID report structure, for creating and sending HID reports to the host PC. /** Type define for the keyboard HID report structure, for creating and sending HID reports to the host PC.
* This mirrors the layout described to the host in the HID report descriptor, in Descriptors.c. * This mirrors the layout described to the host in the HID report descriptor, in Descriptors.c.
@ -96,11 +94,13 @@
} USB_MouseReport_Data_t; } USB_MouseReport_Data_t;
/* Function Prototypes: */ /* Function Prototypes: */
void SetupHardware(void);
void Keyboard_HID_Task(void);
void Mouse_HID_Task(void);
void EVENT_USB_Connect(void); void EVENT_USB_Connect(void);
void EVENT_USB_Disconnect(void); void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void); void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void); void EVENT_USB_UnhandledControlPacket(void);
void UpdateStatus(uint8_t CurrentStatus);
#endif #endif

@ -119,13 +119,12 @@ OBJDIR = .
# Path to the LUFA library # Path to the LUFA library
LUFA_PATH = ../../.. LUFA_PATH = ../../../..
# List C source files here. (C dependencies are automatically generated.) # List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c \ SRC = $(TARGET).c \
Descriptors.c \ Descriptors.c \
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \
@ -136,7 +135,6 @@ SRC = $(TARGET).c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \
$(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c \
# List C++ source files here. (C dependencies are automatically generated.) # List C++ source files here. (C dependencies are automatically generated.)

@ -36,17 +36,24 @@
#include "MIDI.h" #include "MIDI.h"
/* Scheduler Task List */
TASK_LIST
{
{ .Task = USB_USBTask , .TaskStatus = TASK_STOP },
{ .Task = USB_MIDI_Task , .TaskStatus = TASK_STOP },
};
/** Main program entry point. This routine configures the hardware required by the application, then /** Main program entry point. This routine configures the hardware required by the application, then
* starts the scheduler to run the application tasks. * starts the scheduler to run the application tasks.
*/ */
int main(void) int main(void)
{
SetupHardware();
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
for (;;)
{
MIDI_Task();
USB_USBTask();
}
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{ {
/* Disable watchdog if enabled by bootloader/fuses */ /* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF); MCUSR &= ~(1 << WDRF);
@ -59,28 +66,14 @@ int main(void)
Joystick_Init(); Joystick_Init();
LEDs_Init(); LEDs_Init();
Buttons_Init(); Buttons_Init();
/* Indicate USB not ready */
UpdateStatus(Status_USBNotReady);
/* Initialize Scheduler so that it can be used */
Scheduler_Init();
/* Initialize USB Subsystem */
USB_Init(); USB_Init();
/* Scheduling - routine never returns, so put this last in the main function */
Scheduler_Start();
} }
/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs. */ /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs. */
void EVENT_USB_Connect(void) void EVENT_USB_Connect(void)
{ {
/* Start USB management task */
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
/* Indicate USB enumerating */ /* Indicate USB enumerating */
UpdateStatus(Status_USBEnumerating); LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
} }
/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via /** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via
@ -88,12 +81,8 @@ void EVENT_USB_Connect(void)
*/ */
void EVENT_USB_Disconnect(void) void EVENT_USB_Disconnect(void)
{ {
/* Stop running audio and USB management tasks */
Scheduler_SetTaskMode(USB_MIDI_Task, TASK_STOP);
Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);
/* Indicate USB not ready */ /* Indicate USB not ready */
UpdateStatus(Status_USBNotReady); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
} }
/** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration /** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration
@ -111,16 +100,13 @@ void EVENT_USB_ConfigurationChanged(void)
ENDPOINT_BANK_SINGLE); ENDPOINT_BANK_SINGLE);
/* Indicate USB connected and ready */ /* Indicate USB connected and ready */
UpdateStatus(Status_USBReady); LEDs_SetAllLEDs(LEDMASK_USB_READY);
/* Start MIDI task */
Scheduler_SetTaskMode(USB_MIDI_Task, TASK_RUN);
} }
/** Task to handle the generation of MIDI note change events in response to presses of the board joystick, and send them /** Task to handle the generation of MIDI note change events in response to presses of the board joystick, and send them
* to the host. * to the host.
*/ */
TASK(USB_MIDI_Task) void MIDI_Task(void)
{ {
static uint8_t PrevJoystickStatus; static uint8_t PrevJoystickStatus;
@ -164,33 +150,6 @@ TASK(USB_MIDI_Task)
Endpoint_ClearOUT(); Endpoint_ClearOUT();
} }
/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to
* log to a serial port, or anything else that is suitable for status updates.
*
* \param CurrentStatus Current status of the system, from the MIDI_StatusCodes_t enum
*/
void UpdateStatus(uint8_t CurrentStatus)
{
uint8_t LEDMask = LEDS_NO_LEDS;
/* Set the LED mask to the appropriate LED mask based on the given status code */
switch (CurrentStatus)
{
case Status_USBNotReady:
LEDMask = (LEDS_LED1);
break;
case Status_USBEnumerating:
LEDMask = (LEDS_LED1 | LEDS_LED2);
break;
case Status_USBReady:
LEDMask = (LEDS_LED2 | LEDS_LED4);
break;
}
/* Set the board LEDs to the new LED mask */
LEDs_SetAllLEDs(LEDMask);
}
/** Sends a MIDI note change event (note on or off) to the MIDI output jack, on the given virtual cable ID and channel. /** Sends a MIDI note change event (note on or off) to the MIDI output jack, on the given virtual cable ID and channel.
* *
* \param Pitch Pitch of the note to turn on or off * \param Pitch Pitch of the note to turn on or off

@ -44,12 +44,11 @@
#include "Descriptors.h" #include "Descriptors.h"
#include <LUFA/Version.h> // Library Version Information #include <LUFA/Version.h>
#include <LUFA/Drivers/USB/USB.h> // USB Functionality #include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Board/Joystick.h> // Joystick driver #include <LUFA/Drivers/Board/Joystick.h>
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver #include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Drivers/Board/Buttons.h> // Board Buttons driver #include <LUFA/Drivers/Board/Buttons.h>
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
/* Macros: */ /* Macros: */
/** MIDI command for a note on (activation) event */ /** MIDI command for a note on (activation) event */
@ -68,19 +67,22 @@
*/ */
#define MIDI_CHANNEL(channel) (channel - 1) #define MIDI_CHANNEL(channel) (channel - 1)
/* Enums: */ /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
/** Enum for the possible status codes for passing to the UpdateStatus() function. */ #define LEDMASK_USB_NOTREADY LEDS_LED1
enum MIDI_StatusCodes_t
{
Status_USBNotReady = 0, /**< USB is not ready (disconnected from a USB host) */
Status_USBEnumerating = 1, /**< USB interface is enumerating */
Status_USBReady = 2, /**< USB interface is connected and ready */
};
/* Task Definitions: */ /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
TASK(USB_MIDI_Task); #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
#define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
/* Function Prototypes: */ /* Function Prototypes: */
void SetupHardware(void);
void MIDI_Task(void);
void EVENT_USB_Connect(void); void EVENT_USB_Connect(void);
void EVENT_USB_Disconnect(void); void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void); void EVENT_USB_ConfigurationChanged(void);

@ -119,13 +119,12 @@ OBJDIR = .
# Path to the LUFA library # Path to the LUFA library
LUFA_PATH = ../../.. LUFA_PATH = ../../../..
# List C source files here. (C dependencies are automatically generated.) # List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c \ SRC = $(TARGET).c \
Descriptors.c \ Descriptors.c \
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \
@ -136,7 +135,6 @@ SRC = $(TARGET).c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \
$(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c \
# List C++ source files here. (C dependencies are automatically generated.) # List C++ source files here. (C dependencies are automatically generated.)

@ -37,12 +37,6 @@
#define INCLUDE_FROM_MASSSTORAGE_C #define INCLUDE_FROM_MASSSTORAGE_C
#include "MassStorage.h" #include "MassStorage.h"
/* Scheduler Task List */
TASK_LIST
{
{ .Task = USB_MassStorage , .TaskStatus = TASK_STOP },
};
/* Global Variables */ /* Global Variables */
/** Structure to hold the latest Command Block Wrapper issued by the host, containing a SCSI command to execute. */ /** Structure to hold the latest Command Block Wrapper issued by the host, containing a SCSI command to execute. */
CommandBlockWrapper_t CommandBlock; CommandBlockWrapper_t CommandBlock;
@ -57,6 +51,20 @@ volatile bool IsMassStoreReset = false;
* starts the scheduler to run the application tasks. * starts the scheduler to run the application tasks.
*/ */
int main(void) int main(void)
{
SetupHardware();
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
for (;;)
{
MassStorage_Task();
USB_USBTask();
}
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{ {
/* Disable watchdog if enabled by bootloader/fuses */ /* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF); MCUSR &= ~(1 << WDRF);
@ -68,28 +76,17 @@ int main(void)
/* Hardware Initialization */ /* Hardware Initialization */
LEDs_Init(); LEDs_Init();
Dataflash_Init(SPI_SPEED_FCPU_DIV_2); Dataflash_Init(SPI_SPEED_FCPU_DIV_2);
USB_Init();
/* Clear Dataflash sector protections, if enabled */ /* Clear Dataflash sector protections, if enabled */
DataflashManager_ResetDataflashProtections(); DataflashManager_ResetDataflashProtections();
/* Indicate USB not ready */
UpdateStatus(Status_USBNotReady);
/* Initialize Scheduler so that it can be used */
Scheduler_Init();
/* Initialize USB Subsystem */
USB_Init();
/* Scheduling - routine never returns, so put this last in the main function */
Scheduler_Start();
} }
/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs. */ /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs. */
void EVENT_USB_Connect(void) void EVENT_USB_Connect(void)
{ {
/* Indicate USB enumerating */ /* Indicate USB enumerating */
UpdateStatus(Status_USBEnumerating); LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
/* Reset the MSReset flag upon connection */ /* Reset the MSReset flag upon connection */
IsMassStoreReset = false; IsMassStoreReset = false;
@ -100,11 +97,8 @@ void EVENT_USB_Connect(void)
*/ */
void EVENT_USB_Disconnect(void) void EVENT_USB_Disconnect(void)
{ {
/* Stop running mass storage task */
Scheduler_SetTaskMode(USB_MassStorage, TASK_STOP);
/* Indicate USB not ready */ /* Indicate USB not ready */
UpdateStatus(Status_USBNotReady); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
} }
/** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration /** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration
@ -122,10 +116,7 @@ void EVENT_USB_ConfigurationChanged(void)
ENDPOINT_BANK_DOUBLE); ENDPOINT_BANK_DOUBLE);
/* Indicate USB connected and ready */ /* Indicate USB connected and ready */
UpdateStatus(Status_USBReady); LEDs_SetAllLEDs(LEDMASK_USB_READY);
/* Start mass storage task */
Scheduler_SetTaskMode(USB_MassStorage, TASK_RUN);
} }
/** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific /** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific
@ -170,43 +161,10 @@ void EVENT_USB_UnhandledControlPacket(void)
} }
} }
/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to
* log to a serial port, or anything else that is suitable for status updates.
*
* \param CurrentStatus Current status of the system, from the MassStorage_StatusCodes_t enum
*/
void UpdateStatus(uint8_t CurrentStatus)
{
uint8_t LEDMask = LEDS_NO_LEDS;
/* Set the LED mask to the appropriate LED mask based on the given status code */
switch (CurrentStatus)
{
case Status_USBNotReady:
LEDMask = (LEDS_LED1);
break;
case Status_USBEnumerating:
LEDMask = (LEDS_LED1 | LEDS_LED2);
break;
case Status_USBReady:
LEDMask = (LEDS_LED2 | LEDS_LED4);
break;
case Status_CommandBlockError:
LEDMask = (LEDS_LED1);
break;
case Status_ProcessingCommandBlock:
LEDMask = (LEDS_LED1 | LEDS_LED2);
break;
}
/* Set the board LEDs to the new LED mask */
LEDs_SetAllLEDs(LEDMask);
}
/** Task to manage the Mass Storage interface, reading in Command Block Wrappers from the host, processing the SCSI commands they /** Task to manage the Mass Storage interface, reading in Command Block Wrappers from the host, processing the SCSI commands they
* contain, and returning Command Status Wrappers back to the host to indicate the success or failure of the last issued command. * contain, and returning Command Status Wrappers back to the host to indicate the success or failure of the last issued command.
*/ */
TASK(USB_MassStorage) void MassStorage_Task(void)
{ {
/* Check if the USB System is connected to a Host */ /* Check if the USB System is connected to a Host */
if (USB_IsConnected) if (USB_IsConnected)
@ -218,7 +176,7 @@ TASK(USB_MassStorage)
if (Endpoint_IsReadWriteAllowed()) if (Endpoint_IsReadWriteAllowed())
{ {
/* Indicate busy */ /* Indicate busy */
UpdateStatus(Status_ProcessingCommandBlock); LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
/* Process sent command block from the host */ /* Process sent command block from the host */
if (ReadInCommandBlock()) if (ReadInCommandBlock())
@ -260,12 +218,12 @@ TASK(USB_MassStorage)
} }
/* Indicate ready */ /* Indicate ready */
UpdateStatus(Status_USBReady); LEDs_SetAllLEDs(LEDMASK_USB_READY);
} }
else else
{ {
/* Indicate error reading in the command block from the host */ /* Indicate error reading in the command block from the host */
UpdateStatus(Status_CommandBlockError); LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
} }
} }
} }

@ -46,11 +46,10 @@
#include "Lib/SCSI.h" #include "Lib/SCSI.h"
#include "Lib/DataflashManager.h" #include "Lib/DataflashManager.h"
#include <LUFA/Version.h> // Library Version Information #include <LUFA/Version.h>
#include <LUFA/Drivers/USB/USB.h> // USB Functionality #include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver #include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Drivers/Board/Dataflash.h> // Dataflash chip driver #include <LUFA/Drivers/Board/Dataflash.h>
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
/* Macros: */ /* Macros: */
/** Mass Storage Class specific request to reset the Mass Storage interface, ready for the next command. */ /** Mass Storage Class specific request to reset the Mass Storage interface, ready for the next command. */
@ -82,6 +81,21 @@
/** Mask for a Command Block Wrapper's flags attribute to specify a command with data sent from device-to-host. */ /** Mask for a Command Block Wrapper's flags attribute to specify a command with data sent from device-to-host. */
#define COMMAND_DIRECTION_DATA_IN (1 << 7) #define COMMAND_DIRECTION_DATA_IN (1 << 7)
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
#define LEDMASK_USB_NOTREADY LEDS_LED1
/** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
#define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
#define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is busy. */
#define LEDMASK_USB_BUSY (LEDS_LED2)
/* Type defines: */ /* Type defines: */
/** Type define for a Command Block Wrapper, used in the Mass Storage Bulk-Only Transport protocol. */ /** Type define for a Command Block Wrapper, used in the Mass Storage Bulk-Only Transport protocol. */
typedef struct typedef struct
@ -113,32 +127,20 @@
Phase_Error = 2 /**< Command failed due to being invalid in the current phase */ Phase_Error = 2 /**< Command failed due to being invalid in the current phase */
}; };
/** Enum for the possible status codes for passing to the UpdateStatus() function. */
enum MassStorage_StatusCodes_t
{
Status_USBNotReady = 0, /**< USB is not ready (disconnected from a USB host) */
Status_USBEnumerating = 1, /**< USB interface is enumerating */
Status_USBReady = 2, /**< USB interface is connected and ready */
Status_CommandBlockError = 3, /**< Processing a SCSI command block from the host */
Status_ProcessingCommandBlock = 4, /**< Error during the processing of a SCSI command block from the host */
};
/* Global Variables: */ /* Global Variables: */
extern CommandBlockWrapper_t CommandBlock; extern CommandBlockWrapper_t CommandBlock;
extern CommandStatusWrapper_t CommandStatus; extern CommandStatusWrapper_t CommandStatus;
extern volatile bool IsMassStoreReset; extern volatile bool IsMassStoreReset;
/* Task Definitions: */
TASK(USB_MassStorage);
/* Function Prototypes: */ /* Function Prototypes: */
void SetupHardware(void);
void MassStorage_Task(void);
void EVENT_USB_Connect(void); void EVENT_USB_Connect(void);
void EVENT_USB_Disconnect(void); void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void); void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void); void EVENT_USB_UnhandledControlPacket(void);
void UpdateStatus(uint8_t CurrentStatus);
#if defined(INCLUDE_FROM_MASSSTORAGE_C) #if defined(INCLUDE_FROM_MASSSTORAGE_C)
static bool ReadInCommandBlock(void); static bool ReadInCommandBlock(void);
static void ReturnCommandStatus(void); static void ReturnCommandStatus(void);

@ -119,7 +119,7 @@ OBJDIR = .
# Path to the LUFA library # Path to the LUFA library
LUFA_PATH = ../../.. LUFA_PATH = ../../../..
# List C source files here. (C dependencies are automatically generated.) # List C source files here. (C dependencies are automatically generated.)
@ -127,7 +127,6 @@ SRC = $(TARGET).c \
Descriptors.c \ Descriptors.c \
Lib/SCSI.c \ Lib/SCSI.c \
Lib/DataflashManager.c \ Lib/DataflashManager.c \
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \
@ -138,7 +137,6 @@ SRC = $(TARGET).c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \
$(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c \
# List C++ source files here. (C dependencies are automatically generated.) # List C++ source files here. (C dependencies are automatically generated.)

@ -36,13 +36,6 @@
#include "Mouse.h" #include "Mouse.h"
/* Scheduler Task List */
TASK_LIST
{
{ .Task = USB_USBTask , .TaskStatus = TASK_STOP },
{ .Task = USB_Mouse_Report , .TaskStatus = TASK_STOP },
};
/* Global Variables */ /* Global Variables */
/** Indicates what report mode the host has requested, true for normal HID reporting mode, false for special boot /** Indicates what report mode the host has requested, true for normal HID reporting mode, false for special boot
* protocol reporting mode. * protocol reporting mode.
@ -65,6 +58,20 @@ uint16_t IdleMSRemaining = 0;
* starts the scheduler to run the application tasks. * starts the scheduler to run the application tasks.
*/ */
int main(void) int main(void)
{
SetupHardware();
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
for (;;)
{
Mouse_Task();
USB_USBTask();
}
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{ {
/* Disable watchdog if enabled by bootloader/fuses */ /* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF); MCUSR &= ~(1 << WDRF);
@ -77,24 +84,13 @@ int main(void)
Joystick_Init(); Joystick_Init();
LEDs_Init(); LEDs_Init();
Buttons_Init(); Buttons_Init();
USB_Init();
/* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */ /* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */
OCR0A = 0x7D; OCR0A = 0x7D;
TCCR0A = (1 << WGM01); TCCR0A = (1 << WGM01);
TCCR0B = ((1 << CS01) | (1 << CS00)); TCCR0B = ((1 << CS01) | (1 << CS00));
TIMSK0 = (1 << OCIE0A); TIMSK0 = (1 << OCIE0A);
/* Indicate USB not ready */
UpdateStatus(Status_USBNotReady);
/* Initialize Scheduler so that it can be used */
Scheduler_Init();
/* Initialize USB Subsystem */
USB_Init();
/* Scheduling - routine never returns, so put this last in the main function */
Scheduler_Start();
} }
/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and
@ -102,11 +98,8 @@ int main(void)
*/ */
void EVENT_USB_Connect(void) void EVENT_USB_Connect(void)
{ {
/* Start USB management task */
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
/* Indicate USB enumerating */ /* Indicate USB enumerating */
UpdateStatus(Status_USBEnumerating); LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
/* Default to report protocol on connect */ /* Default to report protocol on connect */
UsingReportProtocol = true; UsingReportProtocol = true;
@ -117,12 +110,8 @@ void EVENT_USB_Connect(void)
*/ */
void EVENT_USB_Disconnect(void) void EVENT_USB_Disconnect(void)
{ {
/* Stop running mouse reporting and USB management tasks */
Scheduler_SetTaskMode(USB_Mouse_Report, TASK_STOP);
Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);
/* Indicate USB not ready */ /* Indicate USB not ready */
UpdateStatus(Status_USBNotReady); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
} }
/** Event handler for the USB_ConfigurationChanged event. This is fired when the host sets the current configuration /** Event handler for the USB_ConfigurationChanged event. This is fired when the host sets the current configuration
@ -136,10 +125,7 @@ void EVENT_USB_ConfigurationChanged(void)
ENDPOINT_BANK_SINGLE); ENDPOINT_BANK_SINGLE);
/* Indicate USB connected and ready */ /* Indicate USB connected and ready */
UpdateStatus(Status_USBReady); LEDs_SetAllLEDs(LEDMASK_USB_READY);
/* Start running mouse reporting task */
Scheduler_SetTaskMode(USB_Mouse_Report, TASK_RUN);
} }
/** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific /** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific
@ -321,35 +307,8 @@ void SendNextReport(void)
} }
} }
/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to
* log to a serial port, or anything else that is suitable for status updates.
*
* \param CurrentStatus Current status of the system, from the Mouse_StatusCodes_t enum
*/
void UpdateStatus(uint8_t CurrentStatus)
{
uint8_t LEDMask = LEDS_NO_LEDS;
/* Set the LED mask to the appropriate LED mask based on the given status code */
switch (CurrentStatus)
{
case Status_USBNotReady:
LEDMask = (LEDS_LED1);
break;
case Status_USBEnumerating:
LEDMask = (LEDS_LED1 | LEDS_LED2);
break;
case Status_USBReady:
LEDMask = (LEDS_LED2 | LEDS_LED4);
break;
}
/* Set the board LEDs to the new LED mask */
LEDs_SetAllLEDs(LEDMask);
}
/** Task to manage HID report generation and transmission to the host, when in report mode. */ /** Task to manage HID report generation and transmission to the host, when in report mode. */
TASK(USB_Mouse_Report) void Mouse_Task(void)
{ {
/* Check if the USB system is connected to a host */ /* Check if the USB system is connected to a host */
if (USB_IsConnected) if (USB_IsConnected)

@ -46,15 +46,11 @@
#include "Descriptors.h" #include "Descriptors.h"
#include <LUFA/Version.h> // Library Version Information #include <LUFA/Version.h>
#include <LUFA/Drivers/USB/USB.h> // USB Functionality #include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Board/Joystick.h> // Joystick driver #include <LUFA/Drivers/Board/Joystick.h>
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver #include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Drivers/Board/Buttons.h> // Board Buttons driver #include <LUFA/Drivers/Board/Buttons.h>
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
/* Task Definitions: */
TASK(USB_Mouse_Report);
/* Macros: */ /* Macros: */
/** Idle period indicating that reports should be sent only when the inputs have changed */ /** Idle period indicating that reports should be sent only when the inputs have changed */
@ -78,6 +74,18 @@
/** HID Class specific request to set the current HID protocol in use, either report or boot. */ /** HID Class specific request to set the current HID protocol in use, either report or boot. */
#define REQ_SetProtocol 0x0B #define REQ_SetProtocol 0x0B
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
#define LEDMASK_USB_NOTREADY LEDS_LED1
/** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
#define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
#define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
/* Type Defines: */ /* Type Defines: */
/** Type define for the mouse HID report structure, for creating and sending HID reports to the host PC. /** Type define for the mouse HID report structure, for creating and sending HID reports to the host PC.
* This mirrors the layout described to the host in the HID report descriptor, in Descriptors.c. * This mirrors the layout described to the host in the HID report descriptor, in Descriptors.c.
@ -89,16 +97,10 @@
int8_t Y; /**< Current mouse delta Y movement, as a signed 8-bit integer */ int8_t Y; /**< Current mouse delta Y movement, as a signed 8-bit integer */
} USB_MouseReport_Data_t; } USB_MouseReport_Data_t;
/* Enums: */
/** Enum for the possible status codes for passing to the UpdateStatus() function. */
enum Mouse_StatusCodes_t
{
Status_USBNotReady = 0, /**< USB is not ready (disconnected from a USB host) */
Status_USBEnumerating = 1, /**< USB interface is enumerating */
Status_USBReady = 2, /**< USB interface is connected and ready */
};
/* Function Prototypes: */ /* Function Prototypes: */
void SetupHardware(void);
void Mouse_Task(void);
void EVENT_USB_Connect(void); void EVENT_USB_Connect(void);
void EVENT_USB_Disconnect(void); void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void); void EVENT_USB_ConfigurationChanged(void);

@ -119,13 +119,12 @@ OBJDIR = .
# Path to the LUFA library # Path to the LUFA library
LUFA_PATH = ../../.. LUFA_PATH = ../../../..
# List C source files here. (C dependencies are automatically generated.) # List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c \ SRC = $(TARGET).c \
Descriptors.c \ Descriptors.c \
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \
@ -136,7 +135,6 @@ SRC = $(TARGET).c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \
$(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c \
# List C++ source files here. (C dependencies are automatically generated.) # List C++ source files here. (C dependencies are automatically generated.)
CPPSRC = CPPSRC =

@ -40,8 +40,6 @@
#include <avr/io.h> #include <avr/io.h>
#include <string.h> #include <string.h>
#include <LUFA/Scheduler/Scheduler.h>
#include "EthernetProtocols.h" #include "EthernetProtocols.h"
#include "Ethernet.h" #include "Ethernet.h"
#include "ProtocolDecoders.h" #include "ProtocolDecoders.h"

@ -56,7 +56,7 @@ TCP_ConnectionState_t ConnectionStateTable[MAX_TCP_CONNECTIONS];
* level. If an application produces a response, this task constructs the appropriate Ethernet frame and places it into the Ethernet OUT * level. If an application produces a response, this task constructs the appropriate Ethernet frame and places it into the Ethernet OUT
* buffer for later transmission. * buffer for later transmission.
*/ */
TASK(TCP_Task) void TCP_Task(void)
{ {
/* Task to hand off TCP packets to and from the listening applications. */ /* Task to hand off TCP packets to and from the listening applications. */

@ -40,8 +40,6 @@
#include <avr/io.h> #include <avr/io.h>
#include <stdbool.h> #include <stdbool.h>
#include <LUFA/Scheduler/Scheduler.h>
#include "EthernetProtocols.h" #include "EthernetProtocols.h"
#include "Ethernet.h" #include "Ethernet.h"
#include "ProtocolDecoders.h" #include "ProtocolDecoders.h"
@ -230,14 +228,12 @@
uint16_t UrgentPointer; /**< Urgent data pointer */ uint16_t UrgentPointer; /**< Urgent data pointer */
} TCP_Header_t; } TCP_Header_t;
/* Tasks: */
TASK(TCP_Task);
/* External Variables: */ /* External Variables: */
TCP_PortState_t PortStateTable[MAX_OPEN_TCP_PORTS]; TCP_PortState_t PortStateTable[MAX_OPEN_TCP_PORTS];
/* Function Prototypes: */ /* Function Prototypes: */
void TCP_Init(void); void TCP_Init(void);
void TCP_Task(void);
bool TCP_SetPortState(uint16_t Port, uint8_t State, void (*Handler)(TCP_ConnectionState_t*, TCP_ConnectionBuffer_t*)); bool TCP_SetPortState(uint16_t Port, uint8_t State, void (*Handler)(TCP_ConnectionState_t*, TCP_ConnectionBuffer_t*));
uint8_t TCP_GetPortState(uint16_t Port); uint8_t TCP_GetPortState(uint16_t Port);
bool TCP_SetConnectionState(uint16_t Port, IP_Address_t RemoteAddress, uint16_t RemotePort, uint8_t State); bool TCP_SetConnectionState(uint16_t Port, IP_Address_t RemoteAddress, uint16_t RemotePort, uint8_t State);

@ -36,19 +36,32 @@
#include "RNDISEthernet.h" #include "RNDISEthernet.h"
/* Scheduler Task List */
TASK_LIST
{
{ .Task = USB_USBTask , .TaskStatus = TASK_STOP },
{ .Task = Ethernet_Task , .TaskStatus = TASK_STOP },
{ .Task = TCP_Task , .TaskStatus = TASK_STOP },
{ .Task = RNDIS_Task , .TaskStatus = TASK_STOP },
};
/** Main program entry point. This routine configures the hardware required by the application, then /** Main program entry point. This routine configures the hardware required by the application, then
* starts the scheduler to run the USB management task. * starts the scheduler to run the USB management task.
*/ */
int main(void) int main(void)
{
SetupHardware();
/* Webserver Initialization */
TCP_Init();
Webserver_Init();
printf_P(PSTR("\r\n\r\n****** RNDIS Demo running. ******\r\n"));
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
for (;;)
{
Ethernet_Task();
TCP_Task();
RNDIS_Task();
USB_USBTask();
}
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{ {
/* Disable watchdog if enabled by bootloader/fuses */ /* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF); MCUSR &= ~(1 << WDRF);
@ -60,24 +73,7 @@ int main(void)
/* Hardware Initialization */ /* Hardware Initialization */
LEDs_Init(); LEDs_Init();
SerialStream_Init(9600, false); SerialStream_Init(9600, false);
/* Webserver Initialization */
TCP_Init();
Webserver_Init();
printf_P(PSTR("\r\n\r\n****** RNDIS Demo running. ******\r\n"));
/* Indicate USB not ready */
UpdateStatus(Status_USBNotReady);
/* Initialize Scheduler so that it can be used */
Scheduler_Init();
/* Initialize USB Subsystem */
USB_Init(); USB_Init();
/* Scheduling - routine never returns, so put this last in the main function */
Scheduler_Start();
} }
/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and
@ -85,11 +81,8 @@ int main(void)
*/ */
void EVENT_USB_Connect(void) void EVENT_USB_Connect(void)
{ {
/* Start USB management task */
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
/* Indicate USB enumerating */ /* Indicate USB enumerating */
UpdateStatus(Status_USBEnumerating); LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
} }
/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via /** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via
@ -97,14 +90,8 @@ void EVENT_USB_Connect(void)
*/ */
void EVENT_USB_Disconnect(void) void EVENT_USB_Disconnect(void)
{ {
/* Stop running TCP/IP and USB management tasks */
Scheduler_SetTaskMode(RNDIS_Task, TASK_STOP);
Scheduler_SetTaskMode(Ethernet_Task, TASK_STOP);
Scheduler_SetTaskMode(TCP_Task, TASK_STOP);
Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);
/* Indicate USB not ready */ /* Indicate USB not ready */
UpdateStatus(Status_USBNotReady); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
} }
/** Event handler for the USB_ConfigurationChanged event. This is fired when the host sets the current configuration /** Event handler for the USB_ConfigurationChanged event. This is fired when the host sets the current configuration
@ -126,12 +113,7 @@ void EVENT_USB_ConfigurationChanged(void)
ENDPOINT_BANK_SINGLE); ENDPOINT_BANK_SINGLE);
/* Indicate USB connected and ready */ /* Indicate USB connected and ready */
UpdateStatus(Status_USBReady); LEDs_SetAllLEDs(LEDMASK_USB_READY);
/* Start TCP/IP tasks */
Scheduler_SetTaskMode(RNDIS_Task, TASK_RUN);
Scheduler_SetTaskMode(Ethernet_Task, TASK_RUN);
Scheduler_SetTaskMode(TCP_Task, TASK_RUN);
} }
/** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific /** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific
@ -188,41 +170,11 @@ void EVENT_USB_UnhandledControlPacket(void)
} }
} }
/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to
* log to a serial port, or anything else that is suitable for status updates.
*
* \param CurrentStatus Current status of the system, from the RNDISEthernet_StatusCodes_t enum
*/
void UpdateStatus(uint8_t CurrentStatus)
{
uint8_t LEDMask = LEDS_NO_LEDS;
/* Set the LED mask to the appropriate LED mask based on the given status code */
switch (CurrentStatus)
{
case Status_USBNotReady:
LEDMask = (LEDS_LED1);
break;
case Status_USBEnumerating:
LEDMask = (LEDS_LED1 | LEDS_LED2);
break;
case Status_USBReady:
LEDMask = (LEDS_LED2 | LEDS_LED4);
break;
case Status_ProcessingEthernetFrame:
LEDMask = (LEDS_LED2 | LEDS_LED3);
break;
}
/* Set the board LEDs to the new LED mask */
LEDs_SetAllLEDs(LEDMask);
}
/** Task to manage the sending and receiving of encapsulated RNDIS data and notifications. This removes the RNDIS /** Task to manage the sending and receiving of encapsulated RNDIS data and notifications. This removes the RNDIS
* wrapper from received Ethernet frames and places them in the FrameIN global buffer, or adds the RNDIS wrapper * wrapper from received Ethernet frames and places them in the FrameIN global buffer, or adds the RNDIS wrapper
* to a frame in the FrameOUT global before sending the buffer contents to the host. * to a frame in the FrameOUT global before sending the buffer contents to the host.
*/ */
TASK(RNDIS_Task) void RNDIS_Task(void)
{ {
/* Select the notification endpoint */ /* Select the notification endpoint */
Endpoint_SelectEndpoint(CDC_NOTIFICATION_EPNUM); Endpoint_SelectEndpoint(CDC_NOTIFICATION_EPNUM);
@ -317,7 +269,7 @@ TASK(RNDIS_Task)
/** Ethernet frame processing task. This task checks to see if a frame has been received, and if so hands off the processing /** Ethernet frame processing task. This task checks to see if a frame has been received, and if so hands off the processing
* of the frame to the Ethernet processing routines. * of the frame to the Ethernet processing routines.
*/ */
TASK(Ethernet_Task) void Ethernet_Task(void)
{ {
/* Task for Ethernet processing. Incoming ethernet frames are loaded into the FrameIN structure, and /* Task for Ethernet processing. Incoming ethernet frames are loaded into the FrameIN structure, and
outgoing frames should be loaded into the FrameOUT structure. Both structures can only hold a single outgoing frames should be loaded into the FrameOUT structure. Both structures can only hold a single
@ -327,12 +279,12 @@ TASK(Ethernet_Task)
if (FrameIN.FrameInBuffer) if (FrameIN.FrameInBuffer)
{ {
/* Indicate packet processing started */ /* Indicate packet processing started */
UpdateStatus(Status_ProcessingEthernetFrame); LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
/* Process the ethernet frame - replace this with your own Ethernet handler code as desired */ /* Process the ethernet frame - replace this with your own Ethernet handler code as desired */
Ethernet_ProcessPacket(); Ethernet_ProcessPacket();
/* Indicate packet processing complete */ /* Indicate packet processing complete */
UpdateStatus(Status_USBReady); LEDs_SetAllLEDs(LEDMASK_USB_READY);
} }
} }

@ -52,15 +52,29 @@
#include "Lib/ARP.h" #include "Lib/ARP.h"
#include "Lib/Webserver.h" #include "Lib/Webserver.h"
#include <LUFA/Version.h> // Library Version Information #include <LUFA/Version.h>
#include <LUFA/Drivers/USB/USB.h> // USB Functionality #include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver #include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management #include <LUFA/Drivers/Peripheral/SerialStream.h>
#include <LUFA/Drivers/Peripheral/SerialStream.h> // Serial stream driver
/* Macros: */ /* Macros: */
/** Notification value to indicate that a frame is ready to be read by the host. */ /** Notification value to indicate that a frame is ready to be read by the host. */
#define NOTIF_RESPONSE_AVAILABLE 0x01 #define NOTIF_RESPONSE_AVAILABLE 0x01
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
#define LEDMASK_USB_NOTREADY LEDS_LED1
/** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
#define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
#define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is busy. */
#define LEDMASK_USB_BUSY (LEDS_LED2)
/* Type Defines: */ /* Type Defines: */
/** Type define for a RNDIS notification message, for transmission to the RNDIS host via the notification /** Type define for a RNDIS notification message, for transmission to the RNDIS host via the notification
@ -75,26 +89,14 @@
uint16_t wLength; /**< Size of data payload following the notification header */ uint16_t wLength; /**< Size of data payload following the notification header */
} USB_Notification_t; } USB_Notification_t;
/* Enums: */
/** Enum for the possible status codes for passing to the UpdateStatus() function. */
enum RNDISEthernet_StatusCodes_t
{
Status_USBNotReady = 0, /**< USB is not ready (disconnected from a USB host) */
Status_USBEnumerating = 1, /**< USB interface is enumerating */
Status_USBReady = 2, /**< USB interface is connected and ready */
Status_ProcessingEthernetFrame = 3, /**< Currently processing an ethernet frame from the host */
};
/* Tasks: */
TASK(RNDIS_Task);
TASK(Ethernet_Task);
/* Function Prototypes: */ /* Function Prototypes: */
void SetupHardware(void);
void RNDIS_Task(void);
void Ethernet_Task(void);
void EVENT_USB_Connect(void); void EVENT_USB_Connect(void);
void EVENT_USB_Disconnect(void); void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void); void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void); void EVENT_USB_UnhandledControlPacket(void);
void UpdateStatus(uint8_t CurrentStatus);
#endif #endif

@ -119,7 +119,7 @@ OBJDIR = .
# Path to the LUFA library # Path to the LUFA library
LUFA_PATH = ../../.. LUFA_PATH = ../../../..
# List C source files here. (C dependencies are automatically generated.) # List C source files here. (C dependencies are automatically generated.)
@ -135,7 +135,6 @@ SRC = $(TARGET).c \
Lib/ARP.c \ Lib/ARP.c \
Lib/IP.c \ Lib/IP.c \
Lib/Webserver.c \ Lib/Webserver.c \
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
$(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c \ $(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c \
$(LUFA_PATH)/LUFA/Drivers/Peripheral/Serial.c \ $(LUFA_PATH)/LUFA/Drivers/Peripheral/Serial.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
@ -148,7 +147,6 @@ SRC = $(TARGET).c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \
$(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c \
# List C++ source files here. (C dependencies are automatically generated.) # List C++ source files here. (C dependencies are automatically generated.)

@ -30,13 +30,6 @@
#include "USBtoSerial.h" #include "USBtoSerial.h"
/* Scheduler Task List */
TASK_LIST
{
{ .Task = USB_USBTask , .TaskStatus = TASK_STOP },
{ .Task = CDC_Task , .TaskStatus = TASK_STOP },
};
/* Globals: */ /* Globals: */
/** Contains the current baud rate and other settings of the virtual serial port. /** Contains the current baud rate and other settings of the virtual serial port.
* *
@ -61,6 +54,24 @@ volatile bool Transmitting = false;
* starts the scheduler to run the application tasks. * starts the scheduler to run the application tasks.
*/ */
int main(void) int main(void)
{
SetupHardware();
/* Ring buffer Initialization */
Buffer_Initialize(&Rx_Buffer);
Buffer_Initialize(&Tx_Buffer);
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
for (;;)
{
CDC_Task();
USB_USBTask();
}
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{ {
/* Disable watchdog if enabled by bootloader/fuses */ /* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF); MCUSR &= ~(1 << WDRF);
@ -72,22 +83,7 @@ int main(void)
/* Hardware Initialization */ /* Hardware Initialization */
LEDs_Init(); LEDs_Init();
ReconfigureUSART(); ReconfigureUSART();
/* Ring buffer Initialization */
Buffer_Initialize(&Rx_Buffer);
Buffer_Initialize(&Tx_Buffer);
/* Indicate USB not ready */
UpdateStatus(Status_USBNotReady);
/* Initialize Scheduler so that it can be used */
Scheduler_Init();
/* Initialize USB Subsystem */
USB_Init(); USB_Init();
/* Scheduling - routine never returns, so put this last in the main function */
Scheduler_Start();
} }
/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and
@ -95,11 +91,8 @@ int main(void)
*/ */
void EVENT_USB_Connect(void) void EVENT_USB_Connect(void)
{ {
/* Start USB management task */
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
/* Indicate USB enumerating */ /* Indicate USB enumerating */
UpdateStatus(Status_USBEnumerating); LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
} }
/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via /** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via
@ -107,16 +100,12 @@ void EVENT_USB_Connect(void)
*/ */
void EVENT_USB_Disconnect(void) void EVENT_USB_Disconnect(void)
{ {
/* Stop running CDC and USB management tasks */
Scheduler_SetTaskMode(CDC_Task, TASK_STOP);
Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);
/* Reset Tx and Rx buffers, device disconnected */ /* Reset Tx and Rx buffers, device disconnected */
Buffer_Initialize(&Rx_Buffer); Buffer_Initialize(&Rx_Buffer);
Buffer_Initialize(&Tx_Buffer); Buffer_Initialize(&Tx_Buffer);
/* Indicate USB not ready */ /* Indicate USB not ready */
UpdateStatus(Status_USBNotReady); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
} }
/** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration /** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration
@ -138,10 +127,7 @@ void EVENT_USB_ConfigurationChanged(void)
ENDPOINT_BANK_SINGLE); ENDPOINT_BANK_SINGLE);
/* Indicate USB connected and ready */ /* Indicate USB connected and ready */
UpdateStatus(Status_USBReady); LEDs_SetAllLEDs(LEDMASK_USB_READY);
/* Start CDC task */
Scheduler_SetTaskMode(CDC_Task, TASK_RUN);
} }
/** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific /** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific
@ -207,7 +193,7 @@ void EVENT_USB_UnhandledControlPacket(void)
} }
/** Task to manage CDC data transmission and reception to and from the host, from and to the physical USART. */ /** Task to manage CDC data transmission and reception to and from the host, from and to the physical USART. */
TASK(CDC_Task) void CDC_Task(void)
{ {
if (USB_IsConnected) if (USB_IsConnected)
{ {
@ -309,33 +295,6 @@ ISR(USART1_RX_vect, ISR_BLOCK)
} }
} }
/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to
* log to a serial port, or anything else that is suitable for status updates.
*
* \param CurrentStatus Current status of the system, from the USBtoSerial_StatusCodes_t enum
*/
void UpdateStatus(uint8_t CurrentStatus)
{
uint8_t LEDMask = LEDS_NO_LEDS;
/* Set the LED mask to the appropriate LED mask based on the given status code */
switch (CurrentStatus)
{
case Status_USBNotReady:
LEDMask = (LEDS_LED1);
break;
case Status_USBEnumerating:
LEDMask = (LEDS_LED1 | LEDS_LED2);
break;
case Status_USBReady:
LEDMask = (LEDS_LED2 | LEDS_LED4);
break;
}
/* Set the board LEDs to the new LED mask */
LEDs_SetAllLEDs(LEDMask);
}
/** Reconfigures the USART to match the current serial port settings issued by the host as closely as possible. */ /** Reconfigures the USART to match the current serial port settings issued by the host as closely as possible. */
void ReconfigureUSART(void) void ReconfigureUSART(void)
{ {

@ -46,11 +46,10 @@
#include "Lib/RingBuff.h" #include "Lib/RingBuff.h"
#include <LUFA/Version.h> // Library Version Information #include <LUFA/Version.h>
#include <LUFA/Drivers/USB/USB.h> // USB Functionality #include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Peripheral/Serial.h> // USART driver #include <LUFA/Drivers/Peripheral/Serial.h>
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver #include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
/* Macros: */ /* Macros: */
/** CDC Class specific request to get the current virtual serial port configuration settings. */ /** CDC Class specific request to get the current virtual serial port configuration settings. */
@ -113,6 +112,18 @@
*/ */
#define CONTROL_LINE_IN_OVERRUNERROR (1 << 6) #define CONTROL_LINE_IN_OVERRUNERROR (1 << 6)
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
#define LEDMASK_USB_NOTREADY LEDS_LED1
/** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
#define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
#define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
/* Type Defines: */ /* Type Defines: */
/** Type define for the virtual serial port line encoding settings, for storing the current USART configuration /** 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. * as set by the host via a class specific request.
@ -170,16 +181,14 @@
Status_USBReady = 2, /**< USB interface is connected and ready */ Status_USBReady = 2, /**< USB interface is connected and ready */
}; };
/* Tasks: */
TASK(CDC_Task);
/* Function Prototypes: */ /* Function Prototypes: */
void SetupHardware(void);
void CDC_Task(void);
void ReconfigureUSART(void);
void EVENT_USB_Connect(void); void EVENT_USB_Connect(void);
void EVENT_USB_Disconnect(void); void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void); void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void); void EVENT_USB_UnhandledControlPacket(void);
void ReconfigureUSART(void);
void UpdateStatus(uint8_t CurrentStatus);
#endif #endif

@ -119,14 +119,13 @@ OBJDIR = .
# Path to the LUFA library # Path to the LUFA library
LUFA_PATH = ../../.. LUFA_PATH = ../../../..
# List C source files here. (C dependencies are automatically generated.) # List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c \ SRC = $(TARGET).c \
Descriptors.c \ Descriptors.c \
Lib/RingBuff.c \ Lib/RingBuff.c \
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \
@ -137,7 +136,6 @@ SRC = $(TARGET).c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \
$(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \ $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \
$(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c \
# List C++ source files here. (C dependencies are automatically generated.) # List C++ source files here. (C dependencies are automatically generated.)

File diff suppressed because one or more lines are too long

@ -5,14 +5,13 @@
*/ */
========== TODO: =========== ========== TODO: ===========
- Document new device class drivers (in progress) - Fix bootloaders - make compatible with smaller USB AVRS (USB_IsConnected, RAMPZ)
- Document new device class drivers
- Made new host class drivers - Made new host class drivers
- Document new host class drivers - Document new host class drivers
- Convert Host mode demos to class drivers - Convert Host mode demos to class drivers
- Add in old Host mode demos, convert to schedulerless - Convert Host mode demos to schedulerless
- Add in incomplete host mode demos
- Add standardized descriptor names to class driver structures, controlled by USE_NONSTANDARD_DESCRIPTOR_NAMES - Add standardized descriptor names to class driver structures, controlled by USE_NONSTANDARD_DESCRIPTOR_NAMES
- Remake AVRStudio projects to reflect file structure changes
============================ ============================
/** \page Page_ChangeLog Project Changelog /** \page Page_ChangeLog Project Changelog

Loading…
Cancel
Save