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