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