mbed-dev-f303

Committer:
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4
Date:
Tue Jun 14 09:21:18 2022 +0000
Revision:
0:bdf663c61a82
lib

Who changed what in which revision?

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