mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

Committer:
emilmont
Date:
Wed Oct 10 14:14:12 2012 +0000
Revision:
2:e9a661555b58
Parent:
0:8024c367e29f
Child:
8:c14af7958ef5
Add PWM and I2C implementation;

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