first commit
[clinton/Smoothieware.git] / gcc4mbed / external / mbed / PortIn.h
CommitLineData
4cff3ded
AW
1/* mbed Microcontroller Library - PortInOut\r
2 * Copyright (c) 2006-2009 ARM Limited. All rights reserved.\r
3 */ \r
4 \r
5#ifndef MBED_PORTIN_H\r
6#define MBED_PORTIN_H\r
7\r
8#include "PortNames.h"\r
9#include "PinNames.h"\r
10\r
11namespace mbed {\r
12\r
13/* Class: PortIn\r
14 * A multiple pin digital input\r
15 *\r
16 * Example:\r
17 * > // Switch on an LED if any of mbed pins 21-26 is high\r
18 * >\r
19 * > #include "mbed.h"\r
20 * >\r
21 * > PortIn p(Port2, 0x0000003F); // p21-p26\r
22 * > DigitalOut ind(LED4);\r
23 * >\r
24 * > int main() {\r
25 * > while(1) {\r
26 * > int pins = p.read();\r
27 * > if(pins) {\r
28 * > ind = 1;\r
29 * > } else {\r
30 * > ind = 0;\r
31 * > }\r
32 * > }\r
33 * > }\r
34 */\r
35class PortIn {\r
36public:\r
37\r
38 /* Constructor: PortIn\r
39 * Create an PortIn, connected to the specified port\r
40 *\r
41 * Variables:\r
42 * port - Port to connect to (Port0-Port5)\r
43 * mask - A bitmask to identify which bits in the port should be included (0 - ignore)\r
44 */ \r
45 PortIn(PortName port, int mask = 0xFFFFFFFF);\r
46\r
47 /* Function: read\r
48 * Read the value currently output on the port\r
49 *\r
50 * Variables:\r
51 * returns - An integer with each bit corresponding to associated port pin setting\r
52 */\r
53 int read() {\r
54 return _gpio->FIOPIN & _mask;\r
55 }\r
56\r
57 /* Function: mode\r
58 * Set the input pin mode\r
59 *\r
60 * Variables:\r
61 * mode - PullUp, PullDown, PullNone, OpenDrain\r
62 */\r
63 void mode(PinMode mode);\r
64 \r
65 /* Function: operator int()\r
66 * A shorthand for <read>\r
67 */\r
68 operator int() { \r
69 return read();\r
70 }\r
71\r
72private:\r
73 LPC_GPIO_TypeDef *_gpio;\r
74 PortName _port;\r
75 uint32_t _mask; \r
76};\r
77\r
78} // namespace mbed\r
79\r
80#endif\r