Skip to content

Instantly share code, notes, and snippets.

@jdmichaud
Last active December 3, 2024 19:19
Show Gist options
  • Save jdmichaud/626e9ff5bb3b92ffb9af3c660be5248f to your computer and use it in GitHub Desktop.
Save jdmichaud/626e9ff5bb3b92ffb9af3c660be5248f to your computer and use it in GitHub Desktop.
Module development
rest
[ 9030.422503] xpad-dbg: 00000000: 00 00 0f 7f 7f 7f 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 9030.422526] xpad-dbg: 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
up
[ 9030.342505] xpad-dbg: 00000000: 00 00 0f 7f 00 7f 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 9030.342529] xpad-dbg: 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
down
[ 9054.410631] xpad-dbg: 00000000: 00 00 0f 7f ff 7f 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 9054.410649] xpad-dbg: 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
left
[ 9066.270984] xpad-dbg: 00000000: 00 00 0f 00 7f 7f 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 9066.271007] xpad-dbg: 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
right
[ 9079.210532] xpad-dbg: 00000000: 00 00 0f ff 7f 7f 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 9079.210550] xpad-dbg: 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
A
[ 9092.799170] xpad-dbg: 00000000: 01 00 0f 7f 7f 7f 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 9092.799193] xpad-dbg: 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
B
[ 9100.298543] xpad-dbg: 00000000: 02 00 0f 7f 7f 7f 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 9100.298561] xpad-dbg: 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
C
[ 9107.358549] xpad-dbg: 00000000: 80 00 0f 7f 7f 7f 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 9107.358567] xpad-dbg: 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
X
[ 9115.378550] xpad-dbg: 00000000: 08 00 0f 7f 7f 7f 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 9115.378569] xpad-dbg: 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Y
[ 9122.599056] xpad-dbg: 00000000: 10 00 0f 7f 7f 7f 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 9122.599078] xpad-dbg: 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Z
[ 9130.991022] xpad-dbg: 00000000: 40 00 0f 7f 7f 7f 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 9130.991044] xpad-dbg: 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Left trigger
[ 9141.859028] xpad-dbg: 00000000: 00 01 0f 7f 7f 7f 7f ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 9141.859052] xpad-dbg: 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Right trigger
[ 9150.838572] xpad-dbg: 00000000: 00 02 0f 7f 7f 7f 7f 00 ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 9150.838590] xpad-dbg: 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Star
[ 9159.718560] xpad-dbg: 00000000: 00 00 0f 7f 7f 7f 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 9159.718576] xpad-dbg: 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Bar
[ 9167.419042] xpad-dbg: 00000000: 00 04 0f 7f 7f 7f 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 9167.419064] xpad-dbg: 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Heart
[ 9175.578583] xpad-dbg: 00000000: 04 00 0f 7f 7f 7f 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 9175.578602] xpad-dbg: 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

reference: https://ladis.cloud/blog/posts/firmware-update-8bitdo.html

To get the list of firmware for a particular joystick

curl -X POST -H 'Type: 23' -H 'Beta: 1' http://dl.8bitdo.com:8080/firmware/select

The types corresponds to:

Gamepad Type
Arcade Stick 34
Arcade Stick Receiver 35
F30 GamePad 2
F30 Arcade Stick 5
F30 Pro 1
Lite GamePad 28
M30 23
N30 GamePad 2, 10
N30 NS GamePad 18
N30 Pro 1
N30 Pro 2 13
Pro 2 33
Pro 2 Wired 37
SF30 Pro 9
SN30 GamePad 3,17
SN30 Pro+ 25
SN30 Pro 9

The filePathName fields gives the url path to use:

curl -OL http://dl.8bitdo.com:8080/firmwareFile/upload/090523b7-4ddf-4c3a-ab61-5388e398800a.dat

To upload the firmware on the joystick, start your gamepad by holding down L(1)+R(1)+START for 3 seconds. A status LED on the gamepad should now blink red. Then connect the gamepad to the computer with a USB cable. Get the device ID with:

fwupdmgr get-devices

Then with XXX as the ID, update the firmware with:

fwupdtool install-blob cab12b12-8e01-472f-a9f4-ec2237c598b9.dat XXX
  • Modify xpad so that the vendorId and productId of the M30 in D-pad mode are accepted.
  • Build in insert with:
sudo dkms build -m xpad -v 0.4 --force && \
  sudo dkms install -m xpad -v 0.4 --force && \
  sudo rmmod xpad && \
  sudo modprobe xpad
  • When M30 is connected, when the module is inserted, the probe function is called and the device is recognized:
[43918.320118] usbcore: deregistering interface driver xpad
[43918.370512] xpad_probe begins 0x2dc8 0x5006
[43918.370521] xpad_init_input begins
[43918.370622] input: 8BitDo M30 Bluetooth as /devices/pci0000:00/0000:00:08.1/0000:0b:00.3/usb5/5-3/5-3.4/5-3.4:1.0/input/input65
[43918.370753] xpad_init_input ends
[43918.370778] usbcore: registered new interface driver xpad
[43918.372101] input input65: unable to receive magic message: -121
[43918.426323] xpad-dbg: 00000000: 33 06 5f 0d 00 00 00 ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[43918.426334] xpad-dbg: 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[43918.427096] input input65: unable to receive magic message: -121
[43918.456101] input input65: unable to receive magic message: -121
[43918.476102] input input65: unable to receive magic message: -121
  • When M30 is disconnected and reconnected, the xpad module is not bound and the probe function is not called. The M30 is recognized as a HID device but no module is associated to it.
[46801.777213] usb 5-3.4: new full-speed USB device number 23 using xhci_hcd
[46801.879498] usb 5-3.4: New USB device found, idVendor=2dc8, idProduct=5006, bcdDevice= 0.01
[46801.879510] usb 5-3.4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[46801.879515] usb 5-3.4: Product: 8BitDo M30 gamepad
[46801.879519] usb 5-3.4: Manufacturer: 8Bitdo 
[46801.948913] input: 8Bitdo  8BitDo M30 gamepad as /devices/pci0000:00/0000:00:08.1/0000:0b:00.3/usb5/5-3/5-3.4/5-3.4:1.0/0003:2DC8:5006.001B/input/input66
[46801.949158] hid-generic 0003:2DC8:5006.001B: input,hidraw8: USB HID v1.11 Gamepad [8Bitdo  8BitDo M30 gamepad] on usb-0000:0b:00.3-3.4/input0
  • When the binding is forced, the M30 is sometimes recongnized and sometimes not.
sudo sh -c 'echo -n "5-3.4:1.0" > /sys/bus/usb/drivers/xpad/bind'
  • Download the module sources
  • The folder containing the source must be named ${module}-${version} (e.g.: xpad-0.4)
  • The folder must contain a dkms.conf file
  • Add the module (we assume the source to be in /home/user/project/${module}-${version}):
sudo dkms add -m ${module} -v ${version} --sourcetree /home/user/project/
  • To build:
sudo dkms build -m ${module} -v ${version} --sourcetree /home/user/project/

note that sourcetree option points to the parent directory.

  • Install your module:
sudo dkms install -m ${module} -v ${version} --sourcetree /home/user/project/
  • check that depmod is pointing at your module:
sudo depmod -v | grep ${module}
  • Remove the previous module if need be and install the new one:
sudo rmmod ${module} && sudo modprobe ${module}
  • If the compilation fails, you can look at the logs:
less /var/lib/dkms/#{module}/${version}/${kernel_version}/${arch}/log/make.log
  • When a change is made to the source:
sudo dkms build -m ${module} -v ${version} --force
sudo dkms install -m ${module} -v ${version} --force
sudo rmmod ${module} && sudo modprobe ${module}
[42889.648752] TCP: request_sock_TCP: Possible SYN flooding on port 0.0.0.0:24800. Sending cookies.
[43254.361322] usb 5-3.4: new full-speed USB device number 12 using xhci_hcd
[43254.481101] usb 5-3.4: New USB device found, idVendor=0079, idProduct=0011, bcdDevice= 1.00
[43254.481113] usb 5-3.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[43254.481118] usb 5-3.4: Product: Retro-bit Controller
[43254.481122] usb 5-3.4: Manufacturer: SWITCH CO.,LTD.
[43254.481126] usb 5-3.4: SerialNumber: GH-SP-5027-1 H2
[43254.569594] input: SWITCH CO.,LTD. Retro-bit Controller as /devices/pci0000:00/0000:00:08.1/0000:0b:00.3/usb5/5-3/5-3.4/5-3.4:1.0/0003:0079:0011.0013/input/input39
[43254.569870] dragonrise 0003:0079:0011.0013: input,hidraw7: USB HID v1.11 Joystick [SWITCH CO.,LTD. Retro-bit Controller] on usb-0000:0b:00.3-3.4/input0
[43268.513468] usb 5-3.4: USB disconnect, device number 12
[43268.953808] usb 5-3.4: new full-speed USB device number 13 using xhci_hcd
[43269.054654] usb 5-3.4: New USB device found, idVendor=045e, idProduct=028e, bcdDevice= 5.72
[43269.054666] usb 5-3.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[43269.054671] usb 5-3.4: Product: SEGA Controller
[43269.054675] usb 5-3.4: Manufacturer: SWITCH CO.,LTD.
[43269.054679] usb 5-3.4: SerialNumber: GH-SP-5027-1 H2
[43269.122109] input: Microsoft X-Box 360 pad as /devices/pci0000:00/0000:00:08.1/0000:0b:00.3/usb5/5-3/5-3.4/5-3.4:1.0/input/input40
[43319.968995] usb 5-3.4: USB disconnect, device number 13
[43319.969164] xpad 5-3.4:1.0: xpad_try_sending_next_out_packet - usb_submit_urb failed with result -19
[43320.664317] usb 5-3.4: new full-speed USB device number 14 using xhci_hcd
[43320.766297] usb 5-3.4: New USB device found, idVendor=0079, idProduct=0011, bcdDevice= 1.00
[43320.766309] usb 5-3.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[43320.766314] usb 5-3.4: Product: Retro-bit Controller
[43320.766318] usb 5-3.4: Manufacturer: SWITCH CO.,LTD.
[43320.766321] usb 5-3.4: SerialNumber: GH-SP-5027-1 H2
[43320.840459] input: SWITCH CO.,LTD. Retro-bit Controller as /devices/pci0000:00/0000:00:08.1/0000:0b:00.3/usb5/5-3/5-3.4/5-3.4:1.0/0003:0079:0011.0014/input/input41
[43320.840780] dragonrise 0003:0079:0011.0014: input,hidraw7: USB HID v1.11 Joystick [SWITCH CO.,LTD. Retro-bit Controller] on usb-0000:0b:00.3-3.4/input0
  • Update firmware state: L+R+Start
  • D-input mode (Android mode): B+Start
  • X-input mode (Windows mode): X+Start
  • Switch mode: Y+Start
  • MacOS mode: A+Start

D-pad configuration:

  • Minus button + D-pad up = D-pad control.
  • Minus button + D-pad left = Left stick control.
  • Minus button + D-pad right = Right stick control.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment