RTC auf true
drivers/PortIn.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_PORTIN_H |
kevman | 0:38ceb79fef03 | 17 | #define MBED_PORTIN_H |
kevman | 0:38ceb79fef03 | 18 | |
kevman | 0:38ceb79fef03 | 19 | #include "platform/platform.h" |
kevman | 0:38ceb79fef03 | 20 | |
kevman | 0:38ceb79fef03 | 21 | #if defined (DEVICE_PORTIN) || 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 input |
kevman | 0:38ceb79fef03 | 30 | * |
kevman | 0:38ceb79fef03 | 31 | * @note Synchronization level: Interrupt safe |
kevman | 0:38ceb79fef03 | 32 | * |
kevman | 0:38ceb79fef03 | 33 | * Example: |
kevman | 0:38ceb79fef03 | 34 | * @code |
kevman | 0:38ceb79fef03 | 35 | * // Turn on an LED if any pins of Port2[0:5] are high |
kevman | 0:38ceb79fef03 | 36 | * |
kevman | 0:38ceb79fef03 | 37 | * #include "mbed.h" |
kevman | 0:38ceb79fef03 | 38 | * |
kevman | 0:38ceb79fef03 | 39 | * PortIn p(Port2, 0x0000003F); // Port2 pins [0:5] only |
kevman | 0:38ceb79fef03 | 40 | * DigitalOut led(LED4); |
kevman | 0:38ceb79fef03 | 41 | * |
kevman | 0:38ceb79fef03 | 42 | * int main() { |
kevman | 0:38ceb79fef03 | 43 | * while(1) { |
kevman | 0:38ceb79fef03 | 44 | * int pins = p.read(); |
kevman | 0:38ceb79fef03 | 45 | * if(pins) { |
kevman | 0:38ceb79fef03 | 46 | * led = 1; |
kevman | 0:38ceb79fef03 | 47 | * } else { |
kevman | 0:38ceb79fef03 | 48 | * led = 0; |
kevman | 0:38ceb79fef03 | 49 | * } |
kevman | 0:38ceb79fef03 | 50 | * } |
kevman | 0:38ceb79fef03 | 51 | * } |
kevman | 0:38ceb79fef03 | 52 | * @endcode |
kevman | 0:38ceb79fef03 | 53 | * @ingroup drivers |
kevman | 0:38ceb79fef03 | 54 | */ |
kevman | 0:38ceb79fef03 | 55 | class PortIn { |
kevman | 0:38ceb79fef03 | 56 | public: |
kevman | 0:38ceb79fef03 | 57 | |
kevman | 0:38ceb79fef03 | 58 | /** Create a PortIn, connected to the specified port |
kevman | 0:38ceb79fef03 | 59 | * |
kevman | 0:38ceb79fef03 | 60 | * @param port Port to connect to (as defined in target's PortNames.h) |
kevman | 0:38ceb79fef03 | 61 | * @param mask Bitmask defines which port pins should be an input (0 - ignore, 1 - include) |
kevman | 0:38ceb79fef03 | 62 | */ |
kevman | 0:38ceb79fef03 | 63 | PortIn(PortName port, int mask = 0xFFFFFFFF) |
kevman | 0:38ceb79fef03 | 64 | { |
kevman | 0:38ceb79fef03 | 65 | core_util_critical_section_enter(); |
kevman | 0:38ceb79fef03 | 66 | port_init(&_port, port, mask, PIN_INPUT); |
kevman | 0:38ceb79fef03 | 67 | core_util_critical_section_exit(); |
kevman | 0:38ceb79fef03 | 68 | } |
kevman | 0:38ceb79fef03 | 69 | |
kevman | 0:38ceb79fef03 | 70 | /** Read the value input to the port |
kevman | 0:38ceb79fef03 | 71 | * |
kevman | 0:38ceb79fef03 | 72 | * @returns |
kevman | 0:38ceb79fef03 | 73 | * An integer with each bit corresponding to the associated pin value |
kevman | 0:38ceb79fef03 | 74 | */ |
kevman | 0:38ceb79fef03 | 75 | int read() |
kevman | 0:38ceb79fef03 | 76 | { |
kevman | 0:38ceb79fef03 | 77 | return port_read(&_port); |
kevman | 0:38ceb79fef03 | 78 | } |
kevman | 0:38ceb79fef03 | 79 | |
kevman | 0:38ceb79fef03 | 80 | /** Set the input pin mode |
kevman | 0:38ceb79fef03 | 81 | * |
kevman | 0:38ceb79fef03 | 82 | * @param mode PullUp, PullDown, PullNone, OpenDrain |
kevman | 0:38ceb79fef03 | 83 | */ |
kevman | 0:38ceb79fef03 | 84 | void mode(PinMode mode) |
kevman | 0:38ceb79fef03 | 85 | { |
kevman | 0:38ceb79fef03 | 86 | core_util_critical_section_enter(); |
kevman | 0:38ceb79fef03 | 87 | port_mode(&_port, mode); |
kevman | 0:38ceb79fef03 | 88 | core_util_critical_section_exit(); |
kevman | 0:38ceb79fef03 | 89 | } |
kevman | 0:38ceb79fef03 | 90 | |
kevman | 0:38ceb79fef03 | 91 | /** A shorthand for read() |
kevman | 0:38ceb79fef03 | 92 | */ |
kevman | 0:38ceb79fef03 | 93 | operator int() |
kevman | 0:38ceb79fef03 | 94 | { |
kevman | 0:38ceb79fef03 | 95 | return read(); |
kevman | 0:38ceb79fef03 | 96 | } |
kevman | 0:38ceb79fef03 | 97 | |
kevman | 0:38ceb79fef03 | 98 | private: |
kevman | 0:38ceb79fef03 | 99 | port_t _port; |
kevman | 0:38ceb79fef03 | 100 | }; |
kevman | 0:38ceb79fef03 | 101 | |
kevman | 0:38ceb79fef03 | 102 | } // namespace mbed |
kevman | 0:38ceb79fef03 | 103 | |
kevman | 0:38ceb79fef03 | 104 | #endif |
kevman | 0:38ceb79fef03 | 105 | |
kevman | 0:38ceb79fef03 | 106 | #endif |