mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
187:0387e8f68319
mbed library release version 165

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