mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

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