hal_gpio.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "hal_gpio.h"
  2. void hal_beep_init(void)
  3. {
  4. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
  5. GPIO_InitTypeDef GPIO_StructInit;
  6. GPIO_StructInit.GPIO_Mode = GPIO_Mode_OUT;
  7. GPIO_StructInit.GPIO_OType = GPIO_OType_PP;
  8. GPIO_StructInit.GPIO_Speed = GPIO_Speed_100MHz;
  9. GPIO_StructInit.GPIO_PuPd = GPIO_PuPd_UP;
  10. GPIO_StructInit.GPIO_Pin = HAL_GPIO_BEEP_PIN;
  11. GPIO_Init(HAL_GPIO_BEEP_PORT, &GPIO_StructInit);
  12. }
  13. void hal_led_init(void)
  14. {
  15. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
  16. GPIO_InitTypeDef GPIO_StructInit;
  17. GPIO_StructInit.GPIO_Mode = GPIO_Mode_OUT;
  18. GPIO_StructInit.GPIO_OType = GPIO_OType_PP;
  19. GPIO_StructInit.GPIO_Speed = GPIO_Speed_100MHz;
  20. GPIO_StructInit.GPIO_PuPd = GPIO_PuPd_UP;
  21. GPIO_StructInit.GPIO_Pin = HAL_GPIO_LED1_PIN;
  22. GPIO_Init(HAL_GPIO_LED1_PORT, &GPIO_StructInit);
  23. }
  24. void hal_key_init(void)
  25. {
  26. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  27. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
  28. GPIO_InitTypeDef GPIO_StructInit;
  29. GPIO_StructInit.GPIO_Mode = GPIO_Mode_IN;
  30. GPIO_StructInit.GPIO_OType = GPIO_OType_PP;
  31. GPIO_StructInit.GPIO_Speed = GPIO_Speed_100MHz;
  32. GPIO_StructInit.GPIO_PuPd = GPIO_PuPd_UP;
  33. GPIO_StructInit.GPIO_Pin = HAL_GPIO_KEY0_PIN | HAL_GPIO_KEY1_PIN | HAL_GPIO_KEY2_PIN;
  34. GPIO_Init(HAL_GPIO_KEY0_PORT, &GPIO_StructInit);
  35. GPIO_StructInit.GPIO_PuPd = GPIO_PuPd_DOWN;
  36. GPIO_StructInit.GPIO_Pin = HAL_GPIO_KEY_UP_PIN;
  37. GPIO_Init(HAL_GPIO_KEY_UP_PORT, &GPIO_StructInit);
  38. }
  39. void hal_gpio_init(void)
  40. {
  41. hal_led_init();
  42. hal_key_init();
  43. hal_beep_init();
  44. }