1232

Committer:
ganlikun
Date:
Mon Oct 24 15:19:39 2022 +0000
Revision:
0:06036f8bee2d
11

Who changed what in which revision?

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