Home Alert System
Dependencies: PWM_Tone_Library DHT
mbed/PortOut.h@5:569a4894abc1, 2019-03-08 (annotated)
- Committer:
- aziz111
- Date:
- Fri Mar 08 17:15:02 2019 +0000
- Revision:
- 5:569a4894abc1
- Parent:
- 3:78f223d34f36
Final
Who changed what in which revision?
User | Revision | Line number | New 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_PORTOUT_H |
ethaderu | 3:78f223d34f36 | 17 | #define MBED_PORTOUT_H |
ethaderu | 3:78f223d34f36 | 18 | |
ethaderu | 3:78f223d34f36 | 19 | #include "platform.h" |
ethaderu | 3:78f223d34f36 | 20 | |
ethaderu | 3:78f223d34f36 | 21 | #if DEVICE_PORTOUT |
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 | /** A multiple pin digital out |
ethaderu | 3:78f223d34f36 | 27 | * |
ethaderu | 3:78f223d34f36 | 28 | * Example: |
ethaderu | 3:78f223d34f36 | 29 | * @code |
ethaderu | 3:78f223d34f36 | 30 | * // Toggle all four LEDs |
ethaderu | 3:78f223d34f36 | 31 | * |
ethaderu | 3:78f223d34f36 | 32 | * #include "mbed.h" |
ethaderu | 3:78f223d34f36 | 33 | * |
ethaderu | 3:78f223d34f36 | 34 | * // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23 |
ethaderu | 3:78f223d34f36 | 35 | * #define LED_MASK 0x00B40000 |
ethaderu | 3:78f223d34f36 | 36 | * |
ethaderu | 3:78f223d34f36 | 37 | * PortOut ledport(Port1, LED_MASK); |
ethaderu | 3:78f223d34f36 | 38 | * |
ethaderu | 3:78f223d34f36 | 39 | * int main() { |
ethaderu | 3:78f223d34f36 | 40 | * while(1) { |
ethaderu | 3:78f223d34f36 | 41 | * ledport = LED_MASK; |
ethaderu | 3:78f223d34f36 | 42 | * wait(1); |
ethaderu | 3:78f223d34f36 | 43 | * ledport = 0; |
ethaderu | 3:78f223d34f36 | 44 | * wait(1); |
ethaderu | 3:78f223d34f36 | 45 | * } |
ethaderu | 3:78f223d34f36 | 46 | * } |
ethaderu | 3:78f223d34f36 | 47 | * @endcode |
ethaderu | 3:78f223d34f36 | 48 | */ |
ethaderu | 3:78f223d34f36 | 49 | class PortOut { |
ethaderu | 3:78f223d34f36 | 50 | public: |
ethaderu | 3:78f223d34f36 | 51 | |
ethaderu | 3:78f223d34f36 | 52 | /** Create an PortOut, connected to the specified port |
ethaderu | 3:78f223d34f36 | 53 | * |
ethaderu | 3:78f223d34f36 | 54 | * @param port Port to connect to (Port0-Port5) |
ethaderu | 3:78f223d34f36 | 55 | * @param mask A bitmask to identify which bits in the port should be included (0 - ignore) |
ethaderu | 3:78f223d34f36 | 56 | */ |
ethaderu | 3:78f223d34f36 | 57 | PortOut(PortName port, int mask = 0xFFFFFFFF) { |
ethaderu | 3:78f223d34f36 | 58 | port_init(&_port, port, mask, PIN_OUTPUT); |
ethaderu | 3:78f223d34f36 | 59 | } |
ethaderu | 3:78f223d34f36 | 60 | |
ethaderu | 3:78f223d34f36 | 61 | /** Write the value to the output port |
ethaderu | 3:78f223d34f36 | 62 | * |
ethaderu | 3:78f223d34f36 | 63 | * @param value An integer specifying a bit to write for every corresponding PortOut pin |
ethaderu | 3:78f223d34f36 | 64 | */ |
ethaderu | 3:78f223d34f36 | 65 | void write(int value) { |
ethaderu | 3:78f223d34f36 | 66 | port_write(&_port, value); |
ethaderu | 3:78f223d34f36 | 67 | } |
ethaderu | 3:78f223d34f36 | 68 | |
ethaderu | 3:78f223d34f36 | 69 | /** Read the value currently output on the port |
ethaderu | 3:78f223d34f36 | 70 | * |
ethaderu | 3:78f223d34f36 | 71 | * @returns |
ethaderu | 3:78f223d34f36 | 72 | * An integer with each bit corresponding to associated PortOut pin setting |
ethaderu | 3:78f223d34f36 | 73 | */ |
ethaderu | 3:78f223d34f36 | 74 | int read() { |
ethaderu | 3:78f223d34f36 | 75 | return port_read(&_port); |
ethaderu | 3:78f223d34f36 | 76 | } |
ethaderu | 3:78f223d34f36 | 77 | |
ethaderu | 3:78f223d34f36 | 78 | /** A shorthand for write() |
ethaderu | 3:78f223d34f36 | 79 | */ |
ethaderu | 3:78f223d34f36 | 80 | PortOut& 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 | PortOut& operator= (PortOut& 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 |