gpio.c 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671
  1. //*****************************************************************************
  2. //
  3. // gpio.c - API for GPIO ports
  4. //
  5. // Copyright (c) 2005-2014 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions
  10. // are met:
  11. //
  12. // Redistributions of source code must retain the above copyright
  13. // notice, this list of conditions and the following disclaimer.
  14. //
  15. // Redistributions in binary form must reproduce the above copyright
  16. // notice, this list of conditions and the following disclaimer in the
  17. // documentation and/or other materials provided with the
  18. // distribution.
  19. //
  20. // Neither the name of Texas Instruments Incorporated nor the names of
  21. // its contributors may be used to endorse or promote products derived
  22. // from this software without specific prior written permission.
  23. //
  24. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. // This is part of revision 2.1.0.12573 of the Tiva Peripheral Driver Library.
  37. //
  38. //*****************************************************************************
  39. //*****************************************************************************
  40. //
  41. //! \addtogroup gpio_api
  42. //! @{
  43. //
  44. //*****************************************************************************
  45. #include <stdbool.h>
  46. #include <stdint.h>
  47. #include "inc/hw_gpio.h"
  48. #include "inc/hw_ints.h"
  49. #include "inc/hw_memmap.h"
  50. #include "inc/hw_sysctl.h"
  51. #include "inc/hw_types.h"
  52. #include "driverlib/debug.h"
  53. #include "driverlib/gpio.h"
  54. #include "driverlib/interrupt.h"
  55. //*****************************************************************************
  56. //
  57. // A mapping of GPIO port address to interrupt number.
  58. //
  59. //*****************************************************************************
  60. static const uint32_t g_ppui32GPIOIntMapBlizzard[][2] =
  61. {
  62. { GPIO_PORTA_BASE, INT_GPIOA_TM4C123 },
  63. { GPIO_PORTA_AHB_BASE, INT_GPIOA_TM4C123 },
  64. { GPIO_PORTB_BASE, INT_GPIOB_TM4C123 },
  65. { GPIO_PORTB_AHB_BASE, INT_GPIOB_TM4C123 },
  66. { GPIO_PORTC_BASE, INT_GPIOC_TM4C123 },
  67. { GPIO_PORTC_AHB_BASE, INT_GPIOC_TM4C123 },
  68. { GPIO_PORTD_BASE, INT_GPIOD_TM4C123 },
  69. { GPIO_PORTD_AHB_BASE, INT_GPIOD_TM4C123 },
  70. { GPIO_PORTE_BASE, INT_GPIOE_TM4C123 },
  71. { GPIO_PORTE_AHB_BASE, INT_GPIOE_TM4C123 },
  72. { GPIO_PORTF_BASE, INT_GPIOF_TM4C123 },
  73. { GPIO_PORTF_AHB_BASE, INT_GPIOF_TM4C123 },
  74. { GPIO_PORTG_BASE, INT_GPIOG_TM4C123 },
  75. { GPIO_PORTG_AHB_BASE, INT_GPIOG_TM4C123 },
  76. { GPIO_PORTH_BASE, INT_GPIOH_TM4C123 },
  77. { GPIO_PORTH_AHB_BASE, INT_GPIOH_TM4C123 },
  78. { GPIO_PORTJ_BASE, INT_GPIOJ_TM4C123 },
  79. { GPIO_PORTJ_AHB_BASE, INT_GPIOJ_TM4C123 },
  80. { GPIO_PORTK_BASE, INT_GPIOK_TM4C123 },
  81. { GPIO_PORTL_BASE, INT_GPIOL_TM4C123 },
  82. { GPIO_PORTM_BASE, INT_GPIOM_TM4C123 },
  83. { GPIO_PORTN_BASE, INT_GPION_TM4C123 },
  84. { GPIO_PORTP_BASE, INT_GPIOP0_TM4C123 },
  85. { GPIO_PORTQ_BASE, INT_GPIOQ0_TM4C123 },
  86. };
  87. static const uint_fast32_t g_ui32GPIOIntMapBlizzardRows =
  88. sizeof(g_ppui32GPIOIntMapBlizzard) / sizeof(g_ppui32GPIOIntMapBlizzard[0]);
  89. static const uint32_t g_ppui32GPIOIntMapSnowflake[][2] =
  90. {
  91. { GPIO_PORTA_BASE, INT_GPIOA_TM4C129 },
  92. { GPIO_PORTA_AHB_BASE, INT_GPIOA_TM4C129 },
  93. { GPIO_PORTB_BASE, INT_GPIOB_TM4C129 },
  94. { GPIO_PORTB_AHB_BASE, INT_GPIOB_TM4C129 },
  95. { GPIO_PORTC_BASE, INT_GPIOC_TM4C129 },
  96. { GPIO_PORTC_AHB_BASE, INT_GPIOC_TM4C129 },
  97. { GPIO_PORTD_BASE, INT_GPIOD_TM4C129 },
  98. { GPIO_PORTD_AHB_BASE, INT_GPIOD_TM4C129 },
  99. { GPIO_PORTE_BASE, INT_GPIOE_TM4C129 },
  100. { GPIO_PORTE_AHB_BASE, INT_GPIOE_TM4C129 },
  101. { GPIO_PORTF_BASE, INT_GPIOF_TM4C129 },
  102. { GPIO_PORTF_AHB_BASE, INT_GPIOF_TM4C129 },
  103. { GPIO_PORTG_BASE, INT_GPIOG_TM4C129 },
  104. { GPIO_PORTG_AHB_BASE, INT_GPIOG_TM4C129 },
  105. { GPIO_PORTH_BASE, INT_GPIOH_TM4C129 },
  106. { GPIO_PORTH_AHB_BASE, INT_GPIOH_TM4C129 },
  107. { GPIO_PORTJ_BASE, INT_GPIOJ_TM4C129 },
  108. { GPIO_PORTJ_AHB_BASE, INT_GPIOJ_TM4C129 },
  109. { GPIO_PORTK_BASE, INT_GPIOK_TM4C129 },
  110. { GPIO_PORTL_BASE, INT_GPIOL_TM4C129 },
  111. { GPIO_PORTM_BASE, INT_GPIOM_TM4C129 },
  112. { GPIO_PORTN_BASE, INT_GPION_TM4C129 },
  113. { GPIO_PORTP_BASE, INT_GPIOP0_TM4C129 },
  114. { GPIO_PORTQ_BASE, INT_GPIOQ0_TM4C129 },
  115. };
  116. static const uint_fast32_t g_ui32GPIOIntMapSnowflakeRows =
  117. (sizeof(g_ppui32GPIOIntMapSnowflake) /
  118. sizeof(g_ppui32GPIOIntMapSnowflake[0]));
  119. //*****************************************************************************
  120. //
  121. // The base addresses of all the GPIO modules. Both the APB and AHB apertures
  122. // are provided.
  123. //
  124. //*****************************************************************************
  125. static const uint32_t g_pui32GPIOBaseAddrs[] =
  126. {
  127. GPIO_PORTA_BASE, GPIO_PORTA_AHB_BASE,
  128. GPIO_PORTB_BASE, GPIO_PORTB_AHB_BASE,
  129. GPIO_PORTC_BASE, GPIO_PORTC_AHB_BASE,
  130. GPIO_PORTD_BASE, GPIO_PORTD_AHB_BASE,
  131. GPIO_PORTE_BASE, GPIO_PORTE_AHB_BASE,
  132. GPIO_PORTF_BASE, GPIO_PORTF_AHB_BASE,
  133. GPIO_PORTG_BASE, GPIO_PORTG_AHB_BASE,
  134. GPIO_PORTH_BASE, GPIO_PORTH_AHB_BASE,
  135. GPIO_PORTJ_BASE, GPIO_PORTJ_AHB_BASE,
  136. GPIO_PORTK_BASE, GPIO_PORTK_BASE,
  137. GPIO_PORTL_BASE, GPIO_PORTL_BASE,
  138. GPIO_PORTM_BASE, GPIO_PORTM_BASE,
  139. GPIO_PORTN_BASE, GPIO_PORTN_BASE,
  140. GPIO_PORTP_BASE, GPIO_PORTP_BASE,
  141. GPIO_PORTQ_BASE, GPIO_PORTQ_BASE,
  142. GPIO_PORTR_BASE, GPIO_PORTR_BASE,
  143. GPIO_PORTS_BASE, GPIO_PORTS_BASE,
  144. GPIO_PORTT_BASE, GPIO_PORTT_BASE,
  145. };
  146. //*****************************************************************************
  147. //
  148. //! \internal
  149. //! Checks a GPIO base address.
  150. //!
  151. //! \param ui32Port is the base address of the GPIO port.
  152. //!
  153. //! This function determines if a GPIO port base address is valid.
  154. //!
  155. //! \return Returns \b true if the base address is valid and \b false
  156. //! otherwise.
  157. //
  158. //*****************************************************************************
  159. #ifdef DEBUG
  160. static bool
  161. _GPIOBaseValid(uint32_t ui32Port)
  162. {
  163. return((ui32Port == GPIO_PORTA_BASE) ||
  164. (ui32Port == GPIO_PORTA_AHB_BASE) ||
  165. (ui32Port == GPIO_PORTB_BASE) ||
  166. (ui32Port == GPIO_PORTB_AHB_BASE) ||
  167. (ui32Port == GPIO_PORTC_BASE) ||
  168. (ui32Port == GPIO_PORTC_AHB_BASE) ||
  169. (ui32Port == GPIO_PORTD_BASE) ||
  170. (ui32Port == GPIO_PORTD_AHB_BASE) ||
  171. (ui32Port == GPIO_PORTE_BASE) ||
  172. (ui32Port == GPIO_PORTE_AHB_BASE) ||
  173. (ui32Port == GPIO_PORTF_BASE) ||
  174. (ui32Port == GPIO_PORTF_AHB_BASE) ||
  175. (ui32Port == GPIO_PORTG_BASE) ||
  176. (ui32Port == GPIO_PORTG_AHB_BASE) ||
  177. (ui32Port == GPIO_PORTH_BASE) ||
  178. (ui32Port == GPIO_PORTH_AHB_BASE) ||
  179. (ui32Port == GPIO_PORTJ_BASE) ||
  180. (ui32Port == GPIO_PORTJ_AHB_BASE) ||
  181. (ui32Port == GPIO_PORTK_BASE) ||
  182. (ui32Port == GPIO_PORTL_BASE) ||
  183. (ui32Port == GPIO_PORTM_BASE) ||
  184. (ui32Port == GPIO_PORTN_BASE) ||
  185. (ui32Port == GPIO_PORTP_BASE) ||
  186. (ui32Port == GPIO_PORTQ_BASE) ||
  187. (ui32Port == GPIO_PORTR_BASE) ||
  188. (ui32Port == GPIO_PORTS_BASE) ||
  189. (ui32Port == GPIO_PORTT_BASE));
  190. }
  191. #endif
  192. //*****************************************************************************
  193. //
  194. //! Gets the GPIO interrupt number.
  195. //!
  196. //! \param ui32Port is the base address of the GPIO port.
  197. //!
  198. //! Given a GPIO base address, this function returns the corresponding
  199. //! interrupt number.
  200. //!
  201. //! \return Returns a GPIO interrupt number, or 0 if \e ui32Port is invalid.
  202. //
  203. //*****************************************************************************
  204. static uint32_t
  205. _GPIOIntNumberGet(uint32_t ui32Port)
  206. {
  207. uint_fast32_t ui32Idx, ui32Rows;
  208. const uint32_t (*ppui32GPIOIntMap)[2];
  209. //
  210. // Check the arguments.
  211. //
  212. ASSERT(_GPIOBaseValid(ui32Port));
  213. ppui32GPIOIntMap = g_ppui32GPIOIntMapBlizzard;
  214. ui32Rows = g_ui32GPIOIntMapBlizzardRows;
  215. if(CLASS_IS_TM4C129)
  216. {
  217. ppui32GPIOIntMap = g_ppui32GPIOIntMapSnowflake;
  218. ui32Rows = g_ui32GPIOIntMapSnowflakeRows;
  219. }
  220. //
  221. // Loop through the table that maps I2C base addresses to interrupt
  222. // numbers.
  223. //
  224. for(ui32Idx = 0; ui32Idx < ui32Rows; ui32Idx++)
  225. {
  226. //
  227. // See if this base address matches.
  228. //
  229. if(ppui32GPIOIntMap[ui32Idx][0] == ui32Port)
  230. {
  231. //
  232. // Return the corresponding interrupt number.
  233. //
  234. return(ppui32GPIOIntMap[ui32Idx][1]);
  235. }
  236. }
  237. //
  238. // The base address could not be found, so return an error.
  239. //
  240. return(0);
  241. }
  242. //*****************************************************************************
  243. //
  244. //! Sets the direction and mode of the specified pin(s).
  245. //!
  246. //! \param ui32Port is the base address of the GPIO port
  247. //! \param ui8Pins is the bit-packed representation of the pin(s).
  248. //! \param ui32PinIO is the pin direction and/or mode.
  249. //!
  250. //! This function configures the specified pin(s) on the selected GPIO port
  251. //! as either input or output under software control, or it configures the
  252. //! pin to be under hardware control.
  253. //!
  254. //! The parameter \e ui32PinIO is an enumerated data type that can be one of
  255. //! the following values:
  256. //!
  257. //! - \b GPIO_DIR_MODE_IN
  258. //! - \b GPIO_DIR_MODE_OUT
  259. //! - \b GPIO_DIR_MODE_HW
  260. //!
  261. //! where \b GPIO_DIR_MODE_IN specifies that the pin is programmed as a
  262. //! software controlled input, \b GPIO_DIR_MODE_OUT specifies that the pin is
  263. //! programmed as a software controlled output, and \b GPIO_DIR_MODE_HW
  264. //! specifies that the pin is placed under hardware control.
  265. //!
  266. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  267. //! set identifies the pin to be accessed, and where bit 0 of the byte
  268. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  269. //!
  270. //! \note GPIOPadConfigSet() must also be used to configure the corresponding
  271. //! pad(s) in order for them to propagate the signal to/from the GPIO.
  272. //!
  273. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  274. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  275. //! locked against inadvertent reconfiguration. These pins must be unlocked
  276. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  277. //! registers before this function can be called. Please see the ``gpio_jtag''
  278. //! example application for the mechanism required and consult your part
  279. //! datasheet for information on affected pins.
  280. //!
  281. //! \return None.
  282. //
  283. //*****************************************************************************
  284. void
  285. GPIODirModeSet(uint32_t ui32Port, uint8_t ui8Pins, uint32_t ui32PinIO)
  286. {
  287. //
  288. // Check the arguments.
  289. //
  290. ASSERT(_GPIOBaseValid(ui32Port));
  291. ASSERT((ui32PinIO == GPIO_DIR_MODE_IN) ||
  292. (ui32PinIO == GPIO_DIR_MODE_OUT) ||
  293. (ui32PinIO == GPIO_DIR_MODE_HW));
  294. //
  295. // Set the pin direction and mode.
  296. //
  297. HWREG(ui32Port + GPIO_O_DIR) = ((ui32PinIO & 1) ?
  298. (HWREG(ui32Port + GPIO_O_DIR) | ui8Pins) :
  299. (HWREG(ui32Port + GPIO_O_DIR) & ~(ui8Pins)));
  300. HWREG(ui32Port + GPIO_O_AFSEL) = ((ui32PinIO & 2) ?
  301. (HWREG(ui32Port + GPIO_O_AFSEL) |
  302. ui8Pins) :
  303. (HWREG(ui32Port + GPIO_O_AFSEL) &
  304. ~(ui8Pins)));
  305. }
  306. //*****************************************************************************
  307. //
  308. //! Gets the direction and mode of a pin.
  309. //!
  310. //! \param ui32Port is the base address of the GPIO port.
  311. //! \param ui8Pin is the pin number.
  312. //!
  313. //! This function gets the direction and control mode for a specified pin on
  314. //! the selected GPIO port. The pin can be configured as either an input or
  315. //! output under software control, or it can be under hardware control. The
  316. //! type of control and direction are returned as an enumerated data type.
  317. //!
  318. //! \return Returns one of the enumerated data types described for
  319. //! GPIODirModeSet().
  320. //
  321. //*****************************************************************************
  322. uint32_t
  323. GPIODirModeGet(uint32_t ui32Port, uint8_t ui8Pin)
  324. {
  325. uint32_t ui32Dir, ui32AFSEL;
  326. //
  327. // Check the arguments.
  328. //
  329. ASSERT(_GPIOBaseValid(ui32Port));
  330. ASSERT(ui8Pin < 8);
  331. //
  332. // Convert from a pin number to a bit position.
  333. //
  334. ui8Pin = 1 << ui8Pin;
  335. //
  336. // Return the pin direction and mode.
  337. //
  338. ui32Dir = HWREG(ui32Port + GPIO_O_DIR);
  339. ui32AFSEL = HWREG(ui32Port + GPIO_O_AFSEL);
  340. return(((ui32Dir & ui8Pin) ? 1 : 0) | ((ui32AFSEL & ui8Pin) ? 2 : 0));
  341. }
  342. //*****************************************************************************
  343. //
  344. //! Sets the interrupt type for the specified pin(s).
  345. //!
  346. //! \param ui32Port is the base address of the GPIO port.
  347. //! \param ui8Pins is the bit-packed representation of the pin(s).
  348. //! \param ui32IntType specifies the type of interrupt trigger mechanism.
  349. //!
  350. //! This function sets up the various interrupt trigger mechanisms for the
  351. //! specified pin(s) on the selected GPIO port.
  352. //!
  353. //! One of the following flags can be used to define the \e ui32IntType
  354. //! parameter:
  355. //!
  356. //! - \b GPIO_FALLING_EDGE sets detection to edge and trigger to falling
  357. //! - \b GPIO_RISING_EDGE sets detection to edge and trigger to rising
  358. //! - \b GPIO_BOTH_EDGES sets detection to both edges
  359. //! - \b GPIO_LOW_LEVEL sets detection to low level
  360. //! - \b GPIO_HIGH_LEVEL sets detection to high level
  361. //!
  362. //! In addition to the above flags, the following flag can be OR'd in to the
  363. //! \e ui32IntType parameter:
  364. //!
  365. //! - \b GPIO_DISCRETE_INT sets discrete interrupts for each pin on a GPIO
  366. //! port.
  367. //!
  368. //! The \b GPIO_DISCRETE_INT is not available on all devices or all GPIO ports,
  369. //! consult the data sheet to ensure that the device and the GPIO port supports
  370. //! discrete interrupts.
  371. //!
  372. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  373. //! set identifies the pin to be accessed, and where bit 0 of the byte
  374. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  375. //!
  376. //! \note In order to avoid any spurious interrupts, the user must ensure that
  377. //! the GPIO inputs remain stable for the duration of this function.
  378. //!
  379. //! \return None.
  380. //
  381. //*****************************************************************************
  382. void
  383. GPIOIntTypeSet(uint32_t ui32Port, uint8_t ui8Pins,
  384. uint32_t ui32IntType)
  385. {
  386. //
  387. // Check the arguments.
  388. //
  389. ASSERT(_GPIOBaseValid(ui32Port));
  390. ASSERT((ui32IntType == GPIO_FALLING_EDGE) ||
  391. (ui32IntType == GPIO_RISING_EDGE) ||
  392. (ui32IntType == GPIO_BOTH_EDGES) ||
  393. (ui32IntType == GPIO_LOW_LEVEL) ||
  394. (ui32IntType == GPIO_HIGH_LEVEL));
  395. //
  396. // Set the pin interrupt type.
  397. //
  398. HWREG(ui32Port + GPIO_O_IBE) = ((ui32IntType & 1) ?
  399. (HWREG(ui32Port + GPIO_O_IBE) | ui8Pins) :
  400. (HWREG(ui32Port + GPIO_O_IBE) & ~(ui8Pins)));
  401. HWREG(ui32Port + GPIO_O_IS) = ((ui32IntType & 2) ?
  402. (HWREG(ui32Port + GPIO_O_IS) | ui8Pins) :
  403. (HWREG(ui32Port + GPIO_O_IS) & ~(ui8Pins)));
  404. HWREG(ui32Port + GPIO_O_IEV) = ((ui32IntType & 4) ?
  405. (HWREG(ui32Port + GPIO_O_IEV) | ui8Pins) :
  406. (HWREG(ui32Port + GPIO_O_IEV) & ~(ui8Pins)));
  407. //
  408. // Set or clear the discrete interrupt feature. This is not available
  409. // on all parts or ports but is safe to write in all cases.
  410. //
  411. HWREG(ui32Port + GPIO_O_SI) = ((ui32IntType & 0x10000) ?
  412. (HWREG(ui32Port + GPIO_O_SI) | 0x01) :
  413. (HWREG(ui32Port + GPIO_O_SI) & ~(0x01)));
  414. }
  415. //*****************************************************************************
  416. //
  417. //! Gets the interrupt type for a pin.
  418. //!
  419. //! \param ui32Port is the base address of the GPIO port.
  420. //! \param ui8Pin is the pin number.
  421. //!
  422. //! This function gets the interrupt type for a specified pin on the selected
  423. //! GPIO port. The pin can be configured as a falling-edge, rising-edge, or
  424. //! both-edges detected interrupt, or it can be configured as a low-level or
  425. //! high-level detected interrupt. The type of interrupt detection mechanism
  426. //! is returned and can include the \b GPIO_DISCRETE_INT flag.
  427. //!
  428. //! \return Returns one of the flags described for GPIOIntTypeSet().
  429. //
  430. //*****************************************************************************
  431. uint32_t
  432. GPIOIntTypeGet(uint32_t ui32Port, uint8_t ui8Pin)
  433. {
  434. uint32_t ui32IBE, ui32IS, ui32IEV, ui32SI;
  435. //
  436. // Check the arguments.
  437. //
  438. ASSERT(_GPIOBaseValid(ui32Port));
  439. ASSERT(ui8Pin < 8);
  440. //
  441. // Convert from a pin number to a bit position.
  442. //
  443. ui8Pin = 1 << ui8Pin;
  444. //
  445. // Return the pin interrupt type.
  446. //
  447. ui32IBE = HWREG(ui32Port + GPIO_O_IBE);
  448. ui32IS = HWREG(ui32Port + GPIO_O_IS);
  449. ui32IEV = HWREG(ui32Port + GPIO_O_IEV);
  450. ui32SI = HWREG(ui32Port + GPIO_O_SI);
  451. return(((ui32IBE & ui8Pin) ? 1 : 0) | ((ui32IS & ui8Pin) ? 2 : 0) |
  452. ((ui32IEV & ui8Pin) ? 4 : 0) | (ui32SI & 0x01) ? 0x10000 : 0);
  453. }
  454. //*****************************************************************************
  455. //
  456. //! Sets the pad configuration for the specified pin(s).
  457. //!
  458. //! \param ui32Port is the base address of the GPIO port.
  459. //! \param ui8Pins is the bit-packed representation of the pin(s).
  460. //! \param ui32Strength specifies the output drive strength.
  461. //! \param ui32PinType specifies the pin type.
  462. //!
  463. //! This function sets the drive strength and type for the specified pin(s)
  464. //! on the selected GPIO port. For pin(s) configured as input ports, the
  465. //! pad is configured as requested, but the only real effect on the input
  466. //! is the configuration of the pull-up or pull-down termination.
  467. //!
  468. //! The parameter \e ui32Strength can be one of the following values:
  469. //!
  470. //! - \b GPIO_STRENGTH_2MA
  471. //! - \b GPIO_STRENGTH_4MA
  472. //! - \b GPIO_STRENGTH_8MA
  473. //! - \b GPIO_STRENGTH_8MA_SC
  474. //! - \b GPIO_STRENGTH_6MA
  475. //! - \b GPIO_STRENGTH_10MA
  476. //! - \b GPIO_STRENGTH_12MA
  477. //!
  478. //! where \b GPIO_STRENGTH_xMA specifies either 2, 4, or 8 mA output drive
  479. //! strength, and \b GPIO_OUT_STRENGTH_8MA_SC specifies 8 mA output drive with
  480. //! slew control.
  481. //!
  482. //! Some Tiva devices also support output drive strengths of 6, 10, and 12
  483. //! mA.
  484. //!
  485. //! The parameter \e ui32PinType can be one of the following values:
  486. //!
  487. //! - \b GPIO_PIN_TYPE_STD
  488. //! - \b GPIO_PIN_TYPE_STD_WPU
  489. //! - \b GPIO_PIN_TYPE_STD_WPD
  490. //! - \b GPIO_PIN_TYPE_OD
  491. //! - \b GPIO_PIN_TYPE_ANALOG
  492. //! - \b GPIO_PIN_TYPE_WAKE_HIGH
  493. //! - \b GPIO_PIN_TYPE_WAKE_LOW
  494. //!
  495. //! where \b GPIO_PIN_TYPE_STD* specifies a push-pull pin, \b GPIO_PIN_TYPE_OD*
  496. //! specifies an open-drain pin, \b *_WPU specifies a weak pull-up, \b *_WPD
  497. //! specifies a weak pull-down, and \b GPIO_PIN_TYPE_ANALOG specifies an analog
  498. //! input.
  499. //!
  500. //! The \b GPIO_PIN_TYPE_WAKE_* settings specify the pin to be used as a
  501. //! hibernation wake source. The pin sense level can be high or low. These
  502. //! settings are only available on some Tiva devices.
  503. //!
  504. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  505. //! set identifies the pin to be accessed, and where bit 0 of the byte
  506. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  507. //!
  508. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  509. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  510. //! locked against inadvertent reconfiguration. These pins must be unlocked
  511. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  512. //! registers before this function can be called. Please see the ``gpio_jtag''
  513. //! example application for the mechanism required and consult your part
  514. //! datasheet for information on affected pins.
  515. //!
  516. //! \return None.
  517. //
  518. //*****************************************************************************
  519. void
  520. GPIOPadConfigSet(uint32_t ui32Port, uint8_t ui8Pins,
  521. uint32_t ui32Strength, uint32_t ui32PinType)
  522. {
  523. uint8_t ui8Bit;
  524. //
  525. // Check the arguments.
  526. //
  527. ASSERT(_GPIOBaseValid(ui32Port));
  528. ASSERT((ui32Strength == GPIO_STRENGTH_2MA) ||
  529. (ui32Strength == GPIO_STRENGTH_4MA) ||
  530. (ui32Strength == GPIO_STRENGTH_6MA) ||
  531. (ui32Strength == GPIO_STRENGTH_8MA) ||
  532. (ui32Strength == GPIO_STRENGTH_8MA_SC) ||
  533. (ui32Strength == GPIO_STRENGTH_10MA) ||
  534. (ui32Strength == GPIO_STRENGTH_12MA));
  535. ASSERT((ui32PinType == GPIO_PIN_TYPE_STD) ||
  536. (ui32PinType == GPIO_PIN_TYPE_STD_WPU) ||
  537. (ui32PinType == GPIO_PIN_TYPE_STD_WPD) ||
  538. (ui32PinType == GPIO_PIN_TYPE_OD) ||
  539. (ui32PinType == GPIO_PIN_TYPE_WAKE_LOW) ||
  540. (ui32PinType == GPIO_PIN_TYPE_WAKE_HIGH) ||
  541. (ui32PinType == GPIO_PIN_TYPE_ANALOG));
  542. //
  543. // Set the GPIO peripheral configuration register first as required. This
  544. // register only appears in TM4E111 and later device classes, but is a
  545. // harmless write on older devices. Walk pins 0-7 and clear or set the
  546. // provided PC[EDMn] encoding.
  547. //
  548. for(ui8Bit = 0; ui8Bit < 8; ui8Bit++)
  549. {
  550. if(ui8Pins & (1 << ui8Bit))
  551. {
  552. HWREG(ui32Port + GPIO_O_PC) = (HWREG(ui32Port + GPIO_O_PC) &
  553. ~(0x3 << (2 * ui8Bit)));
  554. HWREG(ui32Port + GPIO_O_PC) |= (((ui32Strength >> 5) & 0x3) <<
  555. (2 * ui8Bit));
  556. }
  557. }
  558. //
  559. // Set the output drive strength.
  560. //
  561. HWREG(ui32Port + GPIO_O_DR2R) = ((ui32Strength & 1) ?
  562. (HWREG(ui32Port + GPIO_O_DR2R) |
  563. ui8Pins) :
  564. (HWREG(ui32Port + GPIO_O_DR2R) &
  565. ~(ui8Pins)));
  566. HWREG(ui32Port + GPIO_O_DR4R) = ((ui32Strength & 2) ?
  567. (HWREG(ui32Port + GPIO_O_DR4R) |
  568. ui8Pins) :
  569. (HWREG(ui32Port + GPIO_O_DR4R) &
  570. ~(ui8Pins)));
  571. HWREG(ui32Port + GPIO_O_DR8R) = ((ui32Strength & 4) ?
  572. (HWREG(ui32Port + GPIO_O_DR8R) |
  573. ui8Pins) :
  574. (HWREG(ui32Port + GPIO_O_DR8R) &
  575. ~(ui8Pins)));
  576. HWREG(ui32Port + GPIO_O_SLR) = ((ui32Strength & 8) ?
  577. (HWREG(ui32Port + GPIO_O_SLR) |
  578. ui8Pins) :
  579. (HWREG(ui32Port + GPIO_O_SLR) &
  580. ~(ui8Pins)));
  581. //
  582. // Set the 12-mA drive select register. This register only appears in
  583. // TM4E111 and later device classes, but is a harmless write on older
  584. // devices.
  585. //
  586. HWREG(ui32Port + GPIO_O_DR12R) = ((ui32Strength & 0x10) ?
  587. (HWREG(ui32Port + GPIO_O_DR12R) |
  588. ui8Pins) :
  589. (HWREG(ui32Port + GPIO_O_DR12R) &
  590. ~(ui8Pins)));
  591. //
  592. // Set the pin type.
  593. //
  594. HWREG(ui32Port + GPIO_O_ODR) = ((ui32PinType & 1) ?
  595. (HWREG(ui32Port + GPIO_O_ODR) | ui8Pins) :
  596. (HWREG(ui32Port + GPIO_O_ODR) & ~(ui8Pins)));
  597. HWREG(ui32Port + GPIO_O_PUR) = ((ui32PinType & 2) ?
  598. (HWREG(ui32Port + GPIO_O_PUR) | ui8Pins) :
  599. (HWREG(ui32Port + GPIO_O_PUR) & ~(ui8Pins)));
  600. HWREG(ui32Port + GPIO_O_PDR) = ((ui32PinType & 4) ?
  601. (HWREG(ui32Port + GPIO_O_PDR) | ui8Pins) :
  602. (HWREG(ui32Port + GPIO_O_PDR) & ~(ui8Pins)));
  603. HWREG(ui32Port + GPIO_O_DEN) = ((ui32PinType & 8) ?
  604. (HWREG(ui32Port + GPIO_O_DEN) | ui8Pins) :
  605. (HWREG(ui32Port + GPIO_O_DEN) & ~(ui8Pins)));
  606. //
  607. // Set the wake pin enable register and the wake level register. These
  608. // registers only appear in TM4E111 and later device classes, but are
  609. // harmless writes on older devices.
  610. //
  611. HWREG(ui32Port + GPIO_O_WAKELVL) = ((ui32PinType & 0x200) ?
  612. (HWREG(ui32Port + GPIO_O_WAKELVL) |
  613. ui8Pins) :
  614. (HWREG(ui32Port + GPIO_O_WAKELVL) &
  615. ~(ui8Pins)));
  616. HWREG(ui32Port + GPIO_O_WAKEPEN) = ((ui32PinType & 0x300) ?
  617. (HWREG(ui32Port + GPIO_O_WAKEPEN) |
  618. ui8Pins) :
  619. (HWREG(ui32Port + GPIO_O_WAKEPEN) &
  620. ~(ui8Pins)));
  621. //
  622. // Set the analog mode select register.
  623. //
  624. HWREG(ui32Port + GPIO_O_AMSEL) =
  625. ((ui32PinType == GPIO_PIN_TYPE_ANALOG) ?
  626. (HWREG(ui32Port + GPIO_O_AMSEL) | ui8Pins) :
  627. (HWREG(ui32Port + GPIO_O_AMSEL) & ~(ui8Pins)));
  628. }
  629. //*****************************************************************************
  630. //
  631. //! Gets the pad configuration for a pin.
  632. //!
  633. //! \param ui32Port is the base address of the GPIO port.
  634. //! \param ui8Pin is the pin number.
  635. //! \param pui32Strength is a pointer to storage for the output drive strength.
  636. //! \param pui32PinType is a pointer to storage for the output drive type.
  637. //!
  638. //! This function gets the pad configuration for a specified pin on the
  639. //! selected GPIO port. The values returned in \e pui32Strength and
  640. //! \e pui32PinType correspond to the values used in GPIOPadConfigSet(). This
  641. //! function also works for pin(s) configured as input pin(s); however, the
  642. //! only meaningful data returned is whether the pin is terminated with a
  643. //! pull-up or down resistor.
  644. //!
  645. //! \return None
  646. //
  647. //*****************************************************************************
  648. void
  649. GPIOPadConfigGet(uint32_t ui32Port, uint8_t ui8Pin,
  650. uint32_t *pui32Strength, uint32_t *pui32PinType)
  651. {
  652. uint32_t ui32PinType, ui32Strength;
  653. //
  654. // Check the arguments.
  655. //
  656. ASSERT(_GPIOBaseValid(ui32Port));
  657. ASSERT(ui8Pin < 8);
  658. //
  659. // Convert from a pin number to a bit position.
  660. //
  661. ui8Pin = (1 << ui8Pin);
  662. //
  663. // Get the drive strength for this pin.
  664. //
  665. ui32Strength = ((HWREG(ui32Port + GPIO_O_DR2R) & ui8Pin) ? 1 : 0);
  666. ui32Strength |= ((HWREG(ui32Port + GPIO_O_DR4R) & ui8Pin) ? 2 : 0);
  667. ui32Strength |= ((HWREG(ui32Port + GPIO_O_DR8R) & ui8Pin) ? 4 : 0);
  668. ui32Strength |= ((HWREG(ui32Port + GPIO_O_SLR) & ui8Pin) ? 8 : 0);
  669. ui32Strength |= ((HWREG(ui32Port + GPIO_O_DR12R) & ui8Pin) ? 0x10 : 0);
  670. ui32Strength |= (((HWREG(ui32Port + GPIO_O_PC) >>
  671. (2 * ui8Pin)) & 0x3) << 5);
  672. *pui32Strength = ui32Strength;
  673. //
  674. // Get the pin type.
  675. //
  676. ui32PinType = ((HWREG(ui32Port + GPIO_O_ODR) & ui8Pin) ? 1 : 0);
  677. ui32PinType |= ((HWREG(ui32Port + GPIO_O_PUR) & ui8Pin) ? 2 : 0);
  678. ui32PinType |= ((HWREG(ui32Port + GPIO_O_PDR) & ui8Pin) ? 4 : 0);
  679. ui32PinType |= ((HWREG(ui32Port + GPIO_O_DEN) & ui8Pin) ? 8 : 0);
  680. if(HWREG(ui32Port + GPIO_O_WAKEPEN) & ui8Pin)
  681. {
  682. ui32PinType |= ((HWREG(ui32Port + GPIO_O_WAKELVL) & ui8Pin) ?
  683. 0x200 : 0x100);
  684. }
  685. *pui32PinType = ui32PinType;
  686. }
  687. //*****************************************************************************
  688. //
  689. //! Enables the specified GPIO interrupts.
  690. //!
  691. //! \param ui32Port is the base address of the GPIO port.
  692. //! \param ui32IntFlags is the bit mask of the interrupt sources to enable.
  693. //!
  694. //! This function enables the indicated GPIO interrupt sources. Only the
  695. //! sources that are enabled can be reflected to the processor interrupt;
  696. //! disabled sources have no effect on the processor.
  697. //!
  698. //! The \e ui32IntFlags parameter is the logical OR of any of the following:
  699. //!
  700. //! - \b GPIO_INT_PIN_0 - interrupt due to activity on Pin 0.
  701. //! - \b GPIO_INT_PIN_1 - interrupt due to activity on Pin 1.
  702. //! - \b GPIO_INT_PIN_2 - interrupt due to activity on Pin 2.
  703. //! - \b GPIO_INT_PIN_3 - interrupt due to activity on Pin 3.
  704. //! - \b GPIO_INT_PIN_4 - interrupt due to activity on Pin 4.
  705. //! - \b GPIO_INT_PIN_5 - interrupt due to activity on Pin 5.
  706. //! - \b GPIO_INT_PIN_6 - interrupt due to activity on Pin 6.
  707. //! - \b GPIO_INT_PIN_7 - interrupt due to activity on Pin 7.
  708. //! - \b GPIO_INT_DMA - interrupt due to DMA activity on this GPIO module.
  709. //!
  710. //! \note If this call is being used to enable summary interrupts on GPIO port
  711. //! P or Q (GPIOIntTypeSet() with GPIO_DISCRETE_INT not enabled), then all
  712. //! individual interrupts for these ports must be enabled in the GPIO module
  713. //! using GPIOIntEnable() and all but the interrupt for pin 0 must be disabled
  714. //! in the NVIC using the IntDisable() function. The summary interrupts for
  715. //! the ports are routed to the INT_GPIOP0 or INT_GPIOQ0 which must be enabled
  716. //! to handle the interrupt. If this is not done then any individual GPIO pin
  717. //! interrupts that are left enabled also trigger the individual interrupts.
  718. //!
  719. //! \return None.
  720. //
  721. //*****************************************************************************
  722. void
  723. GPIOIntEnable(uint32_t ui32Port, uint32_t ui32IntFlags)
  724. {
  725. //
  726. // Check the arguments.
  727. //
  728. ASSERT(_GPIOBaseValid(ui32Port));
  729. //
  730. // Enable the interrupts.
  731. //
  732. HWREG(ui32Port + GPIO_O_IM) |= ui32IntFlags;
  733. }
  734. //*****************************************************************************
  735. //
  736. //! Disables the specified GPIO interrupts.
  737. //!
  738. //! \param ui32Port is the base address of the GPIO port.
  739. //! \param ui32IntFlags is the bit mask of the interrupt sources to disable.
  740. //!
  741. //! This function disables the indicated GPIO interrupt sources. Only the
  742. //! sources that are enabled can be reflected to the processor interrupt;
  743. //! disabled sources have no effect on the processor.
  744. //!
  745. //! The \e ui32IntFlags parameter is the logical OR of any of the following:
  746. //!
  747. //! - \b GPIO_INT_PIN_0 - interrupt due to activity on Pin 0.
  748. //! - \b GPIO_INT_PIN_1 - interrupt due to activity on Pin 1.
  749. //! - \b GPIO_INT_PIN_2 - interrupt due to activity on Pin 2.
  750. //! - \b GPIO_INT_PIN_3 - interrupt due to activity on Pin 3.
  751. //! - \b GPIO_INT_PIN_4 - interrupt due to activity on Pin 4.
  752. //! - \b GPIO_INT_PIN_5 - interrupt due to activity on Pin 5.
  753. //! - \b GPIO_INT_PIN_6 - interrupt due to activity on Pin 6.
  754. //! - \b GPIO_INT_PIN_7 - interrupt due to activity on Pin 7.
  755. //! - \b GPIO_INT_DMA - interrupt due to DMA activity on this GPIO module.
  756. //!
  757. //! \return None.
  758. //
  759. //*****************************************************************************
  760. void
  761. GPIOIntDisable(uint32_t ui32Port, uint32_t ui32IntFlags)
  762. {
  763. //
  764. // Check the arguments.
  765. //
  766. ASSERT(_GPIOBaseValid(ui32Port));
  767. //
  768. // Disable the interrupts.
  769. //
  770. HWREG(ui32Port + GPIO_O_IM) &= ~(ui32IntFlags);
  771. }
  772. //*****************************************************************************
  773. //
  774. //! Gets interrupt status for the specified GPIO port.
  775. //!
  776. //! \param ui32Port is the base address of the GPIO port.
  777. //! \param bMasked specifies whether masked or raw interrupt status is
  778. //! returned.
  779. //!
  780. //! If \e bMasked is set as \b true, then the masked interrupt status is
  781. //! returned; otherwise, the raw interrupt status is returned.
  782. //!
  783. //! \return Returns the current interrupt status for the specified GPIO module.
  784. //! The value returned is the logical OR of the \b GPIO_INT_* values that are
  785. //! currently active.
  786. //
  787. //*****************************************************************************
  788. uint32_t
  789. GPIOIntStatus(uint32_t ui32Port, bool bMasked)
  790. {
  791. //
  792. // Check the arguments.
  793. //
  794. ASSERT(_GPIOBaseValid(ui32Port));
  795. //
  796. // Return the interrupt status.
  797. //
  798. if(bMasked)
  799. {
  800. return(HWREG(ui32Port + GPIO_O_MIS));
  801. }
  802. else
  803. {
  804. return(HWREG(ui32Port + GPIO_O_RIS));
  805. }
  806. }
  807. //*****************************************************************************
  808. //
  809. //! Clears the specified interrupt sources.
  810. //!
  811. //! \param ui32Port is the base address of the GPIO port.
  812. //! \param ui32IntFlags is the bit mask of the interrupt sources to disable.
  813. //!
  814. //! Clears the interrupt for the specified interrupt source(s).
  815. //!
  816. //! The \e ui32IntFlags parameter is the logical OR of the \b GPIO_INT_*
  817. //! values.
  818. //!
  819. //! \note Because there is a write buffer in the Cortex-M processor, it may
  820. //! take several clock cycles before the interrupt source is actually cleared.
  821. //! Therefore, it is recommended that the interrupt source be cleared early in
  822. //! the interrupt handler (as opposed to the very last action) to avoid
  823. //! returning from the interrupt handler before the interrupt source is
  824. //! actually cleared. Failure to do so may result in the interrupt handler
  825. //! being immediately reentered (because the interrupt controller still sees
  826. //! the interrupt source asserted).
  827. //!
  828. //! \return None.
  829. //
  830. //*****************************************************************************
  831. void
  832. GPIOIntClear(uint32_t ui32Port, uint32_t ui32IntFlags)
  833. {
  834. //
  835. // Check the arguments.
  836. //
  837. ASSERT(_GPIOBaseValid(ui32Port));
  838. //
  839. // Clear the interrupts.
  840. //
  841. HWREG(ui32Port + GPIO_O_ICR) = ui32IntFlags;
  842. }
  843. //*****************************************************************************
  844. //
  845. //! Registers an interrupt handler for a GPIO port.
  846. //!
  847. //! \param ui32Port is the base address of the GPIO port.
  848. //! \param pfnIntHandler is a pointer to the GPIO port interrupt handling
  849. //! function.
  850. //!
  851. //! This function ensures that the interrupt handler specified by
  852. //! \e pfnIntHandler is called when an interrupt is detected from the selected
  853. //! GPIO port. This function also enables the corresponding GPIO interrupt
  854. //! in the interrupt controller; individual pin interrupts and interrupt
  855. //! sources must be enabled with GPIOIntEnable().
  856. //!
  857. //! \sa IntRegister() for important information about registering interrupt
  858. //! handlers.
  859. //!
  860. //! \return None.
  861. //
  862. //*****************************************************************************
  863. void
  864. GPIOIntRegister(uint32_t ui32Port, void (*pfnIntHandler)(void))
  865. {
  866. uint32_t ui32Int;
  867. //
  868. // Check the arguments.
  869. //
  870. ASSERT(_GPIOBaseValid(ui32Port));
  871. //
  872. // Get the interrupt number associated with the specified GPIO.
  873. //
  874. ui32Int = _GPIOIntNumberGet(ui32Port);
  875. ASSERT(ui32Int != 0);
  876. //
  877. // Register the interrupt handler.
  878. //
  879. IntRegister(ui32Int, pfnIntHandler);
  880. //
  881. // Enable the GPIO interrupt.
  882. //
  883. IntEnable(ui32Int);
  884. }
  885. //*****************************************************************************
  886. //
  887. //! Removes an interrupt handler for a GPIO port.
  888. //!
  889. //! \param ui32Port is the base address of the GPIO port.
  890. //!
  891. //! This function unregisters the interrupt handler for the specified
  892. //! GPIO port. This function also disables the corresponding
  893. //! GPIO port interrupt in the interrupt controller; individual GPIO interrupts
  894. //! and interrupt sources must be disabled with GPIOIntDisable().
  895. //!
  896. //! \sa IntRegister() for important information about registering interrupt
  897. //! handlers.
  898. //!
  899. //! \return None.
  900. //
  901. //*****************************************************************************
  902. void
  903. GPIOIntUnregister(uint32_t ui32Port)
  904. {
  905. uint32_t ui32Int;
  906. //
  907. // Check the arguments.
  908. //
  909. ASSERT(_GPIOBaseValid(ui32Port));
  910. //
  911. // Get the interrupt number associated with the specified GPIO.
  912. //
  913. ui32Int = _GPIOIntNumberGet(ui32Port);
  914. ASSERT(ui32Int != 0);
  915. //
  916. // Disable the GPIO interrupt.
  917. //
  918. IntDisable(ui32Int);
  919. //
  920. // Unregister the interrupt handler.
  921. //
  922. IntUnregister(ui32Int);
  923. }
  924. //*****************************************************************************
  925. //
  926. //! Reads the values present of the specified pin(s).
  927. //!
  928. //! \param ui32Port is the base address of the GPIO port.
  929. //! \param ui8Pins is the bit-packed representation of the pin(s).
  930. //!
  931. //! The values at the specified pin(s) are read, as specified by \e ui8Pins.
  932. //! Values are returned for both input and output pin(s), and the value
  933. //! for pin(s) that are not specified by \e ui8Pins are set to 0.
  934. //!
  935. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  936. //! set identifies the pin to be accessed, and where bit 0 of the byte
  937. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  938. //!
  939. //! \return Returns a bit-packed byte providing the state of the specified
  940. //! pin, where bit 0 of the byte represents GPIO port pin 0, bit 1 represents
  941. //! GPIO port pin 1, and so on. Any bit that is not specified by \e ui8Pins
  942. //! is returned as a 0. Bits 31:8 should be ignored.
  943. //
  944. //*****************************************************************************
  945. int32_t
  946. GPIOPinRead(uint32_t ui32Port, uint8_t ui8Pins)
  947. {
  948. //
  949. // Check the arguments.
  950. //
  951. ASSERT(_GPIOBaseValid(ui32Port));
  952. //
  953. // Return the pin value(s).
  954. //
  955. return(HWREG(ui32Port + (GPIO_O_DATA + (ui8Pins << 2))));
  956. }
  957. //*****************************************************************************
  958. //
  959. //! Writes a value to the specified pin(s).
  960. //!
  961. //! \param ui32Port is the base address of the GPIO port.
  962. //! \param ui8Pins is the bit-packed representation of the pin(s).
  963. //! \param ui8Val is the value to write to the pin(s).
  964. //!
  965. //! Writes the corresponding bit values to the output pin(s) specified by
  966. //! \e ui8Pins. Writing to a pin configured as an input pin has no effect.
  967. //!
  968. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  969. //! set identifies the pin to be accessed, and where bit 0 of the byte
  970. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  971. //!
  972. //! \return None.
  973. //
  974. //*****************************************************************************
  975. void
  976. GPIOPinWrite(uint32_t ui32Port, uint8_t ui8Pins, uint8_t ui8Val)
  977. {
  978. //
  979. // Check the arguments.
  980. //
  981. ASSERT(_GPIOBaseValid(ui32Port));
  982. //
  983. // Write the pins.
  984. //
  985. HWREG(ui32Port + (GPIO_O_DATA + (ui8Pins << 2))) = ui8Val;
  986. }
  987. //*****************************************************************************
  988. //
  989. //! Configures pin(s) for use as analog-to-digital converter inputs.
  990. //!
  991. //! \param ui32Port is the base address of the GPIO port.
  992. //! \param ui8Pins is the bit-packed representation of the pin(s).
  993. //!
  994. //! The analog-to-digital converter input pins must be properly configured for
  995. //! the analog-to-digital peripheral to function correctly. This function
  996. //! provides the proper configuration for those pin(s).
  997. //!
  998. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  999. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1000. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1001. //!
  1002. //! \note This function cannot be used to turn any pin into an ADC input; it
  1003. //! only configures an ADC input pin for proper operation.
  1004. //!
  1005. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1006. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1007. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1008. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1009. //! registers before this function can be called. Please see the ``gpio_jtag''
  1010. //! example application for the mechanism required and consult your part
  1011. //! datasheet for information on affected pins.
  1012. //!
  1013. //! \return None.
  1014. //
  1015. //*****************************************************************************
  1016. void
  1017. GPIOPinTypeADC(uint32_t ui32Port, uint8_t ui8Pins)
  1018. {
  1019. //
  1020. // Check the arguments.
  1021. //
  1022. ASSERT(_GPIOBaseValid(ui32Port));
  1023. //
  1024. // Make the pin(s) be inputs.
  1025. //
  1026. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_IN);
  1027. //
  1028. // Set the pad(s) for analog operation.
  1029. //
  1030. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA,
  1031. GPIO_PIN_TYPE_ANALOG);
  1032. }
  1033. //*****************************************************************************
  1034. //
  1035. //! Configures pin(s) for use as a CAN device.
  1036. //!
  1037. //! \param ui32Port is the base address of the GPIO port.
  1038. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1039. //!
  1040. //! The CAN pins must be properly configured for the CAN peripherals to
  1041. //! function correctly. This function provides a typical configuration for
  1042. //! those pin(s); other configurations may work as well depending upon the
  1043. //! board setup (for example, using the on-chip pull-ups).
  1044. //!
  1045. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  1046. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1047. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1048. //!
  1049. //! \note This function cannot be used to turn any pin into a CAN pin; it only
  1050. //! configures a CAN pin for proper operation. Note that a GPIOPinConfigure()
  1051. //! function call is also required to properly configure a pin for the CAN
  1052. //! function.
  1053. //!
  1054. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1055. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1056. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1057. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1058. //! registers before this function can be called. Please see the ``gpio_jtag''
  1059. //! example application for the mechanism required and consult your part
  1060. //! datasheet for information on affected pins.
  1061. //!
  1062. //! \return None.
  1063. //
  1064. //*****************************************************************************
  1065. void
  1066. GPIOPinTypeCAN(uint32_t ui32Port, uint8_t ui8Pins)
  1067. {
  1068. //
  1069. // Check the arguments.
  1070. //
  1071. ASSERT(_GPIOBaseValid(ui32Port));
  1072. //
  1073. // Make the pin(s) be inputs.
  1074. //
  1075. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  1076. //
  1077. // Set the pad(s) for standard push-pull operation.
  1078. //
  1079. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
  1080. }
  1081. //*****************************************************************************
  1082. //
  1083. //! Configures pin(s) for use as an analog comparator input.
  1084. //!
  1085. //! \param ui32Port is the base address of the GPIO port.
  1086. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1087. //!
  1088. //! The analog comparator input pins must be properly configured for the analog
  1089. //! comparator to function correctly. This function provides the proper
  1090. //! configuration for those pin(s).
  1091. //!
  1092. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  1093. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1094. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1095. //!
  1096. //! \note This function cannot be used to turn any pin into an analog
  1097. //! comparator input; it only configures an analog comparator pin for proper
  1098. //! operation. Note that a GPIOPinConfigure() function call is also required
  1099. //! to properly configure a pin for the analog comparator function.
  1100. //!
  1101. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1102. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1103. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1104. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1105. //! registers before this function can be called. Please see the ``gpio_jtag''
  1106. //! example application for the mechanism required and consult your part
  1107. //! datasheet for information on affected pins.
  1108. //!
  1109. //! \return None.
  1110. //
  1111. //*****************************************************************************
  1112. void
  1113. GPIOPinTypeComparator(uint32_t ui32Port, uint8_t ui8Pins)
  1114. {
  1115. //
  1116. // Check the arguments.
  1117. //
  1118. ASSERT(_GPIOBaseValid(ui32Port));
  1119. //
  1120. // Make the pin(s) be inputs.
  1121. //
  1122. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_IN);
  1123. //
  1124. // Set the pad(s) for analog operation.
  1125. //
  1126. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA,
  1127. GPIO_PIN_TYPE_ANALOG);
  1128. }
  1129. //*****************************************************************************
  1130. //
  1131. //! Configures pin(s) for use by the external peripheral interface.
  1132. //!
  1133. //! \param ui32Port is the base address of the GPIO port.
  1134. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1135. //!
  1136. //! The external peripheral interface pins must be properly configured for the
  1137. //! external peripheral interface to function correctly. This function
  1138. //! provides a typical configuration for those pin(s); other configurations may
  1139. //! work as well depending upon the board setup (for example, using the on-chip
  1140. //! pull-ups).
  1141. //!
  1142. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  1143. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1144. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1145. //!
  1146. //! \note This function cannot be used to turn any pin into an external
  1147. //! peripheral interface pin; it only configures an external peripheral
  1148. //! interface pin for proper operation. Note that a GPIOPinConfigure()
  1149. //! function call is also required to properly configure a pin for the
  1150. //! external peripheral interface function.
  1151. //!
  1152. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1153. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1154. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1155. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1156. //! registers before this function can be called. Please see the ``gpio_jtag''
  1157. //! example application for the mechanism required and consult your part
  1158. //! datasheet for information on affected pins.
  1159. //!
  1160. //! \return None.
  1161. //
  1162. //*****************************************************************************
  1163. void
  1164. GPIOPinTypeEPI(uint32_t ui32Port, uint8_t ui8Pins)
  1165. {
  1166. //
  1167. // Check the arguments.
  1168. //
  1169. ASSERT(_GPIOBaseValid(ui32Port));
  1170. //
  1171. // Make the pin(s) be peripheral controlled.
  1172. //
  1173. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  1174. //
  1175. // Set the pad(s) for standard push-pull operation.
  1176. //
  1177. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
  1178. }
  1179. //*****************************************************************************
  1180. //
  1181. //! Configures pin(s) for use by the Ethernet peripheral as LED signals.
  1182. //!
  1183. //! \param ui32Port is the base address of the GPIO port.
  1184. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1185. //!
  1186. //! The Ethernet peripheral provides four signals that can be used to drive
  1187. //! an LED (for example, for link status/activity). This function provides a
  1188. //! typical configuration for the pins.
  1189. //!
  1190. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  1191. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1192. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1193. //!
  1194. //! \note This function cannot be used to turn any pin into an Ethernet LED
  1195. //! pin; it only configures an Ethernet LED pin for proper operation. Note
  1196. //! that a GPIOPinConfigure() function call is also required to properly
  1197. //! configure the pin for the Ethernet LED function.
  1198. //!
  1199. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1200. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1201. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1202. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1203. //! registers before this function can be called. Please see the ``gpio_jtag''
  1204. //! example application for the mechanism required and consult your part
  1205. //! datasheet for information on affected pins.
  1206. //!
  1207. //! \return None.
  1208. //
  1209. //*****************************************************************************
  1210. void
  1211. GPIOPinTypeEthernetLED(uint32_t ui32Port, uint8_t ui8Pins)
  1212. {
  1213. //
  1214. // Check the arguments.
  1215. //
  1216. ASSERT(_GPIOBaseValid(ui32Port));
  1217. //
  1218. // Make the pin(s) be peripheral controlled.
  1219. //
  1220. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  1221. //
  1222. // Set the pad(s) for standard push-pull operation.
  1223. //
  1224. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
  1225. }
  1226. //*****************************************************************************
  1227. //
  1228. //! Configures pin(s) for use by the Ethernet peripheral as MII signals.
  1229. //!
  1230. //! \param ui32Port is the base address of the GPIO port.
  1231. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1232. //!
  1233. //! The Ethernet peripheral on some parts provides a set of MII signals that
  1234. //! are used to connect to an external PHY. This function provides a typical
  1235. //! configuration for the pins.
  1236. //!
  1237. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  1238. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1239. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1240. //!
  1241. //! \note This function cannot be used to turn any pin into an Ethernet MII
  1242. //! pin; it only configures an Ethernet MII pin for proper operation. Note
  1243. //! that a GPIOPinConfigure() function call is also required to properly
  1244. //! configure the pin for the Ethernet MII function.
  1245. //!
  1246. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1247. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1248. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1249. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1250. //! registers before this function can be called. Please see the ``gpio_jtag''
  1251. //! example application for the mechanism required and consult your part
  1252. //! datasheet for information on affected pins.
  1253. //!
  1254. //! \return None.
  1255. //
  1256. //*****************************************************************************
  1257. void
  1258. GPIOPinTypeEthernetMII(uint32_t ui32Port, uint8_t ui8Pins)
  1259. {
  1260. //
  1261. // Check the arguments.
  1262. //
  1263. ASSERT(_GPIOBaseValid(ui32Port));
  1264. //
  1265. // Make the pin(s) be peripheral controlled.
  1266. //
  1267. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  1268. //
  1269. // Set the pad(s) for standard push-pull operation.
  1270. //
  1271. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
  1272. }
  1273. //*****************************************************************************
  1274. //
  1275. //! Configures pin(s) for use as GPIO inputs.
  1276. //!
  1277. //! \param ui32Port is the base address of the GPIO port.
  1278. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1279. //!
  1280. //! The GPIO pins must be properly configured in order to function correctly as
  1281. //! GPIO inputs. This function provides the proper configuration for those
  1282. //! pin(s).
  1283. //!
  1284. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  1285. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1286. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1287. //!
  1288. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1289. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1290. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1291. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1292. //! registers before this function can be called. Please see the ``gpio_jtag''
  1293. //! example application for the mechanism required and consult your part
  1294. //! datasheet for information on affected pins.
  1295. //!
  1296. //! \return None.
  1297. //
  1298. //*****************************************************************************
  1299. void
  1300. GPIOPinTypeGPIOInput(uint32_t ui32Port, uint8_t ui8Pins)
  1301. {
  1302. //
  1303. // Check the arguments.
  1304. //
  1305. ASSERT(_GPIOBaseValid(ui32Port));
  1306. //
  1307. // Make the pin(s) be inputs.
  1308. //
  1309. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_IN);
  1310. //
  1311. // Set the pad(s) for standard push-pull operation.
  1312. //
  1313. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
  1314. }
  1315. //*****************************************************************************
  1316. //
  1317. //! Configures pin(s) for use as GPIO outputs.
  1318. //!
  1319. //! \param ui32Port is the base address of the GPIO port.
  1320. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1321. //!
  1322. //! The GPIO pins must be properly configured in order to function correctly as
  1323. //! GPIO outputs. This function provides the proper configuration for those
  1324. //! pin(s).
  1325. //!
  1326. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  1327. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1328. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1329. //!
  1330. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1331. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1332. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1333. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1334. //! registers before this function can be called. Please see the ``gpio_jtag''
  1335. //! example application for the mechanism required and consult your part
  1336. //! datasheet for information on affected pins.
  1337. //!
  1338. //! \return None.
  1339. //
  1340. //*****************************************************************************
  1341. void
  1342. GPIOPinTypeGPIOOutput(uint32_t ui32Port, uint8_t ui8Pins)
  1343. {
  1344. //
  1345. // Check the arguments.
  1346. //
  1347. ASSERT(_GPIOBaseValid(ui32Port));
  1348. //
  1349. // Set the pad(s) for standard push-pull operation.
  1350. //
  1351. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
  1352. //
  1353. // Make the pin(s) be outputs.
  1354. //
  1355. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_OUT);
  1356. }
  1357. //*****************************************************************************
  1358. //
  1359. //! Configures pin(s) for use as GPIO open drain outputs.
  1360. //!
  1361. //! \param ui32Port is the base address of the GPIO port.
  1362. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1363. //!
  1364. //! The GPIO pins must be properly configured in order to function correctly as
  1365. //! GPIO outputs. This function provides the proper configuration for those
  1366. //! pin(s).
  1367. //!
  1368. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  1369. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1370. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1371. //!
  1372. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1373. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1374. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1375. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1376. //! registers before this function can be called. Please see the ``gpio_jtag''
  1377. //! example application for the mechanism required and consult your part
  1378. //! datasheet for information on affected pins.
  1379. //!
  1380. //! \return None.
  1381. //
  1382. //*****************************************************************************
  1383. void
  1384. GPIOPinTypeGPIOOutputOD(uint32_t ui32Port, uint8_t ui8Pins)
  1385. {
  1386. //
  1387. // Check the arguments.
  1388. //
  1389. ASSERT(_GPIOBaseValid(ui32Port));
  1390. //
  1391. // Set the pad(s) for standard push-pull operation.
  1392. //
  1393. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);
  1394. //
  1395. // Make the pin(s) be outputs.
  1396. //
  1397. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_OUT);
  1398. }
  1399. //*****************************************************************************
  1400. //
  1401. //! Configures pin for use as SDA by the I2C peripheral.
  1402. //!
  1403. //! \param ui32Port is the base address of the GPIO port.
  1404. //! \param ui8Pins is the bit-packed representation of the pin.
  1405. //!
  1406. //! The I2C pins must be properly configured for the I2C peripheral to function
  1407. //! correctly. This function provides the proper configuration for the SDA
  1408. //! pin.
  1409. //!
  1410. //! The pin is specified using a bit-packed byte, where each bit that is
  1411. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1412. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1413. //!
  1414. //! \note This function cannot be used to turn any pin into an I2C SDA pin; it
  1415. //! only configures an I2C SDA pin for proper operation. Note that a
  1416. //! GPIOPinConfigure() function call is also required to properly configure a
  1417. //! pin for the I2C SDA function.
  1418. //!
  1419. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1420. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1421. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1422. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1423. //! registers before this function can be called. Please see the ``gpio_jtag''
  1424. //! example application for the mechanism required and consult your part
  1425. //! datasheet for information on affected pins.
  1426. //!
  1427. //! \return None.
  1428. //
  1429. //*****************************************************************************
  1430. void
  1431. GPIOPinTypeI2C(uint32_t ui32Port, uint8_t ui8Pins)
  1432. {
  1433. //
  1434. // Check the arguments.
  1435. //
  1436. ASSERT(_GPIOBaseValid(ui32Port));
  1437. //
  1438. // Make the pin(s) be peripheral controlled.
  1439. //
  1440. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  1441. //
  1442. // Set the pad(s) for open-drain operation with a weak pull-up.
  1443. //
  1444. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);
  1445. }
  1446. //*****************************************************************************
  1447. //
  1448. //! Configures pin for use as SCL by the I2C peripheral.
  1449. //!
  1450. //! \param ui32Port is the base address of the GPIO port.
  1451. //! \param ui8Pins is the bit-packed representation of the pin.
  1452. //!
  1453. //! The I2C pins must be properly configured for the I2C peripheral to function
  1454. //! correctly. This function provides the proper configuration for the SCL
  1455. //! pin.
  1456. //!
  1457. //! The pin is specified using a bit-packed byte, where each bit that is
  1458. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1459. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1460. //!
  1461. //! \note This function cannot be used to turn any pin into an I2C SCL pin; it
  1462. //! only configures an I2C SCL pin for proper operation. Note that a
  1463. //! GPIOPinConfigure() function call is also required to properly configure a
  1464. //! pin for the I2C SCL function.
  1465. //!
  1466. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1467. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1468. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1469. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1470. //! registers before this function can be called. Please see the ``gpio_jtag''
  1471. //! example application for the mechanism required and consult your part
  1472. //! datasheet for information on affected pins.
  1473. //!
  1474. //! \return None.
  1475. //
  1476. //*****************************************************************************
  1477. void
  1478. GPIOPinTypeI2CSCL(uint32_t ui32Port, uint8_t ui8Pins)
  1479. {
  1480. //
  1481. // Check the arguments.
  1482. //
  1483. ASSERT(_GPIOBaseValid(ui32Port));
  1484. //
  1485. // Make the pin(s) be peripheral controlled.
  1486. //
  1487. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  1488. //
  1489. // Set the pad(s) for push-pull operation.
  1490. //
  1491. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
  1492. }
  1493. //*****************************************************************************
  1494. //
  1495. //! Configures pin(s) for use by the LCD Controller.
  1496. //!
  1497. //! \param ui32Port is the base address of the GPIO port.
  1498. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1499. //!
  1500. //! The LCD controller pins must be properly configured for the LCD controller
  1501. //! to function correctly. This function provides a typical configuration for
  1502. //! those pin(s); other configurations may work as well depending upon the
  1503. //! board setup (for example, using the on-chip pull-ups).
  1504. //!
  1505. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  1506. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1507. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1508. //!
  1509. //! \note This function cannot be used to turn any pin into an LCD pin; it only
  1510. //! configures an LCD pin for proper operation. Note that a GPIOPinConfigure()
  1511. //! function call is also required to properly configure a pin for the LCD
  1512. //! controller function.
  1513. //!
  1514. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1515. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1516. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1517. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1518. //! registers before this function can be called. Please see the ``gpio_jtag''
  1519. //! example application for the mechanism required and consult your part
  1520. //! datasheet for information on affected pins.
  1521. //!
  1522. //! \return None.
  1523. //
  1524. //*****************************************************************************
  1525. void
  1526. GPIOPinTypeLCD(uint32_t ui32Port, uint8_t ui8Pins)
  1527. {
  1528. //
  1529. // Check the arguments.
  1530. //
  1531. ASSERT(_GPIOBaseValid(ui32Port));
  1532. //
  1533. // Make the pin(s) be peripheral controlled.
  1534. //
  1535. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  1536. //
  1537. // Set the pad(s) for standard push-pull operation and beefed up drive.
  1538. //
  1539. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
  1540. }
  1541. //*****************************************************************************
  1542. //
  1543. //! Configures pin(s) for use by the LPC module.
  1544. //!
  1545. //! \param ui32Port is the base address of the GPIO port.
  1546. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1547. //!
  1548. //! The LPC pins must be properly configured for the LPC module to function
  1549. //! correctly. This function provides a typical configuration for those
  1550. //! pin(s); other configurations may work as well depending upon the board
  1551. //! setup (for example, using the on-chip pull-ups).
  1552. //!
  1553. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  1554. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1555. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1556. //!
  1557. //! \note This function cannot be used to turn any pin into an LPC pin; it only
  1558. //! configures an LPC pin for proper operation. Note that a GPIOPinConfigure()
  1559. //! function call is also required to properly configure a pin for the LPC
  1560. //! function.
  1561. //!
  1562. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1563. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1564. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1565. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1566. //! registers before this function can be called. Please see the ``gpio_jtag''
  1567. //! example application for the mechanism required and consult your part
  1568. //! datasheet for information on affected pins.
  1569. //!
  1570. //! \return None.
  1571. //
  1572. //*****************************************************************************
  1573. void
  1574. GPIOPinTypeLPC(uint32_t ui32Port, uint8_t ui8Pins)
  1575. {
  1576. //
  1577. // Check the arguments.
  1578. //
  1579. ASSERT(_GPIOBaseValid(ui32Port));
  1580. //
  1581. // Make the pin(s) be peripheral controlled.
  1582. //
  1583. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  1584. //
  1585. // Set the pad(s) for standard push-pull operation.
  1586. //
  1587. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
  1588. }
  1589. //*****************************************************************************
  1590. //
  1591. //! Configures a pin for receive use by the PECI module.
  1592. //!
  1593. //! \param ui32Port is the base address of the GPIO port.
  1594. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1595. //!
  1596. //! The PECI receive pin must be properly configured for the PECI module to
  1597. //! function correctly. This function provides a typical configuration for
  1598. //! that pin.
  1599. //!
  1600. //! The pin is specified using a bit-packed byte, where each bit that is set
  1601. //! identifies the pin to be accessed, and where bit 0 of the byte represents
  1602. //! GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1603. //!
  1604. //! \note This function cannot be used to turn any pin into a PECI receive pin;
  1605. //! it only configures a PECI receive pin for proper operation. Note that a
  1606. //! GPIOPinConfigure() function call is also required to properly configure a
  1607. //! pin for the PECI receive function.
  1608. //!
  1609. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1610. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1611. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1612. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1613. //! registers before this function can be called. Please see the ``gpio_jtag''
  1614. //! example application for the mechanism required and consult your part
  1615. //! datasheet for information on affected pins.
  1616. //!
  1617. //! \return None.
  1618. //
  1619. //*****************************************************************************
  1620. void
  1621. GPIOPinTypePECIRx(uint32_t ui32Port, uint8_t ui8Pins)
  1622. {
  1623. //
  1624. // Check the arguments.
  1625. //
  1626. ASSERT(_GPIOBaseValid(ui32Port));
  1627. //
  1628. // Make the pin(s) be inputs.
  1629. //
  1630. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_IN);
  1631. //
  1632. // Set the pad(s) for analog operation.
  1633. //
  1634. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA,
  1635. GPIO_PIN_TYPE_ANALOG);
  1636. }
  1637. //*****************************************************************************
  1638. //
  1639. //! Configures a pin for transmit use by the PECI module.
  1640. //!
  1641. //! \param ui32Port is the base address of the GPIO port.
  1642. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1643. //!
  1644. //! The PECI transmit pin must be properly configured for the PECI module to
  1645. //! function correctly. This function provides a typical configuration for
  1646. //! that pin.
  1647. //!
  1648. //! The pin is specified using a bit-packed byte, where each bit that is set
  1649. //! identifies the pin to be accessed, and where bit 0 of the byte represents
  1650. //! GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1651. //!
  1652. //! \note This function cannot be used to turn any pin into a PECI transmit
  1653. //! pin; it only configures a PECI transmit pin for proper operation. Note
  1654. //! that a GPIOPinConfigure() function call is also required to properly
  1655. //! configure the pin for the PECI transmit function.
  1656. //!
  1657. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1658. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1659. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1660. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1661. //! registers before this function can be called. Please see the ``gpio_jtag''
  1662. //! example application for the mechanism required and consult your part
  1663. //! datasheet for information on affected pins.
  1664. //!
  1665. //! \return None.
  1666. //
  1667. //*****************************************************************************
  1668. void
  1669. GPIOPinTypePECITx(uint32_t ui32Port, uint8_t ui8Pins)
  1670. {
  1671. //
  1672. // Check the arguments.
  1673. //
  1674. ASSERT(_GPIOBaseValid(ui32Port));
  1675. //
  1676. // Make the pin(s) be inputs.
  1677. //
  1678. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  1679. //
  1680. // Set the pad(s) for analog operation.
  1681. //
  1682. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
  1683. }
  1684. //*****************************************************************************
  1685. //
  1686. //! Configures pin(s) for use by the PWM peripheral.
  1687. //!
  1688. //! \param ui32Port is the base address of the GPIO port.
  1689. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1690. //!
  1691. //! The PWM pins must be properly configured for the PWM peripheral to function
  1692. //! correctly. This function provides a typical configuration for those
  1693. //! pin(s); other configurations may work as well depending upon the board
  1694. //! setup (for example, using the on-chip pull-ups).
  1695. //!
  1696. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  1697. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1698. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1699. //!
  1700. //! \note This function cannot be used to turn any pin into a PWM pin; it only
  1701. //! configures a PWM pin for proper operation. Note that a GPIOPinConfigure()
  1702. //! function call is also required to properly configure a pin for the PWM
  1703. //! function.
  1704. //!
  1705. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1706. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1707. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1708. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1709. //! registers before this function can be called. Please see the ``gpio_jtag''
  1710. //! example application for the mechanism required and consult your part
  1711. //! datasheet for information on affected pins.
  1712. //!
  1713. //! \return None.
  1714. //
  1715. //*****************************************************************************
  1716. void
  1717. GPIOPinTypePWM(uint32_t ui32Port, uint8_t ui8Pins)
  1718. {
  1719. //
  1720. // Check the arguments.
  1721. //
  1722. ASSERT(_GPIOBaseValid(ui32Port));
  1723. //
  1724. // Make the pin(s) be peripheral controlled.
  1725. //
  1726. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  1727. //
  1728. // Set the pad(s) for standard push-pull operation.
  1729. //
  1730. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
  1731. }
  1732. //*****************************************************************************
  1733. //
  1734. //! Configures pin(s) for use by the QEI peripheral.
  1735. //!
  1736. //! \param ui32Port is the base address of the GPIO port.
  1737. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1738. //!
  1739. //! The QEI pins must be properly configured for the QEI peripheral to function
  1740. //! correctly. This function provides a typical configuration for those
  1741. //! pin(s); other configurations may work as well depending upon the board
  1742. //! setup (for example, not using the on-chip pull-ups).
  1743. //!
  1744. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  1745. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1746. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1747. //!
  1748. //! \note This function cannot be used to turn any pin into a QEI pin; it only
  1749. //! configures a QEI pin for proper operation. Note that a GPIOPinConfigure()
  1750. //! function call is also required to properly configure a pin for the QEI
  1751. //! function.
  1752. //!
  1753. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1754. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1755. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1756. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1757. //! registers before this function can be called. Please see the ``gpio_jtag''
  1758. //! example application for the mechanism required and consult your part
  1759. //! datasheet for information on affected pins.
  1760. //!
  1761. //! \return None.
  1762. //
  1763. //*****************************************************************************
  1764. void
  1765. GPIOPinTypeQEI(uint32_t ui32Port, uint8_t ui8Pins)
  1766. {
  1767. //
  1768. // Check the arguments.
  1769. //
  1770. ASSERT(_GPIOBaseValid(ui32Port));
  1771. //
  1772. // Make the pin(s) be peripheral controlled.
  1773. //
  1774. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  1775. //
  1776. // Set the pad(s) for standard push-pull operation with a weak pull-up.
  1777. //
  1778. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA,
  1779. GPIO_PIN_TYPE_STD_WPU);
  1780. }
  1781. //*****************************************************************************
  1782. //
  1783. //! Configures pin(s) for use by the SSI peripheral.
  1784. //!
  1785. //! \param ui32Port is the base address of the GPIO port.
  1786. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1787. //!
  1788. //! The SSI pins must be properly configured for the SSI peripheral to function
  1789. //! correctly. This function provides a typical configuration for those
  1790. //! pin(s); other configurations may work as well depending upon the board
  1791. //! setup (for example, using the on-chip pull-ups).
  1792. //!
  1793. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  1794. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1795. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1796. //!
  1797. //! \note This function cannot be used to turn any pin into a SSI pin; it only
  1798. //! configures a SSI pin for proper operation. Note that a GPIOPinConfigure()
  1799. //! function call is also required to properly configure a pin for the SSI
  1800. //! function.
  1801. //!
  1802. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1803. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1804. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1805. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1806. //! registers before this function can be called. Please see the ``gpio_jtag''
  1807. //! example application for the mechanism required and consult your part
  1808. //! datasheet for information on affected pins.
  1809. //!
  1810. //! \return None.
  1811. //
  1812. //*****************************************************************************
  1813. void
  1814. GPIOPinTypeSSI(uint32_t ui32Port, uint8_t ui8Pins)
  1815. {
  1816. //
  1817. // Check the arguments.
  1818. //
  1819. ASSERT(_GPIOBaseValid(ui32Port));
  1820. //
  1821. // Make the pin(s) be peripheral controlled.
  1822. //
  1823. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  1824. //
  1825. // Set the pad(s) for standard push-pull operation.
  1826. //
  1827. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
  1828. }
  1829. //*****************************************************************************
  1830. //
  1831. //! Configures pin(s) for use by the Timer peripheral.
  1832. //!
  1833. //! \param ui32Port is the base address of the GPIO port.
  1834. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1835. //!
  1836. //! The CCP pins must be properly configured for the timer peripheral to
  1837. //! function correctly. This function provides a typical configuration for
  1838. //! those pin(s); other configurations may work as well depending upon the
  1839. //! board setup (for example, using the on-chip pull-ups).
  1840. //!
  1841. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  1842. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1843. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1844. //!
  1845. //! \note This function cannot be used to turn any pin into a timer pin; it
  1846. //! only configures a timer pin for proper operation. Note that a
  1847. //! GPIOPinConfigure() function call is also required to properly configure a
  1848. //! pin for the CCP function.
  1849. //!
  1850. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1851. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1852. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1853. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1854. //! registers before this function can be called. Please see the ``gpio_jtag''
  1855. //! example application for the mechanism required and consult your part
  1856. //! datasheet for information on affected pins.
  1857. //!
  1858. //! \return None.
  1859. //
  1860. //*****************************************************************************
  1861. void
  1862. GPIOPinTypeTimer(uint32_t ui32Port, uint8_t ui8Pins)
  1863. {
  1864. //
  1865. // Check the arguments.
  1866. //
  1867. ASSERT(_GPIOBaseValid(ui32Port));
  1868. //
  1869. // Make the pin(s) be peripheral controlled.
  1870. //
  1871. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  1872. //
  1873. // Set the pad(s) for standard push-pull operation.
  1874. //
  1875. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
  1876. }
  1877. //*****************************************************************************
  1878. //
  1879. //! Configures pin(s) for use by the UART peripheral.
  1880. //!
  1881. //! \param ui32Port is the base address of the GPIO port.
  1882. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1883. //!
  1884. //! The UART pins must be properly configured for the UART peripheral to
  1885. //! function correctly. This function provides a typical configuration for
  1886. //! those pin(s); other configurations may work as well depending upon the
  1887. //! board setup (for example, using the on-chip pull-ups).
  1888. //!
  1889. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  1890. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1891. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1892. //!
  1893. //! \note This function cannot be used to turn any pin into a UART pin; it
  1894. //! only configures a UART pin for proper operation. Note that a
  1895. //! GPIOPinConfigure() function call is also required to properly configure a
  1896. //! pin for the UART function.
  1897. //!
  1898. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1899. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1900. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1901. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1902. //! registers before this function can be called. Please see the ``gpio_jtag''
  1903. //! example application for the mechanism required and consult your part
  1904. //! datasheet for information on affected pins.
  1905. //!
  1906. //! \return None.
  1907. //
  1908. //*****************************************************************************
  1909. void
  1910. GPIOPinTypeUART(uint32_t ui32Port, uint8_t ui8Pins)
  1911. {
  1912. //
  1913. // Check the arguments.
  1914. //
  1915. ASSERT(_GPIOBaseValid(ui32Port));
  1916. //
  1917. // Make the pin(s) be peripheral controlled.
  1918. //
  1919. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  1920. //
  1921. // Set the pad(s) for standard push-pull operation.
  1922. //
  1923. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
  1924. }
  1925. //*****************************************************************************
  1926. //
  1927. //! Configures pin(s) for use by the USB peripheral.
  1928. //!
  1929. //! \param ui32Port is the base address of the GPIO port.
  1930. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1931. //!
  1932. //! USB analog pins must be properly configured for the USB peripheral to
  1933. //! function correctly. This function provides the proper configuration for
  1934. //! any USB analog pin(s).
  1935. //!
  1936. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  1937. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1938. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1939. //!
  1940. //! \note This function cannot be used to turn any pin into a USB pin; it only
  1941. //! configures a USB pin for proper operation. Note that a GPIOPinConfigure()
  1942. //! function call is also required to properly configure a pin for the USB
  1943. //! function.
  1944. //!
  1945. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1946. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  1947. //! locked against inadvertent reconfiguration. These pins must be unlocked
  1948. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  1949. //! registers before this function can be called. Please see the ``gpio_jtag''
  1950. //! example application for the mechanism required and consult your part
  1951. //! datasheet for information on affected pins.
  1952. //!
  1953. //! \return None.
  1954. //
  1955. //*****************************************************************************
  1956. void
  1957. GPIOPinTypeUSBAnalog(uint32_t ui32Port, uint8_t ui8Pins)
  1958. {
  1959. //
  1960. // Check the arguments.
  1961. //
  1962. ASSERT(_GPIOBaseValid(ui32Port));
  1963. //
  1964. // Make the pin(s) be inputs.
  1965. //
  1966. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_IN);
  1967. //
  1968. // Set the pad(s) for analog operation.
  1969. //
  1970. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA,
  1971. GPIO_PIN_TYPE_ANALOG);
  1972. }
  1973. //*****************************************************************************
  1974. //
  1975. //! Configures pin(s) for use by the USB peripheral.
  1976. //!
  1977. //! \param ui32Port is the base address of the GPIO port.
  1978. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1979. //!
  1980. //! USB digital pins must be properly configured for the USB peripheral to
  1981. //! function correctly. This function provides a typical configuration for
  1982. //! the digital USB pin(s); other configurations may work as well depending
  1983. //! upon the board setup (for example, using the on-chip pull-ups).
  1984. //!
  1985. //! This function should only be used with EPEN and PFAULT pins as all other
  1986. //! USB pins are analog in nature or are not used in devices without OTG
  1987. //! functionality.
  1988. //!
  1989. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  1990. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1991. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1992. //!
  1993. //! \note This function cannot be used to turn any pin into a USB pin; it only
  1994. //! configures a USB pin for proper operation. Note that a GPIOPinConfigure()
  1995. //! function call is also required to properly configure a pin for the USB
  1996. //! function.
  1997. //!
  1998. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  1999. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  2000. //! locked against inadvertent reconfiguration. These pins must be unlocked
  2001. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  2002. //! registers before this function can be called. Please see the ``gpio_jtag''
  2003. //! example application for the mechanism required and consult your part
  2004. //! datasheet for information on affected pins.
  2005. //!
  2006. //! \return None.
  2007. //
  2008. //*****************************************************************************
  2009. void
  2010. GPIOPinTypeUSBDigital(uint32_t ui32Port, uint8_t ui8Pins)
  2011. {
  2012. //
  2013. // Check the arguments.
  2014. //
  2015. ASSERT(_GPIOBaseValid(ui32Port));
  2016. //
  2017. // Make the pin(s) be peripheral controlled.
  2018. //
  2019. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  2020. //
  2021. // Set the pad(s) for standard push-pull operation.
  2022. //
  2023. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
  2024. }
  2025. //*****************************************************************************
  2026. //
  2027. //! Configures pin(s) for use as a hibernate wake-on-high source.
  2028. //!
  2029. //! \param ui32Port is the base address of the GPIO port.
  2030. //! \param ui8Pins is the bit-packed representation of the pin(s).
  2031. //!
  2032. //! The GPIO pins must be properly configured in order to function correctly as
  2033. //! hibernate wake-high inputs. This function provides the proper
  2034. //! configuration for those pin(s).
  2035. //!
  2036. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  2037. //! set identifies the pin to be accessed, and where bit 0 of the byte
  2038. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  2039. //!
  2040. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  2041. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  2042. //! locked against inadvertent reconfiguration. These pins must be unlocked
  2043. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  2044. //! registers before this function can be called. Please see the ``gpio_jtag''
  2045. //! example application for the mechanism required and consult your part
  2046. //! datasheet for information on affected pins.
  2047. //!
  2048. //! \return None.
  2049. //
  2050. //*****************************************************************************
  2051. void
  2052. GPIOPinTypeWakeHigh(uint32_t ui32Port, uint8_t ui8Pins)
  2053. {
  2054. //
  2055. // Check the arguments.
  2056. //
  2057. ASSERT(_GPIOBaseValid(ui32Port));
  2058. //
  2059. // Make the pin(s) inputs.
  2060. //
  2061. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_IN);
  2062. //
  2063. // Set the pad(s) for wake-high operation.
  2064. //
  2065. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA,
  2066. GPIO_PIN_TYPE_WAKE_HIGH);
  2067. }
  2068. //*****************************************************************************
  2069. //
  2070. //! Configures pin(s) for use as a hibernate wake-on-low source.
  2071. //!
  2072. //! \param ui32Port is the base address of the GPIO port.
  2073. //! \param ui8Pins is the bit-packed representation of the pin(s).
  2074. //!
  2075. //! The GPIO pins must be properly configured in order to function correctly as
  2076. //! hibernate wake-low inputs. This function provides the proper
  2077. //! configuration for those pin(s).
  2078. //!
  2079. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  2080. //! set identifies the pin to be accessed, and where bit 0 of the byte
  2081. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  2082. //!
  2083. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  2084. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  2085. //! locked against inadvertent reconfiguration. These pins must be unlocked
  2086. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  2087. //! registers before this function can be called. Please see the ``gpio_jtag''
  2088. //! example application for the mechanism required and consult your part
  2089. //! datasheet for information on affected pins.
  2090. //!
  2091. //! \return None.
  2092. //
  2093. //*****************************************************************************
  2094. void
  2095. GPIOPinTypeWakeLow(uint32_t ui32Port, uint8_t ui8Pins)
  2096. {
  2097. //
  2098. // Check the arguments.
  2099. //
  2100. ASSERT(_GPIOBaseValid(ui32Port));
  2101. //
  2102. // Make the pin(s) inputs.
  2103. //
  2104. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_IN);
  2105. //
  2106. // Set the pad(s) for wake-high operation.
  2107. //
  2108. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA,
  2109. GPIO_PIN_TYPE_WAKE_LOW);
  2110. }
  2111. //*****************************************************************************
  2112. //
  2113. //! Configures pin(s) for use as scan matrix keyboard rows (outputs).
  2114. //!
  2115. //! \param ui32Port is the base address of the GPIO port.
  2116. //! \param ui8Pins is the bit-packed representation of the pin(s).
  2117. //!
  2118. //! The GPIO pins must be properly configured in order to function correctly as
  2119. //! scan matrix keyboard outputs. This function provides the proper
  2120. //! configuration for those pin(s).
  2121. //!
  2122. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  2123. //! set identifies the pin to be accessed, and where bit 0 of the byte
  2124. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  2125. //!
  2126. //! \note This function cannot be used to turn any pin into a scan matrix
  2127. //! keyboard row pin; it only configures a scan matrix keyboard row pin for
  2128. //! proper operation. Note that a GPIOPinConfigure() function call is also
  2129. //! required to properly configure a pin for the scan matrix keyboard
  2130. //! function.
  2131. //!
  2132. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  2133. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  2134. //! locked against inadvertent reconfiguration. These pins must be unlocked
  2135. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  2136. //! registers before this function can be called. Please see the ``gpio_jtag''
  2137. //! example application for the mechanism required and consult your part
  2138. //! datasheet for information on affected pins.
  2139. //!
  2140. //! \return None.
  2141. //
  2142. //*****************************************************************************
  2143. void
  2144. GPIOPinTypeKBRow(uint32_t ui32Port, uint8_t ui8Pins)
  2145. {
  2146. //
  2147. // Check the arguments.
  2148. //
  2149. ASSERT(_GPIOBaseValid(ui32Port));
  2150. //
  2151. // Make the pin(s) be peripheral controlled.
  2152. //
  2153. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  2154. //
  2155. // Set the pad(s) for push/pull operation.
  2156. //
  2157. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
  2158. }
  2159. //*****************************************************************************
  2160. //
  2161. //! Configures pin(s) for use as scan matrix keyboard columns (inputs).
  2162. //!
  2163. //! \param ui32Port is the base address of the GPIO port.
  2164. //! \param ui8Pins is the bit-packed representation of the pin(s).
  2165. //!
  2166. //! The GPIO pins must be properly configured in order to function correctly as
  2167. //! scan matrix keyboard inputs. This function provides the proper
  2168. //! configuration for those pin(s).
  2169. //!
  2170. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  2171. //! set identifies the pin to be accessed, and where bit 0 of the byte
  2172. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  2173. //!
  2174. //! \note This function cannot be used to turn any pin into a scan matrix
  2175. //! keyboard column pin; it only configures a scan matrix keyboard column pin
  2176. //! for proper operation. Note that a GPIOPinConfigure() function call is also
  2177. //! required to properly configure a pin for the scan matrix keyboard
  2178. //! function.
  2179. //!
  2180. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  2181. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  2182. //! locked against inadvertent reconfiguration. These pins must be unlocked
  2183. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  2184. //! registers before this function can be called. Please see the ``gpio_jtag''
  2185. //! example application for the mechanism required and consult your part
  2186. //! datasheet for information on affected pins.
  2187. //!
  2188. //! \return None.
  2189. //
  2190. //*****************************************************************************
  2191. void
  2192. GPIOPinTypeKBColumn(uint32_t ui32Port, uint8_t ui8Pins)
  2193. {
  2194. //
  2195. // Check the arguments.
  2196. //
  2197. ASSERT(_GPIOBaseValid(ui32Port));
  2198. //
  2199. // Make the pin(s) be peripheral controlled.
  2200. //
  2201. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  2202. //
  2203. // Set the pad(s) for standard push-pull operation.
  2204. //
  2205. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA,
  2206. GPIO_PIN_TYPE_STD_WPU);
  2207. }
  2208. //*****************************************************************************
  2209. //
  2210. //! Configures pin(s) for use as an LED sequencer output.
  2211. //!
  2212. //! \param ui32Port is the base address of the GPIO port.
  2213. //! \param ui8Pins is the bit-packed representation of the pin(s).
  2214. //!
  2215. //! The GPIO pins must be properly configured in order to function correctly as
  2216. //! LED sequencers. This function provides the proper configuration for those
  2217. //! pin(s).
  2218. //!
  2219. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  2220. //! set identifies the pin to be accessed, and where bit 0 of the byte
  2221. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  2222. //!
  2223. //! \note This function cannot be used to turn any pin into an LED sequencer
  2224. //! output pin; it only configures an LED sequencer output pin for proper
  2225. //! operation. Note that a GPIOPinConfigure() function call is also
  2226. //! required to properly configure a pin for the LED sequencer function.
  2227. //!
  2228. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  2229. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  2230. //! locked against inadvertent reconfiguration. These pins must be unlocked
  2231. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  2232. //! registers before this function can be called. Please see the ``gpio_jtag''
  2233. //! example application for the mechanism required and consult your part
  2234. //! datasheet for information on affected pins.
  2235. //!
  2236. //! \return None.
  2237. //
  2238. //*****************************************************************************
  2239. void
  2240. GPIOPinTypeLEDSeq(uint32_t ui32Port, uint8_t ui8Pins)
  2241. {
  2242. //
  2243. // Check the arguments.
  2244. //
  2245. ASSERT(_GPIOBaseValid(ui32Port));
  2246. //
  2247. // Make the pin(s) be peripheral controlled.
  2248. //
  2249. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  2250. //
  2251. // Set the pad(s) for push/pull operation and 8mA strength. The external
  2252. // hardware should be set up such that we sink current when the LED is
  2253. // turned on, hence the 8mA configuration choice.
  2254. //
  2255. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
  2256. }
  2257. //*****************************************************************************
  2258. //
  2259. //! Configures pin(s) for use as Consumer Infrared inputs or outputs.
  2260. //!
  2261. //! \param ui32Port is the base address of the GPIO port.
  2262. //! \param ui8Pins is the bit-packed representation of the pin(s).
  2263. //!
  2264. //! The GPIO pins must be properly configured in order to function correctly as
  2265. //! Consumer Infrared pins. This function provides the proper configuration
  2266. //! for those pin(s).
  2267. //!
  2268. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  2269. //! set identifies the pin to be accessed, and where bit 0 of the byte
  2270. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  2271. //!
  2272. //! \note This function cannot be used to turn any pin into a CIR pin; it only
  2273. //! configures a CIR pin for proper operation. Note that a GPIOPinConfigure()
  2274. //! function call is also required to properly configure a pin for the
  2275. //! Consumer Infrared function.
  2276. //!
  2277. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  2278. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  2279. //! locked against inadvertent reconfiguration. These pins must be unlocked
  2280. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  2281. //! registers before this function can be called. Please see the ``gpio_jtag''
  2282. //! example application for the mechanism required and consult your part
  2283. //! datasheet for information on affected pins.
  2284. //!
  2285. //! \return None.
  2286. //
  2287. //*****************************************************************************
  2288. void
  2289. GPIOPinTypeCIR(uint32_t ui32Port, uint8_t ui8Pins)
  2290. {
  2291. //
  2292. // Check the arguments.
  2293. //
  2294. ASSERT(_GPIOBaseValid(ui32Port));
  2295. //
  2296. // Make the pin(s) be peripheral controlled.
  2297. //
  2298. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  2299. //
  2300. // Set the pad(s) for standard push-pull operation.
  2301. //
  2302. GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
  2303. }
  2304. //*****************************************************************************
  2305. //
  2306. //! Retrieves the wake pins status.
  2307. //!
  2308. //! \param ui32Port is the base address of the GPIO port.
  2309. //!
  2310. //! This function returns the GPIO wake pin status values. The returned
  2311. //! bitfield shows low or high pin state via a value of 0 or 1.
  2312. //!
  2313. //! \note This function is not available on all devices, consult the data sheet
  2314. //! to ensure that the device you are using supports GPIO wake pins.
  2315. //!
  2316. //! \note A subset of GPIO pins on Tiva devices, notably those used by the
  2317. //! JTAG/SWD interface and any pin capable of acting as an NMI input, are
  2318. //! locked against inadvertent reconfiguration. These pins must be unlocked
  2319. //! using direct register writes to the relevant GPIO_O_LOCK and GPIO_O_CR
  2320. //! registers before this function can be called. Please see the ``gpio_jtag''
  2321. //! example application for the mechanism required and consult your part
  2322. //! datasheet for information on affected pins.
  2323. //!
  2324. //! \return Returns the wake pin status.
  2325. //
  2326. //*****************************************************************************
  2327. uint32_t
  2328. GPIOPinWakeStatus(uint32_t ui32Port)
  2329. {
  2330. return(ui32Port + GPIO_O_WAKESTAT);
  2331. }
  2332. //*****************************************************************************
  2333. //
  2334. //! Configures the alternate function of a GPIO pin.
  2335. //!
  2336. //! \param ui32PinConfig is the pin configuration value, specified as only one
  2337. //! of the \b GPIO_P??_??? values.
  2338. //!
  2339. //! This function configures the pin mux that selects the peripheral function
  2340. //! associated with a particular GPIO pin. Only one peripheral function at a
  2341. //! time can be associated with a GPIO pin, and each peripheral function should
  2342. //! only be associated with a single GPIO pin at a time (despite the fact that
  2343. //! many of them can be associated with more than one GPIO pin). To fully
  2344. //! configure a pin, a GPIOPinType*() function should also be called.
  2345. //!
  2346. //! The available mappings are supplied on a per-device basis in
  2347. //! <tt>pin_map.h</tt>. The \b PART_<partno> defines controls which set of
  2348. //! defines are included so that they match the device that is being used.
  2349. //! For example, \b PART_TM4C129XNCZAD must be defined in order to get the
  2350. //! correct pin mappings for the TM4C129XNCZAD device.
  2351. //!
  2352. //! \note If the same signal is assigned to two different GPIO port
  2353. //! pins, the signal is assigned to the port with the lowest letter and the
  2354. //! assignment to the higher letter port is ignored.
  2355. //!
  2356. //! \return None.
  2357. //
  2358. //*****************************************************************************
  2359. void
  2360. GPIOPinConfigure(uint32_t ui32PinConfig)
  2361. {
  2362. uint32_t ui32Base, ui32Shift;
  2363. //
  2364. // Check the argument.
  2365. //
  2366. ASSERT(((ui32PinConfig >> 16) & 0xff) < 15);
  2367. ASSERT(((ui32PinConfig >> 8) & 0xe3) == 0);
  2368. //
  2369. // Extract the base address index from the input value.
  2370. //
  2371. ui32Base = (ui32PinConfig >> 16) & 0xff;
  2372. //
  2373. // Get the base address of the GPIO module, selecting either the APB or the
  2374. // AHB aperture as appropriate.
  2375. //
  2376. if(HWREG(SYSCTL_GPIOHBCTL) & (1 << ui32Base))
  2377. {
  2378. ui32Base = g_pui32GPIOBaseAddrs[(ui32Base << 1) + 1];
  2379. }
  2380. else
  2381. {
  2382. ui32Base = g_pui32GPIOBaseAddrs[ui32Base << 1];
  2383. }
  2384. //
  2385. // Extract the shift from the input value.
  2386. //
  2387. ui32Shift = (ui32PinConfig >> 8) & 0xff;
  2388. //
  2389. // Write the requested pin muxing value for this GPIO pin.
  2390. //
  2391. HWREG(ui32Base + GPIO_O_PCTL) = ((HWREG(ui32Base + GPIO_O_PCTL) &
  2392. ~(0xf << ui32Shift)) |
  2393. ((ui32PinConfig & 0xf) << ui32Shift));
  2394. }
  2395. //*****************************************************************************
  2396. //
  2397. //! Enables a GPIO pin as a trigger to start a DMA transaction.
  2398. //!
  2399. //! \param ui32Port is the base address of the GPIO port.
  2400. //! \param ui8Pins is the bit-packed representation of the pin(s).
  2401. //!
  2402. //! This function enables a GPIO pin to be used as a trigger to start a uDMA
  2403. //! transaction. Any GPIO pin can be configured to be an external trigger for
  2404. //! the uDMA. The GPIO pin still generates interrupts if the interrupt is
  2405. //! enabled for the selected pin.
  2406. //!
  2407. //! \return None.
  2408. //
  2409. //*****************************************************************************
  2410. void
  2411. GPIODMATriggerEnable(uint32_t ui32Port, uint8_t ui8Pins)
  2412. {
  2413. //
  2414. // Check the arguments.
  2415. //
  2416. ASSERT(_GPIOBaseValid(ui32Port));
  2417. //
  2418. // Set the pin as a DMA trigger.
  2419. //
  2420. HWREG(ui32Port + GPIO_O_DMACTL) |= ui8Pins;
  2421. }
  2422. //*****************************************************************************
  2423. //
  2424. //! Disables a GPIO pin as a trigger to start a DMA transaction.
  2425. //!
  2426. //! \param ui32Port is the base address of the GPIO port.
  2427. //! \param ui8Pins is the bit-packed representation of the pin(s).
  2428. //!
  2429. //! This function disables a GPIO pin from being used as a trigger to start a
  2430. //! uDMA transaction. This function can be used to disable this feature if it
  2431. //! was enabled via a call to GPIODMATriggerEnable().
  2432. //!
  2433. //! \return None.
  2434. //
  2435. //*****************************************************************************
  2436. void
  2437. GPIODMATriggerDisable(uint32_t ui32Port, uint8_t ui8Pins)
  2438. {
  2439. //
  2440. // Check the arguments.
  2441. //
  2442. ASSERT(_GPIOBaseValid(ui32Port));
  2443. //
  2444. // Set the pin as a DMA trigger.
  2445. //
  2446. HWREG(ui32Port + GPIO_O_DMACTL) &= (~ui8Pins);
  2447. }
  2448. //*****************************************************************************
  2449. //
  2450. //! Enables a GPIO pin as a trigger to start an ADC capture.
  2451. //!
  2452. //! \param ui32Port is the base address of the GPIO port.
  2453. //! \param ui8Pins is the bit-packed representation of the pin(s).
  2454. //!
  2455. //! This function enables a GPIO pin to be used as a trigger to start an ADC
  2456. //! sequence. Any GPIO pin can be configured to be an external trigger for an
  2457. //! ADC sequence. The GPIO pin still generates interrupts if the interrupt is
  2458. //! enabled for the selected pin. To enable the use of a GPIO pin to trigger
  2459. //! the ADC module, the ADCSequenceConfigure() function must be called with the
  2460. //! \b ADC_TRIGGER_EXTERNAL parameter.
  2461. //!
  2462. //! \return None.
  2463. //
  2464. //*****************************************************************************
  2465. void
  2466. GPIOADCTriggerEnable(uint32_t ui32Port, uint8_t ui8Pins)
  2467. {
  2468. //
  2469. // Check the arguments.
  2470. //
  2471. ASSERT(_GPIOBaseValid(ui32Port));
  2472. //
  2473. // Set the pin as a DMA trigger.
  2474. //
  2475. HWREG(ui32Port + GPIO_O_ADCCTL) |= ui8Pins;
  2476. }
  2477. //*****************************************************************************
  2478. //
  2479. //! Disable a GPIO pin as a trigger to start an ADC capture.
  2480. //!
  2481. //! \param ui32Port is the base address of the GPIO port.
  2482. //! \param ui8Pins is the bit-packed representation of the pin(s).
  2483. //!
  2484. //! This function disables a GPIO pin to be used as a trigger to start an ADC
  2485. //! sequence. This function can be used to disable this feature if it was
  2486. //! enabled via a call to GPIOADCTriggerEnable().
  2487. //!
  2488. //! \return None.
  2489. //
  2490. //*****************************************************************************
  2491. void
  2492. GPIOADCTriggerDisable(uint32_t ui32Port, uint8_t ui8Pins)
  2493. {
  2494. //
  2495. // Check the arguments.
  2496. //
  2497. ASSERT(_GPIOBaseValid(ui32Port));
  2498. //
  2499. // Set the pin as a DMA trigger.
  2500. //
  2501. HWREG(ui32Port + GPIO_O_ADCCTL) &= (~ui8Pins);
  2502. }
  2503. //*****************************************************************************
  2504. //
  2505. // Close the Doxygen group.
  2506. //! @}
  2507. //
  2508. //*****************************************************************************