Mbed OS Reference
Loading...
Searching...
No Matches
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 "rtos/Mutex.h"
22#include "platform/NonCopyable.h"
23
24namespace mbed {
25/**
26 * \defgroup drivers_BusOut BusOut class
27 * \ingroup drivers-public-api-gpio
28 * @{
29 */
30
31/** A digital output bus, used for setting the state of a collection of pins
32 */
33class BusOut : private NonCopyable<BusOut> {
34
35public:
36
37 /** Create an BusOut, connected to the specified pins
38 *
39 * @param p0 DigitalOut pin to connect to bus bit
40 * @param p1 DigitalOut pin to connect to bus bit
41 * @param p2 DigitalOut pin to connect to bus bit
42 * @param p3 DigitalOut pin to connect to bus bit
43 * @param p4 DigitalOut pin to connect to bus bit
44 * @param p5 DigitalOut pin to connect to bus bit
45 * @param p6 DigitalOut pin to connect to bus bit
46 * @param p7 DigitalOut pin to connect to bus bit
47 * @param p8 DigitalOut pin to connect to bus bit
48 * @param p9 DigitalOut pin to connect to bus bit
49 * @param p10 DigitalOut pin to connect to bus bit
50 * @param p11 DigitalOut pin to connect to bus bit
51 * @param p12 DigitalOut pin to connect to bus bit
52 * @param p13 DigitalOut pin to connect to bus bit
53 * @param p14 DigitalOut pin to connect to bus bit
54 * @param p15 DigitalOut pin to connect to bus bit
55 *
56 * @note Synchronization level: Thread safe
57 *
58 * @note
59 * It is only required to specify as many pin variables as is required
60 * for the bus; the rest will default to NC (not connected)
61 */
62 BusOut(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
63 PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
64 PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
65 PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
66
67 /** Create an BusOut, connected to the specified pins
68 *
69 * @param pins An array of pins to connect to bus the bit
70 */
71 BusOut(PinName pins[16]);
72
73 virtual ~BusOut();
74
75 /** Write the value to the output bus
76 *
77 * @param value An integer specifying a bit to write for every corresponding DigitalOut pin
78 */
79 void write(int value);
80
81 /** Read the value currently output on the bus
82 *
83 * @returns
84 * An integer with each bit corresponding to associated DigitalOut pin setting
85 */
86 int read();
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 write()
101 * \sa BusOut::write()
102 */
104 BusOut &operator= (BusOut &rhs);
105
106 /** Access to particular bit in random-iterator fashion
107 * @param index Bit Position
108 */
110
111 /** A shorthand for read()
112 * \sa BusOut::read()
113 */
114 operator int();
115#if !defined(DOXYGEN_ONLY)
116protected:
117 virtual void lock();
118 virtual void unlock();
119 DigitalOut *_pin[16];
120
121 /* Mask of bus's NC pins
122 * If bit[n] is set to 1 - pin is connected
123 * if bit[n] is cleared - pin is not connected (NC)
124 */
125 int _nc_mask;
126
127 rtos::Mutex _mutex;
128#endif
129};
130
131/** @}*/
132
133} // namespace mbed
134
135#endif
A digital output bus, used for setting the state of a collection of pins.
Definition: BusOut.h:33
BusOut(PinName pins[16])
Create an BusOut, connected to the specified pins.
void write(int value)
Write the value to the output bus.
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.
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:94
int read()
Read the value currently output on the bus.
DigitalOut & operator[](int index)
Access to particular bit in random-iterator fashion.
BusOut & operator=(int v)
A shorthand for write()
A digital output, used for setting the state of a pin.
Definition: DigitalOut.h:55
Prevents generation of copy constructor and copy assignment operator in derived classes.
Definition: NonCopyable.h:162
The Mutex class is used to synchronize the execution of threads.
Definition: Mutex.h:70