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_DIGITALIN_H
thedo 167:2ee3e82cb6f5 17 #define MBED_DIGITALIN_H
thedo 167:2ee3e82cb6f5 18
thedo 167:2ee3e82cb6f5 19 #include "platform/platform.h"
thedo 167:2ee3e82cb6f5 20
thedo 167:2ee3e82cb6f5 21 #include "hal/gpio_api.h"
thedo 167:2ee3e82cb6f5 22 #include "platform/mbed_critical.h"
thedo 167:2ee3e82cb6f5 23
thedo 167:2ee3e82cb6f5 24 namespace mbed {
thedo 167:2ee3e82cb6f5 25 /** \addtogroup drivers */
thedo 167:2ee3e82cb6f5 26
thedo 167:2ee3e82cb6f5 27 /** A digital input, used for reading the state of a pin
thedo 167:2ee3e82cb6f5 28 *
thedo 167:2ee3e82cb6f5 29 * @note Synchronization level: Interrupt safe
thedo 167:2ee3e82cb6f5 30 *
thedo 167:2ee3e82cb6f5 31 * Example:
thedo 167:2ee3e82cb6f5 32 * @code
thedo 167:2ee3e82cb6f5 33 * // Flash an LED while a DigitalIn is true
thedo 167:2ee3e82cb6f5 34 *
thedo 167:2ee3e82cb6f5 35 * #include "mbed.h"
thedo 167:2ee3e82cb6f5 36 *
thedo 167:2ee3e82cb6f5 37 * DigitalIn enable(p5);
thedo 167:2ee3e82cb6f5 38 * DigitalOut led(LED1);
thedo 167:2ee3e82cb6f5 39 *
thedo 167:2ee3e82cb6f5 40 * int main() {
thedo 167:2ee3e82cb6f5 41 * while(1) {
thedo 167:2ee3e82cb6f5 42 * if(enable) {
thedo 167:2ee3e82cb6f5 43 * led = !led;
thedo 167:2ee3e82cb6f5 44 * }
thedo 167:2ee3e82cb6f5 45 * wait(0.25);
thedo 167:2ee3e82cb6f5 46 * }
thedo 167:2ee3e82cb6f5 47 * }
thedo 167:2ee3e82cb6f5 48 * @endcode
thedo 167:2ee3e82cb6f5 49 * @ingroup drivers
thedo 167:2ee3e82cb6f5 50 */
thedo 167:2ee3e82cb6f5 51 class DigitalIn {
thedo 167:2ee3e82cb6f5 52
thedo 167:2ee3e82cb6f5 53 public:
thedo 167:2ee3e82cb6f5 54 /** Create a DigitalIn connected to the specified pin
thedo 167:2ee3e82cb6f5 55 *
thedo 167:2ee3e82cb6f5 56 * @param pin DigitalIn pin to connect to
thedo 167:2ee3e82cb6f5 57 */
thedo 167:2ee3e82cb6f5 58 DigitalIn(PinName pin) : gpio() {
thedo 167:2ee3e82cb6f5 59 // No lock needed in the constructor
thedo 167:2ee3e82cb6f5 60 gpio_init_in(&gpio, pin);
thedo 167:2ee3e82cb6f5 61 }
thedo 167:2ee3e82cb6f5 62
thedo 167:2ee3e82cb6f5 63 /** Create a DigitalIn connected to the specified pin
thedo 167:2ee3e82cb6f5 64 *
thedo 167:2ee3e82cb6f5 65 * @param pin DigitalIn pin to connect to
thedo 167:2ee3e82cb6f5 66 * @param mode the initial mode of the pin
thedo 167:2ee3e82cb6f5 67 */
thedo 167:2ee3e82cb6f5 68 DigitalIn(PinName pin, PinMode mode) : gpio() {
thedo 167:2ee3e82cb6f5 69 // No lock needed in the constructor
thedo 167:2ee3e82cb6f5 70 gpio_init_in_ex(&gpio, pin, mode);
thedo 167:2ee3e82cb6f5 71 }
thedo 167:2ee3e82cb6f5 72 /** Read the input, represented as 0 or 1 (int)
thedo 167:2ee3e82cb6f5 73 *
thedo 167:2ee3e82cb6f5 74 * @returns
thedo 167:2ee3e82cb6f5 75 * An integer representing the state of the input pin,
thedo 167:2ee3e82cb6f5 76 * 0 for logical 0, 1 for logical 1
thedo 167:2ee3e82cb6f5 77 */
thedo 167:2ee3e82cb6f5 78 int read() {
thedo 167:2ee3e82cb6f5 79 // Thread safe / atomic HAL call
thedo 167:2ee3e82cb6f5 80 return gpio_read(&gpio);
thedo 167:2ee3e82cb6f5 81 }
thedo 167:2ee3e82cb6f5 82
thedo 167:2ee3e82cb6f5 83 /** Set the input pin mode
thedo 167:2ee3e82cb6f5 84 *
thedo 167:2ee3e82cb6f5 85 * @param pull PullUp, PullDown, PullNone, OpenDrain
thedo 167:2ee3e82cb6f5 86 */
thedo 167:2ee3e82cb6f5 87 void mode(PinMode pull) {
thedo 167:2ee3e82cb6f5 88 core_util_critical_section_enter();
thedo 167:2ee3e82cb6f5 89 gpio_mode(&gpio, pull);
thedo 167:2ee3e82cb6f5 90 core_util_critical_section_exit();
thedo 167:2ee3e82cb6f5 91 }
thedo 167:2ee3e82cb6f5 92
thedo 167:2ee3e82cb6f5 93 /** Return the output setting, represented as 0 or 1 (int)
thedo 167:2ee3e82cb6f5 94 *
thedo 167:2ee3e82cb6f5 95 * @returns
thedo 167:2ee3e82cb6f5 96 * Non zero value if pin is connected to uc GPIO
thedo 167:2ee3e82cb6f5 97 * 0 if gpio object was initialized with NC
thedo 167:2ee3e82cb6f5 98 */
thedo 167:2ee3e82cb6f5 99 int is_connected() {
thedo 167:2ee3e82cb6f5 100 // Thread safe / atomic HAL call
thedo 167:2ee3e82cb6f5 101 return gpio_is_connected(&gpio);
thedo 167:2ee3e82cb6f5 102 }
thedo 167:2ee3e82cb6f5 103
thedo 167:2ee3e82cb6f5 104 /** An operator shorthand for read()
thedo 167:2ee3e82cb6f5 105 */
thedo 167:2ee3e82cb6f5 106 operator int() {
thedo 167:2ee3e82cb6f5 107 // Underlying read is thread safe
thedo 167:2ee3e82cb6f5 108 return read();
thedo 167:2ee3e82cb6f5 109 }
thedo 167:2ee3e82cb6f5 110
thedo 167:2ee3e82cb6f5 111 protected:
thedo 167:2ee3e82cb6f5 112 gpio_t gpio;
thedo 167:2ee3e82cb6f5 113 };
thedo 167:2ee3e82cb6f5 114
thedo 167:2ee3e82cb6f5 115 } // namespace mbed
thedo 167:2ee3e82cb6f5 116
thedo 167:2ee3e82cb6f5 117 #endif
thedo 167:2ee3e82cb6f5 118