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