SDCard version

Fork of gr-peach-opencv-project-sd-card by the do

Committer:
thedo
Date:
Fri Jul 21 01:26:54 2017 +0000
Revision:
167:2ee3e82cb6f5
gr-peach-opencv-project-sd-card

Who changed what in which revision?

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