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