gpio.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /**
  2. ******************************************************************************
  3. * @file gpio.c
  4. * @brief 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 Ultimate Liberty license
  13. * SLA0044, the "License"; You may not use this file except in compliance with
  14. * the License. You may obtain a copy of the License at:
  15. * www.st.com/SLA0044
  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. */
  35. void MX_GPIO_Init(void)
  36. {
  37. GPIO_InitTypeDef GPIO_InitStruct = {0};
  38. /* GPIO Ports Clock Enable */
  39. __HAL_RCC_GPIOC_CLK_ENABLE();
  40. __HAL_RCC_GPIOH_CLK_ENABLE();
  41. __HAL_RCC_GPIOB_CLK_ENABLE();
  42. __HAL_RCC_GPIOA_CLK_ENABLE();
  43. __HAL_RCC_GPIOE_CLK_ENABLE();
  44. __HAL_RCC_GPIOD_CLK_ENABLE();
  45. /*Configure GPIO pin Output Level */
  46. HAL_GPIO_WritePin(GPIOA, LED_RED_Pin|LED_GREEN_Pin|LED_BLUE_Pin, GPIO_PIN_SET);
  47. /*Configure GPIO pin Output Level */
  48. HAL_GPIO_WritePin(DISPLAY_RST_GPIO_Port, DISPLAY_RST_Pin, GPIO_PIN_RESET);
  49. /*Configure GPIO pin Output Level */
  50. HAL_GPIO_WritePin(NFC_CS_GPIO_Port, NFC_CS_Pin, GPIO_PIN_SET);
  51. /*Configure GPIO pin Output Level */
  52. HAL_GPIO_WritePin(DISPLAY_DI_GPIO_Port, DISPLAY_DI_Pin, GPIO_PIN_RESET);
  53. /*Configure GPIO pin Output Level */
  54. HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin, GPIO_PIN_RESET);
  55. /*Configure GPIO pin Output Level */
  56. HAL_GPIO_WritePin(GPIOC, DISPLAY_CS_Pin|SD_CS_Pin, GPIO_PIN_SET);
  57. /*Configure GPIO pin Output Level */
  58. HAL_GPIO_WritePin(CC1101_CS_GPIO_Port, CC1101_CS_Pin, GPIO_PIN_SET);
  59. /*Configure GPIO pin : PtPin */
  60. GPIO_InitStruct.Pin = BUTTON_BACK_Pin;
  61. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
  62. GPIO_InitStruct.Pull = GPIO_PULLUP;
  63. HAL_GPIO_Init(BUTTON_BACK_GPIO_Port, &GPIO_InitStruct);
  64. /*Configure GPIO pin : PtPin */
  65. GPIO_InitStruct.Pin = BUTTON_OK_Pin;
  66. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
  67. GPIO_InitStruct.Pull = GPIO_NOPULL;
  68. HAL_GPIO_Init(BUTTON_OK_GPIO_Port, &GPIO_InitStruct);
  69. /*Configure GPIO pins : PCPin PCPin PCPin PCPin */
  70. GPIO_InitStruct.Pin = PC0_Pin|PC1_Pin|PC3_Pin|PC10_Pin;
  71. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  72. GPIO_InitStruct.Pull = GPIO_NOPULL;
  73. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  74. /*Configure GPIO pins : PAPin PAPin PAPin */
  75. GPIO_InitStruct.Pin = LED_RED_Pin|LED_GREEN_Pin|LED_BLUE_Pin;
  76. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
  77. GPIO_InitStruct.Pull = GPIO_NOPULL;
  78. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  79. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  80. /*Configure GPIO pins : PAPin PAPin PAPin */
  81. GPIO_InitStruct.Pin = PA4_Pin|PA6_Pin|PA7_Pin;
  82. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  83. GPIO_InitStruct.Pull = GPIO_NOPULL;
  84. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  85. /*Configure GPIO pin : PtPin */
  86. GPIO_InitStruct.Pin = RFID_PULL_Pin;
  87. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  88. GPIO_InitStruct.Pull = GPIO_NOPULL;
  89. HAL_GPIO_Init(RFID_PULL_GPIO_Port, &GPIO_InitStruct);
  90. /*Configure GPIO pin : PtPin */
  91. GPIO_InitStruct.Pin = CC1101_G0_Pin;
  92. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
  93. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  94. HAL_GPIO_Init(CC1101_G0_GPIO_Port, &GPIO_InitStruct);
  95. /*Configure GPIO pins : PBPin PBPin PBPin */
  96. GPIO_InitStruct.Pin = PB2_Pin|iBTN_Pin|PB3_Pin;
  97. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  98. GPIO_InitStruct.Pull = GPIO_NOPULL;
  99. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  100. /*Configure GPIO pins : PBPin PBPin PBPin PBPin */
  101. GPIO_InitStruct.Pin = BUTTON_UP_Pin|BUTTON_LEFT_Pin|BUTTON_DOWN_Pin|BUTTON_RIGHT_Pin;
  102. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
  103. GPIO_InitStruct.Pull = GPIO_PULLUP;
  104. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  105. /*Configure GPIO pin : PtPin */
  106. GPIO_InitStruct.Pin = DISPLAY_RST_Pin;
  107. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  108. GPIO_InitStruct.Pull = GPIO_NOPULL;
  109. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  110. HAL_GPIO_Init(DISPLAY_RST_GPIO_Port, &GPIO_InitStruct);
  111. /*Configure GPIO pin : PtPin */
  112. GPIO_InitStruct.Pin = NFC_CS_Pin;
  113. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  114. GPIO_InitStruct.Pull = GPIO_NOPULL;
  115. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  116. HAL_GPIO_Init(NFC_CS_GPIO_Port, &GPIO_InitStruct);
  117. /*Configure GPIO pins : PCPin PCPin */
  118. GPIO_InitStruct.Pin = DISPLAY_DI_Pin|DISPLAY_CS_Pin;
  119. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  120. GPIO_InitStruct.Pull = GPIO_NOPULL;
  121. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  122. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  123. /*Configure GPIO pin : PtPin */
  124. GPIO_InitStruct.Pin = DISPLAY_BACKLIGHT_Pin;
  125. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  126. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  127. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  128. HAL_GPIO_Init(DISPLAY_BACKLIGHT_GPIO_Port, &GPIO_InitStruct);
  129. /*Configure GPIO pin : PtPin */
  130. GPIO_InitStruct.Pin = SD_CS_Pin;
  131. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  132. GPIO_InitStruct.Pull = GPIO_NOPULL;
  133. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  134. HAL_GPIO_Init(SD_CS_GPIO_Port, &GPIO_InitStruct);
  135. /*Configure GPIO pin : PtPin */
  136. GPIO_InitStruct.Pin = CC1101_CS_Pin;
  137. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  138. GPIO_InitStruct.Pull = GPIO_NOPULL;
  139. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  140. HAL_GPIO_Init(CC1101_CS_GPIO_Port, &GPIO_InitStruct);
  141. /* EXTI interrupt init*/
  142. HAL_NVIC_SetPriority(EXTI1_IRQn, 5, 0);
  143. HAL_NVIC_EnableIRQ(EXTI1_IRQn);
  144. HAL_NVIC_SetPriority(EXTI3_IRQn, 5, 0);
  145. HAL_NVIC_EnableIRQ(EXTI3_IRQn);
  146. HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0);
  147. HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
  148. HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
  149. HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
  150. }
  151. /* USER CODE BEGIN 2 */
  152. /* USER CODE END 2 */
  153. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/