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