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 /** \addtogroup drivers */
27 
28 /** A digital input bus, used for reading the state of a collection of pins
29  *
30  * @note Synchronization level: Thread safe
31  * @ingroup drivers
32  */
33 class BusIn : private NonCopyable<BusIn> {
34 
35 public:
36  /* Group: Configuration Methods */
37 
38  /** Create an BusIn, connected to the specified pins
39  *
40  * @param p0 DigitalIn pin to connect to bus bit
41  * @param p1 DigitalIn pin to connect to bus bit
42  * @param p2 DigitalIn pin to connect to bus bit
43  * @param p3 DigitalIn pin to connect to bus bit
44  * @param p4 DigitalIn pin to connect to bus bit
45  * @param p5 DigitalIn pin to connect to bus bit
46  * @param p6 DigitalIn pin to connect to bus bit
47  * @param p7 DigitalIn pin to connect to bus bit
48  * @param p8 DigitalIn pin to connect to bus bit
49  * @param p9 DigitalIn pin to connect to bus bit
50  * @param p10 DigitalIn pin to connect to bus bit
51  * @param p11 DigitalIn pin to connect to bus bit
52  * @param p12 DigitalIn pin to connect to bus bit
53  * @param p13 DigitalIn pin to connect to bus bit
54  * @param p14 DigitalIn pin to connect to bus bit
55  * @param p15 DigitalIn pin to connect to bus bit
56  *
57  * @note
58  * It is only required to specify as many pin variables as is required
59  * for the bus; the rest will default to NC (not connected)
60  */
61  BusIn(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
62  PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
63  PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
64  PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
65 
66 
67  /** Create an BusIn, connected to the specified pins
68  *
69  * @param pins An array of pins to connect to bus bit
70  */
71  BusIn(PinName pins[16]);
72 
73  virtual ~BusIn();
74 
75  /** Read the value of the input bus
76  *
77  * @returns
78  * An integer with each bit corresponding to the value read from the associated DigitalIn pin
79  */
80  int read();
81 
82  /** Set the input pin mode
83  *
84  * @param pull PullUp, PullDown, PullNone
85  */
86  void mode(PinMode pull);
87 
88  /** Binary mask of bus pins connected to actual pins (not NC pins)
89  * If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
90  *
91  * @returns
92  * Binary mask of connected pins
93  */
94  int mask()
95  {
96  // No lock needed since _nc_mask is not modified outside the constructor
97  return _nc_mask;
98  }
99 
100  /** A shorthand for read()
101  * \sa DigitalIn::read()
102  */
103  operator int();
104 
105  /** Access to particular bit in random-iterator fashion
106  * @param index Position of bit
107  */
108  DigitalIn &operator[](int index);
109 
110 #if !defined(DOXYGEN_ONLY)
111 protected:
112  DigitalIn *_pin[16];
113 
114  /* Mask of bus's NC pins
115  * If bit[n] is set to 1 - pin is connected
116  * if bit[n] is cleared - pin is not connected (NC)
117  */
118  int _nc_mask;
119 
120  PlatformMutex _mutex;
121 
122 private:
123  virtual void lock();
124  virtual void unlock();
125 #endif
126 };
127 
128 } // namespace mbed
129 
130 #endif
131 
A digital input bus, used for reading the state of a collection of pins.
Definition: BusIn.h:33
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:94
void mode(PinMode pull)
Set the input pin mode.
Prevents generation of copy constructor and copy assignment operator in derived classes.
Definition: NonCopyable.h:168
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:52
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.