#pragma once

#include "shark_types.h"
#include "drv_io.h"

#define CONFIG_XL_MIN		50
#define CONFIG_XL_MAX		100
#define CONFIG_XL_TICKS		200

#define GPIO_RCU_XL			RCU_GPIOB
#define GPIO_PORT_XL		GPIOB
#define GPIO_PIN_XL			GPIO_PIN_7

#define EXTI_PORT_XL		GPIO_PORT_SOURCE_GPIOB
#define EXTI_PIN_XL			GPIO_PIN_SOURCE_7
#define EXTI_XL				EXTI_7

#define SHARK_XL_DEBOUNCE	10

extern shark_u16 shark_xl_ticks;
extern shark_u8 shark_xl_skip;

extern shark_u16 shark_xl_speed_max;
extern shark_u16 shark_xl_speed_tmp;
extern shark_u16 shark_xl_speed;

extern shark_u8 shark_xl_detected;

void shark_xl_init(void);
void shark_xl_tick(void);
void shark_xl_isr(void);

static inline shark_bool shark_xl_check(void)
{
	return shark_xl_speed > CONFIG_XL_MIN;
}

static inline shark_bool shark_xl_check_with_qd(void)
{
	return shark_xl_check() && QD_Dect();
}
