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.

PortInOut.h 2.5KB

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_PORTINOUT_H
  17. #define MBED_PORTINOUT_H
  18. #include "platform.h"
  19. #if DEVICE_PORTINOUT
  20. #include "port_api.h"
  21. namespace mbed {
  22. /** A multiple pin digital in/out used to set/read multiple bi-directional pins
  23. */
  24. class PortInOut {
  25. public:
  26. /** Create an PortInOut, connected to the specified port
  27. *
  28. * @param port Port to connect to (Port0-Port5)
  29. * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
  30. */
  31. PortInOut(PortName port, int mask = 0xFFFFFFFF) {
  32. port_init(&_port, port, mask, PIN_INPUT);
  33. }
  34. /** Write the value to the output port
  35. *
  36. * @param value An integer specifying a bit to write for every corresponding port pin
  37. */
  38. void write(int value) {
  39. port_write(&_port, value);
  40. }
  41. /** Read the value currently output on the port
  42. *
  43. * @returns
  44. * An integer with each bit corresponding to associated port pin setting
  45. */
  46. int read() {
  47. return port_read(&_port);
  48. }
  49. /** Set as an output
  50. */
  51. void output() {
  52. port_dir(&_port, PIN_OUTPUT);
  53. }
  54. /** Set as an input
  55. */
  56. void input() {
  57. port_dir(&_port, PIN_INPUT);
  58. }
  59. /** Set the input pin mode
  60. *
  61. * @param mode PullUp, PullDown, PullNone, OpenDrain
  62. */
  63. void mode(PinMode mode) {
  64. port_mode(&_port, mode);
  65. }
  66. /** A shorthand for write()
  67. */
  68. PortInOut& operator= (int value) {
  69. write(value);
  70. return *this;
  71. }
  72. PortInOut& operator= (PortInOut& rhs) {
  73. write(rhs.read());
  74. return *this;
  75. }
  76. /** A shorthand for read()
  77. */
  78. operator int() {
  79. return read();
  80. }
  81. private:
  82. port_t _port;
  83. };
  84. } // namespace mbed
  85. #endif
  86. #endif