RTC auf true
drivers/PortOut.h@0:38ceb79fef03, 2018-11-28 (annotated)
- Committer:
- kevman
- Date:
- Wed Nov 28 15:10:15 2018 +0000
- Revision:
- 0:38ceb79fef03
RTC modified
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kevman | 0:38ceb79fef03 | 1 | /* mbed Microcontroller Library |
kevman | 0:38ceb79fef03 | 2 | * Copyright (c) 2006-2013 ARM Limited |
kevman | 0:38ceb79fef03 | 3 | * |
kevman | 0:38ceb79fef03 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kevman | 0:38ceb79fef03 | 5 | * you may not use this file except in compliance with the License. |
kevman | 0:38ceb79fef03 | 6 | * You may obtain a copy of the License at |
kevman | 0:38ceb79fef03 | 7 | * |
kevman | 0:38ceb79fef03 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kevman | 0:38ceb79fef03 | 9 | * |
kevman | 0:38ceb79fef03 | 10 | * Unless required by applicable law or agreed to in writing, software |
kevman | 0:38ceb79fef03 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kevman | 0:38ceb79fef03 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kevman | 0:38ceb79fef03 | 13 | * See the License for the specific language governing permissions and |
kevman | 0:38ceb79fef03 | 14 | * limitations under the License. |
kevman | 0:38ceb79fef03 | 15 | */ |
kevman | 0:38ceb79fef03 | 16 | #ifndef MBED_PORTOUT_H |
kevman | 0:38ceb79fef03 | 17 | #define MBED_PORTOUT_H |
kevman | 0:38ceb79fef03 | 18 | |
kevman | 0:38ceb79fef03 | 19 | #include "platform/platform.h" |
kevman | 0:38ceb79fef03 | 20 | |
kevman | 0:38ceb79fef03 | 21 | #if defined (DEVICE_PORTOUT) || defined(DOXYGEN_ONLY) |
kevman | 0:38ceb79fef03 | 22 | |
kevman | 0:38ceb79fef03 | 23 | #include "hal/port_api.h" |
kevman | 0:38ceb79fef03 | 24 | #include "platform/mbed_critical.h" |
kevman | 0:38ceb79fef03 | 25 | |
kevman | 0:38ceb79fef03 | 26 | namespace mbed { |
kevman | 0:38ceb79fef03 | 27 | /** \addtogroup drivers */ |
kevman | 0:38ceb79fef03 | 28 | /** A multiple pin digital output |
kevman | 0:38ceb79fef03 | 29 | * |
kevman | 0:38ceb79fef03 | 30 | * @note Synchronization level: Interrupt safe |
kevman | 0:38ceb79fef03 | 31 | * |
kevman | 0:38ceb79fef03 | 32 | * Example: |
kevman | 0:38ceb79fef03 | 33 | * @code |
kevman | 0:38ceb79fef03 | 34 | * // Toggle all four LEDs |
kevman | 0:38ceb79fef03 | 35 | * |
kevman | 0:38ceb79fef03 | 36 | * #include "mbed.h" |
kevman | 0:38ceb79fef03 | 37 | * |
kevman | 0:38ceb79fef03 | 38 | * // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23 |
kevman | 0:38ceb79fef03 | 39 | * #define LED_MASK 0x00B40000 |
kevman | 0:38ceb79fef03 | 40 | * |
kevman | 0:38ceb79fef03 | 41 | * PortOut ledport(Port1, LED_MASK); |
kevman | 0:38ceb79fef03 | 42 | * |
kevman | 0:38ceb79fef03 | 43 | * int main() { |
kevman | 0:38ceb79fef03 | 44 | * while(1) { |
kevman | 0:38ceb79fef03 | 45 | * ledport = LED_MASK; |
kevman | 0:38ceb79fef03 | 46 | * wait(1); |
kevman | 0:38ceb79fef03 | 47 | * ledport = 0; |
kevman | 0:38ceb79fef03 | 48 | * wait(1); |
kevman | 0:38ceb79fef03 | 49 | * } |
kevman | 0:38ceb79fef03 | 50 | * } |
kevman | 0:38ceb79fef03 | 51 | * @endcode |
kevman | 0:38ceb79fef03 | 52 | * @ingroup drivers |
kevman | 0:38ceb79fef03 | 53 | */ |
kevman | 0:38ceb79fef03 | 54 | class PortOut { |
kevman | 0:38ceb79fef03 | 55 | public: |
kevman | 0:38ceb79fef03 | 56 | |
kevman | 0:38ceb79fef03 | 57 | /** Create a PortOut, connected to the specified port |
kevman | 0:38ceb79fef03 | 58 | * |
kevman | 0:38ceb79fef03 | 59 | * @param port Port to connect to (as defined in target's PortNames.h) |
kevman | 0:38ceb79fef03 | 60 | * @param mask Bitmask defines which port pins are an output (0 - ignore, 1 - include) |
kevman | 0:38ceb79fef03 | 61 | */ |
kevman | 0:38ceb79fef03 | 62 | PortOut(PortName port, int mask = 0xFFFFFFFF) |
kevman | 0:38ceb79fef03 | 63 | { |
kevman | 0:38ceb79fef03 | 64 | core_util_critical_section_enter(); |
kevman | 0:38ceb79fef03 | 65 | port_init(&_port, port, mask, PIN_OUTPUT); |
kevman | 0:38ceb79fef03 | 66 | core_util_critical_section_exit(); |
kevman | 0:38ceb79fef03 | 67 | } |
kevman | 0:38ceb79fef03 | 68 | |
kevman | 0:38ceb79fef03 | 69 | /** Write the value to the output port |
kevman | 0:38ceb79fef03 | 70 | * |
kevman | 0:38ceb79fef03 | 71 | * @param value An integer specifying a bit to write for every corresponding PortOut pin |
kevman | 0:38ceb79fef03 | 72 | */ |
kevman | 0:38ceb79fef03 | 73 | void write(int value) |
kevman | 0:38ceb79fef03 | 74 | { |
kevman | 0:38ceb79fef03 | 75 | port_write(&_port, value); |
kevman | 0:38ceb79fef03 | 76 | } |
kevman | 0:38ceb79fef03 | 77 | |
kevman | 0:38ceb79fef03 | 78 | /** Read the value currently output on the port |
kevman | 0:38ceb79fef03 | 79 | * |
kevman | 0:38ceb79fef03 | 80 | * @returns |
kevman | 0:38ceb79fef03 | 81 | * An integer with each bit corresponding to associated pin value |
kevman | 0:38ceb79fef03 | 82 | */ |
kevman | 0:38ceb79fef03 | 83 | int read() |
kevman | 0:38ceb79fef03 | 84 | { |
kevman | 0:38ceb79fef03 | 85 | return port_read(&_port); |
kevman | 0:38ceb79fef03 | 86 | } |
kevman | 0:38ceb79fef03 | 87 | |
kevman | 0:38ceb79fef03 | 88 | /** A shorthand for write() |
kevman | 0:38ceb79fef03 | 89 | * \sa PortOut::write() |
kevman | 0:38ceb79fef03 | 90 | */ |
kevman | 0:38ceb79fef03 | 91 | PortOut &operator= (int value) |
kevman | 0:38ceb79fef03 | 92 | { |
kevman | 0:38ceb79fef03 | 93 | write(value); |
kevman | 0:38ceb79fef03 | 94 | return *this; |
kevman | 0:38ceb79fef03 | 95 | } |
kevman | 0:38ceb79fef03 | 96 | |
kevman | 0:38ceb79fef03 | 97 | /** A shorthand for read() |
kevman | 0:38ceb79fef03 | 98 | * \sa PortOut::read() |
kevman | 0:38ceb79fef03 | 99 | */ |
kevman | 0:38ceb79fef03 | 100 | PortOut &operator= (PortOut &rhs) |
kevman | 0:38ceb79fef03 | 101 | { |
kevman | 0:38ceb79fef03 | 102 | write(rhs.read()); |
kevman | 0:38ceb79fef03 | 103 | return *this; |
kevman | 0:38ceb79fef03 | 104 | } |
kevman | 0:38ceb79fef03 | 105 | |
kevman | 0:38ceb79fef03 | 106 | /** A shorthand for read() |
kevman | 0:38ceb79fef03 | 107 | * \sa PortOut::read() |
kevman | 0:38ceb79fef03 | 108 | */ |
kevman | 0:38ceb79fef03 | 109 | operator int() |
kevman | 0:38ceb79fef03 | 110 | { |
kevman | 0:38ceb79fef03 | 111 | return read(); |
kevman | 0:38ceb79fef03 | 112 | } |
kevman | 0:38ceb79fef03 | 113 | |
kevman | 0:38ceb79fef03 | 114 | private: |
kevman | 0:38ceb79fef03 | 115 | port_t _port; |
kevman | 0:38ceb79fef03 | 116 | }; |
kevman | 0:38ceb79fef03 | 117 | |
kevman | 0:38ceb79fef03 | 118 | } // namespace mbed |
kevman | 0:38ceb79fef03 | 119 | |
kevman | 0:38ceb79fef03 | 120 | #endif |
kevman | 0:38ceb79fef03 | 121 | |
kevman | 0:38ceb79fef03 | 122 | #endif |