|
发表于 2013-7-24 14:48:30
|
显示全部楼层
BLE的资料实在太少了。英语又不好。我有些疑问请教一下。我想把NRF51822的HID鼠标和健盘的例子改成HID透明传输来用。我想问一下该怎么改呢。我参考了这两个例子。
首先我把HID的报告描术符给改成只有一个输入报告和一个输出报告,参考了STM32 HID的例子。
- static void hids_init(void)
- {
- uint32_t err_code;
- ble_hids_init_t hids_init_obj;
- ble_hids_inp_rep_init_t inp_rep_array[HID_REP_COUNT];
- ble_hids_inp_rep_init_t * p_input_report;
- uint8_t hid_info_flags;
-
- static uint8_t rep_map_data[] =
- {
- 0x05, 0x8c, // USAGE_PAGE (ST Page)
- 0x09, 0x01, //USAGE (Demo Kit) */
- 0xa1, 0x01, /* COLLECTION (Application) */
- /* 6 */
- // The Input report
- 0x85, 0x01, // Report Id 1
- 0x09,0x03, // USAGE ID - Vendor defined
- 0x15,0x00, // LOGICAL_MINIMUM (0)
- 0x26,0x00,0xFF, // LOGICAL_MAXIMUM (255)
- 0x75,HID_INPUT_REP_LEN, // REPORT_SIZE (8)
- 0x95,EP1_PACK_SIZE, // REPORT_COUNT (200)
- 0x81,0x02, // INPUT (Data,Var,Abs)
- //19
-
- // The Output report
- 0x85, 0x02, // Report Id 2
- 0x09,0x04, // USAGE ID - Vendor defined
- 0x15,0x00, // LOGICAL_MINIMUM (0)
- 0x26,0x00,0xFF, // LOGICAL_MAXIMUM (255)
- 0x75,HID_OUTPUT_REP_LEN, // REPORT_SIZE (8)
- 0x95,EP1_PACK_SIZE, // REPORT_COUNT (200) // 200字节
- 0x91,0x02, // OUTPUT (Data,Var,Abs)
- //32
- // The Feature report
- 0xc0 //END_COLLECTION
- };
- // Initialize HID Service
- p_input_report = &inp_rep_array[HID_INPUT_REP_INDEX];
- p_input_report->max_len = HID_INPUT_REP_LEN;
- p_input_report->rep_ref.report_id = HID_INPUT_REP_ID;
- p_input_report->rep_ref.report_type = BLE_HIDS_REP_TYPE_INPUT;
-
- BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&p_input_report->security_mode.cccd_write_perm);
- BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&p_input_report->security_mode.read_perm);
- BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&p_input_report->security_mode.write_perm);
- p_input_report = &inp_rep_array[HID_OUTPUT_REP_INDEX];
- p_input_report->max_len = HID_OUTPUT_REP_LEN;
- p_input_report->rep_ref.report_id = HID_OUTPUT_REP_ID;
- p_input_report->rep_ref.report_type = BLE_HIDS_REP_TYPE_OUTPUT;
-
- BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&p_input_report->security_mode.cccd_write_perm);
- BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&p_input_report->security_mode.read_perm);
- BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&p_input_report->security_mode.write_perm);
- hid_info_flags = HID_INFO_FLAG_REMOTE_WAKE_MSK | HID_INFO_FLAG_NORMALLY_CONNECTABLE_MSK;
-
- memset(&hids_init_obj, 0, sizeof(hids_init_obj));
- hids_init_obj.evt_handler = on_hids_evt;
- hids_init_obj.error_handler = service_error_handler;
- hids_init_obj.is_kb = false;
- hids_init_obj.is_mouse = false;
- hids_init_obj.inp_rep_count = HID_REP_COUNT;
- hids_init_obj.p_inp_rep_array = inp_rep_array;
- hids_init_obj.outp_rep_count = 0;
- hids_init_obj.p_outp_rep_array = NULL;
- hids_init_obj.feature_rep_count = 0;
- hids_init_obj.p_feature_rep_array = NULL;
- hids_init_obj.rep_map.data_len = sizeof(rep_map_data);
- hids_init_obj.rep_map.p_data = rep_map_data;
- hids_init_obj.hid_information.bcd_hid = BASE_USB_HID_SPEC_VERSION;
- hids_init_obj.hid_information.b_country_code = 0;
- hids_init_obj.hid_information.flags = hid_info_flags;
- hids_init_obj.included_services_count = 0;
- hids_init_obj.p_included_services_array = NULL;
-
- BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&hids_init_obj.rep_map.security_mode.read_perm);
- BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&hids_init_obj.rep_map.security_mode.write_perm);
- BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&hids_init_obj.hid_information.security_mode.read_perm);
- BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&hids_init_obj.hid_information.security_mode.write_perm);
- BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&hids_init_obj.security_mode_boot_mouse_inp_rep.cccd_write_perm);
- BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&hids_init_obj.security_mode_boot_mouse_inp_rep.read_perm);
- BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&hids_init_obj.security_mode_boot_mouse_inp_rep.write_perm);
- BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&hids_init_obj.security_mode_protocol.read_perm);
- BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&hids_init_obj.security_mode_protocol.write_perm);
- BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&hids_init_obj.security_mode_ctrl_point.read_perm);
- BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&hids_init_obj.security_mode_ctrl_point.write_perm);
- err_code = ble_hids_init(&m_hids, &hids_init_obj);
- APP_ERROR_CHECK(err_code);
- }
复制代码 接着我参考了HID 键盘的例子里输出报告的事件处理函数(p_evt->evt_type == BLE_HIDS_EVT_REP_CHAR_WRITE)来接收HID的输出报告
- static void on_hids_evt(ble_hids_t * p_hids, ble_hids_evt_t *p_evt)
- {
- switch (p_evt->evt_type)
- {
- case BLE_HIDS_EVT_BOOT_MODE_ENTERED:
- m_in_boot_mode = true;
- break;
- case BLE_HIDS_EVT_REPORT_MODE_ENTERED:
- m_in_boot_mode = false;
- break;
- case BLE_HIDS_EVT_REP_CHAR_WRITE:
- on_hid_rep_char_write(p_evt);
- break;
-
- case BLE_HIDS_EVT_NOTIF_ENABLED:
- {
- if (m_in_boot_mode)
- {
- // Protocol mode is Boot Protocol mode.
- if (
- p_evt->params.notification.char_id.uuid
- ==
- BLE_UUID_BOOT_MOUSE_INPUT_REPORT_CHAR
- )
- {
- // The notification of boot mouse input report has been enabled.
- // Save the system attribute (CCCD) information into the flash.
- uint32_t err_code;
-
- err_code = ble_bondmngr_sys_attr_store();
- if (err_code != NRF_ERROR_INVALID_STATE)
- {
- APP_ERROR_CHECK(err_code);
- }
- else
- {
- // The bondmanager did not write the system attributes to the flash because
- // the connected master is not a new master. The system attributes
- // will only be written to flash only when disconnected from this master.
- // Do nothing now.
- }
- }
- else
- {
- // Do nothing
- }
- }
- else if (
- (p_evt->params.notification.char_id.rep_index == INPUT_REP_MOVEMENT_INDEX)
- &&
- (p_evt->params.notification.char_id.rep_type == BLE_HIDS_REP_TYPE_INPUT)
- )
- {
- // The protocol mode is Report Protocol mode. And the CCCD for the report ID
- // INPUT_REP_MOVEMENT_INDEX is changed. Since this application uses this report to
- // send mouse movements, it is now time to store all the CCCD information (system
- // attributes) into the flash.
- uint32_t err_code;
-
- err_code = ble_bondmngr_sys_attr_store();
- if (err_code != NRF_ERROR_INVALID_STATE)
- {
- APP_ERROR_CHECK(err_code);
- }
- else
- {
- // The bondmanager did not write the system attributes to the flash because
- // the connected master is not a new master. The system attributes
- // will only be written to flash only when disconnected from this master.
- // Do nothing now.
- }
- }
- else
- {
- // The notification of the report that was enabled by the master is not interesting to this
- // application. So do nothing.
- }
- break;
- }
-
- default:
- break;
- }
- }
复制代码 在static void on_hid_rep_char_write(ble_hids_evt_t *p_evt) 这个函数里接收输出报告。
然后参考了鼠标按键事件处理,按键的事件处理函数最终调用了sd_ble_gatts_hvx这个SVC函数来发送HID输入报告。那么我要透过HID发送的数据包应该也是一样的。
请问还有什么细节要注意?这样对不对。?如果用HID是不是上位机程序开发起来会比较容易。用BUS HOUND软件能不能直接调试? |
|