Final version.

Dependencies:   F746_GUI F746_SAI_IO UIT_FFT_Real

Fork of F746_Spectrogram by 不韋 呂

Committer:
mladjo1993
Date:
Wed Aug 30 07:47:58 2017 +0000
Revision:
9:444e58089d09
Parent:
4:c1beacfc42c7
Final version.

Who changed what in which revision?

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