BLE_HID类设备连接上主机后发数据返回错误码解决方法

继上文HID设备的使用,BLE_HID例程增加报表描述符使用

我们在BLE_HID类蓝牙设备应用中调用HidDev_Report函数发送数据,如果出现了返回以下错误码时,一般以0x10,0x15,0x16居多,应该是HID数据通道未能完全成功打开,我们可以在代码中添加处理以手动辅助开启,

#define bleInvalidTaskID                INVALID_TASK  //!< Task ID isn't setup properly
#define bleEecKeyRequestRejected        0x06   //!< key missing
#define bleNotReady                     0x10   //!< Not ready to perform task
#define bleAlreadyInRequestedMode       0x11   //!< Already performing that task
#define bleIncorrectMode                0x12   //!< Not setup properly to perform that task
#define bleMemAllocError                0x13   //!< Memory allocation error occurred
#define bleNotConnected                 0x14   //!< Can't perform function when not in a connection
#define bleNoResources                  0x15   //!< There are no resource available
#define blePending                      0x16   //!< Waiting
#define bleTimeout                      0x17   //!< Timed out performing function
#define bleInvalidRange                 0x18   //!< A parameter is out of range
#define bleLinkEncrypted                0x19   //!< The link is already encrypted
#define bleProcedureComplete            0x1A   //!< The Procedure is completed
#define bleInvalidMtuSize               0x1B   //!< SDU size is larger than peer MTU.

增加代码并在蓝牙打印"connected"的地方调用:

extern uint16_t hidEmuConnHandle;
void OpenHotiChannel()
{
    GATTServApp_WriteCharCfg(hidEmuConnHandle,hidReportKeyInClientCharCfg,0x0001);
    GATTServApp_WriteCharCfg(hidEmuConnHandle,hidReportHIDxInClientCharCfg,0x0001);
    GATTServApp_WriteCharCfg(hidEmuConnHandle,hidReportkeybitInClientCharCfg,0x0001);
    GATTServApp_WriteCharCfg(hidEmuConnHandle,hidReportkeyConsumeInClientCharCfg,0x0001);
    GATTServApp_WriteCharCfg(hidEmuConnHandle,hidReportBootKeyInClientCharCfg,0x0001);
    GATTServApp_WriteCharCfg(hidEmuConnHandle,hidReportmouseInClientCharCfg,0x0001);
    GATTServApp_WriteCharCfg(hidEmuConnHandle,hidReportkeysysInClientCharCfg,0x0001);
}

 

posted @ 2023-10-13 13:30  oTvTo  阅读(266)  评论(0编辑  收藏  举报