diff --git a/Firmware/PocketVoltex/DFU/hid_bootloader_loader.py b/Firmware/PocketVoltex/DFU/hid_bootloader_loader.py index 917d45f..a9487b0 100644 --- a/Firmware/PocketVoltex/DFU/hid_bootloader_loader.py +++ b/Firmware/PocketVoltex/DFU/hid_bootloader_loader.py @@ -24,6 +24,10 @@ from pywinusb import hid from intelhex import IntelHex import time +# new bootloader +import usb1 + +ENDPOINT_SIZE = 32 # Device information table device_info_map = dict() @@ -52,26 +56,23 @@ def get_hid_device_handle(): return valid_hid_devices[0] def bootloader_boot(): - hid_device_filter = hid.HidDeviceFilter(vendor_id=0x16D0, - product_id=0x0A6D, - product_name="Pocket Voltex Config") - - valid_hid_devices = hid_device_filter.get_devices() - - if len(valid_hid_devices) is 0: - return False - else: - try: - hid_device = valid_hid_devices[0] - hid_device.open() - # switch count + static stuff + report id - output_report_data = [0] * (8 + 9 + 1) - # report ID is 0 at byte 0 - output_report_data[1] = 42; - - hid_device.send_output_report(output_report_data) - finally: - hid_device.close() + # eventually the hid loader will use this too + with usb1.USBContext() as context: + voltex = None + for dev in context.getDeviceList(): + if dev.getVendorID() == 0x16D0 and dev.getProductID() == 0x0A6D: + # because there is the pseudo-composite-parent we ignore + try: + voltex = dev.open() + print "Open success!" + except: + print "Open fail" + if voltex is None: + # Device not present, or user is not allowed to access device. + print("Couldn't find device to reboot") + return False + with voltex.claimInterface(0): + voltex.bulkWrite(1, [42] + [0]*(ENDPOINT_SIZE-1)) return True def send_page_data(hid_device, address, data): @@ -93,7 +94,7 @@ def program_device(hex_data, device_info): print("No valid HID device found.") sys.exit(1) print("Rebooted to bootloader") - time.sleep(6) + time.sleep(4) hid_device = get_hid_device_handle() if hid_device is None: print("No valid HID device found.") diff --git a/Firmware/PocketVoltex/DFU/libusb-1.0.dll b/Firmware/PocketVoltex/DFU/libusb-1.0.dll new file mode 100644 index 0000000..5377cb4 Binary files /dev/null and b/Firmware/PocketVoltex/DFU/libusb-1.0.dll differ diff --git a/Firmware/PocketVoltex/Descriptors.c b/Firmware/PocketVoltex/Descriptors.c index 5ff46d9..15f3783 100644 --- a/Firmware/PocketVoltex/Descriptors.c +++ b/Firmware/PocketVoltex/Descriptors.c @@ -34,20 +34,77 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM LEDReport[] = HID_RI_END_COLLECTION(0), }; -const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = +const USB_Descriptor_HIDReport_Datatype_t PROGMEM InputsReport[] = { - // Use the HID class driver's standard Keyboard report - HID_DESCRIPTOR_KEYBOARD(SWITCH_COUNT) -}; - -const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] = -{ - /* Use the HID class driver's standard Mouse report. + /* Mouse Report * Min/max X/Y -128 to 127 * NOTE: need at least 1 button or report does not work * Relative coordinates */ - HID_DESCRIPTOR_MOUSE(-128, 127, -128, 127, 1, false) + HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ + HID_RI_USAGE(8, 0x02), /* Mouse */ + HID_RI_COLLECTION(8, 0x01), /* Application */ + HID_RI_REPORT_ID(8, HID_REPORTID_MouseReport), + HID_RI_USAGE(8, 0x01), /* Pointer */ + HID_RI_COLLECTION(8, 0x00), /* Physical */ + HID_RI_USAGE_PAGE(8, 0x09), /* Button */ + HID_RI_USAGE_MINIMUM(8, 0x01), + HID_RI_USAGE_MAXIMUM(8, 1), + HID_RI_LOGICAL_MINIMUM(8, 0x00), + HID_RI_LOGICAL_MAXIMUM(8, 0x01), + HID_RI_REPORT_COUNT(8, 1), + HID_RI_REPORT_SIZE(8, 0x01), + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), + HID_RI_REPORT_COUNT(8, 0x01), + HID_RI_REPORT_SIZE(8, 7), /* 7 bits padding for our 1 button */ + HID_RI_INPUT(8, HID_IOF_CONSTANT), + HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ + HID_RI_USAGE(8, 0x30), /* Usage X */ + HID_RI_USAGE(8, 0x31), /* Usage Y */ + HID_RI_LOGICAL_MINIMUM(16, -128), + HID_RI_LOGICAL_MAXIMUM(16, 127), + HID_RI_PHYSICAL_MINIMUM(16, -128), + HID_RI_PHYSICAL_MAXIMUM(16, 127), + HID_RI_REPORT_COUNT(8, 0x02), + HID_RI_REPORT_SIZE(8, 8), + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE), + HID_RI_END_COLLECTION(0), + HID_RI_END_COLLECTION(0), + + /* Keyboard Report */ + HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ + HID_RI_USAGE(8, 0x06), /* Keyboard */ + HID_RI_COLLECTION(8, 0x01), /* Application */ + HID_RI_REPORT_ID(8, HID_REPORTID_KeyboardReport), + HID_RI_USAGE_PAGE(8, 0x07), /* Key Codes */ + HID_RI_USAGE_MINIMUM(8, 0xE0), /* Keyboard Left Control */ + HID_RI_USAGE_MAXIMUM(8, 0xE7), /* Keyboard Right GUI */ + HID_RI_LOGICAL_MINIMUM(8, 0x00), + HID_RI_LOGICAL_MAXIMUM(8, 0x01), + HID_RI_REPORT_SIZE(8, 0x01), + HID_RI_REPORT_COUNT(8, 0x08), + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), + HID_RI_REPORT_COUNT(8, 0x01), + HID_RI_REPORT_SIZE(8, 0x08), + HID_RI_INPUT(8, HID_IOF_CONSTANT), + HID_RI_USAGE_PAGE(8, 0x08), /* LEDs */ + HID_RI_USAGE_MINIMUM(8, 0x01), /* Num Lock */ + HID_RI_USAGE_MAXIMUM(8, 0x05), /* Kana */ + HID_RI_REPORT_COUNT(8, 0x05), + HID_RI_REPORT_SIZE(8, 0x01), + HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE), + HID_RI_REPORT_COUNT(8, 0x01), + HID_RI_REPORT_SIZE(8, 0x03), + HID_RI_OUTPUT(8, HID_IOF_CONSTANT), + HID_RI_LOGICAL_MINIMUM(8, 0x00), + HID_RI_LOGICAL_MAXIMUM(8, 0xFF), + HID_RI_USAGE_PAGE(8, 0x07), /* Keyboard */ + HID_RI_USAGE_MINIMUM(8, 0x00), /* Reserved (no event indicated) */ + HID_RI_USAGE_MAXIMUM(8, 0xFF), + HID_RI_REPORT_COUNT(8, SWITCH_COUNT), + HID_RI_REPORT_SIZE(8, 0x08), + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE), + HID_RI_END_COLLECTION(0), }; @@ -108,7 +165,7 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .ManufacturerStrIndex = STRING_ID_Manufacturer, .ProductStrIndex = STRING_ID_Product, - .SerialNumStrIndex = STRING_ID_Product, + .SerialNumStrIndex = USE_INTERNAL_SERIAL, .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS }; @@ -120,7 +177,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration}, .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t), - .TotalInterfaces = 4, + .TotalInterfaces = 3, .ConfigurationNumber = 1, .ConfigurationStrIndex = STRING_ID_Product, @@ -146,17 +203,6 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .InterfaceStrIndex = STRING_ID_Config }, - .Config_DataInEndpoint = - { - .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, - - .EndpointAddress = CONFIG_IN_EPADDR, - .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), - .EndpointSize = CONFIG_EPSIZE, - // ignored but required - .PollingIntervalMS = 0x05 - }, - .Config_DataOutEndpoint = { .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, @@ -168,11 +214,22 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .PollingIntervalMS = 0x05 }, + .Config_DataInEndpoint = + { + .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, + + .EndpointAddress = CONFIG_IN_EPADDR, + .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), + .EndpointSize = CONFIG_EPSIZE, + // ignored but required + .PollingIntervalMS = 0x05 + }, + .HID1_Interface = { .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, - .InterfaceNumber = INTERFACE_ID_Keyboard, + .InterfaceNumber = INTERFACE_ID_Inputs, .AlternateSetting = 0x00, .TotalEndpoints = 1, @@ -181,10 +238,10 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .SubClass = HID_CSCP_NonBootSubclass, .Protocol = HID_CSCP_NonBootProtocol, - .InterfaceStrIndex = NO_DESCRIPTOR + .InterfaceStrIndex = STRING_ID_Controls }, - .HID1_KeyboardHID = + .HID1_InputsHID = { .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, @@ -192,57 +249,20 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .CountryCode = 0x00, .TotalReportDescriptors = 1, .HIDReportType = HID_DTYPE_Report, - .HIDReportLength = sizeof(KeyboardReport) + .HIDReportLength = sizeof(InputsReport) }, .HID1_ReportINEndpoint = { .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, - .EndpointAddress = KEYBOARD_EPADDR, + .EndpointAddress = INPUTS_EPADDR, .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), - .EndpointSize = KEYBOARD_EPSIZE, + .EndpointSize = INPUTS_EPSIZE, .PollingIntervalMS = 0x01 }, - .HID2_MouseInterface = - { - .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, - - .InterfaceNumber = INTERFACE_ID_Mouse, - .AlternateSetting = 0x00, - - .TotalEndpoints = 1, - - .Class = HID_CSCP_HIDClass, - .SubClass = HID_CSCP_BootSubclass, - .Protocol = HID_CSCP_MouseBootProtocol, - - .InterfaceStrIndex = STRING_ID_Knobs - }, - - .HID2_MouseHID = - { - .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, - - .HIDSpec = VERSION_BCD(1,1,1), - .CountryCode = 0x00, - .TotalReportDescriptors = 1, - .HIDReportType = HID_DTYPE_Report, - .HIDReportLength = sizeof(MouseReport) - }, - - .HID2_ReportINEndpoint = - { - .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, - - .EndpointAddress = MOUSE_IN_EPADDR, - .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), - .EndpointSize = MOUSE_EPSIZE, - .PollingIntervalMS = 0x01 - }, - - .HID3_Interface = + .HID2_Interface = { .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, @@ -258,7 +278,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .InterfaceStrIndex = STRING_ID_LED }, - .HID3_LEDHID = + .HID2_LEDHID = { .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, @@ -269,7 +289,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .HIDReportLength = sizeof(LEDReport) }, - .HID3_ReportINEndpoint = + .HID2_ReportINEndpoint = { .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, @@ -288,7 +308,7 @@ const USB_Descriptor_String_t PROGMEM LanguageString = USB_STRING_DESCRIPTOR_ARR const USB_Descriptor_String_t PROGMEM ManufacturerString = USB_STRING_DESCRIPTOR(L"mon.im"); const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(L"Pocket Voltex"); const USB_Descriptor_String_t PROGMEM LEDString = USB_STRING_DESCRIPTOR(L"Pocket Voltex LEDs"); -const USB_Descriptor_String_t PROGMEM KnobString = USB_STRING_DESCRIPTOR(L"Pocket Voltex Knobs"); +const USB_Descriptor_String_t PROGMEM ControlsString = USB_STRING_DESCRIPTOR(L"Pocket Voltex Controls"); const USB_Descriptor_String_t PROGMEM ConfigString = USB_STRING_DESCRIPTOR(L"Pocket Voltex Config"); // There may be a better way to do this const USB_Descriptor_String_t PROGMEM LEDString_indiv[] = { @@ -421,9 +441,9 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, Address = &LEDString; Size = pgm_read_byte(&LEDString.Header.Size); break; - case STRING_ID_Knobs: - Address = &KnobString; - Size = pgm_read_byte(&KnobString.Header.Size); + case STRING_ID_Controls: + Address = &ControlsString; + Size = pgm_read_byte(&ControlsString.Header.Size); break; case STRING_ID_Config: Address = &ConfigString; @@ -439,26 +459,19 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, case HID_DTYPE_HID: Size = sizeof(USB_HID_Descriptor_HID_t); switch (wIndex) { - case INTERFACE_ID_Keyboard: - Address = &ConfigurationDescriptor.HID1_KeyboardHID; - break; - case INTERFACE_ID_Mouse: - Address = &ConfigurationDescriptor.HID2_MouseHID; + case INTERFACE_ID_Inputs: + Address = &ConfigurationDescriptor.HID1_InputsHID; break; case INTERFACE_ID_LED: - Address = &ConfigurationDescriptor.HID3_LEDHID; + Address = &ConfigurationDescriptor.HID2_LEDHID; break; } break; case HID_DTYPE_Report: switch (wIndex) { - case INTERFACE_ID_Keyboard: - Address = &KeyboardReport; - Size = sizeof(KeyboardReport); - break; - case INTERFACE_ID_Mouse: - Address = &MouseReport; - Size = sizeof(MouseReport); + case INTERFACE_ID_Inputs: + Address = &InputsReport; + Size = sizeof(InputsReport); break; case INTERFACE_ID_LED: Address = &LEDReport; diff --git a/Firmware/PocketVoltex/Descriptors.h b/Firmware/PocketVoltex/Descriptors.h index 459a7cd..30bfd96 100644 --- a/Firmware/PocketVoltex/Descriptors.h +++ b/Firmware/PocketVoltex/Descriptors.h @@ -55,23 +55,18 @@ // Config interface as we can't talk to composite directly USB_Descriptor_Interface_t Config_Interface; - USB_Descriptor_Endpoint_t Config_DataInEndpoint; USB_Descriptor_Endpoint_t Config_DataOutEndpoint; + USB_Descriptor_Endpoint_t Config_DataInEndpoint; - // Keyboard HID Interface + // Inputs HID Interface USB_Descriptor_Interface_t HID1_Interface; - USB_HID_Descriptor_HID_t HID1_KeyboardHID; + USB_HID_Descriptor_HID_t HID1_InputsHID; USB_Descriptor_Endpoint_t HID1_ReportINEndpoint; - // Mouse HID Interface - USB_Descriptor_Interface_t HID2_MouseInterface; - USB_HID_Descriptor_HID_t HID2_MouseHID; - USB_Descriptor_Endpoint_t HID2_ReportINEndpoint; - // LED HID Interface for pretty lights - USB_Descriptor_Interface_t HID3_Interface; - USB_HID_Descriptor_HID_t HID3_LEDHID; - USB_Descriptor_Endpoint_t HID3_ReportINEndpoint; + USB_Descriptor_Interface_t HID2_Interface; + USB_HID_Descriptor_HID_t HID2_LEDHID; + USB_Descriptor_Endpoint_t HID2_ReportINEndpoint; } USB_Descriptor_Configuration_t; /** Enum for the device interface descriptor IDs within the device. @@ -79,9 +74,8 @@ enum InterfaceDescriptors_t { INTERFACE_ID_Config = 0, /**< Config interface descriptor ID */ - INTERFACE_ID_Keyboard = 1, /**< Keyboard interface descriptor ID */ - INTERFACE_ID_Mouse = 2, /**< Mouse interface descriptor ID */ - INTERFACE_ID_LED = 3, /**< LED interface descriptor ID */ + INTERFACE_ID_Inputs = 1, /**< Keyboard and mouse interface descriptor ID */ + INTERFACE_ID_LED = 2, /**< LED interface descriptor ID */ }; /** Enum for the device string descriptor IDs within the device. Each string descriptor should @@ -91,7 +85,7 @@ STRING_ID_Language = 0, /**< Supported Languages string descriptor ID (must be zero) */ STRING_ID_Manufacturer = 1, /**< Manufacturer string ID */ STRING_ID_Product = 2, /**< Product string ID */ - STRING_ID_Knobs = 3, + STRING_ID_Controls = 3, STRING_ID_Config = 4, STRING_ID_LED = 5, /**< LED string ID */ STRING_ID_LED_Indiv = 6, @@ -102,21 +96,30 @@ URL_ID_Localhost = 1, URL_ID_Config = 2, }; + + /** Enum for the HID report IDs used in the device. */ + enum + { + HID_REPORTID_MouseReport = 0x01, + HID_REPORTID_KeyboardReport = 0x02, + } HID_Report_IDs; /* Macros: */ - #define CONFIG_IN_EPADDR (ENDPOINT_DIR_IN | 1) - #define CONFIG_OUT_EPADDR (ENDPOINT_DIR_OUT | 5) - #define KEYBOARD_EPADDR (ENDPOINT_DIR_IN | 2) - #define MOUSE_IN_EPADDR (ENDPOINT_DIR_IN | 3) + #define CONFIG_OUT_EPADDR (ENDPOINT_DIR_OUT | 1) + #define CONFIG_IN_EPADDR (ENDPOINT_DIR_IN | 2) + #define INPUTS_EPADDR (ENDPOINT_DIR_IN | 3) #define LED_EPADDR (ENDPOINT_DIR_IN | 4) - #define KEYBOARD_EPSIZE SWITCH_COUNT + 2 - #define MOUSE_EPSIZE 8 - #define LED_EPSIZE LED_TOTAL_COUNT - // MUST be 8, 16, 32 or 64 bytes - #define CONFIG_EPSIZE COMMAND_BYTES <= 8 ? 8 : \ - COMMAND_BYTES <= 16 ? 16 : \ - COMMAND_BYTES <= 32 ? 32 : 64 // if it's larger than 64 bytes, you're out of luck + // the board only supports endpoints of 8, 16, 32 or 64 bytes + #define ROUND_UP(bytes) (bytes <= 8 ? 8 : \ + bytes <= 16 ? 16 : \ + bytes <= 32 ? 32 : 64) // if it's larger than 64 bytes, you're out of luck + + // acts like a union, mouse is 8 bytes + #define INPUTS_EPSIZE ROUND_UP(MAX(SWITCH_COUNT + 2, 8)) + #define LED_EPSIZE ROUND_UP(LED_TOTAL_COUNT) + // ignoring board limits, bulk endpoints MUST be 8, 16, 32 or 64 bytes + #define CONFIG_EPSIZE ROUND_UP(COMMAND_BYTES) /* Function Prototypes: */ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, diff --git a/Firmware/PocketVoltex/PocketVoltex.c b/Firmware/PocketVoltex/PocketVoltex.c index 2e165ce..801c257 100644 --- a/Firmware/PocketVoltex/PocketVoltex.c +++ b/Firmware/PocketVoltex/PocketVoltex.c @@ -34,43 +34,28 @@ typedef struct } LED_Report_t; /** Buffer to hold the previously generated Keyboard HID report, for comparison purposes inside the HID class driver. */ -static uint8_t PrevKeyboardHIDReportBuffer[sizeof(Keyboard_Report_t)]; -static uint8_t PrevMouseHIDReportBuffer[sizeof(USB_MouseReport_Data_t)]; +static uint8_t PrevInputsHIDReportBuffer[MAX(sizeof(Keyboard_Report_t), sizeof(USB_MouseReport_Data_t))]; static uint8_t PrevLEDHIDReportBuffer[sizeof(LED_Report_t)]; +static uint8_t sendKeyboard = 0; + /** LUFA HID Class driver interface configuration and state information. This structure is * passed to all HID Class driver functions, so that multiple instances of the same class * within a device can be differentiated from one another. */ -USB_ClassInfo_HID_Device_t Keyboard_HID_Interface = +USB_ClassInfo_HID_Device_t Inputs_HID_Interface = { .Config = { - .InterfaceNumber = INTERFACE_ID_Keyboard, + .InterfaceNumber = INTERFACE_ID_Inputs, .ReportINEndpoint = { - .Address = KEYBOARD_EPADDR, - .Size = KEYBOARD_EPSIZE, + .Address = INPUTS_EPADDR, + .Size = INPUTS_EPSIZE, .Banks = 1, }, - .PrevReportINBuffer = PrevKeyboardHIDReportBuffer, - .PrevReportINBufferSize = sizeof(PrevKeyboardHIDReportBuffer), - }, -}; - -USB_ClassInfo_HID_Device_t Mouse_HID_Interface = -{ - .Config = - { - .InterfaceNumber = INTERFACE_ID_Mouse, - .ReportINEndpoint = - { - .Address = MOUSE_IN_EPADDR, - .Size = MOUSE_EPSIZE, - .Banks = 1, - }, - .PrevReportINBuffer = PrevMouseHIDReportBuffer, - .PrevReportINBufferSize = sizeof(PrevMouseHIDReportBuffer), + .PrevReportINBuffer = PrevInputsHIDReportBuffer, + .PrevReportINBufferSize = sizeof(PrevInputsHIDReportBuffer), }, }; @@ -170,8 +155,7 @@ int main(void) for (;;) { - HID_Device_USBTask(&Keyboard_HID_Interface); - HID_Device_USBTask(&Mouse_HID_Interface); + HID_Device_USBTask(&Inputs_HID_Interface); HID_Device_USBTask(&LED_HID_Interface); USB_USBTask(); @@ -253,11 +237,12 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn void* ReportData, uint16_t* const ReportSize) { - if(ReportType != HID_REPORT_ITEM_In) { + if(ReportType != HID_REPORT_ITEM_In || HIDInterfaceInfo != &Inputs_HID_Interface) { *ReportSize = 0; return false; } - if (HIDInterfaceInfo == &Keyboard_HID_Interface) { + sendKeyboard ^= 1; + if (sendKeyboard) { Keyboard_Report_t* KeyboardReport = (Keyboard_Report_t*)ReportData; // Only the first 4 bytes are read by bemanitools, so let's use the first @@ -282,11 +267,11 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn } } + *ReportID = HID_REPORTID_KeyboardReport; *ReportSize = sizeof(Keyboard_Report_t); switchesChanged = 0; - return true; - } else if(HIDInterfaceInfo == &Mouse_HID_Interface) { + } else { USB_MouseReport_Data_t* MouseReport = (USB_MouseReport_Data_t*)ReportData; MouseReport->X = encoder_get(0); @@ -297,11 +282,10 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn encoder_set(0, 0); encoder_set(1, 0); + *ReportID = HID_REPORTID_MouseReport; *ReportSize = sizeof(USB_MouseReport_Data_t); - return true; } - *ReportSize = 0; - return false; + return true; } /** HID class driver callback function for the processing of HID reports from the host. @@ -356,10 +340,9 @@ void EVENT_USB_Device_Disconnect(void) /** Event handler for the library USB Configuration Changed event. */ void EVENT_USB_Device_ConfigurationChanged(void) { - Endpoint_ConfigureEndpoint(CONFIG_IN_EPADDR, EP_TYPE_BULK, CONFIG_EPSIZE, 1); Endpoint_ConfigureEndpoint(CONFIG_OUT_EPADDR, EP_TYPE_BULK, CONFIG_EPSIZE, 1); - HID_Device_ConfigureEndpoints(&Keyboard_HID_Interface); - HID_Device_ConfigureEndpoints(&Mouse_HID_Interface); + Endpoint_ConfigureEndpoint(CONFIG_IN_EPADDR, EP_TYPE_BULK, CONFIG_EPSIZE, 1); + HID_Device_ConfigureEndpoints(&Inputs_HID_Interface); HID_Device_ConfigureEndpoints(&LED_HID_Interface); USB_Device_EnableSOFEvents(); @@ -369,16 +352,14 @@ void EVENT_USB_Device_ConfigurationChanged(void) void EVENT_USB_Device_ControlRequest(void) { USB_Process_BOS(); - HID_Device_ProcessControlRequest(&Keyboard_HID_Interface); - HID_Device_ProcessControlRequest(&Mouse_HID_Interface); + HID_Device_ProcessControlRequest(&Inputs_HID_Interface); HID_Device_ProcessControlRequest(&LED_HID_Interface); } /** Event handler for the USB device Start Of Frame event. */ void EVENT_USB_Device_StartOfFrame(void) { - HID_Device_MillisecondElapsed(&Keyboard_HID_Interface); - HID_Device_MillisecondElapsed(&Mouse_HID_Interface); + HID_Device_MillisecondElapsed(&Inputs_HID_Interface); HID_Device_MillisecondElapsed(&LED_HID_Interface); if(hidTimeout > HID_LED_TIMEOUT) { diff --git a/Firmware/PocketVoltex/makefile b/Firmware/PocketVoltex/makefile index 4a3c460..188e7e5 100644 --- a/Firmware/PocketVoltex/makefile +++ b/Firmware/PocketVoltex/makefile @@ -65,4 +65,4 @@ flashboot: $(AVRDUDE) -U flash:w:DFU/BootloaderHID.hex:i flash: all - python DFU/hid_bootloader_loader.py atmega16u2 PocketVoltex.hex + cd DFU && python hid_bootloader_loader.py atmega16u2 ../PocketVoltex.hex