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