Skip to content

Commit

Permalink
update v0.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Apr 27, 2021
1 parent 479308b commit 74a6555
Show file tree
Hide file tree
Showing 97 changed files with 1,061 additions and 440 deletions.
62 changes: 62 additions & 0 deletions apps/common/key/touch_key.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "touch_key.h"
#include "key_driver.h"
#include "app_config.h"


#if TCFG_TOUCH_KEY_ENABLE


/* =========== 触摸键使用说明 ============= */
//1. 使用plcnt模块作计数;
//2. 配置参数时, 在配置好时钟后, 需要调试no_touch_cnt和touch_cnt的值;

static const struct touch_key_platform_data *__this = NULL;

//按键驱动扫描参数列表
struct key_driver_para touch_key_scan_para = {
.scan_time = 10, //按键扫描频率, 单位: ms
.last_key = NO_KEY, //上一次get_value按键值, 初始化为NO_KEY;
.filter_time = 1, //按键消抖延时;
.long_time = 75, //按键判定长按数量
.hold_time = (75 + 15), //按键判定HOLD数量
.click_delay_time = 20, //按键被抬起后等待连击延时数量
.key_type = KEY_DRIVER_TYPE_TOUCH,
.get_value = touch_key_get_value,
};

#define TOUCH_KEY_DEBUG 0

#if TOUCH_KEY_DEBUG
#define touch_key_debug(fmt, ...) printf("[TOUCH] "fmt, ##__VA_ARGS__)
#else
#define touch_key_debug(fmt, ...)
#endif


u8 touch_key_get_value(void)
{
u8 key = get_plcnt_value();

if (key != NO_KEY) {
touch_key_debug("key = %d", key);
return __this->port_list[key].key_value;
}

return NO_KEY;
}


int touch_key_init(const struct touch_key_platform_data *touch_key_data)
{
__this = touch_key_data;
printf("touch_key_init >>>> ");

return plcnt_init((void *)touch_key_data);
}


#endif /* #if TCFG_TOUCH_KEY_ENABLE */




2 changes: 1 addition & 1 deletion apps/common/third_party_profile/jieli/le_at_char_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ static void do_operate_search_handle(void)
}

//return: 0--accept,1--reject
int l2cap_connection_update_request_just(u8 *packet)
int l2cap_connection_update_request_just(u8 *packet, hci_con_handle_t handle)
{
log_info("slave request conn_update:\n-interval_min= %d,\n-interval_max= %d,\n-latency= %d,\n-timeout= %d\n",
little_endian_read_16(packet, 0), little_endian_read_16(packet, 2),
Expand Down
2 changes: 1 addition & 1 deletion apps/common/third_party_profile/jieli/le_at_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ static void do_operate_search_handle(void)
}

//return: 0--accept,1--reject
int l2cap_connection_update_request_just(u8 *packet)
int l2cap_connection_update_request_just(u8 *packet, hci_con_handle_t handle)
{
log_info("slave request conn_update:\n-interval_min= %d,\n-interval_max= %d,\n-latency= %d,\n-timeout= %d\n",
little_endian_read_16(packet, 0), little_endian_read_16(packet, 2),
Expand Down
147 changes: 79 additions & 68 deletions apps/common/third_party_profile/jieli/le_at_com.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ static const struct conn_update_param_t connection_param_table[] = {
};
#define CONN_PARAM_TABLE_CNT (sizeof(connection_param_table)/sizeof(struct conn_update_param_t))

#if (ATT_RAM_BUFSIZE < 64)
#error "adv_data & rsp_data buffer error!!!!!!!!!!!!"
#endif
/* #if (ATT_RAM_BUFSIZE < 64) */
/* #error "adv_data & rsp_data buffer error!!!!!!!!!!!!" */
/* #endif */

//用户可配对的,这是样机跟客户开发的app配对的秘钥
/* const u8 link_key_data[16] = {0x06, 0x77, 0x5f, 0x87, 0x91, 0x8d, 0xd4, 0x23, 0x00, 0x5d, 0xf1, 0xd8, 0xcf, 0x0c, 0x14, 0x2b}; */
Expand Down Expand Up @@ -813,75 +813,20 @@ static int app_send_user_data(u16 handle, u8 *data, u16 len, u8 handle_type)
return ret;
}

//------------------------------------------------------
static int make_set_adv_data(void)
{
u8 offset = 0;
u8 *buf = adv_data;

/* offset += make_eir_packet_val(&buf[offset], offset, HCI_EIR_DATATYPE_FLAGS, 0x18, 1); */
/* offset += make_eir_packet_val(&buf[offset], offset, HCI_EIR_DATATYPE_FLAGS, 0x1A, 1); */
offset += make_eir_packet_val(&buf[offset], offset, HCI_EIR_DATATYPE_FLAGS, 0x06, 1);
offset += make_eir_packet_val(&buf[offset], offset, HCI_EIR_DATATYPE_COMPLETE_16BIT_SERVICE_UUIDS, 0xAF30, 2);

if (offset > ADV_RSP_PACKET_MAX) {
puts("***adv_data overflow!!!!!!\n");
return -1;
}
log_info("adv_data(%d):", offset);
log_info_hexdump(buf, offset);
adv_data_len = offset;
ble_op_set_adv_data(offset, buf);
return 0;
}

static int make_set_rsp_data(void)
{
u8 offset = 0;
u8 *buf = scan_rsp_data;

#if RCSP_BTMATE_EN
u8 tag_len = sizeof(user_tag_string);
offset += make_eir_packet_data(&buf[offset], offset, HCI_EIR_DATATYPE_MANUFACTURER_SPECIFIC_DATA, (void *)user_tag_string, tag_len);
#endif

u8 name_len = gap_device_name_len;
u8 vaild_len = ADV_RSP_PACKET_MAX - (offset + 2);
if (name_len > vaild_len) {
name_len = vaild_len;
}
offset += make_eir_packet_data(&buf[offset], offset, HCI_EIR_DATATYPE_COMPLETE_LOCAL_NAME, (void *)gap_device_name, name_len);

if (offset > ADV_RSP_PACKET_MAX) {
puts("***rsp_data overflow!!!!!!\n");
return -1;
}

log_info("rsp_data(%d):", offset);
log_info_hexdump(buf, offset);
scan_rsp_data_len = offset;
ble_op_set_rsp_data(offset, buf);
return 0;
}

//广播参数设置
static void advertisements_setup_init()
{
uint8_t adv_type = ADV_IND;
uint8_t adv_channel = ADV_CHANNEL_ALL;
int ret = 0;

ble_op_set_adv_param(ADV_INTERVAL_MIN, adv_type, adv_channel);
ble_op_set_adv_data(adv_data_len, adv_data);
ble_op_set_rsp_data(scan_rsp_data_len, scan_rsp_data);

if (auto_adv_enable) {
ret |= make_set_adv_data();
ret |= make_set_rsp_data();
}

if (ret) {
puts("advertisements_setup_init fail !!!!!!\n");
return;
}
log_info("set_adv_data(%d):", adv_data_len);
log_info_hexdump(adv_data, adv_data_len);
log_info("set_rsp_data(%d):", scan_rsp_data_len);
log_info_hexdump(scan_rsp_data, scan_rsp_data_len);

}

Expand Down Expand Up @@ -1227,6 +1172,10 @@ void bt_ble_init(void)

log_info("ble name(%d): %s \n", gap_device_name_len, gap_device_name);

adv_data_len = 0;
scan_rsp_data_len = 0;
con_handle = 0;

set_ble_work_state(BLE_ST_INIT_OK);
ble_module_enable(1);

Expand Down Expand Up @@ -1454,8 +1403,8 @@ int ble_at_set_adv_data(u8 *data, u8 len)
return APP_BLE_OPERATION_ERROR;
}

memcpy(at_tmp_buffer, data, len);
ble_op_set_adv_data(len, at_tmp_buffer);
memcpy(adv_data, data, len);
adv_data_len = len;
return APP_BLE_NO_ERROR;
}

Expand All @@ -1469,8 +1418,8 @@ int ble_at_set_rsp_data(u8 *data, u8 len)
return APP_BLE_OPERATION_ERROR;
}

memcpy(at_tmp_buffer, data, len);
ble_op_set_rsp_data(len, at_tmp_buffer);
memcpy(scan_rsp_data, data, len);
scan_rsp_data_len = len;
return APP_BLE_NO_ERROR;
}

Expand All @@ -1494,10 +1443,72 @@ void input_key_handler(u8 key_status, u8 key_number)
{
}

//------------------------------------------------------
static int default_make_set_adv_data(void)
{
u8 offset = 0;
u8 *buf = adv_data;

/* offset += make_eir_packet_val(&buf[offset], offset, HCI_EIR_DATATYPE_FLAGS, 0x18, 1); */
/* offset += make_eir_packet_val(&buf[offset], offset, HCI_EIR_DATATYPE_FLAGS, 0x1A, 1); */
offset += make_eir_packet_val(&buf[offset], offset, HCI_EIR_DATATYPE_FLAGS, 0x06, 1);
offset += make_eir_packet_val(&buf[offset], offset, HCI_EIR_DATATYPE_COMPLETE_16BIT_SERVICE_UUIDS, 0xAF30, 2);

if (offset > ADV_RSP_PACKET_MAX) {
puts("***adv_data overflow!!!!!!\n");
return -1;
}
log_info("default_adv_data(%d):", offset);
log_info_hexdump(buf, offset);
adv_data_len = offset;
return 0;
}

static int default_make_set_rsp_data(void)
{
u8 offset = 0;
u8 *buf = scan_rsp_data;

#if RCSP_BTMATE_EN
u8 tag_len = sizeof(user_tag_string);
offset += make_eir_packet_data(&buf[offset], offset, HCI_EIR_DATATYPE_MANUFACTURER_SPECIFIC_DATA, (void *)user_tag_string, tag_len);
#endif

u8 name_len = gap_device_name_len;
u8 vaild_len = ADV_RSP_PACKET_MAX - (offset + 2);
if (name_len > vaild_len) {
name_len = vaild_len;
}
offset += make_eir_packet_data(&buf[offset], offset, HCI_EIR_DATATYPE_COMPLETE_LOCAL_NAME, (void *)gap_device_name, name_len);

if (offset > ADV_RSP_PACKET_MAX) {
puts("***rsp_data overflow!!!!!!\n");
return -1;
}

log_info("default_rsp_data(%d):", offset);
log_info_hexdump(buf, offset);
scan_rsp_data_len = offset;
return 0;
}


void ble_test_auto_adv(u8 en)
{
log_info("ble_test_auto_adv = %d", en);
auto_adv_enable = en;
int ret = 0;

if (auto_adv_enable) {
ret |= default_make_set_adv_data();
ret |= default_make_set_rsp_data();
}

if (ret) {
puts("make adv&rsp data fail!!!\n");
return;
}

bt_ble_adv_enable(en);
}

Expand Down
2 changes: 1 addition & 1 deletion apps/common/third_party_profile/jieli/le_client_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ static void do_operate_search_handle(void)

//协议栈内部调用
//return: 0--accept,1--reject
int l2cap_connection_update_request_just(u8 *packet)
int l2cap_connection_update_request_just(u8 *packet, hci_con_handle_t handle)
{
log_info("slave request conn_update:\n-interval_min= %d,\n-interval_max= %d,\n-latency= %d,\n-timeout= %d\n",
little_endian_read_16(packet, 0), little_endian_read_16(packet, 2),
Expand Down
1 change: 1 addition & 0 deletions apps/common/third_party_profile/jieli/le_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "typedef.h"
#include <stdint.h>
#include "btstack/bluetooth.h"
#include "app_config.h"

//--------------------------------------------
#define LE_DEBUG_PRINT_EN 1 // log switch
Expand Down
17 changes: 8 additions & 9 deletions apps/common/third_party_profile/jieli/le_hogp.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,15 @@ static const char Firmware_Revision_String[] = "0.0.1";
static const char Software_Revision_String[] = "0.0.1";
static const u8 System_ID[] = {0, 0, 0, 0, 0, 0, 0, 0};

/*
typedef struct{
u8 vendor_id_source;
u16 vendor_id;
u16 product_id;
u16 product_version;
}
*/
//定义的产品信息,for test
#define PNP_VID_SOURCE 0x02
#define PNP_VID 0x05ac //0x05d6
#define PNP_PID 0x022C //
#define PNP_PID_VERSION 0x011b //1.1.11

static const u8 PnP_ID[] = {PNP_VID_SOURCE, PNP_VID & 0xFF, PNP_VID >> 8, PNP_PID & 0xFF, PNP_PID >> 8, PNP_PID_VERSION & 0xFF, PNP_PID_VERSION >> 8};
/* static const u8 PnP_ID[] = {0x02, 0x17, 0x27, 0x40, 0x00, 0x23, 0x00}; */
static const u8 PnP_ID[] = {0x02, 0xac, 0x05, 0x2c, 0x02, 0x1b, 0x01};
/* static const u8 PnP_ID[] = {0x02, 0xac, 0x05, 0x2c, 0x02, 0x1b, 0x01}; */

/* static const u8 hid_information[] = {0x11, 0x01, 0x00, 0x01}; */
static const u8 hid_information[] = {0x01, 0x01, 0x00, 0x03};
Expand Down
Loading

0 comments on commit 74a6555

Please sign in to comment.