IM31-P2-Display/DP1208/mcu_app/logic/logic_power_manage.c
2025-05-21 11:31:07 +08:00

126 lines
3.1 KiB
C

#include <stdio.h>
#include "cola_init.h"
#include "cola_device.h"
#include "cola_os.h"
#include "fml_gpio.h"
#include "fml_pwm.h"
#include "fml_PMIC.h"
#include "bsp_register_map.h"
static task_t gpioTask1;
static task_t gpioTask2;
static task_t gpioTask3;
bool wakeup = false;
bool lock = false;
extern ST_DIAGNOSE1_DATA Err_status1;
extern bool bist_mode;
void lock_detect(void *arg, uint32_t event)
{
lock = fml_gpio_read(IN_LVDS_UNLOCK);
if((lock == true)||(bist_mode == true))
{
cola_delay_ms(200);
lock = fml_gpio_read(IN_LVDS_UNLOCK);
if((lock == true)||(bist_mode == true))
{
cola_task_delete(&gpioTask2);
fml_gpio_write(OUT_TFT_SHLR,true);
fml_gpio_write(OUT_TFT_RST,false);
cola_delay_ms(100);
fml_gpio_write(OUT_TFT_RST,true);
fml_gpio_write(OUT_TFT_SYBYB,true);
fml_gpio_write(OUT_TFT_DISP,true);
//fml_gpio_write(OUT_TFT_BIST,true);
fml_gpio_write(OUT_BL_EN,true);
fml_gpio_write(OUT_PMIC_EN,true);
fml_pwm_init();
cola_delay_ms(10);
fml_tft_init();
cola_delay_ms(10);
fml_pmic_init();
fml_max25512_init();
power_up_manage();
}
}
}
void power_on_detect(void *arg, uint32_t event)
{
wakeup = fml_gpio_read(IN_WAKEUP);
if((wakeup == true)&&(Err_status1.HIGH_VOL_FAIL == 0)&&(Err_status1.LOW_VOL_FAIL==0))
{
cola_task_delete(&gpioTask1);
fml_gpio_write(OUT_TP_RST,true);
fml_gpio_write(OUT_PON_HOLD,true);
fml_gpio_write(OUT_LDO_1V2_EN,true);
fml_gpio_write(OUT_3V3_TFT_EN,true);
fml_gpio_write(OUT_LVDS_PDB,true);
cola_task_create(&gpioTask2, lock_detect, NULL);
}
}
//start
void power_on_manage(void)
{
// fml_gpio_write(OUT_TP_RST,true);
// fml_gpio_write(OUT_PON_HOLD,true);
// fml_gpio_write(OUT_LDO_1V2_EN,true);
//
// fml_gpio_write(OUT_3V3_TFT_EN,true);
// cola_delay_ms(200);
// fml_gpio_write(OUT_LVDS_PDB,true);
//
//
// fml_gpio_write(OUT_TFT_SHLR,true);
// fml_gpio_write(OUT_TFT_RST,false);
// cola_delay_ms(200);
// fml_gpio_write(OUT_TFT_RST,true);
//
// fml_gpio_write(OUT_TFT_SYBYB,true);
// fml_gpio_write(OUT_TFT_DISP,true);
// fml_gpio_write(OUT_BL_EN,true);
// fml_pwm_init();
// //fml_gpio_write(OUT_TFT_BIST,true);
// fml_gpio_write(OUT_PMIC_EN,true);
// cola_delay_ms(10);
// fml_tft_init();
// cola_delay_ms(10);
// fml_pmic_init();
// fml_max25512_init();
//fml_tft_write_BIST_mode(0);
cola_task_create(&gpioTask1, power_on_detect, NULL);
}
void power_up_detect(void)
{
wakeup = fml_gpio_read(IN_WAKEUP);
if((wakeup == false)||(Err_status1.HIGH_VOL_FAIL == 1)||(Err_status1.LOW_VOL_FAIL==1))
{
cola_delay_ms(200);
wakeup = fml_gpio_read(IN_WAKEUP);
if((wakeup == false)||(Err_status1.HIGH_VOL_FAIL == 1)||(Err_status1.LOW_VOL_FAIL==1))
{
cola_task_delete(&gpioTask3);
fml_gpio_write(OUT_BL_EN,false);
fml_gpio_write(OUT_PMIC_EN,false);
fml_gpio_write(OUT_TFT_SYBYB,false);
fml_gpio_write(OUT_TFT_DISP,false);
fml_gpio_write(OUT_LVDS_PDB,false);
fml_gpio_write(OUT_3V3_TFT_EN,false);
fml_gpio_write(OUT_LDO_1V2_EN,false);
fml_gpio_write(OUT_PON_HOLD,false);
power_on_manage();
}
}
}
void power_up_manage(void)
{
cola_task_create(&gpioTask3, power_up_detect, NULL);
}