The official mbed C/C SDK provides the software platform and libraries to build your applications.
Fork of mbed by
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.h" 00020 00021 #if DEVICE_PORTIN 00022 00023 #include "port_api.h" 00024 00025 namespace mbed { 00026 00027 /** A multiple pin digital input 00028 * 00029 * Example: 00030 * @code 00031 * // Switch on an LED if any of mbed pins 21-26 is high 00032 * 00033 * #include "mbed.h" 00034 * 00035 * PortIn p(Port2, 0x0000003F); // p21-p26 00036 * DigitalOut ind(LED4); 00037 * 00038 * int main() { 00039 * while(1) { 00040 * int pins = p.read(); 00041 * if(pins) { 00042 * ind = 1; 00043 * } else { 00044 * ind = 0; 00045 * } 00046 * } 00047 * } 00048 * @endcode 00049 */ 00050 class PortIn { 00051 public: 00052 00053 /** Create an PortIn, connected to the specified port 00054 * 00055 * @param port Port to connect to (Port0-Port5) 00056 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore) 00057 */ 00058 PortIn(PortName port, int mask = 0xFFFFFFFF) { 00059 port_init(&_port, port, mask, PIN_INPUT); 00060 } 00061 00062 /** Read the value currently output on the port 00063 * 00064 * @returns 00065 * An integer with each bit corresponding to associated port pin setting 00066 */ 00067 int read() { 00068 return port_read(&_port); 00069 } 00070 00071 /** Set the input pin mode 00072 * 00073 * @param mode PullUp, PullDown, PullNone, OpenDrain 00074 */ 00075 void mode(PinMode mode) { 00076 port_mode(&_port, mode); 00077 } 00078 00079 /** A shorthand for read() 00080 */ 00081 operator int() { 00082 return read(); 00083 } 00084 00085 private: 00086 port_t _port; 00087 }; 00088 00089 } // namespace mbed 00090 00091 #endif 00092 00093 #endif
Generated on Sat Jul 16 2022 06:59:32 by 1.7.2