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