at32f425_scfg.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /**
  2. **************************************************************************
  3. * @file at32f425_scfg.c
  4. * @brief contains all the functions for the system config firmware library
  5. **************************************************************************
  6. * Copyright notice & Disclaimer
  7. *
  8. * The software Board Support Package (BSP) that is made available to
  9. * download from Artery official website is the copyrighted work of Artery.
  10. * Artery authorizes customers to use, copy, and distribute the BSP
  11. * software and its related documentation for the purpose of design and
  12. * development in conjunction with Artery microcontrollers. Use of the
  13. * software is governed by this copyright notice and the following disclaimer.
  14. *
  15. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  16. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  17. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  18. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  19. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  21. *
  22. **************************************************************************
  23. */
  24. #include "at32f425_conf.h"
  25. /** @addtogroup AT32F425_periph_driver
  26. * @{
  27. */
  28. /** @defgroup SCFG
  29. * @brief SCFG driver modules
  30. * @{
  31. */
  32. #ifdef SCFG_MODULE_ENABLED
  33. /** @defgroup SCFG_private_functions
  34. * @{
  35. */
  36. /**
  37. * @brief scfg reset
  38. * @param none
  39. * @retval none
  40. */
  41. void scfg_reset(void)
  42. {
  43. crm_periph_reset(CRM_SCFG_PERIPH_RESET, TRUE);
  44. crm_periph_reset(CRM_SCFG_PERIPH_RESET, FALSE);
  45. }
  46. /**
  47. * @brief scfg infrared config
  48. * @param source
  49. * this parameter can be one of the following values:
  50. * - SCFG_IR_SOURCE_TMR10
  51. * @param polarity
  52. * this parameter can be one of the following values:
  53. * - SCFG_IR_POLARITY_NO_AFFECTE
  54. * - SCFG_IR_POLARITY_REVERSE
  55. * @retval none
  56. */
  57. void scfg_infrared_config(scfg_ir_source_type source, scfg_ir_polarity_type polarity)
  58. {
  59. SCFG->cfg1_bit.ir_src_sel = source;
  60. SCFG->cfg1_bit.ir_pol = polarity;
  61. }
  62. /**
  63. * @brief scfg memory address mapping get
  64. * @param none
  65. * @retval return parameter can be one of the following values:
  66. * - SCFG_MEM_MAP_MAIN_MEMORY
  67. * - SCFG_MEM_MAP_BOOT_MEMORY
  68. * - SCFG_MEM_MAP_INTERNAL_SRAM
  69. */
  70. scfg_mem_map_type scfg_mem_map_get(void)
  71. {
  72. if(SCFG->cfg1_bit.mem_map_sel & 0x1)
  73. {
  74. return (scfg_mem_map_type)SCFG->cfg1_bit.mem_map_sel;
  75. }
  76. return SCFG_MEM_MAP_MAIN_MEMORY;
  77. }
  78. /**
  79. * @brief scfg pa11/12 pin remap
  80. * @param pin_remap
  81. * this parameter can be one of the following values:
  82. * - SCFG_PA11PA12_NO_REMAP
  83. * - SCFG_PA11PA12_TO_PA9PA10
  84. * @retval none
  85. */
  86. void scfg_pa11pa12_pin_remap(scfg_pa11pa12_remap_type pin_remap)
  87. {
  88. SCFG->cfg1_bit.pa11_12_rmp = pin_remap;
  89. }
  90. /**
  91. * @brief select the gpio pin used as exint line.
  92. * @param port_source:
  93. * select the gpio port to be used as source for exint lines.
  94. * this parameter can be one of the following values:
  95. * - SCFG_PORT_SOURCE_GPIOA
  96. * - SCFG_PORT_SOURCE_GPIOB
  97. * - SCFG_PORT_SOURCE_GPIOC
  98. * - SCFG_PORT_SOURCE_GPIOD
  99. * - SCFG_PORT_SOURCE_GPIOF
  100. * @param pin_source:
  101. * specifies the exint line to be configured.
  102. * this parameter can be one of the following values:
  103. * - SCFG_PINS_SOURCE0
  104. * - SCFG_PINS_SOURCE1
  105. * - SCFG_PINS_SOURCE2
  106. * - SCFG_PINS_SOURCE3
  107. * - SCFG_PINS_SOURCE4
  108. * - SCFG_PINS_SOURCE5
  109. * - SCFG_PINS_SOURCE6
  110. * - SCFG_PINS_SOURCE7
  111. * - SCFG_PINS_SOURCE8
  112. * - SCFG_PINS_SOURCE9
  113. * - SCFG_PINS_SOURCE10
  114. * - SCFG_PINS_SOURCE11
  115. * - SCFG_PINS_SOURCE12
  116. * - SCFG_PINS_SOURCE13
  117. * - SCFG_PINS_SOURCE14
  118. * - SCFG_PINS_SOURCE15
  119. * @retval none
  120. */
  121. void scfg_exint_line_config(scfg_port_source_type port_source, scfg_pins_source_type pin_source)
  122. {
  123. uint32_t tmp = 0x00;
  124. tmp = ((uint32_t)0x0F) << (0x04 * (pin_source & (uint8_t)0x03));
  125. switch (pin_source >> 0x02)
  126. {
  127. case 0:
  128. SCFG->exintc1 &= ~tmp;
  129. SCFG->exintc1 |= (((uint32_t)port_source) << (0x04 * (pin_source & (uint8_t)0x03)));
  130. break;
  131. case 1:
  132. SCFG->exintc2 &= ~tmp;
  133. SCFG->exintc2 |= (((uint32_t)port_source) << (0x04 * (pin_source & (uint8_t)0x03)));
  134. break;
  135. case 2:
  136. SCFG->exintc3 &= ~tmp;
  137. SCFG->exintc3 |= (((uint32_t)port_source) << (0x04 * (pin_source & (uint8_t)0x03)));
  138. break;
  139. case 3:
  140. SCFG->exintc4 &= ~tmp;
  141. SCFG->exintc4 |= (((uint32_t)port_source) << (0x04 * (pin_source & (uint8_t)0x03)));
  142. break;
  143. default:
  144. break;
  145. }
  146. }
  147. /**
  148. * @brief enable or disable gpio pins ultra driven.
  149. * @param value:
  150. * this parameter can be one of the following values:
  151. * - SCFG_ULTRA_DRIVEN_PB8
  152. * - SCFG_ULTRA_DRIVEN_PB9
  153. * - SCFG_ULTRA_DRIVEN_PB13
  154. * - SCFG_ULTRA_DRIVEN_PB14
  155. * @param new_state (TRUE or FALSE)
  156. * @retval none
  157. */
  158. void scfg_pins_ultra_driven_enable(scfg_ultra_driven_pins_type value, confirm_state new_state)
  159. {
  160. if(TRUE == new_state)
  161. {
  162. SCFG->cfg1 |= value;
  163. }
  164. else
  165. {
  166. SCFG->cfg1&= ~value;
  167. }
  168. }
  169. /**
  170. * @brief i2s full duplex config.
  171. * @param i2s_full_duplex:
  172. * this parameter can be one of the following values:
  173. * - SCFG_FULL_DUPLEX_I2S_NONE
  174. * - SCFG_FULL_DUPLEX_I2S1_I2S3
  175. * - SCFG_FULL_DUPLEX_I2S2_I2S3
  176. * - SCFG_FULL_DUPLEX_I2S1_I2S2
  177. * @retval none
  178. */
  179. void scfg_i2s_full_duplex_config(scfg_i2s_type i2s_full_duplex)
  180. {
  181. SCFG->cfg2_bit.i2s_fd = i2s_full_duplex;
  182. }
  183. /**
  184. * @brief scfg pvm lock enable.
  185. * @param new_state (TRUE or FALSE)
  186. * - TRUE (pvm interrupt connect to the brake of TMR15/16/17 )
  187. * - FALSE (pvm interrupt not connect to the brake of TMR15/16/17 )
  188. * @retval none
  189. */
  190. void scfg_pvm_lock_enable(confirm_state new_state)
  191. {
  192. SCFG->cfg2_bit.pvm_lk = new_state;
  193. }
  194. /**
  195. * @}
  196. */
  197. #endif
  198. /**
  199. * @}
  200. */
  201. /**
  202. * @}
  203. */