Erste version der Software für der Prototyp

Committer:
borlanic
Date:
Thu Mar 29 07:02:09 2018 +0000
Revision:
0:380207fcb5c1
Encoder, IMU --> OK; Controller --> in bearbeitung

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_PORTIN_H
borlanic 0:380207fcb5c1 17 #define MBED_PORTIN_H
borlanic 0:380207fcb5c1 18
borlanic 0:380207fcb5c1 19 #include "platform/platform.h"
borlanic 0:380207fcb5c1 20
borlanic 0:380207fcb5c1 21 #if defined (DEVICE_PORTIN) || 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 input
borlanic 0:380207fcb5c1 30 *
borlanic 0:380207fcb5c1 31 * @note Synchronization level: Interrupt safe
borlanic 0:380207fcb5c1 32 *
borlanic 0:380207fcb5c1 33 * Example:
borlanic 0:380207fcb5c1 34 * @code
borlanic 0:380207fcb5c1 35 * // Switch on an LED if any of mbed pins 21-26 is high
borlanic 0:380207fcb5c1 36 *
borlanic 0:380207fcb5c1 37 * #include "mbed.h"
borlanic 0:380207fcb5c1 38 *
borlanic 0:380207fcb5c1 39 * PortIn p(Port2, 0x0000003F); // p21-p26
borlanic 0:380207fcb5c1 40 * DigitalOut ind(LED4);
borlanic 0:380207fcb5c1 41 *
borlanic 0:380207fcb5c1 42 * int main() {
borlanic 0:380207fcb5c1 43 * while(1) {
borlanic 0:380207fcb5c1 44 * int pins = p.read();
borlanic 0:380207fcb5c1 45 * if(pins) {
borlanic 0:380207fcb5c1 46 * ind = 1;
borlanic 0:380207fcb5c1 47 * } else {
borlanic 0:380207fcb5c1 48 * ind = 0;
borlanic 0:380207fcb5c1 49 * }
borlanic 0:380207fcb5c1 50 * }
borlanic 0:380207fcb5c1 51 * }
borlanic 0:380207fcb5c1 52 * @endcode
borlanic 0:380207fcb5c1 53 * @ingroup drivers
borlanic 0:380207fcb5c1 54 */
borlanic 0:380207fcb5c1 55 class PortIn {
borlanic 0:380207fcb5c1 56 public:
borlanic 0:380207fcb5c1 57
borlanic 0:380207fcb5c1 58 /** Create an PortIn, connected to the specified port
borlanic 0:380207fcb5c1 59 *
borlanic 0:380207fcb5c1 60 * @param port Port to connect to (Port0-Port5)
borlanic 0:380207fcb5c1 61 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
borlanic 0:380207fcb5c1 62 */
borlanic 0:380207fcb5c1 63 PortIn(PortName port, int mask = 0xFFFFFFFF) {
borlanic 0:380207fcb5c1 64 core_util_critical_section_enter();
borlanic 0:380207fcb5c1 65 port_init(&_port, port, mask, PIN_INPUT);
borlanic 0:380207fcb5c1 66 core_util_critical_section_exit();
borlanic 0:380207fcb5c1 67 }
borlanic 0:380207fcb5c1 68
borlanic 0:380207fcb5c1 69 /** Read the value currently output on the port
borlanic 0:380207fcb5c1 70 *
borlanic 0:380207fcb5c1 71 * @returns
borlanic 0:380207fcb5c1 72 * An integer with each bit corresponding to associated port pin setting
borlanic 0:380207fcb5c1 73 */
borlanic 0:380207fcb5c1 74 int read() {
borlanic 0:380207fcb5c1 75 return port_read(&_port);
borlanic 0:380207fcb5c1 76 }
borlanic 0:380207fcb5c1 77
borlanic 0:380207fcb5c1 78 /** Set the input pin mode
borlanic 0:380207fcb5c1 79 *
borlanic 0:380207fcb5c1 80 * @param mode PullUp, PullDown, PullNone, OpenDrain
borlanic 0:380207fcb5c1 81 */
borlanic 0:380207fcb5c1 82 void mode(PinMode mode) {
borlanic 0:380207fcb5c1 83 core_util_critical_section_enter();
borlanic 0:380207fcb5c1 84 port_mode(&_port, mode);
borlanic 0:380207fcb5c1 85 core_util_critical_section_exit();
borlanic 0:380207fcb5c1 86 }
borlanic 0:380207fcb5c1 87
borlanic 0:380207fcb5c1 88 /** A shorthand for read()
borlanic 0:380207fcb5c1 89 */
borlanic 0:380207fcb5c1 90 operator int() {
borlanic 0:380207fcb5c1 91 return read();
borlanic 0:380207fcb5c1 92 }
borlanic 0:380207fcb5c1 93
borlanic 0:380207fcb5c1 94 private:
borlanic 0:380207fcb5c1 95 port_t _port;
borlanic 0:380207fcb5c1 96 };
borlanic 0:380207fcb5c1 97
borlanic 0:380207fcb5c1 98 } // namespace mbed
borlanic 0:380207fcb5c1 99
borlanic 0:380207fcb5c1 100 #endif
borlanic 0:380207fcb5c1 101
borlanic 0:380207fcb5c1 102 #endif