HAL_GPIO.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /*
  2. ******************************************************************************
  3. * @file HAL_GPIO.c
  4. * @version V1.0.0
  5. * @date 2020
  6. * @brief GPIO HAL module driver.
  7. * This file provides firmware functions to manage the following
  8. * functionalities of the General Purpose Input/Output (GPIO) peripheral:
  9. * @ Initialization functions
  10. * @ IO operation functions
  11. ******************************************************************************
  12. */
  13. #include "ACM32Fxx_HAL.h"
  14. /*********************************************************************************
  15. * Function : HAL_GPIO_IRQHandler
  16. * Description : GPIO interrupt Handler
  17. * Input :
  18. * Outpu :
  19. * Author : Chris_Kyle Data : 2020?¨º
  20. **********************************************************************************/
  21. void HAL_GPIO_IRQHandler(enum_GPIOx_t fe_GPIO, uint32_t fu32_GPIO_Pin)
  22. {
  23. GPIO_TypeDef *GPIOx;
  24. switch (fe_GPIO)
  25. {
  26. case GPIOA:
  27. case GPIOB:
  28. {
  29. GPIOx = GPIOAB;
  30. }break;
  31. case GPIOC:
  32. case GPIOD:
  33. {
  34. GPIOx = GPIOCD;
  35. }break;
  36. case GPIOE:
  37. case GPIOF:
  38. {
  39. GPIOx = GPIOEF;
  40. }break;
  41. default: break;
  42. }
  43. if (fe_GPIO == GPIOB || fe_GPIO == GPIOD || fe_GPIO == GPIOF)
  44. {
  45. fu32_GPIO_Pin <<= 16;
  46. }
  47. if (GPIOx->RIS & fu32_GPIO_Pin)
  48. {
  49. GPIOx->IC = fu32_GPIO_Pin;
  50. /* user can call your application process function here */
  51. /* ...... */
  52. }
  53. }
  54. /*********************************************************************************
  55. * Function : HAL_GPIO_Init
  56. * Description : Initializes the GPIOx peripheral according to the specified parameters in the GPIO_Init
  57. * Input : fe_GPIO: to select the GPIO peripheral.
  58. * Input : GPIO_Init: pointer to a GPIO_InitTypeDef structure that contains
  59. the configuration information for the specified GPIO peripheral.
  60. * Outpu :
  61. * Author : Chris_Kyle Data : 2020?¨º
  62. **********************************************************************************/
  63. void HAL_GPIO_Init(enum_GPIOx_t fe_GPIO, GPIO_InitTypeDef *GPIO_Init)
  64. {
  65. uint32_t lu32_Position = 0;
  66. uint32_t lu32_Current_Pin;
  67. uint32_t lu32_Position_Mask;
  68. volatile uint32_t *lu32_SEL1 = NULL; // ???¨° -> 1¨¹???¡ä¨®???¡ä??¡Â1
  69. volatile uint32_t *lu32_SEL2 = NULL; // ???¨° -> 1¨¹???¡ä¨®???¡ä??¡Â2
  70. volatile uint32_t *lu32_PollUP = NULL; // ???¨° -> ¨¦?¨¤-??????¡ä??¡Â
  71. volatile uint32_t *lu32_PollDown = NULL; // ???¨° -> ??¨¤-??????¡ä??¡Â
  72. volatile uint32_t *lu32_ODEnable = NULL; // ???¨° -> ?a??¨º1?¨¹??¡ä??¡Â
  73. volatile uint32_t *lu32_ADS = NULL; // ???¨° -> ¨ºy¡Á??¡é?¡ê?a??????¡ä??¡Â
  74. GPIO_TypeDef *GPIOx;
  75. #if (USE_FULL_ASSERT == 1)
  76. /* Check the parameters */
  77. if (!IS_GPIO_ALL_INSTANCE(fe_GPIO)) return;
  78. if (!IS_GPIO_PIN(GPIO_Init->Pin)) return;
  79. if (!IS_GPIO_MODE(GPIO_Init->Mode)) return;
  80. #endif
  81. switch (fe_GPIO)
  82. {
  83. case GPIOA:
  84. case GPIOB:
  85. {
  86. GPIOx = GPIOAB;
  87. System_Module_Enable(EN_GPIOAB);
  88. lu32_PollUP = &(SCU->PABPUR);
  89. lu32_PollDown = &(SCU->PABPDR);
  90. lu32_ODEnable = &(SCU->PABODR);
  91. lu32_ADS = &(SCU->PABADS);
  92. if (fe_GPIO == GPIOB)
  93. {
  94. GPIO_Init->Pin <<= 16;
  95. lu32_SEL1 = &(SCU->PBSEL1);
  96. lu32_SEL2 = &(SCU->PBSEL2);
  97. }
  98. else
  99. {
  100. lu32_SEL1 = &(SCU->PASEL1);
  101. lu32_SEL2 = &(SCU->PASEL2);
  102. }
  103. }break;
  104. case GPIOC:
  105. case GPIOD:
  106. {
  107. GPIOx = GPIOCD;
  108. System_Module_Enable(EN_GPIOCD);
  109. lu32_PollUP = &(SCU->PCDPUR);
  110. lu32_PollDown = &(SCU->PCDPDR);
  111. lu32_ODEnable = &(SCU->PCDODR);
  112. lu32_ADS = &(SCU->PCDADS);
  113. if (fe_GPIO == GPIOD)
  114. {
  115. GPIO_Init->Pin <<= 16;
  116. lu32_SEL1 = &(SCU->PDSEL1);
  117. lu32_SEL2 = &(SCU->PDSEL2);
  118. }
  119. else
  120. {
  121. lu32_SEL1 = &(SCU->PCSEL1);
  122. lu32_SEL2 = &(SCU->PCSEL2);
  123. }
  124. }break;
  125. case GPIOE:
  126. case GPIOF:
  127. {
  128. GPIOx = GPIOEF;
  129. System_Module_Enable(EN_GPIOEF);
  130. lu32_PollUP = &(SCU->PEFPUR);
  131. lu32_PollDown = &(SCU->PEFPDR);
  132. lu32_ODEnable = &(SCU->PEFODR);
  133. lu32_ADS = &(SCU->PEFADS);
  134. if (fe_GPIO == GPIOF)
  135. {
  136. GPIO_Init->Pin <<= 16;
  137. lu32_SEL1 = &(SCU->PFSEL1);
  138. }
  139. else
  140. {
  141. lu32_SEL1 = &(SCU->PESEL1);
  142. lu32_SEL2 = &(SCU->PESEL2);
  143. }
  144. }break;
  145. default: break;
  146. }
  147. /* Configure Select pins */
  148. while ((GPIO_Init->Pin) >> lu32_Position != 0)
  149. {
  150. /* Get current pin position */
  151. lu32_Current_Pin = (GPIO_Init->Pin) & (1uL << lu32_Position);
  152. if (lu32_Current_Pin)
  153. {
  154. switch (GPIO_Init->Mode)
  155. {
  156. /* GPIO IN Function */
  157. case GPIO_MODE_INPUT:
  158. {
  159. GPIOx->DIR &= ~lu32_Current_Pin;
  160. }break;
  161. /* GPIO OUT Function */
  162. case GPIO_MODE_OUTPUT_PP:
  163. case GPIO_MODE_OUTPUT_OD:
  164. {
  165. GPIOx->DIR |= lu32_Current_Pin;
  166. }break;
  167. /* Alternate Function */
  168. case GPIO_MODE_AF_PP:
  169. case GPIO_MODE_AF_OD:
  170. {
  171. /* Get Position Mask */
  172. if (lu32_Position < 16)
  173. { /* GOIOA?¡éGPIOC?¡éGPIOE */
  174. lu32_Position_Mask = lu32_Position;
  175. }
  176. else
  177. { /* GPIOB?¡éGPIOD?¡éGPIOF */
  178. lu32_Position_Mask = lu32_Position - 16;
  179. }
  180. /* SET GPIO Function */
  181. if (lu32_Position_Mask < 8)
  182. {
  183. *lu32_SEL1 = (*lu32_SEL1 & ~(0xF << (lu32_Position_Mask * 4))) | (GPIO_Init->Alternate << (lu32_Position_Mask * 4));
  184. }
  185. else
  186. {
  187. *lu32_SEL2 = (*lu32_SEL2 & ~(0xF << ((lu32_Position_Mask - 8) * 4))) | (GPIO_Init->Alternate << ((lu32_Position_Mask - 8) * 4));
  188. }
  189. }break;
  190. /* GPIO INT Function */
  191. case GPIO_MODE_IT_RISING:
  192. case GPIO_MODE_IT_FALLING:
  193. case GPIO_MODE_IT_RISING_FALLING:
  194. case GPIO_MODE_IT_HIGH_LEVEL:
  195. case GPIO_MODE_IT_LOW_LEVEL:
  196. {
  197. /* Set direction Input?¡éEnable INT */
  198. GPIOx->DIR &= ~lu32_Current_Pin;
  199. GPIOx->IEN |= lu32_Current_Pin;
  200. /* Single edge */
  201. if (GPIO_Init->Mode == GPIO_MODE_IT_RISING || GPIO_Init->Mode == GPIO_MODE_IT_FALLING)
  202. {
  203. /* edge trigger */
  204. GPIOx->IS &= ~lu32_Current_Pin;
  205. /* Single trigger */
  206. GPIOx->IBE &= ~lu32_Current_Pin;
  207. if (GPIO_Init->Mode == GPIO_MODE_IT_RISING)
  208. {
  209. GPIOx->IEV |= lu32_Current_Pin;
  210. }
  211. else
  212. {
  213. GPIOx->IEV &= ~lu32_Current_Pin;
  214. }
  215. }
  216. /* Double edge */
  217. if (GPIO_Init->Mode == GPIO_MODE_IT_RISING_FALLING)
  218. {
  219. /* edge trigger */
  220. GPIOx->IS &= ~lu32_Current_Pin;
  221. /* Double trigger */
  222. GPIOx->IBE |= lu32_Current_Pin;
  223. }
  224. /* LEVEL trigger */
  225. if (GPIO_Init->Mode == GPIO_MODE_IT_HIGH_LEVEL || GPIO_Init->Mode == GPIO_MODE_IT_LOW_LEVEL)
  226. {
  227. /* LEVEL trigger */
  228. GPIOx->IS |= lu32_Current_Pin;
  229. if (GPIO_Init->Mode == GPIO_MODE_IT_HIGH_LEVEL)
  230. {
  231. GPIOx->IEV |= lu32_Current_Pin;
  232. }
  233. else
  234. {
  235. GPIOx->IEV &= ~lu32_Current_Pin;
  236. }
  237. }
  238. }break;
  239. default: break;
  240. }
  241. /* Set Pull UP or DOWN or NO */
  242. if (GPIO_Init->Pull == GPIO_NOPULL)
  243. {
  244. *lu32_PollUP &= ~lu32_Current_Pin;
  245. *lu32_PollDown &= ~lu32_Current_Pin;
  246. }
  247. else if (GPIO_Init->Pull == GPIO_PULLUP)
  248. {
  249. *lu32_PollUP |= lu32_Current_Pin;
  250. *lu32_PollDown &= ~lu32_Current_Pin;
  251. }
  252. else if (GPIO_Init->Pull == GPIO_PULLDOWN)
  253. {
  254. *lu32_PollUP &= ~lu32_Current_Pin;
  255. *lu32_PollDown |= lu32_Current_Pin;
  256. }
  257. /* Set Open Drain Mode */
  258. if (GPIO_Init->Mode & GPIO_MODE_OD_MASK)
  259. {
  260. *lu32_ODEnable |= lu32_Current_Pin;
  261. }
  262. else
  263. {
  264. *lu32_ODEnable &= ~lu32_Current_Pin;
  265. }
  266. /* GPIO Function */
  267. if (GPIO_Init->Mode & GPIO_MODE_IO_MASK)
  268. {
  269. /* Get Position Mask */
  270. if (lu32_Position < 16)
  271. { /* GOIOA?¡éGPIOC?¡éGPIOE */
  272. lu32_Position_Mask = lu32_Position;
  273. }
  274. else
  275. { /* GPIOB?¡éGPIOD?¡éGPIOF */
  276. lu32_Position_Mask = lu32_Position - 16;
  277. }
  278. /* SET GPIO Function */
  279. if (lu32_Position_Mask < 8)
  280. {
  281. *lu32_SEL1 = (*lu32_SEL1 & ~(0xF << (lu32_Position_Mask * 4))) | (GPIO_FUNCTION_0 << (lu32_Position_Mask * 4));
  282. }
  283. else
  284. {
  285. *lu32_SEL2 = (*lu32_SEL2 & ~(0xF << ((lu32_Position_Mask - 8) * 4))) | (GPIO_FUNCTION_0 << ((lu32_Position_Mask - 8) * 4));
  286. }
  287. }
  288. /* SET Digital or Analog */
  289. if (GPIO_Init->Mode == GPIO_MODE_ANALOG)
  290. {
  291. *lu32_ADS |= lu32_Current_Pin;
  292. }
  293. else
  294. {
  295. *lu32_ADS &= ~lu32_Current_Pin;
  296. }
  297. }
  298. lu32_Position++;
  299. }
  300. }
  301. /*********************************************************************************
  302. * Function : HAL_GPIO_DeInit
  303. * Description : De-initializes the GPIOx peripheral registers to their default reset values.
  304. * Input : fe_GPIO¡êoto select the GPIO peripheral.
  305. * Input : fu32_Pin¡êospecifies the port bit to be written.
  306. This parameter can be one of GPIO_PIN_x where x can be (0..15).
  307. * Outpu :
  308. * Author : Chris_Kyle Data : 2020
  309. **********************************************************************************/
  310. void HAL_GPIO_DeInit(enum_GPIOx_t fe_GPIO, uint32_t fu32_Pin)
  311. {
  312. uint32_t lu32_Position = 0;
  313. uint32_t lu32_Current_Pin;
  314. uint32_t lu32_Position_Mask;
  315. volatile uint32_t *lu32_SEL1 = NULL; // ???¨° -> 1¨¹???¡ä¨®???¡ä??¡Â1
  316. volatile uint32_t *lu32_SEL2 = NULL; // ???¨° -> 1¨¹???¡ä¨®???¡ä??¡Â2
  317. volatile uint32_t *lu32_PollUP = NULL; // ???¨° -> ¨¦?¨¤-??????¡ä??¡Â
  318. volatile uint32_t *lu32_PollDown = NULL; // ???¨° -> ??¨¤-??????¡ä??¡Â
  319. volatile uint32_t *lu32_ODEnable = NULL; // ???¨° -> ?a??¨º1?¨¹??¡ä??¡Â
  320. volatile uint32_t *lu32_ADS = NULL; // ???¨° -> ¨ºy¡Á??¡é?¡ê?a??????¡ä??¡Â
  321. GPIO_TypeDef *GPIOx;
  322. #if (USE_FULL_ASSERT == 1)
  323. /* Check the parameters */
  324. if (!IS_GPIO_ALL_INSTANCE(fe_GPIO)) return;
  325. if (!IS_GPIO_PIN(fu32_Pin)) return;
  326. #endif
  327. switch (fe_GPIO)
  328. {
  329. case GPIOA:
  330. case GPIOB:
  331. {
  332. GPIOx = GPIOAB;
  333. System_Module_Enable(EN_GPIOAB);
  334. lu32_PollUP = &(SCU->PABPUR);
  335. lu32_PollDown = &(SCU->PABPDR);
  336. lu32_ODEnable = &(SCU->PABODR);
  337. lu32_ADS = &(SCU->PABADS);
  338. if (fe_GPIO == GPIOB)
  339. {
  340. fu32_Pin <<= 16;
  341. lu32_SEL1 = &(SCU->PBSEL1);
  342. lu32_SEL2 = &(SCU->PBSEL2);
  343. }
  344. else
  345. {
  346. lu32_SEL1 = &(SCU->PASEL1);
  347. lu32_SEL2 = &(SCU->PASEL2);
  348. }
  349. }break;
  350. case GPIOC:
  351. case GPIOD:
  352. {
  353. GPIOx = GPIOCD;
  354. System_Module_Enable(EN_GPIOCD);
  355. lu32_PollUP = &(SCU->PCDPUR);
  356. lu32_PollDown = &(SCU->PCDPDR);
  357. lu32_ODEnable = &(SCU->PCDODR);
  358. lu32_ADS = &(SCU->PCDADS);
  359. if (fe_GPIO == GPIOD)
  360. {
  361. fu32_Pin <<= 16;
  362. lu32_SEL1 = &(SCU->PDSEL1);
  363. lu32_SEL2 = &(SCU->PDSEL2);
  364. }
  365. else
  366. {
  367. lu32_SEL1 = &(SCU->PCSEL1);
  368. lu32_SEL2 = &(SCU->PCSEL2);
  369. }
  370. }break;
  371. case GPIOE:
  372. case GPIOF:
  373. {
  374. GPIOx = GPIOEF;
  375. System_Module_Enable(EN_GPIOEF);
  376. lu32_PollUP = &(SCU->PEFPUR);
  377. lu32_PollDown = &(SCU->PEFPDR);
  378. lu32_ODEnable = &(SCU->PEFODR);
  379. lu32_ADS = &(SCU->PEFADS);
  380. if (fe_GPIO == GPIOF)
  381. {
  382. fu32_Pin <<= 16;
  383. lu32_SEL1 = &(SCU->PFSEL1);
  384. }
  385. else
  386. {
  387. lu32_SEL1 = &(SCU->PESEL1);
  388. lu32_SEL2 = &(SCU->PESEL2);
  389. }
  390. }break;
  391. default: break;
  392. }
  393. /* Configure Select pins */
  394. while (fu32_Pin >> lu32_Position != 0)
  395. {
  396. /* Get current pin position */
  397. lu32_Current_Pin = fu32_Pin & (1uL << lu32_Position);
  398. if (lu32_Current_Pin)
  399. {
  400. /* GPIO IN Function */
  401. GPIOx->DIR &= ~lu32_Current_Pin;
  402. GPIOx->CLR |= lu32_Current_Pin;
  403. /* Disable Enable INT */
  404. GPIOx->IEN &= ~lu32_Current_Pin;
  405. /* Clear trigger config */
  406. GPIOx->IS &= ~lu32_Current_Pin;
  407. GPIOx->IBE &= ~lu32_Current_Pin;
  408. GPIOx->IEV &= ~lu32_Current_Pin;
  409. /* Get Position Mask */
  410. if (lu32_Position < 16)
  411. { /* GOIOA?¡éGPIOC?¡éGPIOE */
  412. lu32_Position_Mask = lu32_Position;
  413. }
  414. else
  415. { /* GPIOB?¡éGPIOD?¡éGPIOF */
  416. lu32_Position_Mask = lu32_Position - 16;
  417. }
  418. /* SET GPIO Function */
  419. if (lu32_Position_Mask < 8)
  420. {
  421. *lu32_SEL1 &= ~(0xF << (lu32_Position_Mask * 4));
  422. }
  423. else
  424. {
  425. *lu32_SEL2 &= ~(0xF << ((lu32_Position_Mask - 8) * 4));
  426. }
  427. /* NO Pull */
  428. *lu32_PollUP &= ~lu32_Current_Pin;
  429. *lu32_PollDown &= ~lu32_Current_Pin;
  430. /* Not Open Drain */
  431. *lu32_ODEnable &= ~lu32_Current_Pin;
  432. /* Analog Mode */
  433. *lu32_ADS |= lu32_Current_Pin;
  434. }
  435. lu32_Position++;
  436. }
  437. }
  438. /*********************************************************************************
  439. * Function : HAL_GPIO_AnalogEnable
  440. * Description : Quickly Configure to analog function
  441. * Input : fe_GPIO¡êoto select the GPIO peripheral.
  442. * Input : fu32_Pin¡êospecifies the port bit to be written.
  443. This parameter can be one of GPIO_PIN_x where x can be (0..15).
  444. * Outpu :
  445. * Author : Chris_Kyle Data : 2020?¨º
  446. **********************************************************************************/
  447. void HAL_GPIO_AnalogEnable(enum_GPIOx_t fe_GPIO, uint32_t fu32_Pin)
  448. {
  449. uint32_t lu32_Position = 0;
  450. uint32_t lu32_Current_Pin;
  451. volatile uint32_t *lp32_ADS = NULL; // ???¨° -> ¨ºy¡Á??¡é?¡ê?a??????¡ä??¡Â
  452. GPIO_TypeDef *GPIOx;
  453. #if (USE_FULL_ASSERT == 1)
  454. /* Check the parameters */
  455. if (!IS_GPIO_ALL_INSTANCE(fe_GPIO)) return;
  456. if (!IS_GPIO_PIN(fu32_Pin)) return;
  457. #endif
  458. switch (fe_GPIO)
  459. {
  460. case GPIOA:
  461. case GPIOB:
  462. {
  463. System_Module_Enable(EN_GPIOAB);
  464. lp32_ADS = &(SCU->PABADS);
  465. if (fe_GPIO == GPIOB)
  466. {
  467. fu32_Pin <<= 16;
  468. }
  469. }break;
  470. case GPIOC:
  471. case GPIOD:
  472. {
  473. System_Module_Enable(EN_GPIOCD);
  474. lp32_ADS = &(SCU->PCDADS);
  475. if (fe_GPIO == GPIOD)
  476. {
  477. fu32_Pin <<= 16;
  478. }
  479. }break;
  480. case GPIOE:
  481. case GPIOF:
  482. {
  483. System_Module_Enable(EN_GPIOEF);
  484. lp32_ADS = &(SCU->PEFADS);
  485. if (fe_GPIO == GPIOF)
  486. {
  487. fu32_Pin <<= 16;
  488. }
  489. }break;
  490. default: break;
  491. }
  492. /* Configure Select pins */
  493. while ((fu32_Pin) >> lu32_Position != 0)
  494. {
  495. /* Get current pin position */
  496. lu32_Current_Pin = (fu32_Pin) & (1uL << lu32_Position);
  497. if (lu32_Current_Pin)
  498. {
  499. *lp32_ADS |= lu32_Current_Pin;
  500. }
  501. lu32_Position++;
  502. }
  503. }
  504. /*********************************************************************************
  505. * Function : HAL_GPIO_WritePin
  506. * Description : Set or clear the selected data port bit.
  507. * Input :
  508. * Outpu :
  509. * Author : Chris_Kyle Data : 2020?¨º
  510. **********************************************************************************/
  511. void HAL_GPIO_WritePin(enum_GPIOx_t fe_GPIO, uint32_t fu32_GPIO_Pin, enum_PinState_t fe_PinState)
  512. {
  513. GPIO_TypeDef *GPIOx;
  514. #if (USE_FULL_ASSERT == 1)
  515. /* Check the parameters */
  516. if (!IS_GPIO_ALL_INSTANCE(fe_GPIO)) return;
  517. if (!IS_GPIO_PIN(fu32_GPIO_Pin)) return;
  518. if (!IS_GPIO_PIN_ACTION(fe_PinState)) return;
  519. #endif
  520. switch (fe_GPIO)
  521. {
  522. case GPIOA:
  523. case GPIOB:
  524. {
  525. GPIOx = GPIOAB;
  526. }break;
  527. case GPIOC:
  528. case GPIOD:
  529. {
  530. GPIOx = GPIOCD;
  531. }break;
  532. case GPIOE:
  533. case GPIOF:
  534. {
  535. GPIOx = GPIOEF;
  536. }break;
  537. default: break;
  538. }
  539. if (fe_GPIO == GPIOB || fe_GPIO == GPIOD || fe_GPIO == GPIOF)
  540. {
  541. fu32_GPIO_Pin <<= 16;
  542. }
  543. if (GPIO_PIN_SET == fe_PinState)
  544. {
  545. GPIOx->ODATA |= fu32_GPIO_Pin;
  546. }
  547. else
  548. {
  549. GPIOx->ODATA &= ~fu32_GPIO_Pin;
  550. }
  551. }
  552. /*********************************************************************************
  553. * Function : HAL_GPIO_ReadPin
  554. * Description : Read the specified input port pin.
  555. * Input :
  556. * Outpu :
  557. * Author : Chris_Kyle Data : 2020?¨º
  558. **********************************************************************************/
  559. enum_PinState_t HAL_GPIO_ReadPin(enum_GPIOx_t fe_GPIO, uint32_t fu32_GPIO_Pin)
  560. {
  561. GPIO_TypeDef *GPIOx;
  562. switch (fe_GPIO)
  563. {
  564. case GPIOA:
  565. case GPIOB:
  566. {
  567. GPIOx = GPIOAB;
  568. }break;
  569. case GPIOC:
  570. case GPIOD:
  571. {
  572. GPIOx = GPIOCD;
  573. }break;
  574. case GPIOE:
  575. case GPIOF:
  576. {
  577. GPIOx = GPIOEF;
  578. }break;
  579. default: break;
  580. }
  581. if (fe_GPIO == GPIOB || fe_GPIO == GPIOD || fe_GPIO == GPIOF)
  582. {
  583. fu32_GPIO_Pin <<= 16;
  584. }
  585. if (GPIOx->IDATA & fu32_GPIO_Pin)
  586. {
  587. return GPIO_PIN_SET;
  588. }
  589. else
  590. {
  591. return GPIO_PIN_CLEAR;
  592. }
  593. }