422 lines
10 KiB
C
Executable File
422 lines
10 KiB
C
Executable File
// libc
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <kwrap/type.h>
|
|
#include <kwrap/platform.h>
|
|
#include <kwrap/flag.h>
|
|
#include "PStore.h"
|
|
#include "UIWnd/UIFlow.h"
|
|
#include "System/SysMain.h"
|
|
#include "hdal.h"
|
|
#include "SxTimer/SxTimer.h"
|
|
#include "DrvExt.h"
|
|
#include "comm/hwclock.h"
|
|
#include "comm/timer.h"
|
|
#include <pmu.h>
|
|
#include "ImageApp/ImageApp_Common.h"
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
#define __MODULE__ main
|
|
#define __DBGLVL__ 2 // 0=FATAL, 1=ERR, 2=WRN, 3=UNIT, 4=FUNC, 5=IND, 6=MSG, 7=VALUE, 8=USER
|
|
#define __DBGFLT__ "*" //*=All, [mark]=CustomClass
|
|
#include <kwrap/debug.h>
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#define DEFAULT_YEAR 2000
|
|
#define DEFAULT_MON 1
|
|
#define DEFAULT_DAY 1
|
|
#define DEFAULT_HOUR 0
|
|
#define DEFAULT_MIN 0
|
|
#define DEFAULT_SEC 0
|
|
|
|
#define VENDOR_AI_CFG 0x000f0000 //vendor ai config
|
|
|
|
extern void *vdoout_get_buf(void);
|
|
|
|
#if defined(_UI_STYLE_LVGL_)
|
|
|
|
/******************************************************
|
|
* include headers
|
|
*******************************************************/
|
|
#include "lvgl/lvgl.h"
|
|
#include "lv_drivers/display/fbdev.h"
|
|
|
|
/******************************************************
|
|
* extern function declaration
|
|
*******************************************************/
|
|
extern bool keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
|
extern bool pointer_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
|
extern void lvglTimer(void);
|
|
|
|
/******************************************************
|
|
* static variables
|
|
*******************************************************/
|
|
static lv_disp_buf_t disp_buf_2;
|
|
|
|
|
|
/******************************************************
|
|
* global variables
|
|
*******************************************************/
|
|
lv_indev_t* indev_keypad = NULL;
|
|
lv_indev_t* indev_pointer = NULL;
|
|
|
|
|
|
int nvt_lvgl_init(void)
|
|
{
|
|
/*-------------------------
|
|
* Initialize your display
|
|
* -----------------------*/
|
|
|
|
/*LittlevGL init*/
|
|
lv_init();
|
|
|
|
/*Linux frame buffer device init*/
|
|
fbdev_init();
|
|
|
|
/*-----------------------------
|
|
* Create a buffer for drawing
|
|
*----------------------------*/
|
|
/*Set a display buffer*/
|
|
|
|
#if LV_USE_GPU_NVT_DMA2D
|
|
|
|
|
|
|
|
#if LV_USER_CFG_USE_TWO_BUFFER
|
|
void *buf2_1 = (void *)((UINT32)fbp+(screensize*2));
|
|
#else
|
|
void *buf2_1 = (void *)((UINT32)fbp+screensize);
|
|
#endif
|
|
|
|
#else
|
|
lv_color_t* buf2_1 = (lv_color_t*) malloc(LV_HOR_RES_MAX * LV_VER_RES_MAX * sizeof(lv_color_t)); /*A screen sized buffer*/
|
|
LV_ASSERT_NULL(buf2_1);
|
|
memset(buf2_1, 0, LV_HOR_RES_MAX * LV_VER_RES_MAX * sizeof(lv_color_t));
|
|
|
|
#if LV_USER_CFG_USE_TWO_BUFFER
|
|
lv_color_t* buf2_2 = (lv_color_t*) malloc(LV_HOR_RES_MAX * LV_VER_RES_MAX * sizeof(lv_color_t)); /*A screen sized buffer*/
|
|
LV_ASSERT_NULL(buf2_2);
|
|
memset(buf2_2, 0, LV_HOR_RES_MAX * LV_VER_RES_MAX * sizeof(lv_color_t));
|
|
#endif
|
|
#endif
|
|
|
|
lv_disp_buf_init(&disp_buf_2, buf2_1, 0, LV_HOR_RES_MAX * LV_VER_RES_MAX); /*Initialize the display buffer*/
|
|
|
|
/*-----------------------------------
|
|
* Register the display in LVGL
|
|
*----------------------------------*/
|
|
/*Add a display the LittlevGL sing the frame buffer driver*/
|
|
lv_disp_drv_t disp_drv;
|
|
lv_disp_drv_init(&disp_drv);
|
|
|
|
//disp_drv.hor_res = LV_VER_RES_MAX;
|
|
//disp_drv.ver_res = LV_HOR_RES_MAX;
|
|
disp_drv.rotated = 0;
|
|
|
|
/*Set a display buffer*/
|
|
disp_drv.buffer = &disp_buf_2;
|
|
|
|
/*Used to copy the buffer's content to the display*/
|
|
disp_drv.flush_cb = disp_flush;
|
|
|
|
disp_drv.rounder_cb = lv_user_rounder_callback;
|
|
|
|
#if LV_COLOR_DEPTH == 24
|
|
disp_drv.set_px_cb = set_px_cb_8565;
|
|
#else
|
|
disp_drv.set_px_cb = NULL;
|
|
#endif
|
|
|
|
/*Finally register the driver*/
|
|
lv_disp_t * disp;
|
|
disp = lv_disp_drv_register(&disp_drv); /*It flushes the internal graphical buffer to the frame buffer*/
|
|
|
|
lv_disp_drv_update(disp, &disp_drv);
|
|
|
|
|
|
/*Register a keypad input device*/
|
|
lv_indev_drv_t indev_drv;
|
|
lv_indev_drv_init(&indev_drv);
|
|
indev_drv.type = LV_INDEV_TYPE_KEYPAD;
|
|
indev_drv.read_cb = keypad_read;
|
|
indev_keypad = lv_indev_drv_register(&indev_drv);
|
|
|
|
|
|
|
|
/*Register a keypad input device*/
|
|
lv_indev_drv_init(&indev_drv);
|
|
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
|
indev_drv.read_cb = pointer_read;
|
|
indev_pointer = lv_indev_drv_register(&indev_drv);
|
|
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
#include "kwrap/cmdsys.h"
|
|
|
|
#if (USB_POWER_DISABLE==ENABLE)
|
|
static void rtos_usb_power_disable(void)
|
|
{
|
|
nvt_cmdsys_runcmd("mem w 0xF06010D0 0x000000FF");
|
|
nvt_cmdsys_runcmd("mem w 0xF06010D4 0x00000034");
|
|
nvt_cmdsys_runcmd("mem w 0xF0601008 0x00000014");
|
|
nvt_cmdsys_runcmd("mem w 0xF0601000 0x00000088");
|
|
nvt_cmdsys_runcmd("mem w 0xF0601030 0x00000035");
|
|
nvt_cmdsys_runcmd("mem w 0xF060102C 0x000000FF");
|
|
nvt_cmdsys_runcmd("mem w 0xF0601028 0x00000020");
|
|
nvt_cmdsys_runcmd("mem w 0xF0601024 0x00000093");
|
|
}
|
|
#endif
|
|
|
|
#if (ETH_POWER_DISABLE==ENABLE)
|
|
static void rtos_eth_power_disable(void)
|
|
{
|
|
nvt_cmdsys_runcmd("mem w 0xF02B3AE8 0x01");
|
|
nvt_cmdsys_runcmd("mem w 0xF02B3AE0 0x11");
|
|
nvt_cmdsys_runcmd("mem w 0xF02B38DC 0x01");
|
|
nvt_cmdsys_runcmd("mem w 0xF02B389C 0x33");
|
|
nvt_cmdsys_runcmd("mem w 0xF02B38CC 0xA5");
|
|
nvt_cmdsys_runcmd("mem w 0xF02B388C 0x11");
|
|
nvt_cmdsys_runcmd("mem w 0xF02B38C8 0x01");
|
|
nvt_cmdsys_runcmd("mem w 0xF02B3888 0x08");
|
|
nvt_cmdsys_runcmd("mem w 0xF02B38C8 0x03");
|
|
nvt_cmdsys_runcmd("mem w 0xF02B3888 0x08");
|
|
nvt_cmdsys_runcmd("mem w 0xF02B38F8 0x61");
|
|
}
|
|
#endif
|
|
|
|
int nvt_user_init(void)
|
|
{
|
|
UXUSER_OBJ uxuser_param={0};
|
|
ER ret=0;
|
|
|
|
//project init
|
|
PStore_InstallID();
|
|
UIControl_InstallID();
|
|
|
|
uxuser_param.pfMainProc = UserMainProc;
|
|
uxuser_param.pfNvtUserCB = UserErrCb;
|
|
ret = Ux_Open(&uxuser_param);
|
|
if(ret!=0){
|
|
DBG_ERR("Ux_Open fail%d\r\n",ret);
|
|
return -1;
|
|
}
|
|
|
|
BKG_OBJ uiBackObj = {0};
|
|
//Init UI background
|
|
uiBackObj.pDefaultFuncTbl = 0; //gBackgroundExtFuncTable
|
|
uiBackObj.done_event = NVTEVT_BACKGROUND_DONE;
|
|
ret = BKG_Open(&uiBackObj);
|
|
if(ret!=0){
|
|
DBG_ERR("BKG_Open fail%d\r\n",ret);
|
|
return -1;
|
|
}
|
|
|
|
|
|
/* move lvgl timer here due to post event must after timer initialized */
|
|
#if defined(_UI_STYLE_LVGL_)
|
|
|
|
TIMER_ID id;
|
|
if (timer_open((TIMER_ID *)&id, (DRV_CB)lvglTimer) != E_OK) {
|
|
DBG_ERR("timer trig open failed!\r\n");
|
|
return -1;
|
|
}
|
|
|
|
timer_cfg(id, LV_DISP_DEF_REFR_PERIOD * 1000, TIMER_MODE_FREE_RUN | TIMER_MODE_ENABLE_INT, TIMER_STATE_PLAY);
|
|
|
|
#endif
|
|
|
|
#if (ETH_POWER_DISABLE==ENABLE)
|
|
rtos_eth_power_disable();
|
|
#endif
|
|
|
|
#if (USB_POWER_DISABLE==ENABLE)
|
|
rtos_usb_power_disable();
|
|
#endif
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
int nvt_user_uninit(void)
|
|
{
|
|
Ux_Close();
|
|
BKG_Close();
|
|
GxGfx_Exit();
|
|
UIControl_UninstallID();
|
|
return 0;
|
|
}
|
|
|
|
UINT32 nvt_hdal_init(void)
|
|
{
|
|
HD_RESULT ret;
|
|
HD_COMMON_MEM_INIT_CONFIG mem_cfg = {0};
|
|
|
|
ret = hd_common_init(0);
|
|
if(ret != HD_OK) {
|
|
DBG_ERR("common init fail=%d\n", ret);
|
|
return -1;
|
|
}
|
|
|
|
#if (GDC_POWER_DISABLE==ENABLE)
|
|
hd_common_sysconfig(HD_VIDEOPROC_CFG, 0, HD_VIDEOPROC_CFG_LL_FAST, 0);
|
|
#else
|
|
hd_common_sysconfig(HD_VIDEOPROC_CFG, 0, HD_VIDEOPROC_CFG_GDC_BEST, 0);
|
|
#endif
|
|
|
|
#if (ALG_FUNC_AI2 == ENABLE)
|
|
hd_common_sysconfig(0, (1<<16), 0, VENDOR_AI_CFG); //enable AI engine
|
|
#endif
|
|
|
|
#if defined(_UI_STYLE_LVGL_)
|
|
#if LV_USER_CFG_USE_ROTATE_BUFFER
|
|
mem_cfg.pool_info[0].type = HD_COMMON_MEM_COMMON_POOL;
|
|
mem_cfg.pool_info[0].blk_size = LOGO_BS_BLK_SIZE;
|
|
mem_cfg.pool_info[0].blk_cnt = 1;
|
|
mem_cfg.pool_info[0].ddr_id = DDR_ID0;
|
|
#endif
|
|
#else
|
|
#if (VDO_USE_ROTATE_BUFFER==ENABLE)
|
|
mem_cfg.pool_info[0].type = HD_COMMON_MEM_COMMON_POOL;
|
|
mem_cfg.pool_info[0].blk_size = LOGO_BS_BLK_SIZE;
|
|
mem_cfg.pool_info[0].blk_cnt = 1;
|
|
mem_cfg.pool_info[0].ddr_id = DDR_ID0;
|
|
#endif
|
|
#endif
|
|
|
|
ret = hd_common_mem_init(&mem_cfg);
|
|
if(ret != HD_OK) {
|
|
DBG_ERR("mem init fail=%d\n", ret);
|
|
return -1;
|
|
}
|
|
ret = hd_gfx_init();
|
|
if(ret != HD_OK) {
|
|
DBG_ERR("gfx init fail=%d\n", ret);
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
UINT32 nvt_hdal_uninit(void)
|
|
{
|
|
HD_RESULT ret;
|
|
|
|
ret = hd_gfx_uninit();
|
|
if(ret != HD_OK) {
|
|
DBG_ERR("gfx uninit fail=%d\n", ret);
|
|
return -1;
|
|
}
|
|
ret = hd_common_mem_uninit();
|
|
if(ret != HD_OK) {
|
|
DBG_ERR("mem uninit fail=%d\n", ret);
|
|
return -1;
|
|
}
|
|
ret = hd_common_uninit();
|
|
if(ret != HD_OK) {
|
|
DBG_ERR("common uninit fail=%d\n", ret);
|
|
return -1;
|
|
}
|
|
return 0;
|
|
|
|
}
|
|
|
|
ID FLG_ID_MAIN = 0;
|
|
|
|
#define FLG_MAIN_ON 0x00000001 //
|
|
#define FLG_MAIN_OFF 0x00000002 //
|
|
#define FLG_MAIN_COMMAND (FLG_MAIN_ON|FLG_MAIN_OFF) //
|
|
|
|
extern ID _SECTION(".kercfg_data") FLG_ID_MAIN;
|
|
|
|
void System_InstallID(void)
|
|
{
|
|
OS_CONFIG_FLAG(FLG_ID_MAIN);
|
|
}
|
|
|
|
void System_PowerOnFinish(void)
|
|
{
|
|
//clr_flg(FLG_ID_MAIN, FLG_MAIN_COMMAND);
|
|
//sta_tsk(IDLETSK_ID,0);
|
|
vos_flag_set(FLG_ID_MAIN, FLG_MAIN_ON);
|
|
}
|
|
|
|
void System_PowerOffStart(void)
|
|
{
|
|
vos_flag_set(FLG_ID_MAIN, FLG_MAIN_OFF);
|
|
}
|
|
|
|
void System_WaitForPowerOnFinish(void)
|
|
{
|
|
FLGPTN uiFlag;
|
|
vos_flag_wait(&uiFlag, FLG_ID_MAIN, FLG_MAIN_ON, TWF_ORW);
|
|
}
|
|
|
|
void System_WaitForPowerOffStart(void)
|
|
{
|
|
FLGPTN uiFlag;
|
|
vos_flag_wait(&uiFlag, FLG_ID_MAIN, FLG_MAIN_OFF, TWF_ORW);
|
|
}
|
|
|
|
#if (defined(_MODEL_CARDV_M320P_) || defined(_MODEL_CARDV_M320PB_))
|
|
extern void rtcTest_poweroffPWR(void);
|
|
#endif
|
|
|
|
int NvtMain(void)
|
|
{
|
|
System_InstallID();
|
|
#if (USB_MODE==ENABLE)
|
|
System_OnUsbPreInit();
|
|
#endif
|
|
System_OnPowerPreInit();
|
|
#if HUNTING_CAMERA_MCU != ENABLE// The time is controlled by the MCU. sf_get_mcu_rtc_set_sys
|
|
struct tm ctv = {0};
|
|
|
|
//System_OnPowerPreInit() should be prior to rtc checking
|
|
ctv = hwclock_get_time(TIME_ID_CURRENT);
|
|
if(ctv.tm_year < DEFAULT_YEAR) {
|
|
ctv.tm_year = DEFAULT_YEAR;
|
|
ctv.tm_mon = DEFAULT_MON;
|
|
ctv.tm_mday = DEFAULT_DAY;
|
|
ctv.tm_hour = DEFAULT_HOUR;
|
|
ctv.tm_min = DEFAULT_MIN;
|
|
ctv.tm_sec = DEFAULT_SEC;
|
|
hwclock_set_time(TIME_ID_CURRENT, ctv, 0);
|
|
}
|
|
#endif
|
|
|
|
#if (POWERON_TRACE == ENABLE)
|
|
System_WaitForPowerOnFinish(); // Wait for boot cmd
|
|
#endif
|
|
Dx_InitIO();
|
|
|
|
#if (defined(_MODEL_CARDV_M320P_) || defined(_MODEL_CARDV_M320PB_))
|
|
pmu_mod_init();
|
|
#endif
|
|
|
|
SxTimer_Open(); //start sxtimer task
|
|
System_OnTimerInit();
|
|
#if (USB_MODE==ENABLE)
|
|
System_OnUsbInit();
|
|
#endif
|
|
nvt_hdal_init();
|
|
nvt_user_init();
|
|
|
|
System_WaitForPowerOffStart(); // Wait for shutdown cmd
|
|
|
|
nvt_user_uninit();
|
|
nvt_hdal_uninit();
|
|
|
|
#if (defined(_MODEL_CARDV_M320P_) || defined(_MODEL_CARDV_M320PB_))
|
|
vos_util_delay_us(800);
|
|
rtcTest_poweroffPWR(); // power off only, no block cpu
|
|
pmu_mod_exit();
|
|
#else
|
|
System_OnPowerPostExit(); //never return
|
|
#endif
|
|
|
|
return 0;
|
|
}
|