initial

Dependencies:   mbed

Committer:
yihui
Date:
Mon Jan 11 02:32:24 2016 +0000
Revision:
0:638edba3adf6
initial

Who changed what in which revision?

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