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_ANALOGIN_H
thedo 167:1657b442184c 17 #define MBED_ANALOGIN_H
thedo 167:1657b442184c 18
thedo 167:1657b442184c 19 #include "platform/platform.h"
thedo 167:1657b442184c 20
thedo 167:1657b442184c 21 #if defined (DEVICE_ANALOGIN) || defined(DOXYGEN_ONLY)
thedo 167:1657b442184c 22
thedo 167:1657b442184c 23 #include "hal/analogin_api.h"
thedo 167:1657b442184c 24 #include "platform/SingletonPtr.h"
thedo 167:1657b442184c 25 #include "platform/PlatformMutex.h"
thedo 167:1657b442184c 26
thedo 167:1657b442184c 27 namespace mbed {
thedo 167:1657b442184c 28 /** \addtogroup drivers */
thedo 167:1657b442184c 29
thedo 167:1657b442184c 30 /** An analog input, used for reading the voltage on a pin
thedo 167:1657b442184c 31 *
thedo 167:1657b442184c 32 * @note Synchronization level: Thread safe
thedo 167:1657b442184c 33 *
thedo 167:1657b442184c 34 * Example:
thedo 167:1657b442184c 35 * @code
thedo 167:1657b442184c 36 * // Print messages when the AnalogIn is greater than 50%
thedo 167:1657b442184c 37 *
thedo 167:1657b442184c 38 * #include "mbed.h"
thedo 167:1657b442184c 39 *
thedo 167:1657b442184c 40 * AnalogIn temperature(p20);
thedo 167:1657b442184c 41 *
thedo 167:1657b442184c 42 * int main() {
thedo 167:1657b442184c 43 * while(1) {
thedo 167:1657b442184c 44 * if(temperature > 0.5) {
thedo 167:1657b442184c 45 * printf("Too hot! (%f)", temperature.read());
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 AnalogIn {
thedo 167:1657b442184c 53
thedo 167:1657b442184c 54 public:
thedo 167:1657b442184c 55
thedo 167:1657b442184c 56 /** Create an AnalogIn, connected to the specified pin
thedo 167:1657b442184c 57 *
thedo 167:1657b442184c 58 * @param pin AnalogIn pin to connect to
thedo 167:1657b442184c 59 */
thedo 167:1657b442184c 60 AnalogIn(PinName pin) {
thedo 167:1657b442184c 61 lock();
thedo 167:1657b442184c 62 analogin_init(&_adc, pin);
thedo 167:1657b442184c 63 unlock();
thedo 167:1657b442184c 64 }
thedo 167:1657b442184c 65
thedo 167:1657b442184c 66 /** Read the input voltage, represented as a float in the range [0.0, 1.0]
thedo 167:1657b442184c 67 *
thedo 167:1657b442184c 68 * @returns A floating-point value representing the current input voltage, measured as a percentage
thedo 167:1657b442184c 69 */
thedo 167:1657b442184c 70 float read() {
thedo 167:1657b442184c 71 lock();
thedo 167:1657b442184c 72 float ret = analogin_read(&_adc);
thedo 167:1657b442184c 73 unlock();
thedo 167:1657b442184c 74 return ret;
thedo 167:1657b442184c 75 }
thedo 167:1657b442184c 76
thedo 167:1657b442184c 77 /** Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
thedo 167:1657b442184c 78 *
thedo 167:1657b442184c 79 * @returns
thedo 167:1657b442184c 80 * 16-bit unsigned short representing the current input voltage, normalised to a 16-bit value
thedo 167:1657b442184c 81 */
thedo 167:1657b442184c 82 unsigned short read_u16() {
thedo 167:1657b442184c 83 lock();
thedo 167:1657b442184c 84 unsigned short ret = analogin_read_u16(&_adc);
thedo 167:1657b442184c 85 unlock();
thedo 167:1657b442184c 86 return ret;
thedo 167:1657b442184c 87 }
thedo 167:1657b442184c 88
thedo 167:1657b442184c 89 /** An operator shorthand for read()
thedo 167:1657b442184c 90 *
thedo 167:1657b442184c 91 * The float() operator can be used as a shorthand for read() to simplify common code sequences
thedo 167:1657b442184c 92 *
thedo 167:1657b442184c 93 * Example:
thedo 167:1657b442184c 94 * @code
thedo 167:1657b442184c 95 * float x = volume.read();
thedo 167:1657b442184c 96 * float x = volume;
thedo 167:1657b442184c 97 *
thedo 167:1657b442184c 98 * if(volume.read() > 0.25) { ... }
thedo 167:1657b442184c 99 * if(volume > 0.25) { ... }
thedo 167:1657b442184c 100 * @endcode
thedo 167:1657b442184c 101 */
thedo 167:1657b442184c 102 operator float() {
thedo 167:1657b442184c 103 // Underlying call is thread safe
thedo 167:1657b442184c 104 return read();
thedo 167:1657b442184c 105 }
thedo 167:1657b442184c 106
thedo 167:1657b442184c 107 virtual ~AnalogIn() {
thedo 167:1657b442184c 108 // Do nothing
thedo 167:1657b442184c 109 }
thedo 167:1657b442184c 110
thedo 167:1657b442184c 111 protected:
thedo 167:1657b442184c 112
thedo 167:1657b442184c 113 virtual void lock() {
thedo 167:1657b442184c 114 _mutex->lock();
thedo 167:1657b442184c 115 }
thedo 167:1657b442184c 116
thedo 167:1657b442184c 117 virtual void unlock() {
thedo 167:1657b442184c 118 _mutex->unlock();
thedo 167:1657b442184c 119 }
thedo 167:1657b442184c 120
thedo 167:1657b442184c 121 analogin_t _adc;
thedo 167:1657b442184c 122 static SingletonPtr<PlatformMutex> _mutex;
thedo 167:1657b442184c 123 };
thedo 167:1657b442184c 124
thedo 167:1657b442184c 125 } // namespace mbed
thedo 167:1657b442184c 126
thedo 167:1657b442184c 127 #endif
thedo 167:1657b442184c 128
thedo 167:1657b442184c 129 #endif
thedo 167:1657b442184c 130
thedo 167:1657b442184c 131