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