1 //*****************************************************************************
3 // gpio.c - API for GPIO ports
5 // Copyright (c) 2005,2006 Luminary Micro, Inc. All rights reserved.
7 // Software License Agreement
9 // Luminary Micro, Inc. (LMI) is supplying this software for use solely and
10 // exclusively on LMI's Stellaris Family of microcontroller products.
12 // The software is owned by LMI and/or its suppliers, and is protected under
13 // applicable copyright laws. All rights are reserved. Any use in violation
14 // of the foregoing restrictions may subject the user to criminal sanctions
15 // under applicable laws, as well as to civil liability for the breach of the
16 // terms and conditions of this license.
18 // THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19 // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21 // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
22 // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
24 // This is part of revision 991 of the Stellaris Driver Library.
26 //*****************************************************************************
28 //*****************************************************************************
30 //! \addtogroup gpio_api
33 //*****************************************************************************
35 #include "../hw_gpio.h"
36 #include "../hw_ints.h"
37 #include "../hw_memmap.h"
38 #include "../hw_types.h"
41 #include "interrupt.h"
43 //*****************************************************************************
46 //! Get GPIO interrupt number.
48 //! \param ulPort base address of the selected GPIO port
50 //! Given a GPIO base address, returns the corresponding interrupt number.
52 //! \return Returns a GPIO interrupt number, or -1 if \e ulPort is invalid.
54 //*****************************************************************************
55 #if defined(GROUP_getintnumber) || defined(BUILD_ALL)
57 GPIOGetIntNumber(unsigned long ulPort)
62 // Determine the GPIO interrupt number for the given module.
103 // Return GPIO interrupt number.
108 extern long GPIOGetIntNumber(unsigned long ulPort);
111 //*****************************************************************************
113 //! Sets the direction and mode of the specified pins of the selected
116 //! \param ulPort base address of the selected GPIO port
117 //! \param ucPins bit-packed representation of the specified pins
118 //! \param ulPinIO pin direction and/or mode
120 //! This function will set the specified pins on the selected GPIO port
121 //! as either an input or output under software control, or it will set the
122 //! pin to be under hardware control.
124 //! The parameter \e ulPinIO is an enumerated data type that can be one of
125 //! the following values:
127 //! - \b GPIO_DIR_MODE_IN
128 //! - \b GPIO_DIR_MODE_OUT
129 //! - \b GPIO_DIR_MODE_HW
131 //! where \b GPIO_DIR_MODE_IN specifies that the pin will be programmed as
132 //! a software controlled input, \b GPIO_DIR_MODE_OUT specifies that the pin
133 //! will be programmed as a software controlled output, and
134 //! \b GPIO_DIR_MODE_HW specifies that the pin will be placed under
135 //! hardware control.
137 //! The pins are specified using a bit-packed byte, where each bit that is
138 //! set identifies the pin to be accessed, and where bit 0 of the byte
139 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, etc.
143 //*****************************************************************************
144 #if defined(GROUP_dirmodeset) || defined(BUILD_ALL) || defined(DOXYGEN)
146 GPIODirModeSet(unsigned long ulPort, unsigned char ucPins,
147 unsigned long ulPinIO)
150 // Check the arguments.
152 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
153 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
154 (ulPort == GPIO_PORTE_BASE));
155 ASSERT((ulPinIO == GPIO_DIR_MODE_IN) || (ulPinIO == GPIO_DIR_MODE_OUT) ||
156 (ulPinIO == GPIO_DIR_MODE_HW));
159 // Set the pin direction and mode.
161 HWREG(ulPort + GPIO_O_DIR) = ((ulPinIO & 1) ?
162 (HWREG(ulPort + GPIO_O_DIR) | ucPins) :
163 (HWREG(ulPort + GPIO_O_DIR) & ~(ucPins)));
164 HWREG(ulPort + GPIO_O_AFSEL) = ((ulPinIO & 2) ?
165 (HWREG(ulPort + GPIO_O_AFSEL) | ucPins) :
166 (HWREG(ulPort + GPIO_O_AFSEL) &
171 //*****************************************************************************
173 //! Gets the direction and mode of a specified pin of the selected
176 //! \param ulPort base address of the selected GPIO port
177 //! \param ucPin pin number of the specified pin, relative to the selected
180 //! This function gets the direction and control mode for a specified pin on
181 //! the selected GPIO port. The pin can be configured as either an input or
182 //! output under software control, or it can be under hardware control. The
183 //! type of control and direction are returned as an enumerated data type.
185 //! \return Returns one of the enumerated data types described for
186 //! GPIODirModeSet().
188 //*****************************************************************************
189 #if defined(GROUP_dirmodeget) || defined(BUILD_ALL) || defined(DOXYGEN)
191 GPIODirModeGet(unsigned long ulPort, unsigned char ucPin)
193 unsigned long ulDir, ulAFSEL;
196 // Check the arguments.
198 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
199 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
200 (ulPort == GPIO_PORTE_BASE));
204 // Convert from a pin number to a bit position.
209 // Return the pin direction and mode.
211 ulDir = HWREG(ulPort + GPIO_O_DIR);
212 ulAFSEL = HWREG(ulPort + GPIO_O_AFSEL);
213 return(((ulDir & ucPin) ? 1 : 0) | ((ulAFSEL & ucPin) ? 2 : 0));
217 //*****************************************************************************
219 //! Sets the interrupt type for the specified pins of the selected GPIO
222 //! \param ulPort base address of the selected GPIO port
223 //! \param ucPins bit-packed representation of the specified pins
224 //! \param ulIntType specifies the type of interrupt trigger mechanism
226 //! This function sets up the various interrupt trigger mechanisms for the
227 //! specified pins on the selected GPIO port.
229 //! The parameter \e ulIntType is an enumerated data type that can be one of
230 //! the following values:
232 //! - \b GPIO_FALLING_EDGE
233 //! - \b GPIO_RISING_EDGE
234 //! - \b GPIO_BOTH_EDGES
235 //! - \b GPIO_LOW_LEVEL
236 //! - \b GPIO_HIGH_LEVEL
238 //! where the different values describe the interrupt detection mechanism
239 //! (edge or level) and the particular triggering event (falling, rising,
240 //! or both edges for edge detect, low or high for level detect).
242 //! The pins are specified using a bit-packed byte, where each bit that is
243 //! set identifies the pin to be accessed, and where bit 0 of the byte
244 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, etc.
246 //! \note In order to avoid any spurious interrupts, the user must
247 //! ensure that the GPIO inputs remain stable for the duration of
252 //*****************************************************************************
253 #if defined(GROUP_inttypeset) || defined(BUILD_ALL) || defined(DOXYGEN)
255 GPIOIntTypeSet(unsigned long ulPort, unsigned char ucPins,
256 unsigned long ulIntType)
259 // Check the arguments.
261 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
262 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
263 (ulPort == GPIO_PORTE_BASE));
264 ASSERT((ulIntType == GPIO_FALLING_EDGE) ||
265 (ulIntType == GPIO_RISING_EDGE) ||
266 (ulIntType == GPIO_BOTH_EDGES) ||
267 (ulIntType == GPIO_LOW_LEVEL) ||
268 (ulIntType == GPIO_HIGH_LEVEL));
271 // Set the pin interrupt type.
273 HWREG(ulPort + GPIO_O_IBE) = ((ulIntType & 1) ?
274 (HWREG(ulPort + GPIO_O_IBE) | ucPins) :
275 (HWREG(ulPort + GPIO_O_IBE) & ~(ucPins)));
276 HWREG(ulPort + GPIO_O_IS) = ((ulIntType & 2) ?
277 (HWREG(ulPort + GPIO_O_IS) | ucPins) :
278 (HWREG(ulPort + GPIO_O_IS) & ~(ucPins)));
279 HWREG(ulPort + GPIO_O_IEV) = ((ulIntType & 4) ?
280 (HWREG(ulPort + GPIO_O_IEV) | ucPins) :
281 (HWREG(ulPort + GPIO_O_IEV) & ~(ucPins)));
285 //*****************************************************************************
287 //! Gets the interrupt type for the specified pin of the selected GPIO
290 //! \param ulPort base address of the selected GPIO port
291 //! \param ucPin pin number of the specified pin, relative to the selected
294 //! This function gets the interrupt type for a specified pin on the selected
295 //! GPIO port. The pin can be configured as a falling edge, rising edge, or
296 //! both edge detected interrupt, or it can be configured as a low level or
297 //! high level detected interrupt. The type of interrupt detection mechanism
298 //! is returned as an enumerated data type.
300 //! \return Returns one of the enumerated data types described for
301 //! GPIOIntTypeSet().
303 //*****************************************************************************
304 #if defined(GROUP_inttypeget) || defined(BUILD_ALL) || defined(DOXYGEN)
306 GPIOIntTypeGet(unsigned long ulPort, unsigned char ucPin)
308 unsigned long ulIBE, ulIS, ulIEV;
311 // Check the arguments.
313 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
314 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
315 (ulPort == GPIO_PORTE_BASE));
319 // Convert from a pin number to a bit position.
324 // Return the pin interrupt type.
326 ulIBE = HWREG(ulPort + GPIO_O_IBE);
327 ulIS = HWREG(ulPort + GPIO_O_IS);
328 ulIEV = HWREG(ulPort + GPIO_O_IEV);
329 return(((ulIBE & ucPin) ? 1 : 0) | ((ulIS & ucPin) ? 2 : 0) |
330 ((ulIEV & ucPin) ? 4 : 0));
334 //*****************************************************************************
336 //! Sets the pad configuration for the specified pins of the selected GPIO
339 //! \param ulPort is the base address of the GPIO port.
340 //! \param ucPins bit-packed representation of the specified pins.
341 //! \param ulStrength specifies the output drive strength.
342 //! \param ulPinType specifies the pin type.
344 //! This function sets the drive strength and type for the specified pins
345 //! on the selected GPIO port. For pins configured as input ports, the
346 //! pad is configured as requested, but the only real effect on the input
347 //! is the configuration of the pull-up or pull-down termination.
349 //! The parameter \e ulStrength can be one of the following values:
351 //! - \b GPIO_STRENGTH_2MA
352 //! - \b GPIO_STRENGTH_4MA
353 //! - \b GPIO_STRENGTH_8MA
354 //! - \b GPIO_STRENGTH_8MA_SC
356 //! where \b GPIO_STRENGTH_xMA specifies either 2, 4, or 8 mA output drive
357 //! strength, and \b GPIO_OUT_STRENGTH_8MA_SC specifies 8 mA output drive with
360 //! The parameter \e ulPinType can be one of the following values:
362 //! - \b GPIO_PIN_TYPE_STD
363 //! - \b GPIO_PIN_TYPE_STD_WPU
364 //! - \b GPIO_PIN_TYPE_STD_WPD
365 //! - \b GPIO_PIN_TYPE_OD
366 //! - \b GPIO_PIN_TYPE_OD_WPU
367 //! - \b GPIO_PIN_TYPE_OD_WPD
368 //! - \b GPIO_PIN_TYPE_ANALOG
370 //! where \b GPIO_PIN_TYPE_STD* specifies a push-pull pin, \b GPIO_PIN_TYPE_OD*
371 //! specifies an open-drain pin, \b *_WPU specifies a weak pull-up, \b *_WPD
372 //! specifies a weak pull-down, and \b GPIO_PIN_TYPE_ANALOG specifies an
373 //! analog input (for the comparators).
375 //! The pins are specified using a bit-packed byte, where each bit that is
376 //! set identifies the pin to be accessed, and where bit 0 of the byte
377 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, etc.
381 //*****************************************************************************
382 #if defined(GROUP_padconfigset) || defined(BUILD_ALL) || defined(DOXYGEN)
384 GPIOPadConfigSet(unsigned long ulPort, unsigned char ucPins,
385 unsigned long ulStrength, unsigned long ulPinType)
388 // Check the arguments.
390 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
391 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
392 (ulPort == GPIO_PORTE_BASE));
393 ASSERT((ulStrength == GPIO_STRENGTH_2MA) ||
394 (ulStrength == GPIO_STRENGTH_4MA) ||
395 (ulStrength == GPIO_STRENGTH_8MA) ||
396 (ulStrength == GPIO_STRENGTH_8MA_SC));
397 ASSERT((ulPinType == GPIO_PIN_TYPE_STD) ||
398 (ulPinType == GPIO_PIN_TYPE_STD_WPU) ||
399 (ulPinType == GPIO_PIN_TYPE_STD_WPD) ||
400 (ulPinType == GPIO_PIN_TYPE_OD) ||
401 (ulPinType == GPIO_PIN_TYPE_OD_WPU) ||
402 (ulPinType == GPIO_PIN_TYPE_OD_WPD) ||
403 (ulPinType == GPIO_PIN_TYPE_ANALOG))
406 // Set the output drive strength.
408 HWREG(ulPort + GPIO_O_DR2R) = ((ulStrength & 1) ?
409 (HWREG(ulPort + GPIO_O_DR2R) | ucPins) :
410 (HWREG(ulPort + GPIO_O_DR2R) & ~(ucPins)));
411 HWREG(ulPort + GPIO_O_DR4R) = ((ulStrength & 2) ?
412 (HWREG(ulPort + GPIO_O_DR4R) | ucPins) :
413 (HWREG(ulPort + GPIO_O_DR4R) & ~(ucPins)));
414 HWREG(ulPort + GPIO_O_DR8R) = ((ulStrength & 4) ?
415 (HWREG(ulPort + GPIO_O_DR8R) | ucPins) :
416 (HWREG(ulPort + GPIO_O_DR8R) & ~(ucPins)));
417 HWREG(ulPort + GPIO_O_SLR) = ((ulStrength & 8) ?
418 (HWREG(ulPort + GPIO_O_SLR) | ucPins) :
419 (HWREG(ulPort + GPIO_O_SLR) & ~(ucPins)));
424 HWREG(ulPort + GPIO_O_ODR) = ((ulPinType & 1) ?
425 (HWREG(ulPort + GPIO_O_ODR) | ucPins) :
426 (HWREG(ulPort + GPIO_O_ODR) & ~(ucPins)));
427 HWREG(ulPort + GPIO_O_PUR) = ((ulPinType & 2) ?
428 (HWREG(ulPort + GPIO_O_PUR) | ucPins) :
429 (HWREG(ulPort + GPIO_O_PUR) & ~(ucPins)));
430 HWREG(ulPort + GPIO_O_PDR) = ((ulPinType & 4) ?
431 (HWREG(ulPort + GPIO_O_PDR) | ucPins) :
432 (HWREG(ulPort + GPIO_O_PDR) & ~(ucPins)));
433 HWREG(ulPort + GPIO_O_DEN) = ((ulPinType & 8) ?
434 (HWREG(ulPort + GPIO_O_DEN) | ucPins) :
435 (HWREG(ulPort + GPIO_O_DEN) & ~(ucPins)));
439 //*****************************************************************************
441 //! Gets the pad configuration for the specified pin of the selected GPIO
444 //! \param ulPort base address of the selected GPIO port
445 //! \param ucPin pin number of the specified pin, relative to the selected
447 //! \param pulStrength pointer to storage for the output drive strength
448 //! \param pulPinType pointer to storage for the output drive type
450 //! This function gets the pad configuration for a specified pin on the
451 //! selected GPIO port. The values returned in \e eStrength and \e eOutType
452 //! correspond to the values used in GPIOPadConfigSet(). This function also
453 //! works for pins configured as input pins; however, the only meaningful
454 //! data returned is whether the pin is terminated with a pull-up or
459 //*****************************************************************************
460 #if defined(GROUP_padconfigget) || defined(BUILD_ALL) || defined(DOXYGEN)
462 GPIOPadConfigGet(unsigned long ulPort, unsigned char ucPin,
463 unsigned long *pulStrength, unsigned long *pulPinType)
465 unsigned long ulTemp1, ulTemp2, ulTemp3, ulTemp4;
468 // Check the arguments.
470 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
471 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
472 (ulPort == GPIO_PORTE_BASE));
476 // Convert from a pin number to a bit position.
478 ucPin = (1 << ucPin);
481 // Get the drive strength for this pin.
483 ulTemp1 = HWREG(ulPort + GPIO_O_DR2R);
484 ulTemp2 = HWREG(ulPort + GPIO_O_DR4R);
485 ulTemp3 = HWREG(ulPort + GPIO_O_DR8R);
486 ulTemp4 = HWREG(ulPort + GPIO_O_SLR);
487 *pulStrength = (((ulTemp1 & ucPin) ? 1 : 0) | ((ulTemp2 & ucPin) ? 2 : 0) |
488 ((ulTemp3 & ucPin) ? 4 : 0) | ((ulTemp4 & ucPin) ? 8 : 0));
493 ulTemp1 = HWREG(ulPort + GPIO_O_ODR);
494 ulTemp2 = HWREG(ulPort + GPIO_O_PUR);
495 ulTemp3 = HWREG(ulPort + GPIO_O_PDR);
496 ulTemp4 = HWREG(ulPort + GPIO_O_DEN);
497 *pulPinType = (((ulTemp1 & ucPin) ? 1 : 0) | ((ulTemp2 & ucPin) ? 2 : 0) |
498 ((ulTemp3 & ucPin) ? 4 : 0) | ((ulTemp4 & ucPin) ? 8 : 0));
502 //*****************************************************************************
504 //! Enables interrupts for the specified pins of the selected GPIO port.
506 //! \param ulPort base address of the selected GPIO port
507 //! \param ucPins bit-packed representation of the specified pins
509 //! Unmasks the interrupt for the specified pins.
511 //! The pins are specified using a bit-packed byte, where each bit that is
512 //! set identifies the pin to be accessed, and where bit 0 of the byte
513 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, etc.
517 //*****************************************************************************
518 #if defined(GROUP_pinintenable) || defined(BUILD_ALL) || defined(DOXYGEN)
520 GPIOPinIntEnable(unsigned long ulPort, unsigned char ucPins)
523 // Check the arguments.
525 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
526 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
527 (ulPort == GPIO_PORTE_BASE));
530 // Enable the interrupts.
532 HWREG(ulPort + GPIO_O_IM) |= ucPins;
536 //*****************************************************************************
538 //! Disables interrupts for the specified pins of the selected GPIO port.
540 //! \param ulPort base address of the selected GPIO port
541 //! \param ucPins bit-packed representation of the specified pins
543 //! Masks the interrupt for the specified pins.
545 //! The pins are specified using a bit-packed byte, where each bit that is
546 //! set identifies the pin to be accessed, and where bit 0 of the byte
547 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, etc.
551 //*****************************************************************************
552 #if defined(GROUP_pinintdisable) || defined(BUILD_ALL) || defined(DOXYGEN)
554 GPIOPinIntDisable(unsigned long ulPort, unsigned char ucPins)
557 // Check the arguments.
559 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
560 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
561 (ulPort == GPIO_PORTE_BASE));
564 // Disable the interrupts.
566 HWREG(ulPort + GPIO_O_IM) &= ~(ucPins);
570 //*****************************************************************************
572 //! Gets interrupt status for all the pins of the selected GPIO port.
574 //! \param ulPort base address of the selected GPIO port
575 //! \param bMasked specifies whether masked or raw interrupt
576 //! status is returned
578 //! If \e bMasked is set as \b true, then the masked interrupt status is
579 //! returned; otherwise, the raw interrupt status will be returned.
581 //! \return Returns a bit-packed byte, where each bit that is set identifies
582 //! an active masked or raw interrupt, and where bit 0 of the byte
583 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, etc. Bits
584 //! 31:8 should be ignored.
586 //*****************************************************************************
587 #if defined(GROUP_pinintstatus) || defined(BUILD_ALL) || defined(DOXYGEN)
589 GPIOPinIntStatus(unsigned long ulPort, tBoolean bMasked)
592 // Check the arguments.
594 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
595 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
596 (ulPort == GPIO_PORTE_BASE));
599 // Return the interrupt status.
603 return(HWREG(ulPort + GPIO_O_MIS));
607 return(HWREG(ulPort + GPIO_O_RIS));
612 //*****************************************************************************
614 //! Clears the interrupt for the specified pins of the selected GPIO port.
616 //! \param ulPort base address of the selected GPIO port
617 //! \param ucPins bit-packed representation of the specified pins
619 //! Clears the interrupt for the specified pins.
621 //! The pins are specified using a bit-packed byte, where each bit that is
622 //! set identifies the pin to be accessed, and where bit 0 of the byte
623 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, etc.
627 //*****************************************************************************
628 #if defined(GROUP_pinintclear) || defined(BUILD_ALL) || defined(DOXYGEN)
630 GPIOPinIntClear(unsigned long ulPort, unsigned char ucPins)
633 // Check the arguments.
635 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
636 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
637 (ulPort == GPIO_PORTE_BASE));
640 // Clear the interrupts.
642 HWREG(ulPort + GPIO_O_ICR) = ucPins;
646 //*****************************************************************************
648 //! Registers an interrupt handler for the selected GPIO port.
650 //! \param ulPort base address of the selected GPIO port
651 //! \param pfIntHandler pointer to the GPIO port interrupt handling function
653 //! This function will ensure that the interrupt handler specified by \e
654 //! pfIntHandler is called when an interrupt is detected from the selected
655 //! GPIO port. This function will also enable the corresponding GPIO
656 //! interrupt in the interrupt controller; individual pin interrupts and
657 //! interrupt sources must be enabled with GPIOPinIntEnable().
659 //! \sa IntRegister() for important information about registering interrupt
664 //*****************************************************************************
665 #if defined(GROUP_portintregister) || defined(BUILD_ALL) || defined(DOXYGEN)
667 GPIOPortIntRegister(unsigned long ulPort, void (*pfIntHandler)(void))
670 // Check the arguments.
672 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
673 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
674 (ulPort == GPIO_PORTE_BASE));
677 // Get the interrupt number associated with the specified GPIO.
679 ulPort = GPIOGetIntNumber(ulPort);
682 // Register the interrupt handler.
684 IntRegister(ulPort, pfIntHandler);
687 // Enable the GPIO interrupt.
693 //*****************************************************************************
695 //! Removes an interrupt handler for the selected GPIO port.
697 //! \param ulPort base address of the selected GPIO port
699 //! This function will unregister the interrupt handler for the specified
700 //! GPIO port. This function will also disable the corresponding
701 //! GPIO port interrupt in the interrupt controller; individual GPIO interrupts
702 //! and interrupt sources must be disabled with GPIOPinIntDisable().
704 //! \sa IntRegister() for important information about registering interrupt
709 //*****************************************************************************
710 #if defined(GROUP_portintunregister) || defined(BUILD_ALL) || defined(DOXYGEN)
712 GPIOPortIntUnregister(unsigned long ulPort)
715 // Check the arguments.
717 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
718 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
719 (ulPort == GPIO_PORTE_BASE));
722 // Get the interrupt number associated with the specified GPIO.
724 ulPort = GPIOGetIntNumber(ulPort);
727 // Disable the GPIO interrupt.
732 // Unregister the interrupt handler.
734 IntUnregister(ulPort);
738 //*****************************************************************************
740 //! Reads the values present at the specified pins of the selected GPIO port.
742 //! \param ulPort base address of the selected GPIO port
743 //! \param ucPins bit-packed representation of the specified pins
745 //! The values at the specified pins are read, as specified by \e ucPins.
746 //! Values are returned for both input and output pins, and the value
747 //! for pins that are not specified by \e ucPins are set to 0.
749 //! The pins are specified using a bit-packed byte, where each bit that is
750 //! set identifies the pin to be accessed, and where bit 0 of the byte
751 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, etc.
753 //! \return Returns a bit-packed byte providing the state of the specified
754 //! pin, where bit 0 of the byte represents GPIO port pin 0, bit 1 represents
755 //! GPIO port pin 1, etc. Any bit that is not specified by \e ucPins
756 //! is returned as a 0. Bits 31:8 should be ignored.
758 //*****************************************************************************
759 #if defined(GROUP_pinread) || defined(BUILD_ALL) || defined(DOXYGEN)
761 GPIOPinRead(unsigned long ulPort, unsigned char ucPins)
764 // Check the arguments.
766 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
767 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
768 (ulPort == GPIO_PORTE_BASE));
771 // Return the pin value(s).
773 return(HWREG(ulPort + (GPIO_O_DATA + (ucPins << 2))));
777 //*****************************************************************************
779 //! Writes a value at the specified pins of the selected GPIO port.
781 //! \param ulPort base address of the selected GPIO port
782 //! \param ucPins bit-packed representation of the specified pins
783 //! \param ucVal value to write to the specified pins
785 //! Writes the corresponding bit values to the output pins specified
786 //! by \e ucPins. Writing to a pin configured as an input pin has no
789 //! The pins are specified using a bit-packed byte, where each bit that is
790 //! set identifies the pin to be accessed, and where bit 0 of the byte
791 //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, etc.
795 //*****************************************************************************
796 #if defined(GROUP_pinwrite) || defined(BUILD_ALL) || defined(DOXYGEN)
798 GPIOPinWrite(unsigned long ulPort, unsigned char ucPins, unsigned char ucVal)
801 // Check the arguments.
803 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
804 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
805 (ulPort == GPIO_PORTE_BASE));
810 HWREG(ulPort + (GPIO_O_DATA + (ucPins << 2))) = ucVal;
814 //*****************************************************************************
816 //! Configures pin(s) for use as an analog comparator input.
818 //! \param ulPort base address of the selected GPIO port
819 //! \param ucPins bit-packed representation of the specified pins
821 //! The analog comparator input pins must be properly configured for the analog
822 //! comparator to function correctly. This function provides the proper
823 //! configuration for those pins.
825 //! \note This cannot be used to turn any pin into an analog comparator input;
826 //! it only configures an analog comparator pin for proper operation.
830 //*****************************************************************************
831 #if defined(GROUP_pintypecomparator) || defined(BUILD_ALL) || defined(DOXYGEN)
833 GPIOPinTypeComparator(unsigned long ulPort, unsigned char ucPins)
836 // Check the arguments.
838 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
839 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
840 (ulPort == GPIO_PORTE_BASE));
843 // Make the pin(s) be inputs.
845 GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_IN);
848 // Set the pad(s) for analog operation.
850 GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_ANALOG);
854 //*****************************************************************************
856 //! Configures pin(s) for use by the I2C peripheral.
858 //! \param ulPort base address of the selected GPIO port
859 //! \param ucPins bit-packed representation of the specified pins
861 //! The I2C pins must be properly configured for the I2C peripheral to function
862 //! correctly. This function provides the proper configuration for those pins.
864 //! \note This cannot be used to turn any pin into an I2C pin; it only
865 //! configures an I2C pin for proper operation.
869 //*****************************************************************************
870 #if defined(GROUP_pintypei2c) || defined(BUILD_ALL) || defined(DOXYGEN)
872 GPIOPinTypeI2C(unsigned long ulPort, unsigned char ucPins)
875 // Check the arguments.
877 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
878 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
879 (ulPort == GPIO_PORTE_BASE));
882 // Make the pin(s) be peripheral controlled.
884 GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
887 // Set the pad(s) for open-drain operation with a weak pull-up.
889 GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD_WPU);
893 //*****************************************************************************
895 //! Configures pin(s) for use by the PWM peripheral.
897 //! \param ulPort base address of the selected GPIO port
898 //! \param ucPins bit-packed representation of the specified pins
900 //! The PWM pins must be properly configured for the PWM peripheral to function
901 //! correctly. This function provides a typical configuration for those pins;
902 //! other configurations may work as well depending upon the board setup (for
903 //! example, using the on-chip pull-ups).
905 //! \note This cannot be used to turn any pin into a PWM pin; it only
906 //! configures a PWM pin for proper operation.
910 //*****************************************************************************
911 #if defined(GROUP_pintypepwm) || defined(BUILD_ALL) || defined(DOXYGEN)
913 GPIOPinTypePWM(unsigned long ulPort, unsigned char ucPins)
916 // Check the arguments.
918 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
919 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
920 (ulPort == GPIO_PORTE_BASE));
923 // Make the pin(s) be peripheral controlled.
925 GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
928 // Set the pad(s) for standard push-pull operation.
930 GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
934 //*****************************************************************************
936 //! Configures pin(s) for use by the QEI peripheral.
938 //! \param ulPort base address of the selected GPIO port
939 //! \param ucPins bit-packed representation of the specified pins
941 //! The QEI pins must be properly configured for the QEI peripheral to function
942 //! correctly. This function provides a typical configuration for those pins;
943 //! other configurations may work as well depending upon the board setup (for
944 //! example, not using the on-chip pull-ups).
946 //! \note This cannot be used to turn any pin into a QEI pin; it only
947 //! configures a QEI pin for proper operation.
951 //*****************************************************************************
952 #if defined(GROUP_pintypeqei) || defined(BUILD_ALL) || defined(DOXYGEN)
954 GPIOPinTypeQEI(unsigned long ulPort, unsigned char ucPins)
957 // Check the arguments.
959 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
960 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
961 (ulPort == GPIO_PORTE_BASE));
964 // Make the pin(s) be peripheral controlled.
966 GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
969 // Set the pad(s) for standard push-pull operation with a weak pull-up.
971 GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
975 //*****************************************************************************
977 //! Configures pin(s) for use by the SSI peripheral.
979 //! \param ulPort base address of the selected GPIO port
980 //! \param ucPins bit-packed representation of the specified pins
982 //! The SSI pins must be properly configured for the SSI peripheral to function
983 //! correctly. This function provides a typical configuration for those pins;
984 //! other configurations may work as well depending upon the board setup (for
985 //! example, using the on-chip pull-ups).
987 //! \note This cannot be used to turn any pin into a SSI pin; it only
988 //! configures a SSI pin for proper operation.
992 //*****************************************************************************
993 #if defined(GROUP_pintypessi) || defined(BUILD_ALL) || defined(DOXYGEN)
995 GPIOPinTypeSSI(unsigned long ulPort, unsigned char ucPins)
998 // Check the arguments.
1000 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
1001 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
1002 (ulPort == GPIO_PORTE_BASE));
1005 // Make the pin(s) be peripheral controlled.
1007 GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1010 // Set the pad(s) for standard push-pull operation.
1012 GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
1016 //*****************************************************************************
1018 //! Configures pin(s) for use by the Timer peripheral.
1020 //! \param ulPort base address of the selected GPIO port
1021 //! \param ucPins bit-packed representation of the specified pins
1023 //! The CCP pins must be properly configured for the timer peripheral to
1024 //! function correctly. This function provides a typical configuration for
1025 //! those pins; other configurations may work as well depending upon the board
1026 //! setup (for example, using the on-chip pull-ups).
1028 //! \note This cannot be used to turn any pin into a timer pin; it only
1029 //! configures a timer pin for proper operation.
1033 //*****************************************************************************
1034 #if defined(GROUP_pintypetimer) || defined(BUILD_ALL) || defined(DOXYGEN)
1036 GPIOPinTypeTimer(unsigned long ulPort, unsigned char ucPins)
1039 // Check the arguments.
1041 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
1042 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
1043 (ulPort == GPIO_PORTE_BASE));
1046 // Make the pin(s) be peripheral controlled.
1048 GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1051 // Set the pad(s) for standard push-pull operation.
1053 GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
1057 //*****************************************************************************
1059 //! Configures pin(s) for use by the UART peripheral.
1061 //! \param ulPort base address of the selected GPIO port
1062 //! \param ucPins bit-packed representation of the specified pins
1064 //! The UART pins must be properly configured for the UART peripheral to
1065 //! function correctly. This function provides a typical configuration for
1066 //! those pins; other configurations may work as well depending upon the board
1067 //! setup (for example, using the on-chip pull-ups).
1069 //! \note This cannot be used to turn any pin into a UART pin; it only
1070 //! configures a UART pin for proper operation.
1074 //*****************************************************************************
1075 #if defined(GROUP_pintypeuart) || defined(BUILD_ALL) || defined(DOXYGEN)
1077 GPIOPinTypeUART(unsigned long ulPort, unsigned char ucPins)
1080 // Check the arguments.
1082 ASSERT((ulPort == GPIO_PORTA_BASE) || (ulPort == GPIO_PORTB_BASE) ||
1083 (ulPort == GPIO_PORTC_BASE) || (ulPort == GPIO_PORTD_BASE) ||
1084 (ulPort == GPIO_PORTE_BASE));
1087 // Make the pin(s) be peripheral controlled.
1089 GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
1092 // Set the pad(s) for standard push-pull operation.
1094 GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
1098 //*****************************************************************************
1100 // Close the Doxygen group.
1103 //*****************************************************************************