Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement HID keyboard mode #88

Merged
merged 10 commits into from
Aug 19, 2024
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ There also exist button combinations which perform special actions if held while
| Special action | Button combination |
|:---|:---|
| Enter programming mode | B1 + B2 |
| IIDX mode (default) | B1 + B8 |
| SDVX mode | B1 + B9 |
| IIDX mode - HID (default) | B1 + B8 |
| IIDX mode - Keyboard | B2 + B8 |
| SDVX mode - HID | B1 + B9 |
| SDVX mode - Keyboard | B2 + B9 |

## BOM
```
Expand Down
4 changes: 2 additions & 2 deletions fw/Config/LUFAConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@
#define USE_FLASH_DESCRIPTORS
// #define USE_EEPROM_DESCRIPTORS
// #define NO_INTERNAL_SERIAL
#define FIXED_CONTROL_ENDPOINT_SIZE 8
#define FIXED_CONTROL_ENDPOINT_SIZE 64
// #define DEVICE_STATE_AS_GPIOR {Insert Value Here}
#define FIXED_NUM_CONFIGURATIONS 1
// #define CONTROL_ONLY_DEVICE
// #define INTERRUPT_CONTROL_ENDPOINT
#define INTERRUPT_CONTROL_ENDPOINT
// #define NO_DEVICE_REMOTE_WAKEUP
// #define NO_DEVICE_SELF_POWER

Expand Down
22 changes: 0 additions & 22 deletions fw/Descriptors.c

This file was deleted.

121 changes: 121 additions & 0 deletions fw/Descriptors.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#include "Descriptors.h"

const USB_Descriptor_HIDReport_Datatype_t* JoystickHIDReport;
uint16_t SizeOfJoystickHIDReport;
const USB_Descriptor_Device_t* DeviceDescriptor;
const USB_Descriptor_Configuration_t* ConfigurationDescriptor;
uint8_t LedStringCount;
const USB_Descriptor_String_t** LedStrings;

// Language descriptor structure. This descriptor, located in FLASH
// memory, is returned when the host requests the string descriptor
// with index 0 (the first index). It is actually an array of 16-bit
// integers, which indicate via the language ID table available at
// USB.org what languages the device supports for its string
// descriptors.
const USB_Descriptor_String_t PROGMEM LanguageString = USB_STRING_DESCRIPTOR_ARRAY(LANGUAGE_ID_ENG);

// Manufacturer descriptor string. This is a Unicode string containing
// the manufacturer's details in human readable form, and is read out
// upon request by the host when the appropriate string ID is
// requested, listed in the Device Descriptor.
const USB_Descriptor_String_t PROGMEM ManufacturerString = USB_STRING_DESCRIPTOR(L"SEGV");

// Product descriptor string. This is a Unicode string containing the
// product's details in human readable form, and is read out upon
// request by the host when the appropriate string ID is requested,
// listed in the Device Descriptor.
const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(L"BEEF BOARD");

// This function is called by the library when in device mode, and
// must be overridden (see library "USB Descriptors" documentation) by
// the application code so that the address and size of a requested
// descriptor can be given to the USB library. When the device
// receives a Get Descriptor request on the control endpoint, this
// function is called so that the descriptor details can be passed
// back and the appropriate descriptor sent back to the USB host.
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint16_t wIndex,
const void** const DescriptorAddress) {
const uint8_t DescriptorType = (wValue >> 8);
const uint8_t DescriptorNumber = (wValue & 0xFF);

const void* Address = nullptr;
uint16_t Size = NO_DESCRIPTOR;

switch (DescriptorType) {
case DTYPE_Device:
Address = DeviceDescriptor;
Size = sizeof(USB_Descriptor_Device_t);
break;
case DTYPE_Configuration:
Address = ConfigurationDescriptor;
Size = sizeof(USB_Descriptor_Configuration_t);
break;
case DTYPE_String:
switch (DescriptorNumber) {
case STRING_ID_Language:
Address = &LanguageString;
Size = pgm_read_byte(&LanguageString.Header.Size);
break;
case STRING_ID_Manufacturer:
Address = &ManufacturerString;
Size = pgm_read_byte(&ManufacturerString.Header.Size);
break;
case STRING_ID_Product:
Address = &ProductString;
Size = pgm_read_byte(&ProductString.Header.Size);
break;
default:
const int index = DescriptorNumber - LedStringBase - 1;
if (0 <= index && index < LedStringCount) {
Address = LedStrings[index];
Size = pgm_read_byte(&LedStrings[index]->Header.Size);
}
break;
}
break;
case HID_DTYPE_HID:
switch (wIndex)
{
case INTERFACE_ID_Joystick:
Address = &ConfigurationDescriptor->HID_JoystickHID;
Size = sizeof(USB_HID_Descriptor_HID_t);
break;
case INTERFACE_ID_Keyboard:
Address = &ConfigurationDescriptor->HID_KeyboardHID;
Size = sizeof(USB_HID_Descriptor_HID_t);
break;
case INTERFACE_ID_Mouse:
Address = &ConfigurationDescriptor->HID_MouseHID;
Size = sizeof(USB_HID_Descriptor_HID_t);
break;
default:
break;
}
break;
case HID_DTYPE_Report:
switch (wIndex)
{
case INTERFACE_ID_Joystick:
Address = JoystickHIDReport;
Size = SizeOfJoystickHIDReport;
break;
case INTERFACE_ID_Keyboard:
Address = &KeyboardHIDReport;
Size = sizeof(KeyboardHIDReport);
break;
case INTERFACE_ID_Mouse:
Address = &MouseHIDReport;
Size = sizeof(MouseHIDReport);
break;
default:
break;
}
break;
default:
break;
}
*DescriptorAddress = Address;
return Size;
}
Loading