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