This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] MSP430F5510:MSP430F5510:具有 MSP430 USB API 的 USB-HID 游戏手柄控制器

Guru**** 2042910 points
Other Parts Discussed in Thread: MSP430F5529
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1017677/msp430f5510-msp430f5510-usb-hid-gamepad-joystick-controller-with-msp430-usb-api

器件型号:MSP430F5529

各位专家、您好!

我目前正在尝试使用 USB-HID 在 Windows 10上模拟游戏手柄/游戏手柄。 MSP430将采用7-14个模拟输入并将其发送到 Windows、在 Windows 中它们将被视为 USB-HID 游戏控制器输入。

我正在处理 MSP430 USB API 中的 H7_Mouse 示例、因为没有用于传统游戏控制器的示例代码。 描述符是使用 USB-IF 的 HID 描述符工具创建的,然后粘贴到 TI USB 描述符工具中,以在 USB_config 文件夹中创建必要的描述符.c/h。  我正在使用 USB 描述符(如下所示)作为简单的4轴16按钮游戏手柄开始使用。  

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x05, // USAGE (Game Pad)
0xA1, 0x01, // COLLECTION (Application)
0xA1, 0x00, // COLLECTION (Physical)
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x10, // USAGE_MAXIMUM (Button 16)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x95, 0x10, // REPORT_COUNT (16)
0x75, 0x01, // REPORT_SIZE (1)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x30, // USAGE (X)
0x09, 0x31, // USAGE (Y)
0x09, 0x32, // USAGE (Z)
0x09, 0x33, // USAGE (Rx)
0x15, 0x81, // LOGICAL_MINIMUM (-127)
0x25, 0x7F, // LOGICAL_MAXIMUM (127)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x04, // REPORT_COUNT (4)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

main.c 文件(通过鼠标示例进行了细微编辑、以适应新的 HID 报告结构)如下所示:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
* ======== main.c ========
* Mouse HID Demo:
*
* This example functions as a mouse on the host. It causes the mouse pointer
* to move in a circular pattern on the screen. Simply build and run the
* example. To re-gain control of the mouse, unplug USB.
* Unlike the HID-Datapipe examples, this one does not communicate with the
* HID Demo Application
*
+----------------------------------------------------------------------------+
* Please refer to the Examples Guide for more details.
*----------------------------------------------------------------------------*/
#include <string.h>
#include "driverlib.h"
#include "USB_config/descriptors.h"
#include "USB_API/USB_Common/device.h"
#include "USB_API/USB_Common/usb.h" // USB-specific functions
#include "USB_API/USB_HID_API/UsbHid.h"
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

使用上述代码和描述符、Windows 使用正确的输入将 MSP430正确识别为游戏 epad -可在"控制面板\设置 USB 游戏控制器"下看到。 但是、当单击同一页上的"属性"并测试输入时(代码会定期将每个输入值递增1)、Windows 不会从控制器记录可见的按钮按压/操纵杆响应。 我尝试使用 USB API 中的 Java_HID_Demo 工具来查看是否可以通过查看发送的原始数据来调试问题、但软件无法连接到传统的 USB-HID 设备、即使 Windows 将其识别为游戏 epad。

描述符文件也在此处提供完整参考:

descriptors.h

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* --COPYRIGHT--,BSD
* Copyright (c) 2015, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

-描述符.c

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* --COPYRIGHT--,BSD
* Copyright (c) 2015, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

使用实例

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* --COPYRIGHT--,BSD
* Copyright (c) 2015, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好,Hishan,

    让我看看我是否能找到能够提供帮助的人。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好,Hishan,

    我对这个没有运气、所以让我看看我是否可以设置一些东西来模拟您尝试的东西。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    器件型号:MSP430F5529

    各位专家、您好!

    几周前、我尝试使用具有7-14个模拟输入的 MSP430来模拟 USB-HID 游戏。 我在为定制的 USB-HID 设备获取描述符时遇到问题。 我发布了我的代码、但没有人能帮助我。

    幸运  的是、我在网上看到了这个代码:GitHub - TI-FIRST /MSP430-Gamead:适用于 FRC 的 MSP430F5529 Gamead 代码、它帮助我启动 MSP430并将其作为具有8个模拟输入的游戏 epad 运行。

    main.c 文件包含更改报告结构的说明:  

    *此示例在主机上充当游戏 epad。 游戏手柄具有 HID 报告、如所述
    * descriptors.c 中的 REPORT_desc_HID0变量 请注意、如果是此报告结构
    *已更改、则需要更新以下长度-
    * 1. descriptors.h 中的#define REPORT_desc_size_HID0需要使用描述符大小进行更新
    * 2. 需要在描述符.c 中更新 REPORT_desc_size 和 REPORT_len_input
    *本演示将枚举18个字节的输入报告和2个字节的输出报告
    *游戏 epad 的输入和输出报告结构,如 USB_gamepad.h 中所述
    *输入报告用于报告 ADC 值和按钮状态(GPIO)
    *输出报告用于设置/复位指示器(GPIO)

    目前在 descriptors.c 文件中的描述符是:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    UsagePage(USB_HID_GENERIC_DESKTOP),
    Usage(USB_HID_JOYSTICK),
    Collection(USB_HID_APPLICATION),
    //
    // The axis for the controller.
    //
    UsagePage(USB_HID_GENERIC_DESKTOP),
    Usage (USB_HID_POINTER),
    Collection (USB_HID_PHYSICAL),
    //
    // The X, Y and Z values which are specified as 8-bit absolute
    // position values.
    //
    Usage (USB_HID_X),
    Usage (USB_HID_Y),
    Usage (USB_HID_Z),
    Usage (USB_HID_RX),
    Usage (USB_HID_RY),
    Usage (USB_HID_RZ),
    Usage (USB_HID_SLIDER),
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    我想将其更改为14个16位模拟输入、如下所示:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    UsagePage(USB_HID_GENERIC_DESKTOP),
    Usage(USB_HID_JOYSTICK),
    Collection(USB_HID_APPLICATION),
    //
    // The axis for the controller.
    //
    UsagePage(USB_HID_GENERIC_DESKTOP),
    Usage (USB_HID_POINTER),
    Collection (USB_HID_PHYSICAL),
    //
    // The X, Y and Z values which are specified as 8-bit absolute
    // position values.
    //
    Usage (USB_HID_X),
    Usage (USB_HID_Y),
    Usage (USB_HID_Z),
    Usage (USB_HID_RX),
    Usage (USB_HID_RY),
    Usage (USB_HID_RZ),
    Usage (USB_HID_SLIDER),
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    但是、我不知道如何计算描述符的长度/大小/字节。 我尝试了 USB-HID 规范(HID 1.11的器件类定义| USB-IF)、该规范指出项目具有字节前缀、但我无法确定要计数的项目以及它们的累加方式。 抱歉、我在 USB 方面经验不足。

    我认为描述符的大小是32字节? 但计算机在插入时未检测到游戏手柄、因为我认为 我在 report_len_input 中得到的值是错误的。

    是否有人能够查看代码、并让我知道 描述符文件中 REPORT_desc_size、REPORT_len_input 以及我需要更改的任何其他值、以扩展14个16位模拟输入的代码功能。

    P.S.要复制和查看正在工作的游戏 epad、只需将代码上传到开发套件并在 Windows 上搜索"设置 USB 游戏控制器"、如果一切运行正常且报告被接受、则应将其识别为游戏 epad。



    谢谢!

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好,Hishan,

    我将您的帖子合并在一起、因为它们实际上与同一个主题有关。  

    对于 HID、我们的 USB 开发包和描述符工具本身仅支持一些 HID 类型、即键盘、鼠标和数据擦除。 任何其他"传统"HID 类型都需要通过描述符工具中的"自定义"功能来完成、您需要在该工具中输入原始报告描述符。 我们目前无法支持您创建此自定义描述符以满足您的需求。 我建议查看第三方资源或指南、了解描述符报告对于您所选 HID 类型的外观。  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    大家好、

    我正在加入本次对话、因为我们遇到了与此非常类似的问题。  

    由于这个 USB 描述符工具是 TI 特有的、所以我很难理解如果您无法帮助我们、我们如何获得支持? 您能否向我介绍有关第三方资源、推荐阅读或指南、以了解我们如何在该问题上获得额外支持?

    谢谢

    垫  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    大家好、

    USB 描述符工具是 TI 制作的、用于帮助您在使用的 PC 上正确获取支持的 HID 类型。 我们允许自定义类别扩展到本机不支持的 HID 类类型。 游戏手柄/游戏手柄属于此类别。 您可以通过 USB HID 规范或其他在线论坛找到此类的正确描述符字段。 stackexchange 是一个查看一般知识的好论坛、430h.com 是一个独立的 MSP430特定论坛、您可以在其中找到所需的内容。