Contiki 3.x
gpio.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 /**
32  * \addtogroup cc2538
33  * @{
34  *
35  * \defgroup cc2538-gpio cc2538 General-Purpose I/O
36  *
37  * Driver for the cc2538 GPIO controller
38  * @{
39  *
40  * \file
41  * Header file with register and macro declarations for the cc2538 GPIO module
42  */
43 #ifndef GPIO_H_
44 #define GPIO_H_
45 
46 #include "reg.h"
47 
48 #include <stdint.h>
49 
50 /**
51  * \brief Type definition for callbacks invoked by the GPIO ISRs
52  * \param port The port that triggered the GPIO interrupt. \e port is passed
53  * by its numeric representation (Port A:0, B:1 etc). Defines for
54  * these numeric representations are GPIO_x_NUM
55  * \param pin The pin that triggered the interrupt, specified by number
56  * (0, 1, ..., 7)
57  *
58  * This is the prototype of a function pointer passed to
59  * gpio_register_callback(). These callbacks are registered on a port/pin
60  * basis. When a GPIO port generates an interrupt, if a callback has been
61  * registered for the port/pin combination, the ISR will invoke it. The ISR
62  * will pass the port/pin as arguments in that call, so that a developer can
63  * re-use the same callback for multiple port/pin combinations
64  */
65 typedef void (* gpio_callback_t)(uint8_t port, uint8_t pin);
66 /*---------------------------------------------------------------------------*/
67 /** \name Base addresses for the GPIO register instances
68  * @{
69  */
70 #define GPIO_A_BASE 0x400D9000 /**< GPIO_A */
71 #define GPIO_B_BASE 0x400DA000 /**< GPIO_B */
72 #define GPIO_C_BASE 0x400DB000 /**< GPIO_C */
73 #define GPIO_D_BASE 0x400DC000 /**< GPIO_D */
74 /** @} */
75 /*---------------------------------------------------------------------------*/
76 /** \name Numeric representation of the four GPIO ports
77  * @{
78  */
79 #define GPIO_A_NUM 0 /**< GPIO_A: 0 */
80 #define GPIO_B_NUM 1 /**< GPIO_B: 1 */
81 #define GPIO_C_NUM 2 /**< GPIO_C: 2 */
82 #define GPIO_D_NUM 3 /**< GPIO_D: 3 */
83 /** @} */
84 /*---------------------------------------------------------------------------*/
85 /**
86  * \name GPIO Manipulation macros
87  * @{
88  */
89 /** \brief Set pins with PIN_MASK of port with PORT_BASE to input.
90  * \param PORT_BASE GPIO Port register offset
91  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
92  */
93 #define GPIO_SET_INPUT(PORT_BASE, PIN_MASK) \
94  do { REG((PORT_BASE) | GPIO_DIR) &= ~(PIN_MASK); } while(0)
95 
96 /** \brief Set pins with PIN_MASK of port with PORT_BASE to output.
97 * \param PORT_BASE GPIO Port register offset
98 * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
99 */
100 #define GPIO_SET_OUTPUT(PORT_BASE, PIN_MASK) \
101  do { REG((PORT_BASE) | GPIO_DIR) |= (PIN_MASK); } while(0)
102 
103 /** \brief Set pins with PIN_MASK of port with PORT_BASE high.
104  * \param PORT_BASE GPIO Port register offset
105  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
106  */
107 #define GPIO_SET_PIN(PORT_BASE, PIN_MASK) \
108  do { REG(((PORT_BASE) | GPIO_DATA) + ((PIN_MASK) << 2)) = 0xFF; } while(0)
109 
110 /** \brief Set pins with PIN_MASK of port with PORT_BASE low.
111 * \param PORT_BASE GPIO Port register offset
112 * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
113 */
114 #define GPIO_CLR_PIN(PORT_BASE, PIN_MASK) \
115  do { REG(((PORT_BASE) | GPIO_DATA) + ((PIN_MASK) << 2)) = 0x00; } while(0)
116 
117 /** \brief Set pins with PIN_MASK of port with PORT_BASE to value.
118  * \param PORT_BASE GPIO Port register offset
119  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
120  */
121 #define GPIO_WRITE_PIN(PORT_BASE, PIN_MASK, value) \
122  do { REG(((PORT_BASE) | GPIO_DATA) + ((PIN_MASK) << 2)) = (value); } while(0)
123 
124 /** \brief Read pins with PIN_MASK of port with PORT_BASE.
125  * \param PORT_BASE GPIO Port register offset
126  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
127  */
128 #define GPIO_READ_PIN(PORT_BASE, PIN_MASK) \
129  REG(((PORT_BASE) | GPIO_DATA) + ((PIN_MASK) << 2))
130 
131 /** \brief Set pins with PIN_MASK of port with PORT_BASE to detect edge.
132  * \param PORT_BASE GPIO Port register offset
133  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
134  */
135 #define GPIO_DETECT_EDGE(PORT_BASE, PIN_MASK) \
136  do { REG((PORT_BASE) | GPIO_IS) &= ~(PIN_MASK); } while(0)
137 
138 /** \brief Set pins with PIN_MASK of port with PORT_BASE to detect level.
139  * \param PORT_BASE GPIO Port register offset
140  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
141  */
142 #define GPIO_DETECT_LEVEL(PORT_BASE, PIN_MASK) \
143  do { REG((PORT_BASE) | GPIO_IS) |= (PIN_MASK); } while(0)
144 
145 /** \brief Set pins with PIN_MASK of port with PORT_BASE to trigger an
146  * interrupt on both edges.
147  * \param PORT_BASE GPIO Port register offset
148  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
149  */
150 #define GPIO_TRIGGER_BOTH_EDGES(PORT_BASE, PIN_MASK) \
151  do { REG((PORT_BASE) | GPIO_IBE) |= (PIN_MASK); } while(0)
152 
153 /** \brief Set pins with PIN_MASK of port with PORT_BASE to trigger an
154  * interrupt on single edge (controlled by GPIO_IEV).
155  * \param PORT_BASE GPIO Port register offset
156  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
157  */
158 #define GPIO_TRIGGER_SINGLE_EDGE(PORT_BASE, PIN_MASK) \
159  do { REG((PORT_BASE) | GPIO_IBE) &= ~(PIN_MASK); } while(0)
160 
161 /** \brief Set pins with PIN_MASK of port with PORT_BASE to trigger an
162  * interrupt on rising edge.
163  * \param PORT_BASE GPIO Port register offset
164  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
165  */
166 #define GPIO_DETECT_RISING(PORT_BASE, PIN_MASK) \
167  do { REG((PORT_BASE) | GPIO_IEV) |= (PIN_MASK); } while(0)
168 
169 /** \brief Set pins with PIN_MASK of port with PORT_BASE to trigger an
170  * interrupt on falling edge.
171  * \param PORT_BASE GPIO Port register offset
172  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
173  */
174 #define GPIO_DETECT_FALLING(PORT_BASE, PIN_MASK) \
175  do { REG((PORT_BASE) | GPIO_IEV) &= ~(PIN_MASK); } while(0)
176 
177 /** \brief Enable interrupt triggering for pins with PIN_MASK of port with
178  * PORT_BASE.
179  * \param PORT_BASE GPIO Port register offset
180  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
181  */
182 #define GPIO_ENABLE_INTERRUPT(PORT_BASE, PIN_MASK) \
183  do { REG((PORT_BASE) | GPIO_IE) |= (PIN_MASK); } while(0)
184 
185 /** \brief Disable interrupt triggering for pins with PIN_MASK of port with
186  * PORT_BASE.
187  * \param PORT_BASE GPIO Port register offset
188  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
189  */
190 #define GPIO_DISABLE_INTERRUPT(PORT_BASE, PIN_MASK) \
191  do { REG((PORT_BASE) | GPIO_IE) &= ~(PIN_MASK); } while(0)
192 
193 /** \brief Clear interrupt triggering for pins with PIN_MASK of port with
194  * PORT_BASE.
195  * \param PORT_BASE GPIO Port register offset
196  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
197  */
198 #define GPIO_CLEAR_INTERRUPT(PORT_BASE, PIN_MASK) \
199  do { REG((PORT_BASE) | GPIO_IC) = (PIN_MASK); } while(0)
200 
201 /** \brief Configure the pin to be under peripheral control with PIN_MASK of
202  * port with PORT_BASE.
203  * \param PORT_BASE GPIO Port register offset
204  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
205  */
206 #define GPIO_PERIPHERAL_CONTROL(PORT_BASE, PIN_MASK) \
207  do { REG((PORT_BASE) | GPIO_AFSEL) |= (PIN_MASK); } while(0)
208 
209 /** \brief Configure the pin to be software controlled with PIN_MASK of port
210  * with PORT_BASE.
211  * \param PORT_BASE GPIO Port register offset
212  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
213  */
214 #define GPIO_SOFTWARE_CONTROL(PORT_BASE, PIN_MASK) \
215  do { REG((PORT_BASE) | GPIO_AFSEL) &= ~(PIN_MASK); } while(0)
216 
217 /** \brief Set pins with PIN_MASK of port PORT to trigger a power-up interrupt
218  * on rising edge.
219  * \param PORT GPIO Port (not port base address)
220  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
221  */
222 #define GPIO_POWER_UP_ON_RISING(PORT, PIN_MASK) \
223  do { REG(GPIO_PORT_TO_BASE(PORT) | GPIO_P_EDGE_CTRL) &= \
224  ~((PIN_MASK) << ((PORT) << 3)); } while(0)
225 
226 /** \brief Set pins with PIN_MASK of port PORT to trigger a power-up interrupt
227  * on falling edge.
228  * \param PORT GPIO Port (not port base address)
229  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
230  */
231 #define GPIO_POWER_UP_ON_FALLING(PORT, PIN_MASK) \
232  do { REG(GPIO_PORT_TO_BASE(PORT) | GPIO_P_EDGE_CTRL) |= \
233  (PIN_MASK) << ((PORT) << 3); } while(0)
234 
235 /** \brief Enable power-up interrupt triggering for pins with PIN_MASK of port
236  * PORT.
237  * \param PORT GPIO Port (not port base address)
238  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
239  */
240 #define GPIO_ENABLE_POWER_UP_INTERRUPT(PORT, PIN_MASK) \
241  do { REG(GPIO_PORT_TO_BASE(PORT) | GPIO_PI_IEN) |= \
242  (PIN_MASK) << ((PORT) << 3); } while(0)
243 
244 /** \brief Disable power-up interrupt triggering for pins with PIN_MASK of port
245  * PORT.
246  * \param PORT GPIO Port (not port base address)
247  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
248  */
249 #define GPIO_DISABLE_POWER_UP_INTERRUPT(PORT, PIN_MASK) \
250  do { REG(GPIO_PORT_TO_BASE(PORT) | GPIO_PI_IEN) &= \
251  ~((PIN_MASK) << ((PORT) << 3)); } while(0)
252 
253 /** \brief Clear power-up interrupt triggering for pins with PIN_MASK of port
254  * PORT.
255  * \param PORT GPIO Port (not port base address)
256  * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
257  */
258 #define GPIO_CLEAR_POWER_UP_INTERRUPT(PORT, PIN_MASK) \
259  do { REG(GPIO_PORT_TO_BASE(PORT) | GPIO_IRQ_DETECT_ACK) = \
260  (PIN_MASK) << ((PORT) << 3); } while(0)
261 
262 /**
263  * \brief Converts a pin number to a pin mask
264  * \param The pin number in the range [0..7]
265  * \return A pin mask which can be used as the PIN_MASK argument of the macros
266  * in this category
267  */
268 #define GPIO_PIN_MASK(PIN) (1 << (PIN))
269 
270 /**
271  * \brief Converts a port number to the port base address
272  * \param The port number in the range 0 - 3. Likely GPIO_X_NUM.
273  * \return The base address for the registers corresponding to that port
274  * number.
275  */
276 #define GPIO_PORT_TO_BASE(PORT) (GPIO_A_BASE + ((PORT) << 12))
277 /** @} */
278 /*---------------------------------------------------------------------------*/
279 /** \name GPIO Register offset declarations
280  * @{
281  */
282 #define GPIO_DATA 0x00000000 /**< Data register */
283 #define GPIO_DIR 0x00000400 /**< Data direction register */
284 #define GPIO_IS 0x00000404 /**< Interrupt sense */
285 #define GPIO_IBE 0x00000408 /**< Interrupt both edges */
286 #define GPIO_IEV 0x0000040C /**< Interrupt event */
287 #define GPIO_IE 0x00000410 /**< Interrupt mask */
288 #define GPIO_RIS 0x00000414 /**< Interrupt status - raw */
289 #define GPIO_MIS 0x00000418 /**< Interrupt status - masked */
290 #define GPIO_IC 0x0000041C /**< Interrupt clear */
291 #define GPIO_AFSEL 0x00000420 /**< Mode control select */
292 #define GPIO_GPIOLOCK 0x00000520 /**< GPIO commit unlock */
293 #define GPIO_GPIOCR 0x00000524 /**< GPIO commit */
294 #define GPIO_PMUX 0x00000700 /**< PMUX register */
295 #define GPIO_P_EDGE_CTRL 0x00000704 /**< Port edge control */
296 #define GPIO_USB_CTRL 0x00000708 /**< USB input power-up edge ctrl */
297 #define GPIO_PI_IEN 0x00000710 /**< Power-up interrupt enable */
298 #define GPIO_IRQ_DETECT_ACK 0x00000718 /**< IRQ detect ACK - I/O ports */
299 #define GPIO_USB_IRQ_ACK 0x0000071C /**< IRQ detect ACK - USB */
300 #define GPIO_IRQ_DETECT_UNMASK 0x00000720 /**< IRQ detect ACK - masked */
301 /** @} */
302 /*---------------------------------------------------------------------------*/
303 /** \name GPIO_DATA register bit masks
304  * @{
305  */
306 #define GPIO_DATA_DATA 0x000000FF /**< Input and output data */
307 /** @} */
308 /*---------------------------------------------------------------------------*/
309 /** \name GPIO_DIR register bit masks
310  * @{
311  */
312 #define GPIO_DIR_DIR 0x000000FF /**< Pin Input (0) / Output (1) */
313 /** @} */
314 /*---------------------------------------------------------------------------*/
315 /** \name GPIO_IS register bit masks
316  * @{
317  */
318 #define GPIO_IS_IS 0x000000FF /**< Detect Edge (0) / Level (1) */
319 /** @} */
320 /*---------------------------------------------------------------------------*/
321 /** \name GPIO_IBE register bit masks
322  * @{
323  */
324 #define GPIO_IBE_IBE 0x000000FF /**< Both Edges (1) / Single (0) */
325 /** @} */
326 /*---------------------------------------------------------------------------*/
327 /** \name GPIO_IEV register bit masks
328  * @{
329  */
330 #define GPIO_IEV_IEV 0x000000FF /**< Rising (1) / Falling (0) */
331 /** @} */
332 /*---------------------------------------------------------------------------*/
333 /** \name GPIO_IE register bit masks
334  * @{
335  */
336 #define GPIO_IE_IE 0x000000FF /**< Masked (0) / Not Masked (1) */
337 /** @} */
338 /*---------------------------------------------------------------------------*/
339 /** \name GPIO_RIS register bit masks
340  * @{
341  */
342 #define GPIO_RIS_RIS 0x000000FF /**< Raw interrupt status */
343 /** @} */
344 /*---------------------------------------------------------------------------*/
345 /** \name GPIO_MIS register bit masks
346  * @{
347  */
348 #define GPIO_MIS_MIS 0x000000FF /**< Masked interrupt status */
349 /** @} */
350 /*---------------------------------------------------------------------------*/
351 /** \name GPIO_IC register bit masks
352  * @{
353  */
354 #define GPIO_IC_IC 0x000000FF /**< Clear edge detection (1) */
355 /** @} */
356 /*---------------------------------------------------------------------------*/
357 /** \name GPIO_AFSEL register bit masks
358  * @{
359  */
360 #define GPIO_AFSEL_AFSEL 0x000000FF /**< Software (0) / Peripheral (1) */
361 /** @} */
362 /*---------------------------------------------------------------------------*/
363 /** \name GPIO_GPIOLOCK register bit masks
364  * @{
365  */
366 #define GPIO_GPIOLOCK_LOCK 0xFFFFFFFF /**< Locked (1) / Unlocked (0) */
367 /** @} */
368 /*---------------------------------------------------------------------------*/
369 /** \name GPIO_GPIOCR register bit masks
370  * @{
371  */
372 #define GPIO_GPIOCR_CR 0x000000FF /**< Allow alternate function (1) */
373 /** @} */
374 /*---------------------------------------------------------------------------*/
375 /** \name GPIO_PMUX register bit masks
376  * @{
377  */
378 #define GPIO_PMUX_CKOEN 0x00000080 /**< Clock out enable */
379 #define GPIO_PMUX_CKOPIN 0x00000010 /**< Decouple control pin select */
380 #define GPIO_PMUX_DCEN 0x00000008 /**< Decouple control enable */
381 #define GPIO_PMUX_DCPIN 0x00000001 /**< Decouple control pin select */
382 /** @} */
383 /*---------------------------------------------------------------------------*/
384 /** \name GPIO_P_EDGE_CTRL register bit masks.
385  * \brief Rising (0) / Falling (1)
386  * @{
387  */
388 #define GPIO_P_EDGE_CTRL_PDIRC7 0x80000000 /**< Port D bit 7 */
389 #define GPIO_P_EDGE_CTRL_PDIRC6 0x40000000 /**< Port D bit 6 */
390 #define GPIO_P_EDGE_CTRL_PDIRC5 0x20000000 /**< Port D bit 5 */
391 #define GPIO_P_EDGE_CTRL_PDIRC4 0x10000000 /**< Port D bit 4 */
392 #define GPIO_P_EDGE_CTRL_PDIRC3 0x08000000 /**< Port D bit 3 */
393 #define GPIO_P_EDGE_CTRL_PDIRC2 0x04000000 /**< Port D bit 2 */
394 #define GPIO_P_EDGE_CTRL_PDIRC1 0x02000000 /**< Port D bit 1 */
395 #define GPIO_P_EDGE_CTRL_PDIRC0 0x01000000 /**< Port D bit 0 */
396 #define GPIO_P_EDGE_CTRL_PCIRC7 0x00800000 /**< Port C bit 7 */
397 #define GPIO_P_EDGE_CTRL_PCIRC6 0x00400000 /**< Port C bit 6 */
398 #define GPIO_P_EDGE_CTRL_PCIRC5 0x00200000 /**< Port C bit 5 */
399 #define GPIO_P_EDGE_CTRL_PCIRC4 0x00100000 /**< Port C bit 4 */
400 #define GPIO_P_EDGE_CTRL_PCIRC3 0x00080000 /**< Port C bit 3 */
401 #define GPIO_P_EDGE_CTRL_PCIRC2 0x00040000 /**< Port C bit 2 */
402 #define GPIO_P_EDGE_CTRL_PCIRC1 0x00020000 /**< Port C bit 1 */
403 #define GPIO_P_EDGE_CTRL_PCIRC0 0x00010000 /**< Port C bit 0 */
404 #define GPIO_P_EDGE_CTRL_PBIRC7 0x00008000 /**< Port B bit 7 */
405 #define GPIO_P_EDGE_CTRL_PBIRC6 0x00004000 /**< Port B bit 6 */
406 #define GPIO_P_EDGE_CTRL_PBIRC5 0x00002000 /**< Port B bit 5 */
407 #define GPIO_P_EDGE_CTRL_PBIRC4 0x00001000 /**< Port B bit 4 */
408 #define GPIO_P_EDGE_CTRL_PBIRC3 0x00000800 /**< Port B bit 3 */
409 #define GPIO_P_EDGE_CTRL_PBIRC2 0x00000400 /**< Port B bit 2 */
410 #define GPIO_P_EDGE_CTRL_PBIRC1 0x00000200 /**< Port B bit 1 */
411 #define GPIO_P_EDGE_CTRL_PBIRC0 0x00000100 /**< Port B bit 0 */
412 #define GPIO_P_EDGE_CTRL_PAIRC7 0x00000080 /**< Port A bit 7 */
413 #define GPIO_P_EDGE_CTRL_PAIRC6 0x00000040 /**< Port A bit 6 */
414 #define GPIO_P_EDGE_CTRL_PAIRC5 0x00000020 /**< Port A bit 5 */
415 #define GPIO_P_EDGE_CTRL_PAIRC4 0x00000010 /**< Port A bit 4 */
416 #define GPIO_P_EDGE_CTRL_PAIRC3 0x00000008 /**< Port A bit 3 */
417 #define GPIO_P_EDGE_CTRL_PAIRC2 0x00000004 /**< Port A bit 2 */
418 #define GPIO_P_EDGE_CTRL_PAIRC1 0x00000002 /**< Port A bit 1 */
419 #define GPIO_P_EDGE_CTRL_PAIRC0 0x00000001 /**< Port A bit 0 */
420 /** @} */
421 /*---------------------------------------------------------------------------*/
422 /** \name GPIO_USB_CTRL register bit masks
423  * @{
424  */
425 #define GPIO_USB_CTRL_USB_EDGE_CTL 0x00000001 /**< Rising (0) / Falling (1) */
426 /** @} */
427 /*---------------------------------------------------------------------------*/
428 /** \name GPIO_PI_IEN register bit masks.
429  * \brief Enabled (1) / Disabled (0)
430  * @{
431  */
432 #define GPIO_PI_IEN_PDIEN7 0x80000000 /**< Port D bit 7 */
433 #define GPIO_PI_IEN_PDIEN6 0x40000000 /**< Port D bit 6 */
434 #define GPIO_PI_IEN_PDIEN5 0x20000000 /**< Port D bit 5 */
435 #define GPIO_PI_IEN_PDIEN4 0x10000000 /**< Port D bit 4 */
436 #define GPIO_PI_IEN_PDIEN3 0x08000000 /**< Port D bit 3 */
437 #define GPIO_PI_IEN_PDIEN2 0x04000000 /**< Port D bit 2 */
438 #define GPIO_PI_IEN_PDIEN1 0x02000000 /**< Port D bit 1 */
439 #define GPIO_PI_IEN_PDIEN0 0x01000000 /**< Port D bit 0 */
440 #define GPIO_PI_IEN_PCIEN7 0x00800000 /**< Port C bit 7 */
441 #define GPIO_PI_IEN_PCIEN6 0x00400000 /**< Port C bit 6 */
442 #define GPIO_PI_IEN_PCIEN5 0x00200000 /**< Port C bit 5 */
443 #define GPIO_PI_IEN_PCIEN4 0x00100000 /**< Port C bit 4 */
444 #define GPIO_PI_IEN_PCIEN3 0x00080000 /**< Port C bit 3 */
445 #define GPIO_PI_IEN_PCIEN2 0x00040000 /**< Port C bit 2 */
446 #define GPIO_PI_IEN_PCIEN1 0x00020000 /**< Port C bit 1 */
447 #define GPIO_PI_IEN_PCIEN0 0x00010000 /**< Port C bit 0 */
448 #define GPIO_PI_IEN_PBIEN7 0x00008000 /**< Port B bit 7 */
449 #define GPIO_PI_IEN_PBIEN6 0x00004000 /**< Port B bit 6 */
450 #define GPIO_PI_IEN_PBIEN5 0x00002000 /**< Port B bit 5 */
451 #define GPIO_PI_IEN_PBIEN4 0x00001000 /**< Port B bit 4 */
452 #define GPIO_PI_IEN_PBIEN3 0x00000800 /**< Port B bit 3 */
453 #define GPIO_PI_IEN_PBIEN2 0x00000400 /**< Port B bit 2 */
454 #define GPIO_PI_IEN_PBIEN1 0x00000200 /**< Port B bit 1 */
455 #define GPIO_PI_IEN_PBIEN0 0x00000100 /**< Port B bit 0 */
456 #define GPIO_PI_IEN_PAIEN7 0x00000080 /**< Port A bit 7 */
457 #define GPIO_PI_IEN_PAIEN6 0x00000040 /**< Port A bit 6 */
458 #define GPIO_PI_IEN_PAIEN5 0x00000020 /**< Port A bit 5 */
459 #define GPIO_PI_IEN_PAIEN4 0x00000010 /**< Port A bit 4 */
460 #define GPIO_PI_IEN_PAIEN3 0x00000008 /**< Port A bit 3 */
461 #define GPIO_PI_IEN_PAIEN2 0x00000004 /**< Port A bit 2 */
462 #define GPIO_PI_IEN_PAIEN1 0x00000002 /**< Port A bit 1 */
463 #define GPIO_PI_IEN_PAIEN0 0x00000001 /**< Port A bit 0 */
464 /** @} */
465 /*---------------------------------------------------------------------------*/
466 /** \name GPIO_IRQ_DETECT_ACK register bit masks
467  * \brief Detected (1) / Undetected (0)
468  * @{
469  */
470 #define GPIO_IRQ_DETECT_ACK_PDIACK7 0x80000000 /**< Port D bit 7 */
471 #define GPIO_IRQ_DETECT_ACK_PDIACK6 0x40000000 /**< Port D bit 6 */
472 #define GPIO_IRQ_DETECT_ACK_PDIACK5 0x20000000 /**< Port D bit 5 */
473 #define GPIO_IRQ_DETECT_ACK_PDIACK4 0x10000000 /**< Port D bit 4 */
474 #define GPIO_IRQ_DETECT_ACK_PDIACK3 0x08000000 /**< Port D bit 3 */
475 #define GPIO_IRQ_DETECT_ACK_PDIACK2 0x04000000 /**< Port D bit 2 */
476 #define GPIO_IRQ_DETECT_ACK_PDIACK1 0x02000000 /**< Port D bit 1 */
477 #define GPIO_IRQ_DETECT_ACK_PDIACK0 0x01000000 /**< Port D bit 0 */
478 #define GPIO_IRQ_DETECT_ACK_PCIACK7 0x00800000 /**< Port C bit 7 */
479 #define GPIO_IRQ_DETECT_ACK_PCIACK6 0x00400000 /**< Port C bit 6 */
480 #define GPIO_IRQ_DETECT_ACK_PCIACK5 0x00200000 /**< Port C bit 5 */
481 #define GPIO_IRQ_DETECT_ACK_PCIACK4 0x00100000 /**< Port C bit 4 */
482 #define GPIO_IRQ_DETECT_ACK_PCIACK3 0x00080000 /**< Port C bit 3 */
483 #define GPIO_IRQ_DETECT_ACK_PCIACK2 0x00040000 /**< Port C bit 2 */
484 #define GPIO_IRQ_DETECT_ACK_PCIACK1 0x00020000 /**< Port C bit 1 */
485 #define GPIO_IRQ_DETECT_ACK_PCIACK0 0x00010000 /**< Port C bit 0 */
486 #define GPIO_IRQ_DETECT_ACK_PBIACK7 0x00008000 /**< Port B bit 7 */
487 #define GPIO_IRQ_DETECT_ACK_PBIACK6 0x00004000 /**< Port B bit 6 */
488 #define GPIO_IRQ_DETECT_ACK_PBIACK5 0x00002000 /**< Port B bit 5 */
489 #define GPIO_IRQ_DETECT_ACK_PBIACK4 0x00001000 /**< Port B bit 4 */
490 #define GPIO_IRQ_DETECT_ACK_PBIACK3 0x00000800 /**< Port B bit 3 */
491 #define GPIO_IRQ_DETECT_ACK_PBIACK2 0x00000400 /**< Port B bit 2 */
492 #define GPIO_IRQ_DETECT_ACK_PBIACK1 0x00000200 /**< Port B bit 1 */
493 #define GPIO_IRQ_DETECT_ACK_PBIACK0 0x00000100 /**< Port B bit 0 */
494 #define GPIO_IRQ_DETECT_ACK_PAIACK7 0x00000080 /**< Port A bit 7 */
495 #define GPIO_IRQ_DETECT_ACK_PAIACK6 0x00000040 /**< Port A bit 6 */
496 #define GPIO_IRQ_DETECT_ACK_PAIACK5 0x00000020 /**< Port A bit 5 */
497 #define GPIO_IRQ_DETECT_ACK_PAIACK4 0x00000010 /**< Port A bit 4 */
498 #define GPIO_IRQ_DETECT_ACK_PAIACK3 0x00000008 /**< Port A bit 3 */
499 #define GPIO_IRQ_DETECT_ACK_PAIACK2 0x00000004 /**< Port A bit 2 */
500 #define GPIO_IRQ_DETECT_ACK_PAIACK1 0x00000002 /**< Port A bit 1 */
501 #define GPIO_IRQ_DETECT_ACK_PAIACK0 0x00000001 /**< Port A bit 0 */
502 /** @} */
503 /*---------------------------------------------------------------------------*/
504 /** \name GPIO_USB_IRQ_ACK register bit masks
505  * @{
506  */
507 #define GPIO_USB_IRQ_ACK_USBACK 0x00000001 /**< Detected (1) / Not detected (0) */
508 /** @} */
509 /*---------------------------------------------------------------------------*/
510 /** \name GPIO_IRQ_DETECT_UNMASK register bit masks.
511  * \brief Detected (1) / Not detected (0)
512  * @{
513  */
514 #define GPIO_IRQ_DETECT_UNMASK_PDIACK7 0x80000000 /**< Port D bit 7 */
515 #define GPIO_IRQ_DETECT_UNMASK_PDIACK6 0x40000000 /**< Port D bit 6 */
516 #define GPIO_IRQ_DETECT_UNMASK_PDIACK5 0x20000000 /**< Port D bit 5 */
517 #define GPIO_IRQ_DETECT_UNMASK_PDIACK4 0x10000000 /**< Port D bit 4 */
518 #define GPIO_IRQ_DETECT_UNMASK_PDIACK3 0x08000000 /**< Port D bit 3 */
519 #define GPIO_IRQ_DETECT_UNMASK_PDIACK2 0x04000000 /**< Port D bit 2 */
520 #define GPIO_IRQ_DETECT_UNMASK_PDIACK1 0x02000000 /**< Port D bit 1 */
521 #define GPIO_IRQ_DETECT_UNMASK_PDIACK0 0x01000000 /**< Port D bit 0 */
522 #define GPIO_IRQ_DETECT_UNMASK_PCIACK7 0x00800000 /**< Port C bit 7 */
523 #define GPIO_IRQ_DETECT_UNMASK_PCIACK6 0x00400000 /**< Port C bit 6 */
524 #define GPIO_IRQ_DETECT_UNMASK_PCIACK5 0x00200000 /**< Port C bit 5 */
525 #define GPIO_IRQ_DETECT_UNMASK_PCIACK4 0x00100000 /**< Port C bit 4 */
526 #define GPIO_IRQ_DETECT_UNMASK_PCIACK3 0x00080000 /**< Port C bit 3 */
527 #define GPIO_IRQ_DETECT_UNMASK_PCIACK2 0x00040000 /**< Port C bit 2 */
528 #define GPIO_IRQ_DETECT_UNMASK_PCIACK1 0x00020000 /**< Port C bit 1 */
529 #define GPIO_IRQ_DETECT_UNMASK_PCIACK0 0x00010000 /**< Port C bit 0 */
530 #define GPIO_IRQ_DETECT_UNMASK_PBIACK7 0x00008000 /**< Port B bit 7 */
531 #define GPIO_IRQ_DETECT_UNMASK_PBIACK6 0x00004000 /**< Port B bit 6 */
532 #define GPIO_IRQ_DETECT_UNMASK_PBIACK5 0x00002000 /**< Port B bit 5 */
533 #define GPIO_IRQ_DETECT_UNMASK_PBIACK4 0x00001000 /**< Port B bit 4 */
534 #define GPIO_IRQ_DETECT_UNMASK_PBIACK3 0x00000800 /**< Port B bit 3 */
535 #define GPIO_IRQ_DETECT_UNMASK_PBIACK2 0x00000400 /**< Port B bit 2 */
536 #define GPIO_IRQ_DETECT_UNMASK_PBIACK1 0x00000200 /**< Port B bit 1 */
537 #define GPIO_IRQ_DETECT_UNMASK_PBIACK0 0x00000100 /**< Port B bit 0 */
538 #define GPIO_IRQ_DETECT_UNMASK_PAIACK7 0x00000080 /**< Port A bit 7 */
539 #define GPIO_IRQ_DETECT_UNMASK_PAIACK6 0x00000040 /**< Port A bit 6 */
540 #define GPIO_IRQ_DETECT_UNMASK_PAIACK5 0x00000020 /**< Port A bit 5 */
541 #define GPIO_IRQ_DETECT_UNMASK_PAIACK4 0x00000010 /**< Port A bit 4 */
542 #define GPIO_IRQ_DETECT_UNMASK_PAIACK3 0x00000008 /**< Port A bit 3 */
543 #define GPIO_IRQ_DETECT_UNMASK_PAIACK2 0x00000004 /**< Port A bit 2 */
544 #define GPIO_IRQ_DETECT_UNMASK_PAIACK1 0x00000002 /**< Port A bit 1 */
545 #define GPIO_IRQ_DETECT_UNMASK_PAIACK0 0x00000001 /**< Port A bit 0 */
546 /** @} */
547 /*---------------------------------------------------------------------------*/
548 /** \brief Initialise the GPIO module */
549 void gpio_init();
550 
551 /**
552  * \brief Register GPIO callback
553  * \param f Pointer to a function to be called when \a pin of \a port
554  * generates an interrupt
555  * \param port Associate \a f with this port. \e port must be specified with
556  * its numeric representation (Port A:0, B:1 etc). Defines for these
557  * numeric representations are GPIO_x_NUM
558  * \param pin Associate \a f with this pin, which is specified by number
559  * (0, 1, ..., 7)
560  */
561 void gpio_register_callback(gpio_callback_t f, uint8_t port, uint8_t pin);
562 
563 #endif /* GPIO_H_ */
564 
565 /**
566  * @}
567  * @}
568  */
void gpio_init()
Initialise the GPIO module.
Definition: gpio.c:147
Header file with register manipulation macro definitions.
void gpio_register_callback(gpio_callback_t f, uint8_t port, uint8_t pin)
Register GPIO callback.
Definition: gpio.c:56
void(* gpio_callback_t)(uint8_t port, uint8_t pin)
Type definition for callbacks invoked by the GPIO ISRs.
Definition: gpio.h:65