Pinned to some recent date
drivers/BusOut.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_BUSOUT_H |
Simon Cooksey |
0:fb7af294d5d9 | 17 | #define MBED_BUSOUT_H |
Simon Cooksey |
0:fb7af294d5d9 | 18 | |
Simon Cooksey |
0:fb7af294d5d9 | 19 | #include "drivers/DigitalOut.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 output bus, used for setting the state of a collection of pins |
Simon Cooksey |
0:fb7af294d5d9 | 27 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 28 | class BusOut { |
Simon Cooksey |
0:fb7af294d5d9 | 29 | |
Simon Cooksey |
0:fb7af294d5d9 | 30 | public: |
Simon Cooksey |
0:fb7af294d5d9 | 31 | |
Simon Cooksey |
0:fb7af294d5d9 | 32 | /** Create an BusOut, connected to the specified pins |
Simon Cooksey |
0:fb7af294d5d9 | 33 | * |
Simon Cooksey |
0:fb7af294d5d9 | 34 | * @param p<n> DigitalOut pin to connect to bus bit <n> (p5-p30, NC) |
Simon Cooksey |
0:fb7af294d5d9 | 35 | * |
Simon Cooksey |
0:fb7af294d5d9 | 36 | * @Note Synchronization level: Thread safe |
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 | BusOut(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 | BusOut(PinName pins[16]); |
Simon Cooksey |
0:fb7af294d5d9 | 48 | |
Simon Cooksey |
0:fb7af294d5d9 | 49 | virtual ~BusOut(); |
Simon Cooksey |
0:fb7af294d5d9 | 50 | |
Simon Cooksey |
0:fb7af294d5d9 | 51 | /** Write the value to the output bus |
Simon Cooksey |
0:fb7af294d5d9 | 52 | * |
Simon Cooksey |
0:fb7af294d5d9 | 53 | * @param value An integer specifying a bit to write for every corresponding DigitalOut pin |
Simon Cooksey |
0:fb7af294d5d9 | 54 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 55 | void write(int value); |
Simon Cooksey |
0:fb7af294d5d9 | 56 | |
Simon Cooksey |
0:fb7af294d5d9 | 57 | /** Read the value currently output on the bus |
Simon Cooksey |
0:fb7af294d5d9 | 58 | * |
Simon Cooksey |
0:fb7af294d5d9 | 59 | * @returns |
Simon Cooksey |
0:fb7af294d5d9 | 60 | * An integer with each bit corresponding to associated DigitalOut pin setting |
Simon Cooksey |
0:fb7af294d5d9 | 61 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 62 | int read(); |
Simon Cooksey |
0:fb7af294d5d9 | 63 | |
Simon Cooksey |
0:fb7af294d5d9 | 64 | /** Binary mask of bus pins connected to actual pins (not NC pins) |
Simon Cooksey |
0:fb7af294d5d9 | 65 | * 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 | 66 | * |
Simon Cooksey |
0:fb7af294d5d9 | 67 | * @returns |
Simon Cooksey |
0:fb7af294d5d9 | 68 | * Binary mask of connected pins |
Simon Cooksey |
0:fb7af294d5d9 | 69 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 70 | int mask() { |
Simon Cooksey |
0:fb7af294d5d9 | 71 | // No lock needed since _nc_mask is not modified outside the constructor |
Simon Cooksey |
0:fb7af294d5d9 | 72 | return _nc_mask; |
Simon Cooksey |
0:fb7af294d5d9 | 73 | } |
Simon Cooksey |
0:fb7af294d5d9 | 74 | |
Simon Cooksey |
0:fb7af294d5d9 | 75 | /** A shorthand for write() |
Simon Cooksey |
0:fb7af294d5d9 | 76 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 77 | BusOut& operator= (int v); |
Simon Cooksey |
0:fb7af294d5d9 | 78 | BusOut& operator= (BusOut& rhs); |
Simon Cooksey |
0:fb7af294d5d9 | 79 | |
Simon Cooksey |
0:fb7af294d5d9 | 80 | /** Access to particular bit in random-iterator fashion |
Simon Cooksey |
0:fb7af294d5d9 | 81 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 82 | DigitalOut& operator[] (int index); |
Simon Cooksey |
0:fb7af294d5d9 | 83 | |
Simon Cooksey |
0:fb7af294d5d9 | 84 | /** A shorthand for read() |
Simon Cooksey |
0:fb7af294d5d9 | 85 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 86 | operator int(); |
Simon Cooksey |
0:fb7af294d5d9 | 87 | |
Simon Cooksey |
0:fb7af294d5d9 | 88 | protected: |
Simon Cooksey |
0:fb7af294d5d9 | 89 | virtual void lock(); |
Simon Cooksey |
0:fb7af294d5d9 | 90 | virtual void unlock(); |
Simon Cooksey |
0:fb7af294d5d9 | 91 | DigitalOut* _pin[16]; |
Simon Cooksey |
0:fb7af294d5d9 | 92 | |
Simon Cooksey |
0:fb7af294d5d9 | 93 | /** Mask of bus's NC pins |
Simon Cooksey |
0:fb7af294d5d9 | 94 | * If bit[n] is set to 1 - pin is connected |
Simon Cooksey |
0:fb7af294d5d9 | 95 | * if bit[n] is cleared - pin is not connected (NC) |
Simon Cooksey |
0:fb7af294d5d9 | 96 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 97 | int _nc_mask; |
Simon Cooksey |
0:fb7af294d5d9 | 98 | |
Simon Cooksey |
0:fb7af294d5d9 | 99 | PlatformMutex _mutex; |
Simon Cooksey |
0:fb7af294d5d9 | 100 | |
Simon Cooksey |
0:fb7af294d5d9 | 101 | /* disallow copy constructor and assignment operators */ |
Simon Cooksey |
0:fb7af294d5d9 | 102 | private: |
Simon Cooksey |
0:fb7af294d5d9 | 103 | BusOut(const BusOut&); |
Simon Cooksey |
0:fb7af294d5d9 | 104 | BusOut & operator = (const BusOut&); |
Simon Cooksey |
0:fb7af294d5d9 | 105 | }; |
Simon Cooksey |
0:fb7af294d5d9 | 106 | |
Simon Cooksey |
0:fb7af294d5d9 | 107 | } // namespace mbed |
Simon Cooksey |
0:fb7af294d5d9 | 108 | |
Simon Cooksey |
0:fb7af294d5d9 | 109 | #endif |
Simon Cooksey |
0:fb7af294d5d9 | 110 | |
Simon Cooksey |
0:fb7af294d5d9 | 111 | /** @}*/ |