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