当前文档版本为 v1.2.0,您可以访问当前页面的 开发中 版本以获取最近可能的更新。

BLE HID Selfie

1 功能概述

此项目演示基于HID服务的自拍服务,用K1和K2模拟的音量键,我们可以在相机模式下可以实现拍照功能。

2 环境要求

  • board: pan108x evb

  • uart(option): 用来显示串口log(波特率921600,选项8n1

  • 手机app nrf connect

3 编译和烧录

例程位置:<home>\nimble\samples\solutions\ble_hid_selfie\keil

使用keil进行打开项目选择需要的controller进行烧录ble_hid_selfie_origin或者ble_hid_selfie_spark进行编译烧录。

4 演示说明

  1. 在设置蓝牙界面连接nimble_hid进行配对,通过按键KEY1和KEY2模拟音量增大和减小,同时利用音量增大键和减小键实现拍照快捷键功能。

    
    [19:23:23.691]  Try to load HW calibration data.. DONE.
    - Chip Type         : 0x80
    - Chip CP Version   : None
    - Chip FT Version   : 8
    - Chip MAC Address  : D0000C0CBBF5
    - Chip Flash UID    : 32313334320EAC834330FFFFFFFFFFFF
    - Chip Flash Size   : 1024 KB
    LL Spark Controller Version:b0e99c4
    
    [19:23:23.735]  ble_store_config_num_our_secs:0
    ble_store_config_num_peer_secs:0
    ble_store_config_num_cccds:0
    registered service 0x1812 with handle=1
    registering characteristic 0x2a4a with def_handle=2 val_handle=3
    registering characteristic 0x2a4b with def_handle=4 val_handle=5
    registering characteristic 0x2a4d with def_handle=6 val_handle=7
    registering descriptor 0x2908 with handle=9
    registering characteristic 0x2a4d with def_handle=10 val_handle=11
    registering descriptor 0x2908 with handle=13
    registering characteristic 0x2a4c with def_handle=14 val_handle=15
    Device Address: 01 02 03 04 05 06 
    
    
    [19:23:42.214]  connection established; status=0 handle=1 our_ota_addr_type=0 our_ota_addr=01 02 03 04 05 06 
     our_id_addr_type=0 our_id_addr=01 02 03 04 05 06 
     peer_ota_addr_type=1 peer_ota_addr=1e ee c1 b6 69 57 
     peer_id_addr_type=1 peer_id_addr=1e ee c1 b6 69 57 
     conn_itvl=24 conn_latency=0 supervision_timeout=500 encrypted=0 authenticated=0 bonded=0
    
    
    [19:23:45.043]  encryption change event; status=0 handle=1 our_ota_addr_type=0 our_ota_addr=01 02 03 04 05 06 
     our_id_addr_type=0 our_id_addr=01 02 03 04 05 06 
     peer_ota_addr_type=1 peer_ota_addr=1e ee c1 b6 69 57 
     peer_id_addr_type=1 peer_id_addr=1e ee c1 b6 69 57 
     conn_itvl=24 conn_latency=0 supervision_timeout=500 encrypted=1 authenticated=0 bonded=1
    
    ediv=0 rand=0 authenticated=0 ltk= cddfa0325abc4490ff77622c3075800a irk= 00000000000000000000000000000000 
    ediv=0 rand=0 authenticated=0 ltk= cddfa0325abc4490ff77622c3075800a irk= 4a3711a0c1b7cd2c92d64048e813fe34 
    
    [19:23:45.432]  connection updated; status=0 handle=1 our_ota_addr_type=0 our_ota_addr=01 02 03 04 05 06 
     our_id_addr_type=0 our_id_addr=01 02 03 04 05 06 
     peer_ota_addr_type=1 peer_ota_addr=1e ee c1 b6 69 57 
     peer_id_addr_type=0 peer_id_addr=07 49 34 4d af 50 
     conn_itvl=6 conn_latency=0 supervision_timeout=500 encrypted=1 authenticated=0 bonded=1
    
    
    [19:23:45.610]  connection updated; status=0 handle=1 our_ota_addr_type=0 our_ota_addr=01 02 03 04 05 06 
     our_id_addr_type=0 our_id_addr=01 02 03 04 05 06 
     peer_ota_addr_type=1 peer_ota_addr=1e ee c1 b6 69 57 
     peer_id_addr_type=0 peer_id_addr=07 49 34 4d af 50 
     conn_itvl=24 conn_latency=0 supervision_timeout=500 encrypted=1 authenticated=0 bonded=1
    
    
    [19:23:46.352]  subscribe event; conn_handle=1 attr_handle=7 reason=1 prevn=0 curn=1 previ=0 curi=0
    
    [19:23:46.412]  subscribe event; conn_handle=1 attr_handle=11 reason=1 prevn=0 curn=1 previ=0 curi=0
    
    [19:23:48.997]  GPIO ISR in..
    P04 occurred  (KEY1音量增大)
    notify_tx event; conn_handle=1 attr_handle=11 status=0 is_indication=0notify_tx event; conn_handle=1 attr_handle=11 status=0 is_indication=0key_vol_up pressed
    
    [19:23:49.544]  GPIO ISR in..
    P04 occurred
    notify_tx event; conn_handle=1 attr_handle=11 status=0 is_indication=0notify_tx event; conn_handle=1 attr_handle=11 status=0 is_indication=0key_vol_up pressed
    
    [19:23:50.843]  GPIO ISR in..
    P05 occurred  (KEY2音量减小)
    notify_tx event; conn_handle=1 attr_handle=11 status=0 is_indication=0key_vol_down pressed
    notify_tx event; conn_handle=1 attr_handle=11 status=0 is_indication=0
    [19:23:51.443]  GPIO ISR in..
    P05 occurred
    notify_tx event; conn_handle=1 attr_handle=11 status=0 is_indication=0key_vol_down pressed
    notify_tx event; conn_handle=1 attr_handle=11 status=0 is_indication=0
    
    1. hog相关GATT Service的初始化在gatt_svr.c中:

    
    static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
        {
            /* Service: Heart-rate */
            .type = BLE_GATT_SVC_TYPE_PRIMARY,
            .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS),
            .characteristics = (struct ble_gatt_chr_def[]) { {
                /* Characteristic: hids information */
                .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS_INFO),
                .access_cb = gatt_svr_chr_access_hid,
                .flags = BLE_GATT_CHR_F_READ,
            }, {
                /* Characteristic: hids report map */
                .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS_REPORT_MAP),
                .access_cb = gatt_svr_chr_access_hid,
                .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_ENC,
            }, {
                /* Characteristic: hids inout report */
                .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS_REPORT),
                .access_cb = gatt_svr_chr_access_hid_input_report,
                .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY,
                .val_handle = &hid_input_handle,
                .descriptors = (struct ble_gatt_dsc_def[]) { {
                    .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS_REPORT_REF),
                    .access_cb = gatt_svr_chr_access_hid_input_report,
                    .att_flags = BLE_ATT_F_READ,
                }, {
                    0
                }, }
            }, {
                 /* Characteristic: hids consumer report */
                .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS_REPORT),
                .access_cb = gatt_svr_chr_access_hid_consumer_report,
                .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY,
                .val_handle = &hid_consumer_input_handle,
                .descriptors = (struct ble_gatt_dsc_def[]) { {
                    .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS_REPORT_REF),
                    .access_cb = gatt_svr_chr_access_hid_consumer_report,
                    .att_flags = BLE_ATT_F_READ,
                }, {
                    0
                }, }
            }, {
                /* Characteristic: Body sensor location */
                .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS_CTRL_POINT),
                .access_cb = gatt_svr_chr_access_hid,
                .flags = BLE_GATT_CHR_F_WRITE_NO_RSP,
            }, {
                0, /* No more characteristics in this service */
            }, }
         
        }, {
             0, /* No more services. */
        },
        
    };
    
    1. 相关hog硬件初始化和处理以及发送消息的函数在hog.c

5 RAM/Flash资源使用情况

Spark Controller:

Flash Size: 144.86k
RAM Size:  37.47 k