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