gpio.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**************************************************************************//**
  2. * @file gpio.c
  3. * @version V3.00
  4. * $Revision: 4 $
  5. * $Date: 14/01/28 10:49a $
  6. * @brief M051 series GPIO driver source file
  7. *
  8. * @note
  9. * Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved.
  10. *****************************************************************************/
  11. #include "M051Series.h"
  12. /** @addtogroup M051_Device_Driver M051 Device Driver
  13. @{
  14. */
  15. /** @addtogroup M051_GPIO_Driver GPIO Driver
  16. @{
  17. */
  18. /** @addtogroup M051_GPIO_EXPORTED_FUNCTIONS GPIO Exported Functions
  19. @{
  20. */
  21. /**
  22. * @brief Set GPIO operation mode
  23. *
  24. * @param[in] port GPIO port. It could be P0, P1, P2, P3 or P4.
  25. * @param[in] u32PinMask The single or multiple pins of specified GPIO port. It could be BIT0 ~ BIT7.
  26. * @param[in] u32Mode Operation mode. GPIO_PMD_INPUT, GPIO_PMD_OUTPUT, GPIO_PMD_OPEN_DRAIN, GPIO_PMD_QUASI
  27. *
  28. * @return None
  29. *
  30. * @details This function is used to set specified GPIO operation mode.
  31. */
  32. void GPIO_SetMode(GPIO_T *port, uint32_t u32PinMask, uint32_t u32Mode)
  33. {
  34. uint32_t i;
  35. for(i = 0; i < GPIO_PIN_MAX; i++)
  36. {
  37. if(u32PinMask & (1 << i))
  38. {
  39. port->PMD = (port->PMD & ~(0x3 << (i << 1))) | (u32Mode << (i << 1));
  40. }
  41. }
  42. }
  43. /**
  44. * @brief Enable GPIO interrupt
  45. *
  46. * @param[in] port GPIO port. It could be P0, P1, P2, P3 or P4.
  47. * @param[in] u32Pin The pin of specified GPIO port. It could be 0 ~ 7.
  48. * @param[in] u32IntAttribs The interrupt attribute of specified GPIO pin. It could be \n
  49. * GPIO_INT_RISING, GPIO_INT_FALLING, GPIO_INT_BOTH_EDGE, GPIO_INT_HIGH, GPIO_INT_LOW.
  50. *
  51. * @return None
  52. *
  53. * @details This function is used to enable specified GPIO pin interrupt.
  54. */
  55. void GPIO_EnableInt(GPIO_T *port, uint32_t u32Pin, uint32_t u32IntAttribs)
  56. {
  57. port->IMD |= (((u32IntAttribs >> 24) & 0xFFUL) << u32Pin);
  58. port->IEN |= ((u32IntAttribs & 0xFFFFFFUL) << u32Pin);
  59. }
  60. /**
  61. * @brief Disable GPIO interrupt
  62. *
  63. * @param[in] port GPIO port. It could be P0, P1, P2, P3 or P4.
  64. * @param[in] u32Pin The pin of specified GPIO port. It could be 0 ~ 7.
  65. *
  66. * @return None
  67. *
  68. * @details This function is used to enable specified GPIO pin interrupt.
  69. */
  70. void GPIO_DisableInt(GPIO_T *port, uint32_t u32Pin)
  71. {
  72. port->IMD &= ~(1UL << u32Pin);
  73. port->IEN &= ~((0x00010001UL) << u32Pin);
  74. }
  75. /*@}*/ /* end of group M051_GPIO_EXPORTED_FUNCTIONS */
  76. /*@}*/ /* end of group M051_GPIO_Driver */
  77. /*@}*/ /* end of group M051_Device_Driver */
  78. /*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/