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