inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

UserRevisionLine numberNew 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_BUSINOUT_H
NYX 0:85b3fd62ea1a 17 #define MBED_BUSINOUT_H
NYX 0:85b3fd62ea1a 18
NYX 0:85b3fd62ea1a 19 #include "drivers/DigitalInOut.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 input output bus, used for setting the state of a collection of pins
NYX 0:85b3fd62ea1a 27 *
NYX 0:85b3fd62ea1a 28 * @note Synchronization level: Thread safe
NYX 0:85b3fd62ea1a 29 * @ingroup drivers
NYX 0:85b3fd62ea1a 30 */
NYX 0:85b3fd62ea1a 31 class BusInOut : private NonCopyable<BusInOut> {
NYX 0:85b3fd62ea1a 32
NYX 0:85b3fd62ea1a 33 public:
NYX 0:85b3fd62ea1a 34
NYX 0:85b3fd62ea1a 35 /** Create an BusInOut, connected to the specified pins
NYX 0:85b3fd62ea1a 36 *
NYX 0:85b3fd62ea1a 37 * @param p0 DigitalInOut pin to connect to bus bit
NYX 0:85b3fd62ea1a 38 * @param p1 DigitalInOut pin to connect to bus bit
NYX 0:85b3fd62ea1a 39 * @param p2 DigitalInOut pin to connect to bus bit
NYX 0:85b3fd62ea1a 40 * @param p3 DigitalInOut pin to connect to bus bit
NYX 0:85b3fd62ea1a 41 * @param p4 DigitalInOut pin to connect to bus bit
NYX 0:85b3fd62ea1a 42 * @param p5 DigitalInOut pin to connect to bus bit
NYX 0:85b3fd62ea1a 43 * @param p6 DigitalInOut pin to connect to bus bit
NYX 0:85b3fd62ea1a 44 * @param p7 DigitalInOut pin to connect to bus bit
NYX 0:85b3fd62ea1a 45 * @param p8 DigitalInOut pin to connect to bus bit
NYX 0:85b3fd62ea1a 46 * @param p9 DigitalInOut pin to connect to bus bit
NYX 0:85b3fd62ea1a 47 * @param p10 DigitalInOut pin to connect to bus bit
NYX 0:85b3fd62ea1a 48 * @param p11 DigitalInOut pin to connect to bus bit
NYX 0:85b3fd62ea1a 49 * @param p12 DigitalInOut pin to connect to bus bit
NYX 0:85b3fd62ea1a 50 * @param p13 DigitalInOut pin to connect to bus bit
NYX 0:85b3fd62ea1a 51 * @param p14 DigitalInOut pin to connect to bus bit
NYX 0:85b3fd62ea1a 52 * @param p15 DigitalInOut pin to connect to bus bit
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 BusInOut(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 BusInOut, connected to the specified pins
NYX 0:85b3fd62ea1a 64 *
NYX 0:85b3fd62ea1a 65 * @param pins An array of pins to construct a BusInOut from
NYX 0:85b3fd62ea1a 66 */
NYX 0:85b3fd62ea1a 67 BusInOut(PinName pins[16]);
NYX 0:85b3fd62ea1a 68
NYX 0:85b3fd62ea1a 69 virtual ~BusInOut();
NYX 0:85b3fd62ea1a 70
NYX 0:85b3fd62ea1a 71 /* Group: Access Methods */
NYX 0:85b3fd62ea1a 72
NYX 0:85b3fd62ea1a 73 /** Write the value to the output bus
NYX 0:85b3fd62ea1a 74 *
NYX 0:85b3fd62ea1a 75 * @param value An integer specifying a bit to write for every corresponding DigitalInOut pin
NYX 0:85b3fd62ea1a 76 */
NYX 0:85b3fd62ea1a 77 void write(int value);
NYX 0:85b3fd62ea1a 78
NYX 0:85b3fd62ea1a 79 /** Read the value currently output on the bus
NYX 0:85b3fd62ea1a 80 *
NYX 0:85b3fd62ea1a 81 * @returns
NYX 0:85b3fd62ea1a 82 * An integer with each bit corresponding to associated DigitalInOut pin setting
NYX 0:85b3fd62ea1a 83 */
NYX 0:85b3fd62ea1a 84 int read();
NYX 0:85b3fd62ea1a 85
NYX 0:85b3fd62ea1a 86 /** Set as an output
NYX 0:85b3fd62ea1a 87 */
NYX 0:85b3fd62ea1a 88 void output();
NYX 0:85b3fd62ea1a 89
NYX 0:85b3fd62ea1a 90 /** Set as an input
NYX 0:85b3fd62ea1a 91 */
NYX 0:85b3fd62ea1a 92 void input();
NYX 0:85b3fd62ea1a 93
NYX 0:85b3fd62ea1a 94 /** Set the input pin mode
NYX 0:85b3fd62ea1a 95 *
NYX 0:85b3fd62ea1a 96 * @param pull PullUp, PullDown, PullNone
NYX 0:85b3fd62ea1a 97 */
NYX 0:85b3fd62ea1a 98 void mode(PinMode pull);
NYX 0:85b3fd62ea1a 99
NYX 0:85b3fd62ea1a 100 /** Binary mask of bus pins connected to actual pins (not NC pins)
NYX 0:85b3fd62ea1a 101 * 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 102 *
NYX 0:85b3fd62ea1a 103 * @returns
NYX 0:85b3fd62ea1a 104 * Binary mask of connected pins
NYX 0:85b3fd62ea1a 105 */
NYX 0:85b3fd62ea1a 106 int mask() {
NYX 0:85b3fd62ea1a 107 // No lock needed since _nc_mask is not modified outside the constructor
NYX 0:85b3fd62ea1a 108 return _nc_mask;
NYX 0:85b3fd62ea1a 109 }
NYX 0:85b3fd62ea1a 110
NYX 0:85b3fd62ea1a 111 /** A shorthand for write()
NYX 0:85b3fd62ea1a 112 * \sa BusInOut::write()
NYX 0:85b3fd62ea1a 113 */
NYX 0:85b3fd62ea1a 114 BusInOut& operator= (int v);
NYX 0:85b3fd62ea1a 115 BusInOut& operator= (BusInOut& rhs);
NYX 0:85b3fd62ea1a 116
NYX 0:85b3fd62ea1a 117 /** Access to particular bit in random-iterator fashion
NYX 0:85b3fd62ea1a 118 * @param index Bit Position
NYX 0:85b3fd62ea1a 119 */
NYX 0:85b3fd62ea1a 120 DigitalInOut& operator[] (int index);
NYX 0:85b3fd62ea1a 121
NYX 0:85b3fd62ea1a 122 /** A shorthand for read()
NYX 0:85b3fd62ea1a 123 * \sa BusInOut::read()
NYX 0:85b3fd62ea1a 124 */
NYX 0:85b3fd62ea1a 125 operator int();
NYX 0:85b3fd62ea1a 126
NYX 0:85b3fd62ea1a 127 protected:
NYX 0:85b3fd62ea1a 128 virtual void lock();
NYX 0:85b3fd62ea1a 129 virtual void unlock();
NYX 0:85b3fd62ea1a 130 DigitalInOut* _pin[16];
NYX 0:85b3fd62ea1a 131
NYX 0:85b3fd62ea1a 132 /* Mask of bus's NC pins
NYX 0:85b3fd62ea1a 133 * If bit[n] is set to 1 - pin is connected
NYX 0:85b3fd62ea1a 134 * if bit[n] is cleared - pin is not connected (NC)
NYX 0:85b3fd62ea1a 135 */
NYX 0:85b3fd62ea1a 136 int _nc_mask;
NYX 0:85b3fd62ea1a 137
NYX 0:85b3fd62ea1a 138 PlatformMutex _mutex;
NYX 0:85b3fd62ea1a 139 };
NYX 0:85b3fd62ea1a 140
NYX 0:85b3fd62ea1a 141 } // namespace mbed
NYX 0:85b3fd62ea1a 142
NYX 0:85b3fd62ea1a 143 #endif