text: /**************************************************************************//**
   * @file     gpio.c
   * @version  V3.00
   * $Revision: 7 $
   * $Date: 16/10/25 4:25p $
   * @brief    NUC126 series General Purpose I/O (GPIO) driver source file
   *
   * @note
   * Copyright (C) 2016 Nuvoton Technology Corp. All rights reserved.
  *****************************************************************************/
  #include "NUC126.h"
  
  
  /** @addtogroup Standard_Driver Standard Driver
    @{
  */
  
  /** @addtogroup GPIO_Driver GPIO Driver
    @{
  */
  
  /** @addtogroup GPIO_EXPORTED_FUNCTIONS GPIO Exported Functions
    @{
  */
  
  /**
   * @brief       Set GPIO operation mode
   *
   * @param[in]   port        GPIO port. It could be PA, PB, PC, PD, PE or PF.
   * @param[in]   u32PinMask  The single or multiple pins of specified GPIO port. \n
   *                          It could be BIT0 ~ BIT15 for PA, PB, PC and PD. \n
   *                          It could be BIT0 ~ BIT13 for PE. \n
   *                          It could be BIT0 ~ BIT7 for PF.
   * @param[in]   u32Mode     Operation mode.  It could be
   *                          - \ref GPIO_MODE_INPUT
   *                          - \ref GPIO_MODE_OUTPUT
   *                          - \ref GPIO_MODE_OPEN_DRAIN
   *                          - \ref GPIO_MODE_QUASI
   *
   * @return      None
   *
   * @details     This function is used to set specified GPIO operation mode.
   */
  void GPIO_SetMode(GPIO_T *port, uint32_t u32PinMask, uint32_t u32Mode)
  {
      uint32_t i;
  
      for(i = 0; i < GPIO_PIN_MAX; i++)
      {
          if(u32PinMask & (1 << i))
          {
              port->MODE = (port->MODE & ~(0x3 << (i << 1))) | (u32Mode << (i << 1));
          }
      }
  }
  
  /**
   * @brief       Enable GPIO interrupt
   *
   * @param[in]   port            GPIO port. It could be PA, PB, PC, PD, PE or PF.
   * @param[in]   u32Pin          The pin of specified GPIO port. \n
   *                              It could be 0 ~ 15 for PA, PB, PC and PD GPIO port. \n
   *                              It could be 0 ~ 13 for PE GPIO port. \n
   *                              It could be 0 ~ 7 for PF GPIO port.
   * @param[in]   u32IntAttribs   The interrupt attribute of specified GPIO pin. It could be
   *                            - \ref GPIO_INT_RISING
   *                            - \ref GPIO_INT_FALLING
   *                            - \ref GPIO_INT_BOTH_EDGE
   *                            - \ref GPIO_INT_HIGH
   *                            - \ref GPIO_INT_LOW
   *
   * @return      None
   *
   * @details     This function is used to enable specified GPIO pin interrupt.
   */
  void GPIO_EnableInt(GPIO_T *port, uint32_t u32Pin, uint32_t u32IntAttribs)
  {
      /* Configure interrupt mode of specified pin */
      port->INTTYPE |= (((u32IntAttribs >> 24) & 0xFFUL) << u32Pin);
  
      /* Enable interrupt function of specified pin */
      port->INTEN |= ((u32IntAttribs & 0xFFFFFFUL) << u32Pin);
  }
  
  
  /**
   * @brief       Disable GPIO interrupt
   *
   * @param[in]   port        GPIO port. It could be PA, PB, PC, PD, PE or PF.
   * @param[in]   u32Pin      The pin of specified GPIO port. \n
   *                          It could be 0 ~ 15 for PA, PB, PC and PD GPIO port. \n
   *                          It could be 0 ~ 13 for PE GPIO port. \n
   *                          It could be 0 ~ 7 for PF GPIO port.
   *
   * @return      None
   *
   * @details     This function is used to enable specified GPIO pin interrupt.
   */
  void GPIO_DisableInt(GPIO_T *port, uint32_t u32Pin)
  {
      /* Configure interrupt mode of specified pin */
      port->INTTYPE &= ~(1UL << u32Pin);
  
      /* Disable interrupt function of specified pin */
      port->INTEN &= ~((0x00010001UL) << u32Pin);
  }
  
  
  /*@}*/ /* end of group GPIO_EXPORTED_FUNCTIONS */
  
  /*@}*/ /* end of group GPIO_Driver */
  
  /*@}*/ /* end of group Standard_Driver */
  
  /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
  