Erste version der Software für der Prototyp

Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:380207fcb5c1 1 /* mbed Microcontroller Library
borlanic 0:380207fcb5c1 2 * Copyright (c) 2006-2013 ARM Limited
borlanic 0:380207fcb5c1 3 *
borlanic 0:380207fcb5c1 4 * Licensed under the Apache License, Version 2.0 (the "License");
borlanic 0:380207fcb5c1 5 * you may not use this file except in compliance with the License.
borlanic 0:380207fcb5c1 6 * You may obtain a copy of the License at
borlanic 0:380207fcb5c1 7 *
borlanic 0:380207fcb5c1 8 * http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:380207fcb5c1 9 *
borlanic 0:380207fcb5c1 10 * Unless required by applicable law or agreed to in writing, software
borlanic 0:380207fcb5c1 11 * distributed under the License is distributed on an "AS IS" BASIS,
borlanic 0:380207fcb5c1 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:380207fcb5c1 13 * See the License for the specific language governing permissions and
borlanic 0:380207fcb5c1 14 * limitations under the License.
borlanic 0:380207fcb5c1 15 */
borlanic 0:380207fcb5c1 16 #ifndef MBED_PORTINOUT_H
borlanic 0:380207fcb5c1 17 #define MBED_PORTINOUT_H
borlanic 0:380207fcb5c1 18
borlanic 0:380207fcb5c1 19 #include "platform/platform.h"
borlanic 0:380207fcb5c1 20
borlanic 0:380207fcb5c1 21 #if defined (DEVICE_PORTINOUT) || defined(DOXYGEN_ONLY)
borlanic 0:380207fcb5c1 22
borlanic 0:380207fcb5c1 23 #include "hal/port_api.h"
borlanic 0:380207fcb5c1 24 #include "platform/mbed_critical.h"
borlanic 0:380207fcb5c1 25
borlanic 0:380207fcb5c1 26 namespace mbed {
borlanic 0:380207fcb5c1 27 /** \addtogroup drivers */
borlanic 0:380207fcb5c1 28
borlanic 0:380207fcb5c1 29 /** A multiple pin digital in/out used to set/read multiple bi-directional pins
borlanic 0:380207fcb5c1 30 *
borlanic 0:380207fcb5c1 31 * @note Synchronization level: Interrupt safe
borlanic 0:380207fcb5c1 32 * @ingroup drivers
borlanic 0:380207fcb5c1 33 */
borlanic 0:380207fcb5c1 34 class PortInOut {
borlanic 0:380207fcb5c1 35 public:
borlanic 0:380207fcb5c1 36
borlanic 0:380207fcb5c1 37 /** Create an PortInOut, connected to the specified port
borlanic 0:380207fcb5c1 38 *
borlanic 0:380207fcb5c1 39 * @param port Port to connect to (Port0-Port5)
borlanic 0:380207fcb5c1 40 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
borlanic 0:380207fcb5c1 41 */
borlanic 0:380207fcb5c1 42 PortInOut(PortName port, int mask = 0xFFFFFFFF) {
borlanic 0:380207fcb5c1 43 core_util_critical_section_enter();
borlanic 0:380207fcb5c1 44 port_init(&_port, port, mask, PIN_INPUT);
borlanic 0:380207fcb5c1 45 core_util_critical_section_exit();
borlanic 0:380207fcb5c1 46 }
borlanic 0:380207fcb5c1 47
borlanic 0:380207fcb5c1 48 /** Write the value to the output port
borlanic 0:380207fcb5c1 49 *
borlanic 0:380207fcb5c1 50 * @param value An integer specifying a bit to write for every corresponding port pin
borlanic 0:380207fcb5c1 51 */
borlanic 0:380207fcb5c1 52 void write(int value) {
borlanic 0:380207fcb5c1 53 port_write(&_port, value);
borlanic 0:380207fcb5c1 54 }
borlanic 0:380207fcb5c1 55
borlanic 0:380207fcb5c1 56 /** Read the value currently output on the port
borlanic 0:380207fcb5c1 57 *
borlanic 0:380207fcb5c1 58 * @returns
borlanic 0:380207fcb5c1 59 * An integer with each bit corresponding to associated port pin setting
borlanic 0:380207fcb5c1 60 */
borlanic 0:380207fcb5c1 61 int read() {
borlanic 0:380207fcb5c1 62 return port_read(&_port);
borlanic 0:380207fcb5c1 63 }
borlanic 0:380207fcb5c1 64
borlanic 0:380207fcb5c1 65 /** Set as an output
borlanic 0:380207fcb5c1 66 */
borlanic 0:380207fcb5c1 67 void output() {
borlanic 0:380207fcb5c1 68 core_util_critical_section_enter();
borlanic 0:380207fcb5c1 69 port_dir(&_port, PIN_OUTPUT);
borlanic 0:380207fcb5c1 70 core_util_critical_section_exit();
borlanic 0:380207fcb5c1 71 }
borlanic 0:380207fcb5c1 72
borlanic 0:380207fcb5c1 73 /** Set as an input
borlanic 0:380207fcb5c1 74 */
borlanic 0:380207fcb5c1 75 void input() {
borlanic 0:380207fcb5c1 76 core_util_critical_section_enter();
borlanic 0:380207fcb5c1 77 port_dir(&_port, PIN_INPUT);
borlanic 0:380207fcb5c1 78 core_util_critical_section_exit();
borlanic 0:380207fcb5c1 79 }
borlanic 0:380207fcb5c1 80
borlanic 0:380207fcb5c1 81 /** Set the input pin mode
borlanic 0:380207fcb5c1 82 *
borlanic 0:380207fcb5c1 83 * @param mode PullUp, PullDown, PullNone, OpenDrain
borlanic 0:380207fcb5c1 84 */
borlanic 0:380207fcb5c1 85 void mode(PinMode mode) {
borlanic 0:380207fcb5c1 86 core_util_critical_section_enter();
borlanic 0:380207fcb5c1 87 port_mode(&_port, mode);
borlanic 0:380207fcb5c1 88 core_util_critical_section_exit();
borlanic 0:380207fcb5c1 89 }
borlanic 0:380207fcb5c1 90
borlanic 0:380207fcb5c1 91 /** A shorthand for write()
borlanic 0:380207fcb5c1 92 * \sa PortInOut::write()
borlanic 0:380207fcb5c1 93 */
borlanic 0:380207fcb5c1 94 PortInOut& operator= (int value) {
borlanic 0:380207fcb5c1 95 write(value);
borlanic 0:380207fcb5c1 96 return *this;
borlanic 0:380207fcb5c1 97 }
borlanic 0:380207fcb5c1 98
borlanic 0:380207fcb5c1 99 /** A shorthand for write()
borlanic 0:380207fcb5c1 100 * \sa PortInOut::write()
borlanic 0:380207fcb5c1 101 */
borlanic 0:380207fcb5c1 102 PortInOut& operator= (PortInOut& rhs) {
borlanic 0:380207fcb5c1 103 write(rhs.read());
borlanic 0:380207fcb5c1 104 return *this;
borlanic 0:380207fcb5c1 105 }
borlanic 0:380207fcb5c1 106
borlanic 0:380207fcb5c1 107 /** A shorthand for read()
borlanic 0:380207fcb5c1 108 * \sa PortInOut::read()
borlanic 0:380207fcb5c1 109 */
borlanic 0:380207fcb5c1 110 operator int() {
borlanic 0:380207fcb5c1 111 return read();
borlanic 0:380207fcb5c1 112 }
borlanic 0:380207fcb5c1 113
borlanic 0:380207fcb5c1 114 private:
borlanic 0:380207fcb5c1 115 port_t _port;
borlanic 0:380207fcb5c1 116 };
borlanic 0:380207fcb5c1 117
borlanic 0:380207fcb5c1 118 } // namespace mbed
borlanic 0:380207fcb5c1 119
borlanic 0:380207fcb5c1 120 #endif
borlanic 0:380207fcb5c1 121
borlanic 0:380207fcb5c1 122 #endif