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.
18 static inline void _gpio_init_in(gpio_t* gpio, PinName pin, PinMode mode)
22 gpio_dir(gpio, PIN_INPUT);
23 gpio_mode(gpio, mode);
27 static inline void _gpio_init_out(gpio_t* gpio, PinName pin, PinMode mode, int value)
31 gpio_write(gpio, value);
32 gpio_dir(gpio, PIN_OUTPUT);
33 gpio_mode(gpio, mode);
37 void gpio_init_in(gpio_t* gpio, PinName pin) {
38 gpio_init_in_ex(gpio, pin, PullDefault);
41 void gpio_init_in_ex(gpio_t* gpio, PinName pin, PinMode mode) {
42 _gpio_init_in(gpio, pin, mode);
45 void gpio_init_out(gpio_t* gpio, PinName pin) {
46 gpio_init_out_ex(gpio, pin, 0);
49 void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value) {
50 _gpio_init_out(gpio, pin, PullNone, value);
53 void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value) {
54 if (direction == PIN_INPUT) {
55 _gpio_init_in(gpio, pin, mode);
57 gpio_write(gpio, value); // we prepare the value in case it is switched later
59 _gpio_init_out(gpio, pin, mode, value);