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.

PortOut.h 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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_PORTOUT_H
  17. #define MBED_PORTOUT_H
  18. #include "platform.h"
  19. #if DEVICE_PORTOUT
  20. #include "port_api.h"
  21. namespace mbed {
  22. /** A multiple pin digital out
  23. *
  24. * Example:
  25. * @code
  26. * // Toggle all four LEDs
  27. *
  28. * #include "mbed.h"
  29. *
  30. * // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23
  31. * #define LED_MASK 0x00B40000
  32. *
  33. * PortOut ledport(Port1, LED_MASK);
  34. *
  35. * int main() {
  36. * while(1) {
  37. * ledport = LED_MASK;
  38. * wait(1);
  39. * ledport = 0;
  40. * wait(1);
  41. * }
  42. * }
  43. * @endcode
  44. */
  45. class PortOut {
  46. public:
  47. /** Create an PortOut, connected to the specified port
  48. *
  49. * @param port Port to connect to (Port0-Port5)
  50. * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
  51. */
  52. PortOut(PortName port, int mask = 0xFFFFFFFF) {
  53. port_init(&_port, port, mask, PIN_OUTPUT);
  54. }
  55. /** Write the value to the output port
  56. *
  57. * @param value An integer specifying a bit to write for every corresponding PortOut pin
  58. */
  59. void write(int value) {
  60. port_write(&_port, value);
  61. }
  62. /** Read the value currently output on the port
  63. *
  64. * @returns
  65. * An integer with each bit corresponding to associated PortOut pin setting
  66. */
  67. int read() {
  68. return port_read(&_port);
  69. }
  70. /** A shorthand for write()
  71. */
  72. PortOut& operator= (int value) {
  73. write(value);
  74. return *this;
  75. }
  76. PortOut& operator= (PortOut& rhs) {
  77. write(rhs.read());
  78. return *this;
  79. }
  80. /** A shorthand for read()
  81. */
  82. operator int() {
  83. return read();
  84. }
  85. private:
  86. port_t _port;
  87. };
  88. } // namespace mbed
  89. #endif
  90. #endif