A
Arduino4mo ago
arden

Unable to report value over USB

Hi everyone, I've been trying to teach myself how to create USB HID devices and I've gotten to the point of creating my own descriptor and having get sent sucsessfully over usb for the host to understand what my device does. The problem I'm having now is trying to report data to the computer. Maybe I'm doing something wrong and IU just dont see it or its something else. Thanks for anyones help! IDE 2.3.4 Leonardo
#include <HID.h>
#include <math.h>

// Your original descriptor
static const uint8_t _testDescriptor[] PROGMEM = {
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x04, // USAGE (Mouse)
0xA1, 0x01, // COLLECTION (Application)
0x09, 0x01, // USAGE (Pointer)
0xA1, 0x00, // COLLECTION (Physical)

// 3 Buttons
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x08, // USAGE_MAXIMUM (Button 8)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x95, 0x08, // REPORT_COUNT (8)
0x75, 0x01, // REPORT_SIZE (1)
0x81, 0x02, // INPUT (Data,Var,Abs)

// X and Y movement
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
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
};

// Wrap descriptor in the HID library’s sub-descriptor type
static HIDSubDescriptor node(_testDescriptor, sizeof(_testDescriptor));

typedef struct {
uint8_t buttons;
int8_t x;
int8_t y;
} report;

double asdf = 0.0;

void setup() {
// Hook our custom descriptor into the USB stack
HID().AppendDescriptor(&node);

}

void loop() {
double asdfa = sin(asdf);
asdf += 0.5;

report rpt;
rpt.buttons = 0; // no buttons pressed
rpt.x = asdfa; // relative move
rpt.y = 0;

// Send the 3-byte report (report ID = 0)
HID().SendReport(0, &rpt, sizeof(rpt));
}
#include <HID.h>
#include <math.h>

// Your original descriptor
static const uint8_t _testDescriptor[] PROGMEM = {
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x04, // USAGE (Mouse)
0xA1, 0x01, // COLLECTION (Application)
0x09, 0x01, // USAGE (Pointer)
0xA1, 0x00, // COLLECTION (Physical)

// 3 Buttons
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x08, // USAGE_MAXIMUM (Button 8)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x95, 0x08, // REPORT_COUNT (8)
0x75, 0x01, // REPORT_SIZE (1)
0x81, 0x02, // INPUT (Data,Var,Abs)

// X and Y movement
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
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
};

// Wrap descriptor in the HID library’s sub-descriptor type
static HIDSubDescriptor node(_testDescriptor, sizeof(_testDescriptor));

typedef struct {
uint8_t buttons;
int8_t x;
int8_t y;
} report;

double asdf = 0.0;

void setup() {
// Hook our custom descriptor into the USB stack
HID().AppendDescriptor(&node);

}

void loop() {
double asdfa = sin(asdf);
asdf += 0.5;

report rpt;
rpt.buttons = 0; // no buttons pressed
rpt.x = asdfa; // relative move
rpt.y = 0;

// Send the 3-byte report (report ID = 0)
HID().SendReport(0, &rpt, sizeof(rpt));
}
2 Replies
Tuuli 🎹🎸🤘
Did you get it working? Mixxx is open source DJ software, a lot of its written in C and it has HID USB device support. Just a thought that studying its code might be helpful if you have no examples. Though a tutorial for HID would be best.
arden
ardenOP4mo ago
Unfortunately I haven’t gotten it to work, but I’ll check out Mixxx

Did you find this page helpful?