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/BusInOut.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_BUSINOUT_H |
dgabino | 0:c76361bd82e8 | 17 | #define MBED_BUSINOUT_H |
dgabino | 0:c76361bd82e8 | 18 | |
dgabino | 0:c76361bd82e8 | 19 | #include "DigitalInOut.h" |
dgabino | 0:c76361bd82e8 | 20 | #include "PlatformMutex.h" |
dgabino | 0:c76361bd82e8 | 21 | |
dgabino | 0:c76361bd82e8 | 22 | namespace mbed { |
dgabino | 0:c76361bd82e8 | 23 | |
dgabino | 0:c76361bd82e8 | 24 | /** A digital input output bus, used for setting the state of a collection of pins |
dgabino | 0:c76361bd82e8 | 25 | * |
dgabino | 0:c76361bd82e8 | 26 | * @Note Synchronization level: Thread safe |
dgabino | 0:c76361bd82e8 | 27 | */ |
dgabino | 0:c76361bd82e8 | 28 | class BusInOut { |
dgabino | 0:c76361bd82e8 | 29 | |
dgabino | 0:c76361bd82e8 | 30 | public: |
dgabino | 0:c76361bd82e8 | 31 | |
dgabino | 0:c76361bd82e8 | 32 | /** Create an BusInOut, connected to the specified pins |
dgabino | 0:c76361bd82e8 | 33 | * |
dgabino | 0:c76361bd82e8 | 34 | * @param p<n> DigitalInOut pin to connect to bus bit p<n> (p5-p30, NC) |
dgabino | 0:c76361bd82e8 | 35 | * |
dgabino | 0:c76361bd82e8 | 36 | * @note |
dgabino | 0:c76361bd82e8 | 37 | * It is only required to specify as many pin variables as is required |
dgabino | 0:c76361bd82e8 | 38 | * for the bus; the rest will default to NC (not connected) |
dgabino | 0:c76361bd82e8 | 39 | */ |
dgabino | 0:c76361bd82e8 | 40 | BusInOut(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC, |
dgabino | 0:c76361bd82e8 | 41 | PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC, |
dgabino | 0:c76361bd82e8 | 42 | PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC, |
dgabino | 0:c76361bd82e8 | 43 | PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC); |
dgabino | 0:c76361bd82e8 | 44 | |
dgabino | 0:c76361bd82e8 | 45 | BusInOut(PinName pins[16]); |
dgabino | 0:c76361bd82e8 | 46 | |
dgabino | 0:c76361bd82e8 | 47 | virtual ~BusInOut(); |
dgabino | 0:c76361bd82e8 | 48 | |
dgabino | 0:c76361bd82e8 | 49 | /* Group: Access Methods */ |
dgabino | 0:c76361bd82e8 | 50 | |
dgabino | 0:c76361bd82e8 | 51 | /** Write the value to the output bus |
dgabino | 0:c76361bd82e8 | 52 | * |
dgabino | 0:c76361bd82e8 | 53 | * @param value An integer specifying a bit to write for every corresponding DigitalInOut pin |
dgabino | 0:c76361bd82e8 | 54 | */ |
dgabino | 0:c76361bd82e8 | 55 | void write(int value); |
dgabino | 0:c76361bd82e8 | 56 | |
dgabino | 0:c76361bd82e8 | 57 | /** Read the value currently output on the bus |
dgabino | 0:c76361bd82e8 | 58 | * |
dgabino | 0:c76361bd82e8 | 59 | * @returns |
dgabino | 0:c76361bd82e8 | 60 | * An integer with each bit corresponding to associated DigitalInOut pin setting |
dgabino | 0:c76361bd82e8 | 61 | */ |
dgabino | 0:c76361bd82e8 | 62 | int read(); |
dgabino | 0:c76361bd82e8 | 63 | |
dgabino | 0:c76361bd82e8 | 64 | /** Set as an output |
dgabino | 0:c76361bd82e8 | 65 | */ |
dgabino | 0:c76361bd82e8 | 66 | void output(); |
dgabino | 0:c76361bd82e8 | 67 | |
dgabino | 0:c76361bd82e8 | 68 | /** Set as an input |
dgabino | 0:c76361bd82e8 | 69 | */ |
dgabino | 0:c76361bd82e8 | 70 | void input(); |
dgabino | 0:c76361bd82e8 | 71 | |
dgabino | 0:c76361bd82e8 | 72 | /** Set the input pin mode |
dgabino | 0:c76361bd82e8 | 73 | * |
dgabino | 0:c76361bd82e8 | 74 | * @param mode PullUp, PullDown, PullNone |
dgabino | 0:c76361bd82e8 | 75 | */ |
dgabino | 0:c76361bd82e8 | 76 | void mode(PinMode pull); |
dgabino | 0:c76361bd82e8 | 77 | |
dgabino | 0:c76361bd82e8 | 78 | /** Binary mask of bus pins connected to actual pins (not NC pins) |
dgabino | 0:c76361bd82e8 | 79 | * 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 | 80 | * |
dgabino | 0:c76361bd82e8 | 81 | * @returns |
dgabino | 0:c76361bd82e8 | 82 | * Binary mask of connected pins |
dgabino | 0:c76361bd82e8 | 83 | */ |
dgabino | 0:c76361bd82e8 | 84 | int mask() { |
dgabino | 0:c76361bd82e8 | 85 | // No lock needed since _nc_mask is not modified outside the constructor |
dgabino | 0:c76361bd82e8 | 86 | return _nc_mask; |
dgabino | 0:c76361bd82e8 | 87 | } |
dgabino | 0:c76361bd82e8 | 88 | |
dgabino | 0:c76361bd82e8 | 89 | /** A shorthand for write() |
dgabino | 0:c76361bd82e8 | 90 | */ |
dgabino | 0:c76361bd82e8 | 91 | BusInOut& operator= (int v); |
dgabino | 0:c76361bd82e8 | 92 | BusInOut& operator= (BusInOut& rhs); |
dgabino | 0:c76361bd82e8 | 93 | |
dgabino | 0:c76361bd82e8 | 94 | /** Access to particular bit in random-iterator fashion |
dgabino | 0:c76361bd82e8 | 95 | */ |
dgabino | 0:c76361bd82e8 | 96 | DigitalInOut& operator[] (int index); |
dgabino | 0:c76361bd82e8 | 97 | |
dgabino | 0:c76361bd82e8 | 98 | /** A shorthand for read() |
dgabino | 0:c76361bd82e8 | 99 | */ |
dgabino | 0:c76361bd82e8 | 100 | operator int(); |
dgabino | 0:c76361bd82e8 | 101 | |
dgabino | 0:c76361bd82e8 | 102 | protected: |
dgabino | 0:c76361bd82e8 | 103 | virtual void lock(); |
dgabino | 0:c76361bd82e8 | 104 | virtual void unlock(); |
dgabino | 0:c76361bd82e8 | 105 | DigitalInOut* _pin[16]; |
dgabino | 0:c76361bd82e8 | 106 | |
dgabino | 0:c76361bd82e8 | 107 | /** Mask of bus's NC pins |
dgabino | 0:c76361bd82e8 | 108 | * If bit[n] is set to 1 - pin is connected |
dgabino | 0:c76361bd82e8 | 109 | * if bit[n] is cleared - pin is not connected (NC) |
dgabino | 0:c76361bd82e8 | 110 | */ |
dgabino | 0:c76361bd82e8 | 111 | int _nc_mask; |
dgabino | 0:c76361bd82e8 | 112 | |
dgabino | 0:c76361bd82e8 | 113 | PlatformMutex _mutex; |
dgabino | 0:c76361bd82e8 | 114 | |
dgabino | 0:c76361bd82e8 | 115 | /* disallow copy constructor and assignment operators */ |
dgabino | 0:c76361bd82e8 | 116 | private: |
dgabino | 0:c76361bd82e8 | 117 | BusInOut(const BusInOut&); |
dgabino | 0:c76361bd82e8 | 118 | BusInOut & operator = (const BusInOut&); |
dgabino | 0:c76361bd82e8 | 119 | }; |
dgabino | 0:c76361bd82e8 | 120 | |
dgabino | 0:c76361bd82e8 | 121 | } // namespace mbed |
dgabino | 0:c76361bd82e8 | 122 | |
dgabino | 0:c76361bd82e8 | 123 | #endif |