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