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_PORTOUT_H
borlanic 0:380207fcb5c1 17 #define MBED_PORTOUT_H
borlanic 0:380207fcb5c1 18
borlanic 0:380207fcb5c1 19 #include "platform/platform.h"
borlanic 0:380207fcb5c1 20
borlanic 0:380207fcb5c1 21 #if defined (DEVICE_PORTOUT) || 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 /** A multiple pin digital out
borlanic 0:380207fcb5c1 29 *
borlanic 0:380207fcb5c1 30 * @note Synchronization level: Interrupt safe
borlanic 0:380207fcb5c1 31 *
borlanic 0:380207fcb5c1 32 * Example:
borlanic 0:380207fcb5c1 33 * @code
borlanic 0:380207fcb5c1 34 * // Toggle all four LEDs
borlanic 0:380207fcb5c1 35 *
borlanic 0:380207fcb5c1 36 * #include "mbed.h"
borlanic 0:380207fcb5c1 37 *
borlanic 0:380207fcb5c1 38 * // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23
borlanic 0:380207fcb5c1 39 * #define LED_MASK 0x00B40000
borlanic 0:380207fcb5c1 40 *
borlanic 0:380207fcb5c1 41 * PortOut ledport(Port1, LED_MASK);
borlanic 0:380207fcb5c1 42 *
borlanic 0:380207fcb5c1 43 * int main() {
borlanic 0:380207fcb5c1 44 * while(1) {
borlanic 0:380207fcb5c1 45 * ledport = LED_MASK;
borlanic 0:380207fcb5c1 46 * wait(1);
borlanic 0:380207fcb5c1 47 * ledport = 0;
borlanic 0:380207fcb5c1 48 * wait(1);
borlanic 0:380207fcb5c1 49 * }
borlanic 0:380207fcb5c1 50 * }
borlanic 0:380207fcb5c1 51 * @endcode
borlanic 0:380207fcb5c1 52 * @ingroup drivers
borlanic 0:380207fcb5c1 53 */
borlanic 0:380207fcb5c1 54 class PortOut {
borlanic 0:380207fcb5c1 55 public:
borlanic 0:380207fcb5c1 56
borlanic 0:380207fcb5c1 57 /** Create an PortOut, connected to the specified port
borlanic 0:380207fcb5c1 58 *
borlanic 0:380207fcb5c1 59 * @param port Port to connect to (Port0-Port5)
borlanic 0:380207fcb5c1 60 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
borlanic 0:380207fcb5c1 61 */
borlanic 0:380207fcb5c1 62 PortOut(PortName port, int mask = 0xFFFFFFFF) {
borlanic 0:380207fcb5c1 63 core_util_critical_section_enter();
borlanic 0:380207fcb5c1 64 port_init(&_port, port, mask, PIN_OUTPUT);
borlanic 0:380207fcb5c1 65 core_util_critical_section_exit();
borlanic 0:380207fcb5c1 66 }
borlanic 0:380207fcb5c1 67
borlanic 0:380207fcb5c1 68 /** Write the value to the output port
borlanic 0:380207fcb5c1 69 *
borlanic 0:380207fcb5c1 70 * @param value An integer specifying a bit to write for every corresponding PortOut pin
borlanic 0:380207fcb5c1 71 */
borlanic 0:380207fcb5c1 72 void write(int value) {
borlanic 0:380207fcb5c1 73 port_write(&_port, value);
borlanic 0:380207fcb5c1 74 }
borlanic 0:380207fcb5c1 75
borlanic 0:380207fcb5c1 76 /** Read the value currently output on the port
borlanic 0:380207fcb5c1 77 *
borlanic 0:380207fcb5c1 78 * @returns
borlanic 0:380207fcb5c1 79 * An integer with each bit corresponding to associated PortOut pin setting
borlanic 0:380207fcb5c1 80 */
borlanic 0:380207fcb5c1 81 int read() {
borlanic 0:380207fcb5c1 82 return port_read(&_port);
borlanic 0:380207fcb5c1 83 }
borlanic 0:380207fcb5c1 84
borlanic 0:380207fcb5c1 85 /** A shorthand for write()
borlanic 0:380207fcb5c1 86 * \sa PortOut::write()
borlanic 0:380207fcb5c1 87 */
borlanic 0:380207fcb5c1 88 PortOut& operator= (int value) {
borlanic 0:380207fcb5c1 89 write(value);
borlanic 0:380207fcb5c1 90 return *this;
borlanic 0:380207fcb5c1 91 }
borlanic 0:380207fcb5c1 92
borlanic 0:380207fcb5c1 93 /** A shorthand for read()
borlanic 0:380207fcb5c1 94 * \sa PortOut::read()
borlanic 0:380207fcb5c1 95 */
borlanic 0:380207fcb5c1 96 PortOut& operator= (PortOut& rhs) {
borlanic 0:380207fcb5c1 97 write(rhs.read());
borlanic 0:380207fcb5c1 98 return *this;
borlanic 0:380207fcb5c1 99 }
borlanic 0:380207fcb5c1 100
borlanic 0:380207fcb5c1 101 /** A shorthand for read()
borlanic 0:380207fcb5c1 102 * \sa PortOut::read()
borlanic 0:380207fcb5c1 103 */
borlanic 0:380207fcb5c1 104 operator int() {
borlanic 0:380207fcb5c1 105 return read();
borlanic 0:380207fcb5c1 106 }
borlanic 0:380207fcb5c1 107
borlanic 0:380207fcb5c1 108 private:
borlanic 0:380207fcb5c1 109 port_t _port;
borlanic 0:380207fcb5c1 110 };
borlanic 0:380207fcb5c1 111
borlanic 0:380207fcb5c1 112 } // namespace mbed
borlanic 0:380207fcb5c1 113
borlanic 0:380207fcb5c1 114 #endif
borlanic 0:380207fcb5c1 115
borlanic 0:380207fcb5c1 116 #endif