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