Home Alert System

Dependencies:   PWM_Tone_Library DHT

Committer:
ethaderu
Date:
Tue Mar 05 02:34:44 2019 +0000
Revision:
3:78f223d34f36
Publish 1

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_BUSINOUT_H
ethaderu 3:78f223d34f36 17 #define MBED_BUSINOUT_H
ethaderu 3:78f223d34f36 18
ethaderu 3:78f223d34f36 19 #include "DigitalInOut.h"
ethaderu 3:78f223d34f36 20
ethaderu 3:78f223d34f36 21 namespace mbed {
ethaderu 3:78f223d34f36 22
ethaderu 3:78f223d34f36 23 /** A digital input output bus, used for setting the state of a collection of pins
ethaderu 3:78f223d34f36 24 */
ethaderu 3:78f223d34f36 25 class BusInOut {
ethaderu 3:78f223d34f36 26
ethaderu 3:78f223d34f36 27 public:
ethaderu 3:78f223d34f36 28
ethaderu 3:78f223d34f36 29 /** Create an BusInOut, connected to the specified pins
ethaderu 3:78f223d34f36 30 *
ethaderu 3:78f223d34f36 31 * @param p<n> DigitalInOut pin to connect to bus bit p<n> (p5-p30, NC)
ethaderu 3:78f223d34f36 32 *
ethaderu 3:78f223d34f36 33 * @note
ethaderu 3:78f223d34f36 34 * It is only required to specify as many pin variables as is required
ethaderu 3:78f223d34f36 35 * for the bus; the rest will default to NC (not connected)
ethaderu 3:78f223d34f36 36 */
ethaderu 3:78f223d34f36 37 BusInOut(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
ethaderu 3:78f223d34f36 38 PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
ethaderu 3:78f223d34f36 39 PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
ethaderu 3:78f223d34f36 40 PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
ethaderu 3:78f223d34f36 41
ethaderu 3:78f223d34f36 42 BusInOut(PinName pins[16]);
ethaderu 3:78f223d34f36 43
ethaderu 3:78f223d34f36 44 virtual ~BusInOut();
ethaderu 3:78f223d34f36 45
ethaderu 3:78f223d34f36 46 /* Group: Access Methods */
ethaderu 3:78f223d34f36 47
ethaderu 3:78f223d34f36 48 /** Write the value to the output bus
ethaderu 3:78f223d34f36 49 *
ethaderu 3:78f223d34f36 50 * @param value An integer specifying a bit to write for every corresponding DigitalInOut pin
ethaderu 3:78f223d34f36 51 */
ethaderu 3:78f223d34f36 52 void write(int value);
ethaderu 3:78f223d34f36 53
ethaderu 3:78f223d34f36 54 /** Read the value currently output on the bus
ethaderu 3:78f223d34f36 55 *
ethaderu 3:78f223d34f36 56 * @returns
ethaderu 3:78f223d34f36 57 * An integer with each bit corresponding to associated DigitalInOut pin setting
ethaderu 3:78f223d34f36 58 */
ethaderu 3:78f223d34f36 59 int read();
ethaderu 3:78f223d34f36 60
ethaderu 3:78f223d34f36 61 /** Set as an output
ethaderu 3:78f223d34f36 62 */
ethaderu 3:78f223d34f36 63 void output();
ethaderu 3:78f223d34f36 64
ethaderu 3:78f223d34f36 65 /** Set as an input
ethaderu 3:78f223d34f36 66 */
ethaderu 3:78f223d34f36 67 void input();
ethaderu 3:78f223d34f36 68
ethaderu 3:78f223d34f36 69 /** Set the input pin mode
ethaderu 3:78f223d34f36 70 *
ethaderu 3:78f223d34f36 71 * @param mode PullUp, PullDown, PullNone
ethaderu 3:78f223d34f36 72 */
ethaderu 3:78f223d34f36 73 void mode(PinMode pull);
ethaderu 3:78f223d34f36 74
ethaderu 3:78f223d34f36 75 /** Binary mask of bus pins connected to actual pins (not NC pins)
ethaderu 3:78f223d34f36 76 * If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
ethaderu 3:78f223d34f36 77 *
ethaderu 3:78f223d34f36 78 * @returns
ethaderu 3:78f223d34f36 79 * Binary mask of connected pins
ethaderu 3:78f223d34f36 80 */
ethaderu 3:78f223d34f36 81 int mask() {
ethaderu 3:78f223d34f36 82 return _nc_mask;
ethaderu 3:78f223d34f36 83 }
ethaderu 3:78f223d34f36 84
ethaderu 3:78f223d34f36 85 #ifdef MBED_OPERATORS
ethaderu 3:78f223d34f36 86 /** A shorthand for write()
ethaderu 3:78f223d34f36 87 */
ethaderu 3:78f223d34f36 88 BusInOut& operator= (int v);
ethaderu 3:78f223d34f36 89 BusInOut& operator= (BusInOut& rhs);
ethaderu 3:78f223d34f36 90
ethaderu 3:78f223d34f36 91 /** Access to particular bit in random-iterator fashion
ethaderu 3:78f223d34f36 92 */
ethaderu 3:78f223d34f36 93 DigitalInOut& operator[] (int index);
ethaderu 3:78f223d34f36 94
ethaderu 3:78f223d34f36 95 /** A shorthand for read()
ethaderu 3:78f223d34f36 96 */
ethaderu 3:78f223d34f36 97 operator int();
ethaderu 3:78f223d34f36 98 #endif
ethaderu 3:78f223d34f36 99
ethaderu 3:78f223d34f36 100 protected:
ethaderu 3:78f223d34f36 101 DigitalInOut* _pin[16];
ethaderu 3:78f223d34f36 102
ethaderu 3:78f223d34f36 103 /** Mask of bus's NC pins
ethaderu 3:78f223d34f36 104 * If bit[n] is set to 1 - pin is connected
ethaderu 3:78f223d34f36 105 * if bit[n] is cleared - pin is not connected (NC)
ethaderu 3:78f223d34f36 106 */
ethaderu 3:78f223d34f36 107 int _nc_mask;
ethaderu 3:78f223d34f36 108
ethaderu 3:78f223d34f36 109 /* disallow copy constructor and assignment operators */
ethaderu 3:78f223d34f36 110 private:
ethaderu 3:78f223d34f36 111 BusInOut(const BusInOut&);
ethaderu 3:78f223d34f36 112 BusInOut & operator = (const BusInOut&);
ethaderu 3:78f223d34f36 113 };
ethaderu 3:78f223d34f36 114
ethaderu 3:78f223d34f36 115 } // namespace mbed
ethaderu 3:78f223d34f36 116
ethaderu 3:78f223d34f36 117 #endif