mbed library sources with internal temperature sensor for nucleo f401

Committer:
elessair
Date:
Sat Jan 17 18:03:58 2015 +0000
Revision:
0:7e2bd16f80af
nucleo f401re internal temperature added

Who changed what in which revision?

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