gpio.c 69 KB

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