Nicolas Borla / Mbed OS ROME2_Robot_Firmware
Committer:
boro
Date:
Mon Mar 16 13:12:31 2020 +0000
Revision:
0:4beb2ea291ec
a

Who changed what in which revision?

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