Mistake on this page?
Report an issue in GitHub or email us
InterfaceDigitalInOut.h
1 /*
2  * Mbed-OS Microcontroller Library
3  * Copyright (c) 2021 Embedded Planet
4  * Copyright (c) 2021 ARM Limited
5  * SPDX-License-Identifier: Apache-2.0
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License
18  */
19 
20 #ifndef MBED_INTERFACE_DIGITALINOUT_H_
21 #define MBED_INTERFACE_DIGITALINOUT_H_
22 
23 #include "PinNames.h"
24 
25 namespace mbed {
26 
27 class DigitalInOut;
28 
29 namespace interface {
30 
31 #ifdef FEATURE_EXPERIMENTAL_API
32 
33 // TODO - move method doxygen comments to interface once this polymorphism is mainstream
34 
35 // Pure interface definition for DigitalInOut
36 struct DigitalInOut {
37  virtual ~DigitalInOut() = default;
38  virtual void write(int value) = 0;
39  virtual int read() = 0;
40  virtual void output() = 0;
41  virtual void input() = 0;
42  virtual void mode(PinMode pull) = 0;
43  virtual int is_connected() = 0;
44 
45  DigitalInOut &operator= (int value)
46  {
47  // Underlying implementation is responsible for thread-safety
48  write(value);
49  return *this;
50  }
51 
53  {
54  // Underlying implementation is responsible for thread-safety
55  write(rhs.read());
56  return *this;
57  }
58 
59  operator int()
60  {
61  // Underlying implementation is responsible for thread-safety
62  return read();
63  }
64 
65 };
66 #else
68 #endif /* FEATURE_EXPERIMENTAL_API */
69 
70 } // namespace interface
71 } // namespace mbed
72 
73 #endif /* MBED_INTERFACE_DIGITALINOUT_H_ */
void output()
Set as an output.
void input()
Set as an input.
DigitalInOut & operator=(int value)
A shorthand for write()
Definition: DigitalInOut.h:125
A digital input/output, used for setting or reading a bi-directional pin.
Definition: DigitalInOut.h:36
void write(int value)
Set the output, specified as 0 or 1 (int)
Definition: DigitalInOut.h:71
int read()
Return the output setting, represented as 0 or 1 (int)
Definition: DigitalInOut.h:83
int is_connected()
Return the output setting, represented as 0 or 1 (int)
Definition: DigitalInOut.h:109
void mode(PinMode pull)
Set the input pin mode.
DigitalInOut(PinName pin)
Create a DigitalInOut connected to the specified pin.
Definition: DigitalInOut.h:47
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.