发布 HPW421 V1.3 GPIO5 单继电器固件
This commit is contained in:
@@ -49,7 +49,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Default Device Name
|
/// 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_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 "OTA_TEST"
|
||||||
#define APP_SINGLEOTA_DEVICE_NAME_LEN (sizeof(APP_SINGLEOTA_DEVICE_NAME))
|
#define APP_SINGLEOTA_DEVICE_NAME_LEN (sizeof(APP_SINGLEOTA_DEVICE_NAME))
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "fmc_spi_1.h"
|
#include "fmc_spi_1.h"
|
||||||
#include "xc_drv_fmc_spi.h"
|
#include "xc_drv_fmc_spi.h"
|
||||||
#include "rf433.h"
|
#include "rf433.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
uint8_t r_data[256];
|
uint8_t r_data[256];
|
||||||
|
|
||||||
@@ -54,8 +55,11 @@ void read_user_data(void)
|
|||||||
adress_ch1_index = r_data[22];
|
adress_ch1_index = r_data[22];
|
||||||
adress_ch2_index = r_data[23];
|
adress_ch2_index = r_data[23];
|
||||||
|
|
||||||
flash_ch1_state=r_data[24];
|
flash_ch1_state=0;
|
||||||
flash_ch2_state=r_data[25];
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ uint8_t adress_ch2_index = 0; // 通道2地址索引(0-4)
|
|||||||
uint8_t match_ch = 0; // 匹配到的通道(1=GPIO5,2=GPIO2)
|
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匹配标记
|
#define MATCH_CH2 (1 << 1) // 通道2匹配标记
|
||||||
|
|
||||||
|
|
||||||
@@ -94,29 +94,18 @@ void chx_gpio_init(void)
|
|||||||
|
|
||||||
GPIO_InitCfg.Dir = GPIO_DIR_OUTPUT; // 输出方向
|
GPIO_InitCfg.Dir = GPIO_DIR_OUTPUT; // 输出方向
|
||||||
GPIO_InitCfg.Int = NOT_INT; // 不使能中断
|
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.Dir = GPIO_DIR_OUTPUT; // 输出方向
|
||||||
GPIO_InitCfg.Int = NOT_INT; // 不使能中断
|
GPIO_InitCfg.Int = NOT_INT; // 不使能中断
|
||||||
GPIO_InitCfg.Pin = RELAY_CH2_PIN; // 设置通道2引脚
|
GPIO_InitCfg.Pin = RELAY_CH2_PIN; // 设置通道2引脚
|
||||||
xc_gpio_init(&GPIO_InitCfg); // 初始化GPIO
|
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)
|
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
|
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: //双击
|
case MODE_DOUBLE_CLICK: //双击
|
||||||
|
|
||||||
key_state=KEY_SHORT;
|
key_state=KEY_SHORT;
|
||||||
power=4;
|
power=3;
|
||||||
led_state=2;
|
led_state=2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -181,7 +170,7 @@ void ble_mode_scan(void)
|
|||||||
case 1:
|
case 1:
|
||||||
receive_mode=0;
|
receive_mode=0;
|
||||||
key_state=KEY_SHORT;
|
key_state=KEY_SHORT;
|
||||||
power=4;
|
power=3;
|
||||||
led_state=2;
|
led_state=2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -214,54 +203,31 @@ void _433_fun(void)
|
|||||||
{
|
{
|
||||||
case 0x03: //如果是3键遥控或者是正方形白色遥控
|
case 0x03: //如果是3键遥控或者是正方形白色遥控
|
||||||
if(match_ch & MATCH_CH2){
|
if(match_ch & MATCH_CH2){
|
||||||
xc_gpio_toggle_pin(GPIO_2);
|
xc_gpio_toggle_pin(RELAY_CH2_PIN);
|
||||||
flash_ch2_state=xc_gpio_read_pin(GPIO_2);
|
flash_ch2_state=xc_gpio_read_pin(RELAY_CH2_PIN);
|
||||||
ble_state_mark_dirty(BLE_STATE_DIRTY_OUTPUT | BLE_STATE_DIRTY_RF433);
|
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;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case 0x04: //如果是黑色长方形遥控或者椭圆遥控关闭按键
|
case 0x04: //如果是黑色长方形遥控或者椭圆遥控关闭按键
|
||||||
if(match_ch & MATCH_CH2)
|
if(match_ch & MATCH_CH2)
|
||||||
{
|
{
|
||||||
xc_gpio_write_pin(GPIO_2,GPIO_PIN_RESET);
|
xc_gpio_write_pin(RELAY_CH2_PIN,GPIO_PIN_RESET);
|
||||||
flash_ch2_state=xc_gpio_read_pin(GPIO_2);
|
flash_ch2_state=xc_gpio_read_pin(RELAY_CH2_PIN);
|
||||||
ble_state_mark_dirty(BLE_STATE_DIRTY_OUTPUT | BLE_STATE_DIRTY_RF433);
|
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;
|
break;
|
||||||
|
|
||||||
case 0x02: //如果是黑色长方形遥控或者椭圆遥控打开按键
|
case 0x02: //如果是黑色长方形遥控或者椭圆遥控打开按键
|
||||||
if(match_ch & MATCH_CH2)
|
if(match_ch & MATCH_CH2)
|
||||||
{
|
{
|
||||||
xc_gpio_write_pin(GPIO_2,GPIO_PIN_SET);
|
xc_gpio_write_pin(RELAY_CH2_PIN,GPIO_PIN_SET);
|
||||||
flash_ch2_state=xc_gpio_read_pin(GPIO_2);
|
flash_ch2_state=xc_gpio_read_pin(RELAY_CH2_PIN);
|
||||||
ble_state_mark_dirty(BLE_STATE_DIRTY_OUTPUT | BLE_STATE_DIRTY_RF433);
|
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;
|
break;
|
||||||
|
|
||||||
|
|
||||||
@@ -286,9 +252,6 @@ void scan_433(void)
|
|||||||
if(rf433_sw_flag==1)
|
if(rf433_sw_flag==1)
|
||||||
{
|
{
|
||||||
rf433_sw_flag=0;
|
rf433_sw_flag=0;
|
||||||
power=4;
|
|
||||||
key_state=KEY_SHORT;
|
|
||||||
led_state=2;
|
|
||||||
}
|
}
|
||||||
else if(rf433_sw_flag==2)
|
else if(rf433_sw_flag==2)
|
||||||
{
|
{
|
||||||
@@ -436,6 +399,3 @@ void scan_433(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#define RF_DATA xc_gpio_read_pin(GPIO_0) //RF433接收引脚,根据具体单片机定义引脚
|
#define RF_DATA xc_gpio_read_pin(GPIO_0) //RF433接收引脚,根据具体单片机定义引脚
|
||||||
|
|
||||||
#define RELAY_CH1_PIN (GPIO_5)
|
#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_LONG 1
|
||||||
#define KEY_SHORT 2
|
#define KEY_SHORT 2
|
||||||
@@ -90,4 +90,3 @@ void scan_433(void);
|
|||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,6 @@ void switch_init(void)
|
|||||||
|
|
||||||
void trigger_check_process(void)
|
void trigger_check_process(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(S1_first_on_state==1)
|
if(S1_first_on_state==1)
|
||||||
{
|
{
|
||||||
S1_first_on_state=0;
|
S1_first_on_state=0;
|
||||||
@@ -303,7 +302,7 @@ void trigger_check_process(void)
|
|||||||
//printf("对码 trig1_cnt %d\r\n",trig1_cnt);
|
//printf("对码 trig1_cnt %d\r\n",trig1_cnt);
|
||||||
if( s1_state == DB_IDLE)
|
if( s1_state == DB_IDLE)
|
||||||
{
|
{
|
||||||
rf433_sw_flag = 1;
|
rf433_sw_flag = 1;
|
||||||
trig1_cnt = 0;
|
trig1_cnt = 0;
|
||||||
trig1_wait = 0;
|
trig1_wait = 0;
|
||||||
}
|
}
|
||||||
@@ -428,4 +427,3 @@ void gpio_intr_callback(uint64_t intr_sta)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,4 +45,3 @@ void trigger_check_process(void);
|
|||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -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]);
|
//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])
|
switch(user_rx_buf[4])
|
||||||
{
|
{
|
||||||
case 0x01:
|
case 0x01:
|
||||||
switch(user_rx_buf[1])
|
switch(user_rx_buf[1])
|
||||||
{
|
{
|
||||||
case 0x01:
|
case 0x02:
|
||||||
xc_gpio_toggle_pin(GPIO_5);
|
xc_gpio_toggle_pin(RELAY_CH2_PIN);
|
||||||
flash_ch1_state=xc_gpio_read_pin(GPIO_5);
|
flash_ch2_state=xc_gpio_read_pin(RELAY_CH2_PIN);
|
||||||
flash_run();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 0x02:
|
|
||||||
xc_gpio_toggle_pin(GPIO_2);
|
|
||||||
flash_ch2_state=xc_gpio_read_pin(GPIO_2);
|
|
||||||
flash_run();
|
flash_run();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -53,11 +47,7 @@ void scan_uart(uint8_t *arr)
|
|||||||
case 0x02:
|
case 0x02:
|
||||||
switch(user_rx_buf[1])
|
switch(user_rx_buf[1])
|
||||||
{
|
{
|
||||||
case 0x04:
|
case 0x05:
|
||||||
receive_mode=1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 0x05:
|
|
||||||
receive_mode=2;
|
receive_mode=2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,10 @@
|
|||||||
*/
|
*/
|
||||||
#include "usr_server.h"
|
#include "usr_server.h"
|
||||||
#include "uart_1.h"
|
#include "uart_1.h"
|
||||||
|
#include "rf433.h"
|
||||||
#include "xc_drv_gpio.h"
|
#include "xc_drv_gpio.h"
|
||||||
#if (BLE_APP_PRESENT)
|
#if (BLE_APP_PRESENT)
|
||||||
|
|
||||||
extern uint8_t adress_ch1_index;
|
|
||||||
extern uint8_t adress_ch2_index;
|
extern uint8_t adress_ch2_index;
|
||||||
|
|
||||||
uint8_t srv_user_lid = GATT_INVALID_USER_LID;
|
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;
|
uint8_t mask = 0;
|
||||||
|
|
||||||
if (xc_gpio_read_pin(GPIO_5)) {
|
if (xc_gpio_read_pin(GPIO_5)) {
|
||||||
mask |= 0x01;
|
|
||||||
}
|
|
||||||
if (xc_gpio_read_pin(GPIO_2)) {
|
|
||||||
mask |= 0x02;
|
mask |= 0x02;
|
||||||
}
|
}
|
||||||
return mask;
|
return mask;
|
||||||
@@ -108,7 +105,7 @@ static uint8_t ble_state_fill_packet(uint8_t *data)
|
|||||||
data[7] = FIRMWARE_VERSION_MAJOR;
|
data[7] = FIRMWARE_VERSION_MAJOR;
|
||||||
data[8] = FIRMWARE_VERSION_MINOR;
|
data[8] = FIRMWARE_VERSION_MINOR;
|
||||||
data[9] = FIRMWARE_VERSION_PATCH;
|
data[9] = FIRMWARE_VERSION_PATCH;
|
||||||
data[10] = adress_ch1_index;
|
data[10] = 0;
|
||||||
data[11] = adress_ch2_index;
|
data[11] = adress_ch2_index;
|
||||||
data[12] = 0;
|
data[12] = 0;
|
||||||
data[13] = 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)
|
static void ble_state_detect_changes(void)
|
||||||
{
|
{
|
||||||
uint8_t output = ble_state_output_mask();
|
uint8_t output = ble_state_output_mask();
|
||||||
uint8_t ch1_count = adress_ch1_index;
|
|
||||||
uint8_t ch2_count = adress_ch2_index;
|
uint8_t ch2_count = adress_ch2_index;
|
||||||
|
|
||||||
if (!ble_state_last_valid) {
|
if (!ble_state_last_valid) {
|
||||||
ble_state_last_output = output;
|
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_ch2_count = ch2_count;
|
||||||
ble_state_last_valid = 1;
|
ble_state_last_valid = 1;
|
||||||
return;
|
return;
|
||||||
@@ -134,9 +130,8 @@ static void ble_state_detect_changes(void)
|
|||||||
ble_state_mark_dirty(BLE_STATE_DIRTY_OUTPUT);
|
ble_state_mark_dirty(BLE_STATE_DIRTY_OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ble_state_last_ch1_count != ch1_count) ||
|
if (ble_state_last_ch2_count != ch2_count) {
|
||||||
(ble_state_last_ch2_count != ch2_count)) {
|
ble_state_last_ch1_count = 0;
|
||||||
ble_state_last_ch1_count = ch1_count;
|
|
||||||
ble_state_last_ch2_count = ch2_count;
|
ble_state_last_ch2_count = ch2_count;
|
||||||
ble_state_mark_dirty(BLE_STATE_DIRTY_RF433);
|
ble_state_mark_dirty(BLE_STATE_DIRTY_RF433);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
#include "xc_gatt_server_api.h"
|
#include "xc_gatt_server_api.h"
|
||||||
|
|
||||||
#define CUSTOM_SVC_UUID 0xFFF0
|
#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_TX_CHAR_UUID 0xFFF4
|
||||||
#define CUSTOM_SVC_RX_CHAR_VAL_MAX_LENGTH 120
|
#define CUSTOM_SVC_RX_CHAR_VAL_MAX_LENGTH 120
|
||||||
#define CUSTOM_SVC_TX_CHAR_VAL_MAX_LENGTH 120
|
#define CUSTOM_SVC_TX_CHAR_VAL_MAX_LENGTH 120
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
PRODUCT=HPW422
|
PRODUCT=HPW421
|
||||||
VERSION=V1.3
|
VERSION=V1.3
|
||||||
CHIP=XC6517
|
CHIP=XC6517
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user