00

Committer:
ganlikun
Date:
Sun Jun 12 14:02:44 2022 +0000
Revision:
0:13413ea9a877
00

Who changed what in which revision?

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