mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

Committer:
emilmont
Date:
Fri Oct 05 09:16:41 2012 +0000
Revision:
0:8024c367e29f
Child:
2:e9a661555b58
First release of the mbed libraries for KL25Z

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 0:8024c367e29f 1 /* mbed Microcontroller Library - PwmOut
emilmont 0:8024c367e29f 2 * Copyright (c) 2007-2011 ARM Limited. All rights reserved.
emilmont 0:8024c367e29f 3 */
emilmont 0:8024c367e29f 4
emilmont 0:8024c367e29f 5 #ifndef MBED_PWMOUT_H
emilmont 0:8024c367e29f 6 #define MBED_PWMOUT_H
emilmont 0:8024c367e29f 7
emilmont 0:8024c367e29f 8 #include "device.h"
emilmont 0:8024c367e29f 9
emilmont 0:8024c367e29f 10 #if DEVICE_PWMOUT
emilmont 0:8024c367e29f 11
emilmont 0:8024c367e29f 12 #include "platform.h"
emilmont 0:8024c367e29f 13 #include "PinNames.h"
emilmont 0:8024c367e29f 14 #include "PeripheralNames.h"
emilmont 0:8024c367e29f 15 #include "Base.h"
emilmont 0:8024c367e29f 16
emilmont 0:8024c367e29f 17 namespace mbed {
emilmont 0:8024c367e29f 18
emilmont 0:8024c367e29f 19 /* Class: PwmOut
emilmont 0:8024c367e29f 20 * A pulse-width modulation digital output
emilmont 0:8024c367e29f 21 *
emilmont 0:8024c367e29f 22 * Example
emilmont 0:8024c367e29f 23 * > // Fade a led on.
emilmont 0:8024c367e29f 24 * > #include "mbed.h"
emilmont 0:8024c367e29f 25 * >
emilmont 0:8024c367e29f 26 * > PwmOut led(LED1);
emilmont 0:8024c367e29f 27 * >
emilmont 0:8024c367e29f 28 * > int main() {
emilmont 0:8024c367e29f 29 * > while(1) {
emilmont 0:8024c367e29f 30 * > led = led + 0.01;
emilmont 0:8024c367e29f 31 * > wait(0.2);
emilmont 0:8024c367e29f 32 * > if(led == 1.0) {
emilmont 0:8024c367e29f 33 * > led = 0;
emilmont 0:8024c367e29f 34 * > }
emilmont 0:8024c367e29f 35 * > }
emilmont 0:8024c367e29f 36 * > }
emilmont 0:8024c367e29f 37 *
emilmont 0:8024c367e29f 38 * Note that on the LPC1768 and LPC2368, the PWMs all share the same
emilmont 0:8024c367e29f 39 * period - if you change the period for one, you change it for all.
emilmont 0:8024c367e29f 40 * Although routines that change the period maintain the duty cycle
emilmont 0:8024c367e29f 41 * for its PWM, all other PWMs will require their duty cycle to be
emilmont 0:8024c367e29f 42 * refreshed.
emilmont 0:8024c367e29f 43 */
emilmont 0:8024c367e29f 44 class PwmOut : public Base {
emilmont 0:8024c367e29f 45
emilmont 0:8024c367e29f 46 public:
emilmont 0:8024c367e29f 47
emilmont 0:8024c367e29f 48 /* Constructor: PwmOut
emilmont 0:8024c367e29f 49 * Create a PwmOut connected to the specified pin
emilmont 0:8024c367e29f 50 *
emilmont 0:8024c367e29f 51 * Variables:
emilmont 0:8024c367e29f 52 * pin - PwmOut pin to connect to
emilmont 0:8024c367e29f 53 */
emilmont 0:8024c367e29f 54 PwmOut(PinName pin, const char *name = NULL);
emilmont 0:8024c367e29f 55
emilmont 0:8024c367e29f 56 /* Function: write
emilmont 0:8024c367e29f 57 * Set the ouput duty-cycle, specified as a percentage (float)
emilmont 0:8024c367e29f 58 *
emilmont 0:8024c367e29f 59 * Variables:
emilmont 0:8024c367e29f 60 * value - A floating-point value representing the output duty-cycle,
emilmont 0:8024c367e29f 61 * specified as a percentage. The value should lie between
emilmont 0:8024c367e29f 62 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
emilmont 0:8024c367e29f 63 * Values outside this range will be saturated to 0.0f or 1.0f.
emilmont 0:8024c367e29f 64 */
emilmont 0:8024c367e29f 65 void write(float value);
emilmont 0:8024c367e29f 66
emilmont 0:8024c367e29f 67 /* Function: read
emilmont 0:8024c367e29f 68 * Return the current output duty-cycle setting, measured as a percentage (float)
emilmont 0:8024c367e29f 69 *
emilmont 0:8024c367e29f 70 * Variables:
emilmont 0:8024c367e29f 71 * returns - A floating-point value representing the current duty-cycle being output on the pin,
emilmont 0:8024c367e29f 72 * measured as a percentage. The returned value will lie between
emilmont 0:8024c367e29f 73 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
emilmont 0:8024c367e29f 74 *
emilmont 0:8024c367e29f 75 * Note:
emilmont 0:8024c367e29f 76 * This value may not match exactly the value set by a previous <write>.
emilmont 0:8024c367e29f 77 */
emilmont 0:8024c367e29f 78 float read();
emilmont 0:8024c367e29f 79
emilmont 0:8024c367e29f 80 /* Function: period
emilmont 0:8024c367e29f 81 * Set the PWM period, specified in seconds (float), keeping the
emilmont 0:8024c367e29f 82 * duty cycle the same.
emilmont 0:8024c367e29f 83 *
emilmont 0:8024c367e29f 84 * Note:
emilmont 0:8024c367e29f 85 * The resolution is currently in microseconds; periods smaller than this
emilmont 0:8024c367e29f 86 * will be set to zero.
emilmont 0:8024c367e29f 87 */
emilmont 0:8024c367e29f 88 void period(float seconds);
emilmont 0:8024c367e29f 89
emilmont 0:8024c367e29f 90 /* Function: period_ms
emilmont 0:8024c367e29f 91 * Set the PWM period, specified in milli-seconds (int), keeping the
emilmont 0:8024c367e29f 92 * duty cycle the same.
emilmont 0:8024c367e29f 93 */
emilmont 0:8024c367e29f 94 void period_ms(int ms);
emilmont 0:8024c367e29f 95
emilmont 0:8024c367e29f 96 /* Function: period_us
emilmont 0:8024c367e29f 97 * Set the PWM period, specified in micro-seconds (int), keeping the
emilmont 0:8024c367e29f 98 * duty cycle the same.
emilmont 0:8024c367e29f 99 */
emilmont 0:8024c367e29f 100 void period_us(int us);
emilmont 0:8024c367e29f 101
emilmont 0:8024c367e29f 102 /* Function: pulsewidth
emilmont 0:8024c367e29f 103 * Set the PWM pulsewidth, specified in seconds (float), keeping the
emilmont 0:8024c367e29f 104 * period the same.
emilmont 0:8024c367e29f 105 */
emilmont 0:8024c367e29f 106 void pulsewidth(float seconds);
emilmont 0:8024c367e29f 107
emilmont 0:8024c367e29f 108 /* Function: pulsewidth_ms
emilmont 0:8024c367e29f 109 * Set the PWM pulsewidth, specified in milli-seconds (int), keeping
emilmont 0:8024c367e29f 110 * the period the same.
emilmont 0:8024c367e29f 111 */
emilmont 0:8024c367e29f 112 void pulsewidth_ms(int ms);
emilmont 0:8024c367e29f 113
emilmont 0:8024c367e29f 114 /* Function: pulsewidth_us
emilmont 0:8024c367e29f 115 * Set the PWM pulsewidth, specified in micro-seconds (int), keeping
emilmont 0:8024c367e29f 116 * the period the same.
emilmont 0:8024c367e29f 117 */
emilmont 0:8024c367e29f 118 void pulsewidth_us(int us);
emilmont 0:8024c367e29f 119
emilmont 0:8024c367e29f 120 #ifdef MBED_OPERATORS
emilmont 0:8024c367e29f 121 /* Function: operator=
emilmont 0:8024c367e29f 122 * A operator shorthand for <write()>
emilmont 0:8024c367e29f 123 */
emilmont 0:8024c367e29f 124 PwmOut& operator= (float value);
emilmont 0:8024c367e29f 125 PwmOut& operator= (PwmOut& rhs);
emilmont 0:8024c367e29f 126
emilmont 0:8024c367e29f 127 /* Function: operator float()
emilmont 0:8024c367e29f 128 * An operator shorthand for <read()>
emilmont 0:8024c367e29f 129 */
emilmont 0:8024c367e29f 130 operator float();
emilmont 0:8024c367e29f 131 #endif
emilmont 0:8024c367e29f 132
emilmont 0:8024c367e29f 133 #ifdef MBED_RPC
emilmont 0:8024c367e29f 134 virtual const struct rpc_method *get_rpc_methods();
emilmont 0:8024c367e29f 135 static struct rpc_class *get_rpc_class();
emilmont 0:8024c367e29f 136 #endif
emilmont 0:8024c367e29f 137
emilmont 0:8024c367e29f 138 protected:
emilmont 0:8024c367e29f 139
emilmont 0:8024c367e29f 140 PWMName _pwm;
emilmont 0:8024c367e29f 141
emilmont 0:8024c367e29f 142 };
emilmont 0:8024c367e29f 143
emilmont 0:8024c367e29f 144 } // namespace mbed
emilmont 0:8024c367e29f 145
emilmont 0:8024c367e29f 146 #endif
emilmont 0:8024c367e29f 147
emilmont 0:8024c367e29f 148 #endif