]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/api/BusIn.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / api / BusIn.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_BUSIN_H
17 #define MBED_BUSIN_H
18
19 #include "platform.h"
20 #include "DigitalIn.h"
21
22 namespace mbed {
23
24 /** A digital input bus, used for reading the state of a collection of pins
25  */
26 class BusIn {
27
28 public:
29     /* Group: Configuration Methods */
30
31     /** Create an BusIn, connected to the specified pins
32      *
33      * @param <n> DigitalIn pin to connect to bus bit <n> (p5-p30, NC)
34      *
35      * @note
36      *  It is only required to specify as many pin variables as is required
37      *  for the bus; the rest will default to NC (not connected)
38      */
39     BusIn(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
40           PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
41           PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
42           PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
43
44     BusIn(PinName pins[16]);
45
46     virtual ~BusIn();
47
48     /** Read the value of the input bus
49      *
50      *  @returns
51      *   An integer with each bit corresponding to the value read from the associated DigitalIn pin
52      */
53     int read();
54
55     /** Set the input pin mode
56      *
57      *  @param mode PullUp, PullDown, PullNone
58      */
59     void mode(PinMode pull);
60
61     /** Binary mask of bus pins connected to actual pins (not NC pins)
62      *  If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
63      *
64      *  @returns
65      *    Binary mask of connected pins
66      */
67     int mask() {
68         return _nc_mask;
69     }
70
71 #ifdef MBED_OPERATORS
72     /** A shorthand for read()
73      */
74     operator int();
75
76     /** Access to particular bit in random-iterator fashion
77      */
78     DigitalIn & operator[] (int index);
79 #endif
80
81 protected:
82     DigitalIn* _pin[16];
83
84     /** Mask of bus's NC pins
85      * If bit[n] is set to 1 - pin is connected
86      * if bit[n] is cleared - pin is not connected (NC)
87      */
88     int _nc_mask;
89
90     /* disallow copy constructor and assignment operators */
91 private:
92     BusIn(const BusIn&);
93     BusIn & operator = (const BusIn&);
94 };
95
96 } // namespace mbed
97
98 #endif