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