mbed-drivers
DigitalInOut.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_DIGITALINOUT_H
18 #define MBED_DIGITALINOUT_H
19 
20 #include "platform.h"
21 
22 #include "gpio_api.h"
23 
24 namespace mbed {
25 
28 class DigitalInOut {
29 
30 public:
35  DigitalInOut(PinName pin) : gpio() {
36  gpio_init_in(&gpio, pin);
37  }
38 
46  DigitalInOut(PinName pin, PinDirection direction, PinMode mode, int value) : gpio() {
47  gpio_init_inout(&gpio, pin, direction, mode, value);
48  }
49 
55  void write(int value) {
56  gpio_write(&gpio, value);
57  }
58 
65  int read() {
66  return gpio_read(&gpio);
67  }
68 
71  void output() {
72  gpio_dir(&gpio, PIN_OUTPUT);
73  }
74 
77  void input() {
78  gpio_dir(&gpio, PIN_INPUT);
79  }
80 
85  void mode(PinMode pull) {
86  gpio_mode(&gpio, pull);
87  }
88 
89 #ifdef MBED_OPERATORS
90 
92  DigitalInOut& operator= (int value) {
93  write(value);
94  return *this;
95  }
96 
98  write(rhs.read());
99  return *this;
100  }
101 
104  operator int() {
105  return read();
106  }
107 #endif
108 
109 protected:
110  gpio_t gpio;
111 };
112 
113 } // namespace mbed
114 
115 #endif
void input()
Definition: DigitalInOut.h:77
DigitalInOut & operator=(int value)
Definition: DigitalInOut.h:92
Definition: DigitalInOut.h:28
DigitalInOut(PinName pin)
Definition: DigitalInOut.h:35
DigitalInOut(PinName pin, PinDirection direction, PinMode mode, int value)
Definition: DigitalInOut.h:46
int read()
Definition: DigitalInOut.h:65
void output()
Definition: DigitalInOut.h:71
void write(int value)
Definition: DigitalInOut.h:55
void mode(PinMode pull)
Definition: DigitalInOut.h:85
Definition: BusIn.cpp:19