mapp_gpio.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. /************PA0 M3 3V******************/
  56. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ;
  57. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  58. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  59. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  60. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  61. GPIO_Init(GPIOA, &GPIO_InitStructure);
  62. /************PA4:RESET POWER*******/
  63. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 ;
  64. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  65. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  66. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  67. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  68. GPIO_Init(GPIOA, &GPIO_InitStructure);
  69. POWER_RESET_OFF;
  70. /************PA5:esc KEY*******/
  71. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  72. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  73. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  74. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  75. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  76. GPIO_Init(GPIOA, &GPIO_InitStructure);
  77. /************PA6:PWM******************/
  78. GPIO_PinAFConfig(GPIOA,GPIO_PinSource6,GPIO_AF_0);//GPIO_AF_0
  79. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 ;
  80. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  81. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  82. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  83. GPIO_Init(GPIOA, &GPIO_InitStructure);
  84. /************PA6:EMEGENCY LED******************/
  85. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 ;
  86. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  87. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  88. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  89. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  90. GPIO_Init(GPIOA, &GPIO_InitStructure);
  91. LED_EMEGENCY_OFF;
  92. /************PA7:EMEGENCY KEY******************/
  93. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
  94. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  95. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  96. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  97. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  98. GPIO_Init(GPIOA, &GPIO_InitStructure);
  99. /************PA8:EMEGENCY KEY******************/
  100. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
  101. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  102. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  103. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  104. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  105. GPIO_Init(GPIOA, &GPIO_InitStructure);
  106. /************PB0:HADLE KEY******************/
  107. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  108. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  109. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  110. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  111. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  112. GPIO_Init(GPIOB, &GPIO_InitStructure);
  113. /************PB1:CHANGE KEY******************/
  114. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
  115. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  116. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  117. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  118. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  119. GPIO_Init(GPIOB, &GPIO_InitStructure);
  120. /************PA9:CANCEL KEY******************/
  121. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  122. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  123. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  124. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  125. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  126. GPIO_Init(GPIOA, &GPIO_InitStructure);
  127. /************PA10:CALL KEY******************/
  128. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  129. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  130. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  131. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  132. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  133. GPIO_Init(GPIOA, &GPIO_InitStructure);
  134. /************PA11:NURSE KEY******************/
  135. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
  136. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  137. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  138. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  139. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  140. GPIO_Init(GPIOA, &GPIO_InitStructure);
  141. /************PA12:REINFORCE KEY******************/
  142. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
  143. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  144. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  145. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  146. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  147. GPIO_Init(GPIOA, &GPIO_InitStructure);
  148. /************PA15:RELAY******************/
  149. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
  150. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  151. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  152. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  153. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  154. GPIO_Init(GPIOA, &GPIO_InitStructure);
  155. RELAY_OFF;
  156. /************PB3:LEDY******************/
  157. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  158. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  159. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  160. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  161. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  162. GPIO_Init(GPIOB, &GPIO_InitStructure);
  163. LED_Y_OFF;
  164. /************PB4:LEDR******************/
  165. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
  166. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  167. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  168. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  169. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  170. GPIO_Init(GPIOB, &GPIO_InitStructure);
  171. LED_R_OFF;
  172. /************PB5:GREEN******************/
  173. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  174. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  175. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  176. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  177. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  178. GPIO_Init(GPIOB, &GPIO_InitStructure);
  179. LED_GREEN_OFF;
  180. /************PB6:BLUE******************/
  181. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  182. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  183. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  184. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  185. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  186. GPIO_Init(GPIOB, &GPIO_InitStructure);
  187. LED_BLUE_OFF;
  188. /************PB7:RED******************/
  189. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
  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. LED_RED_OFF;
  196. }
  197. void GpioLedInit(void)
  198. {
  199. GPIO_InitTypeDef GPIO_InitStructure;
  200. /* Enable GPIO clocks */
  201. RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  202. /************PA******************
  203. PA13---------------- KEY_LED USB_BATTER_LED
  204. PA14---------------- BK-LED
  205. ****************************************/
  206. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14;
  207. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  208. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  209. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  210. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  211. GPIO_Init(GPIOA, &GPIO_InitStructure);
  212. }
  213. /*----------------------------------------------------------------------
  214. // Function uses : GpioCfgReset
  215. // Input parameter :
  216. // Output parameter :
  217. // Use Function : Reset all IO except specified usage.
  218. // Reserve date : 17:53, 05.Seb.2019, written by dwd
  219. ----------------------------------------------------------------------*/
  220. void GpioCfgReset(void)
  221. {
  222. }
  223. void GpioSpiCSCfg(FlagStatus flag){
  224. if (flag == SET) {
  225. GPIO_SetBits(GPIOA, GPIO_Pin_1);
  226. } else {
  227. GPIO_ResetBits(GPIOA, GPIO_Pin_1);
  228. }
  229. }
  230. void GpioSpiSclCfg(FlagStatus flag){
  231. if (flag == SET) {
  232. GPIO_SetBits(GPIOA, GPIO_Pin_7);
  233. } else {
  234. GPIO_ResetBits(GPIOA, GPIO_Pin_7);
  235. }
  236. }
  237. void GpioMOSICfg(FlagStatus flag)
  238. {
  239. if (flag == SET) {
  240. GPIO_SetBits(GPIOA, GPIO_Pin_9);
  241. } else {
  242. GPIO_ResetBits(GPIOA, GPIO_Pin_9);
  243. }
  244. }
  245. /*------------------------------- E O F ----------------------------------------*/