takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mbed_gpio.c Source File

mbed_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 "hal/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     if (pin != NC) {
00022         gpio_dir(gpio, PIN_INPUT);
00023         gpio_mode(gpio, mode);
00024     }
00025 }
00026 
00027 static inline void _gpio_init_out(gpio_t *gpio, PinName pin, PinMode mode, int value)
00028 {
00029     gpio_init(gpio, pin);
00030     if (pin != NC) {
00031         gpio_write(gpio, value);
00032         gpio_dir(gpio, PIN_OUTPUT);
00033         gpio_mode(gpio, mode);
00034     }
00035 }
00036 
00037 void gpio_init_in(gpio_t *gpio, PinName pin)
00038 {
00039     gpio_init_in_ex(gpio, pin, PullDefault);
00040 }
00041 
00042 void gpio_init_in_ex(gpio_t *gpio, PinName pin, PinMode mode)
00043 {
00044     _gpio_init_in(gpio, pin, mode);
00045 }
00046 
00047 void gpio_init_out(gpio_t *gpio, PinName pin)
00048 {
00049     gpio_init_out_ex(gpio, pin, 0);
00050 }
00051 
00052 void gpio_init_out_ex(gpio_t *gpio, PinName pin, int value)
00053 {
00054     _gpio_init_out(gpio, pin, PullNone, value);
00055 }
00056 
00057 void gpio_init_inout(gpio_t *gpio, PinName pin, PinDirection direction, PinMode mode, int value)
00058 {
00059     if (direction == PIN_INPUT) {
00060         _gpio_init_in(gpio, pin, mode);
00061         if (pin != NC) {
00062             gpio_write(gpio, value);    // we prepare the value in case it is switched later
00063         }
00064     } else {
00065         _gpio_init_out(gpio, pin, mode, value);
00066     }
00067 }