gpio.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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_GPIOE_CLK_ENABLE();
  41. __HAL_RCC_GPIOB_CLK_ENABLE();
  42. __HAL_RCC_GPIOD_CLK_ENABLE();
  43. __HAL_RCC_GPIOA_CLK_ENABLE();
  44. __HAL_RCC_GPIOC_CLK_ENABLE();
  45. /*Configure GPIO pin Output Level */
  46. HAL_GPIO_WritePin(GPIOE, EN_4G_Pin|RST_4G_Pin, GPIO_PIN_SET);
  47. /*Configure GPIO pin Output Level */
  48. HAL_GPIO_WritePin(GPIOD, LED_R_Pin|LED_G_Pin|LED_Y_Pin|BEEP_Pin, GPIO_PIN_RESET);
  49. /*Configure GPIO pin Output Level */
  50. HAL_GPIO_WritePin(OneWireCommuation_GPIO_Port, OneWireCommuation_Pin, GPIO_PIN_RESET);
  51. /*Configure GPIO pin Output Level */
  52. HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
  53. /*Configure GPIO pins : PEPin PEPin */
  54. GPIO_InitStruct.Pin = EN_4G_Pin|RST_4G_Pin;
  55. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  56. GPIO_InitStruct.Pull = GPIO_NOPULL;
  57. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  58. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  59. /*Configure GPIO pins : PDPin PDPin PDPin PDPin */
  60. GPIO_InitStruct.Pin = LED_R_Pin|LED_G_Pin|LED_Y_Pin|BEEP_Pin;
  61. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  62. GPIO_InitStruct.Pull = GPIO_NOPULL;
  63. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  64. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  65. /*Configure GPIO pin : PtPin */
  66. GPIO_InitStruct.Pin = OneWireCommuation_Pin;
  67. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  68. GPIO_InitStruct.Pull = GPIO_NOPULL;
  69. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  70. HAL_GPIO_Init(OneWireCommuation_GPIO_Port, &GPIO_InitStruct);
  71. /*Configure GPIO pin : PtPin */
  72. GPIO_InitStruct.Pin = LED_Pin;
  73. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  74. GPIO_InitStruct.Pull = GPIO_NOPULL;
  75. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  76. HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);
  77. }
  78. /* USER CODE BEGIN 2 */
  79. // 运行灯翻转
  80. void LED0_TOGGLE(void)
  81. {
  82. HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
  83. HAL_GPIO_TogglePin(LED_R_GPIO_Port, LED_R_Pin);
  84. HAL_GPIO_TogglePin(LED_G_GPIO_Port, LED_G_Pin);
  85. HAL_GPIO_TogglePin(LED_Y_GPIO_Port, LED_Y_Pin);
  86. // HAL_GPIO_TogglePin(BEEP_GPIO_Port, BEEP_Pin);
  87. }
  88. /**
  89. * @brief 4G_EN 引脚操作
  90. * @param pinState:GPIO_PIN_RESET
  91. GPIO_PIN_SET
  92. * @note 使能电源 拉低关闭
  93. * @retval 无
  94. */
  95. void GPIO_EN_For_4G(GPIO_PinState pinState){
  96. HAL_GPIO_WritePin(EN_4G_GPIO_Port, EN_4G_Pin, pinState);
  97. }
  98. /**
  99. * @brief 4G_RST 引脚操作
  100. * @param pinState:GPIO_PIN_RESET
  101. GPIO_PIN_SET
  102. * @note 模块RESET/POWERKEY
  103. * @retval 无
  104. */
  105. void GPIO_RST_For_4G(GPIO_PinState pinState){
  106. HAL_GPIO_WritePin(RST_4G_GPIO_Port, RST_4G_Pin, pinState);
  107. }
  108. /**
  109. * @brief LED_R 引脚操作
  110. * @param pinState:GPIO_PIN_RESET
  111. GPIO_PIN_SET
  112. * @note
  113. * @retval 无
  114. */
  115. void GPIO_LED_R (GPIO_PinState pinState){
  116. HAL_GPIO_WritePin(LED_R_GPIO_Port, LED_R_Pin, pinState);
  117. }
  118. /**
  119. * @brief LED_G 引脚操作
  120. * @param pinState:GPIO_PIN_RESET
  121. GPIO_PIN_SET
  122. * @note
  123. * @retval 无
  124. */
  125. void GPIO_LED_G (GPIO_PinState pinState){
  126. HAL_GPIO_WritePin(LED_G_GPIO_Port, LED_G_Pin, pinState);
  127. }
  128. /**
  129. * @brief LED_Y 引脚操作
  130. * @param pinState:GPIO_PIN_RESET
  131. GPIO_PIN_SET
  132. * @note
  133. * @retval 无
  134. */
  135. void GPIO_LED_Y (GPIO_PinState pinState){
  136. HAL_GPIO_WritePin(LED_Y_GPIO_Port, LED_Y_Pin, pinState);
  137. }
  138. /**
  139. * @brief OneWireCommuation 引脚操作
  140. * @param pinState:GPIO_PIN_RESET
  141. GPIO_PIN_SET
  142. * @note
  143. * @retval 无
  144. */
  145. void GPIO_OneWireCommuation (GPIO_PinState pinState){
  146. HAL_GPIO_WritePin(OneWireCommuation_GPIO_Port, OneWireCommuation_Pin, pinState);
  147. }
  148. /**
  149. * @brief BEEP 引脚操作
  150. * @param pinState:GPIO_PIN_RESET
  151. GPIO_PIN_SET
  152. * @note
  153. * @retval 无
  154. */
  155. void GPIO_BEEP (GPIO_PinState pinState){
  156. HAL_GPIO_WritePin(BEEP_GPIO_Port, BEEP_Pin, pinState);
  157. }
  158. /* USER CODE END 2 */