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_PORTIN_H
Bethory 0:6ad07c9019fd 17 #define MBED_PORTIN_H
Bethory 0:6ad07c9019fd 18
Bethory 0:6ad07c9019fd 19 #include "platform/platform.h"
Bethory 0:6ad07c9019fd 20
Bethory 0:6ad07c9019fd 21 #if defined (DEVICE_PORTIN) || defined(DOXYGEN_ONLY)
Bethory 0:6ad07c9019fd 22
Bethory 0:6ad07c9019fd 23 #include "hal/port_api.h"
Bethory 0:6ad07c9019fd 24 #include "platform/mbed_critical.h"
Bethory 0:6ad07c9019fd 25
Bethory 0:6ad07c9019fd 26 namespace mbed {
Bethory 0:6ad07c9019fd 27 /** \addtogroup drivers */
Bethory 0:6ad07c9019fd 28
Bethory 0:6ad07c9019fd 29 /** A multiple pin digital input
Bethory 0:6ad07c9019fd 30 *
Bethory 0:6ad07c9019fd 31 * @note Synchronization level: Interrupt safe
Bethory 0:6ad07c9019fd 32 *
Bethory 0:6ad07c9019fd 33 * Example:
Bethory 0:6ad07c9019fd 34 * @code
Bethory 0:6ad07c9019fd 35 * // Switch on an LED if any of mbed pins 21-26 is high
Bethory 0:6ad07c9019fd 36 *
Bethory 0:6ad07c9019fd 37 * #include "mbed.h"
Bethory 0:6ad07c9019fd 38 *
Bethory 0:6ad07c9019fd 39 * PortIn p(Port2, 0x0000003F); // p21-p26
Bethory 0:6ad07c9019fd 40 * DigitalOut ind(LED4);
Bethory 0:6ad07c9019fd 41 *
Bethory 0:6ad07c9019fd 42 * int main() {
Bethory 0:6ad07c9019fd 43 * while(1) {
Bethory 0:6ad07c9019fd 44 * int pins = p.read();
Bethory 0:6ad07c9019fd 45 * if(pins) {
Bethory 0:6ad07c9019fd 46 * ind = 1;
Bethory 0:6ad07c9019fd 47 * } else {
Bethory 0:6ad07c9019fd 48 * ind = 0;
Bethory 0:6ad07c9019fd 49 * }
Bethory 0:6ad07c9019fd 50 * }
Bethory 0:6ad07c9019fd 51 * }
Bethory 0:6ad07c9019fd 52 * @endcode
Bethory 0:6ad07c9019fd 53 * @ingroup drivers
Bethory 0:6ad07c9019fd 54 */
Bethory 0:6ad07c9019fd 55 class PortIn {
Bethory 0:6ad07c9019fd 56 public:
Bethory 0:6ad07c9019fd 57
Bethory 0:6ad07c9019fd 58 /** Create an PortIn, connected to the specified port
Bethory 0:6ad07c9019fd 59 *
Bethory 0:6ad07c9019fd 60 * @param port Port to connect to (Port0-Port5)
Bethory 0:6ad07c9019fd 61 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
Bethory 0:6ad07c9019fd 62 */
Bethory 0:6ad07c9019fd 63 PortIn(PortName port, int mask = 0xFFFFFFFF) {
Bethory 0:6ad07c9019fd 64 core_util_critical_section_enter();
Bethory 0:6ad07c9019fd 65 port_init(&_port, port, mask, PIN_INPUT);
Bethory 0:6ad07c9019fd 66 core_util_critical_section_exit();
Bethory 0:6ad07c9019fd 67 }
Bethory 0:6ad07c9019fd 68
Bethory 0:6ad07c9019fd 69 /** Read the value currently output on the port
Bethory 0:6ad07c9019fd 70 *
Bethory 0:6ad07c9019fd 71 * @returns
Bethory 0:6ad07c9019fd 72 * An integer with each bit corresponding to associated port pin setting
Bethory 0:6ad07c9019fd 73 */
Bethory 0:6ad07c9019fd 74 int read() {
Bethory 0:6ad07c9019fd 75 return port_read(&_port);
Bethory 0:6ad07c9019fd 76 }
Bethory 0:6ad07c9019fd 77
Bethory 0:6ad07c9019fd 78 /** Set the input pin mode
Bethory 0:6ad07c9019fd 79 *
Bethory 0:6ad07c9019fd 80 * @param mode PullUp, PullDown, PullNone, OpenDrain
Bethory 0:6ad07c9019fd 81 */
Bethory 0:6ad07c9019fd 82 void mode(PinMode mode) {
Bethory 0:6ad07c9019fd 83 core_util_critical_section_enter();
Bethory 0:6ad07c9019fd 84 port_mode(&_port, mode);
Bethory 0:6ad07c9019fd 85 core_util_critical_section_exit();
Bethory 0:6ad07c9019fd 86 }
Bethory 0:6ad07c9019fd 87
Bethory 0:6ad07c9019fd 88 /** A shorthand for read()
Bethory 0:6ad07c9019fd 89 */
Bethory 0:6ad07c9019fd 90 operator int() {
Bethory 0:6ad07c9019fd 91 return read();
Bethory 0:6ad07c9019fd 92 }
Bethory 0:6ad07c9019fd 93
Bethory 0:6ad07c9019fd 94 private:
Bethory 0:6ad07c9019fd 95 port_t _port;
Bethory 0:6ad07c9019fd 96 };
Bethory 0:6ad07c9019fd 97
Bethory 0:6ad07c9019fd 98 } // namespace mbed
Bethory 0:6ad07c9019fd 99
Bethory 0:6ad07c9019fd 100 #endif
Bethory 0:6ad07c9019fd 101
Bethory 0:6ad07c9019fd 102 #endif