IoT Home Alarm System

Dependents:   IoTBurglar_and_Fire_AlarmSystem

Committer:
kbrahmbhatt6
Date:
Fri Apr 29 06:59:59 2016 +0000
Revision:
0:2f388b030837
1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kbrahmbhatt6 0:2f388b030837 1 /* mbed Microcontroller Library
kbrahmbhatt6 0:2f388b030837 2 * Copyright (c) 2006-2013 ARM Limited
kbrahmbhatt6 0:2f388b030837 3 *
kbrahmbhatt6 0:2f388b030837 4 * Licensed under the Apache License, Version 2.0 (the "License");
kbrahmbhatt6 0:2f388b030837 5 * you may not use this file except in compliance with the License.
kbrahmbhatt6 0:2f388b030837 6 * You may obtain a copy of the License at
kbrahmbhatt6 0:2f388b030837 7 *
kbrahmbhatt6 0:2f388b030837 8 * http://www.apache.org/licenses/LICENSE-2.0
kbrahmbhatt6 0:2f388b030837 9 *
kbrahmbhatt6 0:2f388b030837 10 * Unless required by applicable law or agreed to in writing, software
kbrahmbhatt6 0:2f388b030837 11 * distributed under the License is distributed on an "AS IS" BASIS,
kbrahmbhatt6 0:2f388b030837 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kbrahmbhatt6 0:2f388b030837 13 * See the License for the specific language governing permissions and
kbrahmbhatt6 0:2f388b030837 14 * limitations under the License.
kbrahmbhatt6 0:2f388b030837 15 */
kbrahmbhatt6 0:2f388b030837 16 #ifndef MBED_PORTINOUT_H
kbrahmbhatt6 0:2f388b030837 17 #define MBED_PORTINOUT_H
kbrahmbhatt6 0:2f388b030837 18
kbrahmbhatt6 0:2f388b030837 19 #include "platform.h"
kbrahmbhatt6 0:2f388b030837 20
kbrahmbhatt6 0:2f388b030837 21 #if DEVICE_PORTINOUT
kbrahmbhatt6 0:2f388b030837 22
kbrahmbhatt6 0:2f388b030837 23 #include "port_api.h"
kbrahmbhatt6 0:2f388b030837 24
kbrahmbhatt6 0:2f388b030837 25 namespace mbed {
kbrahmbhatt6 0:2f388b030837 26
kbrahmbhatt6 0:2f388b030837 27 /** A multiple pin digital in/out used to set/read multiple bi-directional pins
kbrahmbhatt6 0:2f388b030837 28 */
kbrahmbhatt6 0:2f388b030837 29 class PortInOut {
kbrahmbhatt6 0:2f388b030837 30 public:
kbrahmbhatt6 0:2f388b030837 31
kbrahmbhatt6 0:2f388b030837 32 /** Create an PortInOut, connected to the specified port
kbrahmbhatt6 0:2f388b030837 33 *
kbrahmbhatt6 0:2f388b030837 34 * @param port Port to connect to (Port0-Port5)
kbrahmbhatt6 0:2f388b030837 35 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
kbrahmbhatt6 0:2f388b030837 36 */
kbrahmbhatt6 0:2f388b030837 37 PortInOut(PortName port, int mask = 0xFFFFFFFF) {
kbrahmbhatt6 0:2f388b030837 38 port_init(&_port, port, mask, PIN_INPUT);
kbrahmbhatt6 0:2f388b030837 39 }
kbrahmbhatt6 0:2f388b030837 40
kbrahmbhatt6 0:2f388b030837 41 /** Write the value to the output port
kbrahmbhatt6 0:2f388b030837 42 *
kbrahmbhatt6 0:2f388b030837 43 * @param value An integer specifying a bit to write for every corresponding port pin
kbrahmbhatt6 0:2f388b030837 44 */
kbrahmbhatt6 0:2f388b030837 45 void write(int value) {
kbrahmbhatt6 0:2f388b030837 46 port_write(&_port, value);
kbrahmbhatt6 0:2f388b030837 47 }
kbrahmbhatt6 0:2f388b030837 48
kbrahmbhatt6 0:2f388b030837 49 /** Read the value currently output on the port
kbrahmbhatt6 0:2f388b030837 50 *
kbrahmbhatt6 0:2f388b030837 51 * @returns
kbrahmbhatt6 0:2f388b030837 52 * An integer with each bit corresponding to associated port pin setting
kbrahmbhatt6 0:2f388b030837 53 */
kbrahmbhatt6 0:2f388b030837 54 int read() {
kbrahmbhatt6 0:2f388b030837 55 return port_read(&_port);
kbrahmbhatt6 0:2f388b030837 56 }
kbrahmbhatt6 0:2f388b030837 57
kbrahmbhatt6 0:2f388b030837 58 /** Set as an output
kbrahmbhatt6 0:2f388b030837 59 */
kbrahmbhatt6 0:2f388b030837 60 void output() {
kbrahmbhatt6 0:2f388b030837 61 port_dir(&_port, PIN_OUTPUT);
kbrahmbhatt6 0:2f388b030837 62 }
kbrahmbhatt6 0:2f388b030837 63
kbrahmbhatt6 0:2f388b030837 64 /** Set as an input
kbrahmbhatt6 0:2f388b030837 65 */
kbrahmbhatt6 0:2f388b030837 66 void input() {
kbrahmbhatt6 0:2f388b030837 67 port_dir(&_port, PIN_INPUT);
kbrahmbhatt6 0:2f388b030837 68 }
kbrahmbhatt6 0:2f388b030837 69
kbrahmbhatt6 0:2f388b030837 70 /** Set the input pin mode
kbrahmbhatt6 0:2f388b030837 71 *
kbrahmbhatt6 0:2f388b030837 72 * @param mode PullUp, PullDown, PullNone, OpenDrain
kbrahmbhatt6 0:2f388b030837 73 */
kbrahmbhatt6 0:2f388b030837 74 void mode(PinMode mode) {
kbrahmbhatt6 0:2f388b030837 75 port_mode(&_port, mode);
kbrahmbhatt6 0:2f388b030837 76 }
kbrahmbhatt6 0:2f388b030837 77
kbrahmbhatt6 0:2f388b030837 78 /** A shorthand for write()
kbrahmbhatt6 0:2f388b030837 79 */
kbrahmbhatt6 0:2f388b030837 80 PortInOut& operator= (int value) {
kbrahmbhatt6 0:2f388b030837 81 write(value);
kbrahmbhatt6 0:2f388b030837 82 return *this;
kbrahmbhatt6 0:2f388b030837 83 }
kbrahmbhatt6 0:2f388b030837 84
kbrahmbhatt6 0:2f388b030837 85 PortInOut& operator= (PortInOut& rhs) {
kbrahmbhatt6 0:2f388b030837 86 write(rhs.read());
kbrahmbhatt6 0:2f388b030837 87 return *this;
kbrahmbhatt6 0:2f388b030837 88 }
kbrahmbhatt6 0:2f388b030837 89
kbrahmbhatt6 0:2f388b030837 90 /** A shorthand for read()
kbrahmbhatt6 0:2f388b030837 91 */
kbrahmbhatt6 0:2f388b030837 92 operator int() {
kbrahmbhatt6 0:2f388b030837 93 return read();
kbrahmbhatt6 0:2f388b030837 94 }
kbrahmbhatt6 0:2f388b030837 95
kbrahmbhatt6 0:2f388b030837 96 private:
kbrahmbhatt6 0:2f388b030837 97 port_t _port;
kbrahmbhatt6 0:2f388b030837 98 };
kbrahmbhatt6 0:2f388b030837 99
kbrahmbhatt6 0:2f388b030837 100 } // namespace mbed
kbrahmbhatt6 0:2f388b030837 101
kbrahmbhatt6 0:2f388b030837 102 #endif
kbrahmbhatt6 0:2f388b030837 103
kbrahmbhatt6 0:2f388b030837 104 #endif