GPIO.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2017, Texas Instruments Incorporated
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  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
220 #ifndef ti_drivers_GPIO__include
221 #define ti_drivers_GPIO__include
222 
223 #ifdef __cplusplus
224 extern "C" {
225 #endif
226 
227 #include <stdint.h>
228 
247 #define GPIO_STATUS_RESERVED (-32)
248 
255 #define GPIO_STATUS_SUCCESS (0)
256 
263 #define GPIO_STATUS_ERROR (-1)
264 
275 typedef uint32_t GPIO_PinConfig;
276 
281 #define GPIO_CFG_IO_MASK 0x00ff0000
282 #define GPIO_CFG_IO_LSB 16
283 #define GPIO_CFG_OUT_TYPE_MASK 0x00060000
284 #define GPIO_CFG_OUT_TYPE_LSB 17
285 #define GPIO_CFG_IN_TYPE_MASK 0x00060000
286 #define GPIO_CFG_IN_TYPE_LSB 17
287 #define GPIO_CFG_OUT_STRENGTH_MASK 0x00f00000
288 #define GPIO_CFG_OUT_STRENGTH_LSB 20
289 #define GPIO_CFG_INT_MASK 0x07000000
290 #define GPIO_CFG_INT_LSB 24
291 #define GPIO_CFG_OUT_BIT 19
292 
301 #define GPIO_CFG_OUTPUT (((uint32_t) 0) << GPIO_CFG_IO_LSB)
302 #define GPIO_CFG_OUT_STD (((uint32_t) 0) << GPIO_CFG_IO_LSB)
303 #define GPIO_CFG_OUT_OD_NOPULL (((uint32_t) 2) << GPIO_CFG_IO_LSB)
304 #define GPIO_CFG_OUT_OD_PU (((uint32_t) 4) << GPIO_CFG_IO_LSB)
305 #define GPIO_CFG_OUT_OD_PD (((uint32_t) 6) << GPIO_CFG_IO_LSB)
307 #define GPIO_CFG_OUT_STR_LOW (((uint32_t) 0) << GPIO_CFG_OUT_STRENGTH_LSB)
308 #define GPIO_CFG_OUT_STR_MED (((uint32_t) 1) << GPIO_CFG_OUT_STRENGTH_LSB)
309 #define GPIO_CFG_OUT_STR_HIGH (((uint32_t) 2) << GPIO_CFG_OUT_STRENGTH_LSB)
311 #define GPIO_CFG_OUT_HIGH (((uint32_t) 1) << GPIO_CFG_OUT_BIT)
312 #define GPIO_CFG_OUT_LOW (((uint32_t) 0) << GPIO_CFG_OUT_BIT)
318 #define GPIO_CFG_INPUT (((uint32_t) 1) << GPIO_CFG_IO_LSB)
319 #define GPIO_CFG_IN_NOPULL (((uint32_t) 1) << GPIO_CFG_IO_LSB)
320 #define GPIO_CFG_IN_PU (((uint32_t) 3) << GPIO_CFG_IO_LSB)
321 #define GPIO_CFG_IN_PD (((uint32_t) 5) << GPIO_CFG_IO_LSB)
327 #define GPIO_CFG_IN_INT_NONE (((uint32_t) 0) << GPIO_CFG_INT_LSB)
328 #define GPIO_CFG_IN_INT_FALLING (((uint32_t) 1) << GPIO_CFG_INT_LSB)
329 #define GPIO_CFG_IN_INT_RISING (((uint32_t) 2) << GPIO_CFG_INT_LSB)
330 #define GPIO_CFG_IN_INT_BOTH_EDGES (((uint32_t) 3) << GPIO_CFG_INT_LSB)
331 #define GPIO_CFG_IN_INT_LOW (((uint32_t) 4) << GPIO_CFG_INT_LSB)
332 #define GPIO_CFG_IN_INT_HIGH (((uint32_t) 5) << GPIO_CFG_INT_LSB)
343 #define GPIO_CFG_IN_INT_ONLY (((uint32_t) 1) << 27)
349 #define GPIO_DO_NOT_CONFIG 0x40000000
363 typedef void (*GPIO_CallbackFxn)(uint_least8_t index);
364 
375 extern void GPIO_clearInt(uint_least8_t index);
376 
384 extern void GPIO_disableInt(uint_least8_t index);
385 
399 extern void GPIO_enableInt(uint_least8_t index);
400 
412 extern void GPIO_getConfig(uint_least8_t index, GPIO_PinConfig *pinConfig);
413 
424 extern void GPIO_init();
425 
436 extern uint_fast8_t GPIO_read(uint_least8_t index);
437 
459 extern void GPIO_setCallback(uint_least8_t index, GPIO_CallbackFxn callback);
460 
474 extern int_fast16_t GPIO_setConfig(uint_least8_t index,
475  GPIO_PinConfig pinConfig);
476 
482 extern void GPIO_toggle(uint_least8_t index);
483 
490 extern void GPIO_write(uint_least8_t index, unsigned int value);
491 
492 #ifdef __cplusplus
493 }
494 #endif
495 
496 #endif /* ti_drivers_GPIO__include */
void GPIO_write(uint_least8_t index, unsigned int value)
Writes the value to a GPIO pin.
void GPIO_clearInt(uint_least8_t index)
Clear a GPIO pin interrupt flag.
void GPIO_toggle(uint_least8_t index)
Toggles the current state of a GPIO.
void GPIO_enableInt(uint_least8_t index)
Enable a GPIO pin interrupt.
uint32_t GPIO_PinConfig
GPIO pin configuration settings.
Definition: GPIO.h:275
void GPIO_getConfig(uint_least8_t index, GPIO_PinConfig *pinConfig)
Get the current configuration for a gpio pin.
void GPIO_init()
Initializes the GPIO module.
int_fast16_t GPIO_setConfig(uint_least8_t index, GPIO_PinConfig pinConfig)
Configure the gpio pin.
void GPIO_setCallback(uint_least8_t index, GPIO_CallbackFxn callback)
Bind a callback function to a GPIO pin interrupt.
uint_fast8_t GPIO_read(uint_least8_t index)
Reads the value of a GPIO pin.
void GPIO_disableInt(uint_least8_t index)
Disable a GPIO pin interrupt.
void(* GPIO_CallbackFxn)(uint_least8_t index)
GPIO callback function type.
Definition: GPIO.h:363
Copyright 2017, Texas Instruments Incorporated