gpio.c 69 KB

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