ArduinoBLE and Talking to HID devices

A while ago (last November), I was experimenting with ArduinoBLE to see if I could get it to work on a Teensy 4.x (or 3.6) using the USBHost and BT dongle, and I got it working. At the time I was trying to get it to work with XBox One controllers as well as a BLE mouse (Microsoft Surface Mouse) and had some success. At the time I also tested on Nano 33 ble...

So yesterday I wondered about running the same stuff on the UNO R4 Wifi, so I rebased my fork/branch to current stuff, then merged in the changes from the PR for UNO R4 support.
Also ran with my updated Serial.h/cpp files.

In my Fork/branch, I updated the peripheral explorer sketch to be able to build it to look for one of these two devices.

Looks like it is at least limping along.

Found c8:3f:26:b3:ac:16 'Xbox Wireless Controller' 1812
Connecting ...
Connected
Discovering attributes ...
Attributes discovered

Device name: Xbox Wireless Controll
Appearance: 0x0

Service 1800	//Generic Access service
	Characteristic 2a00, properties 0x2, value 0x58626F7820576972656C65737320436F6E74726F6C6C	//Device Name
		Descriptor 2803, value 0x020300002A	//Characteristic
		Descriptor 00002a00-0000-0000-0000-000000000000, value 0x58626F7820576972656C65737320436F6E74726F6C6C
	Characteristic 2a01, properties 0x2, value 0xC403	//Appearance
		Descriptor 2803, value 0x020500012A	//Characteristic
		Descriptor 00002a01-0000-0000-0000-000000000000, value 0xC403
	Characteristic 2a04, properties 0x2, value 0x0A01900100002C01	//Peripheral Preferred Connection Parameters
		Descriptor 2803, value 0x020700042A	//Characteristic
		Descriptor 00002a04-0000-0000-0000-000000000000, value 0x0A01900100002C01
Service 1801	//Generic Attribute service
Service 180a	//Device Information service
	Characteristic 2a29, properties 0x2, value 0x4D6963726F736F6674	//Manufacturer Name String
		Descriptor 2803, value 0x020B00292A	//Characteristic
		Descriptor 00002a29-0000-0000-0000-000000000000, value 0x4D6963726F736F6674
	Characteristic 2a50, properties 0x2, value 0x025E04200B1505	//PnP ID
		Descriptor 2803, value 0x020D00502A	//Characteristic
		Descriptor 00002a50-0000-0000-0000-000000000000, value 0x025E04200B1505
	Characteristic 2a26, properties 0x2, value 0x352E31352E333136382E30	//Firmware Revision String
		Descriptor 2803, value 0x020F00262A	//Characteristic
		Descriptor 00002a26-0000-0000-0000-000000000000, value 0x352E31352E333136382E30
	Characteristic 2a25, properties 0x2, value 0x3033363030303332393035363234	//Serial Number String
		Descriptor 2803, value 0x021100252A	//Characteristic
		Descriptor 00002a25-0000-0000-0000-000000000000, value 0x3033363030303332393035363234
Service 180f	//Battery service
	Characteristic 2a19, properties 0x12, value 0x32	//Battery Level
		Descriptor 2803, value 0x121400192A	//Characteristic
		Descriptor 00002a19-0000-0000-0000-000000000000, value 0x32
		Descriptor 2902, value 0x0000	//Client Characteristic Configuration
Service 1812	//Human Interface Device service
	Characteristic 2a4a, properties 0x2	//HID Information
		Descriptor 2803, value 0x0218004A2A	//Characteristic
		Descriptor 00002a4a-0000-0000-0000-000000000000, value 0x
	Characteristic 2a4c, properties 0x4	//HID Control Point
		Descriptor 2803, value 0x041A004C2A	//Characteristic
		Descriptor 00002a4c-0000-0000-0000-000000000000, value 0x
	Characteristic 2a4b, properties 0x2	//Report Map
		Descriptor 2803, value 0x021C004B2A	//Characteristic
		Descriptor 00002a4b-0000-0000-0000-000000000000, value 0x
	Characteristic 2a4d, properties 0x12	//Report
		Descriptor 2803, value 0x121E004D2A	//Characteristic
		Descriptor 00002a4d-0000-0000-0000-000000000000, value 0x
		Descriptor 2902, value 0x0000	//Client Characteristic Configuration
		Descriptor 2908, value 0x0101	//Report Reference
	Characteristic 2a4d, properties 0xE	//Report
		Descriptor 2803, value 0x0E22004D2A	//Characteristic
		Descriptor 00002a4d-0000-0000-0000-000000000000, value 0x
		Descriptor 2908, value 0x0302	//Report Reference
Service 00000001-5f60-4c4f-9c83-a7953298d40d
	Characteristic 00000002-5f60-4c4f-9c83-a7953298d40d, properties 0x2
		Descriptor 2803, value 0x0226000DD4983295A7839C4F4C605F02000000	//Characteristic
		Descriptor 00000002-5f60-4c4f-9c83-a7953298d40d, value 0x
	Characteristic 00000003-5f60-4c4f-9c83-a7953298d40d, properties 0x2
		Descriptor 2803, value 0x0228000DD4983295A7839C4F4C605F03000000	//Characteristic
		Descriptor 00000003-5f60-4c4f-9c83-a7953298d40d, value 0x
	Characteristic 00000004-5f60-4c4f-9c83-a7953298d40d, properties 0x8
		Descriptor 2803, value 0x082A000DD4983295A7839C4F4C605F04000000	//Characteristic
		Descriptor 00000004-5f60-4c4f-9c83-a7953298d40d, value 0x

Disconnecting ...
Disconnected

Need to review my notes from then including a couple of issues:
XBox One controller - current firmware (BLE) - (peripheral.discoverAttributes fails · Issue #276 · arduino-libraries/ArduinoBLE (github.com)

Lots of Compiler Warnings - At least if I build for a Teensy 4.1 or Micromod · Issue #274 · arduino-libraries/ArduinoBLE (github.com)
Still does have lots of compiler warnings! - Wish someone would go through and resolve them.

I looked at some of them back then and patched a few of them in my fork/branch, some of which are bugs, like: src\utility\L2CAPSignaling.cpp changed:
for(int i; i<6; i++) peerAddress[5-i] = identityAddress->address[i];
to:
for(int i=0; i<6; i++) peerAddress[5-i] = identityAddress->address[i];

Not sure how far I will take this, but my updates are up in the fork/branch:
KurtE/ArduinoBLE at uno_r4_wifi_teensy (github.com)

Back to playing

Is your program running in Arduino UNO R4 now?

Yes the data I showed above was from running on R4 Wifi

Forgot to mention, back in November I discussed some of the issues and the like on a different thread:

ArduinoBLE - trying to connect to XBox One controller and other BLE devices - Using Arduino / Programming Questions - Arduino Forum

That thread was automatically closed, but asked if any interest in the more enhanced peripheral explorer where I tried to show what some of the standard attributes and the like are....

I found a BLE TV remote (G20S PRO BT) that work with ArduinoBLE on Uno R4 WiFi. The remote also works on Giga R1 WiFi and Nano 33 IOT but Uno R4 WiFi is much slower. The "Attributes discovered" step takes about 12 seconds on Uno R4 WiFi versus about 3 seconds on Giga R1 and Nano 33 IOT. The remote appears as a HID keyboard with consumer controls.

More details here: GitHub - controllercustom/BLE_HID_exp: ArduinoBLE HID explorer