#include <stdio.h>
#include "cola_init.h"
#include "cola_device.h"
#include "cola_os.h"
#include "../fml/fml_gpio.h"
#include "../fml/fml_master_iic.h"
#include "../fml/fml_TFT.h"

static task_t s_bist_task;
static task_t s_bist_check_task;
extern bool bist_mode;
extern bool test_mode_flag;
uint32_t last_time = 0;
uint8_t style = 0;
static bool last_bist_mode = false;
void logic_polling_change_pattern(void *arg, uint32_t event)
{
	(void) arg;
	if((bist_mode == false) && (last_bist_mode != bist_mode))
	{
		fml_gpio_write(OUT_TFT_BIST,false);
		last_bist_mode = bist_mode;
	}
	else if ((bist_mode == true) && (last_bist_mode != bist_mode))
	{
		fml_gpio_write(OUT_TFT_BIST,true);
		last_bist_mode = bist_mode;
		style=0;
		last_time = jiffies-10000;
	}
	if(jiffies-last_time > 5000)
	{
		last_time = jiffies;
		fml_tft_BIST_clear();
		fml_tft_write_BIST_mode(style);
		style = style+1;
		if(style == 24)
		{
			style=0;

		}
	}



}
void check_LVDS_floating(void)
{

	if(bist_mode == true)
	{
		fml_gpio_write(OUT_TFT_BIST,true);
		fml_Write_ISET(0x02);
		fml_tft_BIST_clear();
		last_time = jiffies;
		cola_timer_create(&s_bist_task, logic_polling_change_pattern, NULL);
		cola_timer_start(&s_bist_task, EN_COLA_TIMER_ALWAYS, 50);
		cola_timer_stop(&s_bist_check_task);
	}
}
void Turn_BIST_init(void)
{
	cola_timer_create(&s_bist_check_task, check_LVDS_floating, NULL);
	cola_timer_start(&s_bist_check_task, EN_COLA_TIMER_ALWAYS, 100);
}
