325 lines
8.9 KiB
C
325 lines
8.9 KiB
C
![]() |
/*
|
||
|
* File : main.c
|
||
|
* This file is part of RT-Thread RTOS
|
||
|
* COPYRIGHT (C) 2017, RT-Thread Development Team
|
||
|
*
|
||
|
* This program is free software; you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation; either version 2 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License along
|
||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||
|
*
|
||
|
* Change Logs:
|
||
|
* Date Author Notes
|
||
|
* 2017-5-30 Bernard the first version
|
||
|
*/
|
||
|
|
||
|
#include <rtthread.h>
|
||
|
#include <finsh.h>
|
||
|
#include "common.h"
|
||
|
#include "param_config.h"
|
||
|
#include "ble_pub.h"
|
||
|
#include "gpio_pub.h"
|
||
|
#include "drv_oled.h"
|
||
|
|
||
|
#include "app_ble.h"
|
||
|
#include "app_sdp.h"
|
||
|
#include "app_ble_init.h"
|
||
|
#include "rtos_pub.h"
|
||
|
#if (BLE_APP_SEC)
|
||
|
#include "app_sec.h"
|
||
|
#endif
|
||
|
#include "kernel_mem.h"
|
||
|
|
||
|
#include "rtthread.h"
|
||
|
#include "drv_iic.h"
|
||
|
#if defined(RT_USING_DFS_ROMFS)
|
||
|
#include <dfs_fs.h>
|
||
|
#endif
|
||
|
#if defined(PKG_USING_PLAYER)
|
||
|
#include "player.h"
|
||
|
#endif
|
||
|
|
||
|
#include "include.h"
|
||
|
#include "driver_pub.h"
|
||
|
#include "func_pub.h"
|
||
|
#include "app.h"
|
||
|
#include "ate_app.h"
|
||
|
#include "shell.h"
|
||
|
#include <fal.h>
|
||
|
|
||
|
#ifdef PKG_USING_RT_OTA
|
||
|
#include "rt_ota.h"
|
||
|
#endif
|
||
|
|
||
|
#include "sys_ctrl_pub.h"
|
||
|
static int wlan_app_init(void);
|
||
|
static beken_timer_t timer_detect;
|
||
|
|
||
|
extern const struct romfs_dirent romfs_root;
|
||
|
#define DFS_ROMFS_ROOT (&romfs_root)
|
||
|
extern rt_err_t rt_audio_codec_hw_init(void);
|
||
|
extern int player_system_init(void);
|
||
|
extern void user_main( beken_thread_arg_t args );
|
||
|
|
||
|
extern int rt_hw_flash_disk_readonly_init(const char *name, uint32_t base, uint32_t sector_size, uint32_t capacity);
|
||
|
extern void rt_hw_wdg_start(int argc, char **argv);
|
||
|
extern int bk_wlan_dtim_rf_ps_mode_enable(void );
|
||
|
|
||
|
#define BUILD_UINT16(loByte, hiByte) \
|
||
|
((uint16_t)(((loByte) & 0x00FF) + (((hiByte) & 0x00FF) << 8)))
|
||
|
|
||
|
#define BK_ATT_DECL_PRIMARY_SERVICE_128 {0x00,0x28,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
|
||
|
#define BK_ATT_DECL_CHARACTERISTIC_128 {0x03,0x28,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
|
||
|
#define BK_ATT_DESC_CLIENT_CHAR_CFG_128 {0x02,0x29,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
|
||
|
|
||
|
#define WRITE_REQ_CHARACTERISTIC_128 {0x01,0xFF,0,0,0x34,0x56,0,0,0,0,0x28,0x37,0,0,0,0}
|
||
|
#define INDICATE_CHARACTERISTIC_128 {0x02,0xFF,0,0,0x34,0x56,0,0,0,0,0x28,0x37,0,0,0,0}
|
||
|
#define NOTIFY_CHARACTERISTIC_128 {0x03,0xFF,0,0,0x34,0x56,0,0,0,0,0x28,0x37,0,0,0,0}
|
||
|
|
||
|
static const uint8_t test_svc_uuid[16] = {0xFF,0xFF,0,0,0x34,0x56,0,0,0,0,0x28,0x37,0,0,0,0};
|
||
|
|
||
|
enum
|
||
|
{
|
||
|
TEST_IDX_SVC,
|
||
|
TEST_IDX_FF01_VAL_CHAR,
|
||
|
TEST_IDX_FF01_VAL_VALUE,
|
||
|
TEST_IDX_FF02_VAL_CHAR,
|
||
|
TEST_IDX_FF02_VAL_VALUE,
|
||
|
TEST_IDX_FF02_VAL_IND_CFG,
|
||
|
TEST_IDX_FF03_VAL_CHAR,
|
||
|
TEST_IDX_FF03_VAL_VALUE,
|
||
|
TEST_IDX_FF03_VAL_NTF_CFG,
|
||
|
TEST_IDX_NB,
|
||
|
};
|
||
|
|
||
|
extern bk_attm_desc_t test_att_db[TEST_IDX_NB];
|
||
|
extern void ble_set_notice_cb(ble_notice_cb_t func);
|
||
|
extern ble_err_t bk_ble_init(void);
|
||
|
extern void cli_ble_write_callback(write_req_t *write_req);
|
||
|
extern uint8_t cli_ble_read_callback(read_req_t *read_req);
|
||
|
extern void ble_notice_cb(ble_notice_t notice, void *param);
|
||
|
extern void ble_cmd_cb(ble_cmd_t cmd, ble_cmd_param_t *param);
|
||
|
extern uint8_t ble_active;
|
||
|
uint8_t actv_idx;
|
||
|
int Temp,Temp2,lastTemp;
|
||
|
int temp0,temp1,temp2;
|
||
|
uint8_t tempstr[5];
|
||
|
uint8_t tempstr1[5];
|
||
|
uint8_t tempstr11[5];
|
||
|
uint8_t tempstr2[5];
|
||
|
uint8_t batstr1[5];
|
||
|
uint8_t batstr2[5]="%";
|
||
|
uint8_t batstr3[5]=" ";
|
||
|
char *endPtr;
|
||
|
//uint8_t lo[]="LOW";
|
||
|
//uint8_t hi[]="HIGH";
|
||
|
|
||
|
|
||
|
void timer_temp_run_callback(void *arg){
|
||
|
rt_kprintf("Temp:%d,Temp2:%d\r\n",Temp,Temp2);
|
||
|
//Temp=strtol((char*)tempstr,&endPtr, 10);//IE01_body
|
||
|
//temp=strtol((char*)tempstr2,&endPtr, 10);//IB01/IE01_environment
|
||
|
temp0=Temp;
|
||
|
temp1=temp0/100;
|
||
|
sprintf((char*)tempstr1,"%d",temp1);
|
||
|
temp2=temp0/10%10;
|
||
|
sprintf((char*)tempstr11,"%d",temp2);
|
||
|
//co_printf("temp:%d\r\n",temp);
|
||
|
|
||
|
if(Temp>3199 && Temp<4291){
|
||
|
if(lastTemp<=3199||lastTemp>=4291){
|
||
|
OLED_Clear();
|
||
|
}
|
||
|
|
||
|
OLED_ShowString(0,0+10,tempstr1,32,1);
|
||
|
OLED_ShowChar(32,0+10,'.',32,1);
|
||
|
OLED_ShowString(40,0+10,tempstr11,32,1);
|
||
|
OLED_DrawCircle(58,5+6,4);
|
||
|
OLED_ShowChar(56,8+10,'C',24,1);
|
||
|
|
||
|
}if(Temp<=3199){
|
||
|
//oled_show_data_high( 0,0,REVERSE_OFF);
|
||
|
if(lastTemp>3199){
|
||
|
OLED_Clear();
|
||
|
}
|
||
|
OLED_ShowString(0,0+10,(u8 *)"LOW",32,1);
|
||
|
|
||
|
}if(Temp>=4291){
|
||
|
//oled_show_data( 0,0, hi,FONT_16X40_CHAR,REVERSE_OFF);
|
||
|
if(lastTemp<4291){
|
||
|
OLED_Clear();
|
||
|
}
|
||
|
OLED_ShowString(0,0+10,(u8 *)"HIGH",32,1);
|
||
|
}
|
||
|
lastTemp=Temp;
|
||
|
OLED_Refresh();
|
||
|
}
|
||
|
|
||
|
void Ble_Active() {
|
||
|
ble_set_notice_cb(ble_notice_cb);
|
||
|
ble_entry();
|
||
|
bk_ble_init();
|
||
|
}
|
||
|
|
||
|
void Init_Scan() {
|
||
|
struct scan_param scan_info;
|
||
|
scan_info.channel_map = 7;
|
||
|
scan_info.interval = 100;
|
||
|
scan_info.window = 30;
|
||
|
actv_idx = app_ble_get_idle_actv_idx_handle(SCAN_ACTV);
|
||
|
bk_ble_scan_start(actv_idx, &scan_info, ble_cmd_cb);
|
||
|
}
|
||
|
|
||
|
void Init_Adv() {
|
||
|
struct adv_param adv_info;
|
||
|
adv_info.channel_map = 7;
|
||
|
adv_info.duration = 0;
|
||
|
adv_info.prop = (1 << ADV_PROP_CONNECTABLE_POS) | (1 << ADV_PROP_SCANNABLE_POS);
|
||
|
adv_info.interval_min = 160;
|
||
|
adv_info.interval_max = 160;
|
||
|
adv_info.advData[0] = 0x09;
|
||
|
adv_info.advData[1] = 0x09;
|
||
|
memcpy(&adv_info.advData[2], "7252nBLE", 8);
|
||
|
adv_info.advDataLen = 10;
|
||
|
adv_info.respData[0] = 0x06;
|
||
|
adv_info.respData[1] = 0x08;
|
||
|
memcpy(&adv_info.respData[2], "7252n", 5);
|
||
|
adv_info.respDataLen = 7;
|
||
|
actv_idx = app_ble_get_idle_actv_idx_handle(ADV_ACTV);
|
||
|
bk_ble_adv_start(actv_idx, &adv_info, ble_cmd_cb);
|
||
|
}
|
||
|
|
||
|
void Start_Scan() {
|
||
|
bk_ble_start_scaning(0, 100, 30, ble_cmd_cb);
|
||
|
}
|
||
|
|
||
|
void Stop_Scan() {
|
||
|
bk_ble_stop_scaning(0,ble_cmd_cb);
|
||
|
}
|
||
|
|
||
|
int main(int argc, char **argv)
|
||
|
{
|
||
|
/* mount ROMFS as root directory */
|
||
|
#if defined(RT_USING_DFS_ROMFS)
|
||
|
if (dfs_mount(RT_NULL, "/", "rom", 0, (const void *)DFS_ROMFS_ROOT) == 0)
|
||
|
{
|
||
|
rt_kprintf("ROMFS File System initialized!\n");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
rt_kprintf("ROMFS File System initialized Failed!\n");
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
#if 0
|
||
|
/* mount sd card fat partition 1 as root directory */
|
||
|
saradc_config_vddram_voltage(PSRAM_VDD_3_3V);
|
||
|
if(dfs_mount("sd0", "/sd", "elm", 0, 0) == 0)
|
||
|
rt_kprintf("SD File System initialized!\n");
|
||
|
else
|
||
|
rt_kprintf("SD File System initialzation failed!\n");
|
||
|
#endif
|
||
|
|
||
|
#if 0
|
||
|
const struct fal_partition *dl_part = RT_NULL;
|
||
|
|
||
|
if ((dl_part = fal_partition_find(RT_BK_DL_PART_NAME)) != RT_NULL)
|
||
|
{
|
||
|
/* dump current firmware version. */
|
||
|
rt_kprintf("current image name: %s, version: %s, timestamp: %d \n", rt_ota_get_fw_dest_part_name(dl_part), rt_ota_get_fw_version(dl_part), rt_ota_get_fw_timestamp(dl_part));
|
||
|
|
||
|
rt_hw_flash_disk_readonly_init("flash0", dl_part->offset + 96, 512, dl_part->len - 1024);
|
||
|
/* mount sd card fat partition 1 as root directory */
|
||
|
if(dfs_mount("flash0", "/flash0", "elm", 0, 0) == 0)
|
||
|
rt_kprintf("FLASH File System initialized!\n");
|
||
|
else
|
||
|
rt_kprintf("FLASH File System initialzation failed!\n");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
rt_kprintf("not found %s partition \n", RT_BK_DL_PART_NAME);
|
||
|
}
|
||
|
|
||
|
#endif
|
||
|
|
||
|
wlan_app_init();
|
||
|
#if defined(PKG_USING_PLAYER)
|
||
|
extern int player_codec_helixmp3_register(void);
|
||
|
extern int player_codec_beken_aac_register(void);
|
||
|
extern int player_codec_beken_m4a_register(void);
|
||
|
extern int player_codec_opencore_amr_register(void);
|
||
|
|
||
|
player_codec_helixmp3_register();
|
||
|
player_codec_beken_aac_register();
|
||
|
player_codec_beken_m4a_register();
|
||
|
player_codec_opencore_amr_register();
|
||
|
player_system_init();
|
||
|
#endif
|
||
|
#ifdef XIAOYA_OS
|
||
|
app_manage_init();
|
||
|
#endif
|
||
|
rt_hw_wdg_start(0,NULL);
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
#ifdef BEKEN_USING_WLAN
|
||
|
|
||
|
extern void ate_app_init(void);
|
||
|
extern void ate_start(void);
|
||
|
|
||
|
static int wlan_app_init(void)
|
||
|
{
|
||
|
/* init ate mode check. */
|
||
|
ate_app_init();
|
||
|
|
||
|
if (get_ate_mode_state())
|
||
|
{
|
||
|
rt_kprintf("\r\n\r\nEnter automatic test mode...\r\n\r\n");
|
||
|
|
||
|
finsh_set_echo(0);
|
||
|
finsh_set_prompt("#");
|
||
|
|
||
|
ate_start();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
rt_kprintf("Enter normal mode...\r\n\r\n");
|
||
|
app_start();
|
||
|
//iic_bus_attach();
|
||
|
gpio_init();
|
||
|
|
||
|
OLED_Init();
|
||
|
OLED_Clear();
|
||
|
//OLED_ShowChar(32,0+10,'.',32,1);
|
||
|
//OLED_Refresh();
|
||
|
//rt_thread_mdelay(100);
|
||
|
//OLED_Clear();
|
||
|
//OLED_ShowChar(56,8+10,'C',24,1);
|
||
|
//OLED_Refresh();
|
||
|
//bk_gpio_output(20,0);
|
||
|
//bk_gpio_output(21,0);
|
||
|
//oled_show_temp(370,4);
|
||
|
//user_app_start();
|
||
|
Ble_Active();
|
||
|
Init_Scan();
|
||
|
rt_thread_mdelay(100);
|
||
|
Init_Adv();
|
||
|
rtos_init_timer(&timer_detect,1000,timer_temp_run_callback,NULL);
|
||
|
rtos_start_timer(&timer_detect);
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
#endif
|