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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
mbed_gpio.c
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #include "hal/gpio_api.h" 00018 #include "platform/mbed_toolchain.h" 00019 00020 static inline void _gpio_init_in(gpio_t *gpio, PinName pin, PinMode mode) 00021 { 00022 gpio_init(gpio, pin); 00023 if (pin != NC) { 00024 gpio_dir(gpio, PIN_INPUT); 00025 gpio_mode(gpio, mode); 00026 } 00027 } 00028 00029 static inline void _gpio_init_out(gpio_t *gpio, PinName pin, PinMode mode, int value) 00030 { 00031 gpio_init(gpio, pin); 00032 if (pin != NC) { 00033 gpio_write(gpio, value); 00034 gpio_dir(gpio, PIN_OUTPUT); 00035 gpio_mode(gpio, mode); 00036 } 00037 } 00038 00039 void gpio_init_in(gpio_t *gpio, PinName pin) 00040 { 00041 gpio_init_in_ex(gpio, pin, PullDefault); 00042 } 00043 00044 void gpio_init_in_ex(gpio_t *gpio, PinName pin, PinMode mode) 00045 { 00046 _gpio_init_in(gpio, pin, mode); 00047 } 00048 00049 void gpio_init_out(gpio_t *gpio, PinName pin) 00050 { 00051 gpio_init_out_ex(gpio, pin, 0); 00052 } 00053 00054 void gpio_init_out_ex(gpio_t *gpio, PinName pin, int value) 00055 { 00056 _gpio_init_out(gpio, pin, PullNone, value); 00057 } 00058 00059 void gpio_init_inout(gpio_t *gpio, PinName pin, PinDirection direction, PinMode mode, int value) 00060 { 00061 if (direction == PIN_INPUT) { 00062 _gpio_init_in(gpio, pin, mode); 00063 if (pin != NC) { 00064 gpio_write(gpio, value); // we prepare the value in case it is switched later 00065 } 00066 } else { 00067 _gpio_init_out(gpio, pin, mode, value); 00068 } 00069 } 00070 00071 #ifdef TARGET_FF_ARDUINO 00072 00073 typedef enum { 00074 DEFAULT_GPIO = 0, 00075 } DefaultGPIOPeripheralName; 00076 00077 MBED_WEAK const PinMap *gpio_pinmap() 00078 { 00079 // Targets should override this weak implementation to provide correct data. 00080 static const PinMap empty_gpio_pinmap[] = { 00081 {D0, DEFAULT_GPIO, 0}, 00082 {D1, DEFAULT_GPIO, 0}, 00083 {D2, DEFAULT_GPIO, 0}, 00084 {D3, DEFAULT_GPIO, 0}, 00085 {D4, DEFAULT_GPIO, 0}, 00086 {D5, DEFAULT_GPIO, 0}, 00087 {D6, DEFAULT_GPIO, 0}, 00088 {D7, DEFAULT_GPIO, 0}, 00089 {D8, DEFAULT_GPIO, 0}, 00090 {D9, DEFAULT_GPIO, 0}, 00091 {D10, DEFAULT_GPIO, 0}, 00092 {D11, DEFAULT_GPIO, 0}, 00093 {D12, DEFAULT_GPIO, 0}, 00094 {D13, DEFAULT_GPIO, 0}, 00095 {D14, DEFAULT_GPIO, 0}, 00096 {D15, DEFAULT_GPIO, 0}, 00097 {A0, DEFAULT_GPIO, 0}, 00098 {A1, DEFAULT_GPIO, 0}, 00099 {A2, DEFAULT_GPIO, 0}, 00100 {A3, DEFAULT_GPIO, 0}, 00101 {A4, DEFAULT_GPIO, 0}, 00102 {A5, DEFAULT_GPIO, 0}, 00103 00104 {NC, NC, 0}, 00105 }; 00106 return empty_gpio_pinmap; 00107 } 00108 00109 #else 00110 00111 MBED_WEAK const PinMap *gpio_pinmap() 00112 { 00113 static const PinMap empty_gpio_pinmap[] = { 00114 {NC, NC, 0}, 00115 }; 00116 return empty_gpio_pinmap; 00117 } 00118 00119 #endif
Generated on Tue Jul 12 2022 13:54:33 by
