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