/**
 * @file	   map_hal.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	   Mapping of the hardware interfaces.
 *
 */

#ifndef MAP_HAL_H_
#define MAP_HAL_H_

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

/* CubeMX */
#include "gpio.h"
#include "tim.h"
#include "adc.h"
#include "fdcan.h"
#include "i2c.h"

/******************************************************************************
 * Global define
 ******************************************************************************/
#define MOTOR_PWM_CHANNEL		TIM_CHANNEL_1

/******************************************************************************
 * Type declarations
 ******************************************************************************/
typedef enum
{
	MAP_HAL_PMP_ENABLE,
	MAP_HAL_GPIO_NUMBER
} MapHalGpioPin_en;

typedef enum
{
	MAP_HAL_TIMER_RTOS,
	MAP_HAL_TIMER_FILTER,
	MAP_HAL_TIMER_NUMBER
} MapHalTimerModule_en;

typedef enum
{
	MAP_HAL_ADC_1,
	MAP_HAL_ADC_NUMBER
}MapHalAdcModule_en;

typedef enum
{
	MAP_HAL_GRUNDFOS_PMP_I2C_HANDLE,
	MAP_HAL_I2C_NUMBER
}MapHalI2cModule_en;
/******************************************************************************
 * Extern Function Declarations
 ******************************************************************************/
/**
 * @brief   Maps a HAL GPIO pin to the corresponding STM32 port and pin.
 *
 * @param   pin_en          HAL GPIO pin to be mapped.
 * @param   targetPort_ppst Pointer to the corresponding STM32 port.
 * @param   targetPin_pu16  Pointer to the corresponding STM32 pin.
 *
 * @return  Error code: 0 if successful, nonzero otherwise.
 */
uint32 MapHalGpio(MapHalGpioPin_en pin_en, uint16* targetPin_pu16, GPIO_TypeDef** targetPort_ppst);

/**
 * @brief   Maps a specific pin callback to the corresponding STM32 pin.
 *
 * @param   targetPin_u16   STM32 pin.
 * @param   pin_pen         Pointer to the enumerator representing the HAL pin.
 *
 * @return  Error code: 0 if successful, nonzero otherwise.
 */
uint32 MapHalGpioCallback(uint16 targetPin_u16, MapHalGpioPin_en* pin_pen);

/**
 * @brief   Maps a HAL timer module to its corresponding STM32 timer module.
 *
 * @param[in]   halModule_en     HAL timer module (e.g., HAL_TIMER_1).
 * @param[out]  targetModule_ppst Pointer to the corresponding STM32 timer module (e.g., htim1).
 *
 * @return  Error code:
 *          - HAL_TIM_LOG_LOCATION_4_ERROR_INVALID_ARGUMENT if the mapping fails.
 *          - LOG_ERROR_NONE if successful.
 */
uint32 MapHalTimerModule(MapHalTimerModule_en timer_en, TIM_HandleTypeDef** targetModule_ppst);

/**
 * @brief   Retrieves the HAL timer module associated with a given STM32 timer module.
 *
 * @param[in]   targetModule_ppst Pointer to the STM32 timer module (e.g., htim1).
 * @param[out]  timerModule_pen   Pointer to store the corresponding HAL module (e.g., HAL_TIMER_1).
 *
 * @return  Error code:
 *          - HAL_TIM_LOG_LOCATION_4_ERROR_INVALID_ARGUMENT if the mapping fails.
 *          - LOG_ERROR_NONE if successful.
 */
uint32 MapHalTimerCallback(TIM_HandleTypeDef** targetModule_ppst, MapHalTimerModule_en* timer_pen);

/**
 * @brief   Maps a HAL ADC pin to the corresponding STM32 port and pin.
 *
 * @param   pin_en          	HAL GPIO pin to be mapped.
 * @param   targetModule_ppst 	Pointer to the corresponding STM32 ADC module.
 *
 * @return  Error code: 0 if successful, nonzero otherwise.
 */
uint32 MapHalAdcModule(MapHalAdcModule_en pin_en, ADC_HandleTypeDef** targetModule_ppst);

/**
 * @brief   Maps a specific pin callback to the corresponding STM32 pin.
 *
 * @param   targetModule_pst   STM32 pin.
 * @param   adcModule_en       Pointer to the enumerator representing the HAL pin.
 *
 * @return  Error code: 0 if successful, nonzero otherwise.
 */
uint32 MapHalAdcCallback(ADC_HandleTypeDef *targetModule_pst, MapHalAdcModule_en *adcModule_en);

/**
 * @brief   Maps a HAL I2C pin to the corresponding STM32 port and pin.
 *
 * @param   pin_en          	HAL GPIO pin to be mapped.
 * @param   targetModule_ppst 	Pointer to the corresponding STM32 ADC module.
 *
 * @return  Error code: 0 if successful, nonzero otherwise.
 */
uint32 MapHalI2cModule(MapHalI2cModule_en module_en, I2C_HandleTypeDef ** targetModule_ppst);

#endif /* MAP_HAL_H_ */
