CC13xx Driver Library
gpio.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: gpio.h
3 * Revised: 2015-12-07 16:22:56 +0100 (Mon, 07 Dec 2015)
4 * Revision: 45269
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 #include <inc/hw_fcfg1.h>
75 #include <driverlib/chipinfo.h>
76 
77 static bool
78 dioNumberLegal( uint32_t dioNumber )
79 {
80  uint32_t ioCount =
81  (( HWREG( FCFG1_BASE + FCFG1_O_IOCONF ) &
84 
85  //
86  // Special handling of CC13xx 7x7, where IO_CNT = 30 and legal range is 1..30
87  // for all other chips legal range is 0..(dioNumber-1)
88  //
89  if (( ioCount == 30 ) && ChipInfo_ChipFamilyIsCC13xx() ) {
90  return (( dioNumber > 0 ) && ( dioNumber <= ioCount ));
91  } else {
92  return ( dioNumber < ioCount );
93  }
94 }
95 #endif
96 
97 //*****************************************************************************
98 //
99 // The following values define the bit field for the GPIO DIOs.
100 //
101 //*****************************************************************************
102 #define GPIO_DIO_0_MASK 0x00000001 // GPIO DIO 0 mask
103 #define GPIO_DIO_1_MASK 0x00000002 // GPIO DIO 1 mask
104 #define GPIO_DIO_2_MASK 0x00000004 // GPIO DIO 2 mask
105 #define GPIO_DIO_3_MASK 0x00000008 // GPIO DIO 3 mask
106 #define GPIO_DIO_4_MASK 0x00000010 // GPIO DIO 4 mask
107 #define GPIO_DIO_5_MASK 0x00000020 // GPIO DIO 5 mask
108 #define GPIO_DIO_6_MASK 0x00000040 // GPIO DIO 6 mask
109 #define GPIO_DIO_7_MASK 0x00000080 // GPIO DIO 7 mask
110 #define GPIO_DIO_8_MASK 0x00000100 // GPIO DIO 8 mask
111 #define GPIO_DIO_9_MASK 0x00000200 // GPIO DIO 9 mask
112 #define GPIO_DIO_10_MASK 0x00000400 // GPIO DIO 10 mask
113 #define GPIO_DIO_11_MASK 0x00000800 // GPIO DIO 11 mask
114 #define GPIO_DIO_12_MASK 0x00001000 // GPIO DIO 12 mask
115 #define GPIO_DIO_13_MASK 0x00002000 // GPIO DIO 13 mask
116 #define GPIO_DIO_14_MASK 0x00004000 // GPIO DIO 14 mask
117 #define GPIO_DIO_15_MASK 0x00008000 // GPIO DIO 15 mask
118 #define GPIO_DIO_16_MASK 0x00010000 // GPIO DIO 16 mask
119 #define GPIO_DIO_17_MASK 0x00020000 // GPIO DIO 17 mask
120 #define GPIO_DIO_18_MASK 0x00040000 // GPIO DIO 18 mask
121 #define GPIO_DIO_19_MASK 0x00080000 // GPIO DIO 19 mask
122 #define GPIO_DIO_20_MASK 0x00100000 // GPIO DIO 20 mask
123 #define GPIO_DIO_21_MASK 0x00200000 // GPIO DIO 21 mask
124 #define GPIO_DIO_22_MASK 0x00400000 // GPIO DIO 22 mask
125 #define GPIO_DIO_23_MASK 0x00800000 // GPIO DIO 23 mask
126 #define GPIO_DIO_24_MASK 0x01000000 // GPIO DIO 24 mask
127 #define GPIO_DIO_25_MASK 0x02000000 // GPIO DIO 25 mask
128 #define GPIO_DIO_26_MASK 0x04000000 // GPIO DIO 26 mask
129 #define GPIO_DIO_27_MASK 0x08000000 // GPIO DIO 27 mask
130 #define GPIO_DIO_28_MASK 0x10000000 // GPIO DIO 28 mask
131 #define GPIO_DIO_29_MASK 0x20000000 // GPIO DIO 29 mask
132 #define GPIO_DIO_30_MASK 0x40000000 // GPIO DIO 30 mask
133 #define GPIO_DIO_31_MASK 0x80000000 // GPIO DIO 31 mask
134 #define GPIO_DIO_ALL_MASK 0xFFFFFFFF // GPIO all DIOs mask
135 
136 //*****************************************************************************
137 //
138 // Define constants that shall be passed as the outputEnableValue parameter to
139 // GPIO_setOutputEnableDio() and will be returned from the function
140 // GPIO_getOutputEnableDio().
141 //
142 //*****************************************************************************
143 #define GPIO_OUTPUT_DISABLE 0x00000000 // DIO output is disabled
144 #define GPIO_OUTPUT_ENABLE 0x00000001 // DIO output is enabled
145 
146 //*****************************************************************************
147 //
148 // API Functions and prototypes
149 //
150 //*****************************************************************************
151 
152 //*****************************************************************************
153 //
161 //
162 //*****************************************************************************
163 __STATIC_INLINE uint32_t
164 GPIO_readDio( uint32_t dioNumber )
165 {
166  //
167  // Check the arguments.
168  //
169  ASSERT( dioNumberLegal( dioNumber ));
170 
171  //
172  // Return the input value from the specified DIO.
173  //
174  return (( HWREG( GPIO_BASE + GPIO_O_DIN31_0 ) >> dioNumber ) & 1 );
175 }
176 
177 //*****************************************************************************
178 //
195 //
196 //*****************************************************************************
197 __STATIC_INLINE uint32_t
198 GPIO_readMultiDio( uint32_t dioMask )
199 {
200  //
201  // Check the arguments.
202  //
203  ASSERT( dioMask & GPIO_DIO_ALL_MASK );
204 
205  //
206  // Return the input value from the specified DIOs.
207  //
208  return ( HWREG( GPIO_BASE + GPIO_O_DIN31_0 ) & dioMask );
209 }
210 
211 //*****************************************************************************
212 //
223 //
224 //*****************************************************************************
225 __STATIC_INLINE void
226 GPIO_writeDio( uint32_t dioNumber, uint32_t value )
227 {
228  //
229  // Check the arguments.
230  //
231  ASSERT( dioNumberLegal( dioNumber ));
232  ASSERT(( value == 0 ) || ( value == 1 ));
233 
234  //
235  // Write 0 or 1 to the byte indexed DOUT map
236  //
237  HWREGB( GPIO_BASE + dioNumber ) = value;
238 }
239 
240 //*****************************************************************************
241 //
259 //
260 //*****************************************************************************
261 __STATIC_INLINE void
262 GPIO_writeMultiDio( uint32_t dioMask, uint32_t bitVectoredValue )
263 {
264  //
265  // Check the arguments.
266  //
267  ASSERT( dioMask & GPIO_DIO_ALL_MASK );
268 
269  HWREG( GPIO_BASE + GPIO_O_DOUT31_0 ) =
270  ( HWREG( GPIO_BASE + GPIO_O_DOUT31_0 ) & ~dioMask ) |
271  ( bitVectoredValue & dioMask );
272 }
273 
274 //*****************************************************************************
275 //
283 //
284 //*****************************************************************************
285 __STATIC_INLINE void
286 GPIO_setDio( uint32_t dioNumber )
287 {
288  //
289  // Check the arguments.
290  //
291  ASSERT( dioNumberLegal( dioNumber ));
292 
293  //
294  // Set the specified DIO.
295  //
296  HWREG( GPIO_BASE + GPIO_O_DOUTSET31_0 ) = ( 1 << dioNumber );
297 }
298 
299 //*****************************************************************************
300 //
312 //
313 //*****************************************************************************
314 __STATIC_INLINE void
315 GPIO_setMultiDio( uint32_t dioMask )
316 {
317  //
318  // Check the arguments.
319  //
320  ASSERT( dioMask & GPIO_DIO_ALL_MASK );
321 
322  //
323  // Set the DIOs.
324  //
325  HWREG( GPIO_BASE + GPIO_O_DOUTSET31_0 ) = dioMask;
326 }
327 
328 //*****************************************************************************
329 //
337 //
338 //*****************************************************************************
339 __STATIC_INLINE void
340 GPIO_clearDio( uint32_t dioNumber )
341 {
342  //
343  // Check the arguments.
344  //
345  ASSERT( dioNumberLegal( dioNumber ));
346 
347  //
348  // Clear the specified DIO.
349  //
350  HWREG( GPIO_BASE + GPIO_O_DOUTCLR31_0 ) = ( 1 << dioNumber );
351 }
352 
353 //*****************************************************************************
354 //
366 //
367 //*****************************************************************************
368 __STATIC_INLINE void
369 GPIO_clearMultiDio( uint32_t dioMask )
370 {
371  //
372  // Check the arguments.
373  //
374  ASSERT( dioMask & GPIO_DIO_ALL_MASK );
375 
376  //
377  // Clear the DIOs.
378  //
379  HWREG( GPIO_BASE + GPIO_O_DOUTCLR31_0 ) = dioMask;
380 }
381 
382 //*****************************************************************************
383 //
391 //
392 //*****************************************************************************
393 __STATIC_INLINE void
394 GPIO_toggleDio( uint32_t dioNumber )
395 {
396  //
397  // Check the arguments.
398  //
399  ASSERT( dioNumberLegal( dioNumber ));
400 
401  //
402  // Toggle the specified DIO.
403  //
404  HWREG( GPIO_BASE + GPIO_O_DOUTTGL31_0 ) = ( 1 << dioNumber );
405 }
406 
407 //*****************************************************************************
408 //
420 //
421 //*****************************************************************************
422 __STATIC_INLINE void
423 GPIO_toggleMultiDio( uint32_t dioMask )
424 {
425  //
426  // Check the arguments.
427  //
428  ASSERT( dioMask & GPIO_DIO_ALL_MASK );
429 
430  //
431  // Toggle the DIOs.
432  //
433  HWREG( GPIO_BASE + GPIO_O_DOUTTGL31_0 ) = dioMask;
434 }
435 
436 //*****************************************************************************
437 //
450 //
451 //*****************************************************************************
452 __STATIC_INLINE uint32_t
453 GPIO_getOutputEnableDio( uint32_t dioNumber )
454 {
455  //
456  // Check the arguments.
457  //
458  ASSERT( dioNumberLegal( dioNumber ));
459 
460  //
461  // Return the output enable status for the specified DIO.
462  //
463  return (( HWREG( GPIO_BASE + GPIO_O_DOE31_0 ) >> dioNumber ) & 1 );
464 }
465 
466 //*****************************************************************************
467 //
484 //
485 //*****************************************************************************
486 __STATIC_INLINE uint32_t
487 GPIO_getOutputEnableMultiDio( uint32_t dioMask )
488 {
489  //
490  // Check the arguments.
491  //
492  ASSERT( dioMask & GPIO_DIO_ALL_MASK );
493 
494  //
495  // Return the output enable value for the specified DIOs.
496  //
497  return ( HWREG( GPIO_BASE + GPIO_O_DOE31_0 ) & dioMask );
498 }
499 
500 //*****************************************************************************
501 //
515 //
516 //*****************************************************************************
517 __STATIC_INLINE void
518 GPIO_setOutputEnableDio( uint32_t dioNumber, uint32_t outputEnableValue )
519 {
520  //
521  // Check the arguments.
522  //
523  ASSERT( dioNumberLegal( dioNumber ));
524  ASSERT(( outputEnableValue == GPIO_OUTPUT_DISABLE ) ||
525  ( outputEnableValue == GPIO_OUTPUT_ENABLE ) );
526 
527  //
528  // Update the output enable bit for the specified DIO.
529  //
530  HWREGBITW( GPIO_BASE + GPIO_O_DOE31_0, dioNumber ) = outputEnableValue;
531 }
532 
533 //*****************************************************************************
534 //
555 //
556 //*****************************************************************************
557 __STATIC_INLINE void
558 GPIO_setOutputEnableMultiDio( uint32_t dioMask, uint32_t bitVectoredOutputEnable )
559 {
560  //
561  // Check the arguments.
562  //
563  ASSERT( dioMask & GPIO_DIO_ALL_MASK );
564 
565  HWREG( GPIO_BASE + GPIO_O_DOE31_0 ) =
566  ( HWREG( GPIO_BASE + GPIO_O_DOE31_0 ) & ~dioMask ) |
567  ( bitVectoredOutputEnable & dioMask );
568 }
569 
570 //*****************************************************************************
571 //
581 //
582 //*****************************************************************************
583 __STATIC_INLINE uint32_t
584 GPIO_getEventDio( uint32_t dioNumber )
585 {
586  //
587  // Check the arguments.
588  //
589  ASSERT( dioNumberLegal( dioNumber ));
590 
591  //
592  // Return the event status for the specified DIO.
593  //
594  return (( HWREG( GPIO_BASE + GPIO_O_EVFLAGS31_0 ) >> dioNumber ) & 1 );
595 }
596 
597 //*****************************************************************************
598 //
616 //
617 //*****************************************************************************
618 __STATIC_INLINE uint32_t
619 GPIO_getEventMultiDio( uint32_t dioMask )
620 {
621  //
622  // Check the arguments.
623  //
624  ASSERT( dioMask & GPIO_DIO_ALL_MASK );
625 
626  //
627  // Return the event status for the specified DIO.
628  //
629  return ( HWREG( GPIO_BASE + GPIO_O_EVFLAGS31_0 ) & dioMask );
630 }
631 
632 //*****************************************************************************
633 //
641 //
642 //*****************************************************************************
643 __STATIC_INLINE void
644 GPIO_clearEventDio( uint32_t dioNumber )
645 {
646  //
647  // Check the arguments.
648  //
649  ASSERT( dioNumberLegal( dioNumber ));
650 
651  //
652  // Clear the event status for the specified DIO.
653  //
654  HWREG( GPIO_BASE + GPIO_O_EVFLAGS31_0 ) = ( 1 << dioNumber );
655 }
656 
657 //*****************************************************************************
658 //
671 //
672 //*****************************************************************************
673 __STATIC_INLINE void
674 GPIO_clearEventMultiDio( uint32_t dioMask )
675 {
676  //
677  // Check the arguments.
678  //
679  ASSERT( dioMask & GPIO_DIO_ALL_MASK );
680 
681  //
682  // Clear the event status for the specified DIOs.
683  //
684  HWREG( GPIO_BASE + GPIO_O_EVFLAGS31_0 ) = dioMask;
685 }
686 
687 //*****************************************************************************
688 //
689 // Mark the end of the C bindings section for C++ compilers.
690 //
691 //*****************************************************************************
692 #ifdef __cplusplus
693 }
694 #endif
695 
696 #endif // __GPIO_H__
697 
698 //*****************************************************************************
699 //
703 //
704 //*****************************************************************************
static uint32_t GPIO_getEventDio(uint32_t dioNumber)
Gets the event status of a specific DIO.
Definition: gpio.h:584
static void GPIO_setOutputEnableMultiDio(uint32_t dioMask, uint32_t bitVectoredOutputEnable)
Configures the output enable setting for all specified DIOs.
Definition: gpio.h:558
static uint32_t GPIO_getOutputEnableDio(uint32_t dioNumber)
Gets the output enable status of a specific DIO.
Definition: gpio.h:453
static void GPIO_clearEventDio(uint32_t dioNumber)
Clears the IO event status of a specific DIO.
Definition: gpio.h:644
#define GPIO_DIO_ALL_MASK
Definition: gpio.h:134
#define GPIO_OUTPUT_ENABLE
Definition: gpio.h:144
static void GPIO_clearEventMultiDio(uint32_t dioMask)
Clears the IO event status on the specified DIOs.
Definition: gpio.h:674
static void GPIO_clearMultiDio(uint32_t dioMask)
Clears the specified DIOs to 0 (low).
Definition: gpio.h:369
static void GPIO_clearDio(uint32_t dioNumber)
Clears a specific DIO to 0 (low).
Definition: gpio.h:340
static void GPIO_writeDio(uint32_t dioNumber, uint32_t value)
Writes a value to a specific DIO.
Definition: gpio.h:226
static void GPIO_setMultiDio(uint32_t dioMask)
Sets the specified DIOs to 1 (high).
Definition: gpio.h:315
static void GPIO_toggleMultiDio(uint32_t dioMask)
Toggles the specified DIOs.
Definition: gpio.h:423
static uint32_t GPIO_getOutputEnableMultiDio(uint32_t dioMask)
Gets the output enable setting of the specified DIOs.
Definition: gpio.h:487
#define ASSERT(expr)
Definition: debug.h:74
static void GPIO_setDio(uint32_t dioNumber)
Sets a specific DIO to 1 (high).
Definition: gpio.h:286
static bool ChipInfo_ChipFamilyIsCC13xx(void)
Returns true if this chip is member of the CC13xx family.
Definition: chipinfo.h:320
static void GPIO_toggleDio(uint32_t dioNumber)
Toggles a specific DIO.
Definition: gpio.h:394
static uint32_t GPIO_readDio(uint32_t dioNumber)
Reads a specific DIO.
Definition: gpio.h:164
#define GPIO_OUTPUT_DISABLE
Definition: gpio.h:143
static uint32_t GPIO_readMultiDio(uint32_t dioMask)
Reads the input value for the specified DIOs.
Definition: gpio.h:198
static uint32_t GPIO_getEventMultiDio(uint32_t dioMask)
Gets the event status of the specified DIOs.
Definition: gpio.h:619
static void GPIO_writeMultiDio(uint32_t dioMask, uint32_t bitVectoredValue)
Writes masked data to the specified DIOs.
Definition: gpio.h:262
static void GPIO_setOutputEnableDio(uint32_t dioNumber, uint32_t outputEnableValue)
Sets output enable of a specific DIO.
Definition: gpio.h:518