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