Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
inc/PortOut.h@0:afeca64a6543, 2018-10-17 (annotated)
- Committer:
- martwerl
- Date:
- Wed Oct 17 17:19:45 2018 +0000
- Revision:
- 0:afeca64a6543
Diplomarbeit_MW_CW
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
martwerl | 0:afeca64a6543 | 1 | /* mbed Microcontroller Library |
martwerl | 0:afeca64a6543 | 2 | * Copyright (c) 2006-2013 ARM Limited |
martwerl | 0:afeca64a6543 | 3 | * |
martwerl | 0:afeca64a6543 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
martwerl | 0:afeca64a6543 | 5 | * of this software and associated documentation files (the "Software"), to deal |
martwerl | 0:afeca64a6543 | 6 | * in the Software without restriction, including without limitation the rights |
martwerl | 0:afeca64a6543 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
martwerl | 0:afeca64a6543 | 8 | * copies of the Software, and to permit persons to whom the Software is |
martwerl | 0:afeca64a6543 | 9 | * furnished to do so, subject to the following conditions: |
martwerl | 0:afeca64a6543 | 10 | * |
martwerl | 0:afeca64a6543 | 11 | * The above copyright notice and this permission notice shall be included in |
martwerl | 0:afeca64a6543 | 12 | * all copies or substantial portions of the Software. |
martwerl | 0:afeca64a6543 | 13 | * |
martwerl | 0:afeca64a6543 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
martwerl | 0:afeca64a6543 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
martwerl | 0:afeca64a6543 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
martwerl | 0:afeca64a6543 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
martwerl | 0:afeca64a6543 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
martwerl | 0:afeca64a6543 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
martwerl | 0:afeca64a6543 | 20 | * SOFTWARE. |
martwerl | 0:afeca64a6543 | 21 | */ |
martwerl | 0:afeca64a6543 | 22 | #ifndef MBED_PORTOUT_H |
martwerl | 0:afeca64a6543 | 23 | #define MBED_PORTOUT_H |
martwerl | 0:afeca64a6543 | 24 | |
martwerl | 0:afeca64a6543 | 25 | #include "platform.h" |
martwerl | 0:afeca64a6543 | 26 | |
martwerl | 0:afeca64a6543 | 27 | #if DEVICE_PORTOUT |
martwerl | 0:afeca64a6543 | 28 | |
martwerl | 0:afeca64a6543 | 29 | #include "port_api.h" |
martwerl | 0:afeca64a6543 | 30 | |
martwerl | 0:afeca64a6543 | 31 | namespace mbed { |
martwerl | 0:afeca64a6543 | 32 | /** A multiple pin digital out |
martwerl | 0:afeca64a6543 | 33 | * |
martwerl | 0:afeca64a6543 | 34 | * Example: |
martwerl | 0:afeca64a6543 | 35 | * @code |
martwerl | 0:afeca64a6543 | 36 | * // Toggle all four LEDs |
martwerl | 0:afeca64a6543 | 37 | * |
martwerl | 0:afeca64a6543 | 38 | * #include "mbed.h" |
martwerl | 0:afeca64a6543 | 39 | * |
martwerl | 0:afeca64a6543 | 40 | * // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23 |
martwerl | 0:afeca64a6543 | 41 | * #define LED_MASK 0x00B40000 |
martwerl | 0:afeca64a6543 | 42 | * |
martwerl | 0:afeca64a6543 | 43 | * PortOut ledport(Port1, LED_MASK); |
martwerl | 0:afeca64a6543 | 44 | * |
martwerl | 0:afeca64a6543 | 45 | * int main() { |
martwerl | 0:afeca64a6543 | 46 | * while(1) { |
martwerl | 0:afeca64a6543 | 47 | * ledport = LED_MASK; |
martwerl | 0:afeca64a6543 | 48 | * wait(1); |
martwerl | 0:afeca64a6543 | 49 | * ledport = 0; |
martwerl | 0:afeca64a6543 | 50 | * wait(1); |
martwerl | 0:afeca64a6543 | 51 | * } |
martwerl | 0:afeca64a6543 | 52 | * } |
martwerl | 0:afeca64a6543 | 53 | * @endcode |
martwerl | 0:afeca64a6543 | 54 | */ |
martwerl | 0:afeca64a6543 | 55 | class PortOut { |
martwerl | 0:afeca64a6543 | 56 | public: |
martwerl | 0:afeca64a6543 | 57 | |
martwerl | 0:afeca64a6543 | 58 | /** Create an PortOut, connected to the specified port |
martwerl | 0:afeca64a6543 | 59 | * |
martwerl | 0:afeca64a6543 | 60 | * @param port Port to connect to (Port0-Port5) |
martwerl | 0:afeca64a6543 | 61 | * @param mask A bitmask to identify which bits in the port should be included (0 - ignore) |
martwerl | 0:afeca64a6543 | 62 | */ |
martwerl | 0:afeca64a6543 | 63 | PortOut(PortName port, int mask = 0xFFFFFFFF) { |
martwerl | 0:afeca64a6543 | 64 | port_init(&_port, port, mask, PIN_OUTPUT); |
martwerl | 0:afeca64a6543 | 65 | } |
martwerl | 0:afeca64a6543 | 66 | |
martwerl | 0:afeca64a6543 | 67 | /** Write the value to the output port |
martwerl | 0:afeca64a6543 | 68 | * |
martwerl | 0:afeca64a6543 | 69 | * @param value An integer specifying a bit to write for every corresponding PortOut pin |
martwerl | 0:afeca64a6543 | 70 | */ |
martwerl | 0:afeca64a6543 | 71 | void write(int value) { |
martwerl | 0:afeca64a6543 | 72 | port_write(&_port, value); |
martwerl | 0:afeca64a6543 | 73 | } |
martwerl | 0:afeca64a6543 | 74 | |
martwerl | 0:afeca64a6543 | 75 | /** Read the value currently output on the port |
martwerl | 0:afeca64a6543 | 76 | * |
martwerl | 0:afeca64a6543 | 77 | * @returns |
martwerl | 0:afeca64a6543 | 78 | * An integer with each bit corresponding to associated PortOut pin setting |
martwerl | 0:afeca64a6543 | 79 | */ |
martwerl | 0:afeca64a6543 | 80 | int read() { |
martwerl | 0:afeca64a6543 | 81 | return port_read(&_port); |
martwerl | 0:afeca64a6543 | 82 | } |
martwerl | 0:afeca64a6543 | 83 | |
martwerl | 0:afeca64a6543 | 84 | /** A shorthand for write() |
martwerl | 0:afeca64a6543 | 85 | */ |
martwerl | 0:afeca64a6543 | 86 | PortOut& operator= (int value) { |
martwerl | 0:afeca64a6543 | 87 | write(value); |
martwerl | 0:afeca64a6543 | 88 | return *this; |
martwerl | 0:afeca64a6543 | 89 | } |
martwerl | 0:afeca64a6543 | 90 | |
martwerl | 0:afeca64a6543 | 91 | PortOut& operator= (PortOut& rhs) { |
martwerl | 0:afeca64a6543 | 92 | write(rhs.read()); |
martwerl | 0:afeca64a6543 | 93 | return *this; |
martwerl | 0:afeca64a6543 | 94 | } |
martwerl | 0:afeca64a6543 | 95 | |
martwerl | 0:afeca64a6543 | 96 | /** A shorthand for read() |
martwerl | 0:afeca64a6543 | 97 | */ |
martwerl | 0:afeca64a6543 | 98 | operator int() { |
martwerl | 0:afeca64a6543 | 99 | return read(); |
martwerl | 0:afeca64a6543 | 100 | } |
martwerl | 0:afeca64a6543 | 101 | |
martwerl | 0:afeca64a6543 | 102 | private: |
martwerl | 0:afeca64a6543 | 103 | port_t _port; |
martwerl | 0:afeca64a6543 | 104 | }; |
martwerl | 0:afeca64a6543 | 105 | |
martwerl | 0:afeca64a6543 | 106 | } // namespace mbed |
martwerl | 0:afeca64a6543 | 107 | |
martwerl | 0:afeca64a6543 | 108 | #endif |
martwerl | 0:afeca64a6543 | 109 | |
martwerl | 0:afeca64a6543 | 110 | #endif |
martwerl | 0:afeca64a6543 | 111 |