I’m trying to replicate a USB device (3Dconnexion SpaceMouse) using an ESP32-S2 Mini.
I’ve managed to get it to show up as a genuine SpaceMouse; however, I’m struggling to send any commands.
I’ve found that the USB configuration is not the same.
In the image below, the left side is what I have, and the right side is the SpaceMouse that is working. The Interfaces seem to be in the wrong order, how can I change them to match the original?

This is the code I am referencing, it is made for a pro-micro, so I am trying to convert it for esp32 https://github.com/AndunHH/spacemouse/b ... MouseHID.h
Below is the main file, but the whole repo can be found here https://github.com/Boom123bam/esp32-s2mini-spacemouse
Code: Select all
#ifndef ARDUINO_USB_MODE
#error This ESP32 SoC has no Native USB interface
#elif ARDUINO_USB_MODE == 1
#warning This sketch should be used when USB is in OTG mode
void setup() {}
void loop() {}
#else
#include <Arduino.h>
#include "USB.h"
#include "USBHID.h"
#include "SpaceMouseTypes.h"
#include "SpaceMouseDevice.h"
#define USB_VID 0X256F
#define USB_PID 0xC631
#define USB_MANUFACTURER "3Dconnexion"
#define USB_PRODUCT "SpaceMouse Pro Wireless (cabled)"
#define USB_SERIAL "C"
#include "USB.cpp"
SpaceMouseDevice SpaceMouse;
// Simulated SpaceMouse data
int16_t motionData[6] = {0, 0, 0, 0, 0, 0};
uint8_t buttonKeys[32] = {0}; // Array for 32 buttons
const int buttonPin = 0;
void setup() {
// Configure USB HID
USB.usbClass(0xEF); // Device class: Miscellaneous (0xEF)
USB.usbSubClass(0x02); // Subclass: Common class (0x02)
USB.usbProtocol(0x01); // Interface Association Descriptor (0x01)
USB.usbVersion(0x0200); // USB 2.0 (0x0200) not 1.1
USB.usbVersion(0x0100); // 1.0 (0x0100 = 256 decimal)
USB.usbAttributes(0xA0);
pinMode(buttonPin, INPUT_PULLUP);
SpaceMouse.begin();
USB.begin();
delay(1000);
// Serial.begin(115200);
// Serial.println("SpaceMouse Emulator Started");
// Serial.print("Report descriptor size: ");
// Serial.println(sizeof(report_descriptor));
// Serial.print("Endpoint size: ");
// Serial.println(USB_EP_SIZE);
}
void loop() {
static unsigned long lastUpdate = 0;
// Update motion data
motionData[0]++; // X
if (motionData[0] > 90){
motionData[0] = -90;
}
motionData[1] = 0; // Y
motionData[2] = 0; // Z
motionData[3] = 0; // Rx
motionData[4] = 0; // Ry
motionData[5] = 0; // Rz
// Check button state (example - button 1 on pin 0)
memset(buttonKeys, 0, 32);
if (digitalRead(buttonPin) == LOW) {
buttonKeys[0] = 1; // Button 1 pressed
}
// Use the new send_command function with state machine
bool dataSent = SpaceMouse.send_command(
motionData[3], motionData[4], motionData[5], // Rx, Ry, Rz
motionData[0], motionData[1], motionData[2], // X, Y, Z
buttonKeys, 0 // keys array, no debug
);
delay(1);
}
#endif /* ARDUINO_USB_MODE */