this hurts
Dependencies: FFT
mbed/drivers/PortIn.h@7:0d62545e6d73, 2020-12-03 (annotated)
- Committer:
- shyamgatech
- Date:
- Thu Dec 03 18:15:35 2020 +0000
- Revision:
- 7:0d62545e6d73
- Parent:
- 0:d6c9b09b4042
addded gui mbed code;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
annieluo2 | 0:d6c9b09b4042 | 1 | /* mbed Microcontroller Library |
annieluo2 | 0:d6c9b09b4042 | 2 | * Copyright (c) 2006-2013 ARM Limited |
annieluo2 | 0:d6c9b09b4042 | 3 | * |
annieluo2 | 0:d6c9b09b4042 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
annieluo2 | 0:d6c9b09b4042 | 5 | * you may not use this file except in compliance with the License. |
annieluo2 | 0:d6c9b09b4042 | 6 | * You may obtain a copy of the License at |
annieluo2 | 0:d6c9b09b4042 | 7 | * |
annieluo2 | 0:d6c9b09b4042 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
annieluo2 | 0:d6c9b09b4042 | 9 | * |
annieluo2 | 0:d6c9b09b4042 | 10 | * Unless required by applicable law or agreed to in writing, software |
annieluo2 | 0:d6c9b09b4042 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
annieluo2 | 0:d6c9b09b4042 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
annieluo2 | 0:d6c9b09b4042 | 13 | * See the License for the specific language governing permissions and |
annieluo2 | 0:d6c9b09b4042 | 14 | * limitations under the License. |
annieluo2 | 0:d6c9b09b4042 | 15 | */ |
annieluo2 | 0:d6c9b09b4042 | 16 | #ifndef MBED_PORTIN_H |
annieluo2 | 0:d6c9b09b4042 | 17 | #define MBED_PORTIN_H |
annieluo2 | 0:d6c9b09b4042 | 18 | |
annieluo2 | 0:d6c9b09b4042 | 19 | #include "platform/platform.h" |
annieluo2 | 0:d6c9b09b4042 | 20 | |
annieluo2 | 0:d6c9b09b4042 | 21 | #if DEVICE_PORTIN |
annieluo2 | 0:d6c9b09b4042 | 22 | |
annieluo2 | 0:d6c9b09b4042 | 23 | #include "hal/port_api.h" |
annieluo2 | 0:d6c9b09b4042 | 24 | #include "platform/critical.h" |
annieluo2 | 0:d6c9b09b4042 | 25 | |
annieluo2 | 0:d6c9b09b4042 | 26 | namespace mbed { |
annieluo2 | 0:d6c9b09b4042 | 27 | /** \addtogroup drivers */ |
annieluo2 | 0:d6c9b09b4042 | 28 | /** @{*/ |
annieluo2 | 0:d6c9b09b4042 | 29 | |
annieluo2 | 0:d6c9b09b4042 | 30 | /** A multiple pin digital input |
annieluo2 | 0:d6c9b09b4042 | 31 | * |
annieluo2 | 0:d6c9b09b4042 | 32 | * @Note Synchronization level: Interrupt safe |
annieluo2 | 0:d6c9b09b4042 | 33 | * |
annieluo2 | 0:d6c9b09b4042 | 34 | * Example: |
annieluo2 | 0:d6c9b09b4042 | 35 | * @code |
annieluo2 | 0:d6c9b09b4042 | 36 | * // Switch on an LED if any of mbed pins 21-26 is high |
annieluo2 | 0:d6c9b09b4042 | 37 | * |
annieluo2 | 0:d6c9b09b4042 | 38 | * #include "mbed.h" |
annieluo2 | 0:d6c9b09b4042 | 39 | * |
annieluo2 | 0:d6c9b09b4042 | 40 | * PortIn p(Port2, 0x0000003F); // p21-p26 |
annieluo2 | 0:d6c9b09b4042 | 41 | * DigitalOut ind(LED4); |
annieluo2 | 0:d6c9b09b4042 | 42 | * |
annieluo2 | 0:d6c9b09b4042 | 43 | * int main() { |
annieluo2 | 0:d6c9b09b4042 | 44 | * while(1) { |
annieluo2 | 0:d6c9b09b4042 | 45 | * int pins = p.read(); |
annieluo2 | 0:d6c9b09b4042 | 46 | * if(pins) { |
annieluo2 | 0:d6c9b09b4042 | 47 | * ind = 1; |
annieluo2 | 0:d6c9b09b4042 | 48 | * } else { |
annieluo2 | 0:d6c9b09b4042 | 49 | * ind = 0; |
annieluo2 | 0:d6c9b09b4042 | 50 | * } |
annieluo2 | 0:d6c9b09b4042 | 51 | * } |
annieluo2 | 0:d6c9b09b4042 | 52 | * } |
annieluo2 | 0:d6c9b09b4042 | 53 | * @endcode |
annieluo2 | 0:d6c9b09b4042 | 54 | */ |
annieluo2 | 0:d6c9b09b4042 | 55 | class PortIn { |
annieluo2 | 0:d6c9b09b4042 | 56 | public: |
annieluo2 | 0:d6c9b09b4042 | 57 | |
annieluo2 | 0:d6c9b09b4042 | 58 | /** Create an PortIn, connected to the specified port |
annieluo2 | 0:d6c9b09b4042 | 59 | * |
annieluo2 | 0:d6c9b09b4042 | 60 | * @param port Port to connect to (Port0-Port5) |
annieluo2 | 0:d6c9b09b4042 | 61 | * @param mask A bitmask to identify which bits in the port should be included (0 - ignore) |
annieluo2 | 0:d6c9b09b4042 | 62 | */ |
annieluo2 | 0:d6c9b09b4042 | 63 | PortIn(PortName port, int mask = 0xFFFFFFFF) { |
annieluo2 | 0:d6c9b09b4042 | 64 | core_util_critical_section_enter(); |
annieluo2 | 0:d6c9b09b4042 | 65 | port_init(&_port, port, mask, PIN_INPUT); |
annieluo2 | 0:d6c9b09b4042 | 66 | core_util_critical_section_exit(); |
annieluo2 | 0:d6c9b09b4042 | 67 | } |
annieluo2 | 0:d6c9b09b4042 | 68 | |
annieluo2 | 0:d6c9b09b4042 | 69 | /** Read the value currently output on the port |
annieluo2 | 0:d6c9b09b4042 | 70 | * |
annieluo2 | 0:d6c9b09b4042 | 71 | * @returns |
annieluo2 | 0:d6c9b09b4042 | 72 | * An integer with each bit corresponding to associated port pin setting |
annieluo2 | 0:d6c9b09b4042 | 73 | */ |
annieluo2 | 0:d6c9b09b4042 | 74 | int read() { |
annieluo2 | 0:d6c9b09b4042 | 75 | return port_read(&_port); |
annieluo2 | 0:d6c9b09b4042 | 76 | } |
annieluo2 | 0:d6c9b09b4042 | 77 | |
annieluo2 | 0:d6c9b09b4042 | 78 | /** Set the input pin mode |
annieluo2 | 0:d6c9b09b4042 | 79 | * |
annieluo2 | 0:d6c9b09b4042 | 80 | * @param mode PullUp, PullDown, PullNone, OpenDrain |
annieluo2 | 0:d6c9b09b4042 | 81 | */ |
annieluo2 | 0:d6c9b09b4042 | 82 | void mode(PinMode mode) { |
annieluo2 | 0:d6c9b09b4042 | 83 | core_util_critical_section_enter(); |
annieluo2 | 0:d6c9b09b4042 | 84 | port_mode(&_port, mode); |
annieluo2 | 0:d6c9b09b4042 | 85 | core_util_critical_section_exit(); |
annieluo2 | 0:d6c9b09b4042 | 86 | } |
annieluo2 | 0:d6c9b09b4042 | 87 | |
annieluo2 | 0:d6c9b09b4042 | 88 | /** A shorthand for read() |
annieluo2 | 0:d6c9b09b4042 | 89 | */ |
annieluo2 | 0:d6c9b09b4042 | 90 | operator int() { |
annieluo2 | 0:d6c9b09b4042 | 91 | return read(); |
annieluo2 | 0:d6c9b09b4042 | 92 | } |
annieluo2 | 0:d6c9b09b4042 | 93 | |
annieluo2 | 0:d6c9b09b4042 | 94 | private: |
annieluo2 | 0:d6c9b09b4042 | 95 | port_t _port; |
annieluo2 | 0:d6c9b09b4042 | 96 | }; |
annieluo2 | 0:d6c9b09b4042 | 97 | |
annieluo2 | 0:d6c9b09b4042 | 98 | } // namespace mbed |
annieluo2 | 0:d6c9b09b4042 | 99 | |
annieluo2 | 0:d6c9b09b4042 | 100 | #endif |
annieluo2 | 0:d6c9b09b4042 | 101 | |
annieluo2 | 0:d6c9b09b4042 | 102 | #endif |
annieluo2 | 0:d6c9b09b4042 | 103 | |
annieluo2 | 0:d6c9b09b4042 | 104 | /** @}*/ |