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