Bluetooth: Add sample implementing HIDS
This adds a sample that implements HID Service peripheral, the current descriptor map is for a generic mouse so when connecting to a Linux box it will create a input device like in the following output: input: Test HoG mouse as /devices/virtual/misc/uhid/0005:1D6B:0246.0035/input/input98 hid-generic 0005:1D6B:0246.0035: input,hidraw2: BLUETOOTH HID v5.29 Mouse [Test HoG mouse] on XX:XX:XX:XX:XX:XX Change-Id: Iccf07926ecc7363f4f47e1aa9df506a722e7e2d3 Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
parent
30665185f8
commit
f509d68cf1
|
@ -93,3 +93,8 @@ peripheral_hr:
|
|||
Similar to 'peripheral', except that this application
|
||||
specifically exposes the HR (Heart Rate) GATT Service. Once a
|
||||
device connects it will generate dummy heart-rate values.
|
||||
|
||||
peripheral_hids:
|
||||
Similar to 'peripheral', except that this application
|
||||
specifically exposes the HID GATT Service. The report map used
|
||||
is for a generic mouse.
|
||||
|
|
7
samples/bluetooth/peripheral_hids/Makefile
Normal file
7
samples/bluetooth/peripheral_hids/Makefile
Normal file
|
@ -0,0 +1,7 @@
|
|||
BOARD ?= qemu_x86
|
||||
MDEF_FILE = prj.mdef
|
||||
KERNEL_TYPE = micro
|
||||
CONF_FILE = prj.conf
|
||||
QEMU_EXTRA_FLAGS = -serial unix:/tmp/bt-server-bredr
|
||||
|
||||
include $(ZEPHYR_BASE)/Makefile.inc
|
7
samples/bluetooth/peripheral_hids/prj.conf
Normal file
7
samples/bluetooth/peripheral_hids/prj.conf
Normal file
|
@ -0,0 +1,7 @@
|
|||
CONFIG_BLUETOOTH=y
|
||||
CONFIG_BLUETOOTH_LE=y
|
||||
CONFIG_BLUETOOTH_DEBUG_LOG=y
|
||||
CONFIG_BLUETOOTH_SMP=y
|
||||
CONFIG_BLUETOOTH_PERIPHERAL=y
|
||||
CONFIG_BLUETOOTH_GATT_DYNAMIC_DB=y
|
||||
CONFIG_ARC_INIT=n
|
5
samples/bluetooth/peripheral_hids/prj.mdef
Normal file
5
samples/bluetooth/peripheral_hids/prj.mdef
Normal file
|
@ -0,0 +1,5 @@
|
|||
% Application : Bluetooth beacon sample
|
||||
|
||||
% TASK NAME PRIO ENTRY STACK GROUPS
|
||||
% ===================================================
|
||||
TASK MAIN 7 main 2048 [EXE]
|
5
samples/bluetooth/peripheral_hids/prj_nble.conf
Normal file
5
samples/bluetooth/peripheral_hids/prj_nble.conf
Normal file
|
@ -0,0 +1,5 @@
|
|||
CONFIG_BLUETOOTH=y
|
||||
CONFIG_BLUETOOTH_STACK_NBLE=y
|
||||
CONFIG_NBLE=y
|
||||
CONFIG_ARC_INIT=n
|
||||
CONFIG_BLUETOOTH_DEBUG_LOG=y
|
4
samples/bluetooth/peripheral_hids/src/Makefile
Normal file
4
samples/bluetooth/peripheral_hids/src/Makefile
Normal file
|
@ -0,0 +1,4 @@
|
|||
ccflags-y +=-I${ZEPHYR_BASE}/samples/bluetooth
|
||||
|
||||
obj-y = main.o ../../gatt/gap.o ../../gatt/dis.o ../../gatt/bas.o \
|
||||
../../gatt/hog.o
|
132
samples/bluetooth/peripheral_hids/src/main.c
Normal file
132
samples/bluetooth/peripheral_hids/src/main.c
Normal file
|
@ -0,0 +1,132 @@
|
|||
/* main.c - Application main entry point */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <misc/printk.h>
|
||||
#include <misc/byteorder.h>
|
||||
#include <zephyr.h>
|
||||
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#include <bluetooth/hci.h>
|
||||
#include <bluetooth/conn.h>
|
||||
#include <bluetooth/uuid.h>
|
||||
#include <bluetooth/gatt.h>
|
||||
|
||||
#include <gatt/gap.h>
|
||||
#include <gatt/dis.h>
|
||||
#include <gatt/bas.h>
|
||||
#include <gatt/hog.h>
|
||||
|
||||
#define DEVICE_NAME "Test HoG mouse"
|
||||
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
|
||||
#define HOG_APPEARANCE 0x03c2
|
||||
|
||||
static const struct bt_data ad[] = {
|
||||
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
|
||||
BT_DATA_BYTES(BT_DATA_UUID16_ALL,
|
||||
0x12, 0x18, /* HID Service */
|
||||
0x0f, 0x18), /* Battery Service */
|
||||
};
|
||||
|
||||
static const struct bt_data sd[] = {
|
||||
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
|
||||
};
|
||||
|
||||
static void connected(struct bt_conn *conn, uint8_t err)
|
||||
{
|
||||
if (err) {
|
||||
printk("Connection failed (err %u)\n", err);
|
||||
} else {
|
||||
printk("Connected\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void disconnected(struct bt_conn *conn, uint8_t reason)
|
||||
{
|
||||
printk("Disconnected (reason %u)\n", reason);
|
||||
}
|
||||
|
||||
static struct bt_conn_cb conn_callbacks = {
|
||||
.connected = connected,
|
||||
.disconnected = disconnected,
|
||||
};
|
||||
|
||||
static void bt_ready(int err)
|
||||
{
|
||||
if (err) {
|
||||
printk("Bluetooth init failed (err %d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
printk("Bluetooth initialized\n");
|
||||
|
||||
gap_init(DEVICE_NAME, HOG_APPEARANCE);
|
||||
bas_init();
|
||||
dis_init(CONFIG_SOC, "Manufacturer");
|
||||
hog_init();
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad),
|
||||
sd, ARRAY_SIZE(sd));
|
||||
if (err) {
|
||||
printk("Advertising failed to start (err %d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
printk("Advertising successfully started\n");
|
||||
}
|
||||
|
||||
static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey)
|
||||
{
|
||||
char addr[BT_ADDR_LE_STR_LEN];
|
||||
|
||||
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
|
||||
|
||||
printk("Passkey for %s: %u\n", addr, passkey);
|
||||
}
|
||||
|
||||
static void auth_cancel(struct bt_conn *conn)
|
||||
{
|
||||
char addr[BT_ADDR_LE_STR_LEN];
|
||||
|
||||
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
|
||||
|
||||
printk("Pairing cancelled: %s\n", addr);
|
||||
}
|
||||
|
||||
static struct bt_conn_auth_cb auth_cb_display = {
|
||||
.passkey_display = auth_passkey_display,
|
||||
.passkey_entry = NULL,
|
||||
.cancel = auth_cancel,
|
||||
};
|
||||
|
||||
void main(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = bt_enable(bt_ready);
|
||||
if (err) {
|
||||
printk("Bluetooth init failed (err %d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_conn_cb_register(&conn_callbacks);
|
||||
bt_conn_auth_cb_register(&auth_cb_display);
|
||||
}
|
19
samples/bluetooth/peripheral_hids/testcase.ini
Normal file
19
samples/bluetooth/peripheral_hids/testcase.ini
Normal file
|
@ -0,0 +1,19 @@
|
|||
[test_x86]
|
||||
tags = bluetooth
|
||||
build_only = true
|
||||
arch_whitelist = x86
|
||||
# FIXME Doesn't work for ia32_pci
|
||||
filter = CONFIG_SOC == "ia32"
|
||||
|
||||
[test_arm]
|
||||
tags = bluetooth
|
||||
build_only = true
|
||||
arch_whitelist = arm
|
||||
platform_exclude = arduino_due
|
||||
|
||||
[test_nble]
|
||||
tags = bluetooth
|
||||
build_only = true
|
||||
extra_args = CONF_FILE="prj_nble.conf"
|
||||
arch_whitelist = x86
|
||||
platform_whitelist = arduino_101
|
Loading…
Reference in a new issue