Guest User

Keyboard HID for Pi Zero W

a guest
Dec 15th, 2022
730
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.33 KB | Source Code | 0 0
  1. #!/bin/bash
  2.  
  3. ##
  4. # Addapted from https://www.rmedgar.com/blog/using-rpi-zero-as-keyboard-setup-and-device-definition/
  5. ##
  6.  
  7. cd /sys/kernel/config/usb_gadget/
  8. mkdir mykeyboard
  9. cd mykeyboard
  10.  
  11. echo 0x1d6b > idVendor # Linux Foundation
  12. echo 0x0104 > idProduct # Multifunction Composite Gadget
  13. echo 0x0100 > bcdDevice # v1.0.0
  14. echo 0x0200 > bcdUSB # USB2
  15.  
  16. # Define this for a UK keyboard layout
  17. mkdir -p strings/0x409
  18.  
  19. echo "987651234" > strings/0x409/serialnumber
  20. echo "Reddit Post" > strings/0x409/manufacturer
  21. echo "USB Device" > strings/0x409/product
  22. mkdir -p configs/c.1/strings/0x409
  23. echo "Config 1: ECM network" > configs/c.1/strings/0x409/configuration
  24. echo 250 > configs/c.1/MaxPower
  25.  
  26. # functions
  27. mkdir -p functions/hid.usb0
  28. echo 1 > functions/hid.usb0/protocol
  29. echo 1 > functions/hid.usb0/subclass
  30. echo 8 > functions/hid.usb0/report_length
  31. echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > functions/hid.usb0/report_desc
  32.  
  33. # Link HID function to the configuration
  34. ln -s functions/hid.usb0 configs/c.1/
  35.  
  36. # Activate the device
  37. ls /sys/class/udc > UDC
  38.  
Advertisement
Add Comment
Please, Sign In to add comment