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