1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #ifndef MBED_DIGITALINOUT_H
17 #define MBED_DIGITALINOUT_H
25 /** A digital input/output, used for setting or reading a bi-directional pin
30 /** Create a DigitalInOut connected to the specified pin
32 * @param pin DigitalInOut pin to connect to
34 DigitalInOut(PinName pin) : gpio() {
35 gpio_init_in(&gpio, pin);
38 /** Create a DigitalInOut connected to the specified pin
40 * @param pin DigitalInOut pin to connect to
41 * @param direction the initial direction of the pin
42 * @param mode the initial mode of the pin
43 * @param value the initial value of the pin if is an output
45 DigitalInOut(PinName pin, PinDirection direction, PinMode mode, int value) : gpio() {
46 gpio_init_inout(&gpio, pin, direction, mode, value);
49 /** Set the output, specified as 0 or 1 (int)
51 * @param value An integer specifying the pin output value,
52 * 0 for logical 0, 1 (or any other non-zero value) for logical 1
54 void write(int value) {
55 gpio_write(&gpio, value);
58 /** Return the output setting, represented as 0 or 1 (int)
61 * an integer representing the output setting of the pin if it is an output,
62 * or read the input if set as an input
65 return gpio_read(&gpio);
71 gpio_dir(&gpio, PIN_OUTPUT);
77 gpio_dir(&gpio, PIN_INPUT);
80 /** Set the input pin mode
82 * @param mode PullUp, PullDown, PullNone, OpenDrain
84 void mode(PinMode pull) {
85 gpio_mode(&gpio, pull);
88 /** Return the output setting, represented as 0 or 1 (int)
91 * Non zero value if pin is connected to uc GPIO
92 * 0 if gpio object was initialized with NC
95 return gpio_is_connected(&gpio);
99 /** A shorthand for write()
101 DigitalInOut& operator= (int value) {
106 DigitalInOut& operator= (DigitalInOut& rhs) {
111 /** A shorthand for read()