mbed-drivers
DigitalIn.h
1 /*
2  * Copyright (c) 2006-2016, ARM Limited, All Rights Reserved
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may
6  * 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, WITHOUT
13  * 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_DIGITALIN_H
18 #define MBED_DIGITALIN_H
19 
20 #include "platform.h"
21 
22 #include "gpio_api.h"
23 
24 namespace mbed {
25 
47 class DigitalIn {
48 
49 public:
54  DigitalIn(PinName pin) : gpio() {
55  gpio_init_in(&gpio, pin);
56  }
57 
63  DigitalIn(PinName pin, PinMode mode) : gpio() {
64  gpio_init_in_ex(&gpio, pin, mode);
65  }
72  int read() {
73  return gpio_read(&gpio);
74  }
75 
80  void mode(PinMode pull) {
81  gpio_mode(&gpio, pull);
82  }
83 
84 #ifdef MBED_OPERATORS
85 
87  operator int() {
88  return read();
89  }
90 #endif
91 
92 protected:
93  gpio_t gpio;
94 };
95 
96 } // namespace mbed
97 
98 #endif
int read()
Definition: DigitalIn.h:72
void mode(PinMode pull)
Definition: DigitalIn.h:80
DigitalIn(PinName pin)
Definition: DigitalIn.h:54
Definition: DigitalIn.h:47
Definition: BusIn.cpp:19
DigitalIn(PinName pin, PinMode mode)
Definition: DigitalIn.h:63