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