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_DIGITALINOUT_H
thedo 167:1657b442184c 17 #define MBED_DIGITALINOUT_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/output, used for setting or reading a bi-directional pin
thedo 167:1657b442184c 28 *
thedo 167:1657b442184c 29 * @note Synchronization level: Interrupt safe
thedo 167:1657b442184c 30 * @ingroup drivers
thedo 167:1657b442184c 31 */
thedo 167:1657b442184c 32 class DigitalInOut {
thedo 167:1657b442184c 33
thedo 167:1657b442184c 34 public:
thedo 167:1657b442184c 35 /** Create a DigitalInOut connected to the specified pin
thedo 167:1657b442184c 36 *
thedo 167:1657b442184c 37 * @param pin DigitalInOut pin to connect to
thedo 167:1657b442184c 38 */
thedo 167:1657b442184c 39 DigitalInOut(PinName pin) : gpio() {
thedo 167:1657b442184c 40 // No lock needed in the constructor
thedo 167:1657b442184c 41 gpio_init_in(&gpio, pin);
thedo 167:1657b442184c 42 }
thedo 167:1657b442184c 43
thedo 167:1657b442184c 44 /** Create a DigitalInOut connected to the specified pin
thedo 167:1657b442184c 45 *
thedo 167:1657b442184c 46 * @param pin DigitalInOut pin to connect to
thedo 167:1657b442184c 47 * @param direction the initial direction of the pin
thedo 167:1657b442184c 48 * @param mode the initial mode of the pin
thedo 167:1657b442184c 49 * @param value the initial value of the pin if is an output
thedo 167:1657b442184c 50 */
thedo 167:1657b442184c 51 DigitalInOut(PinName pin, PinDirection direction, PinMode mode, int value) : gpio() {
thedo 167:1657b442184c 52 // No lock needed in the constructor
thedo 167:1657b442184c 53 gpio_init_inout(&gpio, pin, direction, mode, value);
thedo 167:1657b442184c 54 }
thedo 167:1657b442184c 55
thedo 167:1657b442184c 56 /** Set the output, specified as 0 or 1 (int)
thedo 167:1657b442184c 57 *
thedo 167:1657b442184c 58 * @param value An integer specifying the pin output value,
thedo 167:1657b442184c 59 * 0 for logical 0, 1 (or any other non-zero value) for logical 1
thedo 167:1657b442184c 60 */
thedo 167:1657b442184c 61 void write(int value) {
thedo 167:1657b442184c 62 // Thread safe / atomic HAL call
thedo 167:1657b442184c 63 gpio_write(&gpio, value);
thedo 167:1657b442184c 64 }
thedo 167:1657b442184c 65
thedo 167:1657b442184c 66 /** Return the output setting, represented as 0 or 1 (int)
thedo 167:1657b442184c 67 *
thedo 167:1657b442184c 68 * @returns
thedo 167:1657b442184c 69 * an integer representing the output setting of the pin if it is an output,
thedo 167:1657b442184c 70 * or read the input if set as an input
thedo 167:1657b442184c 71 */
thedo 167:1657b442184c 72 int read() {
thedo 167:1657b442184c 73 // Thread safe / atomic HAL call
thedo 167:1657b442184c 74 return gpio_read(&gpio);
thedo 167:1657b442184c 75 }
thedo 167:1657b442184c 76
thedo 167:1657b442184c 77 /** Set as an output
thedo 167:1657b442184c 78 */
thedo 167:1657b442184c 79 void output() {
thedo 167:1657b442184c 80 core_util_critical_section_enter();
thedo 167:1657b442184c 81 gpio_dir(&gpio, PIN_OUTPUT);
thedo 167:1657b442184c 82 core_util_critical_section_exit();
thedo 167:1657b442184c 83 }
thedo 167:1657b442184c 84
thedo 167:1657b442184c 85 /** Set as an input
thedo 167:1657b442184c 86 */
thedo 167:1657b442184c 87 void input() {
thedo 167:1657b442184c 88 core_util_critical_section_enter();
thedo 167:1657b442184c 89 gpio_dir(&gpio, PIN_INPUT);
thedo 167:1657b442184c 90 core_util_critical_section_exit();
thedo 167:1657b442184c 91 }
thedo 167:1657b442184c 92
thedo 167:1657b442184c 93 /** Set the input pin mode
thedo 167:1657b442184c 94 *
thedo 167:1657b442184c 95 * @param pull PullUp, PullDown, PullNone, OpenDrain
thedo 167:1657b442184c 96 */
thedo 167:1657b442184c 97 void mode(PinMode pull) {
thedo 167:1657b442184c 98 core_util_critical_section_enter();
thedo 167:1657b442184c 99 gpio_mode(&gpio, pull);
thedo 167:1657b442184c 100 core_util_critical_section_exit();
thedo 167:1657b442184c 101 }
thedo 167:1657b442184c 102
thedo 167:1657b442184c 103 /** Return the output setting, represented as 0 or 1 (int)
thedo 167:1657b442184c 104 *
thedo 167:1657b442184c 105 * @returns
thedo 167:1657b442184c 106 * Non zero value if pin is connected to uc GPIO
thedo 167:1657b442184c 107 * 0 if gpio object was initialized with NC
thedo 167:1657b442184c 108 */
thedo 167:1657b442184c 109 int is_connected() {
thedo 167:1657b442184c 110 // Thread safe / atomic HAL call
thedo 167:1657b442184c 111 return gpio_is_connected(&gpio);
thedo 167:1657b442184c 112 }
thedo 167:1657b442184c 113
thedo 167:1657b442184c 114 /** A shorthand for write()
thedo 167:1657b442184c 115 */
thedo 167:1657b442184c 116 DigitalInOut& operator= (int value) {
thedo 167:1657b442184c 117 // Underlying write is thread safe
thedo 167:1657b442184c 118 write(value);
thedo 167:1657b442184c 119 return *this;
thedo 167:1657b442184c 120 }
thedo 167:1657b442184c 121
thedo 167:1657b442184c 122 DigitalInOut& operator= (DigitalInOut& rhs) {
thedo 167:1657b442184c 123 core_util_critical_section_enter();
thedo 167:1657b442184c 124 write(rhs.read());
thedo 167:1657b442184c 125 core_util_critical_section_exit();
thedo 167:1657b442184c 126 return *this;
thedo 167:1657b442184c 127 }
thedo 167:1657b442184c 128
thedo 167:1657b442184c 129 /** A shorthand for read()
thedo 167:1657b442184c 130 */
thedo 167:1657b442184c 131 operator int() {
thedo 167:1657b442184c 132 // Underlying call is thread safe
thedo 167:1657b442184c 133 return read();
thedo 167:1657b442184c 134 }
thedo 167:1657b442184c 135
thedo 167:1657b442184c 136 protected:
thedo 167:1657b442184c 137 gpio_t gpio;
thedo 167:1657b442184c 138 };
thedo 167:1657b442184c 139
thedo 167:1657b442184c 140 } // namespace mbed
thedo 167:1657b442184c 141
thedo 167:1657b442184c 142 #endif
thedo 167:1657b442184c 143