Entrega 3er corte - sistemas embebidos

Committer:
Bethory
Date:
Wed May 30 00:01:50 2018 +0000
Revision:
0:6ad07c9019fd
Codigo de tales para todos los pasculaes

Who changed what in which revision?

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