Official Sheffield ARMBand micro:bit program

Committer:
MrBedfordVan
Date:
Mon Oct 17 12:41:20 2016 +0000
Revision:
0:b9164b348919
Official Sheffield ARMBand Micro:bit program

Who changed what in which revision?

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