generated from Embedded_Projects/N32WB031_RTOS_BLE
Initial BASS profile.
Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
parent
eb5a3c2a8d
commit
35170da6ab
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(n32wb03x_template)
|
||||
project(n32wb03x_mys_light)
|
||||
|
||||
enable_language(CXX)
|
||||
enable_language(ASM)
|
||||
|
@ -30,9 +30,12 @@ set(TARGET_SOURCES
|
|||
"SDK/firmware/n32wb03x_std_periph_driver/src/n32wb03x_tim.c"
|
||||
"SDK/firmware/n32wb03x_std_periph_driver/src/n32wb03x_usart.c"
|
||||
"SDK/firmware/n32wb03x_std_periph_driver/src/n32wb03x_wwdg.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/src/bass.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/src/bass_task.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/dis/diss/src/diss.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/dis/diss/src/diss_task.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/prf.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/prf_utils.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/att/lib_att.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/rwip.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/rwip_driver.c"
|
||||
|
@ -53,6 +56,7 @@ set(TARGET_SOURCES
|
|||
"board/system_n32wb03x.c"
|
||||
"SDK/gcc/startup_n32wb03x.S"
|
||||
"src/app_ble_support.c"
|
||||
"src/app_ble_profiles/app_ble_bass.c"
|
||||
"src/app_ble_profiles/app_ble_diss.c"
|
||||
"src/app_freertos_support.c"
|
||||
"src/main.c"
|
||||
|
@ -67,6 +71,8 @@ set(TARGET_C_INCLUDES
|
|||
"SDK/firmware/CMSIS/core"
|
||||
"SDK/firmware/CMSIS/device"
|
||||
"SDK/firmware/n32wb03x_std_periph_driver/inc"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/src"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/dis/diss/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/arch"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/arch"
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit ec8ecda4cd2db465720d2371865e25c1b1f1fdcc
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef APP_BLE_BASS_H
|
||||
#define APP_BLE_BASS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void app_ble_bass_init(void);
|
||||
void app_ble_bass_enable_prf(uint8_t conidx);
|
||||
void app_ble_bass_update_level(uint8_t level);
|
||||
|
||||
#endif // APP_BLE_BASS_H
|
|
@ -93,6 +93,9 @@
|
|||
#define BOND_DATA_BASE_ADDR 0x0103B000
|
||||
|
||||
/* profiles config */
|
||||
#define CFG_APP_BATT 1
|
||||
#define CFG_PRF_BASS 1
|
||||
|
||||
#define CFG_APP_DIS 1
|
||||
#define CFG_PRF_DISS 1
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 0264280230aa6a828247b5f05bf57e33f1994581
|
|
@ -0,0 +1,92 @@
|
|||
#include "app_ble_profiles/app_ble_bass.h"
|
||||
|
||||
/* Stack configuration */
|
||||
#include "rwip_config.h"
|
||||
|
||||
/* BLE Stack */
|
||||
#include "ns_ble.h"
|
||||
|
||||
/* Profile */
|
||||
#include "bass.h"
|
||||
#include "bass_task.h"
|
||||
|
||||
static int app_ble_bass_level_upd_handler(ke_msg_id_t const msgid, struct bass_batt_level_upd_rsp const* param,
|
||||
ke_task_id_t const dest_id, ke_task_id_t const src_id);
|
||||
|
||||
static int app_ble_bass_level_ntf_cfg_ind_handler(ke_msg_id_t const msgid, void const* param,
|
||||
ke_task_id_t const dest_id, ke_task_id_t const src_id);
|
||||
|
||||
static int app_ble_bass_default_handler(ke_msg_id_t const msgid, void const* param, ke_task_id_t const dest_id,
|
||||
ke_task_id_t const src_id);
|
||||
|
||||
static const struct ke_msg_handler app_ble_bass_msg_handler_list[] = {
|
||||
{.id = KE_MSG_DEFAULT_HANDLER, .func = (ke_msg_func_t)app_ble_bass_default_handler},
|
||||
{.id = BASS_BATT_LEVEL_UPD_REQ, .func = (ke_msg_func_t)app_ble_bass_level_upd_handler},
|
||||
{.id = BASS_BATT_LEVEL_NTF_CFG_IND, .func = (ke_msg_func_t)app_ble_bass_level_ntf_cfg_ind_handler},
|
||||
};
|
||||
|
||||
static const struct app_subtask_handlers app_ble_bass_handlers = APP_HANDLERS(app_ble_bass);
|
||||
|
||||
void app_ble_bass_init(void) {
|
||||
struct bass_db_cfg* db_cfg;
|
||||
struct gapm_profile_task_add_cmd* req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, TASK_GAPM, TASK_APP,
|
||||
gapm_profile_task_add_cmd, sizeof(struct bass_db_cfg));
|
||||
req->operation = GAPM_PROFILE_TASK_ADD;
|
||||
req->sec_lvl = PERM(SVC_AUTH, NO_AUTH);
|
||||
req->prf_task_id = TASK_ID_BASS;
|
||||
req->app_task = TASK_APP;
|
||||
req->start_hdl = 0;
|
||||
|
||||
db_cfg = (struct bass_db_cfg*)req->param;
|
||||
|
||||
db_cfg->bas_nb = 1;
|
||||
db_cfg->features[0] = BAS_BATT_LVL_NTF_SUP;
|
||||
|
||||
ke_msg_send(req);
|
||||
|
||||
struct prf_task_t prf;
|
||||
prf.prf_task_id = TASK_ID_BASS;
|
||||
prf.prf_task_handler = &app_ble_bass_handlers;
|
||||
ns_ble_prf_task_register(&prf);
|
||||
|
||||
struct prf_get_func_t get_func;
|
||||
get_func.task_id = TASK_ID_BASS;
|
||||
get_func.prf_itf_get_func = bass_prf_itf_get;
|
||||
prf_get_itf_func_register(&get_func);
|
||||
}
|
||||
|
||||
void app_ble_bass_enable_prf(uint8_t conidx) {
|
||||
struct bass_enable_req* req =
|
||||
KE_MSG_ALLOC(BASS_ENABLE_REQ, prf_get_task_from_id(TASK_ID_BASS), TASK_APP, bass_enable_req);
|
||||
|
||||
req->conidx = conidx;
|
||||
req->ntf_cfg = PRF_CLI_STOP_NTFIND;
|
||||
req->old_batt_lvl[0] = 100;
|
||||
|
||||
ke_msg_send(req);
|
||||
}
|
||||
|
||||
void app_ble_bass_update_level(uint8_t level) {
|
||||
struct bass_batt_level_upd_req* req =
|
||||
KE_MSG_ALLOC(BASS_BATT_LEVEL_UPD_REQ, prf_get_task_from_id(TASK_ID_BASS), TASK_APP, bass_batt_level_upd_req);
|
||||
|
||||
req->bas_instance = 0;
|
||||
req->batt_level = level;
|
||||
|
||||
ke_msg_send(req);
|
||||
}
|
||||
|
||||
static int app_ble_bass_level_upd_handler(ke_msg_id_t const msgid, struct bass_batt_level_upd_rsp const* param,
|
||||
ke_task_id_t const dest_id, ke_task_id_t const src_id) {
|
||||
return KE_MSG_CONSUMED;
|
||||
}
|
||||
|
||||
static int app_ble_bass_level_ntf_cfg_ind_handler(ke_msg_id_t const msgid, void const* param,
|
||||
ke_task_id_t const dest_id, ke_task_id_t const src_id) {
|
||||
return KE_MSG_CONSUMED;
|
||||
}
|
||||
|
||||
static int app_ble_bass_default_handler(ke_msg_id_t const msgid, void const* param, ke_task_id_t const dest_id,
|
||||
ke_task_id_t const src_id) {
|
||||
return KE_MSG_CONSUMED;
|
||||
}
|
|
@ -13,11 +13,11 @@
|
|||
static int app_ble_diss_handler(ke_msg_id_t const msgid, struct diss_value_req_ind const *param,
|
||||
ke_task_id_t const dest_id, ke_task_id_t const src_id);
|
||||
|
||||
static const struct ke_msg_handler app_diss_msg_handler_list[] = {
|
||||
{DISS_VALUE_REQ_IND, (ke_msg_func_t)app_ble_diss_handler},
|
||||
static const struct ke_msg_handler app_ble_diss_msg_handler_list[] = {
|
||||
{.id = DISS_VALUE_REQ_IND, .func = (ke_msg_func_t)app_ble_diss_handler},
|
||||
};
|
||||
|
||||
static const struct app_subtask_handlers app_diss_handlers = APP_HANDLERS(app_diss);
|
||||
static const struct app_subtask_handlers app_ble_diss_handlers = APP_HANDLERS(app_ble_diss);
|
||||
|
||||
void app_ble_diss_init(void) {
|
||||
struct diss_db_cfg *db_cfg;
|
||||
|
@ -36,7 +36,7 @@ void app_ble_diss_init(void) {
|
|||
|
||||
struct prf_task_t prf;
|
||||
prf.prf_task_id = TASK_ID_DISS;
|
||||
prf.prf_task_handler = &app_diss_handlers;
|
||||
prf.prf_task_handler = &app_ble_diss_handlers;
|
||||
ns_ble_prf_task_register(&prf);
|
||||
|
||||
struct prf_get_func_t get_func;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "ns_sec.h"
|
||||
|
||||
/* Profiles */
|
||||
#include "app_ble_profiles/app_ble_bass.h"
|
||||
#include "app_ble_profiles/app_ble_diss.h"
|
||||
|
||||
/* Board */
|
||||
|
@ -71,6 +72,7 @@ static void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) {
|
|||
break;
|
||||
case APP_BLE_GAP_CONNECTED:
|
||||
board_led_set(1, true);
|
||||
app_ble_bass_enable_prf(app_env.conidx);
|
||||
break;
|
||||
case APP_BLE_GAP_DISCONNECTED:
|
||||
ns_ble_adv_start();
|
||||
|
@ -169,5 +171,6 @@ static void app_ble_sec_init(void) {
|
|||
}
|
||||
|
||||
static void app_ble_prf_init(void) {
|
||||
ns_ble_add_prf_func_register(app_ble_bass_init);
|
||||
ns_ble_add_prf_func_register(app_ble_diss_init);
|
||||
}
|
12
src/main.c
12
src/main.c
|
@ -8,6 +8,9 @@
|
|||
/* Board */
|
||||
#include "board.h"
|
||||
|
||||
/* Profiles */
|
||||
#include "app_ble_profiles/app_ble_bass.h"
|
||||
|
||||
void app_ble_init(void);
|
||||
|
||||
static void task_initialize(void *parameters);
|
||||
|
@ -32,8 +35,15 @@ dead_loop:
|
|||
}
|
||||
|
||||
static void task_initialize(void *parameters) {
|
||||
uint8_t battery_level = 0U;
|
||||
for (;;) {
|
||||
board_led_toggle(0);
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
app_ble_bass_update_level(battery_level);
|
||||
|
||||
battery_level++;
|
||||
if (battery_level > 100) {
|
||||
battery_level = 0;
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue