Naze32 clone with Frysky receiver
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

DigitalIn.h 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_DIGITALIN_H
  17. #define MBED_DIGITALIN_H
  18. #include "platform.h"
  19. #include "gpio_api.h"
  20. namespace mbed {
  21. /** A digital input, used for reading the state of a pin
  22. *
  23. * Example:
  24. * @code
  25. * // Flash an LED while a DigitalIn is true
  26. *
  27. * #include "mbed.h"
  28. *
  29. * DigitalIn enable(p5);
  30. * DigitalOut led(LED1);
  31. *
  32. * int main() {
  33. * while(1) {
  34. * if(enable) {
  35. * led = !led;
  36. * }
  37. * wait(0.25);
  38. * }
  39. * }
  40. * @endcode
  41. */
  42. class DigitalIn {
  43. public:
  44. /** Create a DigitalIn connected to the specified pin
  45. *
  46. * @param pin DigitalIn pin to connect to
  47. */
  48. DigitalIn(PinName pin) : gpio() {
  49. gpio_init_in(&gpio, pin);
  50. }
  51. /** Create a DigitalIn connected to the specified pin
  52. *
  53. * @param pin DigitalIn pin to connect to
  54. * @param mode the initial mode of the pin
  55. */
  56. DigitalIn(PinName pin, PinMode mode) : gpio() {
  57. gpio_init_in_ex(&gpio, pin, mode);
  58. }
  59. /** Read the input, represented as 0 or 1 (int)
  60. *
  61. * @returns
  62. * An integer representing the state of the input pin,
  63. * 0 for logical 0, 1 for logical 1
  64. */
  65. int read() {
  66. return gpio_read(&gpio);
  67. }
  68. /** Set the input pin mode
  69. *
  70. * @param mode PullUp, PullDown, PullNone, OpenDrain
  71. */
  72. void mode(PinMode pull) {
  73. gpio_mode(&gpio, pull);
  74. }
  75. /** Return the output setting, represented as 0 or 1 (int)
  76. *
  77. * @returns
  78. * Non zero value if pin is connected to uc GPIO
  79. * 0 if gpio object was initialized with NC
  80. */
  81. int is_connected() {
  82. return gpio_is_connected(&gpio);
  83. }
  84. #ifdef MBED_OPERATORS
  85. /** An operator shorthand for read()
  86. */
  87. operator int() {
  88. return read();
  89. }
  90. #endif
  91. protected:
  92. gpio_t gpio;
  93. };
  94. } // namespace mbed
  95. #endif