Naze32 clone with Frysky receiver
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BusInOut.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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_BUSINOUT_H
  17. #define MBED_BUSINOUT_H
  18. #include "DigitalInOut.h"
  19. namespace mbed {
  20. /** A digital input output bus, used for setting the state of a collection of pins
  21. */
  22. class BusInOut {
  23. public:
  24. /** Create an BusInOut, connected to the specified pins
  25. *
  26. * @param p<n> DigitalInOut pin to connect to bus bit p<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. BusInOut(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. BusInOut(PinName pins[16]);
  37. virtual ~BusInOut();
  38. /* Group: Access Methods */
  39. /** Write the value to the output bus
  40. *
  41. * @param value An integer specifying a bit to write for every corresponding DigitalInOut pin
  42. */
  43. void write(int value);
  44. /** Read the value currently output on the bus
  45. *
  46. * @returns
  47. * An integer with each bit corresponding to associated DigitalInOut pin setting
  48. */
  49. int read();
  50. /** Set as an output
  51. */
  52. void output();
  53. /** Set as an input
  54. */
  55. void input();
  56. /** Set the input pin mode
  57. *
  58. * @param mode PullUp, PullDown, PullNone
  59. */
  60. void mode(PinMode pull);
  61. /** Binary mask of bus pins connected to actual pins (not NC pins)
  62. * If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
  63. *
  64. * @returns
  65. * Binary mask of connected pins
  66. */
  67. int mask() {
  68. return _nc_mask;
  69. }
  70. #ifdef MBED_OPERATORS
  71. /** A shorthand for write()
  72. */
  73. BusInOut& operator= (int v);
  74. BusInOut& operator= (BusInOut& rhs);
  75. /** Access to particular bit in random-iterator fashion
  76. */
  77. DigitalInOut& operator[] (int index);
  78. /** A shorthand for read()
  79. */
  80. operator int();
  81. #endif
  82. protected:
  83. DigitalInOut* _pin[16];
  84. /** Mask of bus's NC pins
  85. * If bit[n] is set to 1 - pin is connected
  86. * if bit[n] is cleared - pin is not connected (NC)
  87. */
  88. int _nc_mask;
  89. /* disallow copy constructor and assignment operators */
  90. private:
  91. BusInOut(const BusInOut&);
  92. BusInOut & operator = (const BusInOut&);
  93. };
  94. } // namespace mbed
  95. #endif