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