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_PWMOUT_H
thedo 167:1657b442184c 17 #define MBED_PWMOUT_H
thedo 167:1657b442184c 18
thedo 167:1657b442184c 19 #include "platform/platform.h"
thedo 167:1657b442184c 20
thedo 167:1657b442184c 21 #if defined (DEVICE_PWMOUT) || defined(DOXYGEN_ONLY)
thedo 167:1657b442184c 22 #include "hal/pwmout_api.h"
thedo 167:1657b442184c 23 #include "platform/mbed_critical.h"
thedo 167:1657b442184c 24
thedo 167:1657b442184c 25 namespace mbed {
thedo 167:1657b442184c 26 /** \addtogroup drivers */
thedo 167:1657b442184c 27
thedo 167:1657b442184c 28 /** A pulse-width modulation digital output
thedo 167:1657b442184c 29 *
thedo 167:1657b442184c 30 * @note Synchronization level: Interrupt safe
thedo 167:1657b442184c 31 *
thedo 167:1657b442184c 32 * Example
thedo 167:1657b442184c 33 * @code
thedo 167:1657b442184c 34 * // Fade a led on.
thedo 167:1657b442184c 35 * #include "mbed.h"
thedo 167:1657b442184c 36 *
thedo 167:1657b442184c 37 * PwmOut led(LED1);
thedo 167:1657b442184c 38 *
thedo 167:1657b442184c 39 * int main() {
thedo 167:1657b442184c 40 * while(1) {
thedo 167:1657b442184c 41 * led = led + 0.01;
thedo 167:1657b442184c 42 * wait(0.2);
thedo 167:1657b442184c 43 * if(led == 1.0) {
thedo 167:1657b442184c 44 * led = 0;
thedo 167:1657b442184c 45 * }
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 PwmOut {
thedo 167:1657b442184c 52
thedo 167:1657b442184c 53 public:
thedo 167:1657b442184c 54
thedo 167:1657b442184c 55 /** Create a PwmOut connected to the specified pin
thedo 167:1657b442184c 56 *
thedo 167:1657b442184c 57 * @param pin PwmOut pin to connect to
thedo 167:1657b442184c 58 */
thedo 167:1657b442184c 59 PwmOut(PinName pin) {
thedo 167:1657b442184c 60 core_util_critical_section_enter();
thedo 167:1657b442184c 61 pwmout_init(&_pwm, pin);
thedo 167:1657b442184c 62 core_util_critical_section_exit();
thedo 167:1657b442184c 63 }
thedo 167:1657b442184c 64
thedo 167:1657b442184c 65 /** Set the ouput duty-cycle, specified as a percentage (float)
thedo 167:1657b442184c 66 *
thedo 167:1657b442184c 67 * @param value A floating-point value representing the output duty-cycle,
thedo 167:1657b442184c 68 * specified as a percentage. The value should lie between
thedo 167:1657b442184c 69 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
thedo 167:1657b442184c 70 * Values outside this range will be saturated to 0.0f or 1.0f.
thedo 167:1657b442184c 71 */
thedo 167:1657b442184c 72 void write(float value) {
thedo 167:1657b442184c 73 core_util_critical_section_enter();
thedo 167:1657b442184c 74 pwmout_write(&_pwm, value);
thedo 167:1657b442184c 75 core_util_critical_section_exit();
thedo 167:1657b442184c 76 }
thedo 167:1657b442184c 77
thedo 167:1657b442184c 78 /** Return the current output duty-cycle setting, measured as a percentage (float)
thedo 167:1657b442184c 79 *
thedo 167:1657b442184c 80 * @returns
thedo 167:1657b442184c 81 * A floating-point value representing the current duty-cycle being output on the pin,
thedo 167:1657b442184c 82 * measured as a percentage. The returned value will lie between
thedo 167:1657b442184c 83 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
thedo 167:1657b442184c 84 *
thedo 167:1657b442184c 85 * @note
thedo 167:1657b442184c 86 * This value may not match exactly the value set by a previous write().
thedo 167:1657b442184c 87 */
thedo 167:1657b442184c 88 float read() {
thedo 167:1657b442184c 89 core_util_critical_section_enter();
thedo 167:1657b442184c 90 float val = pwmout_read(&_pwm);
thedo 167:1657b442184c 91 core_util_critical_section_exit();
thedo 167:1657b442184c 92 return val;
thedo 167:1657b442184c 93 }
thedo 167:1657b442184c 94
thedo 167:1657b442184c 95 /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same.
thedo 167:1657b442184c 96 *
thedo 167:1657b442184c 97 * @param seconds Change the period of a PWM signal in seconds (float) without modifying the duty cycle
thedo 167:1657b442184c 98 * @note
thedo 167:1657b442184c 99 * The resolution is currently in microseconds; periods smaller than this
thedo 167:1657b442184c 100 * will be set to zero.
thedo 167:1657b442184c 101 */
thedo 167:1657b442184c 102 void period(float seconds) {
thedo 167:1657b442184c 103 core_util_critical_section_enter();
thedo 167:1657b442184c 104 pwmout_period(&_pwm, seconds);
thedo 167:1657b442184c 105 core_util_critical_section_exit();
thedo 167:1657b442184c 106 }
thedo 167:1657b442184c 107
thedo 167:1657b442184c 108 /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.
thedo 167:1657b442184c 109 * @param ms Change the period of a PWM signal in milli-seconds without modifying the duty cycle
thedo 167:1657b442184c 110 */
thedo 167:1657b442184c 111 void period_ms(int ms) {
thedo 167:1657b442184c 112 core_util_critical_section_enter();
thedo 167:1657b442184c 113 pwmout_period_ms(&_pwm, ms);
thedo 167:1657b442184c 114 core_util_critical_section_exit();
thedo 167:1657b442184c 115 }
thedo 167:1657b442184c 116
thedo 167:1657b442184c 117 /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.
thedo 167:1657b442184c 118 * @param us Change the period of a PWM signal in micro-seconds without modifying the duty cycle
thedo 167:1657b442184c 119 */
thedo 167:1657b442184c 120 void period_us(int us) {
thedo 167:1657b442184c 121 core_util_critical_section_enter();
thedo 167:1657b442184c 122 pwmout_period_us(&_pwm, us);
thedo 167:1657b442184c 123 core_util_critical_section_exit();
thedo 167:1657b442184c 124 }
thedo 167:1657b442184c 125
thedo 167:1657b442184c 126 /** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.
thedo 167:1657b442184c 127 * @param seconds Change the pulse width of a PWM signal specified in seconds (float)
thedo 167:1657b442184c 128 */
thedo 167:1657b442184c 129 void pulsewidth(float seconds) {
thedo 167:1657b442184c 130 core_util_critical_section_enter();
thedo 167:1657b442184c 131 pwmout_pulsewidth(&_pwm, seconds);
thedo 167:1657b442184c 132 core_util_critical_section_exit();
thedo 167:1657b442184c 133 }
thedo 167:1657b442184c 134
thedo 167:1657b442184c 135 /** Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same.
thedo 167:1657b442184c 136 * @param ms Change the pulse width of a PWM signal specified in milli-seconds
thedo 167:1657b442184c 137 */
thedo 167:1657b442184c 138 void pulsewidth_ms(int ms) {
thedo 167:1657b442184c 139 core_util_critical_section_enter();
thedo 167:1657b442184c 140 pwmout_pulsewidth_ms(&_pwm, ms);
thedo 167:1657b442184c 141 core_util_critical_section_exit();
thedo 167:1657b442184c 142 }
thedo 167:1657b442184c 143
thedo 167:1657b442184c 144 /** Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same.
thedo 167:1657b442184c 145 * @param us Change the pulse width of a PWM signal specified in micro-seconds
thedo 167:1657b442184c 146 */
thedo 167:1657b442184c 147 void pulsewidth_us(int us) {
thedo 167:1657b442184c 148 core_util_critical_section_enter();
thedo 167:1657b442184c 149 pwmout_pulsewidth_us(&_pwm, us);
thedo 167:1657b442184c 150 core_util_critical_section_exit();
thedo 167:1657b442184c 151 }
thedo 167:1657b442184c 152
thedo 167:1657b442184c 153 /** A operator shorthand for write()
thedo 167:1657b442184c 154 */
thedo 167:1657b442184c 155 PwmOut& operator= (float value) {
thedo 167:1657b442184c 156 // Underlying call is thread safe
thedo 167:1657b442184c 157 write(value);
thedo 167:1657b442184c 158 return *this;
thedo 167:1657b442184c 159 }
thedo 167:1657b442184c 160
thedo 167:1657b442184c 161 /** A operator shorthand for write()
thedo 167:1657b442184c 162 */
thedo 167:1657b442184c 163 PwmOut& operator= (PwmOut& rhs) {
thedo 167:1657b442184c 164 // Underlying call is thread safe
thedo 167:1657b442184c 165 write(rhs.read());
thedo 167:1657b442184c 166 return *this;
thedo 167:1657b442184c 167 }
thedo 167:1657b442184c 168
thedo 167:1657b442184c 169 /** An operator shorthand for read()
thedo 167:1657b442184c 170 */
thedo 167:1657b442184c 171 operator float() {
thedo 167:1657b442184c 172 // Underlying call is thread safe
thedo 167:1657b442184c 173 return read();
thedo 167:1657b442184c 174 }
thedo 167:1657b442184c 175
thedo 167:1657b442184c 176 protected:
thedo 167:1657b442184c 177 pwmout_t _pwm;
thedo 167:1657b442184c 178 };
thedo 167:1657b442184c 179
thedo 167:1657b442184c 180 } // namespace mbed
thedo 167:1657b442184c 181
thedo 167:1657b442184c 182 #endif
thedo 167:1657b442184c 183
thedo 167:1657b442184c 184 #endif
thedo 167:1657b442184c 185