temp

Dependencies:   mbed SDFileSystem MS5607 ADXL345_I2C FATFileSystem

Committer:
IKobayashi
Date:
Mon Mar 16 23:37:42 2020 +0900
Revision:
0:c88c3b616c00
copy

Who changed what in which revision?

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