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.

DigitalOut.h 2.8KB

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