My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

lpc17xx_gpio.c 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. /**********************************************************************
  2. * $Id$ lpc17xx_gpio.c 2010-05-21
  3. *//**
  4. * @file lpc17xx_gpio.c
  5. * @brief Contains all functions support for GPIO firmware
  6. * library on LPC17xx
  7. * @version 2.0
  8. * @date 21. May. 2010
  9. * @author NXP MCU SW Application Team
  10. *
  11. * Copyright(C) 2010, NXP Semiconductor
  12. * All rights reserved.
  13. *
  14. ***********************************************************************
  15. * Software that is described herein is for illustrative purposes only
  16. * which provides customers with programming information regarding the
  17. * products. This software is supplied "AS IS" without any warranties.
  18. * NXP Semiconductors assumes no responsibility or liability for the
  19. * use of the software, conveys no license or title under any patent,
  20. * copyright, or mask work right to the product. NXP Semiconductors
  21. * reserves the right to make changes in the software without
  22. * notification. NXP Semiconductors also make no representation or
  23. * warranty that such application will be suitable for the specified
  24. * use without further testing or modification.
  25. * Permission to use, copy, modify, and distribute this software and its
  26. * documentation is hereby granted, under NXP Semiconductors'
  27. * relevant copyright in the software, without fee, provided that it
  28. * is used in conjunction with NXP Semiconductors microcontrollers. This
  29. * copyright, permission, and disclaimer notice must appear in all copies of
  30. * this code.
  31. **********************************************************************/
  32. /* Peripheral group ----------------------------------------------------------- */
  33. /** @addtogroup GPIO
  34. * @{
  35. */
  36. /* Includes ------------------------------------------------------------------- */
  37. #include "lpc17xx_gpio.h"
  38. /* If this source file built with example, the LPC17xx FW library configuration
  39. * file in each example directory ("lpc17xx_libcfg.h") must be included,
  40. * otherwise the default FW library configuration file must be included instead
  41. */
  42. #ifdef __BUILD_WITH_EXAMPLE__
  43. #include "lpc17xx_libcfg.h"
  44. #else
  45. #include "lpc17xx_libcfg_default.h"
  46. #endif /* __BUILD_WITH_EXAMPLE__ */
  47. #ifdef _GPIO
  48. /* Private Functions ---------------------------------------------------------- */
  49. static LPC_GPIO_TypeDef *GPIO_GetPointer(uint8_t portNum);
  50. static GPIO_HalfWord_TypeDef *FIO_HalfWordGetPointer(uint8_t portNum);
  51. static GPIO_Byte_TypeDef *FIO_ByteGetPointer(uint8_t portNum);
  52. /*********************************************************************//**
  53. * @brief Get pointer to GPIO peripheral due to GPIO port
  54. * @param[in] portNum Port Number value, should be in range from 0 to 4.
  55. * @return Pointer to GPIO peripheral
  56. **********************************************************************/
  57. static LPC_GPIO_TypeDef *GPIO_GetPointer(uint8_t portNum)
  58. {
  59. LPC_GPIO_TypeDef *pGPIO = NULL;
  60. switch (portNum) {
  61. case 0:
  62. pGPIO = LPC_GPIO0;
  63. break;
  64. case 1:
  65. pGPIO = LPC_GPIO1;
  66. break;
  67. case 2:
  68. pGPIO = LPC_GPIO2;
  69. break;
  70. case 3:
  71. pGPIO = LPC_GPIO3;
  72. break;
  73. case 4:
  74. pGPIO = LPC_GPIO4;
  75. break;
  76. default:
  77. break;
  78. }
  79. return pGPIO;
  80. }
  81. /*********************************************************************//**
  82. * @brief Get pointer to FIO peripheral in halfword accessible style
  83. * due to FIO port
  84. * @param[in] portNum Port Number value, should be in range from 0 to 4.
  85. * @return Pointer to FIO peripheral
  86. **********************************************************************/
  87. static GPIO_HalfWord_TypeDef *FIO_HalfWordGetPointer(uint8_t portNum)
  88. {
  89. GPIO_HalfWord_TypeDef *pFIO = NULL;
  90. switch (portNum) {
  91. case 0:
  92. pFIO = GPIO0_HalfWord;
  93. break;
  94. case 1:
  95. pFIO = GPIO1_HalfWord;
  96. break;
  97. case 2:
  98. pFIO = GPIO2_HalfWord;
  99. break;
  100. case 3:
  101. pFIO = GPIO3_HalfWord;
  102. break;
  103. case 4:
  104. pFIO = GPIO4_HalfWord;
  105. break;
  106. default:
  107. break;
  108. }
  109. return pFIO;
  110. }
  111. /*********************************************************************//**
  112. * @brief Get pointer to FIO peripheral in byte accessible style
  113. * due to FIO port
  114. * @param[in] portNum Port Number value, should be in range from 0 to 4.
  115. * @return Pointer to FIO peripheral
  116. **********************************************************************/
  117. static GPIO_Byte_TypeDef *FIO_ByteGetPointer(uint8_t portNum)
  118. {
  119. GPIO_Byte_TypeDef *pFIO = NULL;
  120. switch (portNum) {
  121. case 0:
  122. pFIO = GPIO0_Byte;
  123. break;
  124. case 1:
  125. pFIO = GPIO1_Byte;
  126. break;
  127. case 2:
  128. pFIO = GPIO2_Byte;
  129. break;
  130. case 3:
  131. pFIO = GPIO3_Byte;
  132. break;
  133. case 4:
  134. pFIO = GPIO4_Byte;
  135. break;
  136. default:
  137. break;
  138. }
  139. return pFIO;
  140. }
  141. /* End of Private Functions --------------------------------------------------- */
  142. /* Public Functions ----------------------------------------------------------- */
  143. /** @addtogroup GPIO_Public_Functions
  144. * @{
  145. */
  146. /* GPIO ------------------------------------------------------------------------------ */
  147. /*********************************************************************//**
  148. * @brief Set Direction for GPIO port.
  149. * @param[in] portNum Port Number value, should be in range from 0 to 4
  150. * @param[in] bitValue Value that contains all bits to set direction,
  151. * in range from 0 to 0xFFFFFFFF.
  152. * example: value 0x5 to set direction for bit 0 and bit 1.
  153. * @param[in] dir Direction value, should be:
  154. * - 0: Input.
  155. * - 1: Output.
  156. * @return None
  157. *
  158. * Note: All remaining bits that are not activated in bitValue (value '0')
  159. * will not be effected by this function.
  160. **********************************************************************/
  161. void GPIO_SetDir(uint8_t portNum, uint32_t bitValue, uint8_t dir)
  162. {
  163. LPC_GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum);
  164. if (pGPIO != NULL) {
  165. // Enable Output
  166. if (dir) {
  167. pGPIO->FIODIR |= bitValue;
  168. }
  169. // Enable Input
  170. else {
  171. pGPIO->FIODIR &= ~bitValue;
  172. }
  173. }
  174. }
  175. /*********************************************************************//**
  176. * @brief Set Value for bits that have output direction on GPIO port.
  177. * @param[in] portNum Port number value, should be in range from 0 to 4
  178. * @param[in] bitValue Value that contains all bits on GPIO to set,
  179. * in range from 0 to 0xFFFFFFFF.
  180. * example: value 0x5 to set bit 0 and bit 1.
  181. * @return None
  182. *
  183. * Note:
  184. * - For all bits that has been set as input direction, this function will
  185. * not effect.
  186. * - For all remaining bits that are not activated in bitValue (value '0')
  187. * will not be effected by this function.
  188. **********************************************************************/
  189. void GPIO_SetValue(uint8_t portNum, uint32_t bitValue)
  190. {
  191. LPC_GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum);
  192. if (pGPIO != NULL) {
  193. pGPIO->FIOSET = bitValue;
  194. }
  195. }
  196. /*********************************************************************//**
  197. * @brief Clear Value for bits that have output direction on GPIO port.
  198. * @param[in] portNum Port number value, should be in range from 0 to 4
  199. * @param[in] bitValue Value that contains all bits on GPIO to clear,
  200. * in range from 0 to 0xFFFFFFFF.
  201. * example: value 0x5 to clear bit 0 and bit 1.
  202. * @return None
  203. *
  204. * Note:
  205. * - For all bits that has been set as input direction, this function will
  206. * not effect.
  207. * - For all remaining bits that are not activated in bitValue (value '0')
  208. * will not be effected by this function.
  209. **********************************************************************/
  210. void GPIO_ClearValue(uint8_t portNum, uint32_t bitValue)
  211. {
  212. LPC_GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum);
  213. if (pGPIO != NULL) {
  214. pGPIO->FIOCLR = bitValue;
  215. }
  216. }
  217. /*********************************************************************//**
  218. * @brief Read Current state on port pin that have input direction of GPIO
  219. * @param[in] portNum Port number to read value, in range from 0 to 4
  220. * @return Current value of GPIO port.
  221. *
  222. * Note: Return value contain state of each port pin (bit) on that GPIO regardless
  223. * its direction is input or output.
  224. **********************************************************************/
  225. uint32_t GPIO_ReadValue(uint8_t portNum)
  226. {
  227. LPC_GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum);
  228. if (pGPIO != NULL) {
  229. return pGPIO->FIOPIN;
  230. }
  231. return (0);
  232. }
  233. /*********************************************************************//**
  234. * @brief Enable GPIO interrupt (just used for P0.0-P0.30, P2.0-P2.13)
  235. * @param[in] portNum Port number to read value, should be: 0 or 2
  236. * @param[in] bitValue Value that contains all bits on GPIO to enable,
  237. * in range from 0 to 0xFFFFFFFF.
  238. * @param[in] edgeState state of edge, should be:
  239. * - 0: Rising edge
  240. * - 1: Falling edge
  241. * @return None
  242. **********************************************************************/
  243. void GPIO_IntCmd(uint8_t portNum, uint32_t bitValue, uint8_t edgeState)
  244. {
  245. if((portNum == 0)&&(edgeState == 0))
  246. LPC_GPIOINT->IO0IntEnR = bitValue;
  247. else if ((portNum == 2)&&(edgeState == 0))
  248. LPC_GPIOINT->IO2IntEnR = bitValue;
  249. else if ((portNum == 0)&&(edgeState == 1))
  250. LPC_GPIOINT->IO0IntEnF = bitValue;
  251. else if ((portNum == 2)&&(edgeState == 1))
  252. LPC_GPIOINT->IO2IntEnF = bitValue;
  253. else
  254. //Error
  255. while(1);
  256. }
  257. /*********************************************************************//**
  258. * @brief Get GPIO Interrupt Status (just used for P0.0-P0.30, P2.0-P2.13)
  259. * @param[in] portNum Port number to read value, should be: 0 or 2
  260. * @param[in] pinNum Pin number, should be: 0..30(with port 0) and 0..13
  261. * (with port 2)
  262. * @param[in] edgeState state of edge, should be:
  263. * - 0: Rising edge
  264. * - 1: Falling edge
  265. * @return Bool could be:
  266. * - ENABLE: Interrupt has been generated due to a rising
  267. * edge on P0.0
  268. * - DISABLE: A rising edge has not been detected on P0.0
  269. **********************************************************************/
  270. FunctionalState GPIO_GetIntStatus(uint8_t portNum, uint32_t pinNum, uint8_t edgeState)
  271. {
  272. if((portNum == 0) && (edgeState == 0))//Rising Edge
  273. return ((FunctionalState)(((LPC_GPIOINT->IO0IntStatR)>>pinNum)& 0x1));
  274. else if ((portNum == 2) && (edgeState == 0))
  275. return ((FunctionalState)(((LPC_GPIOINT->IO2IntStatR)>>pinNum)& 0x1));
  276. else if ((portNum == 0) && (edgeState == 1))//Falling Edge
  277. return ((FunctionalState)(((LPC_GPIOINT->IO0IntStatF)>>pinNum)& 0x1));
  278. else if ((portNum == 2) && (edgeState == 1))
  279. return ((FunctionalState)(((LPC_GPIOINT->IO2IntStatF)>>pinNum)& 0x1));
  280. else
  281. //Error
  282. while(1);
  283. }
  284. /*********************************************************************//**
  285. * @brief Clear GPIO interrupt (just used for P0.0-P0.30, P2.0-P2.13)
  286. * @param[in] portNum Port number to read value, should be: 0 or 2
  287. * @param[in] bitValue Value that contains all bits on GPIO to enable,
  288. * in range from 0 to 0xFFFFFFFF.
  289. * @return None
  290. **********************************************************************/
  291. void GPIO_ClearInt(uint8_t portNum, uint32_t bitValue)
  292. {
  293. if(portNum == 0)
  294. LPC_GPIOINT->IO0IntClr = bitValue;
  295. else if (portNum == 2)
  296. LPC_GPIOINT->IO2IntClr = bitValue;
  297. else
  298. //Invalid portNum
  299. while(1);
  300. }
  301. /* FIO word accessible ----------------------------------------------------------------- */
  302. /* Stub function for FIO (word-accessible) style */
  303. /**
  304. * @brief The same with GPIO_SetDir()
  305. */
  306. void FIO_SetDir(uint8_t portNum, uint32_t bitValue, uint8_t dir)
  307. {
  308. GPIO_SetDir(portNum, bitValue, dir);
  309. }
  310. /**
  311. * @brief The same with GPIO_SetValue()
  312. */
  313. void FIO_SetValue(uint8_t portNum, uint32_t bitValue)
  314. {
  315. GPIO_SetValue(portNum, bitValue);
  316. }
  317. /**
  318. * @brief The same with GPIO_ClearValue()
  319. */
  320. void FIO_ClearValue(uint8_t portNum, uint32_t bitValue)
  321. {
  322. GPIO_ClearValue(portNum, bitValue);
  323. }
  324. /**
  325. * @brief The same with GPIO_ReadValue()
  326. */
  327. uint32_t FIO_ReadValue(uint8_t portNum)
  328. {
  329. return (GPIO_ReadValue(portNum));
  330. }
  331. /**
  332. * @brief The same with GPIO_IntCmd()
  333. */
  334. void FIO_IntCmd(uint8_t portNum, uint32_t bitValue, uint8_t edgeState)
  335. {
  336. GPIO_IntCmd(portNum, bitValue, edgeState);
  337. }
  338. /**
  339. * @brief The same with GPIO_GetIntStatus()
  340. */
  341. FunctionalState FIO_GetIntStatus(uint8_t portNum, uint32_t pinNum, uint8_t edgeState)
  342. {
  343. return (GPIO_GetIntStatus(portNum, pinNum, edgeState));
  344. }
  345. /**
  346. * @brief The same with GPIO_ClearInt()
  347. */
  348. void FIO_ClearInt(uint8_t portNum, uint32_t bitValue)
  349. {
  350. GPIO_ClearInt(portNum, bitValue);
  351. }
  352. /*********************************************************************//**
  353. * @brief Set mask value for bits in FIO port
  354. * @param[in] portNum Port number, in range from 0 to 4
  355. * @param[in] bitValue Value that contains all bits in to set,
  356. * in range from 0 to 0xFFFFFFFF.
  357. * @param[in] maskValue Mask value contains state value for each bit:
  358. * - 0: not mask.
  359. * - 1: mask.
  360. * @return None
  361. *
  362. * Note:
  363. * - All remaining bits that are not activated in bitValue (value '0')
  364. * will not be effected by this function.
  365. * - After executing this function, in mask register, value '0' on each bit
  366. * enables an access to the corresponding physical pin via a read or write access,
  367. * while value '1' on bit (masked) that corresponding pin will not be changed
  368. * with write access and if read, will not be reflected in the updated pin.
  369. **********************************************************************/
  370. void FIO_SetMask(uint8_t portNum, uint32_t bitValue, uint8_t maskValue)
  371. {
  372. LPC_GPIO_TypeDef *pFIO = GPIO_GetPointer(portNum);
  373. if(pFIO != NULL) {
  374. // Mask
  375. if (maskValue){
  376. pFIO->FIOMASK |= bitValue;
  377. }
  378. // Un-mask
  379. else {
  380. pFIO->FIOMASK &= ~bitValue;
  381. }
  382. }
  383. }
  384. /* FIO halfword accessible ------------------------------------------------------------- */
  385. /*********************************************************************//**
  386. * @brief Set direction for FIO port in halfword accessible style
  387. * @param[in] portNum Port number, in range from 0 to 4
  388. * @param[in] halfwordNum HalfWord part number, should be 0 (lower) or 1(upper)
  389. * @param[in] bitValue Value that contains all bits in to set direction,
  390. * in range from 0 to 0xFFFF.
  391. * @param[in] dir Direction value, should be:
  392. * - 0: Input.
  393. * - 1: Output.
  394. * @return None
  395. *
  396. * Note: All remaining bits that are not activated in bitValue (value '0')
  397. * will not be effected by this function.
  398. **********************************************************************/
  399. void FIO_HalfWordSetDir(uint8_t portNum, uint8_t halfwordNum, uint16_t bitValue, uint8_t dir)
  400. {
  401. GPIO_HalfWord_TypeDef *pFIO = FIO_HalfWordGetPointer(portNum);
  402. if(pFIO != NULL) {
  403. // Output direction
  404. if (dir) {
  405. // Upper
  406. if(halfwordNum) {
  407. pFIO->FIODIRU |= bitValue;
  408. }
  409. // lower
  410. else {
  411. pFIO->FIODIRL |= bitValue;
  412. }
  413. }
  414. // Input direction
  415. else {
  416. // Upper
  417. if(halfwordNum) {
  418. pFIO->FIODIRU &= ~bitValue;
  419. }
  420. // lower
  421. else {
  422. pFIO->FIODIRL &= ~bitValue;
  423. }
  424. }
  425. }
  426. }
  427. /*********************************************************************//**
  428. * @brief Set mask value for bits in FIO port in halfword accessible style
  429. * @param[in] portNum Port number, in range from 0 to 4
  430. * @param[in] halfwordNum HalfWord part number, should be 0 (lower) or 1(upper)
  431. * @param[in] bitValue Value that contains all bits in to set,
  432. * in range from 0 to 0xFFFF.
  433. * @param[in] maskValue Mask value contains state value for each bit:
  434. * - 0: not mask.
  435. * - 1: mask.
  436. * @return None
  437. *
  438. * Note:
  439. * - All remaining bits that are not activated in bitValue (value '0')
  440. * will not be effected by this function.
  441. * - After executing this function, in mask register, value '0' on each bit
  442. * enables an access to the corresponding physical pin via a read or write access,
  443. * while value '1' on bit (masked) that corresponding pin will not be changed
  444. * with write access and if read, will not be reflected in the updated pin.
  445. **********************************************************************/
  446. void FIO_HalfWordSetMask(uint8_t portNum, uint8_t halfwordNum, uint16_t bitValue, uint8_t maskValue)
  447. {
  448. GPIO_HalfWord_TypeDef *pFIO = FIO_HalfWordGetPointer(portNum);
  449. if(pFIO != NULL) {
  450. // Mask
  451. if (maskValue){
  452. // Upper
  453. if(halfwordNum) {
  454. pFIO->FIOMASKU |= bitValue;
  455. }
  456. // lower
  457. else {
  458. pFIO->FIOMASKL |= bitValue;
  459. }
  460. }
  461. // Un-mask
  462. else {
  463. // Upper
  464. if(halfwordNum) {
  465. pFIO->FIOMASKU &= ~bitValue;
  466. }
  467. // lower
  468. else {
  469. pFIO->FIOMASKL &= ~bitValue;
  470. }
  471. }
  472. }
  473. }
  474. /*********************************************************************//**
  475. * @brief Set bits for FIO port in halfword accessible style
  476. * @param[in] portNum Port number, in range from 0 to 4
  477. * @param[in] halfwordNum HalfWord part number, should be 0 (lower) or 1(upper)
  478. * @param[in] bitValue Value that contains all bits in to set,
  479. * in range from 0 to 0xFFFF.
  480. * @return None
  481. *
  482. * Note:
  483. * - For all bits that has been set as input direction, this function will
  484. * not effect.
  485. * - For all remaining bits that are not activated in bitValue (value '0')
  486. * will not be effected by this function.
  487. **********************************************************************/
  488. void FIO_HalfWordSetValue(uint8_t portNum, uint8_t halfwordNum, uint16_t bitValue)
  489. {
  490. GPIO_HalfWord_TypeDef *pFIO = FIO_HalfWordGetPointer(portNum);
  491. if(pFIO != NULL) {
  492. // Upper
  493. if(halfwordNum) {
  494. pFIO->FIOSETU = bitValue;
  495. }
  496. // lower
  497. else {
  498. pFIO->FIOSETL = bitValue;
  499. }
  500. }
  501. }
  502. /*********************************************************************//**
  503. * @brief Clear bits for FIO port in halfword accessible style
  504. * @param[in] portNum Port number, in range from 0 to 4
  505. * @param[in] halfwordNum HalfWord part number, should be 0 (lower) or 1(upper)
  506. * @param[in] bitValue Value that contains all bits in to clear,
  507. * in range from 0 to 0xFFFF.
  508. * @return None
  509. *
  510. * Note:
  511. * - For all bits that has been set as input direction, this function will
  512. * not effect.
  513. * - For all remaining bits that are not activated in bitValue (value '0')
  514. * will not be effected by this function.
  515. **********************************************************************/
  516. void FIO_HalfWordClearValue(uint8_t portNum, uint8_t halfwordNum, uint16_t bitValue)
  517. {
  518. GPIO_HalfWord_TypeDef *pFIO = FIO_HalfWordGetPointer(portNum);
  519. if(pFIO != NULL) {
  520. // Upper
  521. if(halfwordNum) {
  522. pFIO->FIOCLRU = bitValue;
  523. }
  524. // lower
  525. else {
  526. pFIO->FIOCLRL = bitValue;
  527. }
  528. }
  529. }
  530. /*********************************************************************//**
  531. * @brief Read Current state on port pin that have input direction of GPIO
  532. * in halfword accessible style.
  533. * @param[in] portNum Port number, in range from 0 to 4
  534. * @param[in] halfwordNum HalfWord part number, should be 0 (lower) or 1(upper)
  535. * @return Current value of FIO port pin of specified halfword.
  536. * Note: Return value contain state of each port pin (bit) on that FIO regardless
  537. * its direction is input or output.
  538. **********************************************************************/
  539. uint16_t FIO_HalfWordReadValue(uint8_t portNum, uint8_t halfwordNum)
  540. {
  541. GPIO_HalfWord_TypeDef *pFIO = FIO_HalfWordGetPointer(portNum);
  542. if(pFIO != NULL) {
  543. // Upper
  544. if(halfwordNum) {
  545. return (pFIO->FIOPINU);
  546. }
  547. // lower
  548. else {
  549. return (pFIO->FIOPINL);
  550. }
  551. }
  552. return (0);
  553. }
  554. /* FIO Byte accessible ------------------------------------------------------------ */
  555. /*********************************************************************//**
  556. * @brief Set direction for FIO port in byte accessible style
  557. * @param[in] portNum Port number, in range from 0 to 4
  558. * @param[in] byteNum Byte part number, should be in range from 0 to 3
  559. * @param[in] bitValue Value that contains all bits in to set direction,
  560. * in range from 0 to 0xFF.
  561. * @param[in] dir Direction value, should be:
  562. * - 0: Input.
  563. * - 1: Output.
  564. * @return None
  565. *
  566. * Note: All remaining bits that are not activated in bitValue (value '0')
  567. * will not be effected by this function.
  568. **********************************************************************/
  569. void FIO_ByteSetDir(uint8_t portNum, uint8_t byteNum, uint8_t bitValue, uint8_t dir)
  570. {
  571. GPIO_Byte_TypeDef *pFIO = FIO_ByteGetPointer(portNum);
  572. if(pFIO != NULL) {
  573. // Output direction
  574. if (dir) {
  575. if (byteNum <= 3) {
  576. pFIO->FIODIR[byteNum] |= bitValue;
  577. }
  578. }
  579. // Input direction
  580. else {
  581. if (byteNum <= 3) {
  582. pFIO->FIODIR[byteNum] &= ~bitValue;
  583. }
  584. }
  585. }
  586. }
  587. /*********************************************************************//**
  588. * @brief Set mask value for bits in FIO port in byte accessible style
  589. * @param[in] portNum Port number, in range from 0 to 4
  590. * @param[in] byteNum Byte part number, should be in range from 0 to 3
  591. * @param[in] bitValue Value that contains all bits in to set mask,
  592. * in range from 0 to 0xFF.
  593. * @param[in] maskValue Mask value contains state value for each bit:
  594. * - 0: not mask.
  595. * - 1: mask.
  596. * @return None
  597. *
  598. * Note:
  599. * - All remaining bits that are not activated in bitValue (value '0')
  600. * will not be effected by this function.
  601. * - After executing this function, in mask register, value '0' on each bit
  602. * enables an access to the corresponding physical pin via a read or write access,
  603. * while value '1' on bit (masked) that corresponding pin will not be changed
  604. * with write access and if read, will not be reflected in the updated pin.
  605. **********************************************************************/
  606. void FIO_ByteSetMask(uint8_t portNum, uint8_t byteNum, uint8_t bitValue, uint8_t maskValue)
  607. {
  608. GPIO_Byte_TypeDef *pFIO = FIO_ByteGetPointer(portNum);
  609. if(pFIO != NULL) {
  610. // Mask
  611. if (maskValue) {
  612. if (byteNum <= 3) {
  613. pFIO->FIOMASK[byteNum] |= bitValue;
  614. }
  615. }
  616. // Un-mask
  617. else {
  618. if (byteNum <= 3) {
  619. pFIO->FIOMASK[byteNum] &= ~bitValue;
  620. }
  621. }
  622. }
  623. }
  624. /*********************************************************************//**
  625. * @brief Set bits for FIO port in byte accessible style
  626. * @param[in] portNum Port number, in range from 0 to 4
  627. * @param[in] byteNum Byte part number, should be in range from 0 to 3
  628. * @param[in] bitValue Value that contains all bits in to set,
  629. * in range from 0 to 0xFF.
  630. * @return None
  631. *
  632. * Note:
  633. * - For all bits that has been set as input direction, this function will
  634. * not effect.
  635. * - For all remaining bits that are not activated in bitValue (value '0')
  636. * will not be effected by this function.
  637. **********************************************************************/
  638. void FIO_ByteSetValue(uint8_t portNum, uint8_t byteNum, uint8_t bitValue)
  639. {
  640. GPIO_Byte_TypeDef *pFIO = FIO_ByteGetPointer(portNum);
  641. if (pFIO != NULL) {
  642. if (byteNum <= 3){
  643. pFIO->FIOSET[byteNum] = bitValue;
  644. }
  645. }
  646. }
  647. /*********************************************************************//**
  648. * @brief Clear bits for FIO port in byte accessible style
  649. * @param[in] portNum Port number, in range from 0 to 4
  650. * @param[in] byteNum Byte part number, should be in range from 0 to 3
  651. * @param[in] bitValue Value that contains all bits in to clear,
  652. * in range from 0 to 0xFF.
  653. * @return None
  654. *
  655. * Note:
  656. * - For all bits that has been set as input direction, this function will
  657. * not effect.
  658. * - For all remaining bits that are not activated in bitValue (value '0')
  659. * will not be effected by this function.
  660. **********************************************************************/
  661. void FIO_ByteClearValue(uint8_t portNum, uint8_t byteNum, uint8_t bitValue)
  662. {
  663. GPIO_Byte_TypeDef *pFIO = FIO_ByteGetPointer(portNum);
  664. if (pFIO != NULL) {
  665. if (byteNum <= 3){
  666. pFIO->FIOCLR[byteNum] = bitValue;
  667. }
  668. }
  669. }
  670. /*********************************************************************//**
  671. * @brief Read Current state on port pin that have input direction of GPIO
  672. * in byte accessible style.
  673. * @param[in] portNum Port number, in range from 0 to 4
  674. * @param[in] byteNum Byte part number, should be in range from 0 to 3
  675. * @return Current value of FIO port pin of specified byte part.
  676. * Note: Return value contain state of each port pin (bit) on that FIO regardless
  677. * its direction is input or output.
  678. **********************************************************************/
  679. uint8_t FIO_ByteReadValue(uint8_t portNum, uint8_t byteNum)
  680. {
  681. GPIO_Byte_TypeDef *pFIO = FIO_ByteGetPointer(portNum);
  682. if (pFIO != NULL) {
  683. if (byteNum <= 3){
  684. return (pFIO->FIOPIN[byteNum]);
  685. }
  686. }
  687. return (0);
  688. }
  689. /**
  690. * @}
  691. */
  692. #endif /* _GPIO */
  693. /**
  694. * @}
  695. */
  696. /* --------------------------------- End Of File ------------------------------ */