gpio.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 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_GPIOA_CLK_ENABLE();
  42. __HAL_RCC_GPIOB_CLK_ENABLE();
  43. __HAL_RCC_GPIOD_CLK_ENABLE();
  44. /*Configure GPIO pin Output Level */
  45. HAL_GPIO_WritePin(DISPLAY_DI_GPIO_Port, DISPLAY_DI_Pin, GPIO_PIN_RESET);
  46. /*Configure GPIO pin Output Level */
  47. HAL_GPIO_WritePin(GPIOC, NFC_CS_Pin|SD_CS_Pin, GPIO_PIN_SET);
  48. /*Configure GPIO pin Output Level */
  49. HAL_GPIO_WritePin(GPIOB, LED_BLUE_Pin|LED_GREEN_Pin, GPIO_PIN_SET);
  50. /*Configure GPIO pin Output Level */
  51. HAL_GPIO_WritePin(GPIOB, DISPLAY_RST_Pin|DISPLAY_BACKLIGHT_Pin, GPIO_PIN_RESET);
  52. /*Configure GPIO pin Output Level */
  53. HAL_GPIO_WritePin(GPIOC, VIBRO_Pin|DISPLAY_CS_Pin, GPIO_PIN_RESET);
  54. /*Configure GPIO pin Output Level */
  55. HAL_GPIO_WritePin(GPIOA, LED_RED_Pin|CC1101_CS_Pin, GPIO_PIN_SET);
  56. /*Configure GPIO pin : PtPin */
  57. GPIO_InitStruct.Pin = BUTTON_BACK_Pin;
  58. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
  59. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  60. HAL_GPIO_Init(BUTTON_BACK_GPIO_Port, &GPIO_InitStruct);
  61. /*Configure GPIO pins : PC0 PC1 */
  62. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
  63. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  64. GPIO_InitStruct.Pull = GPIO_NOPULL;
  65. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  66. /*Configure GPIO pin : PtPin */
  67. GPIO_InitStruct.Pin = CHRG_Pin;
  68. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
  69. GPIO_InitStruct.Pull = GPIO_PULLUP;
  70. HAL_GPIO_Init(CHRG_GPIO_Port, &GPIO_InitStruct);
  71. /*Configure GPIO pin : PtPin */
  72. GPIO_InitStruct.Pin = BUTTON_DOWN_Pin;
  73. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
  74. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  75. HAL_GPIO_Init(BUTTON_DOWN_GPIO_Port, &GPIO_InitStruct);
  76. /*Configure GPIO pins : PAPin PAPin */
  77. GPIO_InitStruct.Pin = DISPLAY_DI_Pin|CC1101_CS_Pin;
  78. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  79. GPIO_InitStruct.Pull = GPIO_NOPULL;
  80. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  81. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  82. /*Configure GPIO pins : PA4 PA5 PA6 PA7 */
  83. GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
  84. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  85. GPIO_InitStruct.Pull = GPIO_NOPULL;
  86. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  87. /*Configure GPIO pins : PCPin PCPin PCPin PCPin */
  88. GPIO_InitStruct.Pin = NFC_CS_Pin|VIBRO_Pin|DISPLAY_CS_Pin|SD_CS_Pin;
  89. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  90. GPIO_InitStruct.Pull = GPIO_NOPULL;
  91. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  92. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  93. /*Configure GPIO pins : PBPin PBPin PBPin PBPin */
  94. GPIO_InitStruct.Pin = BUTTON_UP_Pin|BUTTON_LEFT_Pin|BUTTON_RIGHT_Pin|BUTTON_OK_Pin;
  95. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
  96. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  97. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  98. /*Configure GPIO pins : PBPin PBPin */
  99. GPIO_InitStruct.Pin = LED_BLUE_Pin|LED_GREEN_Pin;
  100. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
  101. GPIO_InitStruct.Pull = GPIO_NOPULL;
  102. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
  103. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  104. /*Configure GPIO pins : PB2 PB12 */
  105. GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_12;
  106. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  107. GPIO_InitStruct.Pull = GPIO_NOPULL;
  108. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  109. /*Configure GPIO pins : PBPin PBPin */
  110. GPIO_InitStruct.Pin = DISPLAY_RST_Pin|DISPLAY_BACKLIGHT_Pin;
  111. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  112. GPIO_InitStruct.Pull = GPIO_NOPULL;
  113. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  114. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  115. /*Configure GPIO pin : PtPin */
  116. GPIO_InitStruct.Pin = RFID_PULL_Pin;
  117. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  118. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  119. HAL_GPIO_Init(RFID_PULL_GPIO_Port, &GPIO_InitStruct);
  120. /*Configure GPIO pin : PtPin */
  121. GPIO_InitStruct.Pin = LED_RED_Pin;
  122. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
  123. GPIO_InitStruct.Pull = GPIO_NOPULL;
  124. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  125. HAL_GPIO_Init(LED_RED_GPIO_Port, &GPIO_InitStruct);
  126. /*Configure GPIO pin : PD2 */
  127. GPIO_InitStruct.Pin = GPIO_PIN_2;
  128. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  129. GPIO_InitStruct.Pull = GPIO_NOPULL;
  130. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  131. /*Configure GPIO pin : PtPin */
  132. GPIO_InitStruct.Pin = CC1101_G0_Pin;
  133. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  134. GPIO_InitStruct.Pull = GPIO_NOPULL;
  135. HAL_GPIO_Init(CC1101_G0_GPIO_Port, &GPIO_InitStruct);
  136. /* EXTI interrupt init*/
  137. HAL_NVIC_SetPriority(EXTI0_IRQn, 5, 0);
  138. HAL_NVIC_EnableIRQ(EXTI0_IRQn);
  139. HAL_NVIC_SetPriority(EXTI1_IRQn, 5, 0);
  140. HAL_NVIC_EnableIRQ(EXTI1_IRQn);
  141. HAL_NVIC_SetPriority(EXTI2_IRQn, 5, 0);
  142. HAL_NVIC_EnableIRQ(EXTI2_IRQn);
  143. HAL_NVIC_SetPriority(EXTI4_IRQn, 5, 0);
  144. HAL_NVIC_EnableIRQ(EXTI4_IRQn);
  145. HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0);
  146. HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
  147. HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
  148. HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
  149. }
  150. /* USER CODE BEGIN 2 */
  151. /* USER CODE END 2 */
  152. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/