Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

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