Final version.
Dependencies: F746_GUI F746_SAI_IO UIT_FFT_Real
Fork of F746_Spectrogram by
mbed_src_STM32F7/api/PwmOut.h@4:c1beacfc42c7, 2016-10-02 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sun Oct 02 10:51:10 2016 +0000
- Revision:
- 4:c1beacfc42c7
5
Who changed what in which revision?
User | Revision | Line number | New 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_PWMOUT_H |
MikamiUitOpen | 4:c1beacfc42c7 | 17 | #define MBED_PWMOUT_H |
MikamiUitOpen | 4:c1beacfc42c7 | 18 | |
MikamiUitOpen | 4:c1beacfc42c7 | 19 | #include "platform.h" |
MikamiUitOpen | 4:c1beacfc42c7 | 20 | |
MikamiUitOpen | 4:c1beacfc42c7 | 21 | #if DEVICE_PWMOUT |
MikamiUitOpen | 4:c1beacfc42c7 | 22 | #include "pwmout_api.h" |
MikamiUitOpen | 4:c1beacfc42c7 | 23 | |
MikamiUitOpen | 4:c1beacfc42c7 | 24 | namespace mbed { |
MikamiUitOpen | 4:c1beacfc42c7 | 25 | |
MikamiUitOpen | 4:c1beacfc42c7 | 26 | /** A pulse-width modulation digital output |
MikamiUitOpen | 4:c1beacfc42c7 | 27 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 28 | * Example |
MikamiUitOpen | 4:c1beacfc42c7 | 29 | * @code |
MikamiUitOpen | 4:c1beacfc42c7 | 30 | * // Fade a led on. |
MikamiUitOpen | 4:c1beacfc42c7 | 31 | * #include "mbed.h" |
MikamiUitOpen | 4:c1beacfc42c7 | 32 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 33 | * PwmOut led(LED1); |
MikamiUitOpen | 4:c1beacfc42c7 | 34 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 35 | * int main() { |
MikamiUitOpen | 4:c1beacfc42c7 | 36 | * while(1) { |
MikamiUitOpen | 4:c1beacfc42c7 | 37 | * led = led + 0.01; |
MikamiUitOpen | 4:c1beacfc42c7 | 38 | * wait(0.2); |
MikamiUitOpen | 4:c1beacfc42c7 | 39 | * if(led == 1.0) { |
MikamiUitOpen | 4:c1beacfc42c7 | 40 | * led = 0; |
MikamiUitOpen | 4:c1beacfc42c7 | 41 | * } |
MikamiUitOpen | 4:c1beacfc42c7 | 42 | * } |
MikamiUitOpen | 4:c1beacfc42c7 | 43 | * } |
MikamiUitOpen | 4:c1beacfc42c7 | 44 | * @endcode |
MikamiUitOpen | 4:c1beacfc42c7 | 45 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 46 | * @note |
MikamiUitOpen | 4:c1beacfc42c7 | 47 | * On the LPC1768 and LPC2368, the PWMs all share the same |
MikamiUitOpen | 4:c1beacfc42c7 | 48 | * period - if you change the period for one, you change it for all. |
MikamiUitOpen | 4:c1beacfc42c7 | 49 | * Although routines that change the period maintain the duty cycle |
MikamiUitOpen | 4:c1beacfc42c7 | 50 | * for its PWM, all other PWMs will require their duty cycle to be |
MikamiUitOpen | 4:c1beacfc42c7 | 51 | * refreshed. |
MikamiUitOpen | 4:c1beacfc42c7 | 52 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 53 | class PwmOut { |
MikamiUitOpen | 4:c1beacfc42c7 | 54 | |
MikamiUitOpen | 4:c1beacfc42c7 | 55 | public: |
MikamiUitOpen | 4:c1beacfc42c7 | 56 | |
MikamiUitOpen | 4:c1beacfc42c7 | 57 | /** Create a PwmOut connected to the specified pin |
MikamiUitOpen | 4:c1beacfc42c7 | 58 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 59 | * @param pin PwmOut pin to connect to |
MikamiUitOpen | 4:c1beacfc42c7 | 60 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 61 | PwmOut(PinName pin) { |
MikamiUitOpen | 4:c1beacfc42c7 | 62 | pwmout_init(&_pwm, pin); |
MikamiUitOpen | 4:c1beacfc42c7 | 63 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 64 | |
MikamiUitOpen | 4:c1beacfc42c7 | 65 | /** Set the ouput duty-cycle, specified as a percentage (float) |
MikamiUitOpen | 4:c1beacfc42c7 | 66 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 67 | * @param value A floating-point value representing the output duty-cycle, |
MikamiUitOpen | 4:c1beacfc42c7 | 68 | * specified as a percentage. The value should lie between |
MikamiUitOpen | 4:c1beacfc42c7 | 69 | * 0.0f (representing on 0%) and 1.0f (representing on 100%). |
MikamiUitOpen | 4:c1beacfc42c7 | 70 | * Values outside this range will be saturated to 0.0f or 1.0f. |
MikamiUitOpen | 4:c1beacfc42c7 | 71 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 72 | void write(float value) { |
MikamiUitOpen | 4:c1beacfc42c7 | 73 | pwmout_write(&_pwm, value); |
MikamiUitOpen | 4:c1beacfc42c7 | 74 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 75 | |
MikamiUitOpen | 4:c1beacfc42c7 | 76 | /** Return the current output duty-cycle setting, measured as a percentage (float) |
MikamiUitOpen | 4:c1beacfc42c7 | 77 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 78 | * @returns |
MikamiUitOpen | 4:c1beacfc42c7 | 79 | * A floating-point value representing the current duty-cycle being output on the pin, |
MikamiUitOpen | 4:c1beacfc42c7 | 80 | * measured as a percentage. The returned value will lie between |
MikamiUitOpen | 4:c1beacfc42c7 | 81 | * 0.0f (representing on 0%) and 1.0f (representing on 100%). |
MikamiUitOpen | 4:c1beacfc42c7 | 82 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 83 | * @note |
MikamiUitOpen | 4:c1beacfc42c7 | 84 | * This value may not match exactly the value set by a previous <write>. |
MikamiUitOpen | 4:c1beacfc42c7 | 85 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 86 | float read() { |
MikamiUitOpen | 4:c1beacfc42c7 | 87 | return pwmout_read(&_pwm); |
MikamiUitOpen | 4:c1beacfc42c7 | 88 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 89 | |
MikamiUitOpen | 4:c1beacfc42c7 | 90 | /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same. |
MikamiUitOpen | 4:c1beacfc42c7 | 91 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 92 | * @note |
MikamiUitOpen | 4:c1beacfc42c7 | 93 | * The resolution is currently in microseconds; periods smaller than this |
MikamiUitOpen | 4:c1beacfc42c7 | 94 | * will be set to zero. |
MikamiUitOpen | 4:c1beacfc42c7 | 95 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 96 | void period(float seconds) { |
MikamiUitOpen | 4:c1beacfc42c7 | 97 | pwmout_period(&_pwm, seconds); |
MikamiUitOpen | 4:c1beacfc42c7 | 98 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 99 | |
MikamiUitOpen | 4:c1beacfc42c7 | 100 | /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same. |
MikamiUitOpen | 4:c1beacfc42c7 | 101 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 102 | void period_ms(int ms) { |
MikamiUitOpen | 4:c1beacfc42c7 | 103 | pwmout_period_ms(&_pwm, ms); |
MikamiUitOpen | 4:c1beacfc42c7 | 104 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 105 | |
MikamiUitOpen | 4:c1beacfc42c7 | 106 | /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same. |
MikamiUitOpen | 4:c1beacfc42c7 | 107 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 108 | void period_us(int us) { |
MikamiUitOpen | 4:c1beacfc42c7 | 109 | pwmout_period_us(&_pwm, us); |
MikamiUitOpen | 4:c1beacfc42c7 | 110 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 111 | |
MikamiUitOpen | 4:c1beacfc42c7 | 112 | /** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same. |
MikamiUitOpen | 4:c1beacfc42c7 | 113 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 114 | void pulsewidth(float seconds) { |
MikamiUitOpen | 4:c1beacfc42c7 | 115 | pwmout_pulsewidth(&_pwm, seconds); |
MikamiUitOpen | 4:c1beacfc42c7 | 116 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 117 | |
MikamiUitOpen | 4:c1beacfc42c7 | 118 | /** Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same. |
MikamiUitOpen | 4:c1beacfc42c7 | 119 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 120 | void pulsewidth_ms(int ms) { |
MikamiUitOpen | 4:c1beacfc42c7 | 121 | pwmout_pulsewidth_ms(&_pwm, ms); |
MikamiUitOpen | 4:c1beacfc42c7 | 122 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 123 | |
MikamiUitOpen | 4:c1beacfc42c7 | 124 | /** Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same. |
MikamiUitOpen | 4:c1beacfc42c7 | 125 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 126 | void pulsewidth_us(int us) { |
MikamiUitOpen | 4:c1beacfc42c7 | 127 | pwmout_pulsewidth_us(&_pwm, us); |
MikamiUitOpen | 4:c1beacfc42c7 | 128 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 129 | |
MikamiUitOpen | 4:c1beacfc42c7 | 130 | #ifdef MBED_OPERATORS |
MikamiUitOpen | 4:c1beacfc42c7 | 131 | /** A operator shorthand for write() |
MikamiUitOpen | 4:c1beacfc42c7 | 132 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 133 | PwmOut& operator= (float value) { |
MikamiUitOpen | 4:c1beacfc42c7 | 134 | write(value); |
MikamiUitOpen | 4:c1beacfc42c7 | 135 | return *this; |
MikamiUitOpen | 4:c1beacfc42c7 | 136 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 137 | |
MikamiUitOpen | 4:c1beacfc42c7 | 138 | PwmOut& operator= (PwmOut& rhs) { |
MikamiUitOpen | 4:c1beacfc42c7 | 139 | write(rhs.read()); |
MikamiUitOpen | 4:c1beacfc42c7 | 140 | return *this; |
MikamiUitOpen | 4:c1beacfc42c7 | 141 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 142 | |
MikamiUitOpen | 4:c1beacfc42c7 | 143 | /** An operator shorthand for read() |
MikamiUitOpen | 4:c1beacfc42c7 | 144 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 145 | operator float() { |
MikamiUitOpen | 4:c1beacfc42c7 | 146 | return read(); |
MikamiUitOpen | 4:c1beacfc42c7 | 147 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 148 | #endif |
MikamiUitOpen | 4:c1beacfc42c7 | 149 | |
MikamiUitOpen | 4:c1beacfc42c7 | 150 | protected: |
MikamiUitOpen | 4:c1beacfc42c7 | 151 | pwmout_t _pwm; |
MikamiUitOpen | 4:c1beacfc42c7 | 152 | }; |
MikamiUitOpen | 4:c1beacfc42c7 | 153 | |
MikamiUitOpen | 4:c1beacfc42c7 | 154 | } // namespace mbed |
MikamiUitOpen | 4:c1beacfc42c7 | 155 | |
MikamiUitOpen | 4:c1beacfc42c7 | 156 | #endif |
MikamiUitOpen | 4:c1beacfc42c7 | 157 | |
MikamiUitOpen | 4:c1beacfc42c7 | 158 | #endif |