Mistake on this page?
Report an issue in GitHub or email us
gpio_api.h
1 
2 /** \addtogroup hal */
3 /** @{*/
4 /* mbed Microcontroller Library
5  * Copyright (c) 2006-2013 ARM Limited
6  * SPDX-License-Identifier: Apache-2.0
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 #ifndef MBED_GPIO_API_H
21 #define MBED_GPIO_API_H
22 
23 #include <stdint.h>
24 #include "device.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /**
31  * \defgroup hal_gpio GPIO HAL functions
32  *
33  * # Defined behavior
34  * * ::gpio_init and other init functions can be called with NC or a valid PinName for the target - Verified by ::gpio_nc_test
35  * * ::gpio_is_connected can be used to test whether a gpio_t object was initialized with NC - Verified by ::gpio_nc_test
36  *
37  * # Undefined behavior
38  * * Calling any ::gpio_mode, ::gpio_dir, ::gpio_write or ::gpio_read on a gpio_t object that was initialized
39  * with NC.
40  * * Calling ::gpio_set with NC.
41  *
42  * @{
43  */
44 
45 /** Set the given pin as GPIO
46  *
47  * @param pin The pin to be set as GPIO
48  * @return The GPIO port mask for this pin
49  **/
50 uint32_t gpio_set(PinName pin);
51 
52 /** Checks if gpio object is connected (pin was not initialized with NC)
53  * @param obj The GPIO object
54  * @return 0 if object was initialized with NC
55  * @return non-zero if object was initialized with a valid PinName
56  **/
57 int gpio_is_connected(const gpio_t *obj);
58 
59 /** Initialize the GPIO pin
60  *
61  * @param obj The GPIO object to initialize
62  * @param pin The GPIO pin to initialize (may be NC)
63  */
64 void gpio_init(gpio_t *obj, PinName pin);
65 
66 /** Set the input pin mode
67  *
68  * @param obj The GPIO object (must be connected)
69  * @param mode The pin mode to be set
70  */
71 void gpio_mode(gpio_t *obj, PinMode mode);
72 
73 /** Set the pin direction
74  *
75  * @param obj The GPIO object (must be connected)
76  * @param direction The pin direction to be set
77  */
78 void gpio_dir(gpio_t *obj, PinDirection direction);
79 
80 /** Set the output value
81  *
82  * @param obj The GPIO object (must be connected)
83  * @param value The value to be set
84  */
85 void gpio_write(gpio_t *obj, int value);
86 
87 /** Read the input value
88  *
89  * @param obj The GPIO object (must be connected)
90  * @return An integer value 1 or 0
91  */
92 int gpio_read(gpio_t *obj);
93 
94 // the following functions are generic and implemented in the common gpio.c file
95 // TODO: fix, will be moved to the common gpio header file
96 
97 /** Init the input pin and set mode to PullDefault
98  *
99  * @param gpio The GPIO object
100  * @param pin The pin name (may be NC)
101  */
102 void gpio_init_in(gpio_t *gpio, PinName pin);
103 
104 /** Init the input pin and set the mode
105  *
106  * @param gpio The GPIO object
107  * @param pin The pin name (may be NC)
108  * @param mode The pin mode to be set
109  */
110 void gpio_init_in_ex(gpio_t *gpio, PinName pin, PinMode mode);
111 
112 /** Init the output pin as an output, with predefined output value 0
113  *
114  * @param gpio The GPIO object
115  * @param pin The pin name (may be NC)
116  * @return An integer value 1 or 0
117  */
118 void gpio_init_out(gpio_t *gpio, PinName pin);
119 
120 /** Init the pin as an output and set the output value
121  *
122  * @param gpio The GPIO object
123  * @param pin The pin name (may be NC)
124  * @param value The value to be set
125  */
126 void gpio_init_out_ex(gpio_t *gpio, PinName pin, int value);
127 
128 /** Init the pin to be in/out
129  *
130  * @param gpio The GPIO object
131  * @param pin The pin name (may be NC)
132  * @param direction The pin direction to be set
133  * @param mode The pin mode to be set
134  * @param value The value to be set for an output pin
135  */
136 void gpio_init_inout(gpio_t *gpio, PinName pin, PinDirection direction, PinMode mode, int value);
137 
138 /**@}*/
139 
140 #ifdef __cplusplus
141 }
142 #endif
143 
144 #endif
145 
146 /** @}*/
void gpio_init_inout(gpio_t *gpio, PinName pin, PinDirection direction, PinMode mode, int value)
Init the pin to be in/out.
void gpio_init(gpio_t *obj, PinName pin)
Initialize the GPIO pin.
int gpio_is_connected(const gpio_t *obj)
Checks if gpio object is connected (pin was not initialized with NC)
void gpio_write(gpio_t *obj, int value)
Set the output value.
int gpio_read(gpio_t *obj)
Read the input value.
void gpio_dir(gpio_t *obj, PinDirection direction)
Set the pin direction.
uint32_t gpio_set(PinName pin)
Set the given pin as GPIO.
void gpio_init_out(gpio_t *gpio, PinName pin)
Init the output pin as an output, with predefined output value 0.
void gpio_mode(gpio_t *obj, PinMode mode)
Set the input pin mode.
void gpio_init_out_ex(gpio_t *gpio, PinName pin, int value)
Init the pin as an output and set the output value.
void gpio_init_in(gpio_t *gpio, PinName pin)
Init the input pin and set mode to PullDefault.
void gpio_init_in_ex(gpio_t *gpio, PinName pin, PinMode mode)
Init the input pin and set the mode.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.