mbed library for NZ32-SC151

Committer:
modtronix
Date:
Fri Jul 24 21:01:44 2015 +1000
Revision:
1:71204b8406f2
Current mbed v103 (594)

Who changed what in which revision?

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