Opencv 3.1 project on GR-PEACH board

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

Committer:
thedo
Date:
Tue Jul 04 06:23:13 2017 +0000
Revision:
170:54ff26da7eb6
Parent:
167:1657b442184c
project opencv 3.1 on GR PEACH board, no use SD card.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thedo 167:1657b442184c 1 /* mbed Microcontroller Library
thedo 167:1657b442184c 2 * Copyright (c) 2006-2013 ARM Limited
thedo 167:1657b442184c 3 *
thedo 167:1657b442184c 4 * Licensed under the Apache License, Version 2.0 (the "License");
thedo 167:1657b442184c 5 * you may not use this file except in compliance with the License.
thedo 167:1657b442184c 6 * You may obtain a copy of the License at
thedo 167:1657b442184c 7 *
thedo 167:1657b442184c 8 * http://www.apache.org/licenses/LICENSE-2.0
thedo 167:1657b442184c 9 *
thedo 167:1657b442184c 10 * Unless required by applicable law or agreed to in writing, software
thedo 167:1657b442184c 11 * distributed under the License is distributed on an "AS IS" BASIS,
thedo 167:1657b442184c 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
thedo 167:1657b442184c 13 * See the License for the specific language governing permissions and
thedo 167:1657b442184c 14 * limitations under the License.
thedo 167:1657b442184c 15 */
thedo 167:1657b442184c 16 #ifndef MBED_DIGITALIN_H
thedo 167:1657b442184c 17 #define MBED_DIGITALIN_H
thedo 167:1657b442184c 18
thedo 167:1657b442184c 19 #include "platform/platform.h"
thedo 167:1657b442184c 20
thedo 167:1657b442184c 21 #include "hal/gpio_api.h"
thedo 167:1657b442184c 22 #include "platform/mbed_critical.h"
thedo 167:1657b442184c 23
thedo 167:1657b442184c 24 namespace mbed {
thedo 167:1657b442184c 25 /** \addtogroup drivers */
thedo 167:1657b442184c 26
thedo 167:1657b442184c 27 /** A digital input, used for reading the state of a pin
thedo 167:1657b442184c 28 *
thedo 167:1657b442184c 29 * @note Synchronization level: Interrupt safe
thedo 167:1657b442184c 30 *
thedo 167:1657b442184c 31 * Example:
thedo 167:1657b442184c 32 * @code
thedo 167:1657b442184c 33 * // Flash an LED while a DigitalIn is true
thedo 167:1657b442184c 34 *
thedo 167:1657b442184c 35 * #include "mbed.h"
thedo 167:1657b442184c 36 *
thedo 167:1657b442184c 37 * DigitalIn enable(p5);
thedo 167:1657b442184c 38 * DigitalOut led(LED1);
thedo 167:1657b442184c 39 *
thedo 167:1657b442184c 40 * int main() {
thedo 167:1657b442184c 41 * while(1) {
thedo 167:1657b442184c 42 * if(enable) {
thedo 167:1657b442184c 43 * led = !led;
thedo 167:1657b442184c 44 * }
thedo 167:1657b442184c 45 * wait(0.25);
thedo 167:1657b442184c 46 * }
thedo 167:1657b442184c 47 * }
thedo 167:1657b442184c 48 * @endcode
thedo 167:1657b442184c 49 * @ingroup drivers
thedo 167:1657b442184c 50 */
thedo 167:1657b442184c 51 class DigitalIn {
thedo 167:1657b442184c 52
thedo 167:1657b442184c 53 public:
thedo 167:1657b442184c 54 /** Create a DigitalIn connected to the specified pin
thedo 167:1657b442184c 55 *
thedo 167:1657b442184c 56 * @param pin DigitalIn pin to connect to
thedo 167:1657b442184c 57 */
thedo 167:1657b442184c 58 DigitalIn(PinName pin) : gpio() {
thedo 167:1657b442184c 59 // No lock needed in the constructor
thedo 167:1657b442184c 60 gpio_init_in(&gpio, pin);
thedo 167:1657b442184c 61 }
thedo 167:1657b442184c 62
thedo 167:1657b442184c 63 /** Create a DigitalIn connected to the specified pin
thedo 167:1657b442184c 64 *
thedo 167:1657b442184c 65 * @param pin DigitalIn pin to connect to
thedo 167:1657b442184c 66 * @param mode the initial mode of the pin
thedo 167:1657b442184c 67 */
thedo 167:1657b442184c 68 DigitalIn(PinName pin, PinMode mode) : gpio() {
thedo 167:1657b442184c 69 // No lock needed in the constructor
thedo 167:1657b442184c 70 gpio_init_in_ex(&gpio, pin, mode);
thedo 167:1657b442184c 71 }
thedo 167:1657b442184c 72 /** Read the input, represented as 0 or 1 (int)
thedo 167:1657b442184c 73 *
thedo 167:1657b442184c 74 * @returns
thedo 167:1657b442184c 75 * An integer representing the state of the input pin,
thedo 167:1657b442184c 76 * 0 for logical 0, 1 for logical 1
thedo 167:1657b442184c 77 */
thedo 167:1657b442184c 78 int read() {
thedo 167:1657b442184c 79 // Thread safe / atomic HAL call
thedo 167:1657b442184c 80 return gpio_read(&gpio);
thedo 167:1657b442184c 81 }
thedo 167:1657b442184c 82
thedo 167:1657b442184c 83 /** Set the input pin mode
thedo 167:1657b442184c 84 *
thedo 167:1657b442184c 85 * @param pull PullUp, PullDown, PullNone, OpenDrain
thedo 167:1657b442184c 86 */
thedo 167:1657b442184c 87 void mode(PinMode pull) {
thedo 167:1657b442184c 88 core_util_critical_section_enter();
thedo 167:1657b442184c 89 gpio_mode(&gpio, pull);
thedo 167:1657b442184c 90 core_util_critical_section_exit();
thedo 167:1657b442184c 91 }
thedo 167:1657b442184c 92
thedo 167:1657b442184c 93 /** Return the output setting, represented as 0 or 1 (int)
thedo 167:1657b442184c 94 *
thedo 167:1657b442184c 95 * @returns
thedo 167:1657b442184c 96 * Non zero value if pin is connected to uc GPIO
thedo 167:1657b442184c 97 * 0 if gpio object was initialized with NC
thedo 167:1657b442184c 98 */
thedo 167:1657b442184c 99 int is_connected() {
thedo 167:1657b442184c 100 // Thread safe / atomic HAL call
thedo 167:1657b442184c 101 return gpio_is_connected(&gpio);
thedo 167:1657b442184c 102 }
thedo 167:1657b442184c 103
thedo 167:1657b442184c 104 /** An operator shorthand for read()
thedo 167:1657b442184c 105 */
thedo 167:1657b442184c 106 operator int() {
thedo 167:1657b442184c 107 // Underlying read is thread safe
thedo 167:1657b442184c 108 return read();
thedo 167:1657b442184c 109 }
thedo 167:1657b442184c 110
thedo 167:1657b442184c 111 protected:
thedo 167:1657b442184c 112 gpio_t gpio;
thedo 167:1657b442184c 113 };
thedo 167:1657b442184c 114
thedo 167:1657b442184c 115 } // namespace mbed
thedo 167:1657b442184c 116
thedo 167:1657b442184c 117 #endif
thedo 167:1657b442184c 118