First upload. Untested software

This commit is contained in:
2026-04-08 17:02:29 +02:00
commit 9b83763318
11 changed files with 698 additions and 0 deletions
+125
View File
@@ -0,0 +1,125 @@
/* Baremetal Risc-V USB <=> Amiga Joystick/Mouse HID converter.
* March 2026 - Anders Holck
* This software has no license. If you choose to use, please include my name :)
*/
#ifndef USB_DESCRIPTORS_H
#define USB_DESCRIPTORS_H
#include <stdint.h>
// USB Standard Request Codes
#define USB_REQ_GET_STATUS 0x00
#define USB_REQ_CLEAR_FEATURE 0x01
#define USB_REQ_SET_FEATURE 0x03
#define USB_REQ_SET_ADDRESS 0x05
#define USB_REQ_GET_DESCRIPTOR 0x06
#define USB_REQ_SET_DESCRIPTOR 0x07
#define USB_REQ_GET_CONFIGURATION 0x08
#define USB_REQ_SET_CONFIGURATION 0x09
// Descriptor Types
#define USB_DESC_DEVICE 0x01
#define USB_DESC_CONFIGURATION 0x02
#define USB_DESC_STRING 0x03
#define USB_DESC_INTERFACE 0x04
#define USB_DESC_ENDPOINT 0x05
#define USB_DESC_HID 0x21
#define USB_DESC_REPORT 0x22
// Device Descriptor
const uint8_t device_desc[] = {
18, // bLength
USB_DESC_DEVICE, // bDescriptorType
0x00, 0x02, // bcdUSB (2.0)
0x00, // bDeviceClass
0x00, // bDeviceSubClass
0x00, // bDeviceProtocol
64, // bMaxPacketSize0
0x6B, 0x1D, // idVendor (0x1D6B - Linux Foundation)
0x04, 0x01, // idProduct (0x0104)
0x00, 0x01, // bcdDevice
1, // iManufacturer
2, // iProduct
3, // iSerialNumber
1 // bNumConfigurations
};
// HID Report Descriptor (Combined Gamepad and Mouse)
const uint8_t hid_report_desc[] = {
0x05, 0x01, // Usage Page (Generic Desktop)
0x09, 0x04, // Usage (Joystick)
0xA1, 0x01, // Collection (Application)
// Joystick 1 & 2 Buttons (10 buttons total)
0x05, 0x09, // Usage Page (Button)
0x19, 0x01, // Usage Minimum (Button 1)
0x29, 0x0A, // Usage Maximum (Button 10)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x75, 0x01, // Report Size (1)
0x95, 0x0A, // Report Count (10)
0x81, 0x02, // Input (Data, Var, Abs)
// Padding for buttons (6 bits)
0x75, 0x01, // Report Size (1)
0x95, 0x06, // Report Count (6)
0x81, 0x03, // Input (Cnst, Var, Abs)
// Mouse X/Y (Relative)
0x05, 0x01, // Usage Page (Generic Desktop)
0x09, 0x01, // Usage (Pointer)
0xA1, 0x00, // Collection (Physical)
0x09, 0x30, // Usage (X)
0x09, 0x31, // Usage (Y)
0x15, 0x81, // Logical Minimum (-127)
0x25, 0x7F, // Logical Maximum (127)
0x75, 0x08, // Report Size (8)
0x95, 0x02, // Report Count (2)
0x81, 0x06, // Input (Data, Var, Rel)
0xC0, // End Collection
0xC0 // End Collection
};
// Configuration Descriptor
const uint8_t config_desc[] = {
9, // bLength
USB_DESC_CONFIGURATION,
34, 0, // wTotalLength (9+9+9+7)
1, // bNumInterfaces
1, // bConfigurationValue
0, // iConfiguration
0x80, // bmAttributes (Bus Powered)
250, // bMaxPower (500mA)
// Interface Descriptor
9, // bLength
USB_DESC_INTERFACE,
0, // bInterfaceNumber
0, // bAlternateSetting
1, // bNumEndpoints
0x03, // bInterfaceClass (HID)
0x00, // bInterfaceSubClass
0x00, // bInterfaceProtocol
0, // iInterface
// HID Descriptor
9, // bLength
USB_DESC_HID,
0x11, 0x01, // bcdHID (1.11)
0x00, // bCountryCode
1, // bNumDescriptors
USB_DESC_REPORT, // bDescriptorType
sizeof(hid_report_desc), 0, // wItemLength
// Endpoint Descriptor (IN 1)
7, // bLength
USB_DESC_ENDPOINT,
0x81, // bEndpointAddress (IN 1)
0x03, // bmAttributes (Interrupt)
8, 0, // wMaxPacketSize (8 bytes)
10 // bInterval (10ms)
};
#endif /* USB_DESCRIPTORS_H */