CC26xx Driver Library
gpio.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: gpio.h
3 * Revised: 2015-11-19 16:24:40 +0100 (Thu, 19 Nov 2015)
4 * Revision: 45170
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 //
45 //
46 //*****************************************************************************
47 
48 #ifndef __GPIO_H__
49 #define __GPIO_H__
50 
51 //*****************************************************************************
52 //
53 // If building with a C++ compiler, make all of the definitions in this header
54 // have a C binding.
55 //
56 //*****************************************************************************
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61 
62 #include <stdint.h>
63 #include <inc/hw_types.h>
64 #include <inc/hw_memmap.h>
65 #include <inc/hw_gpio.h>
66 #include <driverlib/debug.h>
67 
68 //*****************************************************************************
69 //
70 // Check for legal range of variable dioNumber
71 //
72 //*****************************************************************************
73 #ifdef DRIVERLIB_DEBUG
74 static bool
75 dioNumberLegal( uint32_t dioNumber )
76 {
77  return ( dioNumber < (( HWREG( FCFG_BASE + FCFG1_O_IOCONF ) &
80 }
81 #endif
82 
83 //*****************************************************************************
84 //
85 // The following values define the bit field for the GPIO DIOs.
86 //
87 //*****************************************************************************
88 #define GPIO_DIO_0_MASK 0x00000001 // GPIO DIO 0 mask
89 #define GPIO_DIO_1_MASK 0x00000002 // GPIO DIO 1 mask
90 #define GPIO_DIO_2_MASK 0x00000004 // GPIO DIO 2 mask
91 #define GPIO_DIO_3_MASK 0x00000008 // GPIO DIO 3 mask
92 #define GPIO_DIO_4_MASK 0x00000010 // GPIO DIO 4 mask
93 #define GPIO_DIO_5_MASK 0x00000020 // GPIO DIO 5 mask
94 #define GPIO_DIO_6_MASK 0x00000040 // GPIO DIO 6 mask
95 #define GPIO_DIO_7_MASK 0x00000080 // GPIO DIO 7 mask
96 #define GPIO_DIO_8_MASK 0x00000100 // GPIO DIO 8 mask
97 #define GPIO_DIO_9_MASK 0x00000200 // GPIO DIO 9 mask
98 #define GPIO_DIO_10_MASK 0x00000400 // GPIO DIO 10 mask
99 #define GPIO_DIO_11_MASK 0x00000800 // GPIO DIO 11 mask
100 #define GPIO_DIO_12_MASK 0x00001000 // GPIO DIO 12 mask
101 #define GPIO_DIO_13_MASK 0x00002000 // GPIO DIO 13 mask
102 #define GPIO_DIO_14_MASK 0x00004000 // GPIO DIO 14 mask
103 #define GPIO_DIO_15_MASK 0x00008000 // GPIO DIO 15 mask
104 #define GPIO_DIO_16_MASK 0x00010000 // GPIO DIO 16 mask
105 #define GPIO_DIO_17_MASK 0x00020000 // GPIO DIO 17 mask
106 #define GPIO_DIO_18_MASK 0x00040000 // GPIO DIO 18 mask
107 #define GPIO_DIO_19_MASK 0x00080000 // GPIO DIO 19 mask
108 #define GPIO_DIO_20_MASK 0x00100000 // GPIO DIO 20 mask
109 #define GPIO_DIO_21_MASK 0x00200000 // GPIO DIO 21 mask
110 #define GPIO_DIO_22_MASK 0x00400000 // GPIO DIO 22 mask
111 #define GPIO_DIO_23_MASK 0x00800000 // GPIO DIO 23 mask
112 #define GPIO_DIO_24_MASK 0x01000000 // GPIO DIO 24 mask
113 #define GPIO_DIO_25_MASK 0x02000000 // GPIO DIO 25 mask
114 #define GPIO_DIO_26_MASK 0x04000000 // GPIO DIO 26 mask
115 #define GPIO_DIO_27_MASK 0x08000000 // GPIO DIO 27 mask
116 #define GPIO_DIO_28_MASK 0x10000000 // GPIO DIO 28 mask
117 #define GPIO_DIO_29_MASK 0x20000000 // GPIO DIO 29 mask
118 #define GPIO_DIO_30_MASK 0x40000000 // GPIO DIO 30 mask
119 #define GPIO_DIO_31_MASK 0x80000000 // GPIO DIO 31 mask
120 #define GPIO_DIO_ALL_MASK 0xFFFFFFFF // GPIO all DIOs mask
121 
122 //*****************************************************************************
123 //
124 // Define constants that shall be passed as the outputEnableValue parameter to
125 // GPIO_setOutputEnableDio() and will be returned from the function
126 // GPIO_getOutputEnableDio().
127 //
128 //*****************************************************************************
129 #define GPIO_OUTPUT_DISABLE 0x00000000 // DIO output is disabled
130 #define GPIO_OUTPUT_ENABLE 0x00000001 // DIO output is enabled
131 
132 //*****************************************************************************
133 //
134 // API Functions and prototypes
135 //
136 //*****************************************************************************
137 
138 //*****************************************************************************
139 //
147 //
148 //*****************************************************************************
149 __STATIC_INLINE uint32_t
150 GPIO_readDio( uint32_t dioNumber )
151 {
152  //
153  // Check the arguments.
154  //
155  ASSERT( dioNumberLegal( dioNumber ));
156 
157  //
158  // Return the input value from the specified DIO.
159  //
160  return (( HWREG( GPIO_BASE + GPIO_O_DIN31_0 ) >> dioNumber ) & 1 );
161 }
162 
163 //*****************************************************************************
164 //
181 //
182 //*****************************************************************************
183 __STATIC_INLINE uint32_t
184 GPIO_readMultiDio( uint32_t dioMask )
185 {
186  //
187  // Check the arguments.
188  //
189  ASSERT( dioMask & GPIO_DIO_ALL_MASK );
190 
191  //
192  // Return the input value from the specified DIOs.
193  //
194  return ( HWREG( GPIO_BASE + GPIO_O_DIN31_0 ) & dioMask );
195 }
196 
197 //*****************************************************************************
198 //
209 //
210 //*****************************************************************************
211 __STATIC_INLINE void
212 GPIO_writeDio( uint32_t dioNumber, uint32_t value )
213 {
214  //
215  // Check the arguments.
216  //
217  ASSERT( dioNumberLegal( dioNumber ));
218  ASSERT(( value == 0 ) || ( value == 1 ));
219 
220  //
221  // Write 0 or 1 to the byte indexed DOUT map
222  //
223  HWREGB( GPIO_BASE + dioNumber ) = value;
224 }
225 
226 //*****************************************************************************
227 //
245 //
246 //*****************************************************************************
247 __STATIC_INLINE void
248 GPIO_writeMultiDio( uint32_t dioMask, uint32_t bitVectoredValue )
249 {
250  //
251  // Check the arguments.
252  //
253  ASSERT( dioMask & GPIO_DIO_ALL_MASK );
254 
255  HWREG( GPIO_BASE + GPIO_O_DOUT31_0 ) =
256  ( HWREG( GPIO_BASE + GPIO_O_DOUT31_0 ) & ~dioMask ) |
257  ( bitVectoredValue & dioMask );
258 }
259 
260 //*****************************************************************************
261 //
269 //
270 //*****************************************************************************
271 __STATIC_INLINE void
272 GPIO_setDio( uint32_t dioNumber )
273 {
274  //
275  // Check the arguments.
276  //
277  ASSERT( dioNumberLegal( dioNumber ));
278 
279  //
280  // Set the specified DIO.
281  //
282  HWREG( GPIO_BASE + GPIO_O_DOUTSET31_0 ) = ( 1 << dioNumber );
283 }
284 
285 //*****************************************************************************
286 //
298 //
299 //*****************************************************************************
300 __STATIC_INLINE void
301 GPIO_setMultiDio( uint32_t dioMask )
302 {
303  //
304  // Check the arguments.
305  //
306  ASSERT( dioMask & GPIO_DIO_ALL_MASK );
307 
308  //
309  // Set the DIOs.
310  //
311  HWREG( GPIO_BASE + GPIO_O_DOUTSET31_0 ) = dioMask;
312 }
313 
314 //*****************************************************************************
315 //
323 //
324 //*****************************************************************************
325 __STATIC_INLINE void
326 GPIO_clearDio( uint32_t dioNumber )
327 {
328  //
329  // Check the arguments.
330  //
331  ASSERT( dioNumberLegal( dioNumber ));
332 
333  //
334  // Clear the specified DIO.
335  //
336  HWREG( GPIO_BASE + GPIO_O_DOUTCLR31_0 ) = ( 1 << dioNumber );
337 }
338 
339 //*****************************************************************************
340 //
352 //
353 //*****************************************************************************
354 __STATIC_INLINE void
355 GPIO_clearMultiDio( uint32_t dioMask )
356 {
357  //
358  // Check the arguments.
359  //
360  ASSERT( dioMask & GPIO_DIO_ALL_MASK );
361 
362  //
363  // Clear the DIOs.
364  //
365  HWREG( GPIO_BASE + GPIO_O_DOUTCLR31_0 ) = dioMask;
366 }
367 
368 //*****************************************************************************
369 //
377 //
378 //*****************************************************************************
379 __STATIC_INLINE void
380 GPIO_toggleDio( uint32_t dioNumber )
381 {
382  //
383  // Check the arguments.
384  //
385  ASSERT( dioNumberLegal( dioNumber ));
386 
387  //
388  // Toggle the specified DIO.
389  //
390  HWREG( GPIO_BASE + GPIO_O_DOUTTGL31_0 ) = ( 1 << dioNumber );
391 }
392 
393 //*****************************************************************************
394 //
406 //
407 //*****************************************************************************
408 __STATIC_INLINE void
409 GPIO_toggleMultiDio( uint32_t dioMask )
410 {
411  //
412  // Check the arguments.
413  //
414  ASSERT( dioMask & GPIO_DIO_ALL_MASK );
415 
416  //
417  // Toggle the DIOs.
418  //
419  HWREG( GPIO_BASE + GPIO_O_DOUTTGL31_0 ) = dioMask;
420 }
421 
422 //*****************************************************************************
423 //
436 //
437 //*****************************************************************************
438 __STATIC_INLINE uint32_t
439 GPIO_getOutputEnableDio( uint32_t dioNumber )
440 {
441  //
442  // Check the arguments.
443  //
444  ASSERT( dioNumberLegal( dioNumber ));
445 
446  //
447  // Return the output enable status for the specified DIO.
448  //
449  return (( HWREG( GPIO_BASE + GPIO_O_DOE31_0 ) >> dioNumber ) & 1 );
450 }
451 
452 //*****************************************************************************
453 //
470 //
471 //*****************************************************************************
472 __STATIC_INLINE uint32_t
473 GPIO_getOutputEnableMultiDio( uint32_t dioMask )
474 {
475  //
476  // Check the arguments.
477  //
478  ASSERT( dioMask & GPIO_DIO_ALL_MASK );
479 
480  //
481  // Return the output enable value for the specified DIOs.
482  //
483  return ( HWREG( GPIO_BASE + GPIO_O_DOE31_0 ) & dioMask );
484 }
485 
486 //*****************************************************************************
487 //
501 //
502 //*****************************************************************************
503 __STATIC_INLINE void
504 GPIO_setOutputEnableDio( uint32_t dioNumber, uint32_t outputEnableValue )
505 {
506  //
507  // Check the arguments.
508  //
509  ASSERT( dioNumberLegal( dioNumber ));
510  ASSERT(( outputEnableValue == GPIO_OUTPUT_DISABLE ) ||
511  ( outputEnableValue == GPIO_OUTPUT_ENABLE ) );
512 
513  //
514  // Update the output enable bit for the specified DIO.
515  //
516  HWREGBITW( GPIO_BASE + GPIO_O_DOE31_0, dioNumber ) = outputEnableValue;
517 }
518 
519 //*****************************************************************************
520 //
541 //
542 //*****************************************************************************
543 __STATIC_INLINE void
544 GPIO_setOutputEnableMultiDio( uint32_t dioMask, uint32_t bitVectoredOutputEnable )
545 {
546  //
547  // Check the arguments.
548  //
549  ASSERT( dioMask & GPIO_DIO_ALL_MASK );
550 
551  HWREG( GPIO_BASE + GPIO_O_DOE31_0 ) =
552  ( HWREG( GPIO_BASE + GPIO_O_DOE31_0 ) & ~dioMask ) |
553  ( bitVectoredOutputEnable & dioMask );
554 }
555 
556 //*****************************************************************************
557 //
567 //
568 //*****************************************************************************
569 __STATIC_INLINE uint32_t
570 GPIO_getEventDio( uint32_t dioNumber )
571 {
572  //
573  // Check the arguments.
574  //
575  ASSERT( dioNumberLegal( dioNumber ));
576 
577  //
578  // Return the event status for the specified DIO.
579  //
580  return (( HWREG( GPIO_BASE + GPIO_O_EVFLAGS31_0 ) >> dioNumber ) & 1 );
581 }
582 
583 //*****************************************************************************
584 //
602 //
603 //*****************************************************************************
604 __STATIC_INLINE uint32_t
605 GPIO_getEventMultiDio( uint32_t dioMask )
606 {
607  //
608  // Check the arguments.
609  //
610  ASSERT( dioMask & GPIO_DIO_ALL_MASK );
611 
612  //
613  // Return the event status for the specified DIO.
614  //
615  return ( HWREG( GPIO_BASE + GPIO_O_EVFLAGS31_0 ) & dioMask );
616 }
617 
618 //*****************************************************************************
619 //
627 //
628 //*****************************************************************************
629 __STATIC_INLINE void
630 GPIO_clearEventDio( uint32_t dioNumber )
631 {
632  //
633  // Check the arguments.
634  //
635  ASSERT( dioNumberLegal( dioNumber ));
636 
637  //
638  // Clear the event status for the specified DIO.
639  //
640  HWREG( GPIO_BASE + GPIO_O_EVFLAGS31_0 ) = ( 1 << dioNumber );
641 }
642 
643 //*****************************************************************************
644 //
657 //
658 //*****************************************************************************
659 __STATIC_INLINE void
660 GPIO_clearEventMultiDio( uint32_t dioMask )
661 {
662  //
663  // Check the arguments.
664  //
665  ASSERT( dioMask & GPIO_DIO_ALL_MASK );
666 
667  //
668  // Clear the event status for the specified DIOs.
669  //
670  HWREG( GPIO_BASE + GPIO_O_EVFLAGS31_0 ) = dioMask;
671 }
672 
673 //*****************************************************************************
674 //
675 // Mark the end of the C bindings section for C++ compilers.
676 //
677 //*****************************************************************************
678 #ifdef __cplusplus
679 }
680 #endif
681 
682 #endif // __GPIO_H__
683 
684 //*****************************************************************************
685 //
689 //
690 //*****************************************************************************
static uint32_t GPIO_getEventDio(uint32_t dioNumber)
Gets the event status of a specific DIO.
Definition: gpio.h:570
static void GPIO_setOutputEnableMultiDio(uint32_t dioMask, uint32_t bitVectoredOutputEnable)
Configures the output enable setting for all specified DIOs.
Definition: gpio.h:544
static uint32_t GPIO_getOutputEnableDio(uint32_t dioNumber)
Gets the output enable status of a specific DIO.
Definition: gpio.h:439
static void GPIO_clearEventDio(uint32_t dioNumber)
Clears the IO event status of a specific DIO.
Definition: gpio.h:630
#define GPIO_DIO_ALL_MASK
Definition: gpio.h:120
#define GPIO_OUTPUT_ENABLE
Definition: gpio.h:130
static void GPIO_clearEventMultiDio(uint32_t dioMask)
Clears the IO event status on the specified DIOs.
Definition: gpio.h:660
static void GPIO_clearMultiDio(uint32_t dioMask)
Clears the specified DIOs to 0 (low).
Definition: gpio.h:355
static void GPIO_clearDio(uint32_t dioNumber)
Clears a specific DIO to 0 (low).
Definition: gpio.h:326
static void GPIO_writeDio(uint32_t dioNumber, uint32_t value)
Writes a value to a specific DIO.
Definition: gpio.h:212
static void GPIO_setMultiDio(uint32_t dioMask)
Sets the specified DIOs to 1 (high).
Definition: gpio.h:301
static void GPIO_toggleMultiDio(uint32_t dioMask)
Toggles the specified DIOs.
Definition: gpio.h:409
static uint32_t GPIO_getOutputEnableMultiDio(uint32_t dioMask)
Gets the output enable setting of the specified DIOs.
Definition: gpio.h:473
#define ASSERT(expr)
Definition: debug.h:74
static void GPIO_setDio(uint32_t dioNumber)
Sets a specific DIO to 1 (high).
Definition: gpio.h:272
static void GPIO_toggleDio(uint32_t dioNumber)
Toggles a specific DIO.
Definition: gpio.h:380
static uint32_t GPIO_readDio(uint32_t dioNumber)
Reads a specific DIO.
Definition: gpio.h:150
#define GPIO_OUTPUT_DISABLE
Definition: gpio.h:129
static uint32_t GPIO_readMultiDio(uint32_t dioMask)
Reads the input value for the specified DIOs.
Definition: gpio.h:184
static uint32_t GPIO_getEventMultiDio(uint32_t dioMask)
Gets the event status of the specified DIOs.
Definition: gpio.h:605
static void GPIO_writeMultiDio(uint32_t dioMask, uint32_t bitVectoredValue)
Writes masked data to the specified DIOs.
Definition: gpio.h:248
static void GPIO_setOutputEnableDio(uint32_t dioNumber, uint32_t outputEnableValue)
Sets output enable of a specific DIO.
Definition: gpio.h:504