/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : bsp_key.h
  * @brief          : Board support package key driver header file
  ******************************************************************************
  */
/* USER CODE END Header */

#ifndef BSP_KEY_H
#define BSP_KEY_H

#include <stdint.h>

/**
 * @brief Key ID definitions
 */
typedef enum {
    BSP_KEY_ID_KEY0 = 0,
    BSP_KEY_ID_KEY1,
    BSP_KEY_ID_WKUP,
    BSP_KEY_ID_MAX
} bsp_key_id_t;

/**
 * @brief Key state definitions
 */
typedef enum {
    BSP_KEY_STATE_RELEASED = 0,
    BSP_KEY_STATE_PRESSED
} bsp_key_state_t;

/**
 * @brief Key event definitions
 */
typedef enum {
    BSP_KEY_EVENT_NONE = 0,
    BSP_KEY_EVENT_PRESSED,        /* Key pressed event */
    BSP_KEY_EVENT_RELEASED,       /* Key released event */
    BSP_KEY_EVENT_LONG_PRESSED,   /* Key long pressed event */
    BSP_KEY_EVENT_REPEAT,         /* Key repeat event */
    BSP_KEY_EVENT_SHORT_PRESSED   /* Key short pressed event */
} bsp_key_event_t;

/**
 * @brief Initialize all keys
 */
void bsp_key_init(void);

/**
 * @brief Update key state (call this function periodically, e.g. every 10ms)
 */
void bsp_key_update(void);

/**
 * @brief Read debounced key state
 * @param key_id: Key ID
 * @retval Key state
 */
bsp_key_state_t bsp_key_read(bsp_key_id_t key_id);

/**
 * @brief Check if key is pressed
 * @param key_id: Key ID
 * @retval 1 if pressed, 0 otherwise
 */
uint8_t bsp_key_is_pressed(bsp_key_id_t key_id);

/**
 * @brief Check if key is released
 * @param key_id: Key ID
 * @retval 1 if released, 0 otherwise
 */
uint8_t bsp_key_is_released(bsp_key_id_t key_id);

/**
 * @brief Check for key press event (edge detection)
 * @param key_id: Key ID
 * @retval 1 if key was pressed, 0 otherwise
 */
uint8_t bsp_key_get_press_event(bsp_key_id_t key_id);

/**
 * @brief Check for key release event (edge detection)
 * @param key_id: Key ID
 * @retval 1 if key was released, 0 otherwise
 */
uint8_t bsp_key_get_release_event(bsp_key_id_t key_id);

/**
 * @brief Check for key long pressed event
 * @param key_id: Key ID
 * @retval 1 if key was long pressed, 0 otherwise
 */
uint8_t bsp_key_get_long_press_event(bsp_key_id_t key_id);

/**
 * @brief Check for key repeat event
 * @param key_id: Key ID
 * @retval 1 if key repeat event occurred, 0 otherwise
 */
uint8_t bsp_key_get_repeat_event(bsp_key_id_t key_id);

/**
 * @brief Check for key short pressed event
 * @param key_id: Key ID
 * @retval 1 if key was short pressed, 0 otherwise
 */
uint8_t bsp_key_get_short_press_event(bsp_key_id_t key_id);

#endif /* BSP_KEY_H */
