gpio_def.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #ifndef _DEV_GPIO_DEF_H_
  2. #define _DEV_GPIO_DEF_H_
  3. /*!
  4. * Copyright (C) 2007 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*!
  35. * \file dev/gpio.h
  36. * \brief General purpose I/O.
  37. *
  38. * \verbatim
  39. * $Id: gpio.h 2560 2009-03-18 04:00:06Z thiagocorrea $
  40. * \endverbatim
  41. */
  42. #define NUTGPIO_PORT 0
  43. #define NUTGPIO_PORTA 1
  44. #define NUTGPIO_PORTB 2
  45. #define NUTGPIO_PORTC 3
  46. #define NUTGPIO_PORTD 4
  47. #define NUTGPIO_PORTE 5
  48. #define NUTGPIO_PORTF 6
  49. #define NUTGPIO_PORTG 7
  50. #define NUTGPIO_PORTH 8
  51. #define NUTGPIO_PORTI 9
  52. #define NUTGPIO_PORTJ 10
  53. #define NUTGPIO_PORTK 11
  54. #define NUTGPIO_PORTL 12
  55. #define NUTGPIO_EXTINT0 1
  56. #define NUTGPIO_EXTINT1 2
  57. #define NUTGPIO_EXTINT2 3
  58. #define NUTGPIO_EXTINT3 4
  59. #define NUTGPIO_EXTINT4 5
  60. #define NUTGPIO_EXTINT5 6
  61. #define NUTGPIO_EXTINT6 7
  62. #define NUTGPIO_EXTINT7 8
  63. #define NUTGPIO_EXTFIQ0 -1
  64. /*!
  65. * \brief GPIO input.
  66. *
  67. * Will configure the pin as input. This is the default state, when no other
  68. * config option is given.
  69. */
  70. #define GPIO_CFG_INPUT 0x00000000
  71. /*!
  72. * \brief GPIO disabled.
  73. *
  74. * Will activate the pins alternate function if set. This may not work
  75. * on all platforms.
  76. */
  77. #define GPIO_CFG_DISABLED 0x00000001
  78. /*!
  79. * \brief GPIO output direction enabled.
  80. *
  81. * If set, the pin is configured as an output. Otherwise it is in
  82. * input mode or z-state.
  83. */
  84. #define GPIO_CFG_OUTPUT 0x00000002
  85. /*!
  86. * \brief GPIO pull-up enabled.
  87. */
  88. #define GPIO_CFG_PULLUP 0x00000004
  89. /*!
  90. * \brief GPIO open drain output feature enabled.
  91. *
  92. * If not set, the output will use push pull mode.
  93. */
  94. #define GPIO_CFG_MULTIDRIVE 0x00000008
  95. /*!
  96. * \brief GPIO input glitch filter enabled.
  97. */
  98. #define GPIO_CFG_DEBOUNCE 0x00000010
  99. /*!
  100. * \brief GPIO Peripheral 0 mux.
  101. * Switch pin function to peripheral 0.
  102. */
  103. #define GPIO_CFG_PERIPHERAL0 0x00000020
  104. /*!
  105. * \brief GPIO Peripheral 1 mux.
  106. * Switch pin function to peripheral 1.
  107. */
  108. #define GPIO_CFG_PERIPHERAL1 0x00000040
  109. /*!
  110. * \brief GPIO Peripheral 2 mux.
  111. * Switch pin function to peripheral 2.
  112. */
  113. #define GPIO_CFG_PERIPHERAL2 0x00000080
  114. /*!
  115. * \brief GPIO Peripheral 3 mux.
  116. * Switch pin function to peripheral 3.
  117. */
  118. #define GPIO_CFG_PERIPHERAL3 0x00000100
  119. /*!
  120. * \brief GPIO starts with output high.
  121. */
  122. #define GPIO_CFG_INIT_HIGH 0x00000200
  123. /*!
  124. * \brief GPIO starts with output low.
  125. */
  126. #define GPIO_CFG_INIT_LOW 0x00000400
  127. typedef struct {
  128. void (*iov_handler) (void *);
  129. void *iov_arg;
  130. } GPIO_VECTOR;
  131. typedef struct {
  132. IRQ_HANDLER *ios_sig;
  133. void (*ios_handler) (void *);
  134. int (*ios_ctl) (int cmd, void *param, int bit);
  135. GPIO_VECTOR *ios_vector;
  136. } GPIO_SIGNAL;
  137. #if defined(PIO_ISR)
  138. extern GPIO_SIGNAL sig_GPIO;
  139. #endif
  140. #if defined(PIOA_ISR)
  141. extern GPIO_SIGNAL sig_GPIO1;
  142. #endif
  143. #if defined(PIOB_ISR)
  144. extern GPIO_SIGNAL sig_GPIO2;
  145. #endif
  146. #if defined(PIOC_ISR)
  147. extern GPIO_SIGNAL sig_GPIO3;
  148. #endif
  149. extern uint32_t GpioPinConfigGet(int bank, int bit);
  150. extern int GpioPinConfigSet(int bank, int bit, uint32_t flags);
  151. extern int GpioPortConfigSet(int bank, unsigned int mask, uint32_t flags);
  152. extern int GpioPinGet(int bank, int bit);
  153. extern void GpioPinSet(int bank, int bit, int value);
  154. extern void GpioPinSetLow(int bank, int bit);
  155. extern void GpioPinSetHigh(int bank, int bit);
  156. #define GpioPinRelease(bank, bit)
  157. #define GpioPinDrive(bank, bit)
  158. extern unsigned int GpioPortGet(int bank);
  159. extern void GpioPortSet(int bank, unsigned int value);
  160. extern void GpioPortSetLow(int bank, unsigned int mask);
  161. extern void GpioPortSetHigh(int bank, unsigned int mask);
  162. extern int GpioRegisterIrqHandler(GPIO_SIGNAL * sig, int bit, void (*handler) (void *), void *arg);
  163. extern int GpioIrqEnable(GPIO_SIGNAL * sig, int bit);
  164. extern int GpioIrqDisable(GPIO_SIGNAL * sig, int bit);
  165. #endif /* _DEV_GPIO_DEF_H_ */