BK3432 Bluetooth Low Energy Sofeware Developer’s Guide
Version 1.0
BK3432 Bluetooth®
Low Energy
Software Developer's Guide
v1.0
- 1 -
BK3435 Bluetooth Low Energy Sofeware Developer’s Guide
Version 1.0
更改记录
版本号
日期
V1.0
2018-02-07
作者
许 海
文档建立
注释
- 2 -
BK3435 Bluetooth Low Energy Sofeware Developer’s Guide
Version 1.0
目 录
1. SDK 架构介绍......................................................................................... - 4 -
1.1 BINARIES 目录................................................................................. - 4 -
1.2 DOC 目录........................................................................................... - 4 -
1.3 LIBS 目录........................................................................................... - 4 -
1.4 PROJECTS 目录................................................................................ - 4 -
1.6 UTILITIES 目录.................................................................................- 5 -
2. 带你快速玩转3432.................................................................................- 5 -
2.1 用户配置.............................................................................................- 5 -
2.2 常用的 API 及回调函数....................................................................- 5 -
2.3 外设驱动使用举例............................................................................ - 7 -
2.4 添加一个服务.................................................................................. - 10 -
2.5 添加一个自定义消息...................................................................... - 12 -
2.6 配对方式修改.................................................................................. - 14 -
2.7 程序的烧录...................................................................................... - 15 -
2.8 OAD..................................................................................................- 17 -
2.9 RF 测试.............................................................................................- 17 -
3. SDK 例程介绍....................................................................................... - 17 -
3.1 数据透传...........................................................................................- 17 -
3.2 语音遥控器...................................................................................... - 18 -
3.3 苹果通知服务.................................................................................. - 18 -
3.4 微信接入...........................................................................................- 18 -
- 3 -
BK3435 Bluetooth Low Energy Sofeware Developer’s Guide
Version 1.0
1. sdk 架构介绍
1.1 binaries 目录
该目录保存 sdk 中 demo 工程预编译完成的 bin 文件,可直接用于测试。
1.2 doc 目录
该目录保存开发过程中相关参考文档。
1.3 libs 目录
该目录用于存放与 sdk 相关的库文件。
1.4 projects 目录
该目录为 sdk 工程目录,存放芯片设计商提供的一些 demo 例程。
ble_app_ancs:支持苹果通知中心服务的最小工程;
ble_app_gatt:数据传输最小工程;
ble_app_rc:语音遥控器最小工程;
ble_app_wechat:支持微信接入功能的最小工程;
- 4 -
BK3435 Bluetooth Low Energy Sofeware Developer’s Guide
Version 1.0
1.5 sdk 目录
该目录存放 sdk 公共文件,其中 ble_stack 保存蓝牙协议栈相关文件;plactform 保
存平台相关文件,如 driver、rw 相关等;project_files 保存工程通用性文件。
1.6 utilities 目录
该目录为工具类目录,用于保存 3435 开发过程中可能使用的相关工具,如烧录器
估计、OTA 软件等。
2. 带你快速玩转3432
2.1 用户配置
在软件开发包每个工程下面都有一个 user_config.h 文件,这个文件主要是用来配置
蓝牙的一些基本参数,如蓝牙名称、连接间隔、广播包数据、扫描响应包数据、驱
动等,部分截图如下:
2.2 常用的 API 及回调函数
2.2.1 启动一个软件定时器
/******************************************************************
*
* timer_id : 定时器的 ID,用来区分是哪个定时器
* task_id : 任务 ID
- 5 -
BK3435 Bluetooth Low Energy Sofeware Developer’s Guide
Version 1.0
* Delay :定时器时间,单位 10ms
*
******************************************************************/
void ke_timer_set(ke_msg_id_t const timer_id, ke_task_id_t const task_id,
uint32_t delay)
2.2.2 清除一个软件定时器
/******************************************************************
*
* timer_id : 定时器 ID
*
* task_id : 任务 ID
*
*****************************************************************/
void ke_timer_clear(ke_msg_id_t const timer_id, ke_task_id_t const
task_id)
2.2.3 设备主动发起广播
void appm_start_advertising(void)
2.2.4 设备主动停止广播
void appm_stop_advertising(void)
2.2.5 设备主动断开连接
void appm_disconnect(void)
2.2.6 设备连接成功
static int gapc_connection_req_ind_handler(ke_msg_id_t const msgid,
struct gapc_connection_req_ind const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
2.2.7 设备成功断开
static int gapc_disconnect_ind_handler(ke_msg_id_t const msgid,
struct gapc_disconnect_ind const *param,
ke_task_id_t const dest_id,
- 6 -
BK3435 Bluetooth Low Energy Sofeware Developer’s Guide
Version 1.0
ke_task_id_t const src_id)
2.2.8 数据发送状态
RW 提供 GATTC_CMP_EVT 事件对 GATT 操作状态进行处理,当发送完数据之后,
协议栈会上报 GATTC_CMP_EVT 事件(在每个 profile 对应的 xxx_task.c 中),可
以在这个事件中判断数据发送的具体状态。
static int gattc_cmp_evt_handler(ke_msg_id_t const msgid,
struct gattc_cmp_evt const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
//Command complete event data structure
struct gattc_cmp_evt
{
/// GATT request type
uint8_t operation;
/// Status of the request
uint8_t status;
/// operation sequence number - provided when operation is started
uint16_t seq_num;
};
GAP_ERR_NO_ERROR:成功
其他:失败
2.3 外设驱动使用举例
以下通过在 ble_app_gatt 这个工程中添加 PWM 驱动来说明如何添加一个驱动到对
应的工程项目中:
1 在工程对应的 ble_3435_sdk_ext_xx_xxxx\projects\ble_app_gatt\config 目录下,
打开 user_config.h 文件,打开对应的宏定义,如下:
- 7 -
BK3435 Bluetooth Low Energy Sofeware Developer’s Guide
Version 1.0
2 使用 keil 5.12 打开 ble_app_gatt 工程,在 keil 中添加 pwm.c 源文件如下:
3 在 keil 工程配置中添加相关路径,如下:
- 8 -