forked from mfulz_github/qmk_firmware
Converted device mode low-level demos to schedulerless.
This commit is contained in:
parent
2793c88fc6
commit
33a0184749
|
@ -36,18 +36,27 @@
|
|||
|
||||
#include "AudioInput.h"
|
||||
|
||||
/* Scheduler Task List */
|
||||
TASK_LIST
|
||||
{
|
||||
{ .Task = USB_USBTask , .TaskStatus = TASK_STOP },
|
||||
{ .Task = USB_Audio_Task , .TaskStatus = TASK_STOP },
|
||||
};
|
||||
/** Flag to indicate if the streaming audio alternative interface has been selected by the host. */
|
||||
bool StreamingAudioInterfaceSelected = false;
|
||||
|
||||
|
||||
/** Main program entry point. This routine configures the hardware required by the application, then
|
||||
* starts the scheduler to run the application tasks.
|
||||
/** Main program entry point. This routine contains the overall program flow, including initial
|
||||
* setup of all components and the main program loop.
|
||||
*/
|
||||
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 */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
|
@ -60,21 +69,10 @@ int main(void)
|
|||
LEDs_Init();
|
||||
ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32);
|
||||
ADC_SetupChannel(MIC_IN_ADC_CHANNEL);
|
||||
USB_Init();
|
||||
|
||||
/* Start the ADC conversion in free running mode */
|
||||
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
|
||||
|
@ -82,16 +80,13 @@ int main(void)
|
|||
*/
|
||||
void EVENT_USB_Connect(void)
|
||||
{
|
||||
/* Start USB management task */
|
||||
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
|
||||
|
||||
/* Indicate USB enumerating */
|
||||
UpdateStatus(Status_USBEnumerating);
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
|
||||
|
||||
/* Sample reload timer initialization */
|
||||
OCR0A = (F_CPU / AUDIO_SAMPLE_FREQUENCY) - 1;
|
||||
TCCR0A = (1 << WGM01); // CTC mode
|
||||
TCCR0B = (1 << CS00); // Fcpu speed
|
||||
TCCR0B = (1 << CS00); // Fcpu speed
|
||||
}
|
||||
|
||||
/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via
|
||||
|
@ -102,12 +97,11 @@ void EVENT_USB_Disconnect(void)
|
|||
/* Stop the sample reload timer */
|
||||
TCCR0B = 0;
|
||||
|
||||
/* Stop running audio and USB management tasks */
|
||||
Scheduler_SetTaskMode(USB_Audio_Task, TASK_STOP);
|
||||
Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);
|
||||
/* Indicate streaming audio interface not selected */
|
||||
StreamingAudioInterfaceSelected = false;
|
||||
|
||||
/* 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
|
||||
|
@ -121,7 +115,7 @@ void EVENT_USB_ConfigurationChanged(void)
|
|||
ENDPOINT_BANK_DOUBLE);
|
||||
|
||||
/* 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
|
||||
|
@ -140,16 +134,7 @@ void EVENT_USB_UnhandledControlPacket(void)
|
|||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Check if the host is enabling the audio interface (setting AlternateSetting to 1) */
|
||||
if (USB_ControlRequest.wValue)
|
||||
{
|
||||
/* Start audio task */
|
||||
Scheduler_SetTaskMode(USB_Audio_Task, TASK_RUN);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Stop audio task */
|
||||
Scheduler_SetTaskMode(USB_Audio_Task, TASK_STOP);
|
||||
}
|
||||
StreamingAudioInterfaceSelected = ((USB_ControlRequest.wValue) != 0);
|
||||
|
||||
/* Acknowledge status stage */
|
||||
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(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 */
|
||||
Endpoint_SelectEndpoint(AUDIO_STREAM_EPNUM);
|
||||
|
||||
|
|
|
@ -43,11 +43,10 @@
|
|||
|
||||
#include "Descriptors.h"
|
||||
|
||||
#include <LUFA/Version.h> // Library Version Information
|
||||
#include <LUFA/Drivers/USB/USB.h> // USB Functionality
|
||||
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver
|
||||
#include <LUFA/Drivers/Peripheral/ADC.h> // ADC driver
|
||||
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
#include <LUFA/Drivers/Peripheral/ADC.h>
|
||||
|
||||
/* Macros: */
|
||||
/** ADC channel number for the microphone input. */
|
||||
|
@ -59,24 +58,25 @@
|
|||
/** Maximum ADC range for the microphone input. */
|
||||
#define ADC_MAX_RANGE 0x3FF
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the possible status codes for passing to the UpdateStatus() function. */
|
||||
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 */
|
||||
};
|
||||
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
|
||||
#define LEDMASK_USB_NOTREADY LEDS_LED1
|
||||
|
||||
/* Task Definitions: */
|
||||
TASK(USB_Audio_Task);
|
||||
/** 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)
|
||||
|
||||
/* Function Prototypes: */
|
||||
void SetupHardware(void);
|
||||
void USB_Audio_Task(void);
|
||||
|
||||
void EVENT_USB_Connect(void);
|
||||
void EVENT_USB_Disconnect(void);
|
||||
void EVENT_USB_ConfigurationChanged(void);
|
||||
void EVENT_USB_UnhandledControlPacket(void);
|
||||
|
||||
void UpdateStatus(uint8_t CurrentStatus);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -119,13 +119,12 @@ OBJDIR = .
|
|||
|
||||
|
||||
# Path to the LUFA library
|
||||
LUFA_PATH = ../../..
|
||||
LUFA_PATH = ../../../..
|
||||
|
||||
|
||||
# List C source files here. (C dependencies are automatically generated.)
|
||||
SRC = $(TARGET).c \
|
||||
Descriptors.c \
|
||||
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.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/USBTask.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.)
|
||||
|
|
|
@ -36,18 +36,27 @@
|
|||
|
||||
#include "AudioOutput.h"
|
||||
|
||||
/* Scheduler Task List */
|
||||
TASK_LIST
|
||||
{
|
||||
{ .Task = USB_USBTask , .TaskStatus = TASK_STOP },
|
||||
{ .Task = USB_Audio_Task , .TaskStatus = TASK_STOP },
|
||||
};
|
||||
/** Flag to indicate if the streaming audio alternative interface has been selected by the host. */
|
||||
bool StreamingAudioInterfaceSelected = false;
|
||||
|
||||
|
||||
/** Main program entry point. This routine configures the hardware required by the application, then
|
||||
* starts the scheduler to run the application tasks.
|
||||
/** Main program entry point. This routine contains the overall program flow, including initial
|
||||
* setup of all components and the main program loop.
|
||||
*/
|
||||
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 */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
|
@ -55,21 +64,10 @@ int main(void)
|
|||
|
||||
/* Disable clock division */
|
||||
clock_prescale_set(clock_div_1);
|
||||
|
||||
|
||||
/* Hardware Initialization */
|
||||
LEDs_Init();
|
||||
|
||||
/* 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
|
||||
|
@ -77,11 +75,8 @@ int main(void)
|
|||
*/
|
||||
void EVENT_USB_Connect(void)
|
||||
{
|
||||
/* Start USB management task */
|
||||
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
|
||||
|
||||
/* Indicate USB enumerating */
|
||||
UpdateStatus(Status_USBEnumerating);
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
|
||||
|
||||
/* Sample reload timer initialization */
|
||||
OCR0A = (F_CPU / AUDIO_SAMPLE_FREQUENCY) - 1;
|
||||
|
@ -129,12 +124,11 @@ void EVENT_USB_Disconnect(void)
|
|||
PORTC = 0x00;
|
||||
#endif
|
||||
|
||||
/* Stop running audio and USB management tasks */
|
||||
Scheduler_SetTaskMode(USB_Audio_Task, TASK_STOP);
|
||||
Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);
|
||||
/* Indicate streaming audio interface not selected */
|
||||
StreamingAudioInterfaceSelected = false;
|
||||
|
||||
/* 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
|
||||
|
@ -148,7 +142,7 @@ void EVENT_USB_ConfigurationChanged(void)
|
|||
ENDPOINT_BANK_DOUBLE);
|
||||
|
||||
/* 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
|
||||
|
@ -167,16 +161,7 @@ void EVENT_USB_UnhandledControlPacket(void)
|
|||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Check if the host is enabling the audio interface (setting AlternateSetting to 1) */
|
||||
if (USB_ControlRequest.wValue)
|
||||
{
|
||||
/* Start audio task */
|
||||
Scheduler_SetTaskMode(USB_Audio_Task, TASK_RUN);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Stop audio task */
|
||||
Scheduler_SetTaskMode(USB_Audio_Task, TASK_STOP);
|
||||
}
|
||||
StreamingAudioInterfaceSelected = ((USB_ControlRequest.wValue) != 0);
|
||||
|
||||
/* Acknowledge status stage */
|
||||
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
|
||||
* 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 */
|
||||
Endpoint_SelectEndpoint(AUDIO_STREAM_EPNUM);
|
||||
|
||||
|
|
|
@ -43,10 +43,9 @@
|
|||
|
||||
#include "Descriptors.h"
|
||||
|
||||
#include <LUFA/Version.h> // Library Version Information
|
||||
#include <LUFA/Drivers/USB/USB.h> // USB Functionality
|
||||
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver
|
||||
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
|
||||
/* Macros: */
|
||||
#if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER)
|
||||
|
@ -96,24 +95,25 @@
|
|||
#define CSx0 CS10
|
||||
#endif
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the possible status codes for passing to the UpdateStatus() function. */
|
||||
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 */
|
||||
};
|
||||
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
|
||||
#define LEDMASK_USB_NOTREADY LEDS_LED1
|
||||
|
||||
/* Task Definitions: */
|
||||
TASK(USB_Audio_Task);
|
||||
/** 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)
|
||||
|
||||
/* Function Prototypes: */
|
||||
void SetupHardware(void);
|
||||
void USB_Audio_Task(void);
|
||||
|
||||
void EVENT_USB_Connect(void);
|
||||
void EVENT_USB_Disconnect(void);
|
||||
void EVENT_USB_ConfigurationChanged(void);
|
||||
void EVENT_USB_UnhandledControlPacket(void);
|
||||
|
||||
void UpdateStatus(uint8_t CurrentStatus);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -119,13 +119,12 @@ OBJDIR = .
|
|||
|
||||
|
||||
# Path to the LUFA library
|
||||
LUFA_PATH = ../../..
|
||||
LUFA_PATH = ../../../..
|
||||
|
||||
|
||||
# List C source files here. (C dependencies are automatically generated.)
|
||||
SRC = $(TARGET).c \
|
||||
Descriptors.c \
|
||||
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.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/USBTask.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.)
|
||||
|
|
|
@ -36,13 +36,6 @@
|
|||
|
||||
#include "CDC.h"
|
||||
|
||||
/* Scheduler Task List */
|
||||
TASK_LIST
|
||||
{
|
||||
{ .Task = USB_USBTask , .TaskStatus = TASK_STOP },
|
||||
{ .Task = CDC_Task , .TaskStatus = TASK_STOP },
|
||||
};
|
||||
|
||||
/* Globals: */
|
||||
/** 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
|
||||
|
@ -57,25 +50,24 @@ CDC_Line_Coding_t LineCoding = { .BaudRateBPS = 9600,
|
|||
.ParityType = Parity_None,
|
||||
.DataBits = 8 };
|
||||
|
||||
/** String to print through the virtual serial port when the joystick is pressed upwards. */
|
||||
char JoystickUpString[] = "Joystick Up\r\n";
|
||||
|
||||
/** String to print through the virtual serial port when the joystick is pressed downward. */
|
||||
char JoystickDownString[] = "Joystick Down\r\n";
|
||||
|
||||
/** 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. */
|
||||
char JoystickRightString[] = "Joystick Right\r\n";
|
||||
|
||||
/** String to print through the 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
|
||||
* starts the scheduler to run the application tasks.
|
||||
/** Main program entry point. This routine contains the overall program flow, including initial
|
||||
* setup of all components and the main program loop.
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
SetupHardware();
|
||||
|
||||
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 */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
|
@ -87,18 +79,7 @@ int main(void)
|
|||
/* Hardware Initialization */
|
||||
Joystick_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();
|
||||
|
||||
/* 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
|
||||
|
@ -106,11 +87,8 @@ int main(void)
|
|||
*/
|
||||
void EVENT_USB_Connect(void)
|
||||
{
|
||||
/* Start USB management task */
|
||||
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
|
||||
|
||||
/* 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
|
||||
|
@ -118,12 +96,8 @@ void EVENT_USB_Connect(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 */
|
||||
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
|
||||
|
@ -145,10 +119,7 @@ void EVENT_USB_ConfigurationChanged(void)
|
|||
ENDPOINT_BANK_SINGLE);
|
||||
|
||||
/* Indicate USB connected and ready */
|
||||
UpdateStatus(Status_USBReady);
|
||||
|
||||
/* Start CDC task */
|
||||
Scheduler_SetTaskMode(CDC_Task, TASK_RUN);
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific
|
||||
|
@ -210,39 +181,21 @@ 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. */
|
||||
TASK(CDC_Task)
|
||||
void CDC_Task(void)
|
||||
{
|
||||
char* ReportString = NULL;
|
||||
uint8_t JoyStatus_LCL = Joystick_GetStatus();
|
||||
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
|
||||
/* NOTE: Here you can use the notification endpoint to send back line state changes to the host, for the special RS-232
|
||||
|
@ -269,15 +222,15 @@ TASK(CDC_Task)
|
|||
|
||||
/* Determine if a joystick action has occurred */
|
||||
if (JoyStatus_LCL & JOY_UP)
|
||||
ReportString = JoystickUpString;
|
||||
ReportString = JoystickStrings[0];
|
||||
else if (JoyStatus_LCL & JOY_DOWN)
|
||||
ReportString = JoystickDownString;
|
||||
ReportString = JoystickStrings[1];
|
||||
else if (JoyStatus_LCL & JOY_LEFT)
|
||||
ReportString = JoystickLeftString;
|
||||
ReportString = JoystickStrings[2];
|
||||
else if (JoyStatus_LCL & JOY_RIGHT)
|
||||
ReportString = JoystickRightString;
|
||||
ReportString = JoystickStrings[3];
|
||||
else if (JoyStatus_LCL & JOY_PRESS)
|
||||
ReportString = JoystickPressedString;
|
||||
ReportString = JoystickStrings[4];
|
||||
|
||||
/* Flag management - Only allow one string to be sent per action */
|
||||
if (ReportString == NULL)
|
||||
|
|
|
@ -44,11 +44,10 @@
|
|||
|
||||
#include "Descriptors.h"
|
||||
|
||||
#include <LUFA/Version.h> // Library Version Information
|
||||
#include <LUFA/Drivers/USB/USB.h> // USB Functionality
|
||||
#include <LUFA/Drivers/Board/Joystick.h> // Joystick driver
|
||||
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver
|
||||
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/Board/Joystick.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
|
||||
/* Macros: */
|
||||
/** CDC Class specific request to get the current virtual serial port configuration settings. */
|
||||
|
@ -111,6 +110,18 @@
|
|||
*/
|
||||
#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 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.
|
||||
|
@ -159,19 +170,11 @@
|
|||
Parity_Mark = 3, /**< Mark 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: */
|
||||
void SetupHardware(void);
|
||||
void CDC_Task(void);
|
||||
|
||||
void EVENT_USB_Connect(void);
|
||||
void EVENT_USB_Disconnect(void);
|
||||
void EVENT_USB_ConfigurationChanged(void);
|
||||
|
|
|
@ -119,13 +119,12 @@ OBJDIR = .
|
|||
|
||||
|
||||
# Path to the LUFA library
|
||||
LUFA_PATH = ../../..
|
||||
LUFA_PATH = ../../../..
|
||||
|
||||
|
||||
# List C source files here. (C dependencies are automatically generated.)
|
||||
SRC = $(TARGET).c \
|
||||
Descriptors.c \
|
||||
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.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/USBTask.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.)
|
||||
|
|
|
@ -36,14 +36,6 @@
|
|||
|
||||
#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: */
|
||||
/** 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
|
||||
|
@ -70,26 +62,24 @@ CDC_Line_Coding_t LineCoding2 = { .BaudRateBPS = 9600,
|
|||
.CharFormat = OneStopBit,
|
||||
.ParityType = Parity_None,
|
||||
.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
|
||||
* starts the scheduler to run the application tasks.
|
||||
*/
|
||||
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 */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
|
@ -101,18 +91,7 @@ int main(void)
|
|||
/* Hardware Initialization */
|
||||
Joystick_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();
|
||||
|
||||
/* 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
|
||||
|
@ -120,11 +99,8 @@ int main(void)
|
|||
*/
|
||||
void EVENT_USB_Connect(void)
|
||||
{
|
||||
/* Start USB management task */
|
||||
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
|
||||
|
||||
/* 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
|
||||
|
@ -132,13 +108,8 @@ void EVENT_USB_Connect(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 */
|
||||
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
|
||||
|
@ -173,11 +144,7 @@ void EVENT_USB_ConfigurationChanged(void)
|
|||
ENDPOINT_BANK_SINGLE);
|
||||
|
||||
/* Indicate USB connected and ready */
|
||||
UpdateStatus(Status_USBReady);
|
||||
|
||||
/* Start CDC tasks */
|
||||
Scheduler_SetTaskMode(CDC1_Task, TASK_RUN);
|
||||
Scheduler_SetTaskMode(CDC2_Task, TASK_RUN);
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
}
|
||||
|
||||
/** 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
|
||||
* movements to the host as ASCII strings.
|
||||
*/
|
||||
TASK(CDC1_Task)
|
||||
void CDC1_Task(void)
|
||||
{
|
||||
char* ReportString = NULL;
|
||||
uint8_t JoyStatus_LCL = Joystick_GetStatus();
|
||||
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 */
|
||||
if (JoyStatus_LCL & JOY_UP)
|
||||
ReportString = JoystickUpString;
|
||||
ReportString = JoystickStrings[0];
|
||||
else if (JoyStatus_LCL & JOY_DOWN)
|
||||
ReportString = JoystickDownString;
|
||||
ReportString = JoystickStrings[1];
|
||||
else if (JoyStatus_LCL & JOY_LEFT)
|
||||
ReportString = JoystickLeftString;
|
||||
ReportString = JoystickStrings[2];
|
||||
else if (JoyStatus_LCL & JOY_RIGHT)
|
||||
ReportString = JoystickRightString;
|
||||
ReportString = JoystickStrings[3];
|
||||
else if (JoyStatus_LCL & JOY_PRESS)
|
||||
ReportString = JoystickPressedString;
|
||||
ReportString = JoystickStrings[4];
|
||||
|
||||
/* Flag management - Only allow one string to be sent per action */
|
||||
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
|
||||
* all data sent to it from the host.
|
||||
*/
|
||||
TASK(CDC2_Task)
|
||||
void CDC2_Task(void)
|
||||
{
|
||||
/* Select the Serial Rx Endpoint */
|
||||
Endpoint_SelectEndpoint(CDC2_RX_EPNUM);
|
||||
|
|
|
@ -44,11 +44,10 @@
|
|||
|
||||
#include "Descriptors.h"
|
||||
|
||||
#include <LUFA/Version.h> // Library Version Information
|
||||
#include <LUFA/Drivers/USB/USB.h> // USB Functionality
|
||||
#include <LUFA/Drivers/Board/Joystick.h> // Joystick driver
|
||||
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver
|
||||
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/Board/Joystick.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
|
||||
/* Macros: */
|
||||
/** 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. */
|
||||
#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 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.
|
||||
|
@ -95,24 +106,14 @@
|
|||
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: */
|
||||
void CDC1_Task(void);
|
||||
void CDC2_Task(void);
|
||||
void SetupHardware(void);
|
||||
|
||||
void EVENT_USB_Connect(void);
|
||||
void EVENT_USB_Disconnect(void);
|
||||
void EVENT_USB_ConfigurationChanged(void);
|
||||
void EVENT_USB_UnhandledControlPacket(void);
|
||||
|
||||
void UpdateStatus(uint8_t CurrentStatus);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -119,13 +119,12 @@ OBJDIR = .
|
|||
|
||||
|
||||
# Path to the LUFA library
|
||||
LUFA_PATH = ../../..
|
||||
LUFA_PATH = ../../../..
|
||||
|
||||
|
||||
# List C source files here. (C dependencies are automatically generated.)
|
||||
SRC = $(TARGET).c \
|
||||
Descriptors.c \
|
||||
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.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/USBTask.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.)
|
||||
|
|
|
@ -36,13 +36,6 @@
|
|||
|
||||
#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 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.
|
||||
*/
|
||||
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 */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
|
@ -61,18 +68,7 @@ int main(void)
|
|||
|
||||
/* Hardware Initialization */
|
||||
LEDs_Init();
|
||||
|
||||
/* 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
|
||||
|
@ -80,11 +76,8 @@ int main(void)
|
|||
*/
|
||||
void EVENT_USB_Connect(void)
|
||||
{
|
||||
/* Start USB management task */
|
||||
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
|
||||
|
||||
/* 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
|
||||
|
@ -92,12 +85,8 @@ void EVENT_USB_Connect(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 */
|
||||
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
|
||||
|
@ -116,7 +105,7 @@ void EVENT_USB_ConfigurationChanged(void)
|
|||
ENDPOINT_BANK_SINGLE);
|
||||
|
||||
/* 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
|
||||
|
@ -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.
|
||||
*
|
||||
* \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];
|
||||
}
|
||||
|
||||
TASK(USB_HID_Report)
|
||||
void HID_Task(void)
|
||||
{
|
||||
/* Check if the USB system is connected to a host */
|
||||
if (USB_IsConnected)
|
||||
|
|
|
@ -46,10 +46,9 @@
|
|||
|
||||
#include "Descriptors.h"
|
||||
|
||||
#include <LUFA/Version.h> // Library Version Information
|
||||
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
|
||||
#include <LUFA/Drivers/USB/USB.h> // USB Functionality
|
||||
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
|
||||
/* Macros: */
|
||||
/** 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. */
|
||||
#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: */
|
||||
/** Enum for the possible status codes for passing to the UpdateStatus() function. */
|
||||
enum GenericHID_StatusCodes_t
|
||||
|
@ -67,16 +78,15 @@
|
|||
Status_USBReady = 2, /**< USB interface is connected and ready */
|
||||
};
|
||||
|
||||
/* Task Definitions: */
|
||||
TASK(USB_HID_Report);
|
||||
|
||||
/* Function Prototypes: */
|
||||
void SetupHardware(void);
|
||||
void HID_Task(void);
|
||||
|
||||
void EVENT_USB_Connect(void);
|
||||
void EVENT_USB_Disconnect(void);
|
||||
void EVENT_USB_ConfigurationChanged(void);
|
||||
void EVENT_USB_UnhandledControlPacket(void);
|
||||
|
||||
void UpdateStatus(uint8_t CurrentStatus);
|
||||
void ProcessGenericHIDReport(uint8_t* DataArray);
|
||||
void CreateGenericHIDReport(uint8_t* DataArray);
|
||||
|
||||
|
|
|
@ -119,13 +119,12 @@ OBJDIR = .
|
|||
|
||||
|
||||
# Path to the LUFA library
|
||||
LUFA_PATH = ../../..
|
||||
LUFA_PATH = ../../../..
|
||||
|
||||
|
||||
# List C source files here. (C dependencies are automatically generated.)
|
||||
SRC = $(TARGET).c \
|
||||
Descriptors.c \
|
||||
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.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/USBTask.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.)
|
||||
|
|
|
@ -36,17 +36,24 @@
|
|||
|
||||
#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
|
||||
* starts the scheduler to run the application tasks.
|
||||
*/
|
||||
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 */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
|
@ -59,18 +66,7 @@ int main(void)
|
|||
Joystick_Init();
|
||||
LEDs_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();
|
||||
|
||||
/* 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
|
||||
|
@ -78,11 +74,8 @@ int main(void)
|
|||
*/
|
||||
void EVENT_USB_Connect(void)
|
||||
{
|
||||
/* Start USB management task */
|
||||
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
|
||||
|
||||
/* 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
|
||||
|
@ -90,12 +83,8 @@ void EVENT_USB_Connect(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 */
|
||||
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
|
||||
|
@ -109,10 +98,7 @@ void EVENT_USB_ConfigurationChanged(void)
|
|||
ENDPOINT_BANK_SINGLE);
|
||||
|
||||
/* Indicate USB connected and ready */
|
||||
UpdateStatus(Status_USBReady);
|
||||
|
||||
/* Start joystick reporting task */
|
||||
Scheduler_SetTaskMode(USB_Joystick_Report, TASK_RUN);
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
}
|
||||
|
||||
/** 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;
|
||||
}
|
||||
|
||||
/** 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. */
|
||||
TASK(USB_Joystick_Report)
|
||||
void HID_Task(void)
|
||||
{
|
||||
/* Check if the USB System is connected to a Host */
|
||||
if (USB_IsConnected)
|
||||
|
|
|
@ -44,20 +44,28 @@
|
|||
|
||||
#include "Descriptors.h"
|
||||
|
||||
#include <LUFA/Version.h> // Library Version Information
|
||||
#include <LUFA/Drivers/USB/USB.h> // USB Functionality
|
||||
#include <LUFA/Drivers/Board/Joystick.h> // Joystick driver
|
||||
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver
|
||||
#include <LUFA/Drivers/Board/Buttons.h> // Board Buttons driver
|
||||
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
|
||||
|
||||
/* Task Definitions: */
|
||||
TASK(USB_Joystick_Report);
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/Board/Joystick.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
#include <LUFA/Drivers/Board/Buttons.h>
|
||||
|
||||
/* Macros: */
|
||||
/** HID Class specific request to get the next HID report from the device. */
|
||||
#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 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.
|
||||
|
@ -68,23 +76,16 @@
|
|||
int8_t Y; /**< Current absolute joystick Y position, as a signed 8-bit integer */
|
||||
uint8_t Button; /**< Bit mask of the currently pressed joystick buttons */
|
||||
} 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: */
|
||||
void SetupHardware(void);
|
||||
void HID_Task(void);
|
||||
|
||||
void EVENT_USB_Connect(void);
|
||||
void EVENT_USB_Disconnect(void);
|
||||
void EVENT_USB_ConfigurationChanged(void);
|
||||
void EVENT_USB_UnhandledControlPacket(void);
|
||||
|
||||
bool GetNextReport(USB_JoystickReport_Data_t* ReportData);
|
||||
void UpdateStatus(uint8_t CurrentStatus);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -119,13 +119,12 @@ OBJDIR = .
|
|||
|
||||
|
||||
# Path to the LUFA library
|
||||
LUFA_PATH = ../../..
|
||||
LUFA_PATH = ../../../..
|
||||
|
||||
|
||||
# List C source files here. (C dependencies are automatically generated.)
|
||||
SRC = $(TARGET).c \
|
||||
Descriptors.c \
|
||||
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.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/USBTask.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.)
|
||||
|
|
|
@ -37,13 +37,6 @@
|
|||
|
||||
#include "Keyboard.h"
|
||||
|
||||
/* Scheduler Task List */
|
||||
TASK_LIST
|
||||
{
|
||||
{ .Task = USB_USBTask , .TaskStatus = TASK_STOP },
|
||||
{ .Task = USB_Keyboard_Report , .TaskStatus = TASK_STOP },
|
||||
};
|
||||
|
||||
/* Global Variables */
|
||||
/** Indicates what report mode the host has requested, true for normal HID reporting mode, false for special boot
|
||||
* protocol reporting mode.
|
||||
|
@ -66,6 +59,20 @@ uint16_t IdleMSRemaining = 0;
|
|||
* starts the scheduler to run the USB management task.
|
||||
*/
|
||||
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 */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
|
@ -77,24 +84,13 @@ int main(void)
|
|||
/* Hardware Initialization */
|
||||
Joystick_Init();
|
||||
LEDs_Init();
|
||||
USB_Init();
|
||||
|
||||
/* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */
|
||||
OCR0A = 0x7D;
|
||||
TCCR0A = (1 << WGM01);
|
||||
TCCR0B = ((1 << CS01) | (1 << CS00));
|
||||
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
|
||||
|
@ -102,11 +98,8 @@ int main(void)
|
|||
*/
|
||||
void EVENT_USB_Connect(void)
|
||||
{
|
||||
/* Start USB management task */
|
||||
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
|
||||
|
||||
/* Indicate USB enumerating */
|
||||
UpdateStatus(Status_USBEnumerating);
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
|
||||
|
||||
/* Default to report protocol on connect */
|
||||
UsingReportProtocol = true;
|
||||
|
@ -117,12 +110,8 @@ void EVENT_USB_Connect(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 */
|
||||
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
|
||||
|
@ -141,10 +130,7 @@ void EVENT_USB_ConfigurationChanged(void)
|
|||
ENDPOINT_BANK_SINGLE);
|
||||
|
||||
/* Indicate USB connected and ready */
|
||||
UpdateStatus(Status_USBReady);
|
||||
|
||||
/* Start running keyboard reporting task */
|
||||
Scheduler_SetTaskMode(USB_Keyboard_Report, TASK_RUN);
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
}
|
||||
|
||||
/** 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. */
|
||||
TASK(USB_Keyboard_Report)
|
||||
void HID_Task(void)
|
||||
{
|
||||
/* Check if the USB system is connected to a host */
|
||||
if (USB_IsConnected)
|
||||
|
|
|
@ -47,11 +47,10 @@
|
|||
|
||||
#include "Descriptors.h"
|
||||
|
||||
#include <LUFA/Version.h> // Library Version Information
|
||||
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
|
||||
#include <LUFA/Drivers/USB/USB.h> // USB Functionality
|
||||
#include <LUFA/Drivers/Board/Joystick.h> // Joystick driver
|
||||
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/Board/Joystick.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
|
||||
/* Macros: */
|
||||
/** Idle period indicating that reports should be sent only when the inputs have changed */
|
||||
|
@ -74,9 +73,18 @@
|
|||
|
||||
/** HID Class specific request to set the current HID protocol in use, either report or boot. */
|
||||
#define REQ_SetProtocol 0x0B
|
||||
|
||||
/* Task Definitions: */
|
||||
TASK(USB_Keyboard_Report);
|
||||
|
||||
/** 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 define for the keyboard HID report structure, for creating and sending HID reports to the host PC.
|
||||
|
@ -88,17 +96,11 @@
|
|||
uint8_t Reserved; /**< Reserved, always set as 0x00 */
|
||||
uint8_t KeyCode[6]; /**< Array of up to six simultaneous key codes of pressed keys */
|
||||
} 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: */
|
||||
void SetupHardware(void);
|
||||
void HID_Task(void);
|
||||
|
||||
void EVENT_USB_Connect(void);
|
||||
void EVENT_USB_Disconnect(void);
|
||||
void EVENT_USB_ConfigurationChanged(void);
|
||||
|
@ -108,6 +110,5 @@
|
|||
void ProcessLEDReport(uint8_t LEDReport);
|
||||
void SendNextReport(void);
|
||||
void ReceiveNextReport(void);
|
||||
void UpdateStatus(uint8_t CurrentStatus);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -119,13 +119,12 @@ OBJDIR = .
|
|||
|
||||
|
||||
# Path to the LUFA library
|
||||
LUFA_PATH = ../../..
|
||||
LUFA_PATH = ../../../..
|
||||
|
||||
|
||||
# List C source files here. (C dependencies are automatically generated.)
|
||||
SRC = $(TARGET).c \
|
||||
Descriptors.c \
|
||||
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.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/USBTask.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.)
|
||||
|
|
|
@ -37,14 +37,6 @@
|
|||
|
||||
#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 structure to hold the current keyboard interface HID report, for transmission to the host */
|
||||
USB_KeyboardReport_Data_t KeyboardReportData;
|
||||
|
@ -56,6 +48,21 @@ USB_MouseReport_Data_t MouseReportData;
|
|||
* starts the scheduler to run the USB management task.
|
||||
*/
|
||||
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 */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
|
@ -67,18 +74,7 @@ int main(void)
|
|||
/* Hardware Initialization */
|
||||
Joystick_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();
|
||||
|
||||
/* 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
|
||||
|
@ -86,11 +82,8 @@ int main(void)
|
|||
*/
|
||||
void EVENT_USB_Connect(void)
|
||||
{
|
||||
/* Start USB management task */
|
||||
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
|
||||
|
||||
/* 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
|
||||
|
@ -98,11 +91,8 @@ void EVENT_USB_Connect(void)
|
|||
*/
|
||||
void EVENT_USB_Disconnect(void)
|
||||
{
|
||||
/* Stop running HID reporting and USB management tasks */
|
||||
Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);
|
||||
|
||||
/* 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
|
||||
|
@ -126,7 +116,7 @@ void EVENT_USB_ConfigurationChanged(void)
|
|||
ENDPOINT_BANK_SINGLE);
|
||||
|
||||
/* 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
|
||||
|
@ -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 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.
|
||||
*/
|
||||
TASK(USB_Keyboard)
|
||||
void Keyboard_HID_Task(void)
|
||||
{
|
||||
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 IN endpoint when the host is ready for more data.
|
||||
*/
|
||||
TASK(USB_Mouse)
|
||||
void Mouse_HID_Task(void)
|
||||
{
|
||||
uint8_t JoyStatus_LCL = Joystick_GetStatus();
|
||||
|
||||
|
|
|
@ -41,25 +41,11 @@
|
|||
|
||||
#include "Descriptors.h"
|
||||
|
||||
#include <LUFA/Version.h> // Library Version Information
|
||||
#include <LUFA/Drivers/USB/USB.h> // USB Functionality
|
||||
#include <LUFA/Drivers/Board/Joystick.h> // Joystick driver
|
||||
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver
|
||||
#include <LUFA/Drivers/Board/Buttons.h> // Board Buttons driver
|
||||
#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 */
|
||||
};
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/Board/Joystick.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
#include <LUFA/Drivers/Board/Buttons.h>
|
||||
|
||||
/* Macros: */
|
||||
/** HID Class specific request to get the next HID report from the device. */
|
||||
|
@ -73,6 +59,18 @@
|
|||
|
||||
/** HID Class specific request to set the current HID protocol in use, either report or boot. */
|
||||
#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 define for the keyboard HID report structure, for creating and sending HID reports to the host PC.
|
||||
|
@ -96,11 +94,13 @@
|
|||
} USB_MouseReport_Data_t;
|
||||
|
||||
/* Function Prototypes: */
|
||||
void SetupHardware(void);
|
||||
void Keyboard_HID_Task(void);
|
||||
void Mouse_HID_Task(void);
|
||||
|
||||
void EVENT_USB_Connect(void);
|
||||
void EVENT_USB_Disconnect(void);
|
||||
void EVENT_USB_ConfigurationChanged(void);
|
||||
void EVENT_USB_UnhandledControlPacket(void);
|
||||
|
||||
void UpdateStatus(uint8_t CurrentStatus);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -119,13 +119,12 @@ OBJDIR = .
|
|||
|
||||
|
||||
# Path to the LUFA library
|
||||
LUFA_PATH = ../../..
|
||||
LUFA_PATH = ../../../..
|
||||
|
||||
|
||||
# List C source files here. (C dependencies are automatically generated.)
|
||||
SRC = $(TARGET).c \
|
||||
Descriptors.c \
|
||||
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.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/USBTask.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.)
|
||||
|
|
|
@ -36,17 +36,24 @@
|
|||
|
||||
#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
|
||||
* starts the scheduler to run the application tasks.
|
||||
*/
|
||||
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 */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
|
@ -59,28 +66,14 @@ int main(void)
|
|||
Joystick_Init();
|
||||
LEDs_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();
|
||||
|
||||
/* 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. */
|
||||
void EVENT_USB_Connect(void)
|
||||
{
|
||||
/* Start USB management task */
|
||||
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
|
||||
|
||||
/* 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
|
||||
|
@ -88,12 +81,8 @@ void EVENT_USB_Connect(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 */
|
||||
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
|
||||
|
@ -111,16 +100,13 @@ void EVENT_USB_ConfigurationChanged(void)
|
|||
ENDPOINT_BANK_SINGLE);
|
||||
|
||||
/* Indicate USB connected and ready */
|
||||
UpdateStatus(Status_USBReady);
|
||||
|
||||
/* Start MIDI task */
|
||||
Scheduler_SetTaskMode(USB_MIDI_Task, TASK_RUN);
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
}
|
||||
|
||||
/** Task to handle the generation of MIDI note change events in response to presses of the board joystick, and send them
|
||||
* to the host.
|
||||
*/
|
||||
TASK(USB_MIDI_Task)
|
||||
void MIDI_Task(void)
|
||||
{
|
||||
static uint8_t PrevJoystickStatus;
|
||||
|
||||
|
@ -164,33 +150,6 @@ TASK(USB_MIDI_Task)
|
|||
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.
|
||||
*
|
||||
* \param Pitch Pitch of the note to turn on or off
|
||||
|
|
|
@ -44,12 +44,11 @@
|
|||
|
||||
#include "Descriptors.h"
|
||||
|
||||
#include <LUFA/Version.h> // Library Version Information
|
||||
#include <LUFA/Drivers/USB/USB.h> // USB Functionality
|
||||
#include <LUFA/Drivers/Board/Joystick.h> // Joystick driver
|
||||
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver
|
||||
#include <LUFA/Drivers/Board/Buttons.h> // Board Buttons driver
|
||||
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/Board/Joystick.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
#include <LUFA/Drivers/Board/Buttons.h>
|
||||
|
||||
/* Macros: */
|
||||
/** MIDI command for a note on (activation) event */
|
||||
|
@ -68,19 +67,22 @@
|
|||
*/
|
||||
#define MIDI_CHANNEL(channel) (channel - 1)
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the possible status codes for passing to the UpdateStatus() function. */
|
||||
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 */
|
||||
};
|
||||
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
|
||||
#define LEDMASK_USB_NOTREADY LEDS_LED1
|
||||
|
||||
/* Task Definitions: */
|
||||
TASK(USB_MIDI_Task);
|
||||
/** 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)
|
||||
|
||||
/* Function Prototypes: */
|
||||
void SetupHardware(void);
|
||||
void MIDI_Task(void);
|
||||
|
||||
void EVENT_USB_Connect(void);
|
||||
void EVENT_USB_Disconnect(void);
|
||||
void EVENT_USB_ConfigurationChanged(void);
|
||||
|
|
|
@ -119,13 +119,12 @@ OBJDIR = .
|
|||
|
||||
|
||||
# Path to the LUFA library
|
||||
LUFA_PATH = ../../..
|
||||
LUFA_PATH = ../../../..
|
||||
|
||||
|
||||
# List C source files here. (C dependencies are automatically generated.)
|
||||
SRC = $(TARGET).c \
|
||||
Descriptors.c \
|
||||
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.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/USBTask.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.)
|
||||
|
|
|
@ -37,12 +37,6 @@
|
|||
#define INCLUDE_FROM_MASSSTORAGE_C
|
||||
#include "MassStorage.h"
|
||||
|
||||
/* Scheduler Task List */
|
||||
TASK_LIST
|
||||
{
|
||||
{ .Task = USB_MassStorage , .TaskStatus = TASK_STOP },
|
||||
};
|
||||
|
||||
/* Global Variables */
|
||||
/** Structure to hold the latest Command Block Wrapper issued by the host, containing a SCSI command to execute. */
|
||||
CommandBlockWrapper_t CommandBlock;
|
||||
|
@ -57,6 +51,20 @@ volatile bool IsMassStoreReset = false;
|
|||
* starts the scheduler to run the application tasks.
|
||||
*/
|
||||
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 */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
|
@ -68,28 +76,17 @@ int main(void)
|
|||
/* Hardware Initialization */
|
||||
LEDs_Init();
|
||||
Dataflash_Init(SPI_SPEED_FCPU_DIV_2);
|
||||
USB_Init();
|
||||
|
||||
/* Clear Dataflash sector protections, if enabled */
|
||||
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. */
|
||||
void EVENT_USB_Connect(void)
|
||||
{
|
||||
/* Indicate USB enumerating */
|
||||
UpdateStatus(Status_USBEnumerating);
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
|
||||
|
||||
/* Reset the MSReset flag upon connection */
|
||||
IsMassStoreReset = false;
|
||||
|
@ -100,11 +97,8 @@ void EVENT_USB_Connect(void)
|
|||
*/
|
||||
void EVENT_USB_Disconnect(void)
|
||||
{
|
||||
/* Stop running mass storage task */
|
||||
Scheduler_SetTaskMode(USB_MassStorage, TASK_STOP);
|
||||
|
||||
/* 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
|
||||
|
@ -122,10 +116,7 @@ void EVENT_USB_ConfigurationChanged(void)
|
|||
ENDPOINT_BANK_DOUBLE);
|
||||
|
||||
/* Indicate USB connected and ready */
|
||||
UpdateStatus(Status_USBReady);
|
||||
|
||||
/* Start mass storage task */
|
||||
Scheduler_SetTaskMode(USB_MassStorage, TASK_RUN);
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
}
|
||||
|
||||
/** 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
|
||||
* 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 */
|
||||
if (USB_IsConnected)
|
||||
|
@ -216,9 +174,9 @@ TASK(USB_MassStorage)
|
|||
|
||||
/* Check to see if a command from the host has been issued */
|
||||
if (Endpoint_IsReadWriteAllowed())
|
||||
{
|
||||
{
|
||||
/* Indicate busy */
|
||||
UpdateStatus(Status_ProcessingCommandBlock);
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
|
||||
|
||||
/* Process sent command block from the host */
|
||||
if (ReadInCommandBlock())
|
||||
|
@ -260,12 +218,12 @@ TASK(USB_MassStorage)
|
|||
}
|
||||
|
||||
/* Indicate ready */
|
||||
UpdateStatus(Status_USBReady);
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 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/DataflashManager.h"
|
||||
|
||||
#include <LUFA/Version.h> // Library Version Information
|
||||
#include <LUFA/Drivers/USB/USB.h> // USB Functionality
|
||||
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver
|
||||
#include <LUFA/Drivers/Board/Dataflash.h> // Dataflash chip driver
|
||||
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
#include <LUFA/Drivers/Board/Dataflash.h>
|
||||
|
||||
/* Macros: */
|
||||
/** 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. */
|
||||
#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 define for a Command Block Wrapper, used in the Mass Storage Bulk-Only Transport protocol. */
|
||||
typedef struct
|
||||
|
@ -112,33 +126,21 @@
|
|||
Command_Fail = 1, /**< Command failed to complete - host may check the exact error via a SCSI REQUEST SENSE command */
|
||||
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: */
|
||||
extern CommandBlockWrapper_t CommandBlock;
|
||||
extern CommandStatusWrapper_t CommandStatus;
|
||||
extern volatile bool IsMassStoreReset;
|
||||
|
||||
/* Task Definitions: */
|
||||
TASK(USB_MassStorage);
|
||||
|
||||
/* Function Prototypes: */
|
||||
void SetupHardware(void);
|
||||
void MassStorage_Task(void);
|
||||
|
||||
void EVENT_USB_Connect(void);
|
||||
void EVENT_USB_Disconnect(void);
|
||||
void EVENT_USB_ConfigurationChanged(void);
|
||||
void EVENT_USB_UnhandledControlPacket(void);
|
||||
|
||||
void UpdateStatus(uint8_t CurrentStatus);
|
||||
|
||||
#if defined(INCLUDE_FROM_MASSSTORAGE_C)
|
||||
static bool ReadInCommandBlock(void);
|
||||
static void ReturnCommandStatus(void);
|
||||
|
|
|
@ -119,7 +119,7 @@ OBJDIR = .
|
|||
|
||||
|
||||
# Path to the LUFA library
|
||||
LUFA_PATH = ../../..
|
||||
LUFA_PATH = ../../../..
|
||||
|
||||
|
||||
# List C source files here. (C dependencies are automatically generated.)
|
||||
|
@ -127,7 +127,6 @@ SRC = $(TARGET).c \
|
|||
Descriptors.c \
|
||||
Lib/SCSI.c \
|
||||
Lib/DataflashManager.c \
|
||||
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.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/USBTask.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.)
|
||||
|
|
|
@ -36,13 +36,6 @@
|
|||
|
||||
#include "Mouse.h"
|
||||
|
||||
/* Scheduler Task List */
|
||||
TASK_LIST
|
||||
{
|
||||
{ .Task = USB_USBTask , .TaskStatus = TASK_STOP },
|
||||
{ .Task = USB_Mouse_Report , .TaskStatus = TASK_STOP },
|
||||
};
|
||||
|
||||
/* Global Variables */
|
||||
/** Indicates what report mode the host has requested, true for normal HID reporting mode, false for special boot
|
||||
* protocol reporting mode.
|
||||
|
@ -65,6 +58,20 @@ uint16_t IdleMSRemaining = 0;
|
|||
* starts the scheduler to run the application tasks.
|
||||
*/
|
||||
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 */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
|
@ -77,24 +84,13 @@ int main(void)
|
|||
Joystick_Init();
|
||||
LEDs_Init();
|
||||
Buttons_Init();
|
||||
USB_Init();
|
||||
|
||||
/* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */
|
||||
OCR0A = 0x7D;
|
||||
TCCR0A = (1 << WGM01);
|
||||
TCCR0B = ((1 << CS01) | (1 << CS00));
|
||||
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
|
||||
|
@ -102,11 +98,8 @@ int main(void)
|
|||
*/
|
||||
void EVENT_USB_Connect(void)
|
||||
{
|
||||
/* Start USB management task */
|
||||
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
|
||||
|
||||
/* Indicate USB enumerating */
|
||||
UpdateStatus(Status_USBEnumerating);
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
|
||||
|
||||
/* Default to report protocol on connect */
|
||||
UsingReportProtocol = true;
|
||||
|
@ -117,12 +110,8 @@ void EVENT_USB_Connect(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 */
|
||||
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
|
||||
|
@ -136,10 +125,7 @@ void EVENT_USB_ConfigurationChanged(void)
|
|||
ENDPOINT_BANK_SINGLE);
|
||||
|
||||
/* Indicate USB connected and ready */
|
||||
UpdateStatus(Status_USBReady);
|
||||
|
||||
/* Start running mouse reporting task */
|
||||
Scheduler_SetTaskMode(USB_Mouse_Report, TASK_RUN);
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
}
|
||||
|
||||
/** 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(USB_Mouse_Report)
|
||||
void Mouse_Task(void)
|
||||
{
|
||||
/* Check if the USB system is connected to a host */
|
||||
if (USB_IsConnected)
|
||||
|
|
|
@ -46,15 +46,11 @@
|
|||
|
||||
#include "Descriptors.h"
|
||||
|
||||
#include <LUFA/Version.h> // Library Version Information
|
||||
#include <LUFA/Drivers/USB/USB.h> // USB Functionality
|
||||
#include <LUFA/Drivers/Board/Joystick.h> // Joystick driver
|
||||
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver
|
||||
#include <LUFA/Drivers/Board/Buttons.h> // Board Buttons driver
|
||||
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
|
||||
|
||||
/* Task Definitions: */
|
||||
TASK(USB_Mouse_Report);
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/Board/Joystick.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
#include <LUFA/Drivers/Board/Buttons.h>
|
||||
|
||||
/* Macros: */
|
||||
/** 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. */
|
||||
#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 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.
|
||||
|
@ -88,17 +96,11 @@
|
|||
int8_t X; /**< Current mouse delta X 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;
|
||||
|
||||
/* 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: */
|
||||
void SetupHardware(void);
|
||||
void Mouse_Task(void);
|
||||
|
||||
void EVENT_USB_Connect(void);
|
||||
void EVENT_USB_Disconnect(void);
|
||||
void EVENT_USB_ConfigurationChanged(void);
|
||||
|
|
|
@ -119,13 +119,12 @@ OBJDIR = .
|
|||
|
||||
|
||||
# Path to the LUFA library
|
||||
LUFA_PATH = ../../..
|
||||
LUFA_PATH = ../../../..
|
||||
|
||||
|
||||
# List C source files here. (C dependencies are automatically generated.)
|
||||
SRC = $(TARGET).c \
|
||||
Descriptors.c \
|
||||
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.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/USBTask.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.)
|
||||
CPPSRC =
|
||||
|
|
|
@ -38,9 +38,7 @@
|
|||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <LUFA/Scheduler/Scheduler.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "EthernetProtocols.h"
|
||||
#include "Ethernet.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
|
||||
* buffer for later transmission.
|
||||
*/
|
||||
TASK(TCP_Task)
|
||||
void TCP_Task(void)
|
||||
{
|
||||
/* Task to hand off TCP packets to and from the listening applications. */
|
||||
|
||||
|
|
|
@ -38,9 +38,7 @@
|
|||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <LUFA/Scheduler/Scheduler.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "EthernetProtocols.h"
|
||||
#include "Ethernet.h"
|
||||
|
@ -230,14 +228,12 @@
|
|||
uint16_t UrgentPointer; /**< Urgent data pointer */
|
||||
} TCP_Header_t;
|
||||
|
||||
/* Tasks: */
|
||||
TASK(TCP_Task);
|
||||
|
||||
/* External Variables: */
|
||||
TCP_PortState_t PortStateTable[MAX_OPEN_TCP_PORTS];
|
||||
|
||||
/* Function Prototypes: */
|
||||
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*));
|
||||
uint8_t TCP_GetPortState(uint16_t Port);
|
||||
bool TCP_SetConnectionState(uint16_t Port, IP_Address_t RemoteAddress, uint16_t RemotePort, uint8_t State);
|
||||
|
|
|
@ -36,19 +36,32 @@
|
|||
|
||||
#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
|
||||
* starts the scheduler to run the USB management task.
|
||||
*/
|
||||
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 */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
|
@ -60,24 +73,7 @@ int main(void)
|
|||
/* Hardware Initialization */
|
||||
LEDs_Init();
|
||||
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();
|
||||
|
||||
/* 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
|
||||
|
@ -85,11 +81,8 @@ int main(void)
|
|||
*/
|
||||
void EVENT_USB_Connect(void)
|
||||
{
|
||||
/* Start USB management task */
|
||||
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
|
||||
|
||||
/* 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
|
||||
|
@ -97,14 +90,8 @@ void EVENT_USB_Connect(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 */
|
||||
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
|
||||
|
@ -126,12 +113,7 @@ void EVENT_USB_ConfigurationChanged(void)
|
|||
ENDPOINT_BANK_SINGLE);
|
||||
|
||||
/* Indicate USB connected and ready */
|
||||
UpdateStatus(Status_USBReady);
|
||||
|
||||
/* Start TCP/IP tasks */
|
||||
Scheduler_SetTaskMode(RNDIS_Task, TASK_RUN);
|
||||
Scheduler_SetTaskMode(Ethernet_Task, TASK_RUN);
|
||||
Scheduler_SetTaskMode(TCP_Task, TASK_RUN);
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
}
|
||||
|
||||
/** 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
|
||||
* 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.
|
||||
*/
|
||||
TASK(RNDIS_Task)
|
||||
void RNDIS_Task(void)
|
||||
{
|
||||
/* Select the notification endpoint */
|
||||
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
|
||||
* 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
|
||||
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)
|
||||
{
|
||||
/* 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 */
|
||||
Ethernet_ProcessPacket();
|
||||
|
||||
/* Indicate packet processing complete */
|
||||
UpdateStatus(Status_USBReady);
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,16 +52,30 @@
|
|||
#include "Lib/ARP.h"
|
||||
#include "Lib/Webserver.h"
|
||||
|
||||
#include <LUFA/Version.h> // Library Version Information
|
||||
#include <LUFA/Drivers/USB/USB.h> // USB Functionality
|
||||
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver
|
||||
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
|
||||
#include <LUFA/Drivers/Peripheral/SerialStream.h> // Serial stream driver
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
#include <LUFA/Drivers/Peripheral/SerialStream.h>
|
||||
|
||||
/* Macros: */
|
||||
/** 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 define for a RNDIS notification message, for transmission to the RNDIS host via the notification
|
||||
* Endpoint.
|
||||
|
@ -74,27 +88,15 @@
|
|||
uint16_t wIndex; /**< Two byte notification index parameter */
|
||||
uint16_t wLength; /**< Size of data payload following the notification header */
|
||||
} 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: */
|
||||
void SetupHardware(void);
|
||||
void RNDIS_Task(void);
|
||||
void Ethernet_Task(void);
|
||||
|
||||
void EVENT_USB_Connect(void);
|
||||
void EVENT_USB_Disconnect(void);
|
||||
void EVENT_USB_ConfigurationChanged(void);
|
||||
void EVENT_USB_UnhandledControlPacket(void);
|
||||
|
||||
void UpdateStatus(uint8_t CurrentStatus);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -119,7 +119,7 @@ OBJDIR = .
|
|||
|
||||
|
||||
# Path to the LUFA library
|
||||
LUFA_PATH = ../../..
|
||||
LUFA_PATH = ../../../..
|
||||
|
||||
|
||||
# List C source files here. (C dependencies are automatically generated.)
|
||||
|
@ -135,7 +135,6 @@ SRC = $(TARGET).c \
|
|||
Lib/ARP.c \
|
||||
Lib/IP.c \
|
||||
Lib/Webserver.c \
|
||||
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/Peripheral/Serial.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/USBTask.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.)
|
||||
|
|
|
@ -30,13 +30,6 @@
|
|||
|
||||
#include "USBtoSerial.h"
|
||||
|
||||
/* Scheduler Task List */
|
||||
TASK_LIST
|
||||
{
|
||||
{ .Task = USB_USBTask , .TaskStatus = TASK_STOP },
|
||||
{ .Task = CDC_Task , .TaskStatus = TASK_STOP },
|
||||
};
|
||||
|
||||
/* Globals: */
|
||||
/** 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.
|
||||
*/
|
||||
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 */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
|
@ -72,22 +83,7 @@ int main(void)
|
|||
/* Hardware Initialization */
|
||||
LEDs_Init();
|
||||
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();
|
||||
|
||||
/* Scheduling - routine never returns, so put this last in the main function */
|
||||
Scheduler_Start();
|
||||
USB_Init();
|
||||
}
|
||||
|
||||
/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and
|
||||
|
@ -95,28 +91,21 @@ int main(void)
|
|||
*/
|
||||
void EVENT_USB_Connect(void)
|
||||
{
|
||||
/* Start USB management task */
|
||||
Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);
|
||||
|
||||
/* 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
|
||||
* the status LEDs and stops the USB management and CDC management tasks.
|
||||
*/
|
||||
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 */
|
||||
Buffer_Initialize(&Rx_Buffer);
|
||||
Buffer_Initialize(&Tx_Buffer);
|
||||
|
||||
/* 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
|
||||
|
@ -138,10 +127,7 @@ void EVENT_USB_ConfigurationChanged(void)
|
|||
ENDPOINT_BANK_SINGLE);
|
||||
|
||||
/* Indicate USB connected and ready */
|
||||
UpdateStatus(Status_USBReady);
|
||||
|
||||
/* Start CDC task */
|
||||
Scheduler_SetTaskMode(CDC_Task, TASK_RUN);
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
}
|
||||
|
||||
/** 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(CDC_Task)
|
||||
void CDC_Task(void)
|
||||
{
|
||||
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. */
|
||||
void ReconfigureUSART(void)
|
||||
{
|
||||
|
|
|
@ -46,11 +46,10 @@
|
|||
|
||||
#include "Lib/RingBuff.h"
|
||||
|
||||
#include <LUFA/Version.h> // Library Version Information
|
||||
#include <LUFA/Drivers/USB/USB.h> // USB Functionality
|
||||
#include <LUFA/Drivers/Peripheral/Serial.h> // USART driver
|
||||
#include <LUFA/Drivers/Board/LEDs.h> // LEDs driver
|
||||
#include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/Peripheral/Serial.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
|
||||
/* Macros: */
|
||||
/** CDC Class specific request to get the current virtual serial port configuration settings. */
|
||||
|
@ -112,6 +111,18 @@
|
|||
* to indicate that a data overrun error has occurred on the virtual serial port.
|
||||
*/
|
||||
#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 define for the virtual serial port line encoding settings, for storing the current USART configuration
|
||||
|
@ -170,16 +181,14 @@
|
|||
Status_USBReady = 2, /**< USB interface is connected and ready */
|
||||
};
|
||||
|
||||
/* Tasks: */
|
||||
TASK(CDC_Task);
|
||||
|
||||
/* Function Prototypes: */
|
||||
void SetupHardware(void);
|
||||
void CDC_Task(void);
|
||||
void ReconfigureUSART(void);
|
||||
|
||||
void EVENT_USB_Connect(void);
|
||||
void EVENT_USB_Disconnect(void);
|
||||
void EVENT_USB_ConfigurationChanged(void);
|
||||
void EVENT_USB_UnhandledControlPacket(void);
|
||||
|
||||
void ReconfigureUSART(void);
|
||||
void UpdateStatus(uint8_t CurrentStatus);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -119,14 +119,13 @@ OBJDIR = .
|
|||
|
||||
|
||||
# Path to the LUFA library
|
||||
LUFA_PATH = ../../..
|
||||
LUFA_PATH = ../../../..
|
||||
|
||||
|
||||
# List C source files here. (C dependencies are automatically generated.)
|
||||
SRC = $(TARGET).c \
|
||||
Descriptors.c \
|
||||
Lib/RingBuff.c \
|
||||
$(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
|
||||
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.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/USBTask.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.)
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -5,14 +5,13 @@
|
|||
*/
|
||||
|
||||
========== 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
|
||||
- Document new host class drivers
|
||||
- Convert Host mode demos to class drivers
|
||||
- Add in old Host mode demos, convert to schedulerless
|
||||
- Add in incomplete host mode demos
|
||||
- Convert Host mode demos to schedulerless
|
||||
- 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
|
||||
|
|
Loading…
Reference in New Issue