Mistake on this page?
Report an issue in GitHub or email us
PortInOut.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_PORTINOUT_H
18 #define MBED_PORTINOUT_H
19 
20 #include "platform/platform.h"
21 
22 #if DEVICE_PORTINOUT || defined(DOXYGEN_ONLY)
23 
24 #include "hal/port_api.h"
25 
26 namespace mbed {
27 /**
28  * \defgroup drivers_PortInOut PortInOut class
29  * \ingroup drivers-public-api-gpio
30  * @{
31  */
32 
33 /** A multiple pin digital in/out used to set/read multiple bi-directional pins
34  *
35  * @note Synchronization level: Interrupt safe
36  */
37 class PortInOut {
38 public:
39 
40  /** Create an PortInOut, connected to the specified port
41  *
42  * @param port Port to connect to (Port0-Port5)
43  * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
44  */
45  PortInOut(PortName port, int mask = 0xFFFFFFFF);
46 
47  /** Write the value to the output port
48  *
49  * @param value An integer specifying a bit to write for every corresponding port pin
50  */
51  void write(int value)
52  {
53  port_write(&_port, value);
54  }
55 
56  /** Read the value currently output on the port
57  *
58  * @returns
59  * An integer with each bit corresponding to associated port pin setting
60  */
61  int read()
62  {
63  return port_read(&_port);
64  }
65 
66  /** Set as an output
67  */
68  void output();
69 
70  /** Set as an input
71  */
72  void input();
73 
74  /** Set the input pin mode
75  *
76  * @param mode PullUp, PullDown, PullNone, OpenDrain
77  */
78  void mode(PinMode mode);
79 
80  /** A shorthand for write()
81  * \sa PortInOut::write()
82  */
83  PortInOut &operator= (int value)
84  {
85  write(value);
86  return *this;
87  }
88 
89  /** A shorthand for write()
90  * \sa PortInOut::write()
91  */
93  {
94  write(rhs.read());
95  return *this;
96  }
97 
98  /** A shorthand for read()
99  * \sa PortInOut::read()
100  */
101  operator int()
102  {
103  return read();
104  }
105 
106 private:
107  port_t _port;
108 };
109 
110 /** @}*/
111 
112 } // namespace mbed
113 
114 #endif
115 
116 #endif
int read()
Read the value currently output on the port.
Definition: PortInOut.h:61
A multiple pin digital in/out used to set/read multiple bi-directional pins.
Definition: PortInOut.h:37
void mode(PinMode mode)
Set the input pin mode.
int port_read(port_t *obj)
Read the current value on the port.
void write(int value)
Write the value to the output port.
Definition: PortInOut.h:51
PortInOut(PortName port, int mask=0xFFFFFFFF)
Create an PortInOut, connected to the specified port.
void input()
Set as an input.
PortInOut & operator=(int value)
A shorthand for write()
Definition: PortInOut.h:83
struct port_s port_t
Port HAL structure.
Definition: port_api.h:33
void output()
Set as an output.
Definition: ATHandler.h:46
void port_write(port_t *obj, int value)
Write value to the port.
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.