1 //*****************************************************************************
2 //
3 // gpio.c - API for GPIO ports
4 //
5 // Copyright (c) 2005-2012 Texas Instruments Incorporated.  All rights reserved.
6 // Software License Agreement
7 //
8 //   Redistribution and use in source and binary forms, with or without
9 //   modification, are permitted provided that the following conditions
10 //   are met:
11 //
12 //   Redistributions of source code must retain the above copyright
13 //   notice, this list of conditions and the following disclaimer.
14 //
15 //   Redistributions in binary form must reproduce the above copyright
16 //   notice, this list of conditions and the following disclaimer in the
17 //   documentation and/or other materials provided with the
18 //   distribution.
19 //
20 //   Neither the name of Texas Instruments Incorporated nor the names of
21 //   its contributors may be used to endorse or promote products derived
22 //   from this software without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 // This is part of revision 9453 of the Stellaris Peripheral Driver Library.
37 //
38 //*****************************************************************************
39 
40 //*****************************************************************************
41 //
42 //! \addtogroup gpio_api
43 //! @{
44 //
45 //*****************************************************************************
46 
47 #include "inc/hw_gpio.h"
48 #include "inc/hw_ints.h"
49 #include "inc/hw_memmap.h"
50 #include "inc/hw_sysctl.h"
51 #include "inc/hw_types.h"
52 #include "driverlib/debug.h"
53 #include "driverlib/gpio.h"
54 #include "driverlib/interrupt.h"
55 
56 //*****************************************************************************
57 //
58 // The base addresses of all the GPIO modules.  Both the APB and AHB apertures
59 // are provided.
60 //
61 //*****************************************************************************
62 static const unsigned long g_pulGPIOBaseAddrs[] =
63 {
64     GPIO_PORTA_BASE, GPIO_PORTA_AHB_BASE,
65     GPIO_PORTB_BASE, GPIO_PORTB_AHB_BASE,
66     GPIO_PORTC_BASE, GPIO_PORTC_AHB_BASE,
67     GPIO_PORTD_BASE, GPIO_PORTD_AHB_BASE,
68     GPIO_PORTE_BASE, GPIO_PORTE_AHB_BASE,
69     GPIO_PORTF_BASE, GPIO_PORTF_AHB_BASE,
70     GPIO_PORTG_BASE, GPIO_PORTG_AHB_BASE,
71     GPIO_PORTH_BASE, GPIO_PORTH_AHB_BASE,
72     GPIO_PORTJ_BASE, GPIO_PORTJ_AHB_BASE,
73     GPIO_PORTK_BASE, GPIO_PORTK_BASE,
74     GPIO_PORTL_BASE, GPIO_PORTL_BASE,
75     GPIO_PORTM_BASE, GPIO_PORTM_BASE,
76     GPIO_PORTN_BASE, GPIO_PORTN_BASE,
77     GPIO_PORTP_BASE, GPIO_PORTP_BASE,
78     GPIO_PORTQ_BASE, GPIO_PORTQ_BASE,
79 };
80 
81 //*****************************************************************************
82 //
83 //! \internal
84 //! Checks a GPIO base address.
85 //!
86 //! \param ulPort is the base address of the GPIO port.
87 //!
88 //! This function determines if a GPIO port base address is valid.
89 //!
90 //! \return Returns \b true if the base address is valid and \b false
91 //! otherwise.
92 //
93 //*****************************************************************************
94 #ifdef DEBUG
95 static tBoolean
GPIOBaseValid(unsigned long ulPort)96 GPIOBaseValid(unsigned long ulPort)
97 {
98     return((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTA_AHB_BASE) ||
99            (ulPort == GPIO_PORTB_BASE) || (ulPort == GPIO_PORTB_AHB_BASE) ||
100            (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTC_AHB_BASE) ||
101            (ulPort == GPIO_PORTD_BASE) || (ulPort == GPIO_PORTD_AHB_BASE) ||
102            (ulPort == GPIO_PORTE_BASE) || (ulPort == GPIO_PORTE_AHB_BASE) ||
103            (ulPort == GPIO_PORTF_BASE) || (ulPort == GPIO_PORTF_AHB_BASE) ||
104            (ulPort == GPIO_PORTG_BASE) || (ulPort == GPIO_PORTG_AHB_BASE) ||
105            (ulPort == GPIO_PORTH_BASE) || (ulPort == GPIO_PORTH_AHB_BASE) ||
106            (ulPort == GPIO_PORTJ_BASE) || (ulPort == GPIO_PORTJ_AHB_BASE) ||
107            (ulPort == GPIO_PORTK_BASE) || (ulPort == GPIO_PORTL_BASE) ||
108            (ulPort == GPIO_PORTM_BASE) || (ulPort == GPIO_PORTN_BASE) ||
109            (ulPort == GPIO_PORTP_BASE) || (ulPort == GPIO_PORTQ_BASE));
110 }
111 #endif
112 
113 //*****************************************************************************
114 //
115 //! \internal
116 //! Gets the GPIO interrupt number.
117 //!
118 //! \param ulPort is the base address of the GPIO port.
119 //!
120 //! Given a GPIO base address, this function returns the corresponding
121 //! interrupt number.
122 //!
123 //! \return Returns a GPIO interrupt number, or -1 if \e ulPort is invalid.
124 //
125 //*****************************************************************************
126 static long
GPIOGetIntNumber(unsigned long ulPort)127 GPIOGetIntNumber(unsigned long ulPort)
128 {
129     long lInt;
130 
131     //
132     // Determine the GPIO interrupt number for the given module.
133     //
134     switch(ulPort)
135     {
136         case GPIO_PORTA_BASE:
137         case GPIO_PORTA_AHB_BASE:
138         {
139             lInt = INT_GPIOA;
140             break;
141         }
142 
143         case GPIO_PORTB_BASE:
144         case GPIO_PORTB_AHB_BASE:
145         {
146             lInt = INT_GPIOB;
147             break;
148         }
149 
150         case GPIO_PORTC_BASE:
151         case GPIO_PORTC_AHB_BASE:
152         {
153             lInt = INT_GPIOC;
154             break;
155         }
156 
157         case GPIO_PORTD_BASE:
158         case GPIO_PORTD_AHB_BASE:
159         {
160             lInt = INT_GPIOD;
161             break;
162         }
163 
164         case GPIO_PORTE_BASE:
165         case GPIO_PORTE_AHB_BASE:
166         {
167             lInt = INT_GPIOE;
168             break;
169         }
170 
171         case GPIO_PORTF_BASE:
172         case GPIO_PORTF_AHB_BASE:
173         {
174             lInt = INT_GPIOF;
175             break;
176         }
177 
178         case GPIO_PORTG_BASE:
179         case GPIO_PORTG_AHB_BASE:
180         {
181             lInt = INT_GPIOG;
182             break;
183         }
184 
185         case GPIO_PORTH_BASE:
186         case GPIO_PORTH_AHB_BASE:
187         {
188             lInt = INT_GPIOH;
189             break;
190         }
191 
192         case GPIO_PORTJ_BASE:
193         case GPIO_PORTJ_AHB_BASE:
194         {
195             lInt = INT_GPIOJ;
196             break;
197         }
198 
199         case GPIO_PORTK_BASE:
200         {
201             lInt = INT_GPIOK;
202             break;
203         }
204 
205         case GPIO_PORTL_BASE:
206         {
207             lInt = INT_GPIOL;
208             break;
209         }
210 
211         case GPIO_PORTM_BASE:
212         {
213             lInt = INT_GPIOM;
214             break;
215         }
216 
217         case GPIO_PORTN_BASE:
218         {
219             lInt = INT_GPION;
220             break;
221         }
222 
223         case GPIO_PORTP_BASE:
224         {
225             lInt = INT_GPIOP0;
226             break;
227         }
228 
229         case GPIO_PORTQ_BASE:
230         {
231             lInt = INT_GPIOQ0;
232             break;
233         }
234 
235         default:
236         {
237             return(-1);
238         }
239     }
240 
241     //
242     // Return GPIO interrupt number.
243     //
244     return(lInt);
245 }
246 
247 //*****************************************************************************
248 //
249 //! Sets the direction and mode of the specified pin(s).
250 //!
251 //! \param ulPort is the base address of the GPIO port
252 //! \param ucPins is the bit-packed representation of the pin(s).
253 //! \param ulPinIO is the pin direction and/or mode.
254 //!
255 //! This function configures the specified pin(s) on the selected GPIO port
256 //! as either input or output under software control, or it configures the
257 //! pin to be under hardware control.
258 //!
259 //! The parameter \e ulPinIO is an enumerated data type that can be one of
260 //! the following values:
261 //!
262 //! - \b GPIO_DIR_MODE_IN
263 //! - \b GPIO_DIR_MODE_OUT
264 //! - \b GPIO_DIR_MODE_HW
265 //!
266 //! where \b GPIO_DIR_MODE_IN specifies that the pin is programmed as a
267 //! software controlled input, \b GPIO_DIR_MODE_OUT specifies that the pin is
268 //! programmed as a software controlled output, and \b GPIO_DIR_MODE_HW
269 //! specifies that the pin is placed under hardware control.
270 //!
271 //! The pin(s) are specified using a bit-packed byte, where each bit that is
272 //! set identifies the pin to be accessed, and where bit 0 of the byte
273 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
274 //!
275 //! \note GPIOPadConfigSet() must also be used to configure the corresponding
276 //! pad(s) in order for them to propagate the signal to/from the GPIO.
277 //!
278 //! \return None.
279 //
280 //*****************************************************************************
281 void
GPIODirModeSet(unsigned long ulPort,unsigned char ucPins,unsigned long ulPinIO)282 GPIODirModeSet(unsigned long ulPort, unsigned char ucPins,
283                unsigned long ulPinIO)
284 {
285     //
286     // Check the arguments.
287     //
288     ASSERT(GPIOBaseValid(ulPort));
289     ASSERT((ulPinIO == GPIO_DIR_MODE_IN) || (ulPinIO == GPIO_DIR_MODE_OUT) ||
290            (ulPinIO == GPIO_DIR_MODE_HW));
291 
292     //
293     // Set the pin direction and mode.
294     //
295     HWREG(ulPort + GPIO_O_DIR) = ((ulPinIO & 1) ?
296                                   (HWREG(ulPort + GPIO_O_DIR) | ucPins) :
297                                   (HWREG(ulPort + GPIO_O_DIR) & ~(ucPins)));
298     HWREG(ulPort + GPIO_O_AFSEL) = ((ulPinIO & 2) ?
299                                     (HWREG(ulPort + GPIO_O_AFSEL) | ucPins) :
300                                     (HWREG(ulPort + GPIO_O_AFSEL) &
301                                      ~(ucPins)));
302 }
303 
304 //*****************************************************************************
305 //
306 //! Gets the direction and mode of a pin.
307 //!
308 //! \param ulPort is the base address of the GPIO port.
309 //! \param ucPin is the pin number.
310 //!
311 //! This function gets the direction and control mode for a specified pin on
312 //! the selected GPIO port.  The pin can be configured as either an input or
313 //! output under software control, or it can be under hardware control.  The
314 //! type of control and direction are returned as an enumerated data type.
315 //!
316 //! \return Returns one of the enumerated data types described for
317 //! GPIODirModeSet().
318 //
319 //*****************************************************************************
320 unsigned long
GPIODirModeGet(unsigned long ulPort,unsigned char ucPin)321 GPIODirModeGet(unsigned long ulPort, unsigned char ucPin)
322 {
323     unsigned long ulDir, ulAFSEL;
324 
325     //
326     // Check the arguments.
327     //
328     ASSERT(GPIOBaseValid(ulPort));
329     ASSERT(ucPin < 8);
330 
331     //
332     // Convert from a pin number to a bit position.
333     //
334     ucPin = 1 << ucPin;
335 
336     //
337     // Return the pin direction and mode.
338     //
339     ulDir = HWREG(ulPort + GPIO_O_DIR);
340     ulAFSEL = HWREG(ulPort + GPIO_O_AFSEL);
341     return(((ulDir & ucPin) ? 1 : 0) | ((ulAFSEL & ucPin) ? 2 : 0));
342 }
343 
344 //*****************************************************************************
345 //
346 //! Sets the interrupt type for the specified pin(s).
347 //!
348 //! \param ulPort is the base address of the GPIO port.
349 //! \param ucPins is the bit-packed representation of the pin(s).
350 //! \param ulIntType specifies the type of interrupt trigger mechanism.
351 //!
352 //! This function sets up the various interrupt trigger mechanisms for the
353 //! specified pin(s) on the selected GPIO port.
354 //!
355 //! The parameter \e ulIntType is an enumerated data type that can be one of
356 //! the following values:
357 //!
358 //! - \b GPIO_FALLING_EDGE
359 //! - \b GPIO_RISING_EDGE
360 //! - \b GPIO_BOTH_EDGES
361 //! - \b GPIO_LOW_LEVEL
362 //! - \b GPIO_HIGH_LEVEL
363 //! - \b GPIO_DISCRETE_INT
364 //!
365 //! where the different values describe the interrupt detection mechanism
366 //! (edge or level) and the particular triggering event (falling, rising,
367 //! or both edges for edge detect, low or high for level detect).
368 //!
369 //! Some devices also support discrete interrupts for each pin on a GPIO port,
370 //! giving each pin a separate interrupt vector.  To use this feature, the
371 //! \b GPIO_DISCRETE_INT can be included to enable an interrupt per pin.  The
372 //! \b GPIO_DISCRETE_INT is not available on all devices or all GPIO ports,
373 //! consult the data sheet to ensure that the device and the GPIO port supports
374 //! discrete interrupts.
375 //!
376 //! The pin(s) are specified using a bit-packed byte, where each bit that is
377 //! set identifies the pin to be accessed, and where bit 0 of the byte
378 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
379 //!
380 //! \note In order to avoid any spurious interrupts, the user must
381 //! ensure that the GPIO inputs remain stable for the duration of
382 //! this function.
383 //!
384 //! \return None.
385 //
386 //*****************************************************************************
387 void
GPIOIntTypeSet(unsigned long ulPort,unsigned char ucPins,unsigned long ulIntType)388 GPIOIntTypeSet(unsigned long ulPort, unsigned char ucPins,
389                unsigned long ulIntType)
390 {
391     //
392     // Check the arguments.
393     //
394     ASSERT(GPIOBaseValid(ulPort));
395     ASSERT((ulIntType == GPIO_FALLING_EDGE) ||
396            (ulIntType == GPIO_RISING_EDGE) || (ulIntType == GPIO_BOTH_EDGES) ||
397            (ulIntType == GPIO_LOW_LEVEL) || (ulIntType == GPIO_HIGH_LEVEL));
398 
399     //
400     // Set the pin interrupt type.
401     //
402     HWREG(ulPort + GPIO_O_IBE) = ((ulIntType & 1) ?
403                                   (HWREG(ulPort + GPIO_O_IBE) | ucPins) :
404                                   (HWREG(ulPort + GPIO_O_IBE) & ~(ucPins)));
405     HWREG(ulPort + GPIO_O_IS) = ((ulIntType & 2) ?
406                                  (HWREG(ulPort + GPIO_O_IS) | ucPins) :
407                                  (HWREG(ulPort + GPIO_O_IS) & ~(ucPins)));
408     HWREG(ulPort + GPIO_O_IEV) = ((ulIntType & 4) ?
409                                   (HWREG(ulPort + GPIO_O_IEV) | ucPins) :
410                                   (HWREG(ulPort + GPIO_O_IEV) & ~(ucPins)));
411 }
412 
413 //*****************************************************************************
414 //
415 //! Gets the interrupt type for a pin.
416 //!
417 //! \param ulPort is the base address of the GPIO port.
418 //! \param ucPin is the pin number.
419 //!
420 //! This function gets the interrupt type for a specified pin on the selected
421 //! GPIO port.  The pin can be configured as a falling-edge, rising-edge, or
422 //! both-edges detected interrupt, or it can be configured as a low-level or
423 //! high-level detected interrupt.  The type of interrupt detection mechanism
424 //! is returned as an enumerated data type.
425 //!
426 //! \return Returns one of the enumerated data types described for
427 //! GPIOIntTypeSet().
428 //
429 //*****************************************************************************
430 unsigned long
GPIOIntTypeGet(unsigned long ulPort,unsigned char ucPin)431 GPIOIntTypeGet(unsigned long ulPort, unsigned char ucPin)
432 {
433     unsigned long ulIBE, ulIS, ulIEV;
434 
435     //
436     // Check the arguments.
437     //
438     ASSERT(GPIOBaseValid(ulPort));
439     ASSERT(ucPin < 8);
440 
441     //
442     // Convert from a pin number to a bit position.
443     //
444     ucPin = 1 << ucPin;
445 
446     //
447     // Return the pin interrupt type.
448     //
449     ulIBE = HWREG(ulPort + GPIO_O_IBE);
450     ulIS = HWREG(ulPort + GPIO_O_IS);
451     ulIEV = HWREG(ulPort + GPIO_O_IEV);
452     return(((ulIBE & ucPin) ? 1 : 0) | ((ulIS & ucPin) ? 2 : 0) |
453            ((ulIEV & ucPin) ? 4 : 0));
454 }
455 
456 //*****************************************************************************
457 //
458 //! Sets the pad configuration for the specified pin(s).
459 //!
460 //! \param ulPort is the base address of the GPIO port.
461 //! \param ucPins is the bit-packed representation of the pin(s).
462 //! \param ulStrength specifies the output drive strength.
463 //! \param ulPinType specifies the pin type.
464 //!
465 //! This function sets the drive strength and type for the specified pin(s)
466 //! on the selected GPIO port.  For pin(s) configured as input ports, the
467 //! pad is configured as requested, but the only real effect on the input
468 //! is the configuration of the pull-up or pull-down termination.
469 //!
470 //! The parameter \e ulStrength can be one of the following values:
471 //!
472 //! - \b GPIO_STRENGTH_2MA
473 //! - \b GPIO_STRENGTH_4MA
474 //! - \b GPIO_STRENGTH_8MA
475 //! - \b GPIO_STRENGTH_8MA_SC
476 //!
477 //! where \b GPIO_STRENGTH_xMA specifies either 2, 4, or 8 mA output drive
478 //! strength, and \b GPIO_OUT_STRENGTH_8MA_SC specifies 8 mA output drive with
479 //! slew control.
480 //!
481 //! Some Stellaris devices also support output drive strengths of 6, 10, and 12
482 //! mA.
483 //!
484 //! The parameter \e ulPinType can be one of the following values:
485 //!
486 //! - \b GPIO_PIN_TYPE_STD
487 //! - \b GPIO_PIN_TYPE_STD_WPU
488 //! - \b GPIO_PIN_TYPE_STD_WPD
489 //! - \b GPIO_PIN_TYPE_OD
490 //! - \b GPIO_PIN_TYPE_OD_WPU
491 //! - \b GPIO_PIN_TYPE_OD_WPD
492 //! - \b GPIO_PIN_TYPE_ANALOG
493 //!
494 //! where \b GPIO_PIN_TYPE_STD* specifies a push-pull pin, \b GPIO_PIN_TYPE_OD*
495 //! specifies an open-drain pin, \b *_WPU specifies a weak pull-up, \b *_WPD
496 //! specifies a weak pull-down, and \b GPIO_PIN_TYPE_ANALOG specifies an analog
497 //! input.
498 //!
499 //! The pin(s) are specified using a bit-packed byte, where each bit that is
500 //! set identifies the pin to be accessed, and where bit 0 of the byte
501 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
502 //!
503 //! \return None.
504 //
505 //*****************************************************************************
506 void
GPIOPadConfigSet(unsigned long ulPort,unsigned char ucPins,unsigned long ulStrength,unsigned long ulPinType)507 GPIOPadConfigSet(unsigned long ulPort, unsigned char ucPins,
508                  unsigned long ulStrength, unsigned long ulPinType)
509 {
510     //
511     // Check the arguments.
512     //
513     ASSERT(GPIOBaseValid(ulPort));
514     ASSERT((ulStrength == GPIO_STRENGTH_2MA) ||
515            (ulStrength == GPIO_STRENGTH_4MA) ||
516            (ulStrength == GPIO_STRENGTH_8MA) ||
517            (ulStrength == GPIO_STRENGTH_8MA_SC));
518     ASSERT((ulPinType == GPIO_PIN_TYPE_STD) ||
519            (ulPinType == GPIO_PIN_TYPE_STD_WPU) ||
520            (ulPinType == GPIO_PIN_TYPE_STD_WPD) ||
521            (ulPinType == GPIO_PIN_TYPE_OD) ||
522            (ulPinType == GPIO_PIN_TYPE_OD_WPU) ||
523            (ulPinType == GPIO_PIN_TYPE_OD_WPD) ||
524            (ulPinType == GPIO_PIN_TYPE_ANALOG));
525 
526     //
527     // Set the output drive strength.
528     //
529     HWREG(ulPort + GPIO_O_DR2R) = ((ulStrength & 1) ?
530                                    (HWREG(ulPort + GPIO_O_DR2R) | ucPins) :
531                                    (HWREG(ulPort + GPIO_O_DR2R) & ~(ucPins)));
532     HWREG(ulPort + GPIO_O_DR4R) = ((ulStrength & 2) ?
533                                    (HWREG(ulPort + GPIO_O_DR4R) | ucPins) :
534                                    (HWREG(ulPort + GPIO_O_DR4R) & ~(ucPins)));
535     HWREG(ulPort + GPIO_O_DR8R) = ((ulStrength & 4) ?
536                                    (HWREG(ulPort + GPIO_O_DR8R) | ucPins) :
537                                    (HWREG(ulPort + GPIO_O_DR8R) & ~(ucPins)));
538     HWREG(ulPort + GPIO_O_SLR) = ((ulStrength & 8) ?
539                                   (HWREG(ulPort + GPIO_O_SLR) | ucPins) :
540                                   (HWREG(ulPort + GPIO_O_SLR) & ~(ucPins)));
541 
542     //
543     // Set the pin type.
544     //
545     HWREG(ulPort + GPIO_O_ODR) = ((ulPinType & 1) ?
546                                   (HWREG(ulPort + GPIO_O_ODR) | ucPins) :
547                                   (HWREG(ulPort + GPIO_O_ODR) & ~(ucPins)));
548     HWREG(ulPort + GPIO_O_PUR) = ((ulPinType & 2) ?
549                                   (HWREG(ulPort + GPIO_O_PUR) | ucPins) :
550                                   (HWREG(ulPort + GPIO_O_PUR) & ~(ucPins)));
551     HWREG(ulPort + GPIO_O_PDR) = ((ulPinType & 4) ?
552                                   (HWREG(ulPort + GPIO_O_PDR) | ucPins) :
553                                   (HWREG(ulPort + GPIO_O_PDR) & ~(ucPins)));
554     HWREG(ulPort + GPIO_O_DEN) = ((ulPinType & 8) ?
555                                   (HWREG(ulPort + GPIO_O_DEN) | ucPins) :
556                                   (HWREG(ulPort + GPIO_O_DEN) & ~(ucPins)));
557 
558     //
559     // Set the analog mode select register.  This register only appears in
560     // DustDevil-class (and later) devices, but is a harmless write on
561     // Sandstorm- and Fury-class devices.
562     //
563     HWREG(ulPort + GPIO_O_AMSEL) =
564         ((ulPinType == GPIO_PIN_TYPE_ANALOG) ?
565          (HWREG(ulPort + GPIO_O_AMSEL) | ucPins) :
566          (HWREG(ulPort + GPIO_O_AMSEL) & ~(ucPins)));
567 }
568 
569 //*****************************************************************************
570 //
571 //! Gets the pad configuration for a pin.
572 //!
573 //! \param ulPort is the base address of the GPIO port.
574 //! \param ucPin is the pin number.
575 //! \param pulStrength is a pointer to storage for the output drive strength.
576 //! \param pulPinType is a pointer to storage for the output drive type.
577 //!
578 //! This function gets the pad configuration for a specified pin on the
579 //! selected GPIO port.  The values returned in \e pulStrength and
580 //! \e pulPinType correspond to the values used in GPIOPadConfigSet().  This
581 //! function also works for pin(s) configured as input pin(s); however, the
582 //! only meaningful data returned is whether the pin is terminated with a
583 //! pull-up or down resistor.
584 //!
585 //! \return None
586 //
587 //*****************************************************************************
588 void
GPIOPadConfigGet(unsigned long ulPort,unsigned char ucPin,unsigned long * pulStrength,unsigned long * pulPinType)589 GPIOPadConfigGet(unsigned long ulPort, unsigned char ucPin,
590                  unsigned long *pulStrength, unsigned long *pulPinType)
591 {
592     unsigned long ulPinType, ulStrength;
593 
594     //
595     // Check the arguments.
596     //
597     ASSERT(GPIOBaseValid(ulPort));
598     ASSERT(ucPin < 8);
599 
600     //
601     // Convert from a pin number to a bit position.
602     //
603     ucPin = (1 << ucPin);
604 
605     //
606     // Get the drive strength for this pin.
607     //
608     ulStrength = ((HWREG(ulPort + GPIO_O_DR2R) & ucPin) ? 1 : 0);
609     ulStrength |= ((HWREG(ulPort + GPIO_O_DR4R) & ucPin) ? 2 : 0);
610     ulStrength |= ((HWREG(ulPort + GPIO_O_DR8R) & ucPin) ? 4 : 0);
611     ulStrength |= ((HWREG(ulPort + GPIO_O_SLR) & ucPin) ? 8 : 0);
612     *pulStrength = ulStrength;
613 
614     //
615     // Get the pin type.
616     //
617     ulPinType = ((HWREG(ulPort + GPIO_O_ODR) & ucPin) ? 1 : 0);
618     ulPinType |= ((HWREG(ulPort + GPIO_O_PUR) & ucPin) ? 2 : 0);
619     ulPinType |= ((HWREG(ulPort + GPIO_O_PDR) & ucPin) ? 4 : 0);
620     ulPinType |= ((HWREG(ulPort + GPIO_O_DEN) & ucPin) ? 8 : 0);
621     *pulPinType = ulPinType;
622 }
623 
624 //*****************************************************************************
625 //
626 //! Enables interrupts for the specified pin(s).
627 //!
628 //! \param ulPort is the base address of the GPIO port.
629 //! \param ucPins is the bit-packed representation of the pin(s).
630 //!
631 //! Unmasks the interrupt for the specified pin(s).
632 //!
633 //! The pin(s) are specified using a bit-packed byte, where each bit that is
634 //! set identifies the pin to be accessed, and where bit 0 of the byte
635 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
636 //!
637 //! \return None.
638 //
639 //*****************************************************************************
640 void
GPIOPinIntEnable(unsigned long ulPort,unsigned char ucPins)641 GPIOPinIntEnable(unsigned long ulPort, unsigned char ucPins)
642 {
643     //
644     // Check the arguments.
645     //
646     ASSERT(GPIOBaseValid(ulPort));
647 
648     //
649     // Enable the interrupts.
650     //
651     HWREG(ulPort + GPIO_O_IM) |= ucPins;
652 }
653 
654 //*****************************************************************************
655 //
656 //! Disables interrupts for the specified pin(s).
657 //!
658 //! \param ulPort is the base address of the GPIO port.
659 //! \param ucPins is the bit-packed representation of the pin(s).
660 //!
661 //! Masks the interrupt for the specified pin(s).
662 //!
663 //! The pin(s) are specified using a bit-packed byte, where each bit that is
664 //! set identifies the pin to be accessed, and where bit 0 of the byte
665 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
666 //!
667 //! \return None.
668 //
669 //*****************************************************************************
670 void
GPIOPinIntDisable(unsigned long ulPort,unsigned char ucPins)671 GPIOPinIntDisable(unsigned long ulPort, unsigned char ucPins)
672 {
673     //
674     // Check the arguments.
675     //
676     ASSERT(GPIOBaseValid(ulPort));
677 
678     //
679     // Disable the interrupts.
680     //
681     HWREG(ulPort + GPIO_O_IM) &= ~(ucPins);
682 }
683 
684 //*****************************************************************************
685 //
686 //! Gets interrupt status for the specified GPIO port.
687 //!
688 //! \param ulPort is the base address of the GPIO port.
689 //! \param bMasked specifies whether masked or raw interrupt status is
690 //! returned.
691 //!
692 //! If \e bMasked is set as \b true, then the masked interrupt status is
693 //! returned; otherwise, the raw interrupt status is returned.
694 //!
695 //! \return Returns a bit-packed byte, where each bit that is set identifies
696 //! an active masked or raw interrupt, and where bit 0 of the byte
697 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
698 //! Bits 31:8 should be ignored.
699 //
700 //*****************************************************************************
701 long
GPIOPinIntStatus(unsigned long ulPort,tBoolean bMasked)702 GPIOPinIntStatus(unsigned long ulPort, tBoolean bMasked)
703 {
704     //
705     // Check the arguments.
706     //
707     ASSERT(GPIOBaseValid(ulPort));
708 
709     //
710     // Return the interrupt status.
711     //
712     if(bMasked)
713     {
714         return(HWREG(ulPort + GPIO_O_MIS));
715     }
716     else
717     {
718         return(HWREG(ulPort + GPIO_O_RIS));
719     }
720 }
721 
722 //*****************************************************************************
723 //
724 //! Clears the interrupt for the specified pin(s).
725 //!
726 //! \param ulPort is the base address of the GPIO port.
727 //! \param ucPins is the bit-packed representation of the pin(s).
728 //!
729 //! Clears the interrupt for the specified pin(s).
730 //!
731 //! The pin(s) are specified using a bit-packed byte, where each bit that is
732 //! set identifies the pin to be accessed, and where bit 0 of the byte
733 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
734 //!
735 //! \note Because there is a write buffer in the Cortex-M processor, it may
736 //! take several clock cycles before the interrupt source is actually cleared.
737 //! Therefore, it is recommended that the interrupt source be cleared early in
738 //! the interrupt handler (as opposed to the very last action) to avoid
739 //! returning from the interrupt handler before the interrupt source is
740 //! actually cleared.  Failure to do so may result in the interrupt handler
741 //! being immediately reentered (because the interrupt controller still sees
742 //! the interrupt source asserted).
743 //!
744 //! \return None.
745 //
746 //*****************************************************************************
747 void
GPIOPinIntClear(unsigned long ulPort,unsigned char ucPins)748 GPIOPinIntClear(unsigned long ulPort, unsigned char ucPins)
749 {
750     //
751     // Check the arguments.
752     //
753     ASSERT(GPIOBaseValid(ulPort));
754 
755     //
756     // Clear the interrupts.
757     //
758     HWREG(ulPort + GPIO_O_ICR) = ucPins;
759 }
760 
761 //*****************************************************************************
762 //
763 //! Registers an interrupt handler for a GPIO port.
764 //!
765 //! \param ulPort is the base address of the GPIO port.
766 //! \param pfnIntHandler is a pointer to the GPIO port interrupt handling
767 //! function.
768 //!
769 //! This function ensures that the interrupt handler specified by
770 //! \e pfnIntHandler is called when an interrupt is detected from the selected
771 //! GPIO port.  This function also enables the corresponding GPIO interrupt
772 //! in the interrupt controller; individual pin interrupts and interrupt
773 //! sources must be enabled with GPIOPinIntEnable().
774 //!
775 //! \sa IntRegister() for important information about registering interrupt
776 //! handlers.
777 //!
778 //! \return None.
779 //
780 //*****************************************************************************
781 void
GPIOPortIntRegister(unsigned long ulPort,void (* pfnIntHandler)(void))782 GPIOPortIntRegister(unsigned long ulPort, void (*pfnIntHandler)(void))
783 {
784     //
785     // Check the arguments.
786     //
787     ASSERT(GPIOBaseValid(ulPort));
788 
789     //
790     // Get the interrupt number associated with the specified GPIO.
791     //
792     ulPort = GPIOGetIntNumber(ulPort);
793 
794     //
795     // Register the interrupt handler.
796     //
797     IntRegister(ulPort, pfnIntHandler);
798 
799     //
800     // Enable the GPIO interrupt.
801     //
802     IntEnable(ulPort);
803 }
804 
805 //*****************************************************************************
806 //
807 //! Removes an interrupt handler for a GPIO port.
808 //!
809 //! \param ulPort is the base address of the GPIO port.
810 //!
811 //! This function unregisters the interrupt handler for the specified
812 //! GPIO port.  This function also disables the corresponding
813 //! GPIO port interrupt in the interrupt controller; individual GPIO interrupts
814 //! and interrupt sources must be disabled with GPIOPinIntDisable().
815 //!
816 //! \sa IntRegister() for important information about registering interrupt
817 //! handlers.
818 //!
819 //! \return None.
820 //
821 //*****************************************************************************
822 void
GPIOPortIntUnregister(unsigned long ulPort)823 GPIOPortIntUnregister(unsigned long ulPort)
824 {
825     //
826     // Check the arguments.
827     //
828     ASSERT(GPIOBaseValid(ulPort));
829 
830     //
831     // Get the interrupt number associated with the specified GPIO.
832     //
833     ulPort = GPIOGetIntNumber(ulPort);
834 
835     //
836     // Disable the GPIO interrupt.
837     //
838     IntDisable(ulPort);
839 
840     //
841     // Unregister the interrupt handler.
842     //
843     IntUnregister(ulPort);
844 }
845 
846 //*****************************************************************************
847 //
848 //! Reads the values present of the specified pin(s).
849 //!
850 //! \param ulPort is the base address of the GPIO port.
851 //! \param ucPins is the bit-packed representation of the pin(s).
852 //!
853 //! The values at the specified pin(s) are read, as specified by \e ucPins.
854 //! Values are returned for both input and output pin(s), and the value
855 //! for pin(s) that are not specified by \e ucPins are set to 0.
856 //!
857 //! The pin(s) are specified using a bit-packed byte, where each bit that is
858 //! set identifies the pin to be accessed, and where bit 0 of the byte
859 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
860 //!
861 //! \return Returns a bit-packed byte providing the state of the specified
862 //! pin, where bit 0 of the byte represents GPIO port pin 0, bit 1 represents
863 //! GPIO port pin 1, and so on.  Any bit that is not specified by \e ucPins
864 //! is returned as a 0.  Bits 31:8 should be ignored.
865 //
866 //*****************************************************************************
867 long
GPIOPinRead(unsigned long ulPort,unsigned char ucPins)868 GPIOPinRead(unsigned long ulPort, unsigned char ucPins)
869 {
870     //
871     // Check the arguments.
872     //
873     ASSERT(GPIOBaseValid(ulPort));
874 
875     //
876     // Return the pin value(s).
877     //
878     return(HWREG(ulPort + (GPIO_O_DATA + (ucPins << 2))));
879 }
880 
881 //*****************************************************************************
882 //
883 //! Writes a value to the specified pin(s).
884 //!
885 //! \param ulPort is the base address of the GPIO port.
886 //! \param ucPins is the bit-packed representation of the pin(s).
887 //! \param ucVal is the value to write to the pin(s).
888 //!
889 //! Writes the corresponding bit values to the output pin(s) specified by
890 //! \e ucPins.  Writing to a pin configured as an input pin has no effect.
891 //!
892 //! The pin(s) are specified using a bit-packed byte, where each bit that is
893 //! set identifies the pin to be accessed, and where bit 0 of the byte
894 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
895 //!
896 //! \return None.
897 //
898 //*****************************************************************************
899 void
GPIOPinWrite(unsigned long ulPort,unsigned char ucPins,unsigned char ucVal)900 GPIOPinWrite(unsigned long ulPort, unsigned char ucPins, unsigned char ucVal)
901 {
902     //
903     // Check the arguments.
904     //
905     ASSERT(GPIOBaseValid(ulPort));
906 
907     //
908     // Write the pins.
909     //
910     HWREG(ulPort + (GPIO_O_DATA + (ucPins << 2))) = ucVal;
911 }
912 
913 //*****************************************************************************
914 //
915 //! Configures pin(s) for use as analog-to-digital converter inputs.
916 //!
917 //! \param ulPort is the base address of the GPIO port.
918 //! \param ucPins is the bit-packed representation of the pin(s).
919 //!
920 //! The analog-to-digital converter input pins must be properly configured
921 //! to function correctly on devices that are not Sandstorm- or Fury-class.
922 //! This function provides the proper configuration for those pin(s).
923 //!
924 //! The pin(s) are specified using a bit-packed byte, where each bit that is
925 //! set identifies the pin to be accessed, and where bit 0 of the byte
926 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
927 //!
928 //! \note This function cannot be used to turn any pin into an ADC input; it
929 //! only configures an ADC input pin for proper operation.  Devices with
930 //! flexible pin muxing also require a GPIOPinConfigure() function call.
931 //!
932 //! \return None.
933 //
934 //*****************************************************************************
935 void
GPIOPinTypeADC(unsigned long ulPort,unsigned char ucPins)936 GPIOPinTypeADC(unsigned long ulPort, unsigned char ucPins)
937 {
938     //
939     // Check the arguments.
940     //
941     ASSERT(GPIOBaseValid(ulPort));
942 
943     //
944     // Make the pin(s) be inputs.
945     //
946     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_IN);
947 
948     //
949     // Set the pad(s) for analog operation.
950     //
951     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_ANALOG);
952 }
953 
954 //*****************************************************************************
955 //
956 //! Configures pin(s) for use as a CAN device.
957 //!
958 //! \param ulPort is the base address of the GPIO port.
959 //! \param ucPins is the bit-packed representation of the pin(s).
960 //!
961 //! The CAN pins must be properly configured for the CAN peripherals to
962 //! function correctly.  This function provides a typical configuration for
963 //! those pin(s); other configurations may work as well depending upon the
964 //! board setup (for example, using the on-chip pull-ups).
965 //!
966 //! The pin(s) are specified using a bit-packed byte, where each bit that is
967 //! set identifies the pin to be accessed, and where bit 0 of the byte
968 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
969 //!
970 //! \note This function cannot be used to turn any pin into a CAN pin; it only
971 //! configures a CAN pin for proper operation.  Devices with flexible pin
972 //! muxing also require a GPIOPinConfigure() function call.
973 //!
974 //! \return None.
975 //
976 //*****************************************************************************
977 void
GPIOPinTypeCAN(unsigned long ulPort,unsigned char ucPins)978 GPIOPinTypeCAN(unsigned long ulPort, unsigned char ucPins)
979 {
980     //
981     // Check the arguments.
982     //
983     ASSERT(GPIOBaseValid(ulPort));
984 
985     //
986     // Make the pin(s) be inputs.
987     //
988     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
989 
990     //
991     // Set the pad(s) for standard push-pull operation.
992     //
993     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
994 }
995 
996 //*****************************************************************************
997 //
998 //! Configures pin(s) for use as an analog comparator input.
999 //!
1000 //! \param ulPort is the base address of the GPIO port.
1001 //! \param ucPins is the bit-packed representation of the pin(s).
1002 //!
1003 //! The analog comparator input pins must be properly configured for the analog
1004 //! comparator to function correctly.  This function provides the proper
1005 //! configuration for those pin(s).
1006 //!
1007 //! The pin(s) are specified using a bit-packed byte, where each bit that is
1008 //! set identifies the pin to be accessed, and where bit 0 of the byte
1009 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1010 //!
1011 //! \note This function cannot be used to turn any pin into an analog comparator
1012 //! input; it only configures an analog comparator pin for proper operation.
1013 //! Devices with flexible pin muxing also require a GPIOPinConfigure()
1014 //! function call.
1015 //!
1016 //! \return None.
1017 //
1018 //*****************************************************************************
1019 void
GPIOPinTypeComparator(unsigned long ulPort,unsigned char ucPins)1020 GPIOPinTypeComparator(unsigned long ulPort, unsigned char ucPins)
1021 {
1022     //
1023     // Check the arguments.
1024     //
1025     ASSERT(GPIOBaseValid(ulPort));
1026 
1027     //
1028     // Make the pin(s) be inputs.
1029     //
1030     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_IN);
1031 
1032     //
1033     // Set the pad(s) for analog operation.
1034     //
1035     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_ANALOG);
1036 }
1037 
1038 //*****************************************************************************
1039 //
1040 //! Configures pin(s) for use by the external peripheral interface.
1041 //!
1042 //! \param ulPort is the base address of the GPIO port.
1043 //! \param ucPins is the bit-packed representation of the pin(s).
1044 //!
1045 //! The external peripheral interface pins must be properly configured for the
1046 //! external peripheral interface to function correctly.  This function
1047 //! provides a typical configuration for those pin(s); other configurations may
1048 //! work as well depending upon the board setup (for example, using the on-chip
1049 //! pull-ups).
1050 //!
1051 //! The pin(s) are specified using a bit-packed byte, where each bit that is
1052 //! set identifies the pin to be accessed, and where bit 0 of the byte
1053 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1054 //!
1055 //! \note This function cannot be used to turn any pin into an external
1056 //! peripheral interface pin; it only configures an external peripheral
1057 //! interface pin for proper operation.  Devices with flexible pin muxing also
1058 //! require a GPIOPinConfigure() function call.
1059 //!
1060 //! \return None.
1061 //
1062 //*****************************************************************************
1063 void
GPIOPinTypeEPI(unsigned long ulPort,unsigned char ucPins)1064 GPIOPinTypeEPI(unsigned long ulPort, unsigned char ucPins)
1065 {
1066     //
1067     // Check the arguments.
1068     //
1069     ASSERT(GPIOBaseValid(ulPort));
1070 
1071     //
1072     // Make the pin(s) be peripheral controlled.
1073     //
1074     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1075 
1076     //
1077     // Set the pad(s) for standard push-pull operation.
1078     //
1079     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
1080 }
1081 
1082 //*****************************************************************************
1083 //
1084 //! Configures pin(s) for use by the Ethernet peripheral as LED signals.
1085 //!
1086 //! \param ulPort is the base address of the GPIO port.
1087 //! \param ucPins is the bit-packed representation of the pin(s).
1088 //!
1089 //! The Ethernet peripheral provides two signals that can be used to drive
1090 //! an LED (e.g. for link status/activity).  This function provides a typical
1091 //! configuration for the pins.
1092 //!
1093 //! The pin(s) are specified using a bit-packed byte, where each bit that is
1094 //! set identifies the pin to be accessed, and where bit 0 of the byte
1095 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1096 //!
1097 //! \note This function cannot be used to turn any pin into an Ethernet LED
1098 //! pin; it only configures an Ethernet LED pin for proper operation.  Devices
1099 //! with flexible pin muxing also require a GPIOPinConfigure() function call.
1100 //!
1101 //! \return None.
1102 //
1103 //*****************************************************************************
1104 void
GPIOPinTypeEthernetLED(unsigned long ulPort,unsigned char ucPins)1105 GPIOPinTypeEthernetLED(unsigned long ulPort, unsigned char ucPins)
1106 {
1107     //
1108     // Check the arguments.
1109     //
1110     ASSERT(GPIOBaseValid(ulPort));
1111 
1112     //
1113     // Make the pin(s) be peripheral controlled.
1114     //
1115     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1116 
1117     //
1118     // Set the pad(s) for standard push-pull operation.
1119     //
1120     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
1121 }
1122 
1123 //*****************************************************************************
1124 //
1125 //! Configures pin(s) for use by the Ethernet peripheral as MII signals.
1126 //!
1127 //! \param ulPort is the base address of the GPIO port.
1128 //! \param ucPins is the bit-packed representation of the pin(s).
1129 //!
1130 //! The Ethernet peripheral on some parts provides a set of MII signals that
1131 //! are used to connect to an external PHY.  This function provides a typical
1132 //! configuration for the pins.
1133 //!
1134 //! The pin(s) are specified using a bit-packed byte, where each bit that is
1135 //! set identifies the pin to be accessed, and where bit 0 of the byte
1136 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1137 //!
1138 //! \note This function cannot be used to turn any pin into an Ethernet MII
1139 //! pin; it only configures an Ethernet MII pin for proper operation.  Devices
1140 //! with flexible pin muxing also require a GPIOPinConfigure() function call.
1141 //!
1142 //! \return None.
1143 //
1144 //*****************************************************************************
1145 void
GPIOPinTypeEthernetMII(unsigned long ulPort,unsigned char ucPins)1146 GPIOPinTypeEthernetMII(unsigned long ulPort, unsigned char ucPins)
1147 {
1148     //
1149     // Check the arguments.
1150     //
1151     ASSERT(GPIOBaseValid(ulPort));
1152 
1153     //
1154     // Make the pin(s) be peripheral controlled.
1155     //
1156     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1157 
1158     //
1159     // Set the pad(s) for standard push-pull operation.
1160     //
1161     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
1162 }
1163 
1164 //*****************************************************************************
1165 //
1166 //! Configures pin(s) for use by the fan module.
1167 //!
1168 //! \param ulPort is the base address of the GPIO port.
1169 //! \param ucPins is the bit-packed representation of the pin(s).
1170 //!
1171 //! The fan pins must be properly configured for the fan controller to function
1172 //! correctly.  This function provides a typical configuration for those
1173 //! pin(s); other configurations may work as well depending upon the board
1174 //! setup (for example, using the on-chip pull-ups).
1175 //!
1176 //! The pin(s) are specified using a bit-packed byte, where each bit that is
1177 //! set identifies the pin to be accessed, and where bit 0 of the byte
1178 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1179 //!
1180 //! \note This function cannot be used to turn any pin into a fan pin; it only
1181 //! configures a fan pin for proper operation.  Devices with flexible pin
1182 //! muxing also require a GPIOPinConfigure() function call.
1183 //!
1184 //! \return None.
1185 //
1186 //*****************************************************************************
1187 void
GPIOPinTypeFan(unsigned long ulPort,unsigned char ucPins)1188 GPIOPinTypeFan(unsigned long ulPort, unsigned char ucPins)
1189 {
1190     //
1191     // Check the arguments.
1192     //
1193     ASSERT(GPIOBaseValid(ulPort));
1194 
1195     //
1196     // Make the pin(s) be peripheral controlled.
1197     //
1198     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1199 
1200     //
1201     // Set the pad(s) for standard push-pull operation.
1202     //
1203     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
1204 }
1205 
1206 //*****************************************************************************
1207 //
1208 //! Configures pin(s) for use as GPIO inputs.
1209 //!
1210 //! \param ulPort is the base address of the GPIO port.
1211 //! \param ucPins is the bit-packed representation of the pin(s).
1212 //!
1213 //! The GPIO pins must be properly configured in order to function correctly as
1214 //! GPIO inputs; this is especially true of Fury-class devices where the
1215 //! digital input enable is turned off by default.  This function provides the
1216 //! proper configuration for those pin(s).
1217 //!
1218 //! The pin(s) are specified using a bit-packed byte, where each bit that is
1219 //! set identifies the pin to be accessed, and where bit 0 of the byte
1220 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1221 //!
1222 //! \return None.
1223 //
1224 //*****************************************************************************
1225 void
GPIOPinTypeGPIOInput(unsigned long ulPort,unsigned char ucPins)1226 GPIOPinTypeGPIOInput(unsigned long ulPort, unsigned char ucPins)
1227 {
1228     //
1229     // Check the arguments.
1230     //
1231     ASSERT(GPIOBaseValid(ulPort));
1232 
1233     //
1234     // Make the pin(s) be inputs.
1235     //
1236     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_IN);
1237 
1238     //
1239     // Set the pad(s) for standard push-pull operation.
1240     //
1241     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
1242 }
1243 
1244 //*****************************************************************************
1245 //
1246 //! Configures pin(s) for use as GPIO outputs.
1247 //!
1248 //! \param ulPort is the base address of the GPIO port.
1249 //! \param ucPins is the bit-packed representation of the pin(s).
1250 //!
1251 //! The GPIO pins must be properly configured in order to function correctly as
1252 //! GPIO outputs; this is especially true of Fury-class devices where the
1253 //! digital input enable is turned off by default.  This function provides the
1254 //! proper configuration for those pin(s).
1255 //!
1256 //! The pin(s) are specified using a bit-packed byte, where each bit that is
1257 //! set identifies the pin to be accessed, and where bit 0 of the byte
1258 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1259 //!
1260 //! \return None.
1261 //
1262 //*****************************************************************************
1263 void
GPIOPinTypeGPIOOutput(unsigned long ulPort,unsigned char ucPins)1264 GPIOPinTypeGPIOOutput(unsigned long ulPort, unsigned char ucPins)
1265 {
1266     //
1267     // Check the arguments.
1268     //
1269     ASSERT(GPIOBaseValid(ulPort));
1270 
1271     //
1272     // Set the pad(s) for standard push-pull operation.
1273     //
1274     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
1275 
1276     //
1277     // Make the pin(s) be outputs.
1278     //
1279     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_OUT);
1280 }
1281 
1282 //*****************************************************************************
1283 //
1284 //! Configures pin(s) for use as GPIO open drain outputs.
1285 //!
1286 //! \param ulPort is the base address of the GPIO port.
1287 //! \param ucPins is the bit-packed representation of the pin(s).
1288 //!
1289 //! The GPIO pins must be properly configured in order to function correctly as
1290 //! GPIO outputs; this is especially true of Fury-class devices where the
1291 //! digital input enable is turned off by default.  This function provides the
1292 //! proper configuration for those pin(s).
1293 //!
1294 //! The pin(s) are specified using a bit-packed byte, where each bit that is
1295 //! set identifies the pin to be accessed, and where bit 0 of the byte
1296 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1297 //!
1298 //! \return None.
1299 //
1300 //*****************************************************************************
1301 void
GPIOPinTypeGPIOOutputOD(unsigned long ulPort,unsigned char ucPins)1302 GPIOPinTypeGPIOOutputOD(unsigned long ulPort, unsigned char ucPins)
1303 {
1304     //
1305     // Check the arguments.
1306     //
1307     ASSERT(GPIOBaseValid(ulPort));
1308 
1309     //
1310     // Set the pad(s) for standard push-pull operation.
1311     //
1312     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);
1313 
1314     //
1315     // Make the pin(s) be outputs.
1316     //
1317     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_OUT);
1318 }
1319 
1320 //*****************************************************************************
1321 //
1322 //! Configures pin(s) for use by the I2C peripheral.
1323 //!
1324 //! \param ulPort is the base address of the GPIO port.
1325 //! \param ucPins is the bit-packed representation of the pin(s).
1326 //!
1327 //! The I2C pins must be properly configured for the I2C peripheral to function
1328 //! correctly.  This function provides the proper configuration for those
1329 //! pin(s).
1330 //!
1331 //! The pin(s) are specified using a bit-packed byte, where each bit that is
1332 //! set identifies the pin to be accessed, and where bit 0 of the byte
1333 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1334 //!
1335 //! \note This function cannot be used to turn any pin into an I2C pin; it
1336 //! only configures an I2C pin for proper operation.  Devices with flexible pin
1337 //! muxing also require a GPIOPinConfigure() function call.
1338 //!
1339 //! \return None.
1340 //
1341 //*****************************************************************************
1342 void
GPIOPinTypeI2C(unsigned long ulPort,unsigned char ucPins)1343 GPIOPinTypeI2C(unsigned long ulPort, unsigned char ucPins)
1344 {
1345     //
1346     // Check the arguments.
1347     //
1348     ASSERT(GPIOBaseValid(ulPort));
1349 
1350     //
1351     // Make the pin(s) be peripheral controlled.
1352     //
1353     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1354 
1355     //
1356     // Set the pad(s) for open-drain operation with a weak pull-up.
1357     //
1358     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD_WPU);
1359 }
1360 
1361 //*****************************************************************************
1362 //
1363 //! Configures pin(s) for use as SCL by the I2C peripheral.
1364 //!
1365 //! \param ulPort is the base address of the GPIO port.
1366 //! \param ucPins is the bit-packed representation of the pin(s).
1367 //!
1368 //! The I2C pins must be properly configured for the I2C peripheral to function
1369 //! correctly.  This function provides the proper configuration for the SCL
1370 //! pin(s).
1371 //!
1372 //! The pin(s) are specified using a bit-packed byte, where each bit that is
1373 //! set identifies the pin to be accessed, and where bit 0 of the byte
1374 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1375 //!
1376 //! \note This function should only be used for Blizzard-class devices.  It
1377 //! cannot be used to turn any pin into an I2C SCL pin; it only configures an
1378 //! I2C SCL pin for proper operation.  Devices with flexible pin muxing also
1379 //! require a GPIOPinConfigure() function call.
1380 //!
1381 //! \return None.
1382 //
1383 //*****************************************************************************
1384 void
GPIOPinTypeI2CSCL(unsigned long ulPort,unsigned char ucPins)1385 GPIOPinTypeI2CSCL(unsigned long ulPort, unsigned char ucPins)
1386 {
1387     //
1388     // Check the arguments.
1389     //
1390     ASSERT(GPIOBaseValid(ulPort));
1391 
1392     //
1393     // Make the pin(s) be peripheral controlled.
1394     //
1395     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1396 
1397     //
1398     // Set the pad(s) for open-drain operation with a weak pull-up.
1399     //
1400     if(CLASS_IS_SANDSTORM || CLASS_IS_FURY || CLASS_IS_DUSTDEVIL ||
1401        CLASS_IS_TEMPEST || CLASS_IS_FIRESTORM)
1402     {
1403         GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);
1404     }
1405     else
1406     {
1407         GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
1408     }
1409 }
1410 
1411 //*****************************************************************************
1412 //
1413 //! Configures pin(s) for use by the I2S peripheral.
1414 //!
1415 //! \param ulPort is the base address of the GPIO port.
1416 //! \param ucPins is the bit-packed representation of the pin(s).
1417 //!
1418 //! Some I2S pins must be properly configured for the I2S peripheral to
1419 //! function correctly.  This function provides a typical configuration for
1420 //! the digital I2S pin(s); other configurations may work as well depending
1421 //! upon the board setup (for example, using the on-chip pull-ups).
1422 //!
1423 //! The pin(s) are specified using a bit-packed byte, where each bit that is
1424 //! set identifies the pin to be accessed, and where bit 0 of the byte
1425 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1426 //!
1427 //! \note This function cannot be used to turn any pin into a I2S pin; it only
1428 //! configures a I2S pin for proper operation.  Devices with flexible pin
1429 //! muxing also require a GPIOPinConfigure() function call.
1430 //!
1431 //! \return None.
1432 //
1433 //*****************************************************************************
1434 void
GPIOPinTypeI2S(unsigned long ulPort,unsigned char ucPins)1435 GPIOPinTypeI2S(unsigned long ulPort, unsigned char ucPins)
1436 {
1437     //
1438     // Check the arguments.
1439     //
1440     ASSERT(GPIOBaseValid(ulPort));
1441 
1442     //
1443     // Make the pin(s) be peripheral controlled.
1444     //
1445     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1446 
1447     //
1448     // Set the pad(s) for standard push-pull operation.
1449     //
1450     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
1451 }
1452 
1453 //*****************************************************************************
1454 //
1455 //! Configures pin(s) for use by the LPC module.
1456 //!
1457 //! \param ulPort is the base address of the GPIO port.
1458 //! \param ucPins is the bit-packed representation of the pin(s).
1459 //!
1460 //! The LPC pins must be properly configured for the LPC module to function
1461 //! correctly.  This function provides a typical configuration for those
1462 //! pin(s); other configurations may work as well depending upon the board
1463 //! setup (for example, using the on-chip pull-ups).
1464 //!
1465 //! The pin(s) are specified using a bit-packed byte, where each bit that is
1466 //! set identifies the pin to be accessed, and where bit 0 of the byte
1467 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1468 //!
1469 //! \note This function cannot be used to turn any pin into an LPC pin; it only
1470 //! configures an LPC pin for proper operation.  Devices with flexible pin
1471 //! muxing also require a GPIOPinConfigure() function call.
1472 //!
1473 //! \return None.
1474 //
1475 //*****************************************************************************
1476 void
GPIOPinTypeLPC(unsigned long ulPort,unsigned char ucPins)1477 GPIOPinTypeLPC(unsigned long ulPort, unsigned char ucPins)
1478 {
1479     //
1480     // Check the arguments.
1481     //
1482     ASSERT(GPIOBaseValid(ulPort));
1483 
1484     //
1485     // Make the pin(s) be peripheral controlled.
1486     //
1487     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1488 
1489     //
1490     // Set the pad(s) for standard push-pull operation.
1491     //
1492     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
1493 }
1494 
1495 //*****************************************************************************
1496 //
1497 //! Configures a pin for receive use by the PECI module.
1498 //!
1499 //! \param ulPort is the base address of the GPIO port.
1500 //! \param ucPins is the bit-packed representation of the pin(s).
1501 //!
1502 //! The PECI receive pin must be properly configured for the PECI module to
1503 //! function correctly.  This function provides a typical configuration for
1504 //! that pin.
1505 //!
1506 //! The pin is specified using a bit-packed byte, where each bit that is set
1507 //! identifies the pin to be accessed, and where bit 0 of the byte represents
1508 //! GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1509 //!
1510 //! \note This function cannot be used to turn any pin into a PECI receive pin;
1511 //! it only configures a PECI receive pin for proper operation.  Devices with
1512 //! flexible pin muxing also require a GPIOPinConfigure() function call.
1513 //!
1514 //! \return None.
1515 //
1516 //*****************************************************************************
1517 void
GPIOPinTypePECIRx(unsigned long ulPort,unsigned char ucPins)1518 GPIOPinTypePECIRx(unsigned long ulPort, unsigned char ucPins)
1519 {
1520     //
1521     // Check the arguments.
1522     //
1523     ASSERT(GPIOBaseValid(ulPort));
1524 
1525     //
1526     // Make the pin(s) be inputs.
1527     //
1528     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_IN);
1529 
1530     //
1531     // Set the pad(s) for analog operation.
1532     //
1533     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_ANALOG);
1534 }
1535 
1536 //*****************************************************************************
1537 //
1538 //! Configures a pin for transmit use by the PECI module.
1539 //!
1540 //! \param ulPort is the base address of the GPIO port.
1541 //! \param ucPins is the bit-packed representation of the pin(s).
1542 //!
1543 //! The PECI transmit pin must be properly configured for the PECI module to
1544 //! function correctly.  This function provides a typical configuration for
1545 //! that pin.
1546 //!
1547 //! The pin is specified using a bit-packed byte, where each bit that is set
1548 //! identifies the pin to be accessed, and where bit 0 of the byte represents
1549 //! GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1550 //!
1551 //! \note This function cannot be used to turn any pin into a PECI transmit
1552 //! pin; it only configures a PECI transmit pin for proper operation.  Devices
1553 //! with flexible pin muxing also require a GPIOPinConfigure() function call.
1554 //!
1555 //! \return None.
1556 //
1557 //*****************************************************************************
1558 void
GPIOPinTypePECITx(unsigned long ulPort,unsigned char ucPins)1559 GPIOPinTypePECITx(unsigned long ulPort, unsigned char ucPins)
1560 {
1561     //
1562     // Check the arguments.
1563     //
1564     ASSERT(GPIOBaseValid(ulPort));
1565 
1566     //
1567     // Make the pin(s) be inputs.
1568     //
1569     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1570 
1571     //
1572     // Set the pad(s) for analog operation.
1573     //
1574     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
1575 }
1576 
1577 //*****************************************************************************
1578 //
1579 //! Configures pin(s) for use by the PWM peripheral.
1580 //!
1581 //! \param ulPort is the base address of the GPIO port.
1582 //! \param ucPins is the bit-packed representation of the pin(s).
1583 //!
1584 //! The PWM pins must be properly configured for the PWM peripheral to function
1585 //! correctly.  This function provides a typical configuration for those
1586 //! pin(s); other configurations may work as well depending upon the board
1587 //! setup (for example, using the on-chip pull-ups).
1588 //!
1589 //! The pin(s) are specified using a bit-packed byte, where each bit that is
1590 //! set identifies the pin to be accessed, and where bit 0 of the byte
1591 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1592 //!
1593 //! \note This function cannot be used to turn any pin into a PWM pin; it only
1594 //! configures a PWM pin for proper operation.  Devices wtih flexible pin
1595 //! muxing also require a GPIOPinConfigure() function call.
1596 //!
1597 //! \return None.
1598 //
1599 //*****************************************************************************
1600 void
GPIOPinTypePWM(unsigned long ulPort,unsigned char ucPins)1601 GPIOPinTypePWM(unsigned long ulPort, unsigned char ucPins)
1602 {
1603     //
1604     // Check the arguments.
1605     //
1606     ASSERT(GPIOBaseValid(ulPort));
1607 
1608     //
1609     // Make the pin(s) be peripheral controlled.
1610     //
1611     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1612 
1613     //
1614     // Set the pad(s) for standard push-pull operation.
1615     //
1616     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
1617 }
1618 
1619 //*****************************************************************************
1620 //
1621 //! Configures pin(s) for use by the QEI peripheral.
1622 //!
1623 //! \param ulPort is the base address of the GPIO port.
1624 //! \param ucPins is the bit-packed representation of the pin(s).
1625 //!
1626 //! The QEI pins must be properly configured for the QEI peripheral to function
1627 //! correctly.  This function provides a typical configuration for those
1628 //! pin(s); other configurations may work as well depending upon the board
1629 //! setup (for example, not using the on-chip pull-ups).
1630 //!
1631 //! The pin(s) are specified using a bit-packed byte, where each bit that is
1632 //! set identifies the pin to be accessed, and where bit 0 of the byte
1633 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1634 //!
1635 //! \note This function cannot be used to turn any pin into a QEI pin; it only
1636 //! configures a QEI pin for proper operation.  Devices with flexible pin
1637 //! muxing also require a GPIOPinConfigure() function call.
1638 //!
1639 //! \return None.
1640 //
1641 //*****************************************************************************
1642 void
GPIOPinTypeQEI(unsigned long ulPort,unsigned char ucPins)1643 GPIOPinTypeQEI(unsigned long ulPort, unsigned char ucPins)
1644 {
1645     //
1646     // Check the arguments.
1647     //
1648     ASSERT(GPIOBaseValid(ulPort));
1649 
1650     //
1651     // Make the pin(s) be peripheral controlled.
1652     //
1653     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1654 
1655     //
1656     // Set the pad(s) for standard push-pull operation with a weak pull-up.
1657     //
1658     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
1659 }
1660 
1661 //*****************************************************************************
1662 //
1663 //! Configures pin(s) for use by the SSI peripheral.
1664 //!
1665 //! \param ulPort is the base address of the GPIO port.
1666 //! \param ucPins is the bit-packed representation of the pin(s).
1667 //!
1668 //! The SSI pins must be properly configured for the SSI peripheral to function
1669 //! correctly.  This function provides a typical configuration for those
1670 //! pin(s); other configurations may work as well depending upon the board
1671 //! setup (for example, using the on-chip pull-ups).
1672 //!
1673 //! The pin(s) are specified using a bit-packed byte, where each bit that is
1674 //! set identifies the pin to be accessed, and where bit 0 of the byte
1675 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1676 //!
1677 //! \note This function cannot be used to turn any pin into a SSI pin; it only
1678 //! configures a SSI pin for proper operation.  Devices with flexible pin
1679 //! muxing also require a GPIOPinConfigure() function call.
1680 //!
1681 //! \return None.
1682 //
1683 //*****************************************************************************
1684 void
GPIOPinTypeSSI(unsigned long ulPort,unsigned char ucPins)1685 GPIOPinTypeSSI(unsigned long ulPort, unsigned char ucPins)
1686 {
1687     //
1688     // Check the arguments.
1689     //
1690     ASSERT(GPIOBaseValid(ulPort));
1691 
1692     //
1693     // Make the pin(s) be peripheral controlled.
1694     //
1695     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1696 
1697     //
1698     // Set the pad(s) for standard push-pull operation.
1699     //
1700     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
1701 }
1702 
1703 //*****************************************************************************
1704 //
1705 //! Configures pin(s) for use by the Timer peripheral.
1706 //!
1707 //! \param ulPort is the base address of the GPIO port.
1708 //! \param ucPins is the bit-packed representation of the pin(s).
1709 //!
1710 //! The CCP pins must be properly configured for the timer peripheral to
1711 //! function correctly.  This function provides a typical configuration for
1712 //! those pin(s); other configurations may work as well depending upon the
1713 //! board setup (for example, using the on-chip pull-ups).
1714 //!
1715 //! The pin(s) are specified using a bit-packed byte, where each bit that is
1716 //! set identifies the pin to be accessed, and where bit 0 of the byte
1717 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1718 //!
1719 //! \note This function cannot be used to turn any pin into a timer pin; it
1720 //! only configures a timer pin for proper operation.  Devices with flexible
1721 //! pin muxing also require a GPIOPinConfigure() function call.
1722 //!
1723 //! \return None.
1724 //
1725 //*****************************************************************************
1726 void
GPIOPinTypeTimer(unsigned long ulPort,unsigned char ucPins)1727 GPIOPinTypeTimer(unsigned long ulPort, unsigned char ucPins)
1728 {
1729     //
1730     // Check the arguments.
1731     //
1732     ASSERT(GPIOBaseValid(ulPort));
1733 
1734     //
1735     // Make the pin(s) be peripheral controlled.
1736     //
1737     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1738 
1739     //
1740     // Set the pad(s) for standard push-pull operation.
1741     //
1742     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
1743 }
1744 
1745 //*****************************************************************************
1746 //
1747 //! Configures pin(s) for use by the UART peripheral.
1748 //!
1749 //! \param ulPort is the base address of the GPIO port.
1750 //! \param ucPins is the bit-packed representation of the pin(s).
1751 //!
1752 //! The UART pins must be properly configured for the UART peripheral to
1753 //! function correctly.  This function provides a typical configuration for
1754 //! those pin(s); other configurations may work as well depending upon the
1755 //! board setup (for example, using the on-chip pull-ups).
1756 //!
1757 //! The pin(s) are specified using a bit-packed byte, where each bit that is
1758 //! set identifies the pin to be accessed, and where bit 0 of the byte
1759 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1760 //!
1761 //! \note This function cannot be used to turn any pin into a UART pin; it
1762 //! only configures a UART pin for proper operation.  Devices with flexible
1763 //! pin muxing also require a GPIOPinConfigure() function call.
1764 //!
1765 //! \return None.
1766 //
1767 //*****************************************************************************
1768 void
GPIOPinTypeUART(unsigned long ulPort,unsigned char ucPins)1769 GPIOPinTypeUART(unsigned long ulPort, unsigned char ucPins)
1770 {
1771     //
1772     // Check the arguments.
1773     //
1774     ASSERT(GPIOBaseValid(ulPort));
1775 
1776     //
1777     // Make the pin(s) be peripheral controlled.
1778     //
1779     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1780 
1781     //
1782     // Set the pad(s) for standard push-pull operation.
1783     //
1784     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
1785 }
1786 
1787 //*****************************************************************************
1788 //
1789 //! Configures pin(s) for use by the USB peripheral.
1790 //!
1791 //! \param ulPort is the base address of the GPIO port.
1792 //! \param ucPins is the bit-packed representation of the pin(s).
1793 //!
1794 //! Some USB analog pins must be properly configured for the USB peripheral to
1795 //! function correctly.  This function provides the proper configuration for
1796 //! any USB pin(s).  This can also be used to configure the EPEN and PFAULT pins
1797 //! so that they are no longer used by the USB controller.
1798 //!
1799 //! The pin(s) are specified using a bit-packed byte, where each bit that is
1800 //! set identifies the pin to be accessed, and where bit 0 of the byte
1801 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1802 //!
1803 //! \note This function cannot be used to turn any pin into a USB pin; it only
1804 //! configures a USB pin for proper operation.  Devices with flexible pin
1805 //! muxing also require a GPIOPinConfigure() function call.
1806 //!
1807 //! \return None.
1808 //
1809 //*****************************************************************************
1810 void
GPIOPinTypeUSBAnalog(unsigned long ulPort,unsigned char ucPins)1811 GPIOPinTypeUSBAnalog(unsigned long ulPort, unsigned char ucPins)
1812 {
1813     //
1814     // Check the arguments.
1815     //
1816     ASSERT(GPIOBaseValid(ulPort));
1817 
1818     //
1819     // Make the pin(s) be inputs.
1820     //
1821     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_IN);
1822 
1823     //
1824     // Set the pad(s) for analog operation.
1825     //
1826     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_ANALOG);
1827 }
1828 
1829 //*****************************************************************************
1830 //
1831 //! Configures pin(s) for use by the USB peripheral.
1832 //!
1833 //! \param ulPort is the base address of the GPIO port.
1834 //! \param ucPins is the bit-packed representation of the pin(s).
1835 //!
1836 //! Some USB digital pins must be properly configured for the USB peripheral to
1837 //! function correctly.  This function provides a typical configuration for
1838 //! the digital USB pin(s); other configurations may work as well depending
1839 //! upon the board setup (for example, using the on-chip pull-ups).
1840 //!
1841 //! This function should only be used with EPEN and PFAULT pins as all other
1842 //! USB pins are analog in nature or are not used in devices without OTG
1843 //! functionality.
1844 //!
1845 //! The pin(s) are specified using a bit-packed byte, where each bit that is
1846 //! set identifies the pin to be accessed, and where bit 0 of the byte
1847 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
1848 //!
1849 //! \note This function cannot be used to turn any pin into a USB pin; it only
1850 //! configures a USB pin for proper operation.  Devices with flexible pin
1851 //! muxing also require a GPIOPinConfigure() function call.
1852 //!
1853 //! \return None.
1854 //
1855 //*****************************************************************************
1856 void
GPIOPinTypeUSBDigital(unsigned long ulPort,unsigned char ucPins)1857 GPIOPinTypeUSBDigital(unsigned long ulPort, unsigned char ucPins)
1858 {
1859     //
1860     // Check the arguments.
1861     //
1862     ASSERT(GPIOBaseValid(ulPort));
1863 
1864     //
1865     // Make the pin(s) be peripheral controlled.
1866     //
1867     GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1868 
1869     //
1870     // Set the pad(s) for standard push-pull operation.
1871     //
1872     GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
1873 }
1874 
1875 //*****************************************************************************
1876 //
1877 //! Configures the alternate function of a GPIO pin.
1878 //!
1879 //! \param ulPinConfig is the pin configuration value, specified as only one of
1880 //! the \b GPIO_P??_??? values.
1881 //!
1882 //! This function configures the pin mux that selects the peripheral function
1883 //! associated with a particular GPIO pin.  Only one peripheral function at a
1884 //! time can be associated with a GPIO pin, and each peripheral function should
1885 //! only be associated with a single GPIO pin at a time (despite the fact that
1886 //! many of them can be associated with more than one GPIO pin). To fully
1887 //! configure a pin, a GPIOPinType*() function should also be called.
1888 //!
1889 //! The available mappings are supplied on a per-device basis in
1890 //! <tt>pin_map.h</tt>.  The \b PART_IS_<partno> define enables the
1891 //! appropriate set of defines for the device that is being used.
1892 //!
1893 //! \note This function is not valid on Sandstorm, Fury, and Dustdevil-class
1894 //! devices. Also, if the same signal is assigned to two different GPIO port
1895 //! pins, the signal is assigned to the port with the lowest letter and the
1896 //! assignment to the higher letter port is ignored.
1897 //!
1898 //! \return None.
1899 //
1900 //*****************************************************************************
1901 void
GPIOPinConfigure(unsigned long ulPinConfig)1902 GPIOPinConfigure(unsigned long ulPinConfig)
1903 {
1904     unsigned long ulBase, ulShift;
1905 
1906     //
1907     // Check the argument.
1908     //
1909     ASSERT(((ulPinConfig >> 16) & 0xff) < 15);
1910     ASSERT(((ulPinConfig >> 8) & 0xe3) == 0);
1911 
1912     //
1913     // Extract the base address index from the input value.
1914     //
1915     ulBase = (ulPinConfig >> 16) & 0xff;
1916 
1917     //
1918     // Get the base address of the GPIO module, selecting either the APB or the
1919     // AHB aperture as appropriate.
1920     //
1921     if(HWREG(SYSCTL_GPIOHBCTL) & (1 << ulBase))
1922     {
1923         ulBase = g_pulGPIOBaseAddrs[(ulBase << 1) + 1];
1924     }
1925     else
1926     {
1927         ulBase = g_pulGPIOBaseAddrs[ulBase << 1];
1928     }
1929 
1930     //
1931     // Extract the shift from the input value.
1932     //
1933     ulShift = (ulPinConfig >> 8) & 0xff;
1934 
1935     //
1936     // Write the requested pin muxing value for this GPIO pin.
1937     //
1938     HWREG(ulBase + GPIO_O_PCTL) = ((HWREG(ulBase + GPIO_O_PCTL) &
1939                                     ~(0xf << ulShift)) |
1940                                    ((ulPinConfig & 0xf) << ulShift));
1941 }
1942 
1943 //*****************************************************************************
1944 //
1945 //! Enables a GPIO pin as a trigger to start a DMA transaction.
1946 //!
1947 //! \param ulPort is the base address of the GPIO port.
1948 //! \param ucPins is the bit-packed representation of the pin(s).
1949 //!
1950 //! This function enables a GPIO pin to be used as a trigger to start a uDMA
1951 //! transaction.  Any GPIO pin can be configured to be an external trigger for
1952 //! the uDMA.  The GPIO pin still generates interrupts if the interrupt is
1953 //! enabled for the selected pin.
1954 //!
1955 //! \note This function is not available on all devices, consult the data sheet
1956 //! to ensure that the device you are using supports GPIO DMA Control.
1957 //!
1958 //! \return None.
1959 //
1960 //*****************************************************************************
1961 void
GPIODMATriggerEnable(unsigned long ulPort,unsigned char ucPins)1962 GPIODMATriggerEnable(unsigned long ulPort, unsigned char ucPins)
1963 {
1964     //
1965     // Check the arguments.
1966     //
1967     ASSERT(GPIOBaseValid(ulPort));
1968 
1969     //
1970     // Set the pin as a DMA trigger.
1971     //
1972     HWREG(ulPort + GPIO_O_DMACTL) |= ucPins;
1973 }
1974 
1975 //*****************************************************************************
1976 //
1977 //! Disables a GPIO pin as a trigger to start a DMA transaction.
1978 //!
1979 //! \param ulPort is the base address of the GPIO port.
1980 //! \param ucPins is the bit-packed representation of the pin(s).
1981 //!
1982 //! This function disables a GPIO pin from being used as a trigger to start a
1983 //! uDMA transaction.  This function can be used to disable this feature if it
1984 //! was enabled via a call to GPIODMATriggerEnable().
1985 //!
1986 //! \note This function is not available on all devices, consult the data sheet
1987 //! to ensure that the device you are using supports GPIO DMA Control.
1988 //!
1989 //! \return None.
1990 //
1991 //*****************************************************************************
1992 void
GPIODMATriggerDisable(unsigned long ulPort,unsigned char ucPins)1993 GPIODMATriggerDisable(unsigned long ulPort, unsigned char ucPins)
1994 {
1995     //
1996     // Check the arguments.
1997     //
1998     ASSERT(GPIOBaseValid(ulPort));
1999 
2000     //
2001     // Set the pin as a DMA trigger.
2002     //
2003     HWREG(ulPort + GPIO_O_DMACTL) &= (~ucPins);
2004 }
2005 
2006 //*****************************************************************************
2007 //
2008 //! Enables a GPIO pin as a trigger to start an ADC capture.
2009 //!
2010 //! \param ulPort is the base address of the GPIO port.
2011 //! \param ucPins is the bit-packed representation of the pin(s).
2012 //!
2013 //! This function enables a GPIO pin to be used as a trigger to start an ADC
2014 //! sequence.  Any GPIO pin can be configured to be an external trigger for
2015 //! an ADC sequence.  The GPIO pin still generates interrupts if the
2016 //! interrupt is enabled for the selected pin. To enable the use of a GPIO pin
2017 //! to trigger the ADC module, the ADCSequenceConfigure() function must be called
2018 //! with the ADC_TRIGGER_EXTERNAL parameter.
2019 //!
2020 //! \note This function is not available on all devices, consult the data sheet
2021 //! to ensure that the device you are using supports GPIO ADC Control.
2022 //!
2023 //! \return None.
2024 //
2025 //*****************************************************************************
2026 void
GPIOADCTriggerEnable(unsigned long ulPort,unsigned char ucPins)2027 GPIOADCTriggerEnable(unsigned long ulPort, unsigned char ucPins)
2028 {
2029     //
2030     // Check the arguments.
2031     //
2032     ASSERT(GPIOBaseValid(ulPort));
2033 
2034     //
2035     // Set the pin as a DMA trigger.
2036     //
2037     HWREG(ulPort + GPIO_O_ADCCTL) |= ucPins;
2038 }
2039 
2040 //*****************************************************************************
2041 //
2042 //! Disable a GPIO pin as a trigger to start an ADC capture.
2043 //!
2044 //! \param ulPort is the base address of the GPIO port.
2045 //! \param ucPins is the bit-packed representation of the pin(s).
2046 //!
2047 //! This function disables a GPIO pin to be used as a trigger to start an ADC
2048 //! sequence.  This function can be used to disable this feature if it was
2049 //! enabled via a call to GPIOADCTriggerEnable().
2050 //!
2051 //! \note This function is not available on all devices, consult the data sheet
2052 //! to ensure that the device you are using supports GPIO ADC Control.
2053 //!
2054 //! \return None.
2055 //
2056 //*****************************************************************************
2057 void
GPIOADCTriggerDisable(unsigned long ulPort,unsigned char ucPins)2058 GPIOADCTriggerDisable(unsigned long ulPort, unsigned char ucPins)
2059 {
2060     //
2061     // Check the arguments.
2062     //
2063     ASSERT(GPIOBaseValid(ulPort));
2064 
2065     //
2066     // Set the pin as a DMA trigger.
2067     //
2068     HWREG(ulPort + GPIO_O_ADCCTL) &= (~ucPins);
2069 }
2070 
2071 //*****************************************************************************
2072 //
2073 // Close the Doxygen group.
2074 //! @}
2075 //
2076 //*****************************************************************************
2077