added missing files, working on extruder module ( not finished, removing
[clinton/Smoothieware.git] / gcc4mbed / external / mbed / .svn / text-base / PortOut.h.svn-base
1 /* mbed Microcontroller Library - PortOut
2 * Copyright (c) 2006-2009 ARM Limited. All rights reserved.
3 */
4
5 #ifndef MBED_PORTOUT_H
6 #define MBED_PORTOUT_H
7
8 #include "platform.h"
9 #include "PinNames.h"
10 #include "Base.h"
11
12 #include "PortNames.h"
13
14 namespace mbed {
15 /* Class: PortOut
16 * A multiple pin digital out
17 *
18 * Example:
19 * > // Toggle all four LEDs
20 * >
21 * > #include "mbed.h"
22 * >
23 * > // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23
24 * > #define LED_MASK 0x00B40000
25 * >
26 * > PortOut ledport(Port1, LED_MASK);
27 * >
28 * > int main() {
29 * > while(1) {
30 * > ledport = LED_MASK;
31 * > wait(1);
32 * > ledport = 0;
33 * > wait(1);
34 * > }
35 * > }
36 */
37 class PortOut {
38 public:
39
40 /* Constructor: PortOut
41 * Create an PortOut, connected to the specified port
42 *
43 * Variables:
44 * port - Port to connect to (Port0-Port5)
45 * mask - A bitmask to identify which bits in the port should be included (0 - ignore)
46 */
47 PortOut(PortName port, int mask = 0xFFFFFFFF);
48
49 /* Function: write
50 * Write the value to the output port
51 *
52 * Variables:
53 * value - An integer specifying a bit to write for every corresponding PortOut pin
54 */
55 void write(int value) {
56 _gpio->FIOPIN = (_gpio->FIOPIN & ~_mask) | (value & _mask);
57 }
58
59 /* Function: read
60 * Read the value currently output on the port
61 *
62 * Variables:
63 * returns - An integer with each bit corresponding to associated PortOut pin setting
64 */
65 int read() {
66 return _gpio->FIOPIN & _mask;
67 }
68
69 /* Function: operator=
70 * A shorthand for <write>
71 */
72 PortOut& operator= (int value) {
73 write(value);
74 return *this;
75 }
76
77 PortOut& operator= (PortOut& rhs) {
78 write(rhs.read());
79 return *this;
80 }
81
82 /* Function: operator int()
83 * A shorthand for <read>
84 */
85 operator int() {
86 return read();
87 }
88
89 private:
90 LPC_GPIO_TypeDef *_gpio;
91 PortName _port;
92 uint32_t _mask;
93 };
94
95 } // namespace mbed
96
97 #endif