Upgrade gcc4mbed project used by Smoothie.
[clinton/Smoothieware.git] / gcc4mbed / external / mbed / PortOut.h
CommitLineData
4cff3ded 1/* mbed Microcontroller Library - PortOut\r
8fcce42e 2 * Copyright (c) 2006-2011 ARM Limited. All rights reserved.\r
4cff3ded
AW
3 */ \r
4 \r
5#ifndef MBED_PORTOUT_H\r
6#define MBED_PORTOUT_H\r
7\r
8fcce42e
AG
8#include "device.h"\r
9\r
10#if DEVICE_PORTOUT\r
11\r
4cff3ded
AW
12#include "platform.h"\r
13#include "PinNames.h"\r
14#include "Base.h"\r
15\r
16#include "PortNames.h"\r
17\r
18namespace mbed {\r
19/* Class: PortOut\r
20 * A multiple pin digital out\r
21 *\r
22 * Example:\r
23 * > // Toggle all four LEDs\r
24 * >\r
25 * > #include "mbed.h"\r
26 * >\r
27 * > // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23\r
28 * > #define LED_MASK 0x00B40000\r
29 * >\r
30 * > PortOut ledport(Port1, LED_MASK);\r
31 * >\r
32 * > int main() {\r
33 * > while(1) {\r
34 * > ledport = LED_MASK;\r
35 * > wait(1);\r
36 * > ledport = 0;\r
37 * > wait(1);\r
38 * > }\r
39 * > }\r
40 */ \r
41class PortOut {\r
42public:\r
43\r
44 /* Constructor: PortOut\r
45 * Create an PortOut, connected to the specified port\r
46 *\r
47 * Variables:\r
48 * port - Port to connect to (Port0-Port5)\r
49 * mask - A bitmask to identify which bits in the port should be included (0 - ignore)\r
50 */ \r
51 PortOut(PortName port, int mask = 0xFFFFFFFF);\r
52\r
53 /* Function: write\r
54 * Write the value to the output port\r
55 *\r
56 * Variables:\r
57 * value - An integer specifying a bit to write for every corresponding PortOut pin\r
58 */ \r
8fcce42e 59 void write(int value);\r
4cff3ded
AW
60\r
61 /* Function: read\r
62 * Read the value currently output on the port\r
63 *\r
64 * Variables:\r
65 * returns - An integer with each bit corresponding to associated PortOut pin setting\r
66 */\r
8fcce42e 67 int read();\r
4cff3ded
AW
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
8fcce42e 90#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)\r
4cff3ded 91 LPC_GPIO_TypeDef *_gpio;\r
8fcce42e
AG
92#endif\r
93 PortName _port;\r
94 uint32_t _mask;\r
4cff3ded
AW
95};\r
96\r
97} // namespace mbed\r
98\r
99#endif\r
8fcce42e
AG
100\r
101#endif\r