SDCard version

Fork of gr-peach-opencv-project-sd-card by the do

Committer:
thedo
Date:
Fri Jul 21 01:26:54 2017 +0000
Revision:
167:2ee3e82cb6f5
gr-peach-opencv-project-sd-card

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thedo 167:2ee3e82cb6f5 1 /* mbed Microcontroller Library
thedo 167:2ee3e82cb6f5 2 * Copyright (c) 2006-2013 ARM Limited
thedo 167:2ee3e82cb6f5 3 *
thedo 167:2ee3e82cb6f5 4 * Licensed under the Apache License, Version 2.0 (the "License");
thedo 167:2ee3e82cb6f5 5 * you may not use this file except in compliance with the License.
thedo 167:2ee3e82cb6f5 6 * You may obtain a copy of the License at
thedo 167:2ee3e82cb6f5 7 *
thedo 167:2ee3e82cb6f5 8 * http://www.apache.org/licenses/LICENSE-2.0
thedo 167:2ee3e82cb6f5 9 *
thedo 167:2ee3e82cb6f5 10 * Unless required by applicable law or agreed to in writing, software
thedo 167:2ee3e82cb6f5 11 * distributed under the License is distributed on an "AS IS" BASIS,
thedo 167:2ee3e82cb6f5 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
thedo 167:2ee3e82cb6f5 13 * See the License for the specific language governing permissions and
thedo 167:2ee3e82cb6f5 14 * limitations under the License.
thedo 167:2ee3e82cb6f5 15 */
thedo 167:2ee3e82cb6f5 16 #ifndef MBED_ANALOGOUT_H
thedo 167:2ee3e82cb6f5 17 #define MBED_ANALOGOUT_H
thedo 167:2ee3e82cb6f5 18
thedo 167:2ee3e82cb6f5 19 #include "platform/platform.h"
thedo 167:2ee3e82cb6f5 20
thedo 167:2ee3e82cb6f5 21 #if defined (DEVICE_ANALOGOUT) || defined(DOXYGEN_ONLY)
thedo 167:2ee3e82cb6f5 22
thedo 167:2ee3e82cb6f5 23 #include "hal/analogout_api.h"
thedo 167:2ee3e82cb6f5 24 #include "platform/PlatformMutex.h"
thedo 167:2ee3e82cb6f5 25
thedo 167:2ee3e82cb6f5 26 namespace mbed {
thedo 167:2ee3e82cb6f5 27 /** \addtogroup drivers */
thedo 167:2ee3e82cb6f5 28
thedo 167:2ee3e82cb6f5 29 /** An analog output, used for setting the voltage on a pin
thedo 167:2ee3e82cb6f5 30 *
thedo 167:2ee3e82cb6f5 31 * @note Synchronization level: Thread safe
thedo 167:2ee3e82cb6f5 32 *
thedo 167:2ee3e82cb6f5 33 * Example:
thedo 167:2ee3e82cb6f5 34 * @code
thedo 167:2ee3e82cb6f5 35 * // Make a sawtooth output
thedo 167:2ee3e82cb6f5 36 *
thedo 167:2ee3e82cb6f5 37 * #include "mbed.h"
thedo 167:2ee3e82cb6f5 38 *
thedo 167:2ee3e82cb6f5 39 * AnalogOut tri(p18);
thedo 167:2ee3e82cb6f5 40 * int main() {
thedo 167:2ee3e82cb6f5 41 * while(1) {
thedo 167:2ee3e82cb6f5 42 * tri = tri + 0.01;
thedo 167:2ee3e82cb6f5 43 * wait_us(1);
thedo 167:2ee3e82cb6f5 44 * if(tri == 1) {
thedo 167:2ee3e82cb6f5 45 * tri = 0;
thedo 167:2ee3e82cb6f5 46 * }
thedo 167:2ee3e82cb6f5 47 * }
thedo 167:2ee3e82cb6f5 48 * }
thedo 167:2ee3e82cb6f5 49 * @endcode
thedo 167:2ee3e82cb6f5 50 * @ingroup drivers
thedo 167:2ee3e82cb6f5 51 */
thedo 167:2ee3e82cb6f5 52 class AnalogOut {
thedo 167:2ee3e82cb6f5 53
thedo 167:2ee3e82cb6f5 54 public:
thedo 167:2ee3e82cb6f5 55
thedo 167:2ee3e82cb6f5 56 /** Create an AnalogOut connected to the specified pin
thedo 167:2ee3e82cb6f5 57 *
thedo 167:2ee3e82cb6f5 58 * @param pin AnalogOut pin to connect to
thedo 167:2ee3e82cb6f5 59 */
thedo 167:2ee3e82cb6f5 60 AnalogOut(PinName pin) {
thedo 167:2ee3e82cb6f5 61 analogout_init(&_dac, pin);
thedo 167:2ee3e82cb6f5 62 }
thedo 167:2ee3e82cb6f5 63
thedo 167:2ee3e82cb6f5 64 /** Set the output voltage, specified as a percentage (float)
thedo 167:2ee3e82cb6f5 65 *
thedo 167:2ee3e82cb6f5 66 * @param value A floating-point value representing the output voltage,
thedo 167:2ee3e82cb6f5 67 * specified as a percentage. The value should lie between
thedo 167:2ee3e82cb6f5 68 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
thedo 167:2ee3e82cb6f5 69 * Values outside this range will be saturated to 0.0f or 1.0f.
thedo 167:2ee3e82cb6f5 70 */
thedo 167:2ee3e82cb6f5 71 void write(float value) {
thedo 167:2ee3e82cb6f5 72 lock();
thedo 167:2ee3e82cb6f5 73 analogout_write(&_dac, value);
thedo 167:2ee3e82cb6f5 74 unlock();
thedo 167:2ee3e82cb6f5 75 }
thedo 167:2ee3e82cb6f5 76
thedo 167:2ee3e82cb6f5 77 /** Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
thedo 167:2ee3e82cb6f5 78 *
thedo 167:2ee3e82cb6f5 79 * @param value 16-bit unsigned short representing the output voltage,
thedo 167:2ee3e82cb6f5 80 * normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v)
thedo 167:2ee3e82cb6f5 81 */
thedo 167:2ee3e82cb6f5 82 void write_u16(unsigned short value) {
thedo 167:2ee3e82cb6f5 83 lock();
thedo 167:2ee3e82cb6f5 84 analogout_write_u16(&_dac, value);
thedo 167:2ee3e82cb6f5 85 unlock();
thedo 167:2ee3e82cb6f5 86 }
thedo 167:2ee3e82cb6f5 87
thedo 167:2ee3e82cb6f5 88 /** Return the current output voltage setting, measured as a percentage (float)
thedo 167:2ee3e82cb6f5 89 *
thedo 167:2ee3e82cb6f5 90 * @returns
thedo 167:2ee3e82cb6f5 91 * A floating-point value representing the current voltage being output on the pin,
thedo 167:2ee3e82cb6f5 92 * measured as a percentage. The returned value will lie between
thedo 167:2ee3e82cb6f5 93 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
thedo 167:2ee3e82cb6f5 94 *
thedo 167:2ee3e82cb6f5 95 * @note
thedo 167:2ee3e82cb6f5 96 * This value may not match exactly the value set by a previous write().
thedo 167:2ee3e82cb6f5 97 */
thedo 167:2ee3e82cb6f5 98 float read() {
thedo 167:2ee3e82cb6f5 99 lock();
thedo 167:2ee3e82cb6f5 100 float ret = analogout_read(&_dac);
thedo 167:2ee3e82cb6f5 101 unlock();
thedo 167:2ee3e82cb6f5 102 return ret;
thedo 167:2ee3e82cb6f5 103 }
thedo 167:2ee3e82cb6f5 104
thedo 167:2ee3e82cb6f5 105 /** An operator shorthand for write()
thedo 167:2ee3e82cb6f5 106 */
thedo 167:2ee3e82cb6f5 107 AnalogOut& operator= (float percent) {
thedo 167:2ee3e82cb6f5 108 // Underlying write call is thread safe
thedo 167:2ee3e82cb6f5 109 write(percent);
thedo 167:2ee3e82cb6f5 110 return *this;
thedo 167:2ee3e82cb6f5 111 }
thedo 167:2ee3e82cb6f5 112
thedo 167:2ee3e82cb6f5 113 AnalogOut& operator= (AnalogOut& rhs) {
thedo 167:2ee3e82cb6f5 114 // Underlying write call is thread safe
thedo 167:2ee3e82cb6f5 115 write(rhs.read());
thedo 167:2ee3e82cb6f5 116 return *this;
thedo 167:2ee3e82cb6f5 117 }
thedo 167:2ee3e82cb6f5 118
thedo 167:2ee3e82cb6f5 119 /** An operator shorthand for read()
thedo 167:2ee3e82cb6f5 120 */
thedo 167:2ee3e82cb6f5 121 operator float() {
thedo 167:2ee3e82cb6f5 122 // Underlying read call is thread safe
thedo 167:2ee3e82cb6f5 123 return read();
thedo 167:2ee3e82cb6f5 124 }
thedo 167:2ee3e82cb6f5 125
thedo 167:2ee3e82cb6f5 126 virtual ~AnalogOut() {
thedo 167:2ee3e82cb6f5 127 // Do nothing
thedo 167:2ee3e82cb6f5 128 }
thedo 167:2ee3e82cb6f5 129
thedo 167:2ee3e82cb6f5 130 protected:
thedo 167:2ee3e82cb6f5 131
thedo 167:2ee3e82cb6f5 132 virtual void lock() {
thedo 167:2ee3e82cb6f5 133 _mutex.lock();
thedo 167:2ee3e82cb6f5 134 }
thedo 167:2ee3e82cb6f5 135
thedo 167:2ee3e82cb6f5 136 virtual void unlock() {
thedo 167:2ee3e82cb6f5 137 _mutex.unlock();
thedo 167:2ee3e82cb6f5 138 }
thedo 167:2ee3e82cb6f5 139
thedo 167:2ee3e82cb6f5 140 dac_t _dac;
thedo 167:2ee3e82cb6f5 141 PlatformMutex _mutex;
thedo 167:2ee3e82cb6f5 142 };
thedo 167:2ee3e82cb6f5 143
thedo 167:2ee3e82cb6f5 144 } // namespace mbed
thedo 167:2ee3e82cb6f5 145
thedo 167:2ee3e82cb6f5 146 #endif
thedo 167:2ee3e82cb6f5 147
thedo 167:2ee3e82cb6f5 148 #endif
thedo 167:2ee3e82cb6f5 149