mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

Committer:
emilmont
Date:
Fri Nov 09 11:33:53 2012 +0000
Revision:
8:c14af7958ef5
Parent:
0:8024c367e29f
Child:
9:663789d7729f
SPI driver; ADC driver; DAC driver; microlib support; general bugfixing

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 8:c14af7958ef5 3 */
emilmont 0:8024c367e29f 4 #ifndef MBED_ANALOGOUT_H
emilmont 0:8024c367e29f 5 #define MBED_ANALOGOUT_H
emilmont 0:8024c367e29f 6
emilmont 8:c14af7958ef5 7 #include "platform.h"
emilmont 0:8024c367e29f 8
emilmont 0:8024c367e29f 9 #if DEVICE_ANALOGOUT
emilmont 0:8024c367e29f 10
emilmont 0:8024c367e29f 11 namespace mbed {
emilmont 0:8024c367e29f 12
emilmont 8:c14af7958ef5 13 /** An analog output, used for setting the voltage on a pin
emilmont 0:8024c367e29f 14 *
emilmont 0:8024c367e29f 15 * Example:
emilmont 8:c14af7958ef5 16 * @code
emilmont 8:c14af7958ef5 17 * // Make a sawtooth output
emilmont 8:c14af7958ef5 18 *
emilmont 8:c14af7958ef5 19 * #include "mbed.h"
emilmont 8:c14af7958ef5 20 *
emilmont 8:c14af7958ef5 21 * AnalogOut tri(p18);
emilmont 8:c14af7958ef5 22 * int main() {
emilmont 8:c14af7958ef5 23 * while(1) {
emilmont 8:c14af7958ef5 24 * tri = tri + 0.01;
emilmont 8:c14af7958ef5 25 * wait_us(1);
emilmont 8:c14af7958ef5 26 * if(tri == 1) {
emilmont 8:c14af7958ef5 27 * tri = 0;
emilmont 8:c14af7958ef5 28 * }
emilmont 8:c14af7958ef5 29 * }
emilmont 8:c14af7958ef5 30 * }
emilmont 8:c14af7958ef5 31 * @endcode
emilmont 0:8024c367e29f 32 */
emilmont 8:c14af7958ef5 33 class AnalogOut {
emilmont 0:8024c367e29f 34
emilmont 0:8024c367e29f 35 public:
emilmont 0:8024c367e29f 36
emilmont 8:c14af7958ef5 37 /** Create an AnalogOut connected to the specified pin
emilmont 0:8024c367e29f 38 *
emilmont 8:c14af7958ef5 39 * @param AnalogOut pin to connect to (18)
emilmont 0:8024c367e29f 40 */
emilmont 8:c14af7958ef5 41 AnalogOut(PinName pin);
emilmont 0:8024c367e29f 42
emilmont 8:c14af7958ef5 43 /** Set the output voltage, specified as a percentage (float)
emilmont 0:8024c367e29f 44 *
emilmont 8:c14af7958ef5 45 * @param value A floating-point value representing the output voltage,
emilmont 0:8024c367e29f 46 * specified as a percentage. The value should lie between
emilmont 0:8024c367e29f 47 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
emilmont 8:c14af7958ef5 48 * Values outside this range will be saturated to 0.0f or 1.0f.
emilmont 0:8024c367e29f 49 */
emilmont 0:8024c367e29f 50 void write(float value);
emilmont 0:8024c367e29f 51
emilmont 8:c14af7958ef5 52 /** Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
emilmont 0:8024c367e29f 53 *
emilmont 8:c14af7958ef5 54 * @param value 16-bit unsigned short representing the output voltage,
emilmont 0:8024c367e29f 55 * normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v)
emilmont 0:8024c367e29f 56 */
emilmont 0:8024c367e29f 57 void write_u16(unsigned short value);
emilmont 0:8024c367e29f 58
emilmont 8:c14af7958ef5 59 /** Return the current output voltage setting, measured as a percentage (float)
emilmont 0:8024c367e29f 60 *
emilmont 8:c14af7958ef5 61 * @returns
emilmont 8:c14af7958ef5 62 * A floating-point value representing the current voltage being output on the pin,
emilmont 0:8024c367e29f 63 * measured as a percentage. The returned value will lie between
emilmont 0:8024c367e29f 64 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
emilmont 0:8024c367e29f 65 *
emilmont 8:c14af7958ef5 66 * @note
emilmont 8:c14af7958ef5 67 * This value may not match exactly the value set by a previous write().
emilmont 8:c14af7958ef5 68 */
emilmont 0:8024c367e29f 69 float read();
emilmont 0:8024c367e29f 70
emilmont 0:8024c367e29f 71 #ifdef MBED_OPERATORS
emilmont 8:c14af7958ef5 72 /** An operator shorthand for write()
emilmont 0:8024c367e29f 73 */
emilmont 0:8024c367e29f 74 AnalogOut& operator= (float percent);
emilmont 0:8024c367e29f 75 AnalogOut& operator= (AnalogOut& rhs);
emilmont 0:8024c367e29f 76
emilmont 8:c14af7958ef5 77 /** An operator shorthand for read()
emilmont 8:c14af7958ef5 78 */
emilmont 0:8024c367e29f 79 operator float();
emilmont 0:8024c367e29f 80 #endif
emilmont 0:8024c367e29f 81
emilmont 0:8024c367e29f 82 protected:
emilmont 0:8024c367e29f 83 DACName _dac;
emilmont 0:8024c367e29f 84 };
emilmont 0:8024c367e29f 85
emilmont 0:8024c367e29f 86 } // namespace mbed
emilmont 0:8024c367e29f 87
emilmont 0:8024c367e29f 88 #endif
emilmont 0:8024c367e29f 89
emilmont 0:8024c367e29f 90 #endif