gpio.c 98 KB

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