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.
Fork of mbed-src by
PortInOut.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_PORTINOUT_H 00017 #define MBED_PORTINOUT_H 00018 00019 #include "platform.h" 00020 00021 #if DEVICE_PORTINOUT 00022 00023 #include "port_api.h" 00024 00025 namespace mbed { 00026 00027 /** A multiple pin digital in/out used to set/read multiple bi-directional pins 00028 */ 00029 class PortInOut { 00030 public: 00031 00032 /** Create an PortInOut, connected to the specified port 00033 * 00034 * @param port Port to connect to (Port0-Port5) 00035 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore) 00036 */ 00037 PortInOut(PortName port, int mask = 0xFFFFFFFF) { 00038 port_init(&_port, port, mask, PIN_INPUT); 00039 } 00040 00041 /** Write the value to the output port 00042 * 00043 * @param value An integer specifying a bit to write for every corresponding port pin 00044 */ 00045 void write(int value) { 00046 port_write(&_port, value); 00047 } 00048 00049 /** Read the value currently output on the port 00050 * 00051 * @returns 00052 * An integer with each bit corresponding to associated port pin setting 00053 */ 00054 int read() { 00055 return port_read(&_port); 00056 } 00057 00058 /** Set as an output 00059 */ 00060 void output() { 00061 port_dir(&_port, PIN_OUTPUT); 00062 } 00063 00064 /** Set as an input 00065 */ 00066 void input() { 00067 port_dir(&_port, PIN_INPUT); 00068 } 00069 00070 /** Set the input pin mode 00071 * 00072 * @param mode PullUp, PullDown, PullNone, OpenDrain 00073 */ 00074 void mode(PinMode mode) { 00075 port_mode(&_port, mode); 00076 } 00077 00078 /** A shorthand for write() 00079 */ 00080 PortInOut& operator= (int value) { 00081 write(value); 00082 return *this; 00083 } 00084 00085 PortInOut& operator= (PortInOut& rhs) { 00086 write(rhs.read()); 00087 return *this; 00088 } 00089 00090 /** A shorthand for read() 00091 */ 00092 operator int() { 00093 return read(); 00094 } 00095 00096 private: 00097 port_t _port; 00098 }; 00099 00100 } // namespace mbed 00101 00102 #endif 00103 00104 #endif
Generated on Tue Jul 12 2022 21:21:33 by
