Forked.

Fork of mbed-dev by mbed official

Committer:
Dollyparton
Date:
Tue Dec 19 12:50:13 2017 +0000
Revision:
174:ed647f63e28d
Parent:
168:9672193075cf
Added RAW socket.

Who changed what in which revision?

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