|
@@
-1,4
+1,4
|
|
1
|
/*------------------------------------------------------------------------------
|
|
1
|
/** ------------------------------------------------------------------------------
|
|
2
|
-- This file is a part of the libuc, microcontroler library
|
|
2
|
-- This file is a part of the libuc, microcontroler library
|
|
3
|
-- Copyright (C) 2012, Alexis Jeandet
|
|
3
|
-- Copyright (C) 2012, Alexis Jeandet
|
|
4
|
--
|
|
4
|
--
|
|
@@
-16,8
+16,8
|
|
16
|
-- along with this program; if not, write to the Free Software
|
|
16
|
-- along with this program; if not, write to the Free Software
|
|
17
|
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17
|
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18
|
-------------------------------------------------------------------------------
|
|
18
|
-------------------------------------------------------------------------------
|
|
19
|
-- Author : Alexis Jeandet
|
|
19
|
-- @Author : Alexis Jeandet
|
|
20
|
-- Mail : alexis.jeandet@gmail.com
|
|
20
|
-- @Mail : alexis.jeandet@gmail.com
|
|
21
|
-------------------------------------------------------------------------------*/
|
|
21
|
-------------------------------------------------------------------------------*/
|
|
22
|
|
|
22
|
|
|
23
|
/*! \file gpio.h
|
|
23
|
/*! \file gpio.h
|
|
@@
-51,38
+51,77
A simple example to drive PA0 and read P
|
|
51
|
extern "C" {
|
|
51
|
extern "C" {
|
|
52
|
#endif
|
|
52
|
#endif
|
|
53
|
|
|
53
|
|
|
54
|
|
|
54
|
/**
|
|
|
|
|
55
|
* @brief gpio handle
|
|
|
|
|
56
|
*
|
|
|
|
|
57
|
*gpio_t is the handle type you will use for all
|
|
|
|
|
58
|
*gpio related functions.
|
|
|
|
|
59
|
*/
|
|
55
|
typedef uint32_t gpio_t;
|
|
60
|
typedef uint32_t gpio_t;
|
|
56
|
|
|
61
|
|
|
|
|
|
62
|
|
|
|
|
|
63
|
/**
|
|
|
|
|
64
|
* @brief GPIO speed enum
|
|
|
|
|
65
|
*
|
|
|
|
|
66
|
* Use gpiospeed_t values to configure the speed of your GPIO pin with
|
|
|
|
|
67
|
* gpiosetspeed(gpio_t* gpio,gpiospeed_t speed) function or gpiosetconfig(gpio_t* gpio).
|
|
|
|
|
68
|
* The speed values are realy platform dependant check for each target if you whant to
|
|
|
|
|
69
|
* know the meaning of each speed.
|
|
|
|
|
70
|
* Don't try to use numerical values directly!
|
|
|
|
|
71
|
* @sa gpiosetspeed(gpio_t* gpio,gpiospeed_t speed),gpiosetconfig(gpio_t* gpio)
|
|
|
|
|
72
|
*/
|
|
57
|
typedef enum gpiospeed_t
|
|
73
|
typedef enum gpiospeed_t
|
|
58
|
{
|
|
74
|
{
|
|
59
|
gpiolowspeed = 0x00000,
|
|
75
|
gpiolowspeed = 0x00000, /**< Lowest speed value*/
|
|
60
|
gpiomediumspeed = 0x10000,
|
|
76
|
gpiomediumspeed = 0x10000, /**< Normal or medium speed value*/
|
|
61
|
gpiofastspeed = 0x20000,
|
|
77
|
gpiofastspeed = 0x20000, /**< Higher speed value*/
|
|
62
|
gpiohighspeed = 0x30000
|
|
78
|
gpiohighspeed = 0x30000 /**< Highest speed value*/
|
|
63
|
}gpiospeed_t;
|
|
79
|
}gpiospeed_t;
|
|
64
|
|
|
80
|
|
|
65
|
|
|
81
|
|
|
66
|
|
|
82
|
|
|
|
|
|
83
|
/**
|
|
|
|
|
84
|
* @brief GPIO direction enum
|
|
|
|
|
85
|
*
|
|
|
|
|
86
|
* Use gpiodir_t values to configure the direction of your GPIO pin with
|
|
|
|
|
87
|
* gpiosetdir(gpio_t* gpio,gpiodir_t dir) function or gpiosetconfig(gpio_t* gpio).
|
|
|
|
|
88
|
* Don't try to use numerical values directly!
|
|
|
|
|
89
|
* @sa gpiosetdir(gpio_t* gpio,gpiodir_t dir),gpiosetconfig(gpio_t* gpio)
|
|
|
|
|
90
|
*/
|
|
67
|
typedef enum gpiodir_t
|
|
91
|
typedef enum gpiodir_t
|
|
68
|
{
|
|
92
|
{
|
|
69
|
gpioindir = 0x00000,
|
|
93
|
gpioindir = 0x00000, /**< Input direction*/
|
|
70
|
gpiooutdir = 0x40000,
|
|
94
|
gpiooutdir = 0x40000, /**< Output direction*/
|
|
71
|
gpioaf = 0x80000,
|
|
95
|
gpioaf = 0x80000, /**< Alternate function such as spi, uart, ...*/
|
|
72
|
gpioan = 0xC0000
|
|
96
|
gpioan = 0xC0000 /**< Configure the pin for analogic mode*/
|
|
73
|
}gpiodir_t;
|
|
97
|
}gpiodir_t;
|
|
74
|
|
|
98
|
|
|
75
|
|
|
99
|
|
|
76
|
|
|
100
|
|
|
77
|
|
|
101
|
/**
|
|
|
|
|
102
|
* @brief GPIO output type enum
|
|
|
|
|
103
|
*
|
|
|
|
|
104
|
* Use gpioouttype_t values to configure the kind of output you want with
|
|
|
|
|
105
|
* gpiosetouttype(gpio_t* gpio, gpioouttype_t outtype) function or gpiosetconfig(gpio_t* gpio).
|
|
|
|
|
106
|
* Don't try to use numerical values directly!
|
|
|
|
|
107
|
* @sa gpiosetouttype(gpio_t* gpio, gpioouttype_t outtype),gpiosetconfig(gpio_t* gpio)
|
|
|
|
|
108
|
*/
|
|
78
|
typedef enum gpioouttype_t
|
|
109
|
typedef enum gpioouttype_t
|
|
79
|
{
|
|
110
|
{
|
|
80
|
gpiopushpulltype = 0x000000,
|
|
111
|
gpiopushpulltype = 0x000000, /**< Pushpull output*/
|
|
81
|
gpioopendraintype = 0x100000
|
|
112
|
gpioopendraintype = 0x100000 /**< Open drain output*/
|
|
82
|
}gpioouttype_t;
|
|
113
|
}gpioouttype_t;
|
|
83
|
|
|
114
|
|
|
84
|
|
|
115
|
|
|
85
|
|
|
116
|
|
|
|
|
|
117
|
/**
|
|
|
|
|
118
|
* @brief GPIO pull resistor configuration enum
|
|
|
|
|
119
|
*
|
|
|
|
|
120
|
* Use gpiopulltype_t values to configure the pull resistor of your GPIO pin with
|
|
|
|
|
121
|
* gpiosetpulltype(gpio_t* gpio,gpiopulltype_t pulltype) function or gpiosetconfig(gpio_t* gpio).
|
|
|
|
|
122
|
* Don't try to use numerical values directly!
|
|
|
|
|
123
|
* @sa gpiosetpulltype(gpio_t* gpio,gpiopulltype_t pulltype),gpiosetconfig(gpio_t* gpio)
|
|
|
|
|
124
|
*/
|
|
86
|
typedef enum gpiopulltype_t
|
|
125
|
typedef enum gpiopulltype_t
|
|
87
|
{
|
|
126
|
{
|
|
88
|
gpionopulltype = 0x000000,
|
|
127
|
gpionopulltype = 0x000000,
|
|
@@
-97,17
+136,73
typedef enum gpiopulltype_t
|
|
97
|
#define GPIOPULLTYPEMASK 0x600000
|
|
136
|
#define GPIOPULLTYPEMASK 0x600000
|
|
98
|
#endif
|
|
137
|
#endif
|
|
99
|
|
|
138
|
|
|
100
|
|
|
139
|
/**
|
|
|
|
|
140
|
* @brief gpioopen
|
|
|
|
|
141
|
* @param gpio
|
|
|
|
|
142
|
* @return
|
|
|
|
|
143
|
* @sa gpioclose(gpio_t gpio)
|
|
|
|
|
144
|
*/
|
|
101
|
extern gpio_t gpioopen(uint32_t gpio);
|
|
145
|
extern gpio_t gpioopen(uint32_t gpio);
|
|
|
|
|
146
|
/**
|
|
|
|
|
147
|
* @brief gpioclose
|
|
|
|
|
148
|
* @param gpio
|
|
|
|
|
149
|
* @sa gpioopen(uint32_t gpio)
|
|
|
|
|
150
|
*/
|
|
102
|
extern void gpioclose(gpio_t gpio);
|
|
151
|
extern void gpioclose(gpio_t gpio);
|
|
|
|
|
152
|
/**
|
|
|
|
|
153
|
* @brief gpiosetconfig
|
|
|
|
|
154
|
* @param gpio
|
|
|
|
|
155
|
*/
|
|
103
|
extern void gpiosetconfig(gpio_t* gpio);
|
|
156
|
extern void gpiosetconfig(gpio_t* gpio);
|
|
|
|
|
157
|
/**
|
|
|
|
|
158
|
* @brief gpiosetdir
|
|
|
|
|
159
|
* @param gpio
|
|
|
|
|
160
|
* @param dir
|
|
|
|
|
161
|
*/
|
|
104
|
extern void gpiosetdir(gpio_t* gpio,gpiodir_t dir);
|
|
162
|
extern void gpiosetdir(gpio_t* gpio,gpiodir_t dir);
|
|
|
|
|
163
|
/**
|
|
|
|
|
164
|
* @brief gpiosetouttype
|
|
|
|
|
165
|
* @param gpio
|
|
|
|
|
166
|
* @param outtype
|
|
|
|
|
167
|
* @sa gpiosetconfig(gpio_t* gpio)
|
|
|
|
|
168
|
*/
|
|
105
|
extern void gpiosetouttype(gpio_t* gpio, gpioouttype_t outtype);
|
|
169
|
extern void gpiosetouttype(gpio_t* gpio, gpioouttype_t outtype);
|
|
|
|
|
170
|
/**
|
|
|
|
|
171
|
* @brief gpiosetpulltype
|
|
|
|
|
172
|
* @param gpio
|
|
|
|
|
173
|
* @param pulltype
|
|
|
|
|
174
|
* @sa gpiosetconfig(gpio_t* gpio)
|
|
|
|
|
175
|
*/
|
|
106
|
extern void gpiosetpulltype(gpio_t* gpio,gpiopulltype_t pulltype);
|
|
176
|
extern void gpiosetpulltype(gpio_t* gpio,gpiopulltype_t pulltype);
|
|
|
|
|
177
|
/**
|
|
|
|
|
178
|
* @brief gpiosetspeed
|
|
|
|
|
179
|
* @param gpio
|
|
|
|
|
180
|
* @param speed
|
|
|
|
|
181
|
* @sa gpiosetconfig(gpio_t* gpio)
|
|
|
|
|
182
|
*/
|
|
107
|
extern void gpiosetspeed(gpio_t* gpio,gpiospeed_t speed);
|
|
183
|
extern void gpiosetspeed(gpio_t* gpio,gpiospeed_t speed);
|
|
|
|
|
184
|
/**
|
|
|
|
|
185
|
* @brief gpioset
|
|
|
|
|
186
|
* @param gpio
|
|
|
|
|
187
|
* @sa gpiosetconfig(gpio_t* gpio)
|
|
|
|
|
188
|
*/
|
|
108
|
extern void gpioset(gpio_t gpio);
|
|
189
|
extern void gpioset(gpio_t gpio);
|
|
|
|
|
190
|
/**
|
|
|
|
|
191
|
* @brief gpioclr
|
|
|
|
|
192
|
* @param gpio
|
|
|
|
|
193
|
*/
|
|
109
|
extern void gpioclr(gpio_t gpio);
|
|
194
|
extern void gpioclr(gpio_t gpio);
|
|
|
|
|
195
|
/**
|
|
|
|
|
196
|
* @brief gpiosetval
|
|
|
|
|
197
|
* @param gpio
|
|
|
|
|
198
|
* @param val
|
|
|
|
|
199
|
*/
|
|
110
|
extern void gpiosetval(gpio_t gpio,int val);
|
|
200
|
extern void gpiosetval(gpio_t gpio,int val);
|
|
|
|
|
201
|
/**
|
|
|
|
|
202
|
* @brief gpiogetval
|
|
|
|
|
203
|
* @param gpio
|
|
|
|
|
204
|
* @return
|
|
|
|
|
205
|
*/
|
|
111
|
extern int gpiogetval(gpio_t gpio);
|
|
206
|
extern int gpiogetval(gpio_t gpio);
|
|
112
|
|
|
207
|
|
|
113
|
#define GPIOISINPUT(gpio) (((gpio) & GPIODIRMASK)==gpioindir)
|
|
208
|
#define GPIOISINPUT(gpio) (((gpio) & GPIODIRMASK)==gpioindir)
|