gpio.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file gpio.c
  5. * @brief This file provides code for the configuration
  6. * of all used GPIO pins.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * Copyright (c) 2024 STMicroelectronics.
  11. * All rights reserved.
  12. *
  13. * This software is licensed under terms that can be found in the LICENSE file
  14. * in the root directory of this software component.
  15. * If no LICENSE file comes with this software, it is provided AS-IS.
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "gpio.h"
  22. /* USER CODE BEGIN 0 */
  23. /* USER CODE END 0 */
  24. /*----------------------------------------------------------------------------*/
  25. /* Configure GPIO */
  26. /*----------------------------------------------------------------------------*/
  27. /* USER CODE BEGIN 1 */
  28. /* USER CODE END 1 */
  29. /** Configure pins as
  30. * Analog
  31. * Input
  32. * Output
  33. * EVENT_OUT
  34. * EXTI
  35. */
  36. void MX_GPIO_Init(void)
  37. {
  38. GPIO_InitTypeDef GPIO_InitStruct = {0};
  39. /* GPIO Ports Clock Enable */
  40. __HAL_RCC_GPIOA_CLK_ENABLE();
  41. __HAL_RCC_GPIOC_CLK_ENABLE();
  42. __HAL_RCC_GPIOE_CLK_ENABLE();
  43. __HAL_RCC_GPIOB_CLK_ENABLE();
  44. __HAL_RCC_GPIOD_CLK_ENABLE();
  45. /*Configure GPIO pin Output Level */
  46. HAL_GPIO_WritePin(NORFLASH_CS_GPIO_GPIO_Port, NORFLASH_CS_GPIO_Pin, GPIO_PIN_RESET);
  47. /*Configure GPIO pin Output Level */
  48. HAL_GPIO_WritePin(GPIOE, EN_4G_Pin|RST_4G_Pin, GPIO_PIN_SET);
  49. /*Configure GPIO pin Output Level */
  50. HAL_GPIO_WritePin(GPIOD, LED_R_Pin|LED_G_Pin|LED_Y_Pin|BEEP_Pin, GPIO_PIN_RESET);
  51. /*Configure GPIO pin Output Level */
  52. HAL_GPIO_WritePin(OneWireCommuation_GPIO_Port, OneWireCommuation_Pin, GPIO_PIN_RESET);
  53. /*Configure GPIO pin Output Level */
  54. HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
  55. /*Configure GPIO pin : PtPin */
  56. GPIO_InitStruct.Pin = NORFLASH_CS_GPIO_Pin;
  57. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  58. GPIO_InitStruct.Pull = GPIO_PULLUP;
  59. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  60. HAL_GPIO_Init(NORFLASH_CS_GPIO_GPIO_Port, &GPIO_InitStruct);
  61. /*Configure GPIO pins : PEPin PEPin */
  62. GPIO_InitStruct.Pin = EN_4G_Pin|RST_4G_Pin;
  63. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  64. GPIO_InitStruct.Pull = GPIO_NOPULL;
  65. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  66. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  67. /*Configure GPIO pins : PDPin PDPin PDPin PDPin */
  68. GPIO_InitStruct.Pin = LED_R_Pin|LED_G_Pin|LED_Y_Pin|BEEP_Pin;
  69. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  70. GPIO_InitStruct.Pull = GPIO_NOPULL;
  71. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  72. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  73. /*Configure GPIO pin : PtPin */
  74. GPIO_InitStruct.Pin = OneWireCommuation_Pin;
  75. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  76. GPIO_InitStruct.Pull = GPIO_NOPULL;
  77. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  78. HAL_GPIO_Init(OneWireCommuation_GPIO_Port, &GPIO_InitStruct);
  79. /*Configure GPIO pin : PtPin */
  80. GPIO_InitStruct.Pin = LED_Pin;
  81. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  82. GPIO_InitStruct.Pull = GPIO_NOPULL;
  83. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  84. HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);
  85. }
  86. /* USER CODE BEGIN 2 */
  87. // 运行灯翻转
  88. void LED0_TOGGLE(void)
  89. {
  90. HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
  91. HAL_GPIO_TogglePin(LED_R_GPIO_Port, LED_R_Pin);
  92. // HAL_GPIO_TogglePin(BEEP_GPIO_Port, BEEP_Pin);
  93. }
  94. void LED_G_TOGGLE(void){
  95. HAL_GPIO_TogglePin(LED_G_GPIO_Port, LED_G_Pin);
  96. }
  97. void LED_Y_TOGGLE(void){
  98. HAL_GPIO_TogglePin(LED_Y_GPIO_Port, LED_Y_Pin);
  99. }
  100. /**
  101. * @brief 4G_EN 引脚操作
  102. * @param pinState:GPIO_PIN_RESET
  103. GPIO_PIN_SET
  104. * @note 使能电源 拉低关闭
  105. * @retval 无
  106. */
  107. void GPIO_EN_For_4G(GPIO_PinState pinState){
  108. HAL_GPIO_WritePin(EN_4G_GPIO_Port, EN_4G_Pin, pinState);
  109. }
  110. /**
  111. * @brief 4G_RST 引脚操作
  112. * @param pinState:GPIO_PIN_RESET
  113. GPIO_PIN_SET
  114. * @note 模块RESET/POWERKEY
  115. * @retval 无
  116. */
  117. void GPIO_RST_For_4G(GPIO_PinState pinState){
  118. HAL_GPIO_WritePin(RST_4G_GPIO_Port, RST_4G_Pin, pinState);
  119. }
  120. /**
  121. * @brief LED_R 引脚操作
  122. * @param pinState:GPIO_PIN_RESET
  123. GPIO_PIN_SET
  124. * @note
  125. * @retval 无
  126. */
  127. void GPIO_LED_R (GPIO_PinState pinState){
  128. HAL_GPIO_WritePin(LED_R_GPIO_Port, LED_R_Pin, pinState);
  129. }
  130. /**
  131. * @brief LED_G 引脚操作
  132. * @param pinState:GPIO_PIN_RESET
  133. GPIO_PIN_SET
  134. * @note
  135. * @retval 无
  136. */
  137. void GPIO_LED_G (GPIO_PinState pinState){
  138. HAL_GPIO_WritePin(LED_G_GPIO_Port, LED_G_Pin, pinState);
  139. }
  140. /**
  141. * @brief LED_Y 引脚操作
  142. * @param pinState:GPIO_PIN_RESET
  143. GPIO_PIN_SET
  144. * @note
  145. * @retval 无
  146. */
  147. void GPIO_LED_Y (GPIO_PinState pinState){
  148. HAL_GPIO_WritePin(LED_Y_GPIO_Port, LED_Y_Pin, pinState);
  149. }
  150. /**
  151. * @brief OneWireCommuation 引脚操作
  152. * @param pinState:GPIO_PIN_RESET
  153. GPIO_PIN_SET
  154. * @note
  155. * @retval 无
  156. */
  157. void GPIO_OneWireCommuation (GPIO_PinState pinState){
  158. HAL_GPIO_WritePin(OneWireCommuation_GPIO_Port, OneWireCommuation_Pin, pinState);
  159. }
  160. /**
  161. * @brief BEEP 引脚操作
  162. * @param pinState:GPIO_PIN_RESET
  163. GPIO_PIN_SET
  164. * @note
  165. * @retval 无
  166. */
  167. void GPIO_BEEP (GPIO_PinState pinState){
  168. HAL_GPIO_WritePin(BEEP_GPIO_Port, BEEP_Pin, pinState);
  169. }
  170. /* USER CODE END 2 */