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.

[参考译文] MSP430F5527:修改 MPS430键盘项目:将消费类控制报告使用 ID 从8位改为16位

Guru**** 2454880 points


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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1475749/msp430f5527-modifying-mps430-keyboard-project-changing-consumer-control-report-usage-id-from-8-bit-to-16-bit

器件型号:MSP430F5527
主题中讨论的其他器件:HID2

工具与软件:

您好!  

我目前使用的是基于 MPS430的示例键盘项目、需要一些关于修改代码的指导。 该项目使用消费者报告与 Windows 进行交互、我想将使用 ID 从8位更改为16位值、以适应更多的使用 ID。

我使用的是原始库、想知道处理从8位到16位使用 ID 转换的最佳方法。  

我目前已缩小对以下 HID2报告描述符和相关大小的修改范围

#define report_desc_size_HID2 51

uint8_t const report_desc_HID2[]=
{
    0x05, 0x0C,               // Usage Page (Consumer)
    0x09, 0x01,               // Usage (Consumer Control)
    0xA1, 0x01,               // Collection (Application)
    0x85, 0x03,               // Report Id 
    0x75, 0x01,               // Report Size (1)
    0x95, 0x01,               // Report Count (1)     
    0x15, 0x00,               // Logical Minimum (0)
    0x25, 0x01,               // Logical Maximum (1)  
    0x09, 0xE9,               // Usage (Volume Increment)
    0x81, 0x06,               // Input(Data, Value, Relative, BitField) Bit0
    0x09, 0xEA,               // Usage (Volume Decrement)
    0x81, 0x06,               // Input(Data, Value, Relative, BitField) Bit1
    0x09, 0xE2,               // Usage (Mute)
    0x81, 0x06,               // Input(Data, Value, Relative, BitField) Bit2     
    0x0A, 0x94, 0x01,         // Usage AL Local Machine Browser (App1) 
    0x81, 0x06,               // Input(Data, Value, Relative, BitField) Bit3
    0x0A, 0x92, 0x01,         // Usage AL Calculator (App2) 
    0x81, 0x06,               // Input(Data, Value, Relative, BitField) Bit4
    0x09, 0xCD,               // Usage (Play/Pause)
    0x81, 0x06,               // Input(Data, Value, Relative, BitField) Bit5
    0x09, 0x6F,               // Usage (Brightness Increase)
    0x81, 0x06,               // Input(Data, Value, Relative, BitField) Bit6
    0x09, 0x70,               // Usage (Brightness Decrease)
    0x81, 0x06,               // Input(Data, Value, Relative, BitField) Bit7
    0xC0,                     // End Collection
};

当我将  第17行和第19行上的从8位标签和数据{0x09、0xFF}更改为16位{0x0A、0x92、0x01}时、其中0xFF 只是任何限制为8位的使用 ID 的占位符。 我 还将 REPORT_DESC_SIZE_HID2从49更改为51、以考虑报告中的两个额外字节数据。

我的代码停止同时使用消费者报告、只要我将所有 ID 绑定到8位、音量和亮度的键盘按钮就可以与 Windows 完美交互。 我从0x100开始变为任何 ID 的16位后、所有消费者报告按钮都将停止工作。

是否有人在类似的上下文中修改了使用 ID? 非常感谢您提供任何建议或建议!

谢谢!

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

    您如何将使用 ID 发送到计算机? 您发送两个字节吗? 计算机需要2个字节吗?

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

    有一个2字节的输出缓冲区、第一个字节未使用、第二个字节进行"或"运算为位图。 defines 的顺序与描述符列出的顺序相同。

    #define CONSREP_DATA_OFFSET     (1)
    
    #define hidUsageVolumeUp            0x1101  //bit 0 of Consumer Control Input Report
    #define hidUsageVolumeDown          0x1102  //bit 1 of Consumer Control Input Report
    #define hidUsageConsumerMute        0x1104  //bit 2 of Consumer Control Input Report
    #define hidUsageApp1                0x1108  //bit 3 of Consumer Control Input Report
    #define hidUsageApp2                0x1110  //bit 4 of Consumer Control Input Report
    #define hidUsagePlay                0x1120  //bit 5 of Consumer Control Input Report
    #define hidUsageBrightnessUp        0x1140  //bit 6 of Consumer Control Input Report
    #define hidUsageBrightnessDown      0x1180  //bit 7 of Consumer Control Input Report
    
    
    //in KBD320_Keyboard.c
    if ((keycode & 0xFF00) == CONSUMER_KEY(0))
    {
        #ifdef USE_CONSUMER_REPORT
        // Add key to Consumer Report
        KBD430_ConsReport_Addkey((keycode & 0x00FF));
        #endif
    }
    
    //in KBD430_report.c
    /******************************************************************************
     * @brief  Adds key to the consumer report
     *   Note that the consumer report is bit-based, so it sets/clears bits when
     *   a key is pressed
     *
     * @param key   Bits being set in the report (value will be ORed with the report)
     *
     * @return  true 
     *****************************************************************************/
    #ifdef USE_CONSUMER_REPORT
    bool KBD430_ConsReport_Addkey( uint8_t key )
    {
        ConsReport_buff.Buff[CONSREP_DATA_OFFSET] |= key;
        ConsReport_buff.Update = true;
        return true;
    }
    #endif

    然后将该缓冲器传递给发送 该缓冲器的函数

    #ifdef USE_CONSUMER_REPORT    
        if (ConsReport_buff.Update == true)
        {
            if (KBD430_ReportSend((uint8_t *)&ConsReport_buff.Buff[0], HID_Consumer) == true)
            {
                // Clear flag if the report was sent correctly
                ConsReport_buff.Update = false;
            }
        }
    #endif
    
    bool KBD430_ReportSend(uint8_t * reportData, uint8_t intfNum)
    {
        if (USBHID_sendReport(reportData, intfNum) == kUSBHID_sendComplete)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    uint8_t USBHID_sendReport (const uint8_t * reportData, uint8_t intfNum)
    {
        uint8_t byte_count;
        uint8_t * pEP1;
        uint8_t * pCT1;
    
        uint8_t edbIndex;
    
        edbIndex = stUsbHandle[intfNum].edb_Index;
    
        //do not access USB memory if suspended (PLL off). It may produce BUS_ERROR
        if ((bFunctionSuspended) ||
            (bEnumerationStatus != ENUMERATION_COMPLETE)){
            return (kUSBHID_busNotAvailable);
        }
    
        if (HidWriteCtrl[INTFNUM_OFFSET(intfNum)].bCurrentBufferXY == X_BUFFER){
            //this is the active EP buffer
            pEP1 = (uint8_t*)stUsbHandle[intfNum].iep_X_Buffer;
            pCT1 = &tInputEndPointDescriptorBlock[edbIndex].bEPBCTX;
        } else {
            //this is the active EP buffer
            pEP1 = (uint8_t*)stUsbHandle[intfNum].iep_Y_Buffer;
            pCT1 = &tInputEndPointDescriptorBlock[edbIndex].bEPBCTY;
        }
    
        byte_count = report_len_input[INTFNUM_OFFSET(intfNum)];
    
        if (*pCT1 & EPBCNT_NAK){                                                        //if this EP is empty
            USB_TX_memcpy(pEP1, reportData, byte_count);                                //copy data into IEP X or Y buffer
            uint8_t au8HIDReportDebug[10] = {0};
            memcpy(au8HIDReportDebug, reportData, byte_count);                                //copy data into IEP X or Y buffer
            *pCT1 = byte_count;                                                         //Set counter for usb In-Transaction
            HidWriteCtrl[INTFNUM_OFFSET(intfNum)].bCurrentBufferXY =
                (HidWriteCtrl[INTFNUM_OFFSET(intfNum)].bCurrentBufferXY + 1) & 0x01;    //switch buffer
            return (kUSBHID_sendComplete);
        }
        return (kUSBHID_intfBusyError);
    }

    我想它一直在发送一个8位位位图、在创建描述符期间定义了这些用途。 此用法的大小不应影响代码。

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

    尊敬的 Pillip:

    我没有这个库开发的经验。

    从我的角度来看、一个建议是检查然后整个 send 消息逻辑、以查看其数组计数器是否与 report_desc_HID2[]中增加的数据不一致。

    B.R.

    SAL

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

    我找到了解决方案。 感谢您的答复,您的意见帮助我偶然发现了解决方案。

    在 descriptor.c 中有一个接口大小数组不会拉取#defines。 主机使用该阵列。

    uint16_t const report_desc_size[HID_NUM_INTERFACES] =
    {
    63,
    36,
    49,
    25
    };
    

    应更新此数组以使用 descriptors.h 中的#defines

    //***********************************************************************************************
    // DESCRIPTOR CONSTANTS
    //***********************************************************************************************
    #define SIZEOF_DEVICE_DESCRIPTOR  0x12
    #define MAX_STRING_DESCRIPTOR_INDEX 8
    #define report_desc_size_HID0 63
    #define report_desc_size_HID1 36
    #define report_desc_size_HID2 51
    #define report_desc_size_HID3 25
    //#define SIZEOF_REPORT_DESCRIPTOR  36
    //#define USBHID_REPORT_LENGTH      64  // length of whole HID report (including Report ID)
    #define CONFIG_STRING_INDEX       4
    #define INTF_STRING_INDEX         5
    #define USB_CONFIG_VALUE          0x01
    
    
    //In descriptors.c
    uint16_t const report_desc_size[HID_NUM_INTERFACES] =
    {
    report_desc_size_HID0,
    report_desc_size_HID1,
    report_desc_size_HID2,
    report_desc_size_HID3
    };