Mistake on this page?
Report an issue in GitHub or email us
BusIn.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2013 ARM Limited
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef MBED_BUSIN_H
18 #define MBED_BUSIN_H
19 
20 #include "platform/platform.h"
21 #include "drivers/DigitalIn.h"
22 #include "platform/PlatformMutex.h"
23 #include "platform/NonCopyable.h"
24 
25 namespace mbed {
26 /**
27  * \defgroup drivers_BusIn BusIn class
28  * \ingroup drivers-public-api-gpio
29  * @{
30  */
31 
32 /** A digital input bus, used for reading the state of a collection of pins
33  *
34  * @note Synchronization level: Thread safe
35  */
36 class BusIn : private NonCopyable<BusIn> {
37 
38 public:
39  /* Group: Configuration Methods */
40 
41  /** Create an BusIn, connected to the specified pins
42  *
43  * @param p0 DigitalIn pin to connect to bus bit
44  * @param p1 DigitalIn pin to connect to bus bit
45  * @param p2 DigitalIn pin to connect to bus bit
46  * @param p3 DigitalIn pin to connect to bus bit
47  * @param p4 DigitalIn pin to connect to bus bit
48  * @param p5 DigitalIn pin to connect to bus bit
49  * @param p6 DigitalIn pin to connect to bus bit
50  * @param p7 DigitalIn pin to connect to bus bit
51  * @param p8 DigitalIn pin to connect to bus bit
52  * @param p9 DigitalIn pin to connect to bus bit
53  * @param p10 DigitalIn pin to connect to bus bit
54  * @param p11 DigitalIn pin to connect to bus bit
55  * @param p12 DigitalIn pin to connect to bus bit
56  * @param p13 DigitalIn pin to connect to bus bit
57  * @param p14 DigitalIn pin to connect to bus bit
58  * @param p15 DigitalIn pin to connect to bus bit
59  *
60  * @note
61  * It is only required to specify as many pin variables as is required
62  * for the bus; the rest will default to NC (not connected)
63  */
64  BusIn(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
65  PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
66  PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
67  PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
68 
69 
70  /** Create an BusIn, connected to the specified pins
71  *
72  * @param pins An array of pins to connect to bus bit
73  */
74  BusIn(PinName pins[16]);
75 
76  virtual ~BusIn();
77 
78  /** Read the value of the input bus
79  *
80  * @returns
81  * An integer with each bit corresponding to the value read from the associated DigitalIn pin
82  */
83  int read();
84 
85  /** Set the input pin mode
86  *
87  * @param pull PullUp, PullDown, PullNone
88  */
89  void mode(PinMode pull);
90 
91  /** Binary mask of bus pins connected to actual pins (not NC pins)
92  * If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
93  *
94  * @returns
95  * Binary mask of connected pins
96  */
97  int mask()
98  {
99  // No lock needed since _nc_mask is not modified outside the constructor
100  return _nc_mask;
101  }
102 
103  /** A shorthand for read()
104  * \sa DigitalIn::read()
105  */
106  operator int();
107 
108  /** Access to particular bit in random-iterator fashion
109  * @param index Position of bit
110  */
111  DigitalIn &operator[](int index);
112 
113 #if !defined(DOXYGEN_ONLY)
114 protected:
115  DigitalIn *_pin[16];
116 
117  /* Mask of bus's NC pins
118  * If bit[n] is set to 1 - pin is connected
119  * if bit[n] is cleared - pin is not connected (NC)
120  */
121  int _nc_mask;
122 
123  PlatformMutex _mutex;
124 
125 private:
126  virtual void lock();
127  virtual void unlock();
128 #endif
129 };
130 
131 /** @}*/
132 
133 } // namespace mbed
134 
135 #endif
136 
A digital input bus, used for reading the state of a collection of pins.
Definition: BusIn.h:36
DigitalIn & operator[](int index)
Access to particular bit in random-iterator fashion.
int mask()
Binary mask of bus pins connected to actual pins (not NC pins) If bus pin is in NC state make corresp...
Definition: BusIn.h:97
void mode(PinMode pull)
Set the input pin mode.
Prevents generation of copy constructor and copy assignment operator in derived classes.
Definition: NonCopyable.h:162
The PlatformMutex class is used to synchronize the execution of threads.
Definition: PlatformMutex.h:47
BusIn(PinName p0, PinName p1=NC, PinName p2=NC, PinName p3=NC, PinName p4=NC, PinName p5=NC, PinName p6=NC, PinName p7=NC, PinName p8=NC, PinName p9=NC, PinName p10=NC, PinName p11=NC, PinName p12=NC, PinName p13=NC, PinName p14=NC, PinName p15=NC)
Create an BusIn, connected to the specified pins.
int read()
Read the value of the input bus.
A digital input, used for reading the state of a pin.
Definition: DigitalIn.h:54
Definition: ATHandler.h:46
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.