mbed-os

Fork of mbed-os by erkin yucel

Committer:
xuaner
Date:
Thu Jul 20 14:26:57 2017 +0000
Revision:
1:3deb71413561
Parent:
0:f269e3021894
mbed_os

Who changed what in which revision?

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