使用F1C200S从零制作掌机之USB游戏手柄

一、USB手柄

COIORVIS PC游戏手柄电脑USB FC模拟器经典游戏手柄 安卓手机有线连接单打格斗对打拳皇 经典有线手柄【黄色】

https://item.jd.com/10046453175183.html

image-20240702210549757

插入USB即可自动识别。

# [ 1425.447643] usb 1-1: USB disconnect, device number 7
[ 1427.072155] usb 1-1: new full-speed USB device number 8 using musb-hdrc
[ 1427.275819] usb 1-1: USB disconnect, device number 8
[ 1427.912164] usb 1-1: new full-speed USB device number 9 using musb-hdrc
[ 1428.129207] input:   Android Gamepad as /devices/platform/soc/1c13000.usb/musb-hdrc.1.auto/usb1/1-1/1-1:1.0/0003:0079:181C.0005/input/input7
[ 1428.170743] hid-generic 0003:0079:181C.0005: input: USB HID v1.10 Gamepad [  Android Gamepad] on usb-musb-hdrc.1.auto-1/input0
[ 1428.225910] input:   Android Gamepad System Control as /devices/platform/soc/1c13000.usb/musb-hdrc.1.auto/usb1/1-1/1-1:1.1/0003:0079:181C.0006/input/input8
[ 1428.333248] input:   Android Gamepad Consumer Control as /devices/platform/soc/1c13000.usb/musb-hdrc.1.auto/usb1/1-1/1-1:1.1/0003:0079:181C.0006/input/input9
[ 1428.377856] hid-generic 0003:0079:181C.0006: input: USB HID v1.01 Device [  Android Gamepad] on usb-musb-hdrc.1.auto-1/input1

测试

hexdump /dev/input/event1
# hexdump /dev/input/event1
0000000 05f5 0000 8046 000e 0003 0000 0080 0000
0000010 05f5 0000 8046 000e 0003 0001 0080 0000
0000020 05f5 0000 8046 000e 0003 0002 0080 0000
0000030 05f5 0000 8046 000e 0003 0005 0080 0000
0000040 05f5 0000 8046 000e 0000 0000 0000 0000
0000050 05f7 0000 5fb3 0009 0003 0010 0001 0000
0000060 05f7 0000 5fb3 0009 0000 0000 0000 0000
0000070 05f7 0000 d0a1 000b 0003 0010 0000 0000
0000080 05f7 0000 d0a1 000b 0000 0000 0000 0000
0000090 05f8 0000 bc1f 0004 0003 0010 0001 0000
00000a0 05f8 0000 bc1f 0004 0000 0000 0000 0000
00000b0 05f8 0000 ee99 0006 0003 0010 0000 0000
00000c0 05f8 0000 ee99 0006 0000 0000 0000 0000
00000d0 05f9 0000 1fdd 0004 0003 0010 0001 0000
00000e0 05f9 0000 1fdd 0004 0000 0000 0000 0000
00000f0 05f9 0000 f49c 0005 0003 0010 0000 0000
0000100 05f9 0000 f49c 0005 0000 0000 0000 0000
0000110 05fa 0000 ed65 0001 0003 0010 ffff ffff

按键键值定义和对应关系,使用以下程序测试。

#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/input.h> 
 
 
#define _EV_KEY         0x01    /* button pressed/released */
#define _EV_ABS         0x03    
#define _EV_MSC         0x04   
 
int main() {
    printf("hello, usb hid joystick key test\n");
    int fd = open("/dev/input/event1", O_RDONLY);
    struct input_event e;
    while(1) {
        read(fd, &e, sizeof(e));
        switch(e.type) {
            case _EV_KEY:
                printf("type: %d, code: %d,value: %d, time: %ld\n", e.type, e.code, e.value, e.time);
                break;
            case _EV_ABS:
                printf("type: %d, code: %d,value: %d, time: %ld\n", e.type, e.code, e.value, e.time);
                break;
            case _EV_MSC:
            	printf("type: %d, code: %d,value: %d, time: %ld\n", e.type, e.code, e.value, e.time);
            	break;
            default:
                if(e.type != 0){
                    printf("type:%d, code: %d,value: %d, time: %ld\n",e.type, e.code, e.value, e.time);
                }
        }
    }
    close(fd);
    return 0;
}

#define ABS_HAT0X 0x10

#define ABS_HAT0Y 0x11

https://blog.51cto.com/u_16213568/7903431

二、无线手柄

同USB手柄

三、参考

https://blog.csdn.net/yyz_1987/article/details/132063201

https://www.cnblogs.com/twzy/p/15243838.html

https://whycan.com/t_5139.html

https://blog.csdn.net/yyz_1987/article/details/132063201

相关推荐

  1. 到屎山系列-游戏开发(Day1)

    2024-07-12 01:30:05       28 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-12 01:30:05       49 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-12 01:30:05       53 阅读
  3. 在Django里面运行非项目文件

    2024-07-12 01:30:05       42 阅读
  4. Python语言-面向对象

    2024-07-12 01:30:05       53 阅读

热门阅读

  1. 【Go - 常见的5类函数用法】

    2024-07-12 01:30:05       17 阅读
  2. kotlin flow collect collectLatest 区别

    2024-07-12 01:30:05       19 阅读
  3. 搜维尔科技:触觉反馈数据手套CyberGlove击鼓测试

    2024-07-12 01:30:05       17 阅读
  4. c语言变量修饰词

    2024-07-12 01:30:05       19 阅读
  5. 文心一言使用指南

    2024-07-12 01:30:05       23 阅读
  6. Redis数据同步

    2024-07-12 01:30:05       23 阅读