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-dev by
PortOut.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_PORTOUT_H 00017 #define MBED_PORTOUT_H 00018 00019 #include "platform.h" 00020 00021 #if DEVICE_PORTOUT 00022 00023 #include "port_api.h" 00024 #include "critical.h" 00025 00026 namespace mbed { 00027 /** A multiple pin digital out 00028 * 00029 * @Note Synchronization level: Interrupt safe 00030 * 00031 * Example: 00032 * @code 00033 * // Toggle all four LEDs 00034 * 00035 * #include "mbed.h" 00036 * 00037 * // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23 00038 * #define LED_MASK 0x00B40000 00039 * 00040 * PortOut ledport(Port1, LED_MASK); 00041 * 00042 * int main() { 00043 * while(1) { 00044 * ledport = LED_MASK; 00045 * wait(1); 00046 * ledport = 0; 00047 * wait(1); 00048 * } 00049 * } 00050 * @endcode 00051 */ 00052 class PortOut { 00053 public: 00054 00055 /** Create an PortOut, connected to the specified port 00056 * 00057 * @param port Port to connect to (Port0-Port5) 00058 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore) 00059 */ 00060 PortOut(PortName port, int mask = 0xFFFFFFFF) { 00061 core_util_critical_section_enter(); 00062 port_init(&_port, port, mask, PIN_OUTPUT); 00063 core_util_critical_section_exit(); 00064 } 00065 00066 /** Write the value to the output port 00067 * 00068 * @param value An integer specifying a bit to write for every corresponding PortOut pin 00069 */ 00070 void write(int value) { 00071 port_write(&_port, value); 00072 } 00073 00074 /** Read the value currently output on the port 00075 * 00076 * @returns 00077 * An integer with each bit corresponding to associated PortOut pin setting 00078 */ 00079 int read() { 00080 return port_read(&_port); 00081 } 00082 00083 /** A shorthand for write() 00084 */ 00085 PortOut& operator= (int value) { 00086 write(value); 00087 return *this; 00088 } 00089 00090 PortOut& operator= (PortOut& rhs) { 00091 write(rhs.read()); 00092 return *this; 00093 } 00094 00095 /** A shorthand for read() 00096 */ 00097 operator int() { 00098 return read(); 00099 } 00100 00101 private: 00102 port_t _port; 00103 }; 00104 00105 } // namespace mbed 00106 00107 #endif 00108 00109 #endif
Generated on Tue Jul 12 2022 19:20:55 by
1.7.2
