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 #include "pinmap.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /**
32  * \defgroup hal_gpio GPIO HAL functions
33  *
34  * # Defined behavior
35  * * ::gpio_init and other init functions can be called with NC or a valid PinName for the target - Verified by ::gpio_nc_test
36  * * ::gpio_is_connected can be used to test whether a gpio_t object was initialized with NC - Verified by ::gpio_nc_test
37  * * ::gpio_init initializes the GPIO pin
38  * * ::gpio_free returns the pin owned by the GPIO object to its reset state
39  * * ::gpio_mode sets the mode of the given pin
40  * * ::gpio_dir sets the direction of the given pin
41  * * ::gpio_write sets the gpio output value
42  * * ::gpio_read reads the input value
43  * * ::gpio_init_in inits the input pin and sets mode to PullDefault
44  * * ::gpio_init_in_ex inits the input pin and sets the mode
45  * * ::gpio_init_out inits the pin as an output, with predefined output value 0
46  * * ::gpio_init_out_ex inits the pin as an output and sets the output value
47  * * ::gpio_init_inout inits the pin to be input/output and set pin mode and value
48  * * The GPIO operations ::gpio_write, ::gpio_read take less than 20us to complete
49  *
50  * # Undefined behavior
51  * * Calling any ::gpio_mode, ::gpio_dir, ::gpio_write or ::gpio_read on a gpio_t object that was initialized
52  * with NC.
53  * * Calling ::gpio_set with NC.
54  *
55  * @{
56  */
57 
58 /**
59  * \defgroup hal_gpio_tests GPIO HAL tests
60  * The GPIO HAL tests ensure driver conformance to defined behaviour.
61  *
62  * To run the GPIO hal tests use the command:
63  *
64  * mbed test -t <toolchain> -m <target> -n tests-mbed_hal_fpga_ci_test_shield-gpio,tests-mbed_hal-gpio
65  *
66  */
67 
68 /** Set the given pin as GPIO
69  *
70  * @param pin The pin to be set as GPIO
71  * @return The GPIO port mask for this pin
72  **/
73 uint32_t gpio_set(PinName pin);
74 
75 /** Checks if gpio object is connected (pin was not initialized with NC)
76  * @param obj The GPIO object
77  * @return 0 if object was initialized with NC
78  * @return non-zero if object was initialized with a valid PinName
79  **/
80 int gpio_is_connected(const gpio_t *obj);
81 
82 /** Initialize the GPIO pin
83  *
84  * @param obj The GPIO object to initialize
85  * @param pin The GPIO pin to initialize (may be NC)
86  */
87 void gpio_init(gpio_t *obj, PinName pin);
88 
89 /** Releases the GPIO pin
90  *
91  * @param obj The GPIO object to release
92  */
93 void gpio_free(gpio_t *obj);
94 
95 /** Set the input pin mode
96  *
97  * @param obj The GPIO object (must be connected)
98  * @param mode The pin mode to be set
99  */
100 void gpio_mode(gpio_t *obj, PinMode mode);
101 
102 /** Set the pin direction
103  *
104  * @param obj The GPIO object (must be connected)
105  * @param direction The pin direction to be set
106  */
107 void gpio_dir(gpio_t *obj, PinDirection direction);
108 
109 /** Set the output value
110  *
111  * @param obj The GPIO object (must be connected)
112  * @param value The value to be set
113  */
114 void gpio_write(gpio_t *obj, int value);
115 
116 /** Read the input value
117  *
118  * @param obj The GPIO object (must be connected)
119  * @return An integer value 1 or 0
120  */
121 int gpio_read(gpio_t *obj);
122 
123 // the following functions are generic and implemented in the common gpio.c file
124 // TODO: fix, will be moved to the common gpio header file
125 
126 /** Init the input pin and set mode to PullDefault
127  *
128  * @param gpio The GPIO object
129  * @param pin The pin name (may be NC)
130  */
131 void gpio_init_in(gpio_t *gpio, PinName pin);
132 
133 /** Init the input pin and set the mode
134  *
135  * @param gpio The GPIO object
136  * @param pin The pin name (may be NC)
137  * @param mode The pin mode to be set
138  */
139 void gpio_init_in_ex(gpio_t *gpio, PinName pin, PinMode mode);
140 
141 /** Init the output pin as an output, with predefined output value 0
142  *
143  * @param gpio The GPIO object
144  * @param pin The pin name (may be NC)
145  * @return An integer value 1 or 0
146  */
147 void gpio_init_out(gpio_t *gpio, PinName pin);
148 
149 /** Init the pin as an output and set the output value
150  *
151  * @param gpio The GPIO object
152  * @param pin The pin name (may be NC)
153  * @param value The value to be set
154  */
155 void gpio_init_out_ex(gpio_t *gpio, PinName pin, int value);
156 
157 /** Init the pin to be in/out
158  *
159  * @param gpio The GPIO object
160  * @param pin The pin name (may be NC)
161  * @param direction The pin direction to be set
162  * @param mode The pin mode to be set
163  * @param value The value to be set for an output pin
164  */
165 void gpio_init_inout(gpio_t *gpio, PinName pin, PinDirection direction, PinMode mode, int value);
166 
167 /** Get the pins that support all GPIO tests
168  *
169  * Return a PinMap array of pins that support GPIO. The
170  * array is terminated with {NC, NC, 0}.
171  *
172  * Targets should override the weak implementation of this
173  * function to provide the actual pinmap for GPIO testing.
174  *
175  * @return PinMap array
176  */
177 const PinMap *gpio_pinmap(void);
178 
179 /**@}*/
180 
181 #ifdef __cplusplus
182 }
183 #endif
184 
185 #endif
186 
187 /** @}*/
void gpio_init_inout(gpio_t *gpio, PinName pin, PinDirection direction, PinMode mode, int value)
Init the pin to be in/out.
const PinMap * gpio_pinmap(void)
Get the pins that support all GPIO tests.
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.
Definition: pinmap.h:31
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_free(gpio_t *obj)
Releases the GPIO pin.
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.