/*
************************************************************************************************************
*
*                                             function
*
*    函数名称:
*
*    参数列表:
*
*    返回值  :
*
*    说明    :
*
*
************************************************************************************************************
*/
int sprite_led_init(void)
{
    user_gpio_set_t     gpio_init;
	int					ret;
	int					delay;

	sprite_timer_hd = wBoot_timer_request((void *)sprite_timer_func, 0);
	if(!sprite_timer_hd)
	{
		__inf("reuqest timer for led failed\n");

		return -1;
	}
	else
	{
		sprite_led_status = 1;
		ret = wBoot_script_parser_fetch("card_boot", "sprite_work_delay", (void *)&delay, 1);
		if((ret) || (!delay))
		{
			delay = 500;
		}
	}
	__inf("try gpio config\n");
	sprite_led_hd = NULL;
	memset(&gpio_init, 0, sizeof(user_gpio_set_t));
	ret = wBoot_script_parser_fetch("card_boot", "sprite_gpio0", (void *)&gpio_init, sizeof(user_gpio_set_t)>>2);
	if(!ret)
	{
		if(gpio_init.port)
		{
			sprite_led_hd = wBoot_GPIO_Request(&gpio_init, 1);
			if(!sprite_led_hd)
			{
				__inf("reuqest gpio for led failed\n");

				goto _led_err;
			}
			__inf("gpio start\n");
			wBoot_timer_start(sprite_timer_hd, delay, 1);	//初始1000ms翻转一次,重复显示

			return 0;
		}
	}
	__inf("try codec config\n");
	codec_init();
	codec_led_hd = codec_play();
	wBoot_timer_start(sprite_timer_hd, delay, 1);	//初始1000ms翻转一次,重复显示

	return 0;


_led_err:
	if(sprite_timer_hd)
	{
		wBoot_timer_release(sprite_timer_hd);
	}

	return -1;
}
/*
************************************************************************************************************
*
*                                             function
*
*    函数名称:
*
*    参数列表:
*
*    返回值  :
*
*    说明    :
*
*
************************************************************************************************************
*/
__u32 usb_detect_enter(void)
{
	awxx_usb[0].index = 0;
	awxx_usb[0].reg_base = 	0x01c13000;
	awxx_usb[0].irq_no = GIC_SRC_USB0;
	awxx_usb[0].drq_no = 0x04;

	__inf("usb start detect\n");
	if(!usb_working)
	{
		__inf("usb enter detect\n");
		usb_working = 1;
		usb_clock_init();

		tmr_hd = wBoot_timer_request((void *)timer_test_usbdc, 0);
		if(!tmr_hd)
		{
			__inf("timer request fail\n");
		}
		else
		{
			wBoot_timer_start(tmr_hd, 400, 0);
		}
		wBoot_InsINT_Func(awxx_usb[0].irq_no, (int *)usb_detect_irq_handler, 0);
		wBoot_EnableInt(awxx_usb[0].irq_no);
		usb_init(&awxx_usb[0]);
		usb_soft_connect(&awxx_usb[0]);
	}


	return 0;
}
// [before][step_0][delay_0][step_1][delay_1]......[step_n-2][delay_n-2][step_n-1][delay_n-1][after]
void DRV_lcd_close_callback(void *parg)
{
    __lcd_flow_t *flow;
    __u32 sel = (__u32)parg;
    __s32 i = lcd_flow_cnt[sel]++;

    flow = BSP_disp_lcd_get_close_flow(sel);

    if(i < flow->func_num)
    {
    	flow->func[i].func(sel);
        if(flow->func[i].delay == 0)
        {
            DRV_lcd_close_callback((void*)sel);
        }
        else
        {
            wBoot_timer_start(lcd_timer[sel], flow->func[i].delay, 0);
        }
    }
    else if(i == flow->func_num)
    {
        BSP_disp_lcd_close_after(sel);
        lcd_op_finished[sel] = 1;
    }
}
/*
************************************************************************************************************
*
*                                             function
*
*    函数名称:
*
*    参数列表:
*
*    返回值  :
*
*    说明    :
*
*
************************************************************************************************************
*/
int sprite_led_exit(int status)
{
	int ret;
	int delay;

	if(!sprite_timer_hd)
	{
		return -1;
	}
	wBoot_timer_stop(sprite_timer_hd);
	if(status < 0)
	{
		ret = wBoot_script_parser_fetch("card_boot", "sprite_err_delay", (void *)&delay, 1);
		if((ret) || (!delay))
		{
			delay = 100;
		}
		wBoot_timer_start(sprite_timer_hd, delay, 1);
	}

	return 0;
}