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_ANALOGOUT_H
thedo 167:1657b442184c 17 #define MBED_ANALOGOUT_H
thedo 167:1657b442184c 18
thedo 167:1657b442184c 19 #include "platform/platform.h"
thedo 167:1657b442184c 20
thedo 167:1657b442184c 21 #if defined (DEVICE_ANALOGOUT) || defined(DOXYGEN_ONLY)
thedo 167:1657b442184c 22
thedo 167:1657b442184c 23 #include "hal/analogout_api.h"
thedo 167:1657b442184c 24 #include "platform/PlatformMutex.h"
thedo 167:1657b442184c 25
thedo 167:1657b442184c 26 namespace mbed {
thedo 167:1657b442184c 27 /** \addtogroup drivers */
thedo 167:1657b442184c 28
thedo 167:1657b442184c 29 /** An analog output, used for setting the voltage on a pin
thedo 167:1657b442184c 30 *
thedo 167:1657b442184c 31 * @note Synchronization level: Thread safe
thedo 167:1657b442184c 32 *
thedo 167:1657b442184c 33 * Example:
thedo 167:1657b442184c 34 * @code
thedo 167:1657b442184c 35 * // Make a sawtooth output
thedo 167:1657b442184c 36 *
thedo 167:1657b442184c 37 * #include "mbed.h"
thedo 167:1657b442184c 38 *
thedo 167:1657b442184c 39 * AnalogOut tri(p18);
thedo 167:1657b442184c 40 * int main() {
thedo 167:1657b442184c 41 * while(1) {
thedo 167:1657b442184c 42 * tri = tri + 0.01;
thedo 167:1657b442184c 43 * wait_us(1);
thedo 167:1657b442184c 44 * if(tri == 1) {
thedo 167:1657b442184c 45 * tri = 0;
thedo 167:1657b442184c 46 * }
thedo 167:1657b442184c 47 * }
thedo 167:1657b442184c 48 * }
thedo 167:1657b442184c 49 * @endcode
thedo 167:1657b442184c 50 * @ingroup drivers
thedo 167:1657b442184c 51 */
thedo 167:1657b442184c 52 class AnalogOut {
thedo 167:1657b442184c 53
thedo 167:1657b442184c 54 public:
thedo 167:1657b442184c 55
thedo 167:1657b442184c 56 /** Create an AnalogOut connected to the specified pin
thedo 167:1657b442184c 57 *
thedo 167:1657b442184c 58 * @param pin AnalogOut pin to connect to
thedo 167:1657b442184c 59 */
thedo 167:1657b442184c 60 AnalogOut(PinName pin) {
thedo 167:1657b442184c 61 analogout_init(&_dac, pin);
thedo 167:1657b442184c 62 }
thedo 167:1657b442184c 63
thedo 167:1657b442184c 64 /** Set the output voltage, specified as a percentage (float)
thedo 167:1657b442184c 65 *
thedo 167:1657b442184c 66 * @param value A floating-point value representing the output voltage,
thedo 167:1657b442184c 67 * specified as a percentage. The value should lie between
thedo 167:1657b442184c 68 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
thedo 167:1657b442184c 69 * Values outside this range will be saturated to 0.0f or 1.0f.
thedo 167:1657b442184c 70 */
thedo 167:1657b442184c 71 void write(float value) {
thedo 167:1657b442184c 72 lock();
thedo 167:1657b442184c 73 analogout_write(&_dac, value);
thedo 167:1657b442184c 74 unlock();
thedo 167:1657b442184c 75 }
thedo 167:1657b442184c 76
thedo 167:1657b442184c 77 /** Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
thedo 167:1657b442184c 78 *
thedo 167:1657b442184c 79 * @param value 16-bit unsigned short representing the output voltage,
thedo 167:1657b442184c 80 * normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v)
thedo 167:1657b442184c 81 */
thedo 167:1657b442184c 82 void write_u16(unsigned short value) {
thedo 167:1657b442184c 83 lock();
thedo 167:1657b442184c 84 analogout_write_u16(&_dac, value);
thedo 167:1657b442184c 85 unlock();
thedo 167:1657b442184c 86 }
thedo 167:1657b442184c 87
thedo 167:1657b442184c 88 /** Return the current output voltage setting, measured as a percentage (float)
thedo 167:1657b442184c 89 *
thedo 167:1657b442184c 90 * @returns
thedo 167:1657b442184c 91 * A floating-point value representing the current voltage being output on the pin,
thedo 167:1657b442184c 92 * measured as a percentage. The returned value will lie between
thedo 167:1657b442184c 93 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
thedo 167:1657b442184c 94 *
thedo 167:1657b442184c 95 * @note
thedo 167:1657b442184c 96 * This value may not match exactly the value set by a previous write().
thedo 167:1657b442184c 97 */
thedo 167:1657b442184c 98 float read() {
thedo 167:1657b442184c 99 lock();
thedo 167:1657b442184c 100 float ret = analogout_read(&_dac);
thedo 167:1657b442184c 101 unlock();
thedo 167:1657b442184c 102 return ret;
thedo 167:1657b442184c 103 }
thedo 167:1657b442184c 104
thedo 167:1657b442184c 105 /** An operator shorthand for write()
thedo 167:1657b442184c 106 */
thedo 167:1657b442184c 107 AnalogOut& operator= (float percent) {
thedo 167:1657b442184c 108 // Underlying write call is thread safe
thedo 167:1657b442184c 109 write(percent);
thedo 167:1657b442184c 110 return *this;
thedo 167:1657b442184c 111 }
thedo 167:1657b442184c 112
thedo 167:1657b442184c 113 AnalogOut& operator= (AnalogOut& rhs) {
thedo 167:1657b442184c 114 // Underlying write call is thread safe
thedo 167:1657b442184c 115 write(rhs.read());
thedo 167:1657b442184c 116 return *this;
thedo 167:1657b442184c 117 }
thedo 167:1657b442184c 118
thedo 167:1657b442184c 119 /** An operator shorthand for read()
thedo 167:1657b442184c 120 */
thedo 167:1657b442184c 121 operator float() {
thedo 167:1657b442184c 122 // Underlying read call is thread safe
thedo 167:1657b442184c 123 return read();
thedo 167:1657b442184c 124 }
thedo 167:1657b442184c 125
thedo 167:1657b442184c 126 virtual ~AnalogOut() {
thedo 167:1657b442184c 127 // Do nothing
thedo 167:1657b442184c 128 }
thedo 167:1657b442184c 129
thedo 167:1657b442184c 130 protected:
thedo 167:1657b442184c 131
thedo 167:1657b442184c 132 virtual void lock() {
thedo 167:1657b442184c 133 _mutex.lock();
thedo 167:1657b442184c 134 }
thedo 167:1657b442184c 135
thedo 167:1657b442184c 136 virtual void unlock() {
thedo 167:1657b442184c 137 _mutex.unlock();
thedo 167:1657b442184c 138 }
thedo 167:1657b442184c 139
thedo 167:1657b442184c 140 dac_t _dac;
thedo 167:1657b442184c 141 PlatformMutex _mutex;
thedo 167:1657b442184c 142 };
thedo 167:1657b442184c 143
thedo 167:1657b442184c 144 } // namespace mbed
thedo 167:1657b442184c 145
thedo 167:1657b442184c 146 #endif
thedo 167:1657b442184c 147
thedo 167:1657b442184c 148 #endif
thedo 167:1657b442184c 149