发布 HPW422 V1.3 第一版量产代码
This commit is contained in:
@@ -538,6 +538,7 @@ static uint8_t gapc_callback(ke_msg_id_t const msgid, void const *param,
|
||||
if (p_param->role == GAPM_ROLE_SLAVE) {
|
||||
app_env.slave_conidx = conidx;
|
||||
app_env.slave_connected = true;
|
||||
ble_state_on_connect();
|
||||
}
|
||||
// Check if the received connection index is valid
|
||||
if (conidx != GAP_INVALID_CONIDX) {
|
||||
@@ -563,6 +564,7 @@ static uint8_t gapc_callback(ke_msg_id_t const msgid, void const *param,
|
||||
if (conidx == app_env.slave_conidx) {
|
||||
app_env.slave_conidx = INVALID_DATA;
|
||||
app_env.slave_connected = false;
|
||||
ble_state_on_disconnect();
|
||||
app_start_advertising();
|
||||
}
|
||||
custom_svc_tx_char_notify = DISABLE;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "timeslice.h"
|
||||
#include "dbg.h"
|
||||
#include "rf433_decoder.h"
|
||||
#include "usr_server.h"
|
||||
////用bit表示通道
|
||||
//#define CH_GPIO2 0x01
|
||||
//#define CH_GPIO5 0x10
|
||||
@@ -215,11 +216,13 @@ void _433_fun(void)
|
||||
if(match_ch & MATCH_CH2){
|
||||
xc_gpio_toggle_pin(GPIO_2);
|
||||
flash_ch2_state=xc_gpio_read_pin(GPIO_2);
|
||||
ble_state_mark_dirty(BLE_STATE_DIRTY_OUTPUT | BLE_STATE_DIRTY_RF433);
|
||||
}
|
||||
|
||||
if(match_ch & MATCH_CH1){
|
||||
xc_gpio_toggle_pin(GPIO_5);
|
||||
flash_ch1_state=xc_gpio_read_pin(GPIO_5);
|
||||
ble_state_mark_dirty(BLE_STATE_DIRTY_OUTPUT | BLE_STATE_DIRTY_RF433);
|
||||
}
|
||||
|
||||
|
||||
@@ -231,11 +234,13 @@ void _433_fun(void)
|
||||
{
|
||||
xc_gpio_write_pin(GPIO_2,GPIO_PIN_RESET);
|
||||
flash_ch2_state=xc_gpio_read_pin(GPIO_2);
|
||||
ble_state_mark_dirty(BLE_STATE_DIRTY_OUTPUT | BLE_STATE_DIRTY_RF433);
|
||||
}
|
||||
if(match_ch & MATCH_CH1)
|
||||
{
|
||||
xc_gpio_write_pin(GPIO_5,GPIO_PIN_RESET);
|
||||
flash_ch1_state=xc_gpio_read_pin(GPIO_5);
|
||||
ble_state_mark_dirty(BLE_STATE_DIRTY_OUTPUT | BLE_STATE_DIRTY_RF433);
|
||||
}
|
||||
|
||||
|
||||
@@ -246,12 +251,14 @@ void _433_fun(void)
|
||||
{
|
||||
xc_gpio_write_pin(GPIO_2,GPIO_PIN_SET);
|
||||
flash_ch2_state=xc_gpio_read_pin(GPIO_2);
|
||||
ble_state_mark_dirty(BLE_STATE_DIRTY_OUTPUT | BLE_STATE_DIRTY_RF433);
|
||||
}
|
||||
|
||||
if(match_ch & MATCH_CH1)
|
||||
{
|
||||
xc_gpio_write_pin(GPIO_5,GPIO_PIN_SET);
|
||||
flash_ch1_state=xc_gpio_read_pin(GPIO_5);
|
||||
ble_state_mark_dirty(BLE_STATE_DIRTY_OUTPUT | BLE_STATE_DIRTY_RF433);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "ota_flash_interface.h"
|
||||
#include "ota_protocol.h"
|
||||
#include "rf433_decoder.h"
|
||||
#include "usr_server.h"
|
||||
TASK_COMPONENTS TaskComps[] =
|
||||
{
|
||||
{0, 50, 50, ble_message_process}, //蓝牙处理任务
|
||||
@@ -17,6 +18,7 @@ TASK_COMPONENTS TaskComps[] =
|
||||
{0, 10, 10,trigger_check_process},
|
||||
{0, 300, 300, app_op_flash}, //用户数据持久化 fmc_spi_read9
|
||||
{0, 300, 300, xc_ota_schedule}, //保存flash数据任务
|
||||
{0, 1, 2, ble_state_sync_poll},
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "uart_1.h"
|
||||
#include "xc_drv_gpio.h"
|
||||
#include "rf433.h"
|
||||
#include "usr_server.h"
|
||||
//#include "dbg.h"
|
||||
ble_data_msg user_ble_data_msg;
|
||||
ble_data_msg *p_ble_data_msg = NULL;
|
||||
@@ -96,6 +97,7 @@ void ble_message_process(void)
|
||||
|
||||
|
||||
scan_uart(temp);
|
||||
ble_state_mark_dirty(BLE_STATE_DIRTY_LIGHT | BLE_STATE_DIRTY_OUTPUT);
|
||||
|
||||
p_ble_data_msg = NULL;
|
||||
|
||||
|
||||
@@ -13,8 +13,12 @@
|
||||
*/
|
||||
#include "usr_server.h"
|
||||
#include "uart_1.h"
|
||||
#include "xc_drv_gpio.h"
|
||||
#if (BLE_APP_PRESENT)
|
||||
|
||||
extern uint8_t adress_ch1_index;
|
||||
extern uint8_t adress_ch2_index;
|
||||
|
||||
uint8_t srv_user_lid = GATT_INVALID_USER_LID;
|
||||
uint16_t custom_svc_start_hdl = GATT_INVALID_HDL;
|
||||
uint8_t custom_svc_tx_char_notify = DISABLE;
|
||||
@@ -67,6 +71,122 @@ uint16_t srv_get_hdl_from_att_idx(uint8_t idx)
|
||||
return custom_svc_start_hdl + idx;
|
||||
}
|
||||
|
||||
static uint8_t ble_state_dirty = 0;
|
||||
static uint8_t ble_state_connect_delay = 0;
|
||||
static uint8_t ble_state_last_valid = 0;
|
||||
static uint8_t ble_state_last_output = 0;
|
||||
static uint8_t ble_state_last_ch1_count = 0;
|
||||
static uint8_t ble_state_last_ch2_count = 0;
|
||||
|
||||
static uint8_t ble_state_output_mask(void)
|
||||
{
|
||||
uint8_t mask = 0;
|
||||
|
||||
if (xc_gpio_read_pin(GPIO_5)) {
|
||||
mask |= 0x01;
|
||||
}
|
||||
if (xc_gpio_read_pin(GPIO_2)) {
|
||||
mask |= 0x02;
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
void ble_state_mark_dirty(uint8_t dirty)
|
||||
{
|
||||
ble_state_dirty |= dirty;
|
||||
}
|
||||
|
||||
static uint8_t ble_state_fill_packet(uint8_t *data)
|
||||
{
|
||||
data[0] = 0xA5;
|
||||
data[1] = 0x5A;
|
||||
data[2] = ble_state_dirty;
|
||||
data[3] = ble_state_output_mask();
|
||||
data[4] = 0;
|
||||
data[5] = 0;
|
||||
data[6] = 0;
|
||||
data[7] = FIRMWARE_VERSION_MAJOR;
|
||||
data[8] = FIRMWARE_VERSION_MINOR;
|
||||
data[9] = FIRMWARE_VERSION_PATCH;
|
||||
data[10] = adress_ch1_index;
|
||||
data[11] = adress_ch2_index;
|
||||
data[12] = 0;
|
||||
data[13] = 0;
|
||||
return 14;
|
||||
}
|
||||
|
||||
static void ble_state_detect_changes(void)
|
||||
{
|
||||
uint8_t output = ble_state_output_mask();
|
||||
uint8_t ch1_count = adress_ch1_index;
|
||||
uint8_t ch2_count = adress_ch2_index;
|
||||
|
||||
if (!ble_state_last_valid) {
|
||||
ble_state_last_output = output;
|
||||
ble_state_last_ch1_count = ch1_count;
|
||||
ble_state_last_ch2_count = ch2_count;
|
||||
ble_state_last_valid = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (ble_state_last_output != output) {
|
||||
ble_state_last_output = output;
|
||||
ble_state_mark_dirty(BLE_STATE_DIRTY_OUTPUT);
|
||||
}
|
||||
|
||||
if ((ble_state_last_ch1_count != ch1_count) ||
|
||||
(ble_state_last_ch2_count != ch2_count)) {
|
||||
ble_state_last_ch1_count = ch1_count;
|
||||
ble_state_last_ch2_count = ch2_count;
|
||||
ble_state_mark_dirty(BLE_STATE_DIRTY_RF433);
|
||||
}
|
||||
}
|
||||
|
||||
void ble_state_sync_poll(void)
|
||||
{
|
||||
uint8_t data[14];
|
||||
uint8_t len;
|
||||
struct app_env_tag *app_env = get_app_env();
|
||||
|
||||
if (!app_env->slave_connected) {
|
||||
ble_state_connect_delay = 0;
|
||||
ble_state_last_valid = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (ble_state_connect_delay > 0) {
|
||||
ble_state_connect_delay--;
|
||||
if (ble_state_connect_delay == 0) {
|
||||
ble_state_mark_dirty(BLE_STATE_DIRTY_FULL);
|
||||
}
|
||||
}
|
||||
|
||||
ble_state_detect_changes();
|
||||
|
||||
if (ble_state_dirty == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
len = ble_state_fill_packet(data);
|
||||
if (slave_send_data(data, len, CUSTOM_SVC_TX_CHAR_VAL) != INVALID_DATA) {
|
||||
ble_state_dirty = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ble_state_on_connect(void)
|
||||
{
|
||||
custom_svc_tx_char_notify = ENABLE;
|
||||
ble_state_connect_delay = 20;
|
||||
ble_state_mark_dirty(BLE_STATE_DIRTY_FULL);
|
||||
}
|
||||
|
||||
void ble_state_on_disconnect(void)
|
||||
{
|
||||
custom_svc_tx_char_notify = DISABLE;
|
||||
ble_state_connect_delay = 0;
|
||||
ble_state_last_valid = 0;
|
||||
}
|
||||
|
||||
// This function is called when GATT server user has initiated event send to
|
||||
// peer device or if an error occurs.
|
||||
__STATIC void custom_svc_cb_event_sent(uint8_t conidx, uint8_t user_lid,
|
||||
@@ -126,8 +246,7 @@ __STATIC void custom_svc_cb_att_val_set(uint8_t conidx, uint8_t user_lid,
|
||||
} else {
|
||||
LOGI("notify ENABLE\r\n");
|
||||
custom_svc_tx_char_notify = ENABLE;
|
||||
uint8_t data[] = {0x12, 0x13, 0x14};
|
||||
slave_send_data(data, sizeof(data), CUSTOM_SVC_TX_CHAR_VAL);
|
||||
ble_state_mark_dirty(BLE_STATE_DIRTY_FULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,20 @@ enum cust_svc
|
||||
CUSTOM_SVC_TX_CHAR_VAL,
|
||||
CUSTOM_SVC_TX_CHAR_CFG,
|
||||
};
|
||||
|
||||
#define FIRMWARE_VERSION_MAJOR 1
|
||||
#define FIRMWARE_VERSION_MINOR 3
|
||||
#define FIRMWARE_VERSION_PATCH 0
|
||||
|
||||
#define BLE_STATE_DIRTY_FULL 0x01
|
||||
#define BLE_STATE_DIRTY_OUTPUT 0x02
|
||||
#define BLE_STATE_DIRTY_RF433 0x04
|
||||
#define BLE_STATE_DIRTY_LIGHT 0x08
|
||||
|
||||
uint8_t custom_svc_add(void);
|
||||
uint8_t slave_send_data(uint8_t *data, uint8_t len, uint8_t att_idx);
|
||||
void ble_state_mark_dirty(uint8_t dirty);
|
||||
void ble_state_sync_poll(void);
|
||||
void ble_state_on_connect(void);
|
||||
void ble_state_on_disconnect(void);
|
||||
#endif // _USR_SERVER_H_
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -10,7 +10,7 @@
|
||||
<TargetName>ble-sdk-xip</TargetName>
|
||||
<ToolsetNumber>0x4</ToolsetNumber>
|
||||
<ToolsetName>ARM-ADS</ToolsetName>
|
||||
<pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARMCC</pCCUsed>
|
||||
<pCCUsed>5060750::V5.06 update 6 (build 750)::.\ARMCC</pCCUsed>
|
||||
<uAC6>0</uAC6>
|
||||
<TargetOption>
|
||||
<TargetCommonOption>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -68,5 +68,7 @@ set Ota_use_bin=.\output_bin\ota_data_double.bin
|
||||
|
||||
copy %Download_bin% .\
|
||||
|
||||
call "%~dp0..\..\..\..\..\..\..\make_release_bin.bat"
|
||||
if errorlevel 1 exit /b 1
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user