Entrega 3er corte - sistemas embebidos

Committer:
Bethory
Date:
Wed May 30 04:46:28 2018 +0000
Revision:
1:fcdb45ee95b9
Parent:
0:6ad07c9019fd
Entrega Final

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_BUSIN_H
Bethory 0:6ad07c9019fd 17 #define MBED_BUSIN_H
Bethory 0:6ad07c9019fd 18
Bethory 0:6ad07c9019fd 19 #include "platform/platform.h"
Bethory 0:6ad07c9019fd 20 #include "drivers/DigitalIn.h"
Bethory 0:6ad07c9019fd 21 #include "platform/PlatformMutex.h"
Bethory 0:6ad07c9019fd 22 #include "platform/NonCopyable.h"
Bethory 0:6ad07c9019fd 23
Bethory 0:6ad07c9019fd 24 namespace mbed {
Bethory 0:6ad07c9019fd 25 /** \addtogroup drivers */
Bethory 0:6ad07c9019fd 26
Bethory 0:6ad07c9019fd 27 /** A digital input bus, used for reading the state of a collection of pins
Bethory 0:6ad07c9019fd 28 *
Bethory 0:6ad07c9019fd 29 * @note Synchronization level: Thread safe
Bethory 0:6ad07c9019fd 30 * @ingroup drivers
Bethory 0:6ad07c9019fd 31 */
Bethory 0:6ad07c9019fd 32 class BusIn : private NonCopyable<BusIn> {
Bethory 0:6ad07c9019fd 33
Bethory 0:6ad07c9019fd 34 public:
Bethory 0:6ad07c9019fd 35 /* Group: Configuration Methods */
Bethory 0:6ad07c9019fd 36
Bethory 0:6ad07c9019fd 37 /** Create an BusIn, connected to the specified pins
Bethory 0:6ad07c9019fd 38 *
Bethory 0:6ad07c9019fd 39 * @param p0 DigitalIn pin to connect to bus bit
Bethory 0:6ad07c9019fd 40 * @param p1 DigitalIn pin to connect to bus bit
Bethory 0:6ad07c9019fd 41 * @param p2 DigitalIn pin to connect to bus bit
Bethory 0:6ad07c9019fd 42 * @param p3 DigitalIn pin to connect to bus bit
Bethory 0:6ad07c9019fd 43 * @param p4 DigitalIn pin to connect to bus bit
Bethory 0:6ad07c9019fd 44 * @param p5 DigitalIn pin to connect to bus bit
Bethory 0:6ad07c9019fd 45 * @param p6 DigitalIn pin to connect to bus bit
Bethory 0:6ad07c9019fd 46 * @param p7 DigitalIn pin to connect to bus bit
Bethory 0:6ad07c9019fd 47 * @param p8 DigitalIn pin to connect to bus bit
Bethory 0:6ad07c9019fd 48 * @param p9 DigitalIn pin to connect to bus bit
Bethory 0:6ad07c9019fd 49 * @param p10 DigitalIn pin to connect to bus bit
Bethory 0:6ad07c9019fd 50 * @param p11 DigitalIn pin to connect to bus bit
Bethory 0:6ad07c9019fd 51 * @param p12 DigitalIn pin to connect to bus bit
Bethory 0:6ad07c9019fd 52 * @param p13 DigitalIn pin to connect to bus bit
Bethory 0:6ad07c9019fd 53 * @param p14 DigitalIn pin to connect to bus bit
Bethory 0:6ad07c9019fd 54 * @param p15 DigitalIn pin to connect to bus bit
Bethory 0:6ad07c9019fd 55 *
Bethory 0:6ad07c9019fd 56 * @note
Bethory 0:6ad07c9019fd 57 * It is only required to specify as many pin variables as is required
Bethory 0:6ad07c9019fd 58 * for the bus; the rest will default to NC (not connected)
Bethory 0:6ad07c9019fd 59 */
Bethory 0:6ad07c9019fd 60 BusIn(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
Bethory 0:6ad07c9019fd 61 PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
Bethory 0:6ad07c9019fd 62 PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
Bethory 0:6ad07c9019fd 63 PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
Bethory 0:6ad07c9019fd 64
Bethory 0:6ad07c9019fd 65
Bethory 0:6ad07c9019fd 66 /** Create an BusIn, connected to the specified pins
Bethory 0:6ad07c9019fd 67 *
Bethory 0:6ad07c9019fd 68 * @param pins An array of pins to connect to bus bit
Bethory 0:6ad07c9019fd 69 */
Bethory 0:6ad07c9019fd 70 BusIn(PinName pins[16]);
Bethory 0:6ad07c9019fd 71
Bethory 0:6ad07c9019fd 72 virtual ~BusIn();
Bethory 0:6ad07c9019fd 73
Bethory 0:6ad07c9019fd 74 /** Read the value of the input bus
Bethory 0:6ad07c9019fd 75 *
Bethory 0:6ad07c9019fd 76 * @returns
Bethory 0:6ad07c9019fd 77 * An integer with each bit corresponding to the value read from the associated DigitalIn pin
Bethory 0:6ad07c9019fd 78 */
Bethory 0:6ad07c9019fd 79 int read();
Bethory 0:6ad07c9019fd 80
Bethory 0:6ad07c9019fd 81 /** Set the input pin mode
Bethory 0:6ad07c9019fd 82 *
Bethory 0:6ad07c9019fd 83 * @param pull PullUp, PullDown, PullNone
Bethory 0:6ad07c9019fd 84 */
Bethory 0:6ad07c9019fd 85 void mode(PinMode pull);
Bethory 0:6ad07c9019fd 86
Bethory 0:6ad07c9019fd 87 /** Binary mask of bus pins connected to actual pins (not NC pins)
Bethory 0:6ad07c9019fd 88 * 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 89 *
Bethory 0:6ad07c9019fd 90 * @returns
Bethory 0:6ad07c9019fd 91 * Binary mask of connected pins
Bethory 0:6ad07c9019fd 92 */
Bethory 0:6ad07c9019fd 93 int mask() {
Bethory 0:6ad07c9019fd 94 // No lock needed since _nc_mask is not modified outside the constructor
Bethory 0:6ad07c9019fd 95 return _nc_mask;
Bethory 0:6ad07c9019fd 96 }
Bethory 0:6ad07c9019fd 97
Bethory 0:6ad07c9019fd 98 /** A shorthand for read()
Bethory 0:6ad07c9019fd 99 * \sa DigitalIn::read()
Bethory 0:6ad07c9019fd 100 */
Bethory 0:6ad07c9019fd 101 operator int();
Bethory 0:6ad07c9019fd 102
Bethory 0:6ad07c9019fd 103 /** Access to particular bit in random-iterator fashion
Bethory 0:6ad07c9019fd 104 * @param index Position of bit
Bethory 0:6ad07c9019fd 105 */
Bethory 0:6ad07c9019fd 106 DigitalIn & operator[] (int index);
Bethory 0:6ad07c9019fd 107
Bethory 0:6ad07c9019fd 108 protected:
Bethory 0:6ad07c9019fd 109 DigitalIn* _pin[16];
Bethory 0:6ad07c9019fd 110
Bethory 0:6ad07c9019fd 111 /* Mask of bus's NC pins
Bethory 0:6ad07c9019fd 112 * If bit[n] is set to 1 - pin is connected
Bethory 0:6ad07c9019fd 113 * if bit[n] is cleared - pin is not connected (NC)
Bethory 0:6ad07c9019fd 114 */
Bethory 0:6ad07c9019fd 115 int _nc_mask;
Bethory 0:6ad07c9019fd 116
Bethory 0:6ad07c9019fd 117 PlatformMutex _mutex;
Bethory 0:6ad07c9019fd 118
Bethory 0:6ad07c9019fd 119 private:
Bethory 0:6ad07c9019fd 120 virtual void lock();
Bethory 0:6ad07c9019fd 121 virtual void unlock();
Bethory 0:6ad07c9019fd 122 };
Bethory 0:6ad07c9019fd 123
Bethory 0:6ad07c9019fd 124 } // namespace mbed
Bethory 0:6ad07c9019fd 125
Bethory 0:6ad07c9019fd 126 #endif
Bethory 0:6ad07c9019fd 127