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