mapp_gpio.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. //==================================================================
  2. //
  3. // Filename: mapp_gpio.c
  4. // Description: System driver.
  5. //
  6. //------------------------------------------------------------------
  7. //
  8. // version:
  9. // date: 17:53, 05.Seb.2019, written by dwd
  10. // Description:
  11. //
  12. //------------------------------------------------------------------
  13. //==================================================================
  14. /*------------------------------------------------------------------------------
  15. * I N C L U D E
  16. *------------------------------------------------------------------------------*/
  17. #include "stm32f0xx.h"
  18. #include "general.h"
  19. #include "mapp_gpio.h"
  20. #include "mapp_arm.h"
  21. #include "mapp_msg.h"
  22. #include "mapp_ami.h"
  23. #include "main.h"
  24. /*------------------------------------------------------------------------------
  25. * D E F I N E
  26. *------------------------------------------------------------------------------*/
  27. /*--- ADC1 DMA base address ---*/
  28. /*------------------------------------------------------------------------------
  29. * S T R U C T
  30. *------------------------------------------------------------------------------*/
  31. /*------------------------------------------------------------------------------
  32. * S T A T I C - V A R I A B L E S
  33. *------------------------------------------------------------------------------*/
  34. /*------------------------------------------------------------------------------
  35. * G L O B A L
  36. *------------------------------------------------------------------------------*/
  37. /*------------------------------------------------------------------------------
  38. * P R O T O T Y P E
  39. *------------------------------------------------------------------------------*/
  40. /*----------------------------------------------------------------------
  41. // Function uses : GpioCfgInit
  42. // Input parameter :
  43. // Output parameter :
  44. // Use Function : Configuration all GPIOs for system.
  45. // Reserve date : 17:53, 05.Seb.2019, written by dwd
  46. ----------------------------------------------------------------------*/
  47. void GpioCfgInit(void)
  48. {
  49. GPIO_InitTypeDef GPIO_InitStructure;
  50. /* Enable GPIO clocks */
  51. RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB|RCC_AHBPeriph_GPIOC, ENABLE);
  52. RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF, ENABLE);
  53. RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  54. //GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
  55. RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
  56. RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
  57. GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_0); //uart1——tx stm32f030C8
  58. GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_0);
  59. /* Configure pins as AF pushpull */
  60. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;//TXRX GPIO_Pin_6|
  61. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  62. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  63. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  64. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  65. GPIO_Init(GPIOB, &GPIO_InitStructure);
  66. GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1); //uart2 stm32f030C8
  67. GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1);
  68. /* Configure pins as AF pushpull */
  69. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3;//TXRX
  70. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  71. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  72. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  73. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  74. GPIO_Init(GPIOA, &GPIO_InitStructure);
  75. /************PA0:VOICERSW******************/
  76. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ;
  77. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  78. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  79. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  80. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  81. GPIO_Init(GPIOA, &GPIO_InitStructure);
  82. /************PA1:mute*******/
  83. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ;
  84. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  85. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  86. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  87. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  88. GPIO_Init(GPIOA, &GPIO_InitStructure);
  89. /************PA4:HADLE KEY******************/
  90. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
  91. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  92. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  93. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  94. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  95. GPIO_Init(GPIOA, &GPIO_InitStructure);
  96. /************PA5:CHANGE KEY******************/
  97. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  98. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  99. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  100. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  101. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  102. GPIO_Init(GPIOA, &GPIO_InitStructure);
  103. /************PA6.PA7:PWM******************/
  104. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 ;
  105. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  106. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  107. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  108. GPIO_Init(GPIOA, &GPIO_InitStructure);
  109. GPIO_PinAFConfig(GPIOA,GPIO_PinSource6,GPIO_AF_0);//GPIO_AF_1
  110. // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  111. // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; // 设置为输出模式
  112. // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  113. // GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  114. // GPIO_Init(GPIOA, &GPIO_InitStructure);
  115. // // 设置引脚为低电平
  116. // GPIO_ResetBits(GPIOA, GPIO_Pin_6);
  117. /************PA8:BUS_IN ******************/
  118. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 ;
  119. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  120. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  121. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  122. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  123. GPIO_Init(GPIOA, &GPIO_InitStructure);
  124. /* Connect TIM pin to TIM1_CH1 */
  125. GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_2);
  126. /************PA15:NURSE KEY******************/
  127. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
  128. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  129. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  130. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  131. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  132. GPIO_Init(GPIOA, &GPIO_InitStructure);
  133. /************PF7:VOIVCE SPEAK CONTROL******************/
  134. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
  135. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  136. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  137. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  138. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  139. GPIO_Init(GPIOF,&GPIO_InitStructure);
  140. #if 0
  141. /************PB0,PB1:BUS_IN ******************/
  142. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  143. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  144. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  145. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  146. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  147. GPIO_Init(GPIOB, &GPIO_InitStructure);
  148. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ;
  149. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  150. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  151. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  152. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  153. GPIO_Init(GPIOB, &GPIO_InitStructure);
  154. /* Connect TIM pin to TIM3_CH4 */
  155. // GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_1);
  156. /* Connect TIM pin to TIM14_CH1 */
  157. GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_0);
  158. #endif
  159. /************PB3:REINFORCE KEY******************/
  160. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  161. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  162. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  163. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  164. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  165. GPIO_Init(GPIOB, &GPIO_InitStructure);
  166. /************PB4:CANCEL KEY******************/
  167. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
  168. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  169. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  170. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  171. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  172. GPIO_Init(GPIOB, &GPIO_InitStructure);
  173. /************PB5:CALL KEY******************/
  174. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  175. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  176. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  177. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  178. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  179. GPIO_Init(GPIOB, &GPIO_InitStructure);
  180. VOICE_PB15_ON;
  181. /************PB11:RALAY******************/
  182. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
  183. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  184. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  185. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  186. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  187. GPIO_Init(GPIOB, &GPIO_InitStructure);
  188. /************PB15:D0*****************/
  189. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15 ;
  190. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  191. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  192. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  193. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  194. GPIO_Init(GPIOB, &GPIO_InitStructure);
  195. /************PC13:LEDY******************/
  196. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
  197. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  198. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  199. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  200. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  201. GPIO_Init(GPIOC, &GPIO_InitStructure);
  202. LED_Y_OFF;
  203. /************Pc14:sw_spk******************/
  204. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
  205. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  206. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  207. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  208. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  209. GPIO_Init(GPIOC, &GPIO_InitStructure);
  210. GPIO_SetBits(GPIOC, GPIO_Pin_14); //原来是用来切换二三线制,现在改为默认高电平,支持切换喇叭
  211. /************Pc15:GPIO_MIC_SW******************/
  212. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
  213. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  214. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  215. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  216. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  217. GPIO_Init(GPIOC, &GPIO_InitStructure);
  218. }
  219. void GpioLedInit(void)
  220. {
  221. GPIO_InitTypeDef GPIO_InitStructure;
  222. /* Enable GPIO clocks */
  223. RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  224. /************PA******************
  225. PA13---------------- KEY_LED USB_BATTER_LED
  226. PA14---------------- BK-LED
  227. ****************************************/
  228. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14;
  229. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  230. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  231. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  232. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  233. GPIO_Init(GPIOA, &GPIO_InitStructure);
  234. }
  235. /*----------------------------------------------------------------------
  236. // Function uses : GpioCfgReset
  237. // Input parameter :
  238. // Output parameter :
  239. // Use Function : Reset all IO except specified usage.
  240. // Reserve date : 17:53, 05.Seb.2019, written by dwd
  241. ----------------------------------------------------------------------*/
  242. void GpioCfgReset(void)
  243. {
  244. }
  245. void GpioSpiCSCfg(FlagStatus flag){
  246. if (flag == SET) {
  247. GPIO_SetBits(GPIOA, GPIO_Pin_1);
  248. } else {
  249. GPIO_ResetBits(GPIOA, GPIO_Pin_1);
  250. }
  251. }
  252. void GpioSpiSclCfg(FlagStatus flag){
  253. if (flag == SET) {
  254. GPIO_SetBits(GPIOA, GPIO_Pin_7);
  255. } else {
  256. GPIO_ResetBits(GPIOA, GPIO_Pin_7);
  257. }
  258. }
  259. void GpioMOSICfg(FlagStatus flag)
  260. {
  261. if (flag == SET) {
  262. GPIO_SetBits(GPIOA, GPIO_Pin_9);
  263. } else {
  264. GPIO_ResetBits(GPIOA, GPIO_Pin_9);
  265. }
  266. }
  267. /*------------------------------- E O F ----------------------------------------*/