first commit
[clinton/Smoothieware.git] / gcc4mbed / external / mbed / DigitalOut.h
CommitLineData
4cff3ded
AW
1/* mbed Microcontroller Library - DigitalOut
2 * Copyright (c) 2006-2009 ARM Limited. All rights reserved.
3 * sford
4 */
5
6#ifndef MBED_DIGITALOUT_H
7#define MBED_DIGITALOUT_H
8
9#include "platform.h"
10#include "PinNames.h"
11#include "PeripheralNames.h"
12#include "Base.h"
13
14namespace mbed {
15
16/* Class: DigitalOut
17 * A digital output, used for setting the state of a pin
18 *
19 * Example:
20 * > // Toggle a LED
21 * > #include "mbed.h"
22 * >
23 * > DigitalOut led(LED1);
24 * >
25 * > int main() {
26 * > while(1) {
27 * > led = !led;
28 * > wait(0.2);
29 * > }
30 * > }
31 */
32class DigitalOut : public Base {
33
34public:
35
36 /* Constructor: DigitalOut
37 * Create a DigitalOut connected to the specified pin
38 *
39 * Variables:
40 * pin - DigitalOut pin to connect to
41 */
42 DigitalOut(PinName pin, const char* name = NULL);
43
44 /* Function: write
45 * Set the output, specified as 0 or 1 (int)
46 *
47 * Variables:
48 * value - An integer specifying the pin output value,
49 * 0 for logical 0 and 1 (or any other non-zero value) for logical 1
50 */
51 void write(int value) {
52 if(value) {
53 _gpio->FIOSET = _mask;
54 } else {
55 _gpio->FIOCLR = _mask;
56 }
57 }
58
59 /* Function: read
60 * Return the output setting, represented as 0 or 1 (int)
61 *
62 * Variables:
63 * returns - An integer representing the output setting of the pin,
64 * 0 for logical 0 and 1 for logical 1
65 */
66 int read() {
67 return ((_gpio->FIOPIN & _mask) ? 1 : 0);
68 }
69
70
71#ifdef MBED_OPERATORS
72 /* Function: operator=
73 * A shorthand for <write>
74 */
75 DigitalOut& operator= (int value) {
76 write(value);
77 return *this;
78 }
79
80 DigitalOut& operator= (DigitalOut& rhs) {
81 write(rhs.read());
82 return *this;
83 }
84
85
86 /* Function: operator int()
87 * A shorthand for <read>
88 */
89 operator int() {
90 return read();
91 }
92
93#endif
94
95#ifdef MBED_RPC
96 virtual const struct rpc_method *get_rpc_methods();
97 static struct rpc_class *get_rpc_class();
98#endif
99
100protected:
101
102 PinName _pin;
103 LPC_GPIO_TypeDef *_gpio;
104 uint32_t _mask;
105
106
107};
108
109} // namespace mbed
110
111#endif