]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/api/BusOut.h
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / api / BusOut.h
1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #ifndef MBED_BUSOUT_H
17 #define MBED_BUSOUT_H
18
19 #include "DigitalOut.h"
20
21 namespace mbed {
22
23 /** A digital output bus, used for setting the state of a collection of pins
24 */
25 class BusOut {
26
27 public:
28
29 /** Create an BusOut, connected to the specified pins
30 *
31 * @param p<n> DigitalOut pin to connect to bus bit <n> (p5-p30, NC)
32 *
33 * @note
34 * It is only required to specify as many pin variables as is required
35 * for the bus; the rest will default to NC (not connected)
36 */
37 BusOut(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
38 PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
39 PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
40 PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
41
42 BusOut(PinName pins[16]);
43
44 virtual ~BusOut();
45
46 /** Write the value to the output bus
47 *
48 * @param value An integer specifying a bit to write for every corresponding DigitalOut pin
49 */
50 void write(int value);
51
52 /** Read the value currently output on the bus
53 *
54 * @returns
55 * An integer with each bit corresponding to associated DigitalOut pin setting
56 */
57 int read();
58
59 /** Binary mask of bus pins connected to actual pins (not NC pins)
60 * If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
61 *
62 * @returns
63 * Binary mask of connected pins
64 */
65 int mask() {
66 return _nc_mask;
67 }
68
69 #ifdef MBED_OPERATORS
70 /** A shorthand for write()
71 */
72 BusOut& operator= (int v);
73 BusOut& operator= (BusOut& rhs);
74
75 /** Access to particular bit in random-iterator fashion
76 */
77 DigitalOut& operator[] (int index);
78
79 /** A shorthand for read()
80 */
81 operator int();
82 #endif
83
84 protected:
85 DigitalOut* _pin[16];
86
87 /** Mask of bus's NC pins
88 * If bit[n] is set to 1 - pin is connected
89 * if bit[n] is cleared - pin is not connected (NC)
90 */
91 int _nc_mask;
92
93 /* disallow copy constructor and assignment operators */
94 private:
95 BusOut(const BusOut&);
96 BusOut & operator = (const BusOut&);
97 };
98
99 } // namespace mbed
100
101 #endif
Imprint / Impressum