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