278 lines
8.0 KiB
C
Executable File
278 lines
8.0 KiB
C
Executable File
/* assis_thread.c
|
|
*
|
|
* Copyright (C) 2024 ShangHai High-flying Electronics Technology Co.,Ltd.
|
|
*
|
|
* This file is part of HSF.
|
|
*
|
|
*/
|
|
|
|
#include "hsf.h"
|
|
#include "spotlight.h"
|
|
#ifdef HF_MCU_OTA
|
|
#include "mcu_update.h"
|
|
#endif
|
|
|
|
int g_module_id = HFM_TYPE_LPT262;
|
|
const int hf_lpt_262_gpio_fid_to_pid_map_table[HFM_MAX_FUNC_CODE]=
|
|
{
|
|
HFM_NOPIN, //HFGPIO_F_JTAG_TCK
|
|
HFM_NOPIN, //HFGPIO_F_JTAG_TDO
|
|
HFM_NOPIN, //HFGPIO_F_JTAG_TDI
|
|
HFM_NOPIN, //HFGPIO_F_JTAG_TMS
|
|
HFM_NOPIN, //HFGPIO_F_USBDP
|
|
HFM_NOPIN, //HFGPIO_F_USBDM
|
|
LPT26x_GPIO17, //HFGPIO_F_UART0_TX
|
|
HFM_NOPIN, //HFGPIO_F_UART0_RTS
|
|
LPT26x_GPIO18, //HFGPIO_F_UART0_RX
|
|
HFM_NOPIN, //HFGPIO_F_UART0_CTS
|
|
HFM_NOPIN, //HFGPIO_F_SPI_MISO
|
|
HFM_NOPIN, //HFGPIO_F_SPI_CLK
|
|
HFM_NOPIN, //HFGPIO_F_SPI_CS
|
|
HFM_NOPIN, //HFGPIO_F_SPI_MOSI
|
|
LPT26x_GPIO15, //HFGPIO_F_UART1_TX,
|
|
HFM_NOPIN, //HFGPIO_F_UART1_RTS,
|
|
LPT26x_GPIO16, //HFGPIO_F_UART1_RX,
|
|
HFM_NOPIN, //HFGPIO_F_UART1_CTS,
|
|
|
|
LPT26x_GPIO2, //HFGPIO_F_NLINK
|
|
LPT26x_GPIO10, //HFGPIO_F_NREADY
|
|
LPT26x_GPIO5, //HFGPIO_F_NRELOAD
|
|
|
|
HFM_NOPIN, //HFGPIO_F_SLEEP_RQ
|
|
HFM_NOPIN, //HFGPIO_F_SLEEP_ON
|
|
|
|
HFM_NOPIN, //HFGPIO_F_WPS
|
|
HFM_NOPIN, //HFGPIO_F_RESERVE1
|
|
|
|
HFM_NOPIN, //HFGPIO_F_RESERVE2
|
|
HFM_NOPIN, //HFGPIO_F_RESERVE3
|
|
HFM_NOPIN, //HFGPIO_F_RESERVE4
|
|
HFM_NOPIN, //HFGPIO_F_RESERVE5
|
|
|
|
HFM_NOPIN, //HFGPIO_F_USER_DEFINE
|
|
};
|
|
|
|
const int hf_lpt_263_gpio_fid_to_pid_map_table[HFM_MAX_FUNC_CODE]=
|
|
{
|
|
HFM_NOPIN, //HFGPIO_F_JTAG_TCK
|
|
HFM_NOPIN, //HFGPIO_F_JTAG_TDO
|
|
HFM_NOPIN, //HFGPIO_F_JTAG_TDI
|
|
HFM_NOPIN, //HFGPIO_F_JTAG_TMS
|
|
HFM_NOPIN, //HFGPIO_F_USBDP
|
|
HFM_NOPIN, //HFGPIO_F_USBDM
|
|
LPT26x_GPIO17, //HFGPIO_F_UART0_TX
|
|
HFM_NOPIN, //HFGPIO_F_UART0_RTS
|
|
LPT26x_GPIO18, //HFGPIO_F_UART0_RX
|
|
HFM_NOPIN, //HFGPIO_F_UART0_CTS
|
|
HFM_NOPIN, //HFGPIO_F_SPI_MISO
|
|
HFM_NOPIN, //HFGPIO_F_SPI_CLK
|
|
HFM_NOPIN, //HFGPIO_F_SPI_CS
|
|
HFM_NOPIN, //HFGPIO_F_SPI_MOSI
|
|
LPT26x_GPIO15, //HFGPIO_F_UART1_TX,
|
|
HFM_NOPIN, //HFGPIO_F_UART1_RTS,
|
|
LPT26x_GPIO16, //HFGPIO_F_UART1_RX,
|
|
HFM_NOPIN, //HFGPIO_F_UART1_CTS,
|
|
|
|
LPT26x_GPIO7, //HFGPIO_F_NLINK
|
|
LPT26x_GPIO8, //HFGPIO_F_NREADY
|
|
LPT26x_GPIO9, //HFGPIO_F_NRELOAD
|
|
|
|
HFM_NOPIN, //HFGPIO_F_SLEEP_RQ
|
|
HFM_NOPIN, //HFGPIO_F_SLEEP_ON
|
|
|
|
HFM_NOPIN, //HFGPIO_F_WPS
|
|
HFM_NOPIN, //HFGPIO_F_RESERVE1
|
|
|
|
HFM_NOPIN, //HFGPIO_F_RESERVE2
|
|
HFM_NOPIN, //HFGPIO_F_RESERVE3
|
|
HFM_NOPIN, //HFGPIO_F_RESERVE4
|
|
HFM_NOPIN, //HFGPIO_F_RESERVE5
|
|
|
|
HFM_NOPIN, //HFGPIO_F_USER_DEFINE
|
|
};
|
|
|
|
const int hf_lpt_162_gpio_fid_to_pid_map_table[HFM_MAX_FUNC_CODE]=
|
|
{
|
|
HFM_NOPIN, //HFGPIO_F_JTAG_TCK
|
|
HFM_NOPIN, //HFGPIO_F_JTAG_TDO
|
|
HFM_NOPIN, //HFGPIO_F_JTAG_TDI
|
|
HFM_NOPIN, //HFGPIO_F_JTAG_TMS
|
|
HFM_NOPIN, //HFGPIO_F_USBDP
|
|
HFM_NOPIN, //HFGPIO_F_USBDM
|
|
LPT26x_GPIO17, //HFGPIO_F_UART0_TX
|
|
HFM_NOPIN, //HFGPIO_F_UART0_RTS
|
|
LPT26x_GPIO18, //HFGPIO_F_UART0_RX
|
|
HFM_NOPIN, //HFGPIO_F_UART0_CTS
|
|
HFM_NOPIN, //HFGPIO_F_SPI_MISO
|
|
HFM_NOPIN, //HFGPIO_F_SPI_CLK
|
|
HFM_NOPIN, //HFGPIO_F_SPI_CS
|
|
HFM_NOPIN, //HFGPIO_F_SPI_MOSI
|
|
LPT26x_GPIO15, //HFGPIO_F_UART1_TX,
|
|
HFM_NOPIN, //HFGPIO_F_UART1_RTS,
|
|
LPT26x_GPIO16, //HFGPIO_F_UART1_RX,
|
|
HFM_NOPIN, //HFGPIO_F_UART1_CTS,
|
|
|
|
LPT26x_GPIO7, //HFGPIO_F_NLINK
|
|
LPT26x_GPIO8, //HFGPIO_F_NREADY
|
|
LPT26x_GPIO9, //HFGPIO_F_NRELOAD
|
|
|
|
HFM_NOPIN, //HFGPIO_F_SLEEP_RQ
|
|
HFM_NOPIN, //HFGPIO_F_SLEEP_ON
|
|
|
|
HFM_NOPIN, //HFGPIO_F_WPS
|
|
HFM_NOPIN, //HFGPIO_F_RESERVE1
|
|
|
|
HFM_NOPIN, //HFGPIO_F_RESERVE2
|
|
HFM_NOPIN, //HFGPIO_F_RESERVE3
|
|
HFM_NOPIN, //HFGPIO_F_RESERVE4
|
|
HFM_NOPIN, //HFGPIO_F_RESERVE5
|
|
|
|
HFM_NOPIN, //HFGPIO_F_USER_DEFINE
|
|
};
|
|
#ifdef ENABLE_BLE_SCAN
|
|
void hf_ble_scan_callback(gap_scan_result_data_t *scan_result_data)
|
|
{
|
|
// todo
|
|
return ;
|
|
}
|
|
|
|
int hfble_start_scan(void)
|
|
{
|
|
int ret = 0;
|
|
gap_ble_scan_params_t ble_scan_param = {
|
|
.scan_interval = 0x40, //30*8/5*2*2,
|
|
.scan_window = 0x20, //30*8/5/2,
|
|
.scan_type = 0x00,
|
|
.scan_phy = GAP_BLE_PHY_1M,
|
|
.scan_filter_policy = 0x00,
|
|
};
|
|
gap_ble_extern_scan_params_t ble_extern_scan_param = {
|
|
.filter_duplicate = 0,
|
|
.duration = 0,
|
|
.period = 0,
|
|
};
|
|
|
|
ret = gap_ble_set_scan_parameters(&ble_scan_param);
|
|
if(ret != 0){
|
|
HILINK_SAL_DEBUG("gap_ble_set_scan_parameters failed, errcode = 0x%X\r\n", ret);
|
|
return -1;
|
|
}
|
|
ret = gap_ble_set_scan_extern_parameters(&ble_extern_scan_param);
|
|
if(ret != 0){
|
|
HILINK_SAL_DEBUG("gap_ble_set_scan_extern_parameters failed, errcode = 0x%X\r\n", ret);
|
|
return -1;
|
|
}
|
|
ret = gap_ble_start_scan();
|
|
if(ret != 0){
|
|
HILINK_SAL_DEBUG("gap_ble_start_scan failed, errcode = 0x%X\r\n", ret);
|
|
return -1;
|
|
}
|
|
HILINK_SAL_DEBUG("*****************ble start scan*****************\r\n");
|
|
return 0;
|
|
}
|
|
#endif
|
|
static int USER_FUNC uart_recv_callback(uint32_t event,char *data,uint32_t len,uint32_t buf_len)
|
|
{
|
|
if(data == NULL)
|
|
return 0;
|
|
if(event == HFNET_UART0_DATA_READY)
|
|
HF_Debug(DEBUG_LEVEL_LOW,"[%d]uart 0 recv %d bytes data %d\n",event,len,buf_len);
|
|
else if(event == HFNET_UART1_DATA_READY)
|
|
HF_Debug(DEBUG_LEVEL_LOW,"[%d]uart 1 recv %d bytes data %d\n",event,len,buf_len);
|
|
if(hfsys_get_run_mode() == HFSYS_STATE_RUN_CMD)
|
|
return len;
|
|
|
|
return len;
|
|
}
|
|
void user_app_init(void)
|
|
{
|
|
u_printf("user app init\r\n");
|
|
}
|
|
#define APPVER "1.0.0"
|
|
int hf_atcmd_appver(pat_session_t s,int argc,char *argv[],char *rsp,int len)
|
|
{
|
|
if(argc == 0)
|
|
{
|
|
sprintf(rsp,"=LPT262_Harmonyos_%s_%s",APPVER,"20250227");
|
|
return 0;
|
|
}
|
|
return -3;
|
|
}
|
|
int hf_atcmd_reset(pat_session_t s,int argc,char *argv[],char *rsp,int len)
|
|
{
|
|
extern int HILINK_RestoreFactorySettings(void);
|
|
HILINK_RestoreFactorySettings();
|
|
return 0;
|
|
}
|
|
#ifdef CONFIG_SPOTLIGHT_UT
|
|
extern int hf_atcmd_pwm(pat_session_t s, int argc, char *argv[], char *rsp, int len);
|
|
extern int hf_atcmd_pwm_query(pat_session_t s, int argc, char *argv[], char *rsp, int len);
|
|
extern int hf_atcmd_light(pat_session_t s, int argc, char *argv[], char *rsp, int len);
|
|
extern int hf_atcmd_light_query(pat_session_t s, int argc, char *argv[], char *rsp, int len);
|
|
#endif
|
|
const hfat_cmd_t user_define_at_cmds_table[]=
|
|
{
|
|
{"APPVER", hf_atcmd_appver, "AT+APPVER: get version. \r\n",NULL},
|
|
{"RESET", hf_atcmd_reset, "AT+RESET: reset. \r\n",NULL},
|
|
#ifdef HF_MCU_OTA
|
|
{"MCUOTA", hf_atcmd_mcu, "AT+MCUOTA: start mcu ota. \r\n",NULL},
|
|
{"MCUVER", hf_atcmd_mcuver, "AT+MCUVER: get mcu version. \r\n",NULL},
|
|
{"OTAWAITTIME", hf_atcmd_ota_wait_time, "AT+OTAWAITTIME: set/get uart send mcu ota time\r\n", NULL},
|
|
#endif
|
|
#ifdef CONFIG_SPOTLIGHT_UT
|
|
{"UTPWM", hf_atcmd_pwm, "AT+PWM=<channel>,<duty>: Set PWM duty cycle (0-1000)\r\n", NULL},
|
|
{"UTLIGHT", hf_atcmd_light, "AT+LIGHT=<brightness>,<cct>: Set brightness(0-1000) and CCT(2700-6000)\r\n", NULL},
|
|
{"UTPWMQ", NULL, "AT+PWMQ=<channel>,<duty>: Set PWM duty cycle (0-1000)\r\n", hf_atcmd_pwm_query},
|
|
{"UTLIGHTQ", NULL, "AT+LIGHTQ=<brightness>,<cct>: Set brightness(0-1000) and CCT(2700-6000)\r\n", hf_atcmd_light_query},
|
|
#endif
|
|
{NULL, NULL, NULL, NULL} //the last item must be null
|
|
};
|
|
|
|
int USER_FUNC user_app_main(void)
|
|
{
|
|
//AT+UART uart0
|
|
if(hfnet_start_uart(HFTHREAD_PRIORITIES_LOW,(hfnet_callback_t)uart_recv_callback)!=HF_SUCCESS)
|
|
{
|
|
HF_Debug(DEBUG_WARN,"start uart fail!\r\n");
|
|
}
|
|
#ifdef HF_MCU_OTA
|
|
if(hf_mcu_init() != HF_SUCCESS)
|
|
HF_Debug(DEBUG_WARN,"init mcu ota fail!\r\n");
|
|
#endif
|
|
//See Wi-Fi Config tools APP for detailed usage of this thread, only debug mode open
|
|
if(0 && hfdbg_get_level())
|
|
{
|
|
while(!hfnet_wifi_is_active())
|
|
{
|
|
msleep(50);
|
|
}
|
|
if(hfnet_start_assis(ASSIS_PORT)!=HF_SUCCESS)
|
|
{
|
|
HF_Debug(DEBUG_WARN,"start assis fail\r\n");
|
|
}
|
|
}
|
|
e_printf("start assis success!\r\n");
|
|
// hfgpio_pwm_enable(HFGPIO_F_SPI_CLK, 1000, 50);
|
|
return 1;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|