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