How to read raw data packets from usb host port ?

kamil.szu

Member
Hi. So I wonder how to do it, because I have plugged in ps3 controller and what I want to do is to retransmit to usb serial, if that makes any sense, because I haven't done anything with usb protocol. And I'm trying this code and rawHid gets nothing. Is RawHIDController something different what I think it is ? Like some kind of special device, instead of abstraction for reading raw hid data from device ?

C++:
#include "USBHost_t36.h"
USBHost myusb;
USBHub hub1(myusb);
USBHIDParser hid1(myusb);
RawHIDController rawhid1(myusb);
JoystickController joystick(myusb);
void setup() {
  Serial1.begin(2000000);
 
  while (!Serial) ; // wait for Arduino Serial Monitor
  Serial.println("\n\nUSB Host Joystick Testing");
  rawhid1.attachReceive(OnReceiveHidData);
  myusb.begin();
}
void loop() {
  myusb.Task();
  const uint8_t *psz = joystick.manufacturer();
  if (psz && *psz) Serial.printf(" joystick manufacturer: %s\n", psz);
 
  const uint8_t *psz2 = rawhid1.manufacturer();
  if (psz2 && *psz2) Serial.printf(" raw manufacturer: %s\n", psz);
  delay(50);
}
bool OnReceiveHidData(uint32_t usage, const uint8_t *data, uint32_t len) {
  Serial.printf("OnReceiveHidData");
  return true;
}
 
Last edited:
I'm looking now sample HIDDeviceInfo and there is the code, but how do I know if I'm not processing again the same packet. Api would be much more friendly if HidParser had callback function, because looking at source code invoking those method will keep old buffer value
C++:
const uint8_t * getHIDReportDescriptor() {return _bigBuffer;}

C++:
void HIDDumpController::dumpHIDReportDescriptor(USBHIDParser *phidp) {
  const uint8_t *p = phidp->getHIDReportDescriptor();
  uint16_t report_size = phidp->getHIDReportDescriptorSize();
  const uint8_t *pend = p + report_size;
 
Back
Top