initial

Dependencies:   mbed

Committer:
yihui
Date:
Mon Jan 11 02:32:24 2016 +0000
Revision:
0:638edba3adf6
initial

Who changed what in which revision?

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