1
0

lpc_gpio.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /**********************************************************************
  2. * $Id$ lpc_gpio.h 2011-06-02
  3. *//**
  4. * @file lpc_gpio.h
  5. * @brief Contains all macro definitions and function prototypes
  6. * support for GPIO firmware library on LPC
  7. * @version 1.0
  8. * @date 02. June. 2011
  9. * @author NXP MCU SW Application Team
  10. *
  11. * Copyright(C) 2011, NXP Semiconductor
  12. * All rights reserved.
  13. *
  14. ***********************************************************************
  15. * Software that is described herein is for illustrative purposes only
  16. * which provides customers with programming information regarding the
  17. * products. This software is supplied "AS IS" without any warranties.
  18. * NXP Semiconductors assumes no responsibility or liability for the
  19. * use of the software, conveys no license or title under any patent,
  20. * copyright, or mask work right to the product. NXP Semiconductors
  21. * reserves the right to make changes in the software without
  22. * notification. NXP Semiconductors also make no representation or
  23. * warranty that such application will be suitable for the specified
  24. * use without further testing or modification.
  25. * Permission to use, copy, modify, and distribute this software and its
  26. * documentation is hereby granted, under NXP Semiconductors'
  27. * relevant copyright in the software, without fee, provided that it
  28. * is used in conjunction with NXP Semiconductors microcontrollers. This
  29. * copyright, permission, and disclaimer notice must appear in all copies of
  30. * this code.
  31. **********************************************************************/
  32. /* Peripheral group ----------------------------------------------------------- */
  33. /** @defgroup GPIO GPIO (General Purpose Input/Output)
  34. * @ingroup LPC_CMSIS_FwLib_Drivers
  35. * @{
  36. */
  37. #ifndef __LPC_GPIO_H_
  38. #define __LPC_GPIO_H_
  39. /* Includes ------------------------------------------------------------------- */
  40. #include "LPC407x_8x_177x_8x.h"
  41. #include "lpc_types.h"
  42. #ifdef __cplusplus
  43. extern "C"
  44. {
  45. #endif
  46. /* Public Macros -------------------------------------------------------------- */
  47. /** @defgroup GPIO_Public_Macros GPIO Public Macros
  48. * @{
  49. */
  50. #define GPIO_DIRECTION_INPUT (0)
  51. #define GPIO_DIRECTION_OUTPUT (1)
  52. /** Fast GPIO port 0 byte accessible definition */
  53. #define GPIO0_Byte ((GPIO_Byte_TypeDef *)(LPC_GPIO0_BASE))
  54. /** Fast GPIO port 1 byte accessible definition */
  55. #define GPIO1_Byte ((GPIO_Byte_TypeDef *)(LPC_GPIO1_BASE))
  56. /** Fast GPIO port 2 byte accessible definition */
  57. #define GPIO2_Byte ((GPIO_Byte_TypeDef *)(LPC_GPIO2_BASE))
  58. /** Fast GPIO port 3 byte accessible definition */
  59. #define GPIO3_Byte ((GPIO_Byte_TypeDef *)(LPC_GPIO3_BASE))
  60. /** Fast GPIO port 4 byte accessible definition */
  61. #define GPIO4_Byte ((GPIO_Byte_TypeDef *)(LPC_GPIO4_BASE))
  62. /** Fast GPIO port 4 byte accessible definition */
  63. #define GPIO5_Byte ((GPIO_Byte_TypeDef *)(LPC_GPIO5_BASE))
  64. /** Fast GPIO port 0 half-word accessible definition */
  65. #define GPIO0_HalfWord ((GPIO_HalfWord_TypeDef *)(LPC_GPIO0_BASE))
  66. /** Fast GPIO port 1 half-word accessible definition */
  67. #define GPIO1_HalfWord ((GPIO_HalfWord_TypeDef *)(LPC_GPIO1_BASE))
  68. /** Fast GPIO port 2 half-word accessible definition */
  69. #define GPIO2_HalfWord ((GPIO_HalfWord_TypeDef *)(LPC_GPIO2_BASE))
  70. /** Fast GPIO port 3 half-word accessible definition */
  71. #define GPIO3_HalfWord ((GPIO_HalfWord_TypeDef *)(LPC_GPIO3_BASE))
  72. /** Fast GPIO port 4 half-word accessible definition */
  73. #define GPIO4_HalfWord ((GPIO_HalfWord_TypeDef *)(LPC_GPIO4_BASE))
  74. /** Fast GPIO port 4 half-word accessible definition */
  75. #define GPIO5_HalfWord ((GPIO_HalfWord_TypeDef *)(LPC_GPIO5_BASE))
  76. /**
  77. * @}
  78. */
  79. /* Public Types --------------------------------------------------------------- */
  80. /** @defgroup GPIO_Public_Types GPIO Public Types
  81. * @{
  82. */
  83. /**
  84. * @brief Fast GPIO port byte type definition
  85. */
  86. typedef struct {
  87. __IO uint8_t FIODIR[4]; /**< FIO direction register in byte-align */
  88. uint32_t RESERVED0[3]; /**< Reserved */
  89. __IO uint8_t FIOMASK[4]; /**< FIO mask register in byte-align */
  90. __IO uint8_t FIOPIN[4]; /**< FIO pin register in byte align */
  91. __IO uint8_t FIOSET[4]; /**< FIO set register in byte-align */
  92. __O uint8_t FIOCLR[4]; /**< FIO clear register in byte-align */
  93. } GPIO_Byte_TypeDef;
  94. /**
  95. * @brief Fast GPIO port half-word type definition
  96. */
  97. typedef struct {
  98. __IO uint16_t FIODIRL; /**< FIO direction register lower halfword part */
  99. __IO uint16_t FIODIRU; /**< FIO direction register upper halfword part */
  100. uint32_t RESERVED0[3]; /**< Reserved */
  101. __IO uint16_t FIOMASKL; /**< FIO mask register lower halfword part */
  102. __IO uint16_t FIOMASKU; /**< FIO mask register upper halfword part */
  103. __IO uint16_t FIOPINL; /**< FIO pin register lower halfword part */
  104. __IO uint16_t FIOPINU; /**< FIO pin register upper halfword part */
  105. __IO uint16_t FIOSETL; /**< FIO set register lower halfword part */
  106. __IO uint16_t FIOSETU; /**< FIO set register upper halfword part */
  107. __O uint16_t FIOCLRL; /**< FIO clear register lower halfword part */
  108. __O uint16_t FIOCLRU; /**< FIO clear register upper halfword part */
  109. } GPIO_HalfWord_TypeDef;
  110. /**
  111. * @}
  112. */
  113. /* Public Functions ----------------------------------------------------------- */
  114. /** @defgroup GPIO_Public_Functions GPIO Public Functions
  115. * @{
  116. */
  117. /* GPIO style ------------------------------- */
  118. void GPIO_Init(void);
  119. void GPIO_Deinit(void);
  120. void GPIO_SetDir(uint8_t portNum, uint32_t bitValue, uint8_t dir);
  121. void GPIO_SetValue(uint8_t portNum, uint32_t bitValue);
  122. void GPIO_ClearValue(uint8_t portNum, uint32_t bitValue);
  123. void GPIO_OutputValue(uint8_t portNum, uint32_t bitMask, uint8_t value);
  124. uint32_t GPIO_ReadValue(uint8_t portNum);
  125. void GPIO_IntCmd(uint8_t portNum, uint32_t bitValue, uint8_t edgeState);
  126. FunctionalState GPIO_GetIntStatus(uint8_t portNum, uint32_t pinNum, uint8_t edgeState);
  127. void GPIO_ClearInt(uint8_t portNum, uint32_t bitValue);
  128. /* FIO (word-accessible) style ------------------------------- */
  129. void FIO_SetDir(uint8_t portNum, uint32_t bitValue, uint8_t dir);
  130. void FIO_SetValue(uint8_t portNum, uint32_t bitValue);
  131. void FIO_ClearValue(uint8_t portNum, uint32_t bitValue);
  132. uint32_t FIO_ReadValue(uint8_t portNum);
  133. void FIO_SetMask(uint8_t portNum, uint32_t bitValue, uint8_t maskValue);
  134. void FIO_IntCmd(uint8_t portNum, uint32_t bitValue, uint8_t edgeState);
  135. FunctionalState FIO_GetIntStatus(uint8_t portNum, uint32_t pinNum, uint8_t edgeState);
  136. void FIO_ClearInt(uint8_t portNum, uint32_t pinNum);
  137. /* FIO (halfword-accessible) style ------------------------------- */
  138. void FIO_HalfWordSetDir(uint8_t portNum, uint8_t halfwordNum, uint16_t bitValue, uint8_t dir);
  139. void FIO_HalfWordSetMask(uint8_t portNum, uint8_t halfwordNum, uint16_t bitValue, uint8_t maskValue);
  140. void FIO_HalfWordSetValue(uint8_t portNum, uint8_t halfwordNum, uint16_t bitValue);
  141. void FIO_HalfWordClearValue(uint8_t portNum, uint8_t halfwordNum, uint16_t bitValue);
  142. uint16_t FIO_HalfWordReadValue(uint8_t portNum, uint8_t halfwordNum);
  143. /* FIO (byte-accessible) style ------------------------------- */
  144. void FIO_ByteSetDir(uint8_t portNum, uint8_t byteNum, uint8_t bitValue, uint8_t dir);
  145. void FIO_ByteSetMask(uint8_t portNum, uint8_t byteNum, uint8_t bitValue, uint8_t maskValue);
  146. void FIO_ByteSetValue(uint8_t portNum, uint8_t byteNum, uint8_t bitValue);
  147. void FIO_ByteClearValue(uint8_t portNum, uint8_t byteNum, uint8_t bitValue);
  148. uint8_t FIO_ByteReadValue(uint8_t portNum, uint8_t byteNum);
  149. /**
  150. * @}
  151. */
  152. #ifdef __cplusplus
  153. }
  154. #endif
  155. #endif /* __LPC_GPIO_H_ */
  156. /**
  157. * @}
  158. */
  159. /* --------------------------------- End Of File ------------------------------ */