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.
BusInOut.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_BUSINOUT_H 00017 #define MBED_BUSINOUT_H 00018 00019 #include "drivers/DigitalInOut.h" 00020 #include "platform/PlatformMutex.h" 00021 #include "platform/NonCopyable.h" 00022 00023 namespace mbed { 00024 /** \addtogroup drivers */ 00025 00026 /** A digital input output bus, used for setting the state of a collection of pins 00027 * 00028 * @note Synchronization level: Thread safe 00029 * @ingroup drivers 00030 */ 00031 class BusInOut : private NonCopyable<BusInOut> { 00032 00033 public: 00034 00035 /** Create an BusInOut, connected to the specified pins 00036 * 00037 * @param p0 DigitalInOut pin to connect to bus bit 00038 * @param p1 DigitalInOut pin to connect to bus bit 00039 * @param p2 DigitalInOut pin to connect to bus bit 00040 * @param p3 DigitalInOut pin to connect to bus bit 00041 * @param p4 DigitalInOut pin to connect to bus bit 00042 * @param p5 DigitalInOut pin to connect to bus bit 00043 * @param p6 DigitalInOut pin to connect to bus bit 00044 * @param p7 DigitalInOut pin to connect to bus bit 00045 * @param p8 DigitalInOut pin to connect to bus bit 00046 * @param p9 DigitalInOut pin to connect to bus bit 00047 * @param p10 DigitalInOut pin to connect to bus bit 00048 * @param p11 DigitalInOut pin to connect to bus bit 00049 * @param p12 DigitalInOut pin to connect to bus bit 00050 * @param p13 DigitalInOut pin to connect to bus bit 00051 * @param p14 DigitalInOut pin to connect to bus bit 00052 * @param p15 DigitalInOut pin to connect to bus bit 00053 * 00054 * @note 00055 * It is only required to specify as many pin variables as is required 00056 * for the bus; the rest will default to NC (not connected) 00057 */ 00058 BusInOut(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC, 00059 PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC, 00060 PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC, 00061 PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC); 00062 00063 /** Create an BusInOut, connected to the specified pins 00064 * 00065 * @param pins An array of pins to construct a BusInOut from 00066 */ 00067 BusInOut(PinName pins[16]); 00068 00069 virtual ~BusInOut(); 00070 00071 /* Group: Access Methods */ 00072 00073 /** Write the value to the output bus 00074 * 00075 * @param value An integer specifying a bit to write for every corresponding DigitalInOut pin 00076 */ 00077 void write(int value); 00078 00079 /** Read the value currently output on the bus 00080 * 00081 * @returns 00082 * An integer with each bit corresponding to associated DigitalInOut pin setting 00083 */ 00084 int read(); 00085 00086 /** Set as an output 00087 */ 00088 void output(); 00089 00090 /** Set as an input 00091 */ 00092 void input(); 00093 00094 /** Set the input pin mode 00095 * 00096 * @param pull PullUp, PullDown, PullNone 00097 */ 00098 void mode(PinMode pull); 00099 00100 /** Binary mask of bus pins connected to actual pins (not NC pins) 00101 * If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1 00102 * 00103 * @returns 00104 * Binary mask of connected pins 00105 */ 00106 int mask() { 00107 // No lock needed since _nc_mask is not modified outside the constructor 00108 return _nc_mask; 00109 } 00110 00111 /** A shorthand for write() 00112 * \sa BusInOut::write() 00113 */ 00114 BusInOut& operator= (int v); 00115 BusInOut& operator= (BusInOut& rhs); 00116 00117 /** Access to particular bit in random-iterator fashion 00118 * @param index Bit Position 00119 */ 00120 DigitalInOut& operator[] (int index); 00121 00122 /** A shorthand for read() 00123 * \sa BusInOut::read() 00124 */ 00125 operator int(); 00126 00127 protected: 00128 virtual void lock(); 00129 virtual void unlock(); 00130 DigitalInOut* _pin[16]; 00131 00132 /* Mask of bus's NC pins 00133 * If bit[n] is set to 1 - pin is connected 00134 * if bit[n] is cleared - pin is not connected (NC) 00135 */ 00136 int _nc_mask; 00137 00138 PlatformMutex _mutex; 00139 }; 00140 00141 } // namespace mbed 00142 00143 #endif
Generated on Tue Jul 12 2022 12:21:44 by
