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