,,

Fork of Application by Daniel Sygut

Committer:
Zaitsev
Date:
Tue Jan 10 20:42:26 2017 +0000
Revision:
10:41552d038a69
USB Serial bi-directional bridge

Who changed what in which revision?

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