clean descriptor setting. Remove keyboard OUT Endpoint.
- to make descriptor get VID/PID/Version from config.h. - remove keyboard out endpoint. Instead host can use control request.
This commit is contained in:
parent
3969ec09b4
commit
effa5914bf
@ -120,12 +120,12 @@ include $(LUFA_PATH)/LUFA/makefile
|
|||||||
|
|
||||||
|
|
||||||
# List C source files here. (C dependencies are automatically generated.)
|
# List C source files here. (C dependencies are automatically generated.)
|
||||||
LSRC = $(TARGET).c \
|
LUFA_SRC = $(TARGET).c \
|
||||||
Descriptors.c \
|
descriptor.c \
|
||||||
$(LUFA_SRC_USB) \
|
$(LUFA_SRC_USB) \
|
||||||
$(LUFA_SRC_USBCLASS)
|
$(LUFA_SRC_USBCLASS)
|
||||||
|
|
||||||
SRC = $(subst $(LUFA_PATH)/LUFA/,,$(LSRC))
|
SRC = $(subst $(LUFA_PATH)/LUFA/,,$(LUFA_SRC))
|
||||||
SRC += keymap.c \
|
SRC += keymap.c \
|
||||||
matrix.c \
|
matrix.c \
|
||||||
led.c
|
led.c
|
||||||
|
@ -21,10 +21,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
/* controller configuration */
|
/* controller configuration */
|
||||||
#include "controller_teensy.h"
|
#include "controller_teensy.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* USB Device descriptor */
|
||||||
#define VENDOR_ID 0xFEED
|
#define VENDOR_ID 0xFEED
|
||||||
#define PRODUCT_ID 0xBEE1
|
#define PRODUCT_ID 0xBEE1
|
||||||
|
#define DEVICE_VER 0x0101
|
||||||
#define MANUFACTURER t.m.k.
|
#define MANUFACTURER t.m.k.
|
||||||
#define PRODUCT Macway mod(LUFA)
|
#define PRODUCT Macway mod(LUFA)
|
||||||
|
|
||||||
|
|
||||||
|
/* message strings */
|
||||||
#define DESCRIPTION t.m.k. keyboard firmware for Macway mod(LUFA)
|
#define DESCRIPTION t.m.k. keyboard firmware for Macway mod(LUFA)
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,14 +36,8 @@
|
|||||||
this software.
|
this software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** \file
|
#include "util.h"
|
||||||
*
|
#include "descriptor.h"
|
||||||
* USB Device Descriptors, for library use when in USB device mode. Descriptors are special
|
|
||||||
* computer-readable structures which the host requests upon device enumeration, to determine
|
|
||||||
* the device's capabilities and functions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "Descriptors.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -152,9 +146,9 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
|
|||||||
|
|
||||||
.Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
|
.Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
|
||||||
|
|
||||||
.VendorID = 0xFEED,
|
.VendorID = VENDOR_ID,
|
||||||
.ProductID = 0x204D,
|
.ProductID = PRODUCT_ID,
|
||||||
.ReleaseNumber = VERSION_BCD(00.02),
|
.ReleaseNumber = DEVICE_VER,
|
||||||
|
|
||||||
.ManufacturerStrIndex = 0x01,
|
.ManufacturerStrIndex = 0x01,
|
||||||
.ProductStrIndex = 0x02,
|
.ProductStrIndex = 0x02,
|
||||||
@ -178,7 +172,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
|
|||||||
.ConfigurationNumber = 1,
|
.ConfigurationNumber = 1,
|
||||||
.ConfigurationStrIndex = NO_DESCRIPTOR,
|
.ConfigurationStrIndex = NO_DESCRIPTOR,
|
||||||
|
|
||||||
.ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED), //TODO: bus powered?
|
.ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_REMOTEWAKEUP),
|
||||||
|
|
||||||
.MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
|
.MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
|
||||||
},
|
},
|
||||||
@ -186,14 +180,14 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
|
|||||||
/*
|
/*
|
||||||
* Keyboard
|
* Keyboard
|
||||||
*/
|
*/
|
||||||
.HID1_KeyboardInterface =
|
.HID0_KeyboardInterface =
|
||||||
{
|
{
|
||||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||||
|
|
||||||
.InterfaceNumber = 0x00,
|
.InterfaceNumber = KEYBOARD_INTERFACE,
|
||||||
.AlternateSetting = 0x00,
|
.AlternateSetting = 0x00,
|
||||||
|
|
||||||
.TotalEndpoints = 2,
|
.TotalEndpoints = 1,
|
||||||
|
|
||||||
.Class = HID_CSCP_HIDClass,
|
.Class = HID_CSCP_HIDClass,
|
||||||
.SubClass = HID_CSCP_BootSubclass,
|
.SubClass = HID_CSCP_BootSubclass,
|
||||||
@ -202,7 +196,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
|
|||||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||||
},
|
},
|
||||||
|
|
||||||
.HID1_KeyboardHID =
|
.HID0_KeyboardHID =
|
||||||
{
|
{
|
||||||
.Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
|
.Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
|
||||||
|
|
||||||
@ -213,7 +207,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
|
|||||||
.HIDReportLength = sizeof(KeyboardReport)
|
.HIDReportLength = sizeof(KeyboardReport)
|
||||||
},
|
},
|
||||||
|
|
||||||
.HID1_ReportINEndpoint =
|
.HID0_ReportINEndpoint =
|
||||||
{
|
{
|
||||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||||
|
|
||||||
@ -223,24 +217,14 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
|
|||||||
.PollingIntervalMS = 0x01
|
.PollingIntervalMS = 0x01
|
||||||
},
|
},
|
||||||
|
|
||||||
.HID1_ReportOUTEndpoint =
|
|
||||||
{
|
|
||||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
|
||||||
|
|
||||||
.EndpointAddress = (ENDPOINT_DIR_OUT | KEYBOARD_OUT_EPNUM),
|
|
||||||
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
|
||||||
.EndpointSize = HID_EPSIZE,
|
|
||||||
.PollingIntervalMS = 0x01
|
|
||||||
},
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Mouse
|
* Mouse
|
||||||
*/
|
*/
|
||||||
.HID2_MouseInterface =
|
.HID1_MouseInterface =
|
||||||
{
|
{
|
||||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||||
|
|
||||||
.InterfaceNumber = 0x01,
|
.InterfaceNumber = MOUSE_INTERFACE,
|
||||||
.AlternateSetting = 0x00,
|
.AlternateSetting = 0x00,
|
||||||
|
|
||||||
.TotalEndpoints = 1,
|
.TotalEndpoints = 1,
|
||||||
@ -252,7 +236,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
|
|||||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||||
},
|
},
|
||||||
|
|
||||||
.HID2_MouseHID =
|
.HID1_MouseHID =
|
||||||
{
|
{
|
||||||
.Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
|
.Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
|
||||||
|
|
||||||
@ -263,7 +247,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
|
|||||||
.HIDReportLength = sizeof(MouseReport)
|
.HIDReportLength = sizeof(MouseReport)
|
||||||
},
|
},
|
||||||
|
|
||||||
.HID2_ReportINEndpoint =
|
.HID1_ReportINEndpoint =
|
||||||
{
|
{
|
||||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||||
|
|
||||||
@ -276,11 +260,11 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
|
|||||||
/*
|
/*
|
||||||
* Generic
|
* Generic
|
||||||
*/
|
*/
|
||||||
.HID3_GenericInterface =
|
.HID2_GenericInterface =
|
||||||
{
|
{
|
||||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||||
|
|
||||||
.InterfaceNumber = 0x02,
|
.InterfaceNumber = GENERIC_INTERFACE,
|
||||||
.AlternateSetting = 0x00,
|
.AlternateSetting = 0x00,
|
||||||
|
|
||||||
.TotalEndpoints = 2,
|
.TotalEndpoints = 2,
|
||||||
@ -292,7 +276,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
|
|||||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||||
},
|
},
|
||||||
|
|
||||||
.HID3_GenericHID =
|
.HID2_GenericHID =
|
||||||
{
|
{
|
||||||
.Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
|
.Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
|
||||||
|
|
||||||
@ -303,7 +287,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
|
|||||||
.HIDReportLength = sizeof(GenericReport)
|
.HIDReportLength = sizeof(GenericReport)
|
||||||
},
|
},
|
||||||
|
|
||||||
.HID3_ReportINEndpoint =
|
.HID2_ReportINEndpoint =
|
||||||
{
|
{
|
||||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||||
|
|
||||||
@ -313,7 +297,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
|
|||||||
.PollingIntervalMS = 0x01
|
.PollingIntervalMS = 0x01
|
||||||
},
|
},
|
||||||
|
|
||||||
.HID3_ReportOUTEndpoint =
|
.HID2_ReportOUTEndpoint =
|
||||||
{
|
{
|
||||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||||
|
|
||||||
@ -339,14 +323,14 @@ const USB_Descriptor_String_t PROGMEM ManufacturerString =
|
|||||||
{
|
{
|
||||||
.Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String},
|
.Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String},
|
||||||
|
|
||||||
.UnicodeString = L"Dean Camera" // TODO:
|
.UnicodeString = LSTR(MANUFACTURER)
|
||||||
};
|
};
|
||||||
|
|
||||||
const USB_Descriptor_String_t PROGMEM ProductString =
|
const USB_Descriptor_String_t PROGMEM ProductString =
|
||||||
{
|
{
|
||||||
.Header = {.Size = USB_STRING_LEN(28), .Type = DTYPE_String},
|
.Header = {.Size = USB_STRING_LEN(28), .Type = DTYPE_String},
|
||||||
|
|
||||||
.UnicodeString = L"LUFA Mouse and Keyboard Demo" // TODO:
|
.UnicodeString = LSTR(PRODUCT)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -395,31 +379,31 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
|
|||||||
break;
|
break;
|
||||||
case HID_DTYPE_HID:
|
case HID_DTYPE_HID:
|
||||||
switch (wIndex) {
|
switch (wIndex) {
|
||||||
case 0:
|
case KEYBOARD_INTERFACE:
|
||||||
Address = &ConfigurationDescriptor.HID1_KeyboardHID;
|
Address = &ConfigurationDescriptor.HID0_KeyboardHID;
|
||||||
Size = sizeof(USB_HID_Descriptor_HID_t);
|
Size = sizeof(USB_HID_Descriptor_HID_t);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case MOUSE_INTERFACE:
|
||||||
Address = &ConfigurationDescriptor.HID2_MouseHID;
|
Address = &ConfigurationDescriptor.HID1_MouseHID;
|
||||||
Size = sizeof(USB_HID_Descriptor_HID_t);
|
Size = sizeof(USB_HID_Descriptor_HID_t);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case GENERIC_INTERFACE:
|
||||||
Address = &ConfigurationDescriptor.HID3_GenericHID;
|
Address = &ConfigurationDescriptor.HID2_GenericHID;
|
||||||
Size = sizeof(USB_HID_Descriptor_HID_t);
|
Size = sizeof(USB_HID_Descriptor_HID_t);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case HID_DTYPE_Report:
|
case HID_DTYPE_Report:
|
||||||
switch (wIndex) {
|
switch (wIndex) {
|
||||||
case 0:
|
case KEYBOARD_INTERFACE:
|
||||||
Address = &KeyboardReport;
|
Address = &KeyboardReport;
|
||||||
Size = sizeof(KeyboardReport);
|
Size = sizeof(KeyboardReport);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case MOUSE_INTERFACE:
|
||||||
Address = &MouseReport;
|
Address = &MouseReport;
|
||||||
Size = sizeof(MouseReport);
|
Size = sizeof(MouseReport);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case GENERIC_INTERFACE:
|
||||||
Address = &GenericReport;
|
Address = &GenericReport;
|
||||||
Size = sizeof(GenericReport);
|
Size = sizeof(GenericReport);
|
||||||
break;
|
break;
|
@ -46,30 +46,32 @@ typedef struct
|
|||||||
USB_Descriptor_Configuration_Header_t Config;
|
USB_Descriptor_Configuration_Header_t Config;
|
||||||
|
|
||||||
// Keyboard HID Interface
|
// Keyboard HID Interface
|
||||||
USB_Descriptor_Interface_t HID1_KeyboardInterface;
|
USB_Descriptor_Interface_t HID0_KeyboardInterface;
|
||||||
USB_HID_Descriptor_HID_t HID1_KeyboardHID;
|
USB_HID_Descriptor_HID_t HID0_KeyboardHID;
|
||||||
USB_Descriptor_Endpoint_t HID1_ReportINEndpoint;
|
USB_Descriptor_Endpoint_t HID0_ReportINEndpoint;
|
||||||
USB_Descriptor_Endpoint_t HID1_ReportOUTEndpoint;
|
|
||||||
|
|
||||||
// Mouse HID Interface
|
// Mouse HID Interface
|
||||||
USB_Descriptor_Interface_t HID2_MouseInterface;
|
USB_Descriptor_Interface_t HID1_MouseInterface;
|
||||||
USB_HID_Descriptor_HID_t HID2_MouseHID;
|
USB_HID_Descriptor_HID_t HID1_MouseHID;
|
||||||
USB_Descriptor_Endpoint_t HID2_ReportINEndpoint;
|
USB_Descriptor_Endpoint_t HID1_ReportINEndpoint;
|
||||||
|
|
||||||
// Generic HID Interface
|
// Generic HID Interface
|
||||||
USB_Descriptor_Interface_t HID3_GenericInterface;
|
USB_Descriptor_Interface_t HID2_GenericInterface;
|
||||||
USB_HID_Descriptor_HID_t HID3_GenericHID;
|
USB_HID_Descriptor_HID_t HID2_GenericHID;
|
||||||
USB_Descriptor_Endpoint_t HID3_ReportINEndpoint;
|
USB_Descriptor_Endpoint_t HID2_ReportINEndpoint;
|
||||||
USB_Descriptor_Endpoint_t HID3_ReportOUTEndpoint;
|
USB_Descriptor_Endpoint_t HID2_ReportOUTEndpoint;
|
||||||
} USB_Descriptor_Configuration_t;
|
} USB_Descriptor_Configuration_t;
|
||||||
|
|
||||||
|
|
||||||
|
#define KEYBOARD_INTERFACE 0
|
||||||
|
#define MOUSE_INTERFACE 1
|
||||||
|
#define GENERIC_INTERFACE 2
|
||||||
|
|
||||||
// Endopoint number/size
|
// Endopoint number/size
|
||||||
#define KEYBOARD_IN_EPNUM 1
|
#define KEYBOARD_IN_EPNUM 1
|
||||||
#define KEYBOARD_OUT_EPNUM 2
|
#define MOUSE_IN_EPNUM 2
|
||||||
#define MOUSE_IN_EPNUM 3
|
#define GENERIC_IN_EPNUM 3
|
||||||
#define GENERIC_IN_EPNUM 4
|
#define GENERIC_OUT_EPNUM 4
|
||||||
#define GENERIC_OUT_EPNUM 5
|
|
||||||
|
|
||||||
#define HID_EPSIZE 8
|
#define HID_EPSIZE 8
|
||||||
#define GENERIC_EPSIZE 8
|
#define GENERIC_EPSIZE 8
|
@ -42,11 +42,15 @@
|
|||||||
#include "keyboard.h"
|
#include "keyboard.h"
|
||||||
#include "sendchar.h"
|
#include "sendchar.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
|
#include "descriptor.h"
|
||||||
#include "lufa.h"
|
#include "lufa.h"
|
||||||
|
|
||||||
static uint8_t keyboard_led_stats = 0;
|
static uint8_t keyboard_led_stats = 0;
|
||||||
report_keyboard_t keyboard_report_sent;
|
|
||||||
report_mouse_t mouse_report_sent;
|
// TODO: impl Control Request GET_REPORT
|
||||||
|
static report_keyboard_t keyboard_report_sent;
|
||||||
|
static report_mouse_t mouse_report_sent;
|
||||||
|
|
||||||
/* Host driver */
|
/* Host driver */
|
||||||
static uint8_t keyboard_leds(void);
|
static uint8_t keyboard_leds(void);
|
||||||
@ -63,6 +67,9 @@ static host_driver_t lufa_driver = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static void SetupHardware(void);
|
||||||
|
static void Generic_HID_Task(void);
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
SetupHardware();
|
SetupHardware();
|
||||||
@ -74,20 +81,23 @@ int main(void)
|
|||||||
debug_keyboard = true;
|
debug_keyboard = true;
|
||||||
debug_mouse = true;
|
debug_mouse = true;
|
||||||
|
|
||||||
_delay_ms(3000);
|
/* TODO: can't print here
|
||||||
|
_delay_ms(5000);
|
||||||
|
USB_USBTask();
|
||||||
print("abcdefg\n");
|
print("abcdefg\n");
|
||||||
|
USB_USBTask();
|
||||||
|
*/
|
||||||
|
|
||||||
keyboard_init();
|
keyboard_init();
|
||||||
host_set_driver(&lufa_driver);
|
host_set_driver(&lufa_driver);
|
||||||
while (1) {
|
while (1) {
|
||||||
keyboard_proc();
|
keyboard_proc();
|
||||||
Keyboard_HID_Task();
|
|
||||||
Generic_HID_Task();
|
Generic_HID_Task();
|
||||||
USB_USBTask();
|
USB_USBTask();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Configures the board hardware and chip peripherals for the demo's functionality. */
|
|
||||||
void SetupHardware(void)
|
void SetupHardware(void)
|
||||||
{
|
{
|
||||||
/* Disable watchdog if enabled by bootloader/fuses */
|
/* Disable watchdog if enabled by bootloader/fuses */
|
||||||
@ -100,6 +110,46 @@ void SetupHardware(void)
|
|||||||
USB_Init();
|
USB_Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void Generic_HID_Task(void)
|
||||||
|
{
|
||||||
|
/* Device must be connected and configured for the task to run */
|
||||||
|
if (USB_DeviceState != DEVICE_STATE_Configured)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// TODO: impl receivechar()/recvchar()
|
||||||
|
Endpoint_SelectEndpoint(GENERIC_OUT_EPNUM);
|
||||||
|
|
||||||
|
/* Check to see if a packet has been sent from the host */
|
||||||
|
if (Endpoint_IsOUTReceived())
|
||||||
|
{
|
||||||
|
/* Check to see if the packet contains data */
|
||||||
|
if (Endpoint_IsReadWriteAllowed())
|
||||||
|
{
|
||||||
|
/* Create a temporary buffer to hold the read in report from the host */
|
||||||
|
uint8_t GenericData[GENERIC_REPORT_SIZE];
|
||||||
|
|
||||||
|
/* Read Generic Report Data */
|
||||||
|
Endpoint_Read_Stream_LE(&GenericData, sizeof(GenericData), NULL);
|
||||||
|
|
||||||
|
/* Process Generic Report Data */
|
||||||
|
//ProcessGenericHIDReport(GenericData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Finalize the stream transfer to send the last packet */
|
||||||
|
Endpoint_ClearOUT();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* IN packet */
|
||||||
|
Endpoint_SelectEndpoint(GENERIC_IN_EPNUM);
|
||||||
|
// send IN packet
|
||||||
|
if (Endpoint_IsINReady())
|
||||||
|
Endpoint_ClearIN();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* USB Events
|
||||||
|
******************************************************************************/
|
||||||
/** Event handler for the USB_Connect event. */
|
/** Event handler for the USB_Connect event. */
|
||||||
void EVENT_USB_Device_Connect(void)
|
void EVENT_USB_Device_Connect(void)
|
||||||
{
|
{
|
||||||
@ -120,8 +170,6 @@ void EVENT_USB_Device_ConfigurationChanged(void)
|
|||||||
/* Setup Keyboard HID Report Endpoints */
|
/* Setup Keyboard HID Report Endpoints */
|
||||||
ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
|
ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
|
||||||
HID_EPSIZE, ENDPOINT_BANK_SINGLE);
|
HID_EPSIZE, ENDPOINT_BANK_SINGLE);
|
||||||
ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT,
|
|
||||||
HID_EPSIZE, ENDPOINT_BANK_SINGLE);
|
|
||||||
|
|
||||||
/* Setup Mouse HID Report Endpoint */
|
/* Setup Mouse HID Report Endpoint */
|
||||||
ConfigSuccess &= Endpoint_ConfigureEndpoint(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
|
ConfigSuccess &= Endpoint_ConfigureEndpoint(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
|
||||||
@ -152,15 +200,17 @@ void EVENT_USB_Device_ControlRequest(void)
|
|||||||
|
|
||||||
// Interface
|
// Interface
|
||||||
switch (USB_ControlRequest.wIndex) {
|
switch (USB_ControlRequest.wIndex) {
|
||||||
case 1: // Keyboard
|
case KEYBOARD_INTERFACE:
|
||||||
|
// TODO: test/check
|
||||||
ReportData = (uint8_t*)&keyboard_report_sent;
|
ReportData = (uint8_t*)&keyboard_report_sent;
|
||||||
ReportSize = sizeof(keyboard_report_sent);
|
ReportSize = sizeof(keyboard_report_sent);
|
||||||
break;
|
break;
|
||||||
case 2: // Mouse
|
case MOUSE_INTERFACE:
|
||||||
|
// TODO: test/check
|
||||||
ReportData = (uint8_t*)&mouse_report_sent;
|
ReportData = (uint8_t*)&mouse_report_sent;
|
||||||
ReportSize = sizeof(mouse_report_sent);
|
ReportSize = sizeof(mouse_report_sent);
|
||||||
break;
|
break;
|
||||||
case 3: // Generic
|
case GENERIC_INTERFACE:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,13 +234,14 @@ void EVENT_USB_Device_ControlRequest(void)
|
|||||||
|
|
||||||
// Interface
|
// Interface
|
||||||
switch (USB_ControlRequest.wIndex) {
|
switch (USB_ControlRequest.wIndex) {
|
||||||
case 1: // Keyboard
|
case KEYBOARD_INTERFACE:
|
||||||
|
// TODO: test/check
|
||||||
/* Read in the LED report from the host */
|
/* Read in the LED report from the host */
|
||||||
keyboard_led_stats = Endpoint_Read_8();
|
keyboard_led_stats = Endpoint_Read_8();
|
||||||
break;
|
break;
|
||||||
case 2: // Mouse
|
case MOUSE_INTERFACE:
|
||||||
break;
|
break;
|
||||||
case 3: // Generic
|
case GENERIC_INTERFACE:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,64 +253,6 @@ void EVENT_USB_Device_ControlRequest(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Keyboard task.
|
|
||||||
* This processes host LED status reports sent to the device via the keyboard OUT reporting endpoint.
|
|
||||||
*/
|
|
||||||
void Keyboard_HID_Task(void)
|
|
||||||
{
|
|
||||||
/* Device must be connected and configured for the task to run */
|
|
||||||
if (USB_DeviceState != DEVICE_STATE_Configured)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* Select the Keyboard LED Report Endpoint */
|
|
||||||
Endpoint_SelectEndpoint(KEYBOARD_OUT_EPNUM);
|
|
||||||
|
|
||||||
/* Check if Keyboard LED Endpoint Ready for Read/Write */
|
|
||||||
if (Endpoint_IsReadWriteAllowed())
|
|
||||||
{
|
|
||||||
/* Read in the LED report from the host */
|
|
||||||
keyboard_led_stats = Endpoint_Read_8();
|
|
||||||
|
|
||||||
/* Handshake the OUT Endpoint - clear endpoint and ready for next report */
|
|
||||||
Endpoint_ClearOUT();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Generic_HID_Task(void)
|
|
||||||
{
|
|
||||||
/* Device must be connected and configured for the task to run */
|
|
||||||
if (USB_DeviceState != DEVICE_STATE_Configured)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Endpoint_SelectEndpoint(GENERIC_OUT_EPNUM);
|
|
||||||
|
|
||||||
/* Check to see if a packet has been sent from the host */
|
|
||||||
if (Endpoint_IsOUTReceived())
|
|
||||||
{
|
|
||||||
/* Check to see if the packet contains data */
|
|
||||||
if (Endpoint_IsReadWriteAllowed())
|
|
||||||
{
|
|
||||||
/* Create a temporary buffer to hold the read in report from the host */
|
|
||||||
uint8_t GenericData[GENERIC_REPORT_SIZE];
|
|
||||||
|
|
||||||
/* Read Generic Report Data */
|
|
||||||
Endpoint_Read_Stream_LE(&GenericData, sizeof(GenericData), NULL);
|
|
||||||
|
|
||||||
/* Process Generic Report Data */
|
|
||||||
//TODO: ProcessGenericHIDReport(GenericData);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Finalize the stream transfer to send the last packet */
|
|
||||||
Endpoint_ClearOUT();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* IN packet */
|
|
||||||
Endpoint_SelectEndpoint(GENERIC_IN_EPNUM);
|
|
||||||
// send IN packet
|
|
||||||
if (Endpoint_IsINReady())
|
|
||||||
Endpoint_ClearIN();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Host driver
|
* Host driver
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
@ -332,7 +325,6 @@ int8_t sendchar(uint8_t c)
|
|||||||
}
|
}
|
||||||
if (Endpoint_IsStalled())
|
if (Endpoint_IsStalled())
|
||||||
return -1;
|
return -1;
|
||||||
uint16_t currFN = USB_Device_GetFrameNumber();
|
|
||||||
if (prevFN != USB_Device_GetFrameNumber()) {
|
if (prevFN != USB_Device_GetFrameNumber()) {
|
||||||
if (!(timeout--))
|
if (!(timeout--))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -39,40 +39,7 @@
|
|||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "Descriptors.h"
|
|
||||||
|
|
||||||
#include <LUFA/Version.h>
|
#include <LUFA/Version.h>
|
||||||
#include <LUFA/Drivers/USB/USB.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: */
|
|
||||||
/** 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)
|
|
||||||
|
|
||||||
/* Function Prototypes: */
|
|
||||||
void SetupHardware(void);
|
|
||||||
void Keyboard_ProcessLEDReport(const uint8_t LEDStatus);
|
|
||||||
void Keyboard_HID_Task(void);
|
|
||||||
void Generic_HID_Task(void);
|
|
||||||
|
|
||||||
void EVENT_USB_Device_Connect(void);
|
|
||||||
void EVENT_USB_Device_Disconnect(void);
|
|
||||||
void EVENT_USB_Device_ConfigurationChanged(void);
|
|
||||||
void EVENT_USB_Device_ControlRequest(void);
|
|
||||||
void EVENT_USB_Device_StartOfFrame(void);
|
|
||||||
|
|
||||||
void Keyboard_send(USB_KeyboardReport_Data_t report);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user