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