gpio.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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) 2021 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, RFID_PULL_Pin|RFID_TUNE_Pin|VIBRO_Pin, GPIO_PIN_RESET);
  47. /*Configure GPIO pin Output Level */
  48. HAL_GPIO_WritePin(PERIPH_POWER_GPIO_Port, PERIPH_POWER_Pin, GPIO_PIN_SET);
  49. /*Configure GPIO pin Output Level */
  50. HAL_GPIO_WritePin(RF_SW_0_GPIO_Port, RF_SW_0_Pin, GPIO_PIN_RESET);
  51. /*Configure GPIO pin Output Level */
  52. HAL_GPIO_WritePin(GPIOB, DISPLAY_RST_Pin|DISPLAY_DI_Pin, GPIO_PIN_RESET);
  53. /*Configure GPIO pin Output Level */
  54. HAL_GPIO_WritePin(NFC_CS_GPIO_Port, NFC_CS_Pin, GPIO_PIN_SET);
  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 */
  70. GPIO_InitStruct.Pin = PC0_Pin|PC1_Pin|PC3_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 PAPin */
  75. GPIO_InitStruct.Pin = CC1101_G0_Pin|PA4_Pin|PA6_Pin|PA7_Pin;
  76. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  77. GPIO_InitStruct.Pull = GPIO_NOPULL;
  78. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  79. /*Configure GPIO pins : PAPin PAPin PAPin */
  80. GPIO_InitStruct.Pin = RFID_PULL_Pin|RFID_TUNE_Pin|VIBRO_Pin;
  81. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  82. GPIO_InitStruct.Pull = GPIO_NOPULL;
  83. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  84. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  85. /*Configure GPIO pin : PtPin */
  86. GPIO_InitStruct.Pin = PERIPH_POWER_Pin;
  87. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
  88. GPIO_InitStruct.Pull = GPIO_NOPULL;
  89. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  90. HAL_GPIO_Init(PERIPH_POWER_GPIO_Port, &GPIO_InitStruct);
  91. /*Configure GPIO pins : PCPin PCPin */
  92. GPIO_InitStruct.Pin = RF_SW_0_Pin|DISPLAY_CS_Pin;
  93. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  94. GPIO_InitStruct.Pull = GPIO_NOPULL;
  95. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  96. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  97. /*Configure GPIO pins : PBPin PBPin PBPin */
  98. GPIO_InitStruct.Pin = PB2_Pin|iBTN_Pin|PB3_Pin;
  99. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  100. GPIO_InitStruct.Pull = GPIO_NOPULL;
  101. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  102. /*Configure GPIO pins : PBPin PBPin PBPin */
  103. GPIO_InitStruct.Pin = BUTTON_UP_Pin|BUTTON_LEFT_Pin|BUTTON_RIGHT_Pin;
  104. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
  105. GPIO_InitStruct.Pull = GPIO_PULLUP;
  106. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  107. /*Configure GPIO pins : PBPin PBPin */
  108. GPIO_InitStruct.Pin = DISPLAY_RST_Pin|DISPLAY_DI_Pin;
  109. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  110. GPIO_InitStruct.Pull = GPIO_NOPULL;
  111. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  112. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  113. /*Configure GPIO pin : PtPin */
  114. GPIO_InitStruct.Pin = NFC_CS_Pin;
  115. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  116. GPIO_InitStruct.Pull = GPIO_NOPULL;
  117. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  118. HAL_GPIO_Init(NFC_CS_GPIO_Port, &GPIO_InitStruct);
  119. /*Configure GPIO pins : PCPin PCPin */
  120. GPIO_InitStruct.Pin = BUTTON_DOWN_Pin|SD_CD_Pin;
  121. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  122. GPIO_InitStruct.Pull = GPIO_NOPULL;
  123. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  124. /*Configure GPIO pin : PtPin */
  125. GPIO_InitStruct.Pin = SD_CS_Pin;
  126. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  127. GPIO_InitStruct.Pull = GPIO_NOPULL;
  128. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  129. HAL_GPIO_Init(SD_CS_GPIO_Port, &GPIO_InitStruct);
  130. /*Configure GPIO pin : PtPin */
  131. GPIO_InitStruct.Pin = CC1101_CS_Pin;
  132. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  133. GPIO_InitStruct.Pull = GPIO_NOPULL;
  134. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  135. HAL_GPIO_Init(CC1101_CS_GPIO_Port, &GPIO_InitStruct);
  136. /* EXTI interrupt init*/
  137. HAL_NVIC_SetPriority(EXTI3_IRQn, 5, 0);
  138. HAL_NVIC_EnableIRQ(EXTI3_IRQn);
  139. HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
  140. HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
  141. }
  142. /* USER CODE BEGIN 2 */
  143. /* USER CODE END 2 */
  144. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/