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_BUSIN_H
borlanic 0:02dd72d1d465 17 #define MBED_BUSIN_H
borlanic 0:02dd72d1d465 18
borlanic 0:02dd72d1d465 19 #include "platform/platform.h"
borlanic 0:02dd72d1d465 20 #include "drivers/DigitalIn.h"
borlanic 0:02dd72d1d465 21 #include "platform/PlatformMutex.h"
borlanic 0:02dd72d1d465 22 #include "platform/NonCopyable.h"
borlanic 0:02dd72d1d465 23
borlanic 0:02dd72d1d465 24 namespace mbed {
borlanic 0:02dd72d1d465 25 /** \addtogroup drivers */
borlanic 0:02dd72d1d465 26
borlanic 0:02dd72d1d465 27 /** A digital input bus, used for reading the state of a collection of pins
borlanic 0:02dd72d1d465 28 *
borlanic 0:02dd72d1d465 29 * @note Synchronization level: Thread safe
borlanic 0:02dd72d1d465 30 * @ingroup drivers
borlanic 0:02dd72d1d465 31 */
borlanic 0:02dd72d1d465 32 class BusIn : private NonCopyable<BusIn> {
borlanic 0:02dd72d1d465 33
borlanic 0:02dd72d1d465 34 public:
borlanic 0:02dd72d1d465 35 /* Group: Configuration Methods */
borlanic 0:02dd72d1d465 36
borlanic 0:02dd72d1d465 37 /** Create an BusIn, connected to the specified pins
borlanic 0:02dd72d1d465 38 *
borlanic 0:02dd72d1d465 39 * @param p0 DigitalIn pin to connect to bus bit
borlanic 0:02dd72d1d465 40 * @param p1 DigitalIn pin to connect to bus bit
borlanic 0:02dd72d1d465 41 * @param p2 DigitalIn pin to connect to bus bit
borlanic 0:02dd72d1d465 42 * @param p3 DigitalIn pin to connect to bus bit
borlanic 0:02dd72d1d465 43 * @param p4 DigitalIn pin to connect to bus bit
borlanic 0:02dd72d1d465 44 * @param p5 DigitalIn pin to connect to bus bit
borlanic 0:02dd72d1d465 45 * @param p6 DigitalIn pin to connect to bus bit
borlanic 0:02dd72d1d465 46 * @param p7 DigitalIn pin to connect to bus bit
borlanic 0:02dd72d1d465 47 * @param p8 DigitalIn pin to connect to bus bit
borlanic 0:02dd72d1d465 48 * @param p9 DigitalIn pin to connect to bus bit
borlanic 0:02dd72d1d465 49 * @param p10 DigitalIn pin to connect to bus bit
borlanic 0:02dd72d1d465 50 * @param p11 DigitalIn pin to connect to bus bit
borlanic 0:02dd72d1d465 51 * @param p12 DigitalIn pin to connect to bus bit
borlanic 0:02dd72d1d465 52 * @param p13 DigitalIn pin to connect to bus bit
borlanic 0:02dd72d1d465 53 * @param p14 DigitalIn pin to connect to bus bit
borlanic 0:02dd72d1d465 54 * @param p15 DigitalIn pin to connect to bus bit
borlanic 0:02dd72d1d465 55 *
borlanic 0:02dd72d1d465 56 * @note
borlanic 0:02dd72d1d465 57 * It is only required to specify as many pin variables as is required
borlanic 0:02dd72d1d465 58 * for the bus; the rest will default to NC (not connected)
borlanic 0:02dd72d1d465 59 */
borlanic 0:02dd72d1d465 60 BusIn(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
borlanic 0:02dd72d1d465 61 PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
borlanic 0:02dd72d1d465 62 PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
borlanic 0:02dd72d1d465 63 PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
borlanic 0:02dd72d1d465 64
borlanic 0:02dd72d1d465 65
borlanic 0:02dd72d1d465 66 /** Create an BusIn, connected to the specified pins
borlanic 0:02dd72d1d465 67 *
borlanic 0:02dd72d1d465 68 * @param pins An array of pins to connect to bus bit
borlanic 0:02dd72d1d465 69 */
borlanic 0:02dd72d1d465 70 BusIn(PinName pins[16]);
borlanic 0:02dd72d1d465 71
borlanic 0:02dd72d1d465 72 virtual ~BusIn();
borlanic 0:02dd72d1d465 73
borlanic 0:02dd72d1d465 74 /** Read the value of the input bus
borlanic 0:02dd72d1d465 75 *
borlanic 0:02dd72d1d465 76 * @returns
borlanic 0:02dd72d1d465 77 * An integer with each bit corresponding to the value read from the associated DigitalIn pin
borlanic 0:02dd72d1d465 78 */
borlanic 0:02dd72d1d465 79 int read();
borlanic 0:02dd72d1d465 80
borlanic 0:02dd72d1d465 81 /** Set the input pin mode
borlanic 0:02dd72d1d465 82 *
borlanic 0:02dd72d1d465 83 * @param pull PullUp, PullDown, PullNone
borlanic 0:02dd72d1d465 84 */
borlanic 0:02dd72d1d465 85 void mode(PinMode pull);
borlanic 0:02dd72d1d465 86
borlanic 0:02dd72d1d465 87 /** Binary mask of bus pins connected to actual pins (not NC pins)
borlanic 0:02dd72d1d465 88 * 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 89 *
borlanic 0:02dd72d1d465 90 * @returns
borlanic 0:02dd72d1d465 91 * Binary mask of connected pins
borlanic 0:02dd72d1d465 92 */
borlanic 0:02dd72d1d465 93 int mask() {
borlanic 0:02dd72d1d465 94 // No lock needed since _nc_mask is not modified outside the constructor
borlanic 0:02dd72d1d465 95 return _nc_mask;
borlanic 0:02dd72d1d465 96 }
borlanic 0:02dd72d1d465 97
borlanic 0:02dd72d1d465 98 /** A shorthand for read()
borlanic 0:02dd72d1d465 99 * \sa DigitalIn::read()
borlanic 0:02dd72d1d465 100 */
borlanic 0:02dd72d1d465 101 operator int();
borlanic 0:02dd72d1d465 102
borlanic 0:02dd72d1d465 103 /** Access to particular bit in random-iterator fashion
borlanic 0:02dd72d1d465 104 * @param index Position of bit
borlanic 0:02dd72d1d465 105 */
borlanic 0:02dd72d1d465 106 DigitalIn & operator[] (int index);
borlanic 0:02dd72d1d465 107
borlanic 0:02dd72d1d465 108 protected:
borlanic 0:02dd72d1d465 109 DigitalIn* _pin[16];
borlanic 0:02dd72d1d465 110
borlanic 0:02dd72d1d465 111 /* Mask of bus's NC pins
borlanic 0:02dd72d1d465 112 * If bit[n] is set to 1 - pin is connected
borlanic 0:02dd72d1d465 113 * if bit[n] is cleared - pin is not connected (NC)
borlanic 0:02dd72d1d465 114 */
borlanic 0:02dd72d1d465 115 int _nc_mask;
borlanic 0:02dd72d1d465 116
borlanic 0:02dd72d1d465 117 PlatformMutex _mutex;
borlanic 0:02dd72d1d465 118
borlanic 0:02dd72d1d465 119 private:
borlanic 0:02dd72d1d465 120 virtual void lock();
borlanic 0:02dd72d1d465 121 virtual void unlock();
borlanic 0:02dd72d1d465 122 };
borlanic 0:02dd72d1d465 123
borlanic 0:02dd72d1d465 124 } // namespace mbed
borlanic 0:02dd72d1d465 125
borlanic 0:02dd72d1d465 126 #endif
borlanic 0:02dd72d1d465 127