ch32v20x_gpio.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  1. /********************************** (C) COPYRIGHT *******************************
  2. * File Name : ch32v20x_gpio.c
  3. * Author : WCH
  4. * Version : V1.0.0
  5. * Date : 2024/05/06
  6. * Description : This file provides all the GPIO firmware functions.
  7. *********************************************************************************
  8. * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
  9. * Attention: This software (modified or not) and binary are used for
  10. * microcontroller manufactured by Nanjing Qinheng Microelectronics.
  11. *******************************************************************************/
  12. #include "ch32v20x_gpio.h"
  13. #include "ch32v20x_rcc.h"
  14. /* MASK */
  15. #define ECR_PORTPINCONFIG_MASK ((uint16_t)0xFF80)
  16. #define LSB_MASK ((uint16_t)0xFFFF)
  17. #define DBGAFR_POSITION_MASK ((uint32_t)0x000F0000)
  18. #define DBGAFR_SWJCFG_MASK ((uint32_t)0xF0FFFFFF)
  19. #define DBGAFR_LOCATION_MASK ((uint32_t)0x00200000)
  20. #define DBGAFR_NUMBITS_MASK ((uint32_t)0x00100000)
  21. #if defined (CH32V20x_D6)
  22. uint8_t MCU_Version = 0;
  23. #endif
  24. /*********************************************************************
  25. * @fn GPIO_DeInit
  26. *
  27. * @brief Deinitializes the GPIOx peripheral registers to their default
  28. * reset values.
  29. *
  30. * @param GPIOx - where x can be (A..G) to select the GPIO peripheral.
  31. *
  32. * @return none
  33. */
  34. void GPIO_DeInit(GPIO_TypeDef *GPIOx)
  35. {
  36. if(GPIOx == GPIOA)
  37. {
  38. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA, ENABLE);
  39. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA, DISABLE);
  40. }
  41. else if(GPIOx == GPIOB)
  42. {
  43. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOB, ENABLE);
  44. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOB, DISABLE);
  45. }
  46. else if(GPIOx == GPIOC)
  47. {
  48. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC, ENABLE);
  49. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC, DISABLE);
  50. }
  51. else if(GPIOx == GPIOD)
  52. {
  53. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOD, ENABLE);
  54. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOD, DISABLE);
  55. }
  56. else if(GPIOx == GPIOE)
  57. {
  58. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOE, ENABLE);
  59. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOE, DISABLE);
  60. }
  61. }
  62. /*********************************************************************
  63. * @fn GPIO_AFIODeInit
  64. *
  65. * @brief Deinitializes the Alternate Functions (remap, event control
  66. * and EXTI configuration) registers to their default reset values.
  67. *
  68. * @return none
  69. */
  70. void GPIO_AFIODeInit(void)
  71. {
  72. RCC_APB2PeriphResetCmd(RCC_APB2Periph_AFIO, ENABLE);
  73. RCC_APB2PeriphResetCmd(RCC_APB2Periph_AFIO, DISABLE);
  74. }
  75. /*********************************************************************
  76. * @fn GPIO_Init
  77. *
  78. * @brief GPIOx - where x can be (A..G) to select the GPIO peripheral.
  79. *
  80. * @param GPIO_InitStruct - pointer to a GPIO_InitTypeDef structure that
  81. * contains the configuration information for the specified GPIO peripheral.
  82. *
  83. * @return none
  84. */
  85. void GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_InitStruct)
  86. {
  87. uint32_t currentmode = 0x00, currentpin = 0x00, pinpos = 0x00, pos = 0x00;
  88. uint32_t tmpreg = 0x00, pinmask = 0x00;
  89. currentmode = ((uint32_t)GPIO_InitStruct->GPIO_Mode) & ((uint32_t)0x0F);
  90. if((((uint32_t)GPIO_InitStruct->GPIO_Mode) & ((uint32_t)0x10)) != 0x00)
  91. {
  92. currentmode |= (uint32_t)GPIO_InitStruct->GPIO_Speed;
  93. }
  94. #if defined (CH32V20x_D6)
  95. if(((*(uint32_t *) 0x40022030) & 0x0F000000) == 0)
  96. {
  97. MCU_Version = 1;
  98. }
  99. if((GPIOx == GPIOC) && MCU_Version){
  100. GPIO_InitStruct->GPIO_Pin = GPIO_InitStruct->GPIO_Pin >> 13;
  101. }
  102. #endif
  103. if(((uint32_t)GPIO_InitStruct->GPIO_Pin & ((uint32_t)0x00FF)) != 0x00)
  104. {
  105. tmpreg = GPIOx->CFGLR;
  106. for(pinpos = 0x00; pinpos < 0x08; pinpos++)
  107. {
  108. pos = ((uint32_t)0x01) << pinpos;
  109. currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;
  110. if(currentpin == pos)
  111. {
  112. pos = pinpos << 2;
  113. pinmask = ((uint32_t)0x0F) << pos;
  114. tmpreg &= ~pinmask;
  115. tmpreg |= (currentmode << pos);
  116. if(GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD)
  117. {
  118. GPIOx->BCR = (((uint32_t)0x01) << pinpos);
  119. }
  120. else
  121. {
  122. if(GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU)
  123. {
  124. GPIOx->BSHR = (((uint32_t)0x01) << pinpos);
  125. }
  126. }
  127. }
  128. }
  129. GPIOx->CFGLR = tmpreg;
  130. }
  131. if(GPIO_InitStruct->GPIO_Pin > 0x00FF)
  132. {
  133. tmpreg = GPIOx->CFGHR;
  134. for(pinpos = 0x00; pinpos < 0x08; pinpos++)
  135. {
  136. pos = (((uint32_t)0x01) << (pinpos + 0x08));
  137. currentpin = ((GPIO_InitStruct->GPIO_Pin) & pos);
  138. if(currentpin == pos)
  139. {
  140. pos = pinpos << 2;
  141. pinmask = ((uint32_t)0x0F) << pos;
  142. tmpreg &= ~pinmask;
  143. tmpreg |= (currentmode << pos);
  144. if(GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD)
  145. {
  146. GPIOx->BCR = (((uint32_t)0x01) << (pinpos + 0x08));
  147. }
  148. if(GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU)
  149. {
  150. GPIOx->BSHR = (((uint32_t)0x01) << (pinpos + 0x08));
  151. }
  152. }
  153. }
  154. GPIOx->CFGHR = tmpreg;
  155. }
  156. }
  157. /*********************************************************************
  158. * @fn GPIO_StructInit
  159. *
  160. * @brief Fills each GPIO_InitStruct member with its default
  161. *
  162. * @param GPIO_InitStruct - pointer to a GPIO_InitTypeDef structure
  163. * which will be initialized.
  164. *
  165. * @return none
  166. */
  167. void GPIO_StructInit(GPIO_InitTypeDef *GPIO_InitStruct)
  168. {
  169. GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All;
  170. GPIO_InitStruct->GPIO_Speed = GPIO_Speed_2MHz;
  171. GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN_FLOATING;
  172. }
  173. /*********************************************************************
  174. * @fn GPIO_ReadInputDataBit
  175. *
  176. * @brief GPIOx - where x can be (A..G) to select the GPIO peripheral.
  177. *
  178. * @param GPIO_Pin - specifies the port bit to read.
  179. * This parameter can be GPIO_Pin_x where x can be (0..15).
  180. *
  181. * @return The input port pin value.
  182. */
  183. uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
  184. {
  185. uint8_t bitstatus = 0x00;
  186. #if defined (CH32V20x_D6)
  187. if((GPIOx == GPIOC) && MCU_Version){
  188. GPIO_Pin = GPIO_Pin >> 13;
  189. }
  190. #endif
  191. if((GPIOx->INDR & GPIO_Pin) != (uint32_t)Bit_RESET)
  192. {
  193. bitstatus = (uint8_t)Bit_SET;
  194. }
  195. else
  196. {
  197. bitstatus = (uint8_t)Bit_RESET;
  198. }
  199. return bitstatus;
  200. }
  201. /*********************************************************************
  202. * @fn GPIO_ReadInputData
  203. *
  204. * @brief Reads the specified GPIO input data port.
  205. *
  206. * @param GPIOx - where x can be (A..G) to select the GPIO peripheral.
  207. *
  208. * @return The output port pin value.
  209. */
  210. uint16_t GPIO_ReadInputData(GPIO_TypeDef *GPIOx)
  211. {
  212. uint16_t val;
  213. #if defined (CH32V20x_D6)
  214. if((GPIOx == GPIOC) && MCU_Version){
  215. val = ( uint16_t )(GPIOx->INDR << 13);
  216. }
  217. else{
  218. val = ( uint16_t )GPIOx->INDR;
  219. }
  220. #else
  221. val = ( uint16_t )GPIOx->INDR;
  222. #endif
  223. return ( val );
  224. }
  225. /*********************************************************************
  226. * @fn GPIO_ReadOutputDataBit
  227. *
  228. * @brief Reads the specified output data port bit.
  229. *
  230. * @param GPIOx - where x can be (A..G) to select the GPIO peripheral.
  231. * GPIO_Pin - specifies the port bit to read.
  232. * This parameter can be GPIO_Pin_x where x can be (0..15).
  233. *
  234. * @return none
  235. */
  236. uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
  237. {
  238. uint8_t bitstatus = 0x00;
  239. #if defined (CH32V20x_D6)
  240. if((GPIOx == GPIOC) && MCU_Version){
  241. GPIO_Pin = GPIO_Pin >> 13;
  242. }
  243. #endif
  244. if((GPIOx->OUTDR & GPIO_Pin) != (uint32_t)Bit_RESET)
  245. {
  246. bitstatus = (uint8_t)Bit_SET;
  247. }
  248. else
  249. {
  250. bitstatus = (uint8_t)Bit_RESET;
  251. }
  252. return bitstatus;
  253. }
  254. /*********************************************************************
  255. * @fn GPIO_ReadOutputData
  256. *
  257. * @brief Reads the specified GPIO output data port.
  258. *
  259. * @param GPIOx - where x can be (A..G) to select the GPIO peripheral.
  260. *
  261. * @return GPIO output port pin value.
  262. */
  263. uint16_t GPIO_ReadOutputData(GPIO_TypeDef *GPIOx)
  264. {
  265. uint16_t val;
  266. #if defined (CH32V20x_D6)
  267. if((GPIOx == GPIOC) && MCU_Version){
  268. val = ( uint16_t )(GPIOx->OUTDR << 13);
  269. }
  270. else{
  271. val = ( uint16_t )GPIOx->OUTDR;
  272. }
  273. #else
  274. val = ( uint16_t )GPIOx->OUTDR;
  275. #endif
  276. return ( val );
  277. }
  278. /*********************************************************************
  279. * @fn GPIO_SetBits
  280. *
  281. * @brief Sets the selected data port bits.
  282. *
  283. * @param GPIOx - where x can be (A..G) to select the GPIO peripheral.
  284. * GPIO_Pin - specifies the port bits to be written.
  285. * This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
  286. *
  287. * @return none
  288. */
  289. void GPIO_SetBits(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
  290. {
  291. #if defined (CH32V20x_D6)
  292. if((GPIOx == GPIOC) && MCU_Version){
  293. GPIO_Pin = GPIO_Pin >> 13;
  294. }
  295. #endif
  296. GPIOx->BSHR = GPIO_Pin;
  297. }
  298. /*********************************************************************
  299. * @fn GPIO_ResetBits
  300. *
  301. * @brief Clears the selected data port bits.
  302. *
  303. * @param GPIOx - where x can be (A..G) to select the GPIO peripheral.
  304. * GPIO_Pin - specifies the port bits to be written.
  305. * This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
  306. *
  307. * @return none
  308. */
  309. void GPIO_ResetBits(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
  310. {
  311. #if defined (CH32V20x_D6)
  312. if((GPIOx == GPIOC) && MCU_Version){
  313. GPIO_Pin = GPIO_Pin >> 13;
  314. }
  315. #endif
  316. GPIOx->BCR = GPIO_Pin;
  317. }
  318. /*********************************************************************
  319. * @fn GPIO_WriteBit
  320. *
  321. * @brief Sets or clears the selected data port bit.
  322. *
  323. * @param GPIO_Pin - specifies the port bit to be written.
  324. * This parameter can be one of GPIO_Pin_x where x can be (0..15).
  325. * BitVal - specifies the value to be written to the selected bit.
  326. * Bit_RESET - to clear the port pin.
  327. * Bit_SET - to set the port pin.
  328. *
  329. * @return none
  330. */
  331. void GPIO_WriteBit(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
  332. {
  333. #if defined (CH32V20x_D6)
  334. if((GPIOx == GPIOC) && MCU_Version){
  335. GPIO_Pin = GPIO_Pin >> 13;
  336. }
  337. #endif
  338. if(BitVal != Bit_RESET)
  339. {
  340. GPIOx->BSHR = GPIO_Pin;
  341. }
  342. else
  343. {
  344. GPIOx->BCR = GPIO_Pin;
  345. }
  346. }
  347. /*********************************************************************
  348. * @fn GPIO_Write
  349. *
  350. * @brief Writes data to the specified GPIO data port.
  351. *
  352. * @param GPIOx - where x can be (A..G) to select the GPIO peripheral.
  353. * PortVal - specifies the value to be written to the port output data register.
  354. *
  355. * @return none
  356. */
  357. void GPIO_Write(GPIO_TypeDef *GPIOx, uint16_t PortVal)
  358. {
  359. #if defined (CH32V20x_D6)
  360. if((GPIOx == GPIOC) && MCU_Version){
  361. PortVal = PortVal >> 13;
  362. }
  363. #endif
  364. GPIOx->OUTDR = PortVal;
  365. }
  366. /*********************************************************************
  367. * @fn GPIO_PinLockConfig
  368. *
  369. * @brief Locks GPIO Pins configuration registers.
  370. *
  371. * @param GPIOx - where x can be (A..G) to select the GPIO peripheral.
  372. * GPIO_Pin - specifies the port bit to be written.
  373. * This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
  374. *
  375. * @return none
  376. */
  377. void GPIO_PinLockConfig(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
  378. {
  379. uint32_t tmp = 0x00010000;
  380. #if defined (CH32V20x_D6)
  381. if((GPIOx == GPIOC) && MCU_Version){
  382. GPIO_Pin = GPIO_Pin >> 13;
  383. }
  384. #endif
  385. tmp |= GPIO_Pin;
  386. GPIOx->LCKR = tmp;
  387. GPIOx->LCKR = GPIO_Pin;
  388. GPIOx->LCKR = tmp;
  389. tmp = GPIOx->LCKR;
  390. tmp = GPIOx->LCKR;
  391. }
  392. /*********************************************************************
  393. * @fn GPIO_EventOutputConfig
  394. *
  395. * @brief Selects the GPIO pin used as Event output.
  396. *
  397. * @param GPIO_PortSource - selects the GPIO port to be used as source
  398. * for Event output.
  399. * This parameter can be GPIO_PortSourceGPIOx where x can be (A..E).
  400. * GPIO_PinSource - specifies the pin for the Event output.
  401. * This parameter can be GPIO_PinSourcex where x can be (0..15).
  402. *
  403. * @return none
  404. */
  405. void GPIO_EventOutputConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource)
  406. {
  407. uint32_t tmpreg = 0x00;
  408. tmpreg = AFIO->ECR;
  409. tmpreg &= ECR_PORTPINCONFIG_MASK;
  410. tmpreg |= (uint32_t)GPIO_PortSource << 0x04;
  411. tmpreg |= GPIO_PinSource;
  412. AFIO->ECR = tmpreg;
  413. }
  414. /*********************************************************************
  415. * @fn GPIO_EventOutputCmd
  416. *
  417. * @brief Enables or disables the Event Output.
  418. *
  419. * @param NewState - ENABLE or DISABLE.
  420. *
  421. * @return none
  422. */
  423. void GPIO_EventOutputCmd(FunctionalState NewState)
  424. {
  425. if(NewState)
  426. {
  427. AFIO->ECR |= (1 << 7);
  428. }
  429. else
  430. {
  431. AFIO->ECR &= ~(1 << 7);
  432. }
  433. }
  434. /*********************************************************************
  435. * @fn GPIO_PinRemapConfig
  436. *
  437. * @brief Changes the mapping of the specified pin.
  438. *
  439. * @param GPIO_Remap - selects the pin to remap.
  440. * GPIO_Remap_SPI1 - SPI1 Alternate Function mapping
  441. * GPIO_Remap_I2C1 - I2C1 Alternate Function mapping
  442. * GPIO_Remap_USART1 - USART1 Alternate Function mapping
  443. * GPIO_Remap_USART2 - USART2 Alternate Function mapping
  444. * GPIO_PartialRemap_USART3 - USART3 Partial Alternate Function mapping
  445. * GPIO_FullRemap_USART3 - USART3 Full Alternate Function mapping
  446. * GPIO_PartialRemap_TIM1 - TIM1 Partial Alternate Function mapping
  447. * GPIO_FullRemap_TIM1 - TIM1 Full Alternate Function mapping
  448. * GPIO_PartialRemap1_TIM2 - TIM2 Partial1 Alternate Function mapping
  449. * GPIO_PartialRemap2_TIM2 - TIM2 Partial2 Alternate Function mapping
  450. * GPIO_FullRemap_TIM2 - TIM2 Full Alternate Function mapping
  451. * GPIO_PartialRemap_TIM3 - TIM3 Partial Alternate Function mapping
  452. * GPIO_FullRemap_TIM3 - TIM3 Full Alternate Function mapping
  453. * GPIO_Remap_TIM4 - TIM4 Alternate Function mapping
  454. * GPIO_Remap1_CAN1 - CAN1 Alternate Function mapping
  455. * GPIO_Remap2_CAN1 - CAN1 Alternate Function mapping
  456. * GPIO_Remap_PD0PD1 - PD0 and PD1 Alternate Function mapping
  457. * GPIO_Remap_ADC1_ETRGINJ - ADC1 External Trigger Injected Conversion remapping
  458. * GPIO_Remap_ADC1_ETRGREG - ADC1 External Trigger Regular Conversion remapping
  459. * GPIO_Remap_ADC2_ETRGINJ - ADC2 External Trigger Injected Conversion remapping
  460. * GPIO_Remap_ADC2_ETRGREG - ADC2 External Trigger Regular Conversion remapping
  461. * GPIO_Remap_ETH - Ethernet remapping
  462. * GPIO_Remap_CAN2 - CAN2 remapping
  463. * GPIO_Remap_MII_RMII_SEL - MII or RMII selection
  464. * GPIO_Remap_SWJ_Disable - Full SWJ Disabled
  465. * GPIO_Remap_TIM2ITR1_PTP_SOF - Ethernet PTP output or USB OTG SOF (Start of Frame) connected
  466. * to TIM2 Internal Trigger 1 for calibration
  467. * GPIO_Remap_TIM2ITR1_PTP_SOF - Ethernet PTP output or USB OTG SOF (Start of Frame)
  468. * GPIO_Remap_TIM8 - TIM8 Alternate Function mapping
  469. * GPIO_PartialRemap_TIM9 - TIM9 Partial Alternate Function mapping
  470. * GPIO_FullRemap_TIM9 - TIM9 Full Alternate Function mapping
  471. * GPIO_PartialRemap_TIM10 - TIM10 Partial Alternate Function mapping
  472. * GPIO_FullRemap_TIM10 - TIM10 Full Alternate Function mapping
  473. * GPIO_Remap_FSMC_NADV - FSMC_NADV Alternate Function mapping
  474. * GPIO_PartialRemap_USART4 - USART4 Partial Alternate Function mapping
  475. * GPIO_FullRemap_USART4 - USART4 Full Alternate Function mapping
  476. * GPIO_PartialRemap_USART5 - USART5 Partial Alternate Function mapping
  477. * GPIO_FullRemap_USART5 - USART5 Full Alternate Function mapping
  478. * GPIO_PartialRemap_USART6 - USART6 Partial Alternate Function mapping
  479. * GPIO_FullRemap_USART6 - USART6 Full Alternate Function mapping
  480. * GPIO_PartialRemap_USART7 - USART7 Partial Alternate Function mapping
  481. * GPIO_FullRemap_USART7 - USART7 Full Alternate Function mapping
  482. * GPIO_PartialRemap_USART8 - USART8 Partial Alternate Function mapping
  483. * GPIO_FullRemap_USART8 - USART8 Full Alternate Function mapping
  484. * GPIO_Remap_USART1_HighBit - USART1 Alternate Function mapping high bit
  485. * NewState - ENABLE or DISABLE.
  486. *
  487. * @return none
  488. */
  489. void GPIO_PinRemapConfig(uint32_t GPIO_Remap, FunctionalState NewState)
  490. {
  491. uint32_t tmp = 0x00, tmp1 = 0x00, tmpreg = 0x00, tmpmask = 0x00;
  492. if((GPIO_Remap & 0x80000000) == 0x80000000)
  493. {
  494. tmpreg = AFIO->PCFR2;
  495. }
  496. else
  497. {
  498. tmpreg = AFIO->PCFR1;
  499. if(((*(uint32_t *) 0x40022030) & 0x0F000000) == 0){
  500. tmpreg = ((tmpreg>>1)&0xFFFFE000)|(tmpreg&0x00001FFF);
  501. }
  502. }
  503. tmpmask = (GPIO_Remap & DBGAFR_POSITION_MASK) >> 0x10;
  504. tmp = GPIO_Remap & LSB_MASK;
  505. /* Clear bit */
  506. if((GPIO_Remap & 0x80000000) == 0x80000000)
  507. { /* PCFR2 */
  508. if((GPIO_Remap & (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK)) == (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK)) /* [31:16] 2bit */
  509. {
  510. tmp1 = ((uint32_t)0x03) << (tmpmask + 0x10);
  511. tmpreg &= ~tmp1;
  512. }
  513. else if((GPIO_Remap & DBGAFR_NUMBITS_MASK) == DBGAFR_NUMBITS_MASK) /* [15:0] 2bit */
  514. {
  515. tmp1 = ((uint32_t)0x03) << tmpmask;
  516. tmpreg &= ~tmp1;
  517. }
  518. else /* [31:0] 1bit */
  519. {
  520. tmpreg &= ~(tmp << (((GPIO_Remap & 0x7FFFFFFF ) >> 0x15) * 0x10));
  521. }
  522. }
  523. else
  524. { /* PCFR1 */
  525. if((GPIO_Remap & (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK)) == (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK)) /* [26:24] 3bit SWD_JTAG */
  526. {
  527. tmpreg &= DBGAFR_SWJCFG_MASK;
  528. AFIO->PCFR1 &= DBGAFR_SWJCFG_MASK;
  529. }
  530. else if((GPIO_Remap & DBGAFR_NUMBITS_MASK) == DBGAFR_NUMBITS_MASK) /* [15:0] 2bit */
  531. {
  532. tmp1 = ((uint32_t)0x03) << tmpmask;
  533. tmpreg &= ~tmp1;
  534. tmpreg |= ~DBGAFR_SWJCFG_MASK;
  535. }
  536. else /* [31:0] 1bit */
  537. {
  538. tmpreg &= ~(tmp << ((GPIO_Remap >> 0x15) * 0x10));
  539. tmpreg |= ~DBGAFR_SWJCFG_MASK;
  540. }
  541. }
  542. /* Set bit */
  543. if(NewState != DISABLE)
  544. {
  545. tmpreg |= (tmp << (((GPIO_Remap & 0x7FFFFFFF )>> 0x15) * 0x10));
  546. }
  547. if((GPIO_Remap & 0x80000000) == 0x80000000)
  548. {
  549. AFIO->PCFR2 = tmpreg;
  550. }
  551. else
  552. {
  553. AFIO->PCFR1 = tmpreg;
  554. }
  555. }
  556. /*********************************************************************
  557. * @fn GPIO_EXTILineConfig
  558. *
  559. * @brief Selects the GPIO pin used as EXTI Line.
  560. *
  561. * @param GPIO_PortSource - selects the GPIO port to be used as source for EXTI lines.
  562. * This parameter can be GPIO_PortSourceGPIOx where x can be (A..G).
  563. * GPIO_PinSource - specifies the EXTI line to be configured.
  564. * This parameter can be GPIO_PinSourcex where x can be (0..15).
  565. *
  566. * @return none
  567. */
  568. void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource)
  569. {
  570. uint32_t tmp = 0x00;
  571. tmp = ((uint32_t)0x0F) << (0x04 * (GPIO_PinSource & (uint8_t)0x03));
  572. AFIO->EXTICR[GPIO_PinSource >> 0x02] &= ~tmp;
  573. AFIO->EXTICR[GPIO_PinSource >> 0x02] |= (((uint32_t)GPIO_PortSource) << (0x04 * (GPIO_PinSource & (uint8_t)0x03)));
  574. }
  575. /*********************************************************************
  576. * @fn GPIO_ETH_MediaInterfaceConfig
  577. *
  578. * @brief Selects the Ethernet media interface.
  579. *
  580. * @param GPIO_ETH_MediaInterface - specifies the Media Interface mode.
  581. * GPIO_ETH_MediaInterface_MII - MII mode
  582. * GPIO_ETH_MediaInterface_RMII - RMII mode
  583. *
  584. * @return none
  585. */
  586. void GPIO_ETH_MediaInterfaceConfig(uint32_t GPIO_ETH_MediaInterface)
  587. {
  588. if(GPIO_ETH_MediaInterface)
  589. {
  590. AFIO->PCFR1 |= (1 << 23);
  591. }
  592. else
  593. {
  594. AFIO->PCFR1 &= ~(1 << 23);
  595. }
  596. }
  597. /*********************************************************************
  598. * @fn GPIO_IPD_Unused
  599. *
  600. * @brief Configure unused GPIO as input pull-up.
  601. *
  602. * @param none
  603. *
  604. * @return none
  605. */
  606. void GPIO_IPD_Unused(void)
  607. {
  608. GPIO_InitTypeDef GPIO_InitStructure = {0};
  609. uint32_t chip = 0;
  610. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB \
  611. | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO,ENABLE);
  612. chip = *( uint32_t * )0x1FFFF704 & (~0x000000F0);
  613. switch(chip)
  614. {
  615. #ifdef CH32V20x_D6
  616. case 0x20370500: //CH32V203F6P6
  617. {
  618. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9\
  619. |GPIO_Pin_10|GPIO_Pin_15;
  620. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  621. GPIO_Init(GPIOA, &GPIO_InitStructure);
  622. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0\
  623. |GPIO_Pin_3|GPIO_Pin_4\
  624. |GPIO_Pin_5|GPIO_Pin_6\
  625. |GPIO_Pin_7|GPIO_Pin_9\
  626. |GPIO_Pin_10|GPIO_Pin_11\
  627. |GPIO_Pin_12|GPIO_Pin_13\
  628. |GPIO_Pin_14|GPIO_Pin_15;
  629. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  630. GPIO_Init(GPIOB, &GPIO_InitStructure);
  631. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1\
  632. |GPIO_Pin_2|GPIO_Pin_3\
  633. |GPIO_Pin_4|GPIO_Pin_5\
  634. |GPIO_Pin_6|GPIO_Pin_7\
  635. |GPIO_Pin_8|GPIO_Pin_9\
  636. |GPIO_Pin_10|GPIO_Pin_11\
  637. |GPIO_Pin_12|GPIO_Pin_13\
  638. |GPIO_Pin_14|GPIO_Pin_15;
  639. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  640. GPIO_Init(GPIOC, &GPIO_InitStructure);
  641. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3\
  642. |GPIO_Pin_4|GPIO_Pin_5\
  643. |GPIO_Pin_6;
  644. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  645. GPIO_Init(GPIOD, &GPIO_InitStructure);
  646. break;
  647. }
  648. case 0x203A0500: //CH32V203F8P6
  649. {
  650. GPIO_PinRemapConfig(GPIO_Remap_PD01, ENABLE);
  651. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_12\
  652. |GPIO_Pin_15;
  653. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  654. GPIO_Init(GPIOA, &GPIO_InitStructure);
  655. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  656. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
  657. GPIO_Init(GPIOB, &GPIO_InitStructure);
  658. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1\
  659. |GPIO_Pin_3|GPIO_Pin_4\
  660. |GPIO_Pin_5|GPIO_Pin_8\
  661. |GPIO_Pin_9|GPIO_Pin_10\
  662. |GPIO_Pin_11|GPIO_Pin_12;
  663. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  664. GPIO_Init(GPIOB, &GPIO_InitStructure);
  665. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1\
  666. |GPIO_Pin_2|GPIO_Pin_3\
  667. |GPIO_Pin_4|GPIO_Pin_5\
  668. |GPIO_Pin_6|GPIO_Pin_7\
  669. |GPIO_Pin_8|GPIO_Pin_9\
  670. |GPIO_Pin_10|GPIO_Pin_11\
  671. |GPIO_Pin_12|GPIO_Pin_13\
  672. |GPIO_Pin_14|GPIO_Pin_15;
  673. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  674. GPIO_Init(GPIOC, &GPIO_InitStructure);
  675. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3\
  676. |GPIO_Pin_4|GPIO_Pin_5\
  677. |GPIO_Pin_6;
  678. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  679. GPIO_Init(GPIOD, &GPIO_InitStructure);
  680. break;
  681. }
  682. case 0x203E0500: //CH32V203F8U6
  683. {
  684. GPIO_PinRemapConfig(GPIO_Remap_PD01, ENABLE);
  685. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
  686. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  687. GPIO_Init(GPIOA, &GPIO_InitStructure);
  688. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  689. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
  690. GPIO_Init(GPIOB, &GPIO_InitStructure);
  691. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3\
  692. |GPIO_Pin_4|GPIO_Pin_5\
  693. |GPIO_Pin_6|GPIO_Pin_7\
  694. |GPIO_Pin_8|GPIO_Pin_9\
  695. |GPIO_Pin_12|GPIO_Pin_13;
  696. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  697. GPIO_Init(GPIOB, &GPIO_InitStructure);
  698. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1\
  699. |GPIO_Pin_2|GPIO_Pin_3\
  700. |GPIO_Pin_4|GPIO_Pin_5\
  701. |GPIO_Pin_6|GPIO_Pin_7\
  702. |GPIO_Pin_8|GPIO_Pin_9\
  703. |GPIO_Pin_10|GPIO_Pin_11\
  704. |GPIO_Pin_12|GPIO_Pin_13\
  705. |GPIO_Pin_14|GPIO_Pin_15;
  706. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  707. GPIO_Init(GPIOC, &GPIO_InitStructure);
  708. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3\
  709. |GPIO_Pin_4|GPIO_Pin_5\
  710. |GPIO_Pin_6;
  711. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  712. GPIO_Init(GPIOD, &GPIO_InitStructure);
  713. break;
  714. }
  715. case 0x20360500: //CH32V203G6U6
  716. {
  717. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
  718. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  719. GPIO_Init(GPIOA, &GPIO_InitStructure);
  720. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  721. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
  722. GPIO_Init(GPIOB, &GPIO_InitStructure);
  723. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9\
  724. |GPIO_Pin_10|GPIO_Pin_11\
  725. |GPIO_Pin_12|GPIO_Pin_13\
  726. |GPIO_Pin_14|GPIO_Pin_15;
  727. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  728. GPIO_Init(GPIOB, &GPIO_InitStructure);
  729. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1\
  730. |GPIO_Pin_2|GPIO_Pin_3\
  731. |GPIO_Pin_4|GPIO_Pin_5\
  732. |GPIO_Pin_6|GPIO_Pin_7\
  733. |GPIO_Pin_8|GPIO_Pin_9\
  734. |GPIO_Pin_10|GPIO_Pin_11\
  735. |GPIO_Pin_12|GPIO_Pin_13\
  736. |GPIO_Pin_14|GPIO_Pin_15;
  737. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  738. GPIO_Init(GPIOC, &GPIO_InitStructure);
  739. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3\
  740. |GPIO_Pin_4|GPIO_Pin_5\
  741. |GPIO_Pin_6;
  742. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  743. GPIO_Init(GPIOD, &GPIO_InitStructure);
  744. break;
  745. }
  746. case 0x203B0500: //CH32V203G8R6
  747. {
  748. GPIO_PinRemapConfig(GPIO_Remap_PD01, ENABLE);
  749. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
  750. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  751. GPIO_Init(GPIOA, &GPIO_InitStructure);
  752. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  753. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
  754. GPIO_Init(GPIOB, &GPIO_InitStructure);
  755. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3\
  756. |GPIO_Pin_4|GPIO_Pin_9;
  757. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  758. GPIO_Init(GPIOB, &GPIO_InitStructure);
  759. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1\
  760. |GPIO_Pin_2|GPIO_Pin_3\
  761. |GPIO_Pin_4|GPIO_Pin_5\
  762. |GPIO_Pin_6|GPIO_Pin_7\
  763. |GPIO_Pin_8|GPIO_Pin_9\
  764. |GPIO_Pin_10|GPIO_Pin_11\
  765. |GPIO_Pin_12|GPIO_Pin_13\
  766. |GPIO_Pin_14|GPIO_Pin_15;
  767. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  768. GPIO_Init(GPIOC, &GPIO_InitStructure);
  769. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3\
  770. |GPIO_Pin_4|GPIO_Pin_5\
  771. |GPIO_Pin_6;
  772. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  773. GPIO_Init(GPIOD, &GPIO_InitStructure);
  774. break;
  775. }
  776. case 0x20320500: //CH32V203K8T6
  777. {
  778. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  779. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
  780. GPIO_Init(GPIOB, &GPIO_InitStructure);
  781. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9\
  782. |GPIO_Pin_10|GPIO_Pin_11\
  783. |GPIO_Pin_12|GPIO_Pin_13\
  784. |GPIO_Pin_14|GPIO_Pin_15;
  785. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  786. GPIO_Init(GPIOB, &GPIO_InitStructure);
  787. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1\
  788. |GPIO_Pin_2|GPIO_Pin_3\
  789. |GPIO_Pin_4|GPIO_Pin_5\
  790. |GPIO_Pin_6|GPIO_Pin_7\
  791. |GPIO_Pin_8|GPIO_Pin_9\
  792. |GPIO_Pin_10|GPIO_Pin_11\
  793. |GPIO_Pin_12|GPIO_Pin_13\
  794. |GPIO_Pin_14|GPIO_Pin_15;
  795. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  796. GPIO_Init(GPIOC, &GPIO_InitStructure);
  797. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3\
  798. |GPIO_Pin_4|GPIO_Pin_5\
  799. |GPIO_Pin_6;
  800. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  801. GPIO_Init(GPIOD, &GPIO_InitStructure);
  802. break;
  803. }
  804. case 0x20330500: //CH32V203C6T6
  805. {
  806. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1\
  807. |GPIO_Pin_2|GPIO_Pin_3\
  808. |GPIO_Pin_4|GPIO_Pin_5\
  809. |GPIO_Pin_6|GPIO_Pin_7\
  810. |GPIO_Pin_8|GPIO_Pin_9\
  811. |GPIO_Pin_10|GPIO_Pin_11\
  812. |GPIO_Pin_12;
  813. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  814. GPIO_Init(GPIOC, &GPIO_InitStructure);
  815. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3\
  816. |GPIO_Pin_4|GPIO_Pin_5\
  817. |GPIO_Pin_6;
  818. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  819. GPIO_Init(GPIOD, &GPIO_InitStructure);
  820. break;
  821. }
  822. case 0x20310500: //CH32V203C8T6
  823. {
  824. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1\
  825. |GPIO_Pin_2|GPIO_Pin_3\
  826. |GPIO_Pin_4|GPIO_Pin_5\
  827. |GPIO_Pin_6|GPIO_Pin_7\
  828. |GPIO_Pin_8|GPIO_Pin_9\
  829. |GPIO_Pin_10|GPIO_Pin_11\
  830. |GPIO_Pin_12;
  831. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  832. GPIO_Init(GPIOC, &GPIO_InitStructure);
  833. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3\
  834. |GPIO_Pin_4|GPIO_Pin_5\
  835. |GPIO_Pin_6;
  836. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  837. GPIO_Init(GPIOD, &GPIO_InitStructure);
  838. break;
  839. }
  840. case 0x20300500: //CH32V203C8U6
  841. {
  842. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1\
  843. |GPIO_Pin_2|GPIO_Pin_3\
  844. |GPIO_Pin_4|GPIO_Pin_5\
  845. |GPIO_Pin_6|GPIO_Pin_7\
  846. |GPIO_Pin_8|GPIO_Pin_9\
  847. |GPIO_Pin_10|GPIO_Pin_11\
  848. |GPIO_Pin_12;
  849. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  850. GPIO_Init(GPIOC, &GPIO_InitStructure);
  851. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3\
  852. |GPIO_Pin_4|GPIO_Pin_5\
  853. |GPIO_Pin_6;
  854. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  855. GPIO_Init(GPIOD, &GPIO_InitStructure);
  856. break;
  857. }
  858. #elif defined(CH32V20x_D8)
  859. case 0x2034050C: //CH32V203RBT6
  860. {
  861. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4\
  862. |GPIO_Pin_5|GPIO_Pin_6;
  863. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  864. GPIO_Init(GPIOD, &GPIO_InitStructure);
  865. break;
  866. }
  867. #elif defined(CH32V20x_D8W)
  868. case 0x2083050C: //CH32V208GBU6
  869. {
  870. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9\
  871. |GPIO_Pin_10|GPIO_Pin_15;
  872. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  873. GPIO_Init(GPIOA, &GPIO_InitStructure);
  874. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  875. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
  876. GPIO_Init(GPIOB, &GPIO_InitStructure);
  877. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1\
  878. |GPIO_Pin_3\
  879. |GPIO_Pin_4|GPIO_Pin_5\
  880. |GPIO_Pin_9|GPIO_Pin_10\
  881. |GPIO_Pin_11|GPIO_Pin_12\
  882. |GPIO_Pin_13|GPIO_Pin_14\
  883. |GPIO_Pin_15;
  884. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  885. GPIO_Init(GPIOB, &GPIO_InitStructure);
  886. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1\
  887. |GPIO_Pin_2|GPIO_Pin_3\
  888. |GPIO_Pin_4|GPIO_Pin_5\
  889. |GPIO_Pin_10|GPIO_Pin_11\
  890. |GPIO_Pin_12|GPIO_Pin_13;
  891. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  892. GPIO_Init(GPIOC, &GPIO_InitStructure);
  893. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3\
  894. |GPIO_Pin_4|GPIO_Pin_5\
  895. |GPIO_Pin_6;
  896. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  897. GPIO_Init(GPIOD, &GPIO_InitStructure);
  898. break;
  899. }
  900. case 0x2082050C: //CH32V208CBU6
  901. {
  902. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1\
  903. |GPIO_Pin_2|GPIO_Pin_3\
  904. |GPIO_Pin_4|GPIO_Pin_5\
  905. |GPIO_Pin_6|GPIO_Pin_7\
  906. |GPIO_Pin_8|GPIO_Pin_9\
  907. |GPIO_Pin_10|GPIO_Pin_11\
  908. |GPIO_Pin_12;
  909. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  910. GPIO_Init(GPIOC, &GPIO_InitStructure);
  911. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3\
  912. |GPIO_Pin_4|GPIO_Pin_5\
  913. |GPIO_Pin_6;
  914. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  915. GPIO_Init(GPIOD, &GPIO_InitStructure);
  916. break;
  917. }
  918. case 0x2081050C: //CH32V208RBT6
  919. {
  920. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4\
  921. |GPIO_Pin_5|GPIO_Pin_6;
  922. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  923. GPIO_Init(GPIOD, &GPIO_InitStructure);
  924. break;
  925. }
  926. #endif
  927. default:
  928. {
  929. break;
  930. }
  931. }
  932. }