Mbed OS Reference
Loading...
Searching...
No Matches
InterfaceDigitalIn.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_DIGITALIN_H_
21#define MBED_INTERFACE_DIGITALIN_H_
22
23#include "PinNames.h"
24
25namespace mbed {
26
27class DigitalIn;
28
29namespace 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 DigitalIn
36struct DigitalIn {
37 virtual ~DigitalIn() = default;
38 virtual int read() = 0;
39 virtual void mode(PinMode pull) = 0;
40 virtual int is_connected() = 0;
41
42 operator int()
43 {
44 // Underlying implementation is responsible for thread-safety
45 return read();
46 }
47
48};
49#else
50using DigitalIn = ::mbed::DigitalIn;
51#endif /* FEATURE_EXPERIMENTAL_API */
52
53} // namespace interface
54} // namespace mbed
55
56#endif /* MBED_INTERFACE_DIGITALIN_H_ */
A digital input, used for reading the state of a pin.
Definition: DigitalIn.h:60