游戏王对战板,目前code还是空的

Committer:
WFKnight
Date:
Thu Jun 21 13:51:43 2018 +0000
Revision:
0:9b3d4731edbb
UART, RTOS, LED

Who changed what in which revision?

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