gpio.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. ******************************************************************************
  3. * File Name : gpio.c
  4. * Description : This file provides code for the configuration
  5. * of all used GPIO pins.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "gpio.h"
  21. /* USER CODE BEGIN 0 */
  22. /* USER CODE END 0 */
  23. /*----------------------------------------------------------------------------*/
  24. /* Configure GPIO */
  25. /*----------------------------------------------------------------------------*/
  26. /* USER CODE BEGIN 1 */
  27. /* USER CODE END 1 */
  28. /** Configure pins as
  29. * Analog
  30. * Input
  31. * Output
  32. * EVENT_OUT
  33. * EXTI
  34. * Free pins are configured automatically as Analog (this feature is enabled through
  35. * the Code Generation settings)
  36. */
  37. void MX_GPIO_Init(void)
  38. {
  39. GPIO_InitTypeDef GPIO_InitStruct = {0};
  40. /* GPIO Ports Clock Enable */
  41. __HAL_RCC_GPIOC_CLK_ENABLE();
  42. __HAL_RCC_GPIOD_CLK_ENABLE();
  43. __HAL_RCC_GPIOA_CLK_ENABLE();
  44. __HAL_RCC_GPIOB_CLK_ENABLE();
  45. /*Configure GPIO pin Output Level */
  46. HAL_GPIO_WritePin(GPIOA, LED1_Pin|LED2_Pin|LED3_Pin
  47. |CAN_SLIENT_Pin, GPIO_PIN_SET);
  48. /*Configure GPIO pin Output Level */
  49. HAL_GPIO_WritePin(GPIOB, LED_R_Pin|LED_G_Pin|LED_B_Pin|GPIO_PIN_14, GPIO_PIN_RESET);
  50. /*Configure GPIO pins : PC13 PC14 PC15 */
  51. GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  52. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  53. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  54. /*Configure GPIO pins : PA1 PA9 PA10 */
  55. GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_9|GPIO_PIN_10;
  56. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  57. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  58. /*Configure GPIO pins : PAPin PAPin PAPin PAPin
  59. PAPin */
  60. GPIO_InitStruct.Pin = LED1_Pin|LED3_Pin
  61. |CAN_SLIENT_Pin;
  62. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
  63. GPIO_InitStruct.Pull = GPIO_NOPULL;
  64. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  65. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  66. GPIO_InitStruct.Pin = LED2_Pin;
  67. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
  68. GPIO_InitStruct.Pull = GPIO_NOPULL;
  69. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  70. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  71. /*Configure GPIO pins : PBPin PBPin PBPin PB15 */
  72. GPIO_InitStruct.Pin = LED_R_Pin|LED_G_Pin|LED_B_Pin;
  73. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  74. GPIO_InitStruct.Pull = GPIO_NOPULL;
  75. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  76. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  77. GPIO_InitStruct.Pin = GPIO_PIN_14;
  78. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  79. GPIO_InitStruct.Pull = GPIO_PULLUP;
  80. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  81. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  82. /*Configure GPIO pins : PB12 PB13 PB14 */
  83. GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13;
  84. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  85. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  86. GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
  87. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  88. GPIO_InitStruct.Pull = GPIO_PULLUP;
  89. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  90. }
  91. /* USER CODE BEGIN 2 */
  92. void init_gpio(uint8_t uav_type)
  93. {
  94. if(uav_type == 18)
  95. {
  96. GPIO_InitTypeDef GPIO_InitStruct = {0};
  97. GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  98. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  99. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  100. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  101. }
  102. }
  103. /* USER CODE END 2 */
  104. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/