diff --git a/project/example/ble/ble_peripheral/app/api/app_task.h b/project/example/ble/ble_peripheral/app/api/app_task.h index c56c201..aa1cf57 100644 --- a/project/example/ble/ble_peripheral/app/api/app_task.h +++ b/project/example/ble/ble_peripheral/app/api/app_task.h @@ -49,7 +49,7 @@ } /// Default Device Name -#define APP_DFLT_DEVICE_NAME ("HPW422") +#define APP_DFLT_DEVICE_NAME ("HPW421") #define APP_DFLT_DEVICE_NAME_LEN (sizeof(APP_DFLT_DEVICE_NAME))//must not be greater than APP_DEVICE_NAME_MAX_LEN #define APP_SINGLEOTA_DEVICE_NAME "OTA_TEST" #define APP_SINGLEOTA_DEVICE_NAME_LEN (sizeof(APP_SINGLEOTA_DEVICE_NAME)) diff --git a/project/example/ble/ble_peripheral/app/src/fmc_spi_1.c b/project/example/ble/ble_peripheral/app/src/fmc_spi_1.c index 29cb347..e65ba16 100644 --- a/project/example/ble/ble_peripheral/app/src/fmc_spi_1.c +++ b/project/example/ble/ble_peripheral/app/src/fmc_spi_1.c @@ -1,6 +1,7 @@ #include "fmc_spi_1.h" #include "xc_drv_fmc_spi.h" #include "rf433.h" +#include uint8_t r_data[256]; @@ -54,8 +55,11 @@ void read_user_data(void) adress_ch1_index = r_data[22]; adress_ch2_index = r_data[23]; - flash_ch1_state=r_data[24]; + flash_ch1_state=0; flash_ch2_state=r_data[25]; + memset(adress_H_ch1, 0, sizeof(adress_H_ch1)); + memset(adress_L_ch1, 0, sizeof(adress_L_ch1)); + adress_ch1_index = 0; } } diff --git a/project/example/ble/ble_peripheral/app/src/rf433.c b/project/example/ble/ble_peripheral/app/src/rf433.c index a4ee9fe..bf95b23 100644 --- a/project/example/ble/ble_peripheral/app/src/rf433.c +++ b/project/example/ble/ble_peripheral/app/src/rf433.c @@ -42,7 +42,7 @@ uint8_t adress_ch2_index = 0; // 通道2地址索引(0-4) uint8_t match_ch = 0; // 匹配到的通道(1=GPIO5,2=GPIO2) -#define MATCH_CH1 (1 << 0) // 通道1匹配标记 +#define MATCH_CH1 0 // HPW421 不使用通道1 #define MATCH_CH2 (1 << 1) // 通道2匹配标记 @@ -94,29 +94,18 @@ void chx_gpio_init(void) GPIO_InitCfg.Dir = GPIO_DIR_OUTPUT; // 输出方向 GPIO_InitCfg.Int = NOT_INT; // 不使能中断 - GPIO_InitCfg.Pin = RELAY_CH1_PIN; // 设置通道5引脚 - xc_gpio_init(&GPIO_InitCfg); // 初始化GPIO - GPIO_InitCfg.Dir = GPIO_DIR_OUTPUT; // 输出方向 GPIO_InitCfg.Int = NOT_INT; // 不使能中断 GPIO_InitCfg.Pin = RELAY_CH2_PIN; // 设置通道2引脚 xc_gpio_init(&GPIO_InitCfg); // 初始化GPIO - if(flash_ch1_state==1) - { - xc_gpio_write_pin(GPIO_5,GPIO_PIN_SET); - } - else - { - xc_gpio_write_pin(GPIO_5,GPIO_PIN_RESET); - } if(flash_ch2_state==1) { - xc_gpio_write_pin(GPIO_2,GPIO_PIN_SET); + xc_gpio_write_pin(RELAY_CH2_PIN,GPIO_PIN_SET); } else { - xc_gpio_write_pin(GPIO_2,GPIO_PIN_RESET); + xc_gpio_write_pin(RELAY_CH2_PIN,GPIO_PIN_RESET); } } @@ -154,7 +143,7 @@ void app_key_callback_handler(uint16_t key_value) //按键回调函数 case MODE_DOUBLE_CLICK: //双击 key_state=KEY_SHORT; - power=4; + power=3; led_state=2; break; @@ -181,7 +170,7 @@ void ble_mode_scan(void) case 1: receive_mode=0; key_state=KEY_SHORT; - power=4; + power=3; led_state=2; break; @@ -214,54 +203,31 @@ void _433_fun(void) { case 0x03: //如果是3键遥控或者是正方形白色遥控 if(match_ch & MATCH_CH2){ - xc_gpio_toggle_pin(GPIO_2); - flash_ch2_state=xc_gpio_read_pin(GPIO_2); + xc_gpio_toggle_pin(RELAY_CH2_PIN); + flash_ch2_state=xc_gpio_read_pin(RELAY_CH2_PIN); 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); - } - - break; case 0x04: //如果是黑色长方形遥控或者椭圆遥控关闭按键 if(match_ch & MATCH_CH2) { - xc_gpio_write_pin(GPIO_2,GPIO_PIN_RESET); - flash_ch2_state=xc_gpio_read_pin(GPIO_2); + xc_gpio_write_pin(RELAY_CH2_PIN,GPIO_PIN_RESET); + flash_ch2_state=xc_gpio_read_pin(RELAY_CH2_PIN); 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); - } - - break; case 0x02: //如果是黑色长方形遥控或者椭圆遥控打开按键 if(match_ch & MATCH_CH2) { - xc_gpio_write_pin(GPIO_2,GPIO_PIN_SET); - flash_ch2_state=xc_gpio_read_pin(GPIO_2); + xc_gpio_write_pin(RELAY_CH2_PIN,GPIO_PIN_SET); + flash_ch2_state=xc_gpio_read_pin(RELAY_CH2_PIN); 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); - } - - break; @@ -286,9 +252,6 @@ void scan_433(void) if(rf433_sw_flag==1) { rf433_sw_flag=0; - power=4; - key_state=KEY_SHORT; - led_state=2; } else if(rf433_sw_flag==2) { @@ -436,6 +399,3 @@ void scan_433(void) } } - - - diff --git a/project/example/ble/ble_peripheral/app/src/rf433.h b/project/example/ble/ble_peripheral/app/src/rf433.h index 2190c9a..429491c 100644 --- a/project/example/ble/ble_peripheral/app/src/rf433.h +++ b/project/example/ble/ble_peripheral/app/src/rf433.h @@ -11,7 +11,7 @@ #define RF_DATA xc_gpio_read_pin(GPIO_0) //RF433接收引脚,根据具体单片机定义引脚 #define RELAY_CH1_PIN (GPIO_5) -#define RELAY_CH2_PIN (GPIO_2) +#define RELAY_CH2_PIN (GPIO_5) /* HPW421: protocol channel 2 relay */ #define KEY_LONG 1 #define KEY_SHORT 2 @@ -90,4 +90,3 @@ void scan_433(void); #endif - diff --git a/project/example/ble/ble_peripheral/app/src/switch_s.c b/project/example/ble/ble_peripheral/app/src/switch_s.c index acd75bc..4dad851 100644 --- a/project/example/ble/ble_peripheral/app/src/switch_s.c +++ b/project/example/ble/ble_peripheral/app/src/switch_s.c @@ -83,7 +83,6 @@ void switch_init(void) void trigger_check_process(void) { - if(S1_first_on_state==1) { S1_first_on_state=0; @@ -303,7 +302,7 @@ void trigger_check_process(void) //printf("对码 trig1_cnt %d\r\n",trig1_cnt); if( s1_state == DB_IDLE) { - rf433_sw_flag = 1; + rf433_sw_flag = 1; trig1_cnt = 0; trig1_wait = 0; } @@ -428,4 +427,3 @@ void gpio_intr_callback(uint64_t intr_sta) } } } - diff --git a/project/example/ble/ble_peripheral/app/src/switch_s.h b/project/example/ble/ble_peripheral/app/src/switch_s.h index cfff444..bb4c011 100644 --- a/project/example/ble/ble_peripheral/app/src/switch_s.h +++ b/project/example/ble/ble_peripheral/app/src/switch_s.h @@ -45,4 +45,3 @@ void trigger_check_process(void); #endif - diff --git a/project/example/ble/ble_peripheral/app/src/uart_1.c b/project/example/ble/ble_peripheral/app/src/uart_1.c index dabdf31..0836cad 100644 --- a/project/example/ble/ble_peripheral/app/src/uart_1.c +++ b/project/example/ble/ble_peripheral/app/src/uart_1.c @@ -28,18 +28,12 @@ void scan_uart(uint8_t *arr) //LOGI("%02x %02x %02x %02x %02x %02x\r\n",user_rx_buf[0],user_rx_buf[1],user_rx_buf[2],user_rx_buf[3],user_rx_buf[4],user_rx_buf[5]); switch(user_rx_buf[4]) { - case 0x01: - switch(user_rx_buf[1]) - { - case 0x01: - xc_gpio_toggle_pin(GPIO_5); - flash_ch1_state=xc_gpio_read_pin(GPIO_5); - flash_run(); - break; - - case 0x02: - xc_gpio_toggle_pin(GPIO_2); - flash_ch2_state=xc_gpio_read_pin(GPIO_2); + case 0x01: + switch(user_rx_buf[1]) + { + case 0x02: + xc_gpio_toggle_pin(RELAY_CH2_PIN); + flash_ch2_state=xc_gpio_read_pin(RELAY_CH2_PIN); flash_run(); break; @@ -53,11 +47,7 @@ void scan_uart(uint8_t *arr) case 0x02: switch(user_rx_buf[1]) { - case 0x04: - receive_mode=1; - break; - - case 0x05: + case 0x05: receive_mode=2; break; diff --git a/project/example/ble/ble_peripheral/app/src/usr_server.c b/project/example/ble/ble_peripheral/app/src/usr_server.c index 8105ad6..ba7cacf 100644 --- a/project/example/ble/ble_peripheral/app/src/usr_server.c +++ b/project/example/ble/ble_peripheral/app/src/usr_server.c @@ -13,10 +13,10 @@ */ #include "usr_server.h" #include "uart_1.h" +#include "rf433.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; @@ -83,9 +83,6 @@ 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; @@ -108,7 +105,7 @@ static uint8_t ble_state_fill_packet(uint8_t *data) data[7] = FIRMWARE_VERSION_MAJOR; data[8] = FIRMWARE_VERSION_MINOR; data[9] = FIRMWARE_VERSION_PATCH; - data[10] = adress_ch1_index; + data[10] = 0; data[11] = adress_ch2_index; data[12] = 0; data[13] = 0; @@ -118,12 +115,11 @@ static uint8_t ble_state_fill_packet(uint8_t *data) 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_ch1_count = 0; ble_state_last_ch2_count = ch2_count; ble_state_last_valid = 1; return; @@ -134,9 +130,8 @@ static void ble_state_detect_changes(void) 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; + if (ble_state_last_ch2_count != ch2_count) { + ble_state_last_ch1_count = 0; ble_state_last_ch2_count = ch2_count; ble_state_mark_dirty(BLE_STATE_DIRTY_RF433); } diff --git a/project/example/ble/ble_peripheral/app/src/usr_server.h b/project/example/ble/ble_peripheral/app/src/usr_server.h index 353e955..cca86f5 100644 --- a/project/example/ble/ble_peripheral/app/src/usr_server.h +++ b/project/example/ble/ble_peripheral/app/src/usr_server.h @@ -21,7 +21,7 @@ #include "xc_gatt_server_api.h" #define CUSTOM_SVC_UUID 0xFFF0 -#define CUSTOM_SVC_RX_CHAR_UUID 0xFFE2 +#define CUSTOM_SVC_RX_CHAR_UUID 0xFFE1 #define CUSTOM_SVC_TX_CHAR_UUID 0xFFF4 #define CUSTOM_SVC_RX_CHAR_VAL_MAX_LENGTH 120 #define CUSTOM_SVC_TX_CHAR_VAL_MAX_LENGTH 120 diff --git a/project_info.ini b/project_info.ini index 8461e30..8ae6a5a 100644 --- a/project_info.ini +++ b/project_info.ini @@ -1,4 +1,4 @@ -PRODUCT=HPW422 +PRODUCT=HPW421 VERSION=V1.3 CHIP=XC6517 diff --git a/release/online/HPW421_V1.3_XC6517_5685AE80.bin b/release/online/HPW421_V1.3_XC6517_5685AE80.bin new file mode 100644 index 0000000..3734e5f Binary files /dev/null and b/release/online/HPW421_V1.3_XC6517_5685AE80.bin differ diff --git a/release/ota/HPW421_V1.3_XC6517_5685AE80_OTA.bin b/release/ota/HPW421_V1.3_XC6517_5685AE80_OTA.bin new file mode 100644 index 0000000..d2615f2 Binary files /dev/null and b/release/ota/HPW421_V1.3_XC6517_5685AE80_OTA.bin differ diff --git a/tools/offline_burn/40-ab-00-cd-01-01_5685AE80_1000000.bin b/tools/offline_burn/40-ab-00-cd-01-01_5685AE80_1000000.bin new file mode 100644 index 0000000..f9ad990 Binary files /dev/null and b/tools/offline_burn/40-ab-00-cd-01-01_5685AE80_1000000.bin differ