尝试将RPi Zero W用作USB键盘

时间:2018-11-28 20:22:27

标签: raspberry-pi usb

我正在为此练习使用RPi ZeroW。我下载了2018-11-13-raspbian-stretch-full.zip并将其安装到32G microSD卡上:

sudo dd bs=4M if=2018-11-13-raspbian-stretch-full.img of=/dev/mmcblk0

使用上述microSD卡启动了我的RPi Zero W,并立即更新系统:

apt-get update

在/ etc / modules的末尾添加了以下两行:

dwc2
libcomposite

然后执行以下shell脚本:

#!/bin/sh

# Create gadget
mkdir /sys/kernel/config/usb_gadget/mykeyboard
cd /sys/kernel/config/usb_gadget/mykeyboard

# Add basic information
echo 0x0100 > bcdDevice # Version 1.0.0
echo 0x0200 > bcdUSB # USB 2.0
echo 0x00 > bDeviceClass
echo 0x00 > bDeviceProtocol
echo 0x00 > bDeviceSubClass
echo 0x08 > bMaxPacketSize0
echo 0x0104 > idProduct # Multifunction Composite Gadget
echo 0x1d6b > idVendor # Linux Foundation

# Create English locale
mkdir strings/0x409

echo "My manufacturer" > strings/0x409/manufacturer
echo "My virtual keyboard" > strings/0x409/product
echo "0123456789" > strings/0x409/serialnumber

# Create HID function
mkdir functions/hid.usb0

echo 1 > functions/hid.usb0/protocol
echo 8 > functions/hid.usb0/report_length # 8-byte reports
echo 1 > functions/hid.usb0/subclass

# Write report descriptor
echo "05010906a101050719e029e71500250175019508810275089501810175019503050819012903910275019505910175089506150026ff00050719002aff008100c0" | xxd -r -ps > functions/hid.usb0/report_desc

# Create configuration
mkdir configs/c.1
mkdir configs/c.1/strings/0x409

echo 0x80 > configs/c.1/bmAttributes
echo 200 > configs/c.1/MaxPower # 200 mA
echo "Example configuration" > configs/c.1/strings/0x409/configuration

# Link HID function to configuration
ln -s functions/hid.usb0 configs/c.1

# Enable gadget
ls /sys/class/udc > UDC

然后我将RPi Zero插入我的Fedora 29笔记本电脑中,并希望在执行以下命令时看到RPi出现: lsusb -t 与设备(我的RPi Zero)与 Class = Human Interface Device 一起显示。

除了我已知的设备外,什么都没有显示。

我知道这是ConfigFS中的一个练习,以及如何使用它将您的Micro-micro-Linus主板变成“ USB小工具”。

有什么建议吗?

0 个答案:

没有答案