Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Dec 16 16:27:57 2016 +0000
Revision:
3:1198227e6421
Parent:
0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms

Who changed what in which revision?

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