Mistake on this page?
Report an issue in GitHub or email us
PortIn.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2019 ARM Limited
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef MBED_PORTIN_H
18 #define MBED_PORTIN_H
19 
20 #include "platform/platform.h"
21 
22 #if DEVICE_PORTIN || defined(DOXYGEN_ONLY)
23 
24 #include "hal/port_api.h"
25 
26 namespace mbed {
27 /**
28  * \defgroup drivers_PortIn PortIn class
29  * \ingroup drivers-public-api-gpio
30  * @{
31  */
32 
33 /** A multiple pin digital input
34  *
35  * @note Synchronization level: Interrupt safe
36  *
37  * Example:
38  * @code
39  * // Turn on an LED if any pins of Port2[0:5] are high
40  *
41  * #include "mbed.h"
42  *
43  * PortIn p(Port2, 0x0000003F); // Port2 pins [0:5] only
44  * DigitalOut led(LED4);
45  *
46  * int main() {
47  * while(1) {
48  * int pins = p.read();
49  * if(pins) {
50  * led = 1;
51  * } else {
52  * led = 0;
53  * }
54  * }
55  * }
56  * @endcode
57  */
58 class PortIn {
59 public:
60 
61  /** Create a PortIn, connected to the specified port
62  *
63  * @param port Port to connect to (as defined in target's PortNames.h)
64  * @param mask Bitmask defines which port pins should be an input (0 - ignore, 1 - include)
65  */
66  PortIn(PortName port, int mask = 0xFFFFFFFF);
67 
68  /** Read the value input to the port
69  *
70  * @returns
71  * An integer with each bit corresponding to the associated pin value
72  */
73  int read()
74  {
75  return port_read(&_port);
76  }
77 
78  /** Set the input pin mode
79  *
80  * @param mode PullUp, PullDown, PullNone, OpenDrain
81  */
82  void mode(PinMode mode);
83 
84  /** A shorthand for read()
85  */
86  operator int()
87  {
88  return read();
89  }
90 
91 private:
92  port_t _port;
93 };
94 
95 /** @}*/
96 
97 } // namespace mbed
98 
99 #endif
100 
101 #endif
void mode(PinMode mode)
Set the input pin mode.
int read()
Read the value input to the port.
Definition: PortIn.h:73
int port_read(port_t *obj)
Read the current value on the port.
PortIn(PortName port, int mask=0xFFFFFFFF)
Create a PortIn, connected to the specified port.
A multiple pin digital input.
Definition: PortIn.h:58
struct port_s port_t
Port HAL structure.
Definition: port_api.h:33
Definition: ATHandler.h:46
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.