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_PORTINOUT_H
MrBedfordVan 0:b9164b348919 17 #define MBED_PORTINOUT_H
MrBedfordVan 0:b9164b348919 18
MrBedfordVan 0:b9164b348919 19 #include "platform.h"
MrBedfordVan 0:b9164b348919 20
MrBedfordVan 0:b9164b348919 21 #if DEVICE_PORTINOUT
MrBedfordVan 0:b9164b348919 22
MrBedfordVan 0:b9164b348919 23 #include "port_api.h"
MrBedfordVan 0:b9164b348919 24
MrBedfordVan 0:b9164b348919 25 namespace mbed {
MrBedfordVan 0:b9164b348919 26
MrBedfordVan 0:b9164b348919 27 /** A multiple pin digital in/out used to set/read multiple bi-directional pins
MrBedfordVan 0:b9164b348919 28 */
MrBedfordVan 0:b9164b348919 29 class PortInOut {
MrBedfordVan 0:b9164b348919 30 public:
MrBedfordVan 0:b9164b348919 31
MrBedfordVan 0:b9164b348919 32 /** Create an PortInOut, connected to the specified port
MrBedfordVan 0:b9164b348919 33 *
MrBedfordVan 0:b9164b348919 34 * @param port Port to connect to (Port0-Port5)
MrBedfordVan 0:b9164b348919 35 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
MrBedfordVan 0:b9164b348919 36 */
MrBedfordVan 0:b9164b348919 37 PortInOut(PortName port, int mask = 0xFFFFFFFF) {
MrBedfordVan 0:b9164b348919 38 port_init(&_port, port, mask, PIN_INPUT);
MrBedfordVan 0:b9164b348919 39 }
MrBedfordVan 0:b9164b348919 40
MrBedfordVan 0:b9164b348919 41 /** Write the value to the output port
MrBedfordVan 0:b9164b348919 42 *
MrBedfordVan 0:b9164b348919 43 * @param value An integer specifying a bit to write for every corresponding port pin
MrBedfordVan 0:b9164b348919 44 */
MrBedfordVan 0:b9164b348919 45 void write(int value) {
MrBedfordVan 0:b9164b348919 46 port_write(&_port, value);
MrBedfordVan 0:b9164b348919 47 }
MrBedfordVan 0:b9164b348919 48
MrBedfordVan 0:b9164b348919 49 /** Read the value currently output on the port
MrBedfordVan 0:b9164b348919 50 *
MrBedfordVan 0:b9164b348919 51 * @returns
MrBedfordVan 0:b9164b348919 52 * An integer with each bit corresponding to associated port pin setting
MrBedfordVan 0:b9164b348919 53 */
MrBedfordVan 0:b9164b348919 54 int read() {
MrBedfordVan 0:b9164b348919 55 return port_read(&_port);
MrBedfordVan 0:b9164b348919 56 }
MrBedfordVan 0:b9164b348919 57
MrBedfordVan 0:b9164b348919 58 /** Set as an output
MrBedfordVan 0:b9164b348919 59 */
MrBedfordVan 0:b9164b348919 60 void output() {
MrBedfordVan 0:b9164b348919 61 port_dir(&_port, PIN_OUTPUT);
MrBedfordVan 0:b9164b348919 62 }
MrBedfordVan 0:b9164b348919 63
MrBedfordVan 0:b9164b348919 64 /** Set as an input
MrBedfordVan 0:b9164b348919 65 */
MrBedfordVan 0:b9164b348919 66 void input() {
MrBedfordVan 0:b9164b348919 67 port_dir(&_port, PIN_INPUT);
MrBedfordVan 0:b9164b348919 68 }
MrBedfordVan 0:b9164b348919 69
MrBedfordVan 0:b9164b348919 70 /** Set the input pin mode
MrBedfordVan 0:b9164b348919 71 *
MrBedfordVan 0:b9164b348919 72 * @param mode PullUp, PullDown, PullNone, OpenDrain
MrBedfordVan 0:b9164b348919 73 */
MrBedfordVan 0:b9164b348919 74 void mode(PinMode mode) {
MrBedfordVan 0:b9164b348919 75 port_mode(&_port, mode);
MrBedfordVan 0:b9164b348919 76 }
MrBedfordVan 0:b9164b348919 77
MrBedfordVan 0:b9164b348919 78 /** A shorthand for write()
MrBedfordVan 0:b9164b348919 79 */
MrBedfordVan 0:b9164b348919 80 PortInOut& operator= (int value) {
MrBedfordVan 0:b9164b348919 81 write(value);
MrBedfordVan 0:b9164b348919 82 return *this;
MrBedfordVan 0:b9164b348919 83 }
MrBedfordVan 0:b9164b348919 84
MrBedfordVan 0:b9164b348919 85 PortInOut& operator= (PortInOut& rhs) {
MrBedfordVan 0:b9164b348919 86 write(rhs.read());
MrBedfordVan 0:b9164b348919 87 return *this;
MrBedfordVan 0:b9164b348919 88 }
MrBedfordVan 0:b9164b348919 89
MrBedfordVan 0:b9164b348919 90 /** A shorthand for read()
MrBedfordVan 0:b9164b348919 91 */
MrBedfordVan 0:b9164b348919 92 operator int() {
MrBedfordVan 0:b9164b348919 93 return read();
MrBedfordVan 0:b9164b348919 94 }
MrBedfordVan 0:b9164b348919 95
MrBedfordVan 0:b9164b348919 96 private:
MrBedfordVan 0:b9164b348919 97 port_t _port;
MrBedfordVan 0:b9164b348919 98 };
MrBedfordVan 0:b9164b348919 99
MrBedfordVan 0:b9164b348919 100 } // namespace mbed
MrBedfordVan 0:b9164b348919 101
MrBedfordVan 0:b9164b348919 102 #endif
MrBedfordVan 0:b9164b348919 103
MrBedfordVan 0:b9164b348919 104 #endif