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