mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

Committer:
emilmont
Date:
Fri Nov 09 11:33:53 2012 +0000
Revision:
8:c14af7958ef5
Parent:
2:e9a661555b58
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 2:e9a661555b58 1 /* mbed Microcontroller Library - DigitalInOut
emilmont 2:e9a661555b58 2 * Copyright (c) 2006-2011 ARM Limited. All rights reserved.
emilmont 2:e9a661555b58 3 */
emilmont 2:e9a661555b58 4 #ifndef MBED_DIGITALINOUT_H
emilmont 2:e9a661555b58 5 #define MBED_DIGITALINOUT_H
emilmont 2:e9a661555b58 6
emilmont 2:e9a661555b58 7 #include "platform.h"
emilmont 2:e9a661555b58 8
emilmont 2:e9a661555b58 9 #include "gpio_api.h"
emilmont 2:e9a661555b58 10
emilmont 2:e9a661555b58 11 namespace mbed {
emilmont 2:e9a661555b58 12
emilmont 8:c14af7958ef5 13 /** A digital input/output, used for setting or reading a bi-directional pin
emilmont 2:e9a661555b58 14 */
emilmont 8:c14af7958ef5 15 class DigitalInOut {
emilmont 2:e9a661555b58 16
emilmont 2:e9a661555b58 17 public:
emilmont 8:c14af7958ef5 18 /** Create a DigitalInOut connected to the specified pin
emilmont 2:e9a661555b58 19 *
emilmont 8:c14af7958ef5 20 * @param pin DigitalInOut pin to connect to
emilmont 2:e9a661555b58 21 */
emilmont 8:c14af7958ef5 22 DigitalInOut(PinName pin);
emilmont 2:e9a661555b58 23
emilmont 8:c14af7958ef5 24 /** Set the output, specified as 0 or 1 (int)
emilmont 2:e9a661555b58 25 *
emilmont 8:c14af7958ef5 26 * @param value An integer specifying the pin output value,
emilmont 8:c14af7958ef5 27 * 0 for logical 0, 1 (or any other non-zero value) for logical 1
emilmont 2:e9a661555b58 28 */
emilmont 2:e9a661555b58 29 void write(int value);
emilmont 2:e9a661555b58 30
emilmont 8:c14af7958ef5 31 /** Return the output setting, represented as 0 or 1 (int)
emilmont 2:e9a661555b58 32 *
emilmont 8:c14af7958ef5 33 * @returns
emilmont 8:c14af7958ef5 34 * an integer representing the output setting of the pin if it is an output,
emilmont 8:c14af7958ef5 35 * or read the input if set as an input
emilmont 2:e9a661555b58 36 */
emilmont 2:e9a661555b58 37 int read();
emilmont 2:e9a661555b58 38
emilmont 8:c14af7958ef5 39 /** Set as an output
emilmont 2:e9a661555b58 40 */
emilmont 2:e9a661555b58 41 void output();
emilmont 2:e9a661555b58 42
emilmont 8:c14af7958ef5 43 /** Set as an input
emilmont 2:e9a661555b58 44 */
emilmont 2:e9a661555b58 45 void input();
emilmont 2:e9a661555b58 46
emilmont 8:c14af7958ef5 47 /** Set the input pin mode
emilmont 2:e9a661555b58 48 *
emilmont 8:c14af7958ef5 49 * @param mode PullUp, PullDown, PullNone, OpenDrain
emilmont 2:e9a661555b58 50 */
emilmont 2:e9a661555b58 51 void mode(PinMode pull);
emilmont 2:e9a661555b58 52
emilmont 2:e9a661555b58 53 #ifdef MBED_OPERATORS
emilmont 8:c14af7958ef5 54 /** A shorthand for write()
emilmont 2:e9a661555b58 55 */
emilmont 2:e9a661555b58 56 DigitalInOut& operator= (int value) {
emilmont 2:e9a661555b58 57 write(value);
emilmont 2:e9a661555b58 58 return *this;
emilmont 2:e9a661555b58 59 }
emilmont 2:e9a661555b58 60
emilmont 2:e9a661555b58 61 DigitalInOut& operator= (DigitalInOut& rhs) {
emilmont 2:e9a661555b58 62 write(rhs.read());
emilmont 2:e9a661555b58 63 return *this;
emilmont 2:e9a661555b58 64 }
emilmont 2:e9a661555b58 65
emilmont 8:c14af7958ef5 66 /** A shorthand for read()
emilmont 2:e9a661555b58 67 */
emilmont 2:e9a661555b58 68 operator int() {
emilmont 2:e9a661555b58 69 return read();
emilmont 2:e9a661555b58 70 }
emilmont 2:e9a661555b58 71 #endif
emilmont 2:e9a661555b58 72
emilmont 2:e9a661555b58 73 protected:
emilmont 2:e9a661555b58 74 gpio_object gpio;
emilmont 2:e9a661555b58 75 };
emilmont 2:e9a661555b58 76
emilmont 8:c14af7958ef5 77 } // namespace mbed
emilmont 2:e9a661555b58 78
emilmont 8:c14af7958ef5 79 #endif