Describes predefine macros for mbed online compiler (armcc)

Committer:
MACRUM
Date:
Thu Mar 16 21:58:09 2017 +0900
Revision:
6:40e873bbc5f7
Add licence header info

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MACRUM 6:40e873bbc5f7 1 /* mbed Microcontroller Library
MACRUM 6:40e873bbc5f7 2 * Copyright (c) 2006-2013 ARM Limited
MACRUM 6:40e873bbc5f7 3 *
MACRUM 6:40e873bbc5f7 4 * Licensed under the Apache License, Version 2.0 (the "License");
MACRUM 6:40e873bbc5f7 5 * you may not use this file except in compliance with the License.
MACRUM 6:40e873bbc5f7 6 * You may obtain a copy of the License at
MACRUM 6:40e873bbc5f7 7 *
MACRUM 6:40e873bbc5f7 8 * http://www.apache.org/licenses/LICENSE-2.0
MACRUM 6:40e873bbc5f7 9 *
MACRUM 6:40e873bbc5f7 10 * Unless required by applicable law or agreed to in writing, software
MACRUM 6:40e873bbc5f7 11 * distributed under the License is distributed on an "AS IS" BASIS,
MACRUM 6:40e873bbc5f7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MACRUM 6:40e873bbc5f7 13 * See the License for the specific language governing permissions and
MACRUM 6:40e873bbc5f7 14 * limitations under the License.
MACRUM 6:40e873bbc5f7 15 */
MACRUM 6:40e873bbc5f7 16 #ifndef MBED_PWMOUT_H
MACRUM 6:40e873bbc5f7 17 #define MBED_PWMOUT_H
MACRUM 6:40e873bbc5f7 18
MACRUM 6:40e873bbc5f7 19 #include "platform/platform.h"
MACRUM 6:40e873bbc5f7 20
MACRUM 6:40e873bbc5f7 21 #if DEVICE_PWMOUT
MACRUM 6:40e873bbc5f7 22 #include "hal/pwmout_api.h"
MACRUM 6:40e873bbc5f7 23 #include "platform/mbed_critical.h"
MACRUM 6:40e873bbc5f7 24
MACRUM 6:40e873bbc5f7 25 namespace mbed {
MACRUM 6:40e873bbc5f7 26 /** \addtogroup drivers */
MACRUM 6:40e873bbc5f7 27 /** @{*/
MACRUM 6:40e873bbc5f7 28
MACRUM 6:40e873bbc5f7 29 /** A pulse-width modulation digital output
MACRUM 6:40e873bbc5f7 30 *
MACRUM 6:40e873bbc5f7 31 * @Note Synchronization level: Interrupt safe
MACRUM 6:40e873bbc5f7 32 *
MACRUM 6:40e873bbc5f7 33 * Example
MACRUM 6:40e873bbc5f7 34 * @code
MACRUM 6:40e873bbc5f7 35 * // Fade a led on.
MACRUM 6:40e873bbc5f7 36 * #include "mbed.h"
MACRUM 6:40e873bbc5f7 37 *
MACRUM 6:40e873bbc5f7 38 * PwmOut led(LED1);
MACRUM 6:40e873bbc5f7 39 *
MACRUM 6:40e873bbc5f7 40 * int main() {
MACRUM 6:40e873bbc5f7 41 * while(1) {
MACRUM 6:40e873bbc5f7 42 * led = led + 0.01;
MACRUM 6:40e873bbc5f7 43 * wait(0.2);
MACRUM 6:40e873bbc5f7 44 * if(led == 1.0) {
MACRUM 6:40e873bbc5f7 45 * led = 0;
MACRUM 6:40e873bbc5f7 46 * }
MACRUM 6:40e873bbc5f7 47 * }
MACRUM 6:40e873bbc5f7 48 * }
MACRUM 6:40e873bbc5f7 49 * @endcode
MACRUM 6:40e873bbc5f7 50 *
MACRUM 6:40e873bbc5f7 51 * @note
MACRUM 6:40e873bbc5f7 52 * On the LPC1768 and LPC2368, the PWMs all share the same
MACRUM 6:40e873bbc5f7 53 * period - if you change the period for one, you change it for all.
MACRUM 6:40e873bbc5f7 54 * Although routines that change the period maintain the duty cycle
MACRUM 6:40e873bbc5f7 55 * for its PWM, all other PWMs will require their duty cycle to be
MACRUM 6:40e873bbc5f7 56 * refreshed.
MACRUM 6:40e873bbc5f7 57 */
MACRUM 6:40e873bbc5f7 58 class PwmOut {
MACRUM 6:40e873bbc5f7 59
MACRUM 6:40e873bbc5f7 60 public:
MACRUM 6:40e873bbc5f7 61
MACRUM 6:40e873bbc5f7 62 /** Create a PwmOut connected to the specified pin
MACRUM 6:40e873bbc5f7 63 *
MACRUM 6:40e873bbc5f7 64 * @param pin PwmOut pin to connect to
MACRUM 6:40e873bbc5f7 65 */
MACRUM 6:40e873bbc5f7 66 PwmOut(PinName pin) {
MACRUM 6:40e873bbc5f7 67 core_util_critical_section_enter();
MACRUM 6:40e873bbc5f7 68 pwmout_init(&_pwm, pin);
MACRUM 6:40e873bbc5f7 69 core_util_critical_section_exit();
MACRUM 6:40e873bbc5f7 70 }
MACRUM 6:40e873bbc5f7 71
MACRUM 6:40e873bbc5f7 72 /** Set the ouput duty-cycle, specified as a percentage (float)
MACRUM 6:40e873bbc5f7 73 *
MACRUM 6:40e873bbc5f7 74 * @param value A floating-point value representing the output duty-cycle,
MACRUM 6:40e873bbc5f7 75 * specified as a percentage. The value should lie between
MACRUM 6:40e873bbc5f7 76 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
MACRUM 6:40e873bbc5f7 77 * Values outside this range will be saturated to 0.0f or 1.0f.
MACRUM 6:40e873bbc5f7 78 */
MACRUM 6:40e873bbc5f7 79 void write(float value) {
MACRUM 6:40e873bbc5f7 80 core_util_critical_section_enter();
MACRUM 6:40e873bbc5f7 81 pwmout_write(&_pwm, value);
MACRUM 6:40e873bbc5f7 82 core_util_critical_section_exit();
MACRUM 6:40e873bbc5f7 83 }
MACRUM 6:40e873bbc5f7 84
MACRUM 6:40e873bbc5f7 85 /** Return the current output duty-cycle setting, measured as a percentage (float)
MACRUM 6:40e873bbc5f7 86 *
MACRUM 6:40e873bbc5f7 87 * @returns
MACRUM 6:40e873bbc5f7 88 * A floating-point value representing the current duty-cycle being output on the pin,
MACRUM 6:40e873bbc5f7 89 * measured as a percentage. The returned value will lie between
MACRUM 6:40e873bbc5f7 90 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
MACRUM 6:40e873bbc5f7 91 *
MACRUM 6:40e873bbc5f7 92 * @note
MACRUM 6:40e873bbc5f7 93 * This value may not match exactly the value set by a previous <write>.
MACRUM 6:40e873bbc5f7 94 */
MACRUM 6:40e873bbc5f7 95 float read() {
MACRUM 6:40e873bbc5f7 96 core_util_critical_section_enter();
MACRUM 6:40e873bbc5f7 97 float val = pwmout_read(&_pwm);
MACRUM 6:40e873bbc5f7 98 core_util_critical_section_exit();
MACRUM 6:40e873bbc5f7 99 return val;
MACRUM 6:40e873bbc5f7 100 }
MACRUM 6:40e873bbc5f7 101
MACRUM 6:40e873bbc5f7 102 /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same.
MACRUM 6:40e873bbc5f7 103 *
MACRUM 6:40e873bbc5f7 104 * @note
MACRUM 6:40e873bbc5f7 105 * The resolution is currently in microseconds; periods smaller than this
MACRUM 6:40e873bbc5f7 106 * will be set to zero.
MACRUM 6:40e873bbc5f7 107 */
MACRUM 6:40e873bbc5f7 108 void period(float seconds) {
MACRUM 6:40e873bbc5f7 109 core_util_critical_section_enter();
MACRUM 6:40e873bbc5f7 110 pwmout_period(&_pwm, seconds);
MACRUM 6:40e873bbc5f7 111 core_util_critical_section_exit();
MACRUM 6:40e873bbc5f7 112 }
MACRUM 6:40e873bbc5f7 113
MACRUM 6:40e873bbc5f7 114 /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.
MACRUM 6:40e873bbc5f7 115 */
MACRUM 6:40e873bbc5f7 116 void period_ms(int ms) {
MACRUM 6:40e873bbc5f7 117 core_util_critical_section_enter();
MACRUM 6:40e873bbc5f7 118 pwmout_period_ms(&_pwm, ms);
MACRUM 6:40e873bbc5f7 119 core_util_critical_section_exit();
MACRUM 6:40e873bbc5f7 120 }
MACRUM 6:40e873bbc5f7 121
MACRUM 6:40e873bbc5f7 122 /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.
MACRUM 6:40e873bbc5f7 123 */
MACRUM 6:40e873bbc5f7 124 void period_us(int us) {
MACRUM 6:40e873bbc5f7 125 core_util_critical_section_enter();
MACRUM 6:40e873bbc5f7 126 pwmout_period_us(&_pwm, us);
MACRUM 6:40e873bbc5f7 127 core_util_critical_section_exit();
MACRUM 6:40e873bbc5f7 128 }
MACRUM 6:40e873bbc5f7 129
MACRUM 6:40e873bbc5f7 130 /** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.
MACRUM 6:40e873bbc5f7 131 */
MACRUM 6:40e873bbc5f7 132 void pulsewidth(float seconds) {
MACRUM 6:40e873bbc5f7 133 core_util_critical_section_enter();
MACRUM 6:40e873bbc5f7 134 pwmout_pulsewidth(&_pwm, seconds);
MACRUM 6:40e873bbc5f7 135 core_util_critical_section_exit();
MACRUM 6:40e873bbc5f7 136 }
MACRUM 6:40e873bbc5f7 137
MACRUM 6:40e873bbc5f7 138 /** Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same.
MACRUM 6:40e873bbc5f7 139 */
MACRUM 6:40e873bbc5f7 140 void pulsewidth_ms(int ms) {
MACRUM 6:40e873bbc5f7 141 core_util_critical_section_enter();
MACRUM 6:40e873bbc5f7 142 pwmout_pulsewidth_ms(&_pwm, ms);
MACRUM 6:40e873bbc5f7 143 core_util_critical_section_exit();
MACRUM 6:40e873bbc5f7 144 }
MACRUM 6:40e873bbc5f7 145
MACRUM 6:40e873bbc5f7 146 /** Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same.
MACRUM 6:40e873bbc5f7 147 */
MACRUM 6:40e873bbc5f7 148 void pulsewidth_us(int us) {
MACRUM 6:40e873bbc5f7 149 core_util_critical_section_enter();
MACRUM 6:40e873bbc5f7 150 pwmout_pulsewidth_us(&_pwm, us);
MACRUM 6:40e873bbc5f7 151 core_util_critical_section_exit();
MACRUM 6:40e873bbc5f7 152 }
MACRUM 6:40e873bbc5f7 153
MACRUM 6:40e873bbc5f7 154 /** A operator shorthand for write()
MACRUM 6:40e873bbc5f7 155 */
MACRUM 6:40e873bbc5f7 156 PwmOut& operator= (float value) {
MACRUM 6:40e873bbc5f7 157 // Underlying call is thread safe
MACRUM 6:40e873bbc5f7 158 write(value);
MACRUM 6:40e873bbc5f7 159 return *this;
MACRUM 6:40e873bbc5f7 160 }
MACRUM 6:40e873bbc5f7 161
MACRUM 6:40e873bbc5f7 162 PwmOut& operator= (PwmOut& rhs) {
MACRUM 6:40e873bbc5f7 163 // Underlying call is thread safe
MACRUM 6:40e873bbc5f7 164 write(rhs.read());
MACRUM 6:40e873bbc5f7 165 return *this;
MACRUM 6:40e873bbc5f7 166 }
MACRUM 6:40e873bbc5f7 167
MACRUM 6:40e873bbc5f7 168 /** An operator shorthand for read()
MACRUM 6:40e873bbc5f7 169 */
MACRUM 6:40e873bbc5f7 170 operator float() {
MACRUM 6:40e873bbc5f7 171 // Underlying call is thread safe
MACRUM 6:40e873bbc5f7 172 return read();
MACRUM 6:40e873bbc5f7 173 }
MACRUM 6:40e873bbc5f7 174
MACRUM 6:40e873bbc5f7 175 protected:
MACRUM 6:40e873bbc5f7 176 pwmout_t _pwm;
MACRUM 6:40e873bbc5f7 177 };
MACRUM 6:40e873bbc5f7 178
MACRUM 6:40e873bbc5f7 179 } // namespace mbed
MACRUM 6:40e873bbc5f7 180
MACRUM 6:40e873bbc5f7 181 #endif
MACRUM 6:40e873bbc5f7 182
MACRUM 6:40e873bbc5f7 183 #endif
MACRUM 6:40e873bbc5f7 184
MACRUM 6:40e873bbc5f7 185 /** @}*/