mbed library sources

Dependents:   bare

Fork of mbed-src by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers gpio.c Source File

gpio.c

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "gpio_api.h"
00017 
00018 static inline void _gpio_init_in(gpio_t* gpio, PinName pin, PinMode mode)
00019 {
00020     gpio_init(gpio, pin);    
00021     gpio_dir(gpio, PIN_INPUT);
00022     gpio_mode(gpio, mode);
00023 }
00024     
00025 static inline void _gpio_init_out(gpio_t* gpio, PinName pin, PinMode mode, int value)
00026 {
00027     gpio_init(gpio, pin);
00028     gpio_write(gpio, value);
00029     gpio_dir(gpio, PIN_OUTPUT);
00030     gpio_mode(gpio, mode);
00031 }
00032 
00033 void gpio_init_in(gpio_t* gpio, PinName pin) {
00034     gpio_init_in_ex(gpio, pin, PullDefault);
00035 }
00036 
00037 void gpio_init_in_ex(gpio_t* gpio, PinName pin, PinMode mode) {
00038     _gpio_init_in(gpio, pin, mode);
00039 }
00040 
00041 void gpio_init_out(gpio_t* gpio, PinName pin) {
00042     gpio_init_out_ex(gpio, pin, 0);
00043 }
00044 
00045 void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value) {
00046     _gpio_init_out(gpio, pin, PullNone, value);
00047 }
00048 
00049 void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value) {
00050     if (direction == PIN_INPUT) {
00051         _gpio_init_in(gpio, pin, mode);
00052         gpio_write(gpio, value); // we prepare the value in case it is switched later
00053     } else {
00054         _gpio_init_out(gpio, pin, mode, value);
00055     }
00056 }