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