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