Browse files

Add bulk in endpoint as programming channel.

  • Loading branch information...
1 parent 10dc13c commit 9171dd89e60e6ac5ec6aa913a0e510730d5fd703 @humblehacker humblehacker committed Aug 19, 2010
Showing with 120 additions and 60 deletions.
  1. +81 −56 src/Descriptors.c
  2. +13 −4 src/Descriptors.h
  3. +26 −0 src/Keyboard.c
View
137 src/Descriptors.c
@@ -149,8 +149,6 @@ USB_Descriptor_HIDReport_Datatype_t DBGReport[] PROGMEM =
0xC0 // end collection
};
-
-
/** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
* device characteristics, including the supported USB version, control endpoint size and the
* number of device configurations. The descriptor is read out by the USB host when the enumeration
@@ -190,7 +188,7 @@ USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
.Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
.TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
- .TotalInterfaces = 2,
+ .TotalInterfaces = 3,
.ConfigurationNumber = 1,
.ConfigurationStrIndex = NO_DESCRIPTOR,
@@ -236,42 +234,67 @@ USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
.EndpointSize = KEYBOARD_EPSIZE,
.PollingIntervalMS = 0x0A
},
- .HIDDBG_Interface =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
-
- .InterfaceNumber = 0x01,
- .AlternateSetting = 0x00,
-
- .TotalEndpoints = 1,
-
- .Class = 0x03,
- .SubClass = 0x00,
- .Protocol = 0x00,
-
- .InterfaceStrIndex = NO_DESCRIPTOR
- },
-
- .HIDDBG_HID =
- {
- .Header = {.Size = sizeof(USB_HID_Descriptor_t), .Type = DTYPE_HID},
-
- .HIDSpec = VERSION_BCD(01.11),
- .CountryCode = 0x00,
- .TotalReportDescriptors = 1,
- .HIDReportType = DTYPE_Report,
- .HIDReportLength = sizeof(DBGReport)
- },
-
- .HIDDBG_ReportINEndpoint =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
-
- .EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | DBG_EPNUM),
- .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
- .EndpointSize = DBG_EPSIZE,
- .PollingIntervalMS = 0x0A
- },
+ .HIDDBG_Interface =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
+
+ .InterfaceNumber = 0x01,
+ .AlternateSetting = 0x00,
+
+ .TotalEndpoints = 1,
+
+ .Class = 0x03,
+ .SubClass = 0x00,
+ .Protocol = 0x00,
+
+ .InterfaceStrIndex = NO_DESCRIPTOR
+ },
+
+ .HIDDBG_HID =
+ {
+ .Header = {.Size = sizeof(USB_HID_Descriptor_t), .Type = DTYPE_HID},
+
+ .HIDSpec = VERSION_BCD(01.11),
+ .CountryCode = 0x00,
+ .TotalReportDescriptors = 1,
+ .HIDReportType = DTYPE_Report,
+ .HIDReportLength = sizeof(DBGReport)
+ },
+
+ .HIDDBG_ReportINEndpoint =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
+
+ .EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | DBG_EPNUM),
+ .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
+ .EndpointSize = DBG_EPSIZE,
+ .PollingIntervalMS = 0x0A
+ },
+ .Programming_Interface =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
+
+ .InterfaceNumber = 0x02,
+ .AlternateSetting = 0x00,
+
+ .TotalEndpoints = 1,
+
+ .Class = 0xFF, /* Vendor specific */
+ .SubClass = 0x00,
+ .Protocol = 0x00,
+
+ .InterfaceStrIndex = NO_DESCRIPTOR
+ },
+
+ .Programming_ReportINEndpoint =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
+
+ .EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | PRG_EPNUM),
+ .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
+ .EndpointSize = PRG_EPSIZE,
+ .PollingIntervalMS = 0x00 /* ignored for full-speed bulk transfers */
+ },
};
/** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
@@ -350,27 +373,29 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex,
break;
case DTYPE_HID:
- if (wIndex == 0)
- {
- Address = (void*)&ConfigurationDescriptor.HID_KeyboardHID;
- Size = sizeof(USB_HID_Descriptor_t);
- }
- else
+ switch (wIndex)
{
- Address = (void*)&ConfigurationDescriptor.HIDDBG_HID;
- Size = sizeof(USB_HID_Descriptor_t);
+ case 0:
+ Address = (void*)&ConfigurationDescriptor.HID_KeyboardHID;
+ Size = sizeof(USB_HID_Descriptor_t);
+ break;
+ case 1:
+ Address = (void*)&ConfigurationDescriptor.HIDDBG_HID;
+ Size = sizeof(USB_HID_Descriptor_t);
+ break;
}
break;
- case DTYPE_Report:
- if (wIndex == 0)
- {
- Address = (void*)&KeyboardReport;
- Size = sizeof(KeyboardReport);
- }
- else
+ case DTYPE_Report:
+ switch (wIndex)
{
- Address = (void*)&DBGReport;
- Size = sizeof(DBGReport);
+ case 0:
+ Address = (void*)&KeyboardReport;
+ Size = sizeof(KeyboardReport);
+ break;
+ case 1:
+ Address = (void*)&DBGReport;
+ Size = sizeof(DBGReport);
+ break;
}
break;
}
View
17 src/Descriptors.h
@@ -68,22 +68,31 @@
USB_Descriptor_Interface_t HIDDBG_Interface;
USB_HID_Descriptor_t HIDDBG_HID;
USB_Descriptor_Endpoint_t HIDDBG_ReportINEndpoint;
+ USB_Descriptor_Interface_t Programming_Interface;
+ USB_Descriptor_Endpoint_t Programming_ReportINEndpoint;
} USB_Descriptor_Configuration_t;
/* Macros: */
- /** Endpoint number of the Keyboard HID reporting IN endpoint. */
+ /** Endpoint number of the Keyboard HID report IN endpoint. */
#define KEYBOARD_EPNUM 1
- /** Size in bytes of the Keyboard HID reporting IN and OUT endpoints. */
+ /** Size in bytes of the Keyboard HID report IN and OUT endpoints. */
#define KEYBOARD_EPSIZE 8
- /** Endpoint number of the DBG HID reporting IN endpoint. */
+ /** Endpoint number of the DBG HID report IN endpoint. */
#define DBG_EPNUM 2
- /** Size in bytes of the DBG HID reporting IN and OUT
+ /** Size in bytes of the DBG HID report IN and OUT
* endpoints. */
#define DBG_EPSIZE 32
+ /** Endpoint number of the DBG HID report IN endpoint. */
+ #define PRG_EPNUM 3
+
+ /** Size in bytes of the Programming report IN and
+ * OUT endpoints. */
+ #define PRG_EPSIZE 64
+
/* Function Prototypes: */
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress)
ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
View
26 src/Keyboard.c
@@ -102,6 +102,26 @@ uint8_t g_num_lock, g_caps_lock, g_scrl_lock;
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
+
+void PRG_Device_USBTask(void);
+
+void PRG_Device_USBTask()
+{
+ if (USB_DeviceState != DEVICE_STATE_Configured)
+ return;
+
+ Endpoint_SelectEndpoint(PRG_EPNUM);
+
+ if (Endpoint_IsConfigured() && Endpoint_IsINReady() && Endpoint_IsReadWriteAllowed())
+ {
+ static char data[] = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
+ Endpoint_Write_Stream_LE((void *)data, 64, NULL);
+ // FIXME handle err
+
+ Endpoint_ClearIN();
+ }
+}
+
int main(void)
{
SetupHardware();
@@ -121,6 +141,8 @@ int main(void)
{
HID_Device_USBTask(&Keyboard_HID_Interface);
HID_Device_USBTask(&DBG_HID_Interface);
+
+ PRG_Device_USBTask();
}
else if (USB_RemoteWakeupEnabled && Keyboard__key_is_down())
{
@@ -193,6 +215,10 @@ void EVENT_USB_Device_ConfigurationChanged(void)
if (!(HID_Device_ConfigureEndpoints(&DBG_HID_Interface)))
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+ if (!(Endpoint_ConfigureEndpoint(PRG_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_IN,
+ PRG_EPSIZE, ENDPOINT_BANK_SINGLE)))
+ LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+
USB_Device_EnableSOFEvents();
}

0 comments on commit 9171dd8

Please sign in to comment.