CC26xx Driver Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gpio.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: gpio.h
3 * Revised: 2015-01-14 12:12:44 +0100 (on, 14 jan 2015)
4 * Revision: 42373
5 *
6 * Description: Defines and prototypes for the GPIO.
7 *
8 * Copyright (c) 2015, Texas Instruments Incorporated
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * 1) Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 *
17 * 2) Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38 
39 //****************************************************************************
40 //
43 //
44 //****************************************************************************
45 
46 #ifndef __GPIO_H__
47 #define __GPIO_H__
48 
49 //*****************************************************************************
50 //
51 // If building with a C++ compiler, make all of the definitions in this header
52 // have a C binding.
53 //
54 //*****************************************************************************
55 #ifdef __cplusplus
56 extern "C"
57 {
58 #endif
59 
60 #include <stdbool.h>
61 #include <stdint.h>
62 #include <inc/hw_types.h>
63 #include <inc/hw_memmap.h>
64 #include <inc/hw_gpio.h>
65 #include <driverlib/debug.h>
66 
67 //*****************************************************************************
68 //
69 // Number of GPIO pins
70 //
71 //*****************************************************************************
72 #define NUM_GPIO_PINS 32
73 
74 //*****************************************************************************
75 //
76 // The following values define the bit field for the GPIO Pins in a port.
77 //
78 //*****************************************************************************
79 #define GPIO_PIN_0 0x00000001 // GPIO pin 0
80 #define GPIO_PIN_1 0x00000002 // GPIO pin 1
81 #define GPIO_PIN_2 0x00000004 // GPIO pin 2
82 #define GPIO_PIN_3 0x00000008 // GPIO pin 3
83 #define GPIO_PIN_4 0x00000010 // GPIO pin 4
84 #define GPIO_PIN_5 0x00000020 // GPIO pin 5
85 #define GPIO_PIN_6 0x00000040 // GPIO pin 6
86 #define GPIO_PIN_7 0x00000080 // GPIO pin 7
87 #define GPIO_PIN_8 0x00000100 // GPIO pin 8
88 #define GPIO_PIN_9 0x00000200 // GPIO pin 9
89 #define GPIO_PIN_10 0x00000400 // GPIO pin 10
90 #define GPIO_PIN_11 0x00000800 // GPIO pin 11
91 #define GPIO_PIN_12 0x00001000 // GPIO pin 12
92 #define GPIO_PIN_13 0x00002000 // GPIO pin 13
93 #define GPIO_PIN_14 0x00004000 // GPIO pin 14
94 #define GPIO_PIN_15 0x00008000 // GPIO pin 15
95 #define GPIO_PIN_16 0x00010000 // GPIO pin 16
96 #define GPIO_PIN_17 0x00020000 // GPIO pin 17
97 #define GPIO_PIN_18 0x00040000 // GPIO pin 18
98 #define GPIO_PIN_19 0x00080000 // GPIO pin 19
99 #define GPIO_PIN_20 0x00100000 // GPIO pin 20
100 #define GPIO_PIN_21 0x00200000 // GPIO pin 21
101 #define GPIO_PIN_22 0x00400000 // GPIO pin 22
102 #define GPIO_PIN_23 0x00800000 // GPIO pin 23
103 #define GPIO_PIN_24 0x01000000 // GPIO pin 24
104 #define GPIO_PIN_25 0x02000000 // GPIO pin 25
105 #define GPIO_PIN_26 0x04000000 // GPIO pin 26
106 #define GPIO_PIN_27 0x08000000 // GPIO pin 27
107 #define GPIO_PIN_28 0x10000000 // GPIO pin 28
108 #define GPIO_PIN_29 0x20000000 // GPIO pin 29
109 #define GPIO_PIN_30 0x40000000 // GPIO pin 30
110 #define GPIO_PIN_31 0x80000000 // GPIO pin 31
111 #define GPIO_PIN_UNUSED 0x00000000 // GPIO pin unused
112 #define GPIO_PIN_MASK 0xFFFFFFFF // GPIO pin mask
113 
114 //*****************************************************************************
115 //
116 // Values that can be passed to GPIODirModeSet as the ui32PinIO parameter, and
117 // returned from GPIODirModeGet.
118 //
119 //*****************************************************************************
120 #define GPIO_DIR_MODE_IN 0x00000000 // Pin is a GPIO input
121 #define GPIO_DIR_MODE_OUT 0x00000001 // Pin is a GPIO output
122 
123 //*****************************************************************************
124 //
125 // API Functions and prototypes
126 //
127 //*****************************************************************************
128 
129 //****************************************************************************
130 //
146 //
147 //****************************************************************************
148 __STATIC_INLINE void
149 GPIODirModeSet(uint32_t ui32Pins, uint32_t ui32Dir)
150 {
151  uint32_t ui32Reg;
152 
153  //
154  // Check the arguments.
155  //
156  ASSERT(ui32Pins & GPIO_PIN_MASK);
157  ASSERT((ui32Dir == GPIO_DIR_MODE_IN) ||
158  (ui32Dir == GPIO_DIR_MODE_OUT));
159 
160  //
161  // Update the output pin enable bit.
162  //
163  ui32Reg = HWREG(GPIO_BASE + GPIO_O_DOE31_0);
164  if(ui32Dir == GPIO_DIR_MODE_IN)
165  {
166  ui32Reg &= ~ui32Pins;
167  }
168  else
169  {
170  ui32Reg |= ui32Pins;
171  }
172  HWREG(GPIO_BASE + GPIO_O_DOE31_0) = ui32Reg;
173 }
174 
175 //*****************************************************************************
176 //
191 //
192 //*****************************************************************************
193 __STATIC_INLINE uint32_t
194 GPIODirModeGet(uint32_t ui32Pin)
195 {
196  uint32_t ui32Reg;
197 
198  //
199  // Check the arguments.
200  //
201  ASSERT((ui32Pin >= GPIO_PIN_0) && (ui32Pin <= GPIO_PIN_31));
202 
203  //
204  // Return the pin direction.
205  //
206  ui32Reg = HWREG(GPIO_BASE + GPIO_O_DOE31_0);
207  return((ui32Reg & ui32Pin) ? GPIO_DIR_MODE_OUT : GPIO_DIR_MODE_IN);
208 }
209 
210 //****************************************************************************
211 //
227 //
228 //****************************************************************************
229 __STATIC_INLINE void
230 GPIOPinWrite(uint32_t ui32Pins, uint32_t ui32Val)
231 {
232  uint32_t ui32Addr;
233 
234  //
235  // Check the arguments.
236  //
237  ASSERT(ui32Pins & GPIO_PIN_MASK);
238 
239  //
240  // Write to the port.
241  //
242  if(ui32Val)
243  {
244  ui32Addr = GPIO_BASE + GPIO_O_DOUTSET31_0;
245  }
246  else
247  {
248  ui32Addr = GPIO_BASE + GPIO_O_DOUTCLR31_0;
249  }
250  HWREG(ui32Addr) = ui32Pins;
251 }
252 
253 //****************************************************************************
254 //
264 //
265 //****************************************************************************
266 __STATIC_INLINE uint32_t
267 GPIOPinRead(uint32_t ui32Pins)
268 {
269  //
270  // Check the arguments.
271  //
272  ASSERT((ui32Pins >= GPIO_PIN_0) && (ui32Pins <= GPIO_PIN_31));
273 
274  //
275  // Return the value of the pin(s).
276  //
277  return (HWREG(GPIO_BASE + GPIO_O_DIN31_0) & ui32Pins);
278 }
279 
280 //****************************************************************************
281 //
291 //
292 //****************************************************************************
293 __STATIC_INLINE void
294 GPIOPinClear(uint32_t ui32Pins)
295 {
296  //
297  // Check the arguments.
298  //
299  ASSERT(ui32Pins & GPIO_PIN_MASK);
300 
301  //
302  // Clear the pin(s).
303  //
304  HWREG(GPIO_BASE + GPIO_O_DOUTCLR31_0) = ui32Pins;
305 }
306 
307 //****************************************************************************
308 //
318 //
319 //****************************************************************************
320 __STATIC_INLINE void
321 GPIOPinToggle(uint32_t ui32Pins)
322 {
323  //
324  // Check the arguments.
325  //
326  ASSERT(ui32Pins & GPIO_PIN_MASK);
327 
328  //
329  // Toggle the pin.
330  //
331  HWREG(GPIO_BASE + GPIO_O_DOUTTGL31_0) = ui32Pins;
332 }
333 
334 //****************************************************************************
335 //
345 //
346 //****************************************************************************
347 __STATIC_INLINE uint32_t
348 GPIOEventGet(uint32_t ui32Pin)
349 {
350  //
351  // Check the arguments.
352  //
353  ASSERT(ui32Pin & GPIO_PIN_MASK);
354 
355  //
356  // Return the event status.
357  //
358  return ((HWREG(GPIO_BASE + GPIO_O_EVFLAGS31_0) & ui32Pin) ? 1 : 0);
359 }
360 
361 //****************************************************************************
362 //
372 //
373 //****************************************************************************
374 __STATIC_INLINE void
375 GPIOEventClear(uint32_t ui32Pins)
376 {
377  //
378  // Check the arguments.
379  //
380  ASSERT(ui32Pins & GPIO_PIN_MASK);
381 
382  //
383  // Toggle the pin.
384  //
385  HWREG(GPIO_BASE + GPIO_O_EVFLAGS31_0) = ui32Pins;
386 }
387 
388 //*****************************************************************************
389 //
390 // Mark the end of the C bindings section for C++ compilers.
391 //
392 //*****************************************************************************
393 #ifdef __cplusplus
394 }
395 #endif
396 
397 #endif // __GPIO_H__
398 
399 //****************************************************************************
400 //
403 //
404 //****************************************************************************
__STATIC_INLINE void GPIOPinToggle(uint32_t ui32Pins)
Toggle specific pin(s).
Definition: gpio.h:321
__STATIC_INLINE uint32_t GPIOEventGet(uint32_t ui32Pin)
Get the event status of a specific pin.
Definition: gpio.h:348
__STATIC_INLINE uint32_t GPIODirModeGet(uint32_t ui32Pin)
Gets the direction of a pin.
Definition: gpio.h:194
#define ASSERT(expr)
Definition: debug.h:65
__STATIC_INLINE uint32_t GPIOPinRead(uint32_t ui32Pins)
Read the value of specific pin(s).
Definition: gpio.h:267
__STATIC_INLINE void GPIODirModeSet(uint32_t ui32Pins, uint32_t ui32Dir)
Sets the direction of the specified pin(s).
Definition: gpio.h:149
#define GPIO_DIR_MODE_OUT
Definition: gpio.h:121
#define GPIO_PIN_31
Definition: gpio.h:110
__STATIC_INLINE void GPIOEventClear(uint32_t ui32Pins)
Clear an IO event on a pin.
Definition: gpio.h:375
#define GPIO_PIN_MASK
Definition: gpio.h:112
__STATIC_INLINE void GPIOPinClear(uint32_t ui32Pins)
Clear specific pin(s).
Definition: gpio.h:294
#define GPIO_DIR_MODE_IN
Definition: gpio.h:120
__STATIC_INLINE void GPIOPinWrite(uint32_t ui32Pins, uint32_t ui32Val)
Write to pin(s).
Definition: gpio.h:230
#define GPIO_PIN_0
Definition: gpio.h:79