/************************************************************************************
* @Copyright (c)	  :(C)2020, Qindao ieslab Co., Ltd
* @FileName   		  :hc32_gpio_driver.c
* @Author           :QDIES PLATFORM TEAM
* @Version          :V1.0
* @Date             :2020-07-01
* @Description      :
************************************************************************************/

#ifdef	__cplusplus
extern "C"
{
#endif

#include "UWater_gpio_driver.h"

/*****************************变量定义***************************************/
	

/*********************************************内部接口*************************************************/
void GpioInit(void)
{
		stc_gpio_cfg_t stcGpioCfg;

	  DDL_ZERO_STRUCT(stcGpioCfg);
	  
    stcGpioCfg.enDir = GpioDirOut;    ///< 端口方向配置->输出
    stcGpioCfg.enDrv = GpioDrvL;      ///< 端口驱动能力配置->高驱动能力
    stcGpioCfg.enPu = GpioPuDisable;  ///< 端口上下拉配置->无
    stcGpioCfg.enPd = GpioPdDisable;
    stcGpioCfg.enOD = GpioOdDisable;  ///< 端口开漏输出配置->开漏输出关闭
    stcGpioCfg.enCtrlMode = GpioAHB;  ///< 端口输入/输出值寄存器总线控制模式配置->AHB
    Gpio_Init(EN_IR_PWR_PORT, EN_IR_PWR_PIN, &stcGpioCfg);
}

/*********************************************外部接口*************************************************/
	
/*******************************************************************************************************
  * @brief  Initialize the GPIOx peripheral according to the specified parameters in the GPIO_Init.
  * @param  GPIOx: where x can be (A..H) to select the GPIO peripheral for STM32L4 family
  * @param  GPIO_Init: pointer to a GPIO_InitTypeDef structure that contains
  *         the configuration information for the specified GPIO peripheral.
  * @retval None
  *****************************************************************************************************/
//void MCU_GPIO_Init(GPIO_TypeDef  GPIOx, GPIO_InitTypeDef *GPIO_Init)
//{
//	stc_gpio_cfg_t stcGpioCfg;
//	en_gpio_irqtype_t enIrqType;

//	/* Configure the port pins */
//	if(GPIO_MODE_INPUT == GPIO_Init->Mode)
//	{
//		stcGpioCfg.enDir = GpioDirIn;
//	}
//	else if(GPIO_MODE_RISING == GPIO_Init->Mode)
//	{
//		stcGpioCfg.enDir = GpioDirIn;
//		enIrqType = GpioIrqRising;
//	}
//	else if(GPIO_MODE_FALLING == GPIO_Init->Mode)
//	{
//		stcGpioCfg.enDir = GpioDirIn;
//		enIrqType = GpioIrqFalling;
//	}
//	else if(GPIO_MODE_OUTPUT_OD == GPIO_Init->Mode)
//	{
//		stcGpioCfg.enDir = GpioDirOut;
//		stcGpioCfg.enOD = GpioOdEnable;
//	}
//	else if(GPIO_MODE_OUTPUT_PP == GPIO_Init->Mode)
//	{
//		stcGpioCfg.enDir = GpioDirOut;
//		stcGpioCfg.enOD = GpioOdDisable;
//	}

//	if(GPIO_NOPULL == GPIO_Init->Pull)
//	{
//		stcGpioCfg.enPu = GpioPuDisable;
//		stcGpioCfg.enPd = GpioPdDisable;
//	}
//	else if(GPIO_PULLUP == GPIO_Init->Pull)
//	{
//		stcGpioCfg.enPu = GpioPuEnable;
//		stcGpioCfg.enPd = GpioPdDisable;
//	}
//	else if(GPIO_PULLDOWN == GPIO_Init->Pull)
//	{
//		stcGpioCfg.enPu = GpioPuDisable;
//		stcGpioCfg.enPd = GpioPdEnable;
//	}

//	if(GpioDrvLow == GPIO_Init->Drv)
//	{
//		stcGpioCfg.enDrv = GpioDrvL;
//	}
//	else if(GpioDrvHigh == GPIO_Init->Drv)
//	{
//		stcGpioCfg.enDrv = GpioDrvH;
//	}

//	///< 打开GPIO外设时钟门控
//	MCU_GPIO_CLK_ENABLE(); 

//	///< GPIO IO LED端口初始化
//	Gpio_Init((GPIO_TypeDef)GPIOx, (GPIO_PIN_t)GPIO_Init->Pin, &stcGpioCfg);

//	if(GPIO_MODE_ANALOG == GPIO_Init->Mode)
//	{
//		Gpio_SetAnalogMode((GPIO_TypeDef)GPIOx, (GPIO_PIN_t)GPIO_Init->Pin);
//	}
//	else if((GPIO_MODE_RISING == GPIO_Init->Mode)||(GPIO_MODE_RISING == GPIO_Init->Mode))
//	{
//		Gpio_EnableIrq((GPIO_TypeDef)GPIOx, (GPIO_PIN_t)GPIO_Init->Pin, enIrqType);
//		
//		if(GPIOx == GpioA)
//		{
//				EnableNvic(PORTA_IRQn, IrqLevel3, TRUE);
//		}
//		else if(GPIOx == GpioB)
//		{
//				EnableNvic(PORTB_IRQn, IrqLevel3, TRUE);
//		}
//		else if((GPIOx == GpioC)||(GPIOx == GpioE))
//		{
//				EnableNvic(PORTC_E_IRQn, IrqLevel3, TRUE);
//		}
//		else if((GPIOx == GpioD)||(GPIOx == GpioF))
//		{
//				EnableNvic(PORTD_F_IRQn, IrqLevel3, TRUE);
//		}
//	}
//	
//}

/*******************************************************************************************************
  * @brief  De-initialize the GPIOx peripheral registers to their default reset values.
  * @param  GPIOx: where x can be (A..H) to select the GPIO peripheral for STM32L4 family
  * @param  GPIO_Pin: specifies the port bit to be written.
  *         This parameter can be one of GPIO_PIN_x where x can be (0..15).
  * @retval None
  *****************************************************************************************************/
//void MCU_GPIO_DeInit(GPIO_TypeDef GPIOx, GPIO_PIN_t GPIO_Pin)
//{
//  /* Configure the port pins */
//  
//}

/**
  * @brief  Read the specified input port pin.
  * @param  GPIOx: where x can be (A..H) to select the GPIO peripheral for STM32L4 family
  * @param  GPIO_Pin: specifies the port bit to read.
  *         This parameter can be GPIO_PIN_x where x can be (0..15).
  * @retval The input port pin value.
  */
GPIO_PinState GPIO_ReadPin(GPIO_TypeDef GPIOx, GPIO_PIN_t GPIO_Pin)
{
  return (GPIO_PinState)Gpio_GetInputIO(GPIOx, GPIO_Pin);
}

/*******************************************************************************************************
  * @brief  Set or clear the selected data port bit.
  *
  * @note   This function uses GPIOx_BSRR and GPIOx_BRR registers to allow atomic read/modify
  *         accesses. In this way, there is no risk of an IRQ occurring between
  *         the read and the modify access.
  *
  * @param  GPIOx: where x can be (A..H) to select the GPIO peripheral for STM32L4 family
  * @param  GPIO_Pin: specifies the port bit to be written.
  *         This parameter can be one of GPIO_PIN_x where x can be (0..15).
  * @param  PinState: specifies the value to be written to the selected bit.
  *         This parameter can be one of the GPIO_PinState enum values:
  *            @arg GPIO_PIN_RESET: to clear the port pin
  *            @arg GPIO_PIN_SET: to set the port pin
  * @retval None
  *****************************************************************************************************/
void GPIO_WritePin(GPIO_TypeDef GPIOx, GPIO_PIN_t GPIO_Pin, GPIO_PinState PinState)
{
   Gpio_WriteOutputIO(GPIOx, GPIO_Pin, PinState);
}

/*******************************************************************************************************
  * @brief  Toggle the specified GPIO pin.
  * @param  GPIOx: where x can be (A..H) to select the GPIO peripheral for STM32L4 family
  * @param  GPIO_Pin: specifies the pin to be toggled.
  * @retval None
  *****************************************************************************************************/
void GPIO_TogglePin(GPIO_TypeDef GPIOx, GPIO_PIN_t GPIO_Pin)
{
  
}

#ifdef	__cplusplus
}
#endif
