HID_RI_END_COLLECTION(0),
};
+#ifdef MOUSE_ENABLE
const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] =
{
HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */
HID_RI_END_COLLECTION(0),
HID_RI_END_COLLECTION(0),
};
-
-const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] =
-{
- HID_RI_USAGE_PAGE(16, 0xFF31), /* Vendor Page(PJRC Teensy compatible) */
- HID_RI_USAGE(8, 0x74), /* Vendor Usage(PJRC Teensy compatible) */
- HID_RI_COLLECTION(8, 0x01), /* Application */
- HID_RI_USAGE(8, 0x75), /* Vendor Usage 0x75 */
- HID_RI_LOGICAL_MINIMUM(8, 0x00),
- HID_RI_LOGICAL_MAXIMUM(8, 0xFF),
- HID_RI_REPORT_COUNT(8, CONSOLE_EPSIZE),
- HID_RI_REPORT_SIZE(8, 0x08),
- HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
- HID_RI_USAGE(8, 0x76), /* Vendor Usage 0x76 */
- HID_RI_LOGICAL_MINIMUM(8, 0x00),
- HID_RI_LOGICAL_MAXIMUM(8, 0xFF),
- HID_RI_REPORT_COUNT(8, CONSOLE_EPSIZE),
- HID_RI_REPORT_SIZE(8, 0x08),
- HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
- HID_RI_END_COLLECTION(0),
-};
+#endif
#ifdef EXTRAKEY_ENABLE
-const USB_Descriptor_HIDReport_Datatype_t PROGMEM ExtraReport[] =
+const USB_Descriptor_HIDReport_Datatype_t PROGMEM ExtrakeyReport[] =
{
HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */
HID_RI_USAGE(8, 0x80), /* System Control */
};
#endif
+#ifdef CONSOLE_ENABLE
+const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] =
+{
+ HID_RI_USAGE_PAGE(16, 0xFF31), /* Vendor Page(PJRC Teensy compatible) */
+ HID_RI_USAGE(8, 0x74), /* Vendor Usage(PJRC Teensy compatible) */
+ HID_RI_COLLECTION(8, 0x01), /* Application */
+ HID_RI_USAGE(8, 0x75), /* Vendor Usage 0x75 */
+ HID_RI_LOGICAL_MINIMUM(8, 0x00),
+ HID_RI_LOGICAL_MAXIMUM(8, 0xFF),
+ HID_RI_REPORT_COUNT(8, CONSOLE_EPSIZE),
+ HID_RI_REPORT_SIZE(8, 0x08),
+ HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
+ HID_RI_USAGE(8, 0x76), /* Vendor Usage 0x76 */
+ HID_RI_LOGICAL_MINIMUM(8, 0x00),
+ HID_RI_LOGICAL_MAXIMUM(8, 0xFF),
+ HID_RI_REPORT_COUNT(8, CONSOLE_EPSIZE),
+ HID_RI_REPORT_SIZE(8, 0x08),
+ HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
+ HID_RI_END_COLLECTION(0),
+};
+#endif
+
#ifdef NKRO_ENABLE
const USB_Descriptor_HIDReport_Datatype_t PROGMEM NKROReport[] =
{
#endif
/*
- * Console
+ * Extra
*/
- .Console_Interface =
+#ifdef EXTRAKEY_ENABLE
+ .Extrakey_Interface =
{
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
- .InterfaceNumber = CONSOLE_INTERFACE,
+ .InterfaceNumber = EXTRAKEY_INTERFACE,
.AlternateSetting = 0x00,
- .TotalEndpoints = 2,
+ .TotalEndpoints = 1,
.Class = HID_CSCP_HIDClass,
.SubClass = HID_CSCP_NonBootSubclass,
.InterfaceStrIndex = NO_DESCRIPTOR
},
- .Console_HID =
+ .Extrakey_HID =
{
.Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
.CountryCode = 0x00,
.TotalReportDescriptors = 1,
.HIDReportType = HID_DTYPE_Report,
- .HIDReportLength = sizeof(ConsoleReport)
+ .HIDReportLength = sizeof(ExtrakeyReport)
},
- .Console_INEndpoint =
+ .Extrakey_INEndpoint =
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
- .EndpointAddress = (ENDPOINT_DIR_IN | CONSOLE_IN_EPNUM),
+ .EndpointAddress = (ENDPOINT_DIR_IN | EXTRAKEY_IN_EPNUM),
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
- .EndpointSize = CONSOLE_EPSIZE,
- .PollingIntervalMS = 0x01
- },
-
- .Console_OUTEndpoint =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
-
- .EndpointAddress = (ENDPOINT_DIR_OUT | CONSOLE_OUT_EPNUM),
- .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
- .EndpointSize = CONSOLE_EPSIZE,
+ .EndpointSize = EXTRAKEY_EPSIZE,
.PollingIntervalMS = 0x01
},
+#endif
/*
- * Extra
+ * Console
*/
-#ifdef EXTRAKEY_ENABLE
- .Extra_Interface =
+#ifdef CONSOLE_ENABLE
+ .Console_Interface =
{
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
- .InterfaceNumber = EXTRA_INTERFACE,
+ .InterfaceNumber = CONSOLE_INTERFACE,
.AlternateSetting = 0x00,
- .TotalEndpoints = 1,
+ .TotalEndpoints = 2,
.Class = HID_CSCP_HIDClass,
.SubClass = HID_CSCP_NonBootSubclass,
.InterfaceStrIndex = NO_DESCRIPTOR
},
- .Extra_HID =
+ .Console_HID =
{
.Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
.CountryCode = 0x00,
.TotalReportDescriptors = 1,
.HIDReportType = HID_DTYPE_Report,
- .HIDReportLength = sizeof(ExtraReport)
+ .HIDReportLength = sizeof(ConsoleReport)
},
- .Extra_INEndpoint =
+ .Console_INEndpoint =
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
- .EndpointAddress = (ENDPOINT_DIR_IN | EXTRA_IN_EPNUM),
+ .EndpointAddress = (ENDPOINT_DIR_IN | CONSOLE_IN_EPNUM),
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
- .EndpointSize = EXTRA_EPSIZE,
+ .EndpointSize = CONSOLE_EPSIZE,
+ .PollingIntervalMS = 0x01
+ },
+
+ .Console_OUTEndpoint =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
+
+ .EndpointAddress = (ENDPOINT_DIR_OUT | CONSOLE_OUT_EPNUM),
+ .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
+ .EndpointSize = CONSOLE_EPSIZE,
.PollingIntervalMS = 0x01
},
#endif
Size = sizeof(USB_HID_Descriptor_HID_t);
break;
#endif
- case CONSOLE_INTERFACE:
- Address = &ConfigurationDescriptor.Console_HID;
+#ifdef EXTRAKEY_ENABLE
+ case EXTRAKEY_INTERFACE:
+ Address = &ConfigurationDescriptor.Extrakey_HID;
Size = sizeof(USB_HID_Descriptor_HID_t);
break;
-#ifdef EXTRAKEY_ENABLE
- case EXTRA_INTERFACE:
- Address = &ConfigurationDescriptor.Extra_HID;
+#endif
+#ifdef CONSOLE_ENABLE
+ case CONSOLE_INTERFACE:
+ Address = &ConfigurationDescriptor.Console_HID;
Size = sizeof(USB_HID_Descriptor_HID_t);
break;
#endif
Size = sizeof(MouseReport);
break;
#endif
+#ifdef EXTRAKEY_ENABLE
+ case EXTRAKEY_INTERFACE:
+ Address = &ExtrakeyReport;
+ Size = sizeof(ExtrakeyReport);
+ break;
+#endif
+#ifdef CONSOLE_ENABLE
case CONSOLE_INTERFACE:
Address = &ConsoleReport;
Size = sizeof(ConsoleReport);
break;
-#ifdef EXTRAKEY_ENABLE
- case EXTRA_INTERFACE:
- Address = &ExtraReport;
- Size = sizeof(ExtraReport);
- break;
#endif
}
break;
USB_HID_Descriptor_HID_t Keyboard_HID;
USB_Descriptor_Endpoint_t Keyboard_INEndpoint;
- // Mouse HID Interface
#ifdef MOUSE_ENABLE
+ // Mouse HID Interface
USB_Descriptor_Interface_t Mouse_Interface;
USB_HID_Descriptor_HID_t Mouse_HID;
USB_Descriptor_Endpoint_t Mouse_INEndpoint;
#endif
+#ifdef EXTRAKEY_ENABLE
+ // Extrakey HID Interface
+ USB_Descriptor_Interface_t Extrakey_Interface;
+ USB_HID_Descriptor_HID_t Extrakey_HID;
+ USB_Descriptor_Endpoint_t Extrakey_INEndpoint;
+#endif
+
+#ifdef CONSOLE_ENABLE
// Console HID Interface
USB_Descriptor_Interface_t Console_Interface;
USB_HID_Descriptor_HID_t Console_HID;
USB_Descriptor_Endpoint_t Console_INEndpoint;
USB_Descriptor_Endpoint_t Console_OUTEndpoint;
-
- // Extra HID Interface
-#ifdef EXTRAKEY_ENABLE
- USB_Descriptor_Interface_t Extra_Interface;
- USB_HID_Descriptor_HID_t Extra_HID;
- USB_Descriptor_Endpoint_t Extra_INEndpoint;
#endif
} USB_Descriptor_Configuration_t;
#endif
#ifdef EXTRAKEY_ENABLE
-# define EXTRA_INTERFACE (MOUSE_INTERFACE + 1)
+# define EXTRAKEY_INTERFACE (MOUSE_INTERFACE + 1)
#else
-# define EXTRA_INTERFACE MOUSE_INTERFACE
+# define EXTRAKEY_INTERFACE MOUSE_INTERFACE
#endif
-#define CONSOLE_INTERFACE (EXTRA_INTERFACE + 1)
+#ifdef CONSOLE_ENABLE
+# define CONSOLE_INTERFACE (EXTRAKEY_INTERFACE + 1)
+#else
+# define CONSOLE_INTERFACE EXTRAKEY_INTERFACE
+#endif
/* nubmer of interfaces */
// Endopoint number and size
#define KEYBOARD_IN_EPNUM 1
-#define MOUSE_IN_EPNUM 2
-#define CONSOLE_IN_EPNUM 3
-#define CONSOLE_OUT_EPNUM 4
-#define EXTRA_IN_EPNUM 5
+
+#ifdef MOUSE_ENABLE
+# define MOUSE_IN_EPNUM (KEYBOARD_IN_EPNUM + 1)
+#else
+# define MOUSE_IN_EPNUM KEYBOARD_IN_EPNUM
+#endif
+
+#ifdef EXTRAKEY_ENABLE
+# define EXTRAKEY_IN_EPNUM (MOUSE_IN_EPNUM + 1)
+#else
+# define EXTRAKEY_IN_EPNUM MOUSE_IN_EPNUM
+#endif
+
+#ifdef CONSOLE_ENABLE
+# define CONSOLE_IN_EPNUM (EXTRAKEY_IN_EPNUM + 1)
+# define CONSOLE_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 2)
+#endif
+
#define KEYBOARD_EPSIZE 8
#define MOUSE_EPSIZE 8
+#define EXTRAKEY_EPSIZE 8
#define CONSOLE_EPSIZE 32
-#define EXTRA_EPSIZE 8
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
USB_Device_EnableSOFEvents();
}
+#ifdef CONSOLE_ENABLE
static void Console_Task(void)
{
/* Device must be connected and configured for the task to run */
/* IN packet */
Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM);
+
+ // fill empty bank
+ while (Endpoint_IsReadWriteAllowed())
+ Endpoint_Write_8(0);
+
// flash senchar packet
if (Endpoint_IsINReady()) {
Endpoint_ClearIN();
Endpoint_SelectEndpoint(ep);
}
+#else
+static void Console_Task(void)
+{
+}
+#endif
/*******************************************************************************
{
}
-#define CONSOLE_TASK_INTERVAL 50
void EVENT_USB_Device_StartOfFrame(void)
{
- static uint8_t interval;
- if (++interval == CONSOLE_TASK_INTERVAL) {
- Console_Task();
- interval = 0;
- }
+ Console_Task();
}
/** Event handler for the USB_ConfigurationChanged event.
#ifdef EXTRAKEY_ENABLE
/* Setup Extra HID Report Endpoint */
- ConfigSuccess &= Endpoint_ConfigureEndpoint(EXTRA_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
- EXTRA_EPSIZE, ENDPOINT_BANK_SINGLE);
+ ConfigSuccess &= Endpoint_ConfigureEndpoint(EXTRAKEY_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
+ EXTRAKEY_EPSIZE, ENDPOINT_BANK_SINGLE);
#endif
+#ifdef CONSOLE_ENABLE
/* Setup Console HID Report Endpoints */
ConfigSuccess &= Endpoint_ConfigureEndpoint(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
CONSOLE_EPSIZE, ENDPOINT_BANK_DOUBLE);
ConfigSuccess &= Endpoint_ConfigureEndpoint(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT,
CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
+#endif
}
/*
.report_id = REPORT_ID_SYSTEM,
.usage = data
};
- Endpoint_SelectEndpoint(EXTRA_IN_EPNUM);
+ Endpoint_SelectEndpoint(EXTRAKEY_IN_EPNUM);
if (Endpoint_IsReadWriteAllowed()) {
Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL);
Endpoint_ClearIN();
.report_id = REPORT_ID_CONSUMER,
.usage = data
};
- Endpoint_SelectEndpoint(EXTRA_IN_EPNUM);
+ Endpoint_SelectEndpoint(EXTRAKEY_IN_EPNUM);
if (Endpoint_IsReadWriteAllowed()) {
Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL);
Endpoint_ClearIN();
/*******************************************************************************
* sendchar
******************************************************************************/
-#define SEND_TIMEOUT 10
+#ifdef CONSOLE_ENABLE
+#define SEND_TIMEOUT 5
int8_t sendchar(uint8_t c)
{
if (USB_DeviceState != DEVICE_STATE_Configured)
return -1;
+ uint8_t ep = Endpoint_GetCurrentEndpoint();
Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM);
uint8_t timeout = SEND_TIMEOUT;
case DEVICE_STATE_Suspended:
return -1;
}
- if (Endpoint_IsStalled())
+ if (Endpoint_IsStalled()) {
+ Endpoint_SelectEndpoint(ep);
return -1;
+ }
if (prevFN != USB_Device_GetFrameNumber()) {
- if (!(timeout--))
+ if (!(timeout--)) {
+ Endpoint_SelectEndpoint(ep);
return -1;
+ }
prevFN = USB_Device_GetFrameNumber();
}
}
if (!Endpoint_IsReadWriteAllowed())
Endpoint_ClearIN();
+ Endpoint_SelectEndpoint(ep);
+ return 0;
+}
+#else
+int8_t sendchar(uint8_t c)
+{
return 0;
}
+#endif