RTC auf true
drivers/BusInOut.h@2:7aab896b1a3b, 2019-03-13 (annotated)
- Committer:
- kevman
- Date:
- Wed Mar 13 11:03:24 2019 +0000
- Revision:
- 2:7aab896b1a3b
- Parent:
- 0:38ceb79fef03
2019-03-13
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kevman | 0:38ceb79fef03 | 1 | /* mbed Microcontroller Library |
kevman | 0:38ceb79fef03 | 2 | * Copyright (c) 2006-2013 ARM Limited |
kevman | 0:38ceb79fef03 | 3 | * |
kevman | 0:38ceb79fef03 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kevman | 0:38ceb79fef03 | 5 | * you may not use this file except in compliance with the License. |
kevman | 0:38ceb79fef03 | 6 | * You may obtain a copy of the License at |
kevman | 0:38ceb79fef03 | 7 | * |
kevman | 0:38ceb79fef03 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kevman | 0:38ceb79fef03 | 9 | * |
kevman | 0:38ceb79fef03 | 10 | * Unless required by applicable law or agreed to in writing, software |
kevman | 0:38ceb79fef03 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kevman | 0:38ceb79fef03 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kevman | 0:38ceb79fef03 | 13 | * See the License for the specific language governing permissions and |
kevman | 0:38ceb79fef03 | 14 | * limitations under the License. |
kevman | 0:38ceb79fef03 | 15 | */ |
kevman | 0:38ceb79fef03 | 16 | #ifndef MBED_BUSINOUT_H |
kevman | 0:38ceb79fef03 | 17 | #define MBED_BUSINOUT_H |
kevman | 0:38ceb79fef03 | 18 | |
kevman | 0:38ceb79fef03 | 19 | #include "drivers/DigitalInOut.h" |
kevman | 0:38ceb79fef03 | 20 | #include "platform/PlatformMutex.h" |
kevman | 0:38ceb79fef03 | 21 | #include "platform/NonCopyable.h" |
kevman | 0:38ceb79fef03 | 22 | |
kevman | 0:38ceb79fef03 | 23 | namespace mbed { |
kevman | 0:38ceb79fef03 | 24 | /** \addtogroup drivers */ |
kevman | 0:38ceb79fef03 | 25 | |
kevman | 0:38ceb79fef03 | 26 | /** A digital input output bus, used for setting the state of a collection of pins |
kevman | 0:38ceb79fef03 | 27 | * |
kevman | 0:38ceb79fef03 | 28 | * @note Synchronization level: Thread safe |
kevman | 0:38ceb79fef03 | 29 | * @ingroup drivers |
kevman | 0:38ceb79fef03 | 30 | */ |
kevman | 0:38ceb79fef03 | 31 | class BusInOut : private NonCopyable<BusInOut> { |
kevman | 0:38ceb79fef03 | 32 | |
kevman | 0:38ceb79fef03 | 33 | public: |
kevman | 0:38ceb79fef03 | 34 | |
kevman | 0:38ceb79fef03 | 35 | /** Create an BusInOut, connected to the specified pins |
kevman | 0:38ceb79fef03 | 36 | * |
kevman | 0:38ceb79fef03 | 37 | * @param p0 DigitalInOut pin to connect to bus bit |
kevman | 0:38ceb79fef03 | 38 | * @param p1 DigitalInOut pin to connect to bus bit |
kevman | 0:38ceb79fef03 | 39 | * @param p2 DigitalInOut pin to connect to bus bit |
kevman | 0:38ceb79fef03 | 40 | * @param p3 DigitalInOut pin to connect to bus bit |
kevman | 0:38ceb79fef03 | 41 | * @param p4 DigitalInOut pin to connect to bus bit |
kevman | 0:38ceb79fef03 | 42 | * @param p5 DigitalInOut pin to connect to bus bit |
kevman | 0:38ceb79fef03 | 43 | * @param p6 DigitalInOut pin to connect to bus bit |
kevman | 0:38ceb79fef03 | 44 | * @param p7 DigitalInOut pin to connect to bus bit |
kevman | 0:38ceb79fef03 | 45 | * @param p8 DigitalInOut pin to connect to bus bit |
kevman | 0:38ceb79fef03 | 46 | * @param p9 DigitalInOut pin to connect to bus bit |
kevman | 0:38ceb79fef03 | 47 | * @param p10 DigitalInOut pin to connect to bus bit |
kevman | 0:38ceb79fef03 | 48 | * @param p11 DigitalInOut pin to connect to bus bit |
kevman | 0:38ceb79fef03 | 49 | * @param p12 DigitalInOut pin to connect to bus bit |
kevman | 0:38ceb79fef03 | 50 | * @param p13 DigitalInOut pin to connect to bus bit |
kevman | 0:38ceb79fef03 | 51 | * @param p14 DigitalInOut pin to connect to bus bit |
kevman | 0:38ceb79fef03 | 52 | * @param p15 DigitalInOut pin to connect to bus bit |
kevman | 0:38ceb79fef03 | 53 | * |
kevman | 0:38ceb79fef03 | 54 | * @note |
kevman | 0:38ceb79fef03 | 55 | * It is only required to specify as many pin variables as is required |
kevman | 0:38ceb79fef03 | 56 | * for the bus; the rest will default to NC (not connected) |
kevman | 0:38ceb79fef03 | 57 | */ |
kevman | 0:38ceb79fef03 | 58 | BusInOut(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC, |
kevman | 0:38ceb79fef03 | 59 | PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC, |
kevman | 0:38ceb79fef03 | 60 | PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC, |
kevman | 0:38ceb79fef03 | 61 | PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC); |
kevman | 0:38ceb79fef03 | 62 | |
kevman | 0:38ceb79fef03 | 63 | /** Create an BusInOut, connected to the specified pins |
kevman | 0:38ceb79fef03 | 64 | * |
kevman | 0:38ceb79fef03 | 65 | * @param pins An array of pins to construct a BusInOut from |
kevman | 0:38ceb79fef03 | 66 | */ |
kevman | 0:38ceb79fef03 | 67 | BusInOut(PinName pins[16]); |
kevman | 0:38ceb79fef03 | 68 | |
kevman | 0:38ceb79fef03 | 69 | virtual ~BusInOut(); |
kevman | 0:38ceb79fef03 | 70 | |
kevman | 0:38ceb79fef03 | 71 | /* Group: Access Methods */ |
kevman | 0:38ceb79fef03 | 72 | |
kevman | 0:38ceb79fef03 | 73 | /** Write the value to the output bus |
kevman | 0:38ceb79fef03 | 74 | * |
kevman | 0:38ceb79fef03 | 75 | * @param value An integer specifying a bit to write for every corresponding DigitalInOut pin |
kevman | 0:38ceb79fef03 | 76 | */ |
kevman | 0:38ceb79fef03 | 77 | void write(int value); |
kevman | 0:38ceb79fef03 | 78 | |
kevman | 0:38ceb79fef03 | 79 | /** Read the value currently output on the bus |
kevman | 0:38ceb79fef03 | 80 | * |
kevman | 0:38ceb79fef03 | 81 | * @returns |
kevman | 0:38ceb79fef03 | 82 | * An integer with each bit corresponding to associated DigitalInOut pin setting |
kevman | 0:38ceb79fef03 | 83 | */ |
kevman | 0:38ceb79fef03 | 84 | int read(); |
kevman | 0:38ceb79fef03 | 85 | |
kevman | 0:38ceb79fef03 | 86 | /** Set as an output |
kevman | 0:38ceb79fef03 | 87 | */ |
kevman | 0:38ceb79fef03 | 88 | void output(); |
kevman | 0:38ceb79fef03 | 89 | |
kevman | 0:38ceb79fef03 | 90 | /** Set as an input |
kevman | 0:38ceb79fef03 | 91 | */ |
kevman | 0:38ceb79fef03 | 92 | void input(); |
kevman | 0:38ceb79fef03 | 93 | |
kevman | 0:38ceb79fef03 | 94 | /** Set the input pin mode |
kevman | 0:38ceb79fef03 | 95 | * |
kevman | 0:38ceb79fef03 | 96 | * @param pull PullUp, PullDown, PullNone |
kevman | 0:38ceb79fef03 | 97 | */ |
kevman | 0:38ceb79fef03 | 98 | void mode(PinMode pull); |
kevman | 0:38ceb79fef03 | 99 | |
kevman | 0:38ceb79fef03 | 100 | /** Binary mask of bus pins connected to actual pins (not NC pins) |
kevman | 0:38ceb79fef03 | 101 | * If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1 |
kevman | 0:38ceb79fef03 | 102 | * |
kevman | 0:38ceb79fef03 | 103 | * @returns |
kevman | 0:38ceb79fef03 | 104 | * Binary mask of connected pins |
kevman | 0:38ceb79fef03 | 105 | */ |
kevman | 0:38ceb79fef03 | 106 | int mask() |
kevman | 0:38ceb79fef03 | 107 | { |
kevman | 0:38ceb79fef03 | 108 | // No lock needed since _nc_mask is not modified outside the constructor |
kevman | 0:38ceb79fef03 | 109 | return _nc_mask; |
kevman | 0:38ceb79fef03 | 110 | } |
kevman | 0:38ceb79fef03 | 111 | |
kevman | 0:38ceb79fef03 | 112 | /** A shorthand for write() |
kevman | 0:38ceb79fef03 | 113 | * \sa BusInOut::write() |
kevman | 0:38ceb79fef03 | 114 | */ |
kevman | 0:38ceb79fef03 | 115 | BusInOut &operator= (int v); |
kevman | 0:38ceb79fef03 | 116 | BusInOut &operator= (BusInOut &rhs); |
kevman | 0:38ceb79fef03 | 117 | |
kevman | 0:38ceb79fef03 | 118 | /** Access to particular bit in random-iterator fashion |
kevman | 0:38ceb79fef03 | 119 | * @param index Bit Position |
kevman | 0:38ceb79fef03 | 120 | */ |
kevman | 0:38ceb79fef03 | 121 | DigitalInOut &operator[](int index); |
kevman | 0:38ceb79fef03 | 122 | |
kevman | 0:38ceb79fef03 | 123 | /** A shorthand for read() |
kevman | 0:38ceb79fef03 | 124 | * \sa BusInOut::read() |
kevman | 0:38ceb79fef03 | 125 | */ |
kevman | 0:38ceb79fef03 | 126 | operator int(); |
kevman | 0:38ceb79fef03 | 127 | |
kevman | 0:38ceb79fef03 | 128 | protected: |
kevman | 0:38ceb79fef03 | 129 | virtual void lock(); |
kevman | 0:38ceb79fef03 | 130 | virtual void unlock(); |
kevman | 0:38ceb79fef03 | 131 | DigitalInOut *_pin[16]; |
kevman | 0:38ceb79fef03 | 132 | |
kevman | 0:38ceb79fef03 | 133 | /* Mask of bus's NC pins |
kevman | 0:38ceb79fef03 | 134 | * If bit[n] is set to 1 - pin is connected |
kevman | 0:38ceb79fef03 | 135 | * if bit[n] is cleared - pin is not connected (NC) |
kevman | 0:38ceb79fef03 | 136 | */ |
kevman | 0:38ceb79fef03 | 137 | int _nc_mask; |
kevman | 0:38ceb79fef03 | 138 | |
kevman | 0:38ceb79fef03 | 139 | PlatformMutex _mutex; |
kevman | 0:38ceb79fef03 | 140 | }; |
kevman | 0:38ceb79fef03 | 141 | |
kevman | 0:38ceb79fef03 | 142 | } // namespace mbed |
kevman | 0:38ceb79fef03 | 143 | |
kevman | 0:38ceb79fef03 | 144 | #endif |