Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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