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