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