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.

BusOut.h 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_BUSOUT_H
  17. #define MBED_BUSOUT_H
  18. #include "DigitalOut.h"
  19. namespace mbed {
  20. /** A digital output bus, used for setting the state of a collection of pins
  21. */
  22. class BusOut {
  23. public:
  24. /** Create an BusOut, connected to the specified pins
  25. *
  26. * @param p<n> DigitalOut pin to connect to bus bit <n> (p5-p30, NC)
  27. *
  28. * @note
  29. * It is only required to specify as many pin variables as is required
  30. * for the bus; the rest will default to NC (not connected)
  31. */
  32. BusOut(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
  33. PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
  34. PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
  35. PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
  36. BusOut(PinName pins[16]);
  37. virtual ~BusOut();
  38. /** Write the value to the output bus
  39. *
  40. * @param value An integer specifying a bit to write for every corresponding DigitalOut pin
  41. */
  42. void write(int value);
  43. /** Read the value currently output on the bus
  44. *
  45. * @returns
  46. * An integer with each bit corresponding to associated DigitalOut pin setting
  47. */
  48. int read();
  49. /** Binary mask of bus pins connected to actual pins (not NC pins)
  50. * If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
  51. *
  52. * @returns
  53. * Binary mask of connected pins
  54. */
  55. int mask() {
  56. return _nc_mask;
  57. }
  58. #ifdef MBED_OPERATORS
  59. /** A shorthand for write()
  60. */
  61. BusOut& operator= (int v);
  62. BusOut& operator= (BusOut& rhs);
  63. /** Access to particular bit in random-iterator fashion
  64. */
  65. DigitalOut& operator[] (int index);
  66. /** A shorthand for read()
  67. */
  68. operator int();
  69. #endif
  70. protected:
  71. DigitalOut* _pin[16];
  72. /** Mask of bus's NC pins
  73. * If bit[n] is set to 1 - pin is connected
  74. * if bit[n] is cleared - pin is not connected (NC)
  75. */
  76. int _nc_mask;
  77. /* disallow copy constructor and assignment operators */
  78. private:
  79. BusOut(const BusOut&);
  80. BusOut & operator = (const BusOut&);
  81. };
  82. } // namespace mbed
  83. #endif