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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
BusInOut.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #ifndef MBED_BUSINOUT_H 00018 #define MBED_BUSINOUT_H 00019 00020 #include "drivers/DigitalInOut.h" 00021 #include "platform/PlatformMutex.h" 00022 #include "platform/NonCopyable.h" 00023 00024 namespace mbed { 00025 /** 00026 * \defgroup drivers_BusInOut BusInOut class 00027 * \ingroup drivers-public-api-gpio 00028 * @{ 00029 */ 00030 00031 /** A digital input output bus, used for setting the state of a collection of pins. 00032 * Implemented as an array of DigitalInOut pins, the bus can be constructed by any 00033 * pins without restriction other than being capable of digital input or output 00034 * capabilities 00035 * 00036 * @note Synchronization level: Thread safe 00037 */ 00038 class BusInOut : private NonCopyable<BusInOut> { 00039 00040 public: 00041 00042 /** Create a BusInOut, connected to the specified pins 00043 * 00044 * @param p0 DigitalInOut pin to connect to bus bit 00045 * @param p1 DigitalInOut pin to connect to bus bit 00046 * @param p2 DigitalInOut pin to connect to bus bit 00047 * @param p3 DigitalInOut pin to connect to bus bit 00048 * @param p4 DigitalInOut pin to connect to bus bit 00049 * @param p5 DigitalInOut pin to connect to bus bit 00050 * @param p6 DigitalInOut pin to connect to bus bit 00051 * @param p7 DigitalInOut pin to connect to bus bit 00052 * @param p8 DigitalInOut pin to connect to bus bit 00053 * @param p9 DigitalInOut pin to connect to bus bit 00054 * @param p10 DigitalInOut pin to connect to bus bit 00055 * @param p11 DigitalInOut pin to connect to bus bit 00056 * @param p12 DigitalInOut pin to connect to bus bit 00057 * @param p13 DigitalInOut pin to connect to bus bit 00058 * @param p14 DigitalInOut pin to connect to bus bit 00059 * @param p15 DigitalInOut pin to connect to bus bit 00060 * 00061 * @note 00062 * It is only required to specify as many pin variables as is required 00063 * for the bus; the rest will default to NC (not connected) 00064 */ 00065 BusInOut(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC, 00066 PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC, 00067 PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC, 00068 PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC); 00069 00070 /** Create a BusInOut, connected to the specified pins 00071 * 00072 * @param pins An array of pins (PinName) to construct a BusInOut from. The maximum 00073 * number of pins in the array is 16 and any pins that are unspecified or are not to be 00074 * connected must be specified as NC in the array that is passed in 00075 */ 00076 BusInOut(PinName pins[16]); 00077 00078 virtual ~BusInOut(); 00079 00080 /* Group: Access Methods */ 00081 00082 /** Write the value to the output bus 00083 * 00084 * @param value An integer specifying a bit to write for every corresponding DigitalInOut pin 00085 */ 00086 void write(int value); 00087 00088 /** Read the value currently output on the bus 00089 * 00090 * @returns 00091 * An integer with each bit corresponding to associated DigitalInOut pin setting 00092 */ 00093 int read(); 00094 00095 /** Set all the pins in bus as output 00096 */ 00097 void output(); 00098 00099 /** Set all the pins in bus as an input 00100 */ 00101 void input(); 00102 00103 /** Set the input pin mode for all the pins in bus 00104 * 00105 * @param pull PullUp, PullDown, PullNone 00106 */ 00107 void mode(PinMode pull); 00108 00109 /** Binary mask of bus pins connected to actual pins (not NC pins) 00110 * If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1 00111 * 00112 * @returns 00113 * Binary mask of connected pins 00114 */ 00115 int mask() 00116 { 00117 // No lock needed since _nc_mask is not modified outside the constructor 00118 return _nc_mask; 00119 } 00120 00121 /** A shorthand for write() 00122 * \sa BusInOut::write() 00123 */ 00124 BusInOut &operator= (int v); 00125 BusInOut &operator= (BusInOut &rhs); 00126 00127 /** Access to particular bit in random-iterator fashion 00128 * @param index Bit Position 00129 */ 00130 DigitalInOut &operator[](int index); 00131 00132 /** A shorthand for read() 00133 * \sa BusInOut::read() 00134 */ 00135 operator int(); 00136 00137 protected: 00138 #if !defined(DOXYGEN_ONLY) 00139 virtual void lock(); 00140 virtual void unlock(); 00141 DigitalInOut *_pin[16]; 00142 00143 /* Mask of bus's NC pins 00144 * If bit[n] is set to 1 - pin is connected 00145 * if bit[n] is cleared - pin is not connected (NC) 00146 */ 00147 int _nc_mask; 00148 00149 PlatformMutex _mutex; 00150 #endif //!defined(DOXYGEN_ONLY) 00151 }; 00152 00153 /** @}*/ 00154 00155 } // namespace mbed 00156 00157 #endif
Generated on Tue Jul 12 2022 13:54:04 by
