Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PortIn.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef MBED_PORTIN_H 00017 #define MBED_PORTIN_H 00018 00019 #include "platform/platform.h" 00020 00021 #if defined (DEVICE_PORTIN) || defined(DOXYGEN_ONLY) 00022 00023 #include "hal/port_api.h" 00024 #include "platform/mbed_critical.h" 00025 00026 namespace mbed { 00027 /** \addtogroup drivers */ 00028 00029 /** A multiple pin digital input 00030 * 00031 * @note Synchronization level: Interrupt safe 00032 * 00033 * Example: 00034 * @code 00035 * // Turn on an LED if any pins of Port2[0:5] are high 00036 * 00037 * #include "mbed.h" 00038 * 00039 * PortIn p(Port2, 0x0000003F); // Port2 pins [0:5] only 00040 * DigitalOut led(LED4); 00041 * 00042 * int main() { 00043 * while(1) { 00044 * int pins = p.read(); 00045 * if(pins) { 00046 * led = 1; 00047 * } else { 00048 * led = 0; 00049 * } 00050 * } 00051 * } 00052 * @endcode 00053 * @ingroup drivers 00054 */ 00055 class PortIn { 00056 public: 00057 00058 /** Create a PortIn, connected to the specified port 00059 * 00060 * @param port Port to connect to (as defined in target's PortNames.h) 00061 * @param mask Bitmask defines which port pins should be an input (0 - ignore, 1 - include) 00062 */ 00063 PortIn(PortName port, int mask = 0xFFFFFFFF) 00064 { 00065 core_util_critical_section_enter(); 00066 port_init(&_port, port, mask, PIN_INPUT); 00067 core_util_critical_section_exit(); 00068 } 00069 00070 /** Read the value input to the port 00071 * 00072 * @returns 00073 * An integer with each bit corresponding to the associated pin value 00074 */ 00075 int read() 00076 { 00077 return port_read(&_port); 00078 } 00079 00080 /** Set the input pin mode 00081 * 00082 * @param mode PullUp, PullDown, PullNone, OpenDrain 00083 */ 00084 void mode(PinMode mode) 00085 { 00086 core_util_critical_section_enter(); 00087 port_mode(&_port, mode); 00088 core_util_critical_section_exit(); 00089 } 00090 00091 /** A shorthand for read() 00092 */ 00093 operator int() 00094 { 00095 return read(); 00096 } 00097 00098 private: 00099 port_t _port; 00100 }; 00101 00102 } // namespace mbed 00103 00104 #endif 00105 00106 #endif
Generated on Tue Jul 12 2022 20:52:54 by
1.7.2