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