gpio(3104).c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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(LED_G_GPIO_Port, LED_G_Pin);
  93. HAL_GPIO_TogglePin(LED_Y_GPIO_Port, LED_Y_Pin);
  94. // HAL_GPIO_TogglePin(BEEP_GPIO_Port, BEEP_Pin);
  95. }
  96. /**
  97. * @brief 4G_EN 引脚操作
  98. * @param pinState:GPIO_PIN_RESET
  99. GPIO_PIN_SET
  100. * @note 使能电源 拉低关闭
  101. * @retval 无
  102. */
  103. void GPIO_EN_For_4G(GPIO_PinState pinState){
  104. HAL_GPIO_WritePin(EN_4G_GPIO_Port, EN_4G_Pin, pinState);
  105. }
  106. /**
  107. * @brief 4G_RST 引脚操作
  108. * @param pinState:GPIO_PIN_RESET
  109. GPIO_PIN_SET
  110. * @note 模块RESET/POWERKEY
  111. * @retval 无
  112. */
  113. void GPIO_RST_For_4G(GPIO_PinState pinState){
  114. HAL_GPIO_WritePin(RST_4G_GPIO_Port, RST_4G_Pin, pinState);
  115. }
  116. /**
  117. * @brief LED_R 引脚操作
  118. * @param pinState:GPIO_PIN_RESET
  119. GPIO_PIN_SET
  120. * @note
  121. * @retval 无
  122. */
  123. void GPIO_LED_R (GPIO_PinState pinState){
  124. HAL_GPIO_WritePin(LED_R_GPIO_Port, LED_R_Pin, pinState);
  125. }
  126. /**
  127. * @brief LED_G 引脚操作
  128. * @param pinState:GPIO_PIN_RESET
  129. GPIO_PIN_SET
  130. * @note
  131. * @retval 无
  132. */
  133. void GPIO_LED_G (GPIO_PinState pinState){
  134. HAL_GPIO_WritePin(LED_G_GPIO_Port, LED_G_Pin, pinState);
  135. }
  136. /**
  137. * @brief LED_Y 引脚操作
  138. * @param pinState:GPIO_PIN_RESET
  139. GPIO_PIN_SET
  140. * @note
  141. * @retval 无
  142. */
  143. void GPIO_LED_Y (GPIO_PinState pinState){
  144. HAL_GPIO_WritePin(LED_Y_GPIO_Port, LED_Y_Pin, pinState);
  145. }
  146. /**
  147. * @brief OneWireCommuation 引脚操作
  148. * @param pinState:GPIO_PIN_RESET
  149. GPIO_PIN_SET
  150. * @note
  151. * @retval 无
  152. */
  153. void GPIO_OneWireCommuation (GPIO_PinState pinState){
  154. HAL_GPIO_WritePin(OneWireCommuation_GPIO_Port, OneWireCommuation_Pin, pinState);
  155. }
  156. /**
  157. * @brief BEEP 引脚操作
  158. * @param pinState:GPIO_PIN_RESET
  159. GPIO_PIN_SET
  160. * @note
  161. * @retval 无
  162. */
  163. void GPIO_BEEP (GPIO_PinState pinState){
  164. HAL_GPIO_WritePin(BEEP_GPIO_Port, BEEP_Pin, pinState);
  165. }
  166. /* USER CODE END 2 */