You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于MSP430 USB API的USB-HID游戏手柄:描述符配置及模拟输入扩展问题

Alright, let's work through getting your 14-channel 16-bit analog input gamepad up and running on the MSP430. I'll break down exactly what you need to adjust in the descriptor settings and code, step by step.


Calculating the HID Report Descriptor Size (report_desc_size_HID0)

To get the correct descriptor size, we need to count the total bytes of every item in your modified HID report descriptor. Each HID descriptor item has a 1-byte prefix (encoding tag, type, and data size) plus the data bytes specified by the size field.

For your adjusted descriptor, let's tally up the bytes:

  • Global items (like UsagePage, ReportSize, LogicalMinimum): Each takes 2 bytes (1-byte prefix + 1-byte data, since all values fit in 1 byte)
  • Local items (like Usage, UsageMinimum): Each takes 2 bytes
  • Main items (like Collection, Input, Output): Each takes 2 bytes, except EndCollection which only takes 1 byte (no data field)

Adding up all items in your modified descriptor gives a total of 88 bytes. So you'll need to update:

#define report_desc_size_HID0 88

in descriptors.h.


Calculating the Input Report Length (report_len_input)

The input report length is the total number of bytes sent to the host, calculated from the Input sections of your descriptor:

  1. 14 channels of 16-bit analog data: 16 bits × 14 = 224 bits = 28 bytes
  2. 32 bits of button data (even though you only use 6 buttons, the descriptor specifies 32 bits): 32 bits = 4 bytes

Adding these gives a total input report length of 32 bytes. Update this value in descriptors.c:

const uint16_t report_len_input = 32;

Additional Required Code Changes

Beyond the descriptor values, you'll need to adjust a few other parts of the code to match your new setup:

  1. Update report structs in USB_gamepad.h:
    Modify the input report struct to hold 14 analog channels and your 6 buttons:
    typedef struct {
        uint16_t analog[14];  // Stores 14 16-bit ADC readings
        uint32_t buttons;     // Bits 0-5 map to your 6 buttons; remaining bits unused
    } USB_Gamepad_InputReport_t;
    
    For the output report (indicators), keep the 16-bit structure but ensure only bits 0-5 are used for your 6 indicators:
    typedef struct {
        uint16_t indicators;  // Bits 0-5 control your 6 LEDs; remaining bits unused
    } USB_Gamepad_OutputReport_t;
    
  2. Adjust macro definitions:
    Update NUM_BUTTONS and NUM_INDICATORS (in descriptors.h or USB_gamepad.h) to 6:
    #define NUM_BUTTONS 6
    #define NUM_INDICATORS 6
    
  3. Update ADC sampling logic:
    In main.c, modify the code that reads ADC values to sample 14 channels instead of 8, and populate the analog array in the input report correctly.
  4. Update button handling:
    Ensure only your 6 physical buttons are mapped to the first 6 bits of the buttons field in the input report.

Validation Steps

Once you've made these changes:

  1. Compile the modified code and flash it to your MSP430 development kit.
  2. Connect the board to a Windows PC.
  3. Open Settings > Bluetooth & devices > Game controllers – your device should appear as a recognized gamepad.
  4. Open the controller's properties to test:
    • Verify all 14 analog axes show changing values when you adjust your inputs.
    • Confirm each button press registers correctly.
    • Check that indicators (LEDs) respond to output commands from the host.

内容的提问来源于stack exchange,提问作者ihish52

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 23:12:46