RTC auf true
drivers/PortInOut.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_PORTINOUT_H |
kevman | 0:38ceb79fef03 | 17 | #define MBED_PORTINOUT_H |
kevman | 0:38ceb79fef03 | 18 | |
kevman | 0:38ceb79fef03 | 19 | #include "platform/platform.h" |
kevman | 0:38ceb79fef03 | 20 | |
kevman | 0:38ceb79fef03 | 21 | #if defined (DEVICE_PORTINOUT) || 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 | |
kevman | 0:38ceb79fef03 | 29 | /** A multiple pin digital in/out used to set/read multiple bi-directional pins |
kevman | 0:38ceb79fef03 | 30 | * |
kevman | 0:38ceb79fef03 | 31 | * @note Synchronization level: Interrupt safe |
kevman | 0:38ceb79fef03 | 32 | * @ingroup drivers |
kevman | 0:38ceb79fef03 | 33 | */ |
kevman | 0:38ceb79fef03 | 34 | class PortInOut { |
kevman | 0:38ceb79fef03 | 35 | public: |
kevman | 0:38ceb79fef03 | 36 | |
kevman | 0:38ceb79fef03 | 37 | /** Create an PortInOut, connected to the specified port |
kevman | 0:38ceb79fef03 | 38 | * |
kevman | 0:38ceb79fef03 | 39 | * @param port Port to connect to (Port0-Port5) |
kevman | 0:38ceb79fef03 | 40 | * @param mask A bitmask to identify which bits in the port should be included (0 - ignore) |
kevman | 0:38ceb79fef03 | 41 | */ |
kevman | 0:38ceb79fef03 | 42 | PortInOut(PortName port, int mask = 0xFFFFFFFF) |
kevman | 0:38ceb79fef03 | 43 | { |
kevman | 0:38ceb79fef03 | 44 | core_util_critical_section_enter(); |
kevman | 0:38ceb79fef03 | 45 | port_init(&_port, port, mask, PIN_INPUT); |
kevman | 0:38ceb79fef03 | 46 | core_util_critical_section_exit(); |
kevman | 0:38ceb79fef03 | 47 | } |
kevman | 0:38ceb79fef03 | 48 | |
kevman | 0:38ceb79fef03 | 49 | /** Write the value to the output port |
kevman | 0:38ceb79fef03 | 50 | * |
kevman | 0:38ceb79fef03 | 51 | * @param value An integer specifying a bit to write for every corresponding port pin |
kevman | 0:38ceb79fef03 | 52 | */ |
kevman | 0:38ceb79fef03 | 53 | void write(int value) |
kevman | 0:38ceb79fef03 | 54 | { |
kevman | 0:38ceb79fef03 | 55 | port_write(&_port, value); |
kevman | 0:38ceb79fef03 | 56 | } |
kevman | 0:38ceb79fef03 | 57 | |
kevman | 0:38ceb79fef03 | 58 | /** Read the value currently output on the port |
kevman | 0:38ceb79fef03 | 59 | * |
kevman | 0:38ceb79fef03 | 60 | * @returns |
kevman | 0:38ceb79fef03 | 61 | * An integer with each bit corresponding to associated port pin setting |
kevman | 0:38ceb79fef03 | 62 | */ |
kevman | 0:38ceb79fef03 | 63 | int read() |
kevman | 0:38ceb79fef03 | 64 | { |
kevman | 0:38ceb79fef03 | 65 | return port_read(&_port); |
kevman | 0:38ceb79fef03 | 66 | } |
kevman | 0:38ceb79fef03 | 67 | |
kevman | 0:38ceb79fef03 | 68 | /** Set as an output |
kevman | 0:38ceb79fef03 | 69 | */ |
kevman | 0:38ceb79fef03 | 70 | void output() |
kevman | 0:38ceb79fef03 | 71 | { |
kevman | 0:38ceb79fef03 | 72 | core_util_critical_section_enter(); |
kevman | 0:38ceb79fef03 | 73 | port_dir(&_port, PIN_OUTPUT); |
kevman | 0:38ceb79fef03 | 74 | core_util_critical_section_exit(); |
kevman | 0:38ceb79fef03 | 75 | } |
kevman | 0:38ceb79fef03 | 76 | |
kevman | 0:38ceb79fef03 | 77 | /** Set as an input |
kevman | 0:38ceb79fef03 | 78 | */ |
kevman | 0:38ceb79fef03 | 79 | void input() |
kevman | 0:38ceb79fef03 | 80 | { |
kevman | 0:38ceb79fef03 | 81 | core_util_critical_section_enter(); |
kevman | 0:38ceb79fef03 | 82 | port_dir(&_port, PIN_INPUT); |
kevman | 0:38ceb79fef03 | 83 | core_util_critical_section_exit(); |
kevman | 0:38ceb79fef03 | 84 | } |
kevman | 0:38ceb79fef03 | 85 | |
kevman | 0:38ceb79fef03 | 86 | /** Set the input pin mode |
kevman | 0:38ceb79fef03 | 87 | * |
kevman | 0:38ceb79fef03 | 88 | * @param mode PullUp, PullDown, PullNone, OpenDrain |
kevman | 0:38ceb79fef03 | 89 | */ |
kevman | 0:38ceb79fef03 | 90 | void mode(PinMode mode) |
kevman | 0:38ceb79fef03 | 91 | { |
kevman | 0:38ceb79fef03 | 92 | core_util_critical_section_enter(); |
kevman | 0:38ceb79fef03 | 93 | port_mode(&_port, mode); |
kevman | 0:38ceb79fef03 | 94 | core_util_critical_section_exit(); |
kevman | 0:38ceb79fef03 | 95 | } |
kevman | 0:38ceb79fef03 | 96 | |
kevman | 0:38ceb79fef03 | 97 | /** A shorthand for write() |
kevman | 0:38ceb79fef03 | 98 | * \sa PortInOut::write() |
kevman | 0:38ceb79fef03 | 99 | */ |
kevman | 0:38ceb79fef03 | 100 | PortInOut &operator= (int value) |
kevman | 0:38ceb79fef03 | 101 | { |
kevman | 0:38ceb79fef03 | 102 | write(value); |
kevman | 0:38ceb79fef03 | 103 | return *this; |
kevman | 0:38ceb79fef03 | 104 | } |
kevman | 0:38ceb79fef03 | 105 | |
kevman | 0:38ceb79fef03 | 106 | /** A shorthand for write() |
kevman | 0:38ceb79fef03 | 107 | * \sa PortInOut::write() |
kevman | 0:38ceb79fef03 | 108 | */ |
kevman | 0:38ceb79fef03 | 109 | PortInOut &operator= (PortInOut &rhs) |
kevman | 0:38ceb79fef03 | 110 | { |
kevman | 0:38ceb79fef03 | 111 | write(rhs.read()); |
kevman | 0:38ceb79fef03 | 112 | return *this; |
kevman | 0:38ceb79fef03 | 113 | } |
kevman | 0:38ceb79fef03 | 114 | |
kevman | 0:38ceb79fef03 | 115 | /** A shorthand for read() |
kevman | 0:38ceb79fef03 | 116 | * \sa PortInOut::read() |
kevman | 0:38ceb79fef03 | 117 | */ |
kevman | 0:38ceb79fef03 | 118 | operator int() |
kevman | 0:38ceb79fef03 | 119 | { |
kevman | 0:38ceb79fef03 | 120 | return read(); |
kevman | 0:38ceb79fef03 | 121 | } |
kevman | 0:38ceb79fef03 | 122 | |
kevman | 0:38ceb79fef03 | 123 | private: |
kevman | 0:38ceb79fef03 | 124 | port_t _port; |
kevman | 0:38ceb79fef03 | 125 | }; |
kevman | 0:38ceb79fef03 | 126 | |
kevman | 0:38ceb79fef03 | 127 | } // namespace mbed |
kevman | 0:38ceb79fef03 | 128 | |
kevman | 0:38ceb79fef03 | 129 | #endif |
kevman | 0:38ceb79fef03 | 130 | |
kevman | 0:38ceb79fef03 | 131 | #endif |