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