1.现象
1.开发板无法识别北通无线游戏手柄
北通蝙蝠BD2A无线游戏手柄
lsusb
Bus 007 Device 003: ID 045e:028e Microsoft Corp. Xbox360 Controller
ls /dev/input
by-id by-path event0 event1 event2 event3 event4 event5 event6
没有识别到js0设备
2.ubuntu系统可以到input设备
ls /dev/input
by-id by-path event0 event1 event2 event3 event4 event5 event6 js0
2.解决方法:
开发板内核配置xbox手柄
CONFIG_INPUT_JOYDEV=y
CONFIG_INPUT_JOYSTICK=y
CONFIG_JOYSTICK_SIDEWINDER=y
CONFIG_JOYSTICK_XPAD=y
CONFIG_JOYSTICK_XPAD_FF=y
CONFIG_JOYSTICK_XPAD_LEDS=y
重新编译内核
更新kernel boot.img
插入北通无线游戏手柄,ls /dev/input 识别到js[x]设备
ls /dev/input
by-id by-path event0 event1 event2 event3 event4 event5 event6 js0
3.原理反推
方法1:
找到代码
ok3588-linux-source/kernel$ find -name Makefile|xargs grep JOYSTICK_XPAD
./drivers/input/joystick/Makefile:obj-$(CONFIG_JOYSTICK_XPAD) += xpad.o
xpad.c
usb pid:vid 045e:028e设备枚举
static const struct xpad_device {u16 idVendor;u16 idProduct;char *name;u8 mapping;u8 xtype;
} xpad_device[] = {{ 0x045e, 0x0289, "Microsoft X-Box pad v2 (US)", 0, XTYPE_XBOX },{ 0x045e, 0x028e, "Microsoft X-Box 360 pad", 0, XTYPE_XBOX360 },{ 0x045e, 0x028f, "Microsoft X-Box 360 pad v2", 0, XTYPE_XBOX360 },
};
usb设备注册input设备
xpad_probe()
{for (i = 0; xpad_device[i].idVendor; i++) {if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) &&(le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct))break;}xpad = kzalloc(sizeof(struct usb_xpad), GFP_KERNEL);if (!xpad)return -ENOMEM;usb_make_path(udev, xpad->phys, sizeof(xpad->phys));strlcat(xpad->phys, "/input0", sizeof(xpad->phys));
}
具体过程可以看usb设备枚举过程文章,书籍.
方法2: 由于ubuntu 系统能识别, 即linux kernel默认支持.
内核代码搜索usb pid
grep --include=*.c --binary-files=without-match -rn --colour=auto 028e
fs/exfat/nls.c:105: 0x01ae, 0x0244, 0x01b1, 0x01b2, 0x0245, 0x028d, 0x028e, 0x028f,
fs/cifs/netmisc.c:761: ERRDOS, ERRnoaccess, 0xc000028e}, {
drivers/input/joystick/xpad.c:125: { 0x045e, 0x028e, “Microsoft X-Box 360 pad”, 0, XTYPE_XBOX360 },
开启xpad.c对应CONFIG_JOYSTICK_XPAD
make ARCH=arm64 menuconfig
开启内核依赖配置.