mbed library sources. Supersedes mbed-src.

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

Committer:
AnnaBridge
Date:
Thu Sep 06 13:40:20 2018 +0100
Revision:
187:0387e8f68319
Parent:
168:9672193075cf
Child:
189:f392fc9709a3
mbed-dev library. Release version 163

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