Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of TUKS-COURSE-TIMER by
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 gpio_init_in_ex(gpio, pin, PullDefault); 00039 } 00040 00041 void gpio_init_in_ex(gpio_t* gpio, PinName pin, PinMode mode) { 00042 _gpio_init_in(gpio, pin, mode); 00043 } 00044 00045 void gpio_init_out(gpio_t* gpio, PinName pin) { 00046 gpio_init_out_ex(gpio, pin, 0); 00047 } 00048 00049 void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value) { 00050 _gpio_init_out(gpio, pin, PullNone, value); 00051 } 00052 00053 void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value) { 00054 if (direction == PIN_INPUT) { 00055 _gpio_init_in(gpio, pin, mode); 00056 if (pin != NC) 00057 gpio_write(gpio, value); // we prepare the value in case it is switched later 00058 } else { 00059 _gpio_init_out(gpio, pin, mode, value); 00060 } 00061 }
Generated on Tue Jul 12 2022 17:38:48 by
