Naze32 clone with Frysky receiver
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

InterruptIn.h 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* mbed Microcontroller Library
  2. * Copyright (c) 2006-2013 ARM Limited
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MBED_INTERRUPTIN_H
  17. #define MBED_INTERRUPTIN_H
  18. #include "platform.h"
  19. #if DEVICE_INTERRUPTIN
  20. #include "gpio_api.h"
  21. #include "gpio_irq_api.h"
  22. #include "FunctionPointer.h"
  23. namespace mbed {
  24. /** A digital interrupt input, used to call a function on a rising or falling edge
  25. *
  26. * Example:
  27. * @code
  28. * // Flash an LED while waiting for events
  29. *
  30. * #include "mbed.h"
  31. *
  32. * InterruptIn event(p16);
  33. * DigitalOut led(LED1);
  34. *
  35. * void trigger() {
  36. * printf("triggered!\n");
  37. * }
  38. *
  39. * int main() {
  40. * event.rise(&trigger);
  41. * while(1) {
  42. * led = !led;
  43. * wait(0.25);
  44. * }
  45. * }
  46. * @endcode
  47. */
  48. class InterruptIn {
  49. public:
  50. /** Create an InterruptIn connected to the specified pin
  51. *
  52. * @param pin InterruptIn pin to connect to
  53. * @param name (optional) A string to identify the object
  54. */
  55. InterruptIn(PinName pin);
  56. virtual ~InterruptIn();
  57. int read();
  58. #ifdef MBED_OPERATORS
  59. operator int();
  60. #endif
  61. /** Attach a function to call when a rising edge occurs on the input
  62. *
  63. * @param fptr A pointer to a void function, or 0 to set as none
  64. */
  65. void rise(void (*fptr)(void));
  66. /** Attach a member function to call when a rising edge occurs on the input
  67. *
  68. * @param tptr pointer to the object to call the member function on
  69. * @param mptr pointer to the member function to be called
  70. */
  71. template<typename T>
  72. void rise(T* tptr, void (T::*mptr)(void)) {
  73. _rise.attach(tptr, mptr);
  74. gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
  75. }
  76. /** Attach a function to call when a falling edge occurs on the input
  77. *
  78. * @param fptr A pointer to a void function, or 0 to set as none
  79. */
  80. void fall(void (*fptr)(void));
  81. /** Attach a member function to call when a falling edge occurs on the input
  82. *
  83. * @param tptr pointer to the object to call the member function on
  84. * @param mptr pointer to the member function to be called
  85. */
  86. template<typename T>
  87. void fall(T* tptr, void (T::*mptr)(void)) {
  88. _fall.attach(tptr, mptr);
  89. gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
  90. }
  91. /** Set the input pin mode
  92. *
  93. * @param mode PullUp, PullDown, PullNone
  94. */
  95. void mode(PinMode pull);
  96. /** Enable IRQ. This method depends on hw implementation, might enable one
  97. * port interrupts. For further information, check gpio_irq_enable().
  98. */
  99. void enable_irq();
  100. /** Disable IRQ. This method depends on hw implementation, might disable one
  101. * port interrupts. For further information, check gpio_irq_disable().
  102. */
  103. void disable_irq();
  104. static void _irq_handler(uint32_t id, gpio_irq_event event);
  105. protected:
  106. gpio_t gpio;
  107. gpio_irq_t gpio_irq;
  108. FunctionPointer _rise;
  109. FunctionPointer _fall;
  110. };
  111. } // namespace mbed
  112. #endif
  113. #endif