mirror of
https://github.com/m5stack/StackChan.git
synced 2026-04-27 19:12:40 +00:00
update firmware v1.2.4 (#16)
This commit is contained in:
@@ -32,8 +32,35 @@
|
||||
|
||||
#if CONFIG_EXAMPLE_EXTENDED_ADV
|
||||
static uint8_t ext_adv_pattern_1[] = {
|
||||
0x02, 0x01, 0x06, 0x03, 0x03, 0xab, 0xcd, 0x03, 0x03, 0x18, 0x11, 0x11, 0X09, 'n', 'i',
|
||||
'm', 'b', 'l', 'e', '-', 'b', 'l', 'e', 'p', 'r', 'p', 'h', '-', 'e',
|
||||
0x02,
|
||||
BLE_HS_ADV_TYPE_FLAGS,
|
||||
0x06,
|
||||
0x03,
|
||||
BLE_HS_ADV_TYPE_COMP_UUIDS16,
|
||||
0xab,
|
||||
0xcd,
|
||||
0x03,
|
||||
BLE_HS_ADV_TYPE_COMP_UUIDS16,
|
||||
0x18,
|
||||
0x11,
|
||||
0x11,
|
||||
BLE_HS_ADV_TYPE_COMP_NAME,
|
||||
'n',
|
||||
'i',
|
||||
'm',
|
||||
'b',
|
||||
'l',
|
||||
'e',
|
||||
'-',
|
||||
'b',
|
||||
'l',
|
||||
'e',
|
||||
'p',
|
||||
'r',
|
||||
'p',
|
||||
'h',
|
||||
'-',
|
||||
'e',
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -50,6 +77,8 @@ static uint16_t cids[MYNEWT_VAL(BLE_EATT_CHAN_NUM)];
|
||||
static uint16_t bearers;
|
||||
#endif
|
||||
|
||||
static bool s_use_alt_uuid = false;
|
||||
|
||||
void ble_store_config_init(void);
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
@@ -103,8 +132,8 @@ static void ext_bleprph_advertise(void)
|
||||
|
||||
params.primary_phy = BLE_HCI_LE_PHY_1M;
|
||||
params.secondary_phy = BLE_HCI_LE_PHY_2M;
|
||||
// params.tx_power = 127;
|
||||
params.sid = 1;
|
||||
params.tx_power = 127;
|
||||
params.sid = 1;
|
||||
|
||||
params.itvl_min = BLE_GAP_ADV_FAST_INTERVAL1_MIN;
|
||||
params.itvl_max = BLE_GAP_ADV_FAST_INTERVAL1_MIN;
|
||||
@@ -229,10 +258,17 @@ static void bleprph_advertise(void)
|
||||
// fields.num_uuids16 = 1;
|
||||
// fields.uuids16_is_complete = 1;
|
||||
|
||||
ble_uuid128_t stackchan_uuid = BLE_UUID128_INIT(STACKCHAN_SVC_UUID_BASE);
|
||||
fields.uuids128 = &stackchan_uuid;
|
||||
fields.num_uuids128 = 1;
|
||||
fields.uuids128_is_complete = 1;
|
||||
ble_uuid128_t stackchan_uuid = BLE_UUID128_INIT(STACKCHAN_SVC_UUID_BASE);
|
||||
ble_uuid128_t stackchan_uuid_alt = BLE_UUID128_INIT(STACKCHAN_SVC_UUID_BASE_ALT);
|
||||
|
||||
if (s_use_alt_uuid) {
|
||||
fields.uuids128 = &stackchan_uuid_alt;
|
||||
} else {
|
||||
fields.uuids128 = &stackchan_uuid;
|
||||
}
|
||||
|
||||
fields.num_uuids128 = 1;
|
||||
fields.uuids128_is_complete = 1;
|
||||
|
||||
rc = ble_gap_adv_set_fields(&fields);
|
||||
if (rc != 0) {
|
||||
@@ -600,8 +636,9 @@ void bleprph_host_task(void *param)
|
||||
nimble_port_freertos_deinit();
|
||||
}
|
||||
|
||||
void ble_prph_init(void)
|
||||
void ble_prph_init(bool use_alt_uuid)
|
||||
{
|
||||
s_use_alt_uuid = use_alt_uuid;
|
||||
int rc;
|
||||
esp_err_t ret;
|
||||
|
||||
@@ -647,14 +684,18 @@ void ble_prph_init(void)
|
||||
ble_hs_cfg.sm_their_key_dist |= BLE_SM_PAIR_KEY_DIST_ID;
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(STATIC_PASSKEY) && NIMBLE_BLE_CONNECT
|
||||
ble_sm_configure_static_passkey(456789, true);
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATTS)
|
||||
rc = gatt_svr_init();
|
||||
rc = gatt_svr_init(use_alt_uuid);
|
||||
assert(rc == 0);
|
||||
#endif
|
||||
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
/* Set the default device name. */
|
||||
rc = ble_svc_gap_device_name_set("Stack-Chan");
|
||||
rc = ble_svc_gap_device_name_set("StackChan");
|
||||
assert(rc == 0);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -44,6 +44,10 @@ struct ble_gatt_register_ctxt;
|
||||
#define STACKCHAN_SVC_UUID_BASE \
|
||||
0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12, 0xe0, 0xe5, 0xe5, 0xe2
|
||||
|
||||
// Service UUID Alt: e2e5e5ff-1234-5678-1234-56789abcdef0
|
||||
#define STACKCHAN_SVC_UUID_BASE_ALT \
|
||||
0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12, 0xff, 0xe5, 0xe5, 0xe2
|
||||
|
||||
// Motion Characteristic UUID: e2e5e5e1-1234-5678-1234-56789abcdef0
|
||||
#define STACKCHAN_CHR_MOTION_UUID \
|
||||
0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12, 0xe1, 0xe5, 0xe5, 0xe2
|
||||
@@ -160,9 +164,9 @@ void stackchan_ble_set_conn_handle(uint16_t conn_handle);
|
||||
bool stackchan_ble_is_connected(void);
|
||||
|
||||
void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg);
|
||||
int gatt_svr_init(void);
|
||||
int gatt_svr_init(bool use_alt_uuid);
|
||||
|
||||
void ble_prph_init(void);
|
||||
void ble_prph_init(bool use_alt_uuid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@
|
||||
#define MAX_NOTIFY 5
|
||||
|
||||
/* Stack-Chan Service */
|
||||
static const ble_uuid128_t stackchan_svc_uuid = BLE_UUID128_INIT(STACKCHAN_SVC_UUID_BASE);
|
||||
static const ble_uuid128_t stackchan_svc_uuid = BLE_UUID128_INIT(STACKCHAN_SVC_UUID_BASE);
|
||||
static const ble_uuid128_t stackchan_svc_uuid_alt = BLE_UUID128_INIT(STACKCHAN_SVC_UUID_BASE_ALT);
|
||||
|
||||
static const ble_uuid128_t stackchan_chr_motion_uuid = BLE_UUID128_INIT(STACKCHAN_CHR_MOTION_UUID);
|
||||
|
||||
@@ -77,7 +78,7 @@ static int stackchan_svc_access(uint16_t conn_handle, uint16_t attr_handle, stru
|
||||
|
||||
static int battery_svc_access(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg);
|
||||
|
||||
static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
|
||||
static struct ble_gatt_svc_def gatt_svr_svcs[] = {
|
||||
{
|
||||
/*** Stack-Chan Service ***/
|
||||
.type = BLE_GATT_SVC_TYPE_PRIMARY,
|
||||
@@ -321,7 +322,7 @@ void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
int gatt_svr_init(void)
|
||||
int gatt_svr_init(bool use_alt_uuid)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@@ -339,6 +340,12 @@ int gatt_svr_init(void)
|
||||
ble_svc_gap_init();
|
||||
ble_svc_gatt_init();
|
||||
|
||||
if (use_alt_uuid) {
|
||||
gatt_svr_svcs[0].uuid = &stackchan_svc_uuid_alt.u;
|
||||
} else {
|
||||
gatt_svr_svcs[0].uuid = &stackchan_svc_uuid.u;
|
||||
}
|
||||
|
||||
rc = ble_gatts_count_cfg(gatt_svr_svcs);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@@ -32,7 +32,7 @@ static int enter_passkey_handler(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
sscanf(argv[1], "%s", pkey);
|
||||
sscanf(argv[1], "%7s", pkey);
|
||||
ESP_LOGI("You entered", "%s %s", argv[0], argv[1]);
|
||||
num = pkey[0];
|
||||
|
||||
@@ -45,7 +45,9 @@ static int enter_passkey_handler(int argc, char *argv[])
|
||||
xQueueSend(cli_handle, &key, 0);
|
||||
}
|
||||
} else {
|
||||
sscanf(pkey, "%d", &key);
|
||||
if (sscanf(pkey, "%d", &key) != 1) {
|
||||
key = 0;
|
||||
}
|
||||
xQueueSend(cli_handle, &key, 0);
|
||||
}
|
||||
|
||||
@@ -84,14 +86,14 @@ static void scli_task(void *arg)
|
||||
QueueHandle_t uart_queue;
|
||||
uart_event_t event;
|
||||
|
||||
uart_driver_install(uart_num, 256, 0, 8, &uart_queue, 0);
|
||||
ESP_ERROR_CHECK(uart_driver_install(uart_num, 256, 0, 8, &uart_queue, 0));
|
||||
/* Initialize the console */
|
||||
esp_console_config_t console_config = {
|
||||
.max_cmdline_args = 8,
|
||||
.max_cmdline_length = 256,
|
||||
};
|
||||
|
||||
esp_console_init(&console_config);
|
||||
ESP_ERROR_CHECK(esp_console_init(&console_config));
|
||||
|
||||
while (!stop) {
|
||||
i = 0;
|
||||
@@ -107,6 +109,9 @@ static void scli_task(void *arg)
|
||||
}
|
||||
if (event.type == UART_DATA) {
|
||||
while (uart_read_bytes(uart_num, (uint8_t *)&linebuf[i], 1, 0)) {
|
||||
if (i >= sizeof(linebuf) - 1) {
|
||||
break;
|
||||
}
|
||||
if (linebuf[i] == '\r') {
|
||||
uart_write_bytes(uart_num, "\r\n", 2);
|
||||
} else {
|
||||
@@ -115,13 +120,17 @@ static void scli_task(void *arg)
|
||||
i++;
|
||||
}
|
||||
}
|
||||
} while ((i < 255) && linebuf[i - 1] != '\r');
|
||||
|
||||
} while ((i < 255) && (i == 0 || linebuf[i - 1] != '\r'));
|
||||
if (stop) {
|
||||
break;
|
||||
}
|
||||
/* Remove the truncating \r\n */
|
||||
linebuf[strlen((char *)linebuf) - 1] = '\0';
|
||||
ret = esp_console_run((char *)linebuf, &cmd_ret);
|
||||
size_t len = strlen((char *)linebuf);
|
||||
if (len > 0) {
|
||||
linebuf[len - 1] = '\0';
|
||||
}
|
||||
ret = esp_console_run((char *)linebuf, &cmd_ret);
|
||||
if (ret < 0) {
|
||||
break;
|
||||
}
|
||||
@@ -144,3 +153,40 @@ int scli_init(void)
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
int scli_deinit(void)
|
||||
{
|
||||
if (cli_task == NULL) {
|
||||
return ESP_OK; // Already deinitialized
|
||||
}
|
||||
|
||||
// Signal task to exit
|
||||
stop = 1;
|
||||
|
||||
// Wait for task to exit (it will clean up UART and console)
|
||||
int timeout_ms = 200;
|
||||
while (timeout_ms > 0 && cli_task != NULL && eTaskGetState(cli_task) != eDeleted) {
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
timeout_ms -= 10;
|
||||
}
|
||||
|
||||
// Force delete if still running (shouldn't happen if task exits properly)
|
||||
if (cli_task != NULL && eTaskGetState(cli_task) != eDeleted) {
|
||||
vTaskDelete(cli_task);
|
||||
// If force-deleted, clean up resources manually
|
||||
uart_driver_delete(0);
|
||||
esp_console_deinit();
|
||||
}
|
||||
cli_task = NULL;
|
||||
|
||||
// Clean up queue
|
||||
if (cli_handle != NULL) {
|
||||
vQueueDelete(cli_handle);
|
||||
cli_handle = NULL;
|
||||
}
|
||||
|
||||
// Reset stop flag
|
||||
stop = 0;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user