/**
 * @file	   hal_gpio.c
 *
 * @copyright  Nehemis SARL reserves all rights even in the event of industrial
 *             property rights. We reserve all rights of disposal such as
 *             copying and passing on to third parties.
 *
 * @brief	   HAL layer for the GPIO module.
 *
 */


#ifndef HAL_TIMER_H_
#define HAL_TIMER_H_

/******************************************************************************
 * Include Header Files
 ******************************************************************************/
#include "nms_types.h"
#include "map_hal.h"

/******************************************************************************
 * Type declarations
 ******************************************************************************/
typedef enum
{
    HAL_GPIO_STATE_UNKNOWN = 0U,
    HAL_GPIO_STATE_LOW,
    HAL_GPIO_STATE_HIGH,
} HalGpioState_en; /**< Enumeration used to analyze the gpio state. */

typedef enum {
    HAL_GPIO_EDGE_NONE = 0U,
    HAL_GPIO_EDGE_RISING,
    HAL_GPIO_EDGE_FALLING,
    HAL_GPIO_EDGE_RISING_AND_FALLING
} HalGpioEdgeType_en;  /**< Enumeration used to analyze the edge of interrupt. */

typedef enum
{
    HAL_GPIO_INPUT = 0U,
    HAL_GPIO_OUTPUT_PUSH_PULL_UP,
    HAL_GPIO_OUTPUT_PUSH_PULL_DOWN,
    HAL_GPIO_OUTPUT_PUSH_PULL_FREE,
    HAL_GPIO_OUTPUT_OPEN_DRAIN_UP,
    HAL_GPIO_OUTPUT_OPEN_DRAIN_FREE,
    HAL_GPIO_ISR_RISING,
    HAL_GPIO_ISR_FALLING,
    HAL_GPIO_ALTERNATE
} HalGpioType_en; /**< Enumeration used to analyze the gpio function type. */

/******************************************************************************
 * Extern Function Declarations
 ******************************************************************************/
/**
 * @brief   Initializes and configures GPIO input/output pins.
 *
 * @note    Output pins are set to predefined states during initialization.
 *
 * @return  Pin state: HIGH, LOW, or UNKNOWN.
 */
uint32 HalGpioInit(void);

/**
 * @brief   Reads the state of a GPIO input pin.
 *
 * @param   pin_en      GPIO pin selection.
 * 		    state_pen   Pointer to store the read pin state.
 *
 * @return  Error code: 0 if successful, nonzero otherwise.
 */
uint32 HalGpioRead(MapHalGpioPin_en pin_en, HalGpioState_en *state_pen);

/**
 * @brief   Sets the state of a GPIO output pin.
 *
 * @param   pin_en      GPIO pin selection.
 *			state_pen   Desired GPIO pin state.
 *
 * @return  Error code: 0 if successful, nonzero otherwise.
 */
uint32 HalGpioWrite(MapHalGpioPin_en pin_en, HalGpioState_en state_pen);

/**
 * @brief   Toggles the state of a GPIO pin.
 *
 * @param   pin_en  GPIO pin selection.
 *
 * @return  Error code: 0 if successful, nonzero otherwise.
 */
uint32 HalGpioToggle(MapHalGpioPin_en pin_en);

/**
 * @brief   Reconfigures the properties of a GPIO pin.
 *
 * @param   pin_en   GPIO pin selection.
 *			type_en  GPIO pin type.
 *
 * @return  Error code: 0 if successful, nonzero otherwise.
 *
 * @warning GPIO speed modification is not supported in this driver version.
 *          Future updates may include support for this feature.
 */
uint32 HalGpioReConfigure(MapHalGpioPin_en pin_en, HalGpioType_en type_en);

/**
 * @brief   Assigns a callback function for GPIO interrupt events.
 *
 * @param   pin_en         GPIO pin selection.
 *			callback_pfn   Pointer to the callback function.
 *			edge_en        Interrupt trigger edge:
 *                         - 1 for Rising Edge
 *                         - 0 for Falling Edge (Consider using an enum for clarity).
 *
 * @return  Error code: 0 if successful, nonzero otherwise.
 */
uint32 HalGpioSetCallback(MapHalGpioPin_en pin_en, uint32 (*callback_pfn)(HalGpioEdgeType_en edge_en));


#endif /* HAL_GPIO_H_ */
