mbed-os

Fork of mbed-os by erkin yucel

Committer:
xuaner
Date:
Thu Jul 20 14:26:57 2017 +0000
Revision:
1:3deb71413561
Parent:
0:f269e3021894
mbed_os

Who changed what in which revision?

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