re-enabling serial
[clinton/Smoothieware.git] / gcc4mbed / external / mbed / .svn / text-base / AnalogOut.h.svn-base
1 /* mbed Microcontroller Library - AnalogOut
2 * Copyright (c) 2006-2009 ARM Limited. All rights reserved.
3 * sford
4 */
5
6 #ifndef MBED_ANALOGOUT_H
7 #define MBED_ANALOGOUT_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: AnalogOut
17 * An analog output, used for setting the voltage on a pin
18 *
19 * Example:
20 * > // Make a sawtooth output
21 * >
22 * > #include "mbed.h"
23 * >
24 * > AnalogOut tri(p18);
25 * > int main() {
26 * > while(1) {
27 * > tri = tri + 0.01;
28 * > wait_us(1);
29 * > if(tri == 1) {
30 * > tri = 0;
31 * > }
32 * > }
33 * > }
34 */
35 class AnalogOut : public Base {
36
37 public:
38
39 /* Constructor: AnalogOut
40 * Create an AnalogOut connected to the specified pin
41 *
42 * Variables:
43 * pin - AnalogOut pin to connect to (18)
44 */
45 AnalogOut(PinName pin, const char *name = NULL);
46
47 /* Function: write
48 * Set the output voltage, specified as a percentage (float)
49 *
50 * Variables:
51 * percent - A floating-point value representing the output voltage,
52 * specified as a percentage. The value should lie between
53 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
54 * Values outside this range will be saturated to 0.0f or 1.0f.
55 */
56 void write(float value);
57
58 /* Function: write_u16
59 * Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
60 *
61 * Variables:
62 * value - 16-bit unsigned short representing the output voltage,
63 * normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v)
64 */
65 void write_u16(unsigned short value);
66
67 /* Function: read
68 * Return the current output voltage setting, measured as a percentage (float)
69 *
70 * Variables:
71 * returns - A floating-point value representing the current voltage being output on the pin,
72 * measured as a percentage. The returned value will lie between
73 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
74 *
75 * Note:
76 * This value may not match exactly the value set by a previous <write>.
77 */
78 float read();
79
80
81 #ifdef MBED_OPERATORS
82 /* Function: operator=
83 * An operator shorthand for <write()>
84 */
85 AnalogOut& operator= (float percent);
86 AnalogOut& operator= (AnalogOut& rhs);
87
88 /* Function: operator float()
89 * An operator shorthand for <read()>
90 */
91 operator float();
92 #endif
93
94 #ifdef MBED_RPC
95 virtual const struct rpc_method *get_rpc_methods();
96 static struct rpc_class *get_rpc_class();
97 #endif
98
99 protected:
100
101 DACName _dac;
102
103 };
104
105 } // namespace mbed
106
107 #endif
108