Home Alert System

Dependencies:   PWM_Tone_Library DHT

Committer:
aziz111
Date:
Fri Mar 08 17:15:02 2019 +0000
Revision:
5:569a4894abc1
Parent:
3:78f223d34f36
Final

Who changed what in which revision?

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