#pragma once

#include "shark_types.h"
#include "common.h"

#define SHARK_CHG_TIME_DETECT		10
#define SHARK_CHG_TIME_SWITCH		12

#define SHARK_CHG_INSERT_MIN		50
#define SHARK_CHG_REMOVE_MIN		2000

#define GPIO_PORT_CHG_DET			GPIOC
#define GPIO_PIN_CHG_DET			GPIO_PIN_4
#define GPIO_RCU_CHG_DET			RCU_GPIOC

#define GPIO_PORT_CHG_EN			GPIOB
#define GPIO_PIN_CHG_EN				GPIO_PIN_12
#define GPIO_RCU_CHG_EN				RCU_GPIOB

#define EXTI_PORT_CHG_DET			GPIO_PORT_SOURCE_GPIOC
#define EXTI_PIN_CHG_DET			GPIO_PIN_SOURCE_4
#define EXTI_CHG_DET				EXTI_4

typedef enum {
	SHARK_CHG_REMOVE,
	SHARK_CHG_DETECT,
	SHARK_CHG_INSERT,
} shark_charger_state_t;

extern shark_charger_state_t shark_charger_state;
extern shark_bool shark_charger_enabled;
extern shark_bool shark_charger_valid;
extern shark_bool shark_battery_full;
extern shark_u32 shark_charge_time;

void shark_charger_set_enable(shark_bool enable);
shark_bool shark_battery_charge_full(void);
shark_bool shark_charger_is_normal(void);
shark_bool shark_charger_is_allow(void);
void shark_charger_set_poll(void);
void shark_charger_disable(void);
void shark_charge_init(void);
void shark_charge_tick(void);
void shark_charge_poll(void);
void shark_charge_isr(void);

static inline shark_u32 shark_charge_get_time(void)
{
	return shark_get_seconds() - shark_charge_time;
}

