mc_hall_gpio.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef _MC_HALL_H__
  2. #define _MC_HALL_H__
  3. #include "bsp/bsp.h"
  4. //51ms, 77.6
  5. //52.2ms
  6. //25.2
  7. #ifdef GD32_DEMO
  8. #define HALL_GPOI_CLK RCU_GPIOB
  9. #define HALL_1_PIN GPIO_PIN_6
  10. #define HALL_1_GROUP GPIOA
  11. #define HALL_2_PIN GPIO_PIN_7
  12. #define HALL_2_GROUP GPIOA
  13. #define HALL_3_PIN GPIO_PIN_0
  14. #define HALL_3_GROUP GPIOB
  15. #else
  16. #define HALL_GPOI_CLK RCU_GPIOB
  17. #define HALL_1_PIN GPIO_PIN_8
  18. #define HALL_1_GROUP GPIOB
  19. #define HALL_2_PIN GPIO_PIN_7
  20. #define HALL_2_GROUP GPIOB
  21. #define HALL_3_PIN GPIO_PIN_6
  22. #define HALL_3_GROUP GPIOB
  23. #endif
  24. #define DEGREES_120 0u
  25. #define DEGREES_60 1u
  26. #define HALL_PLACE DEGREES_120
  27. static int __inline__ hall_bit_get(uint32_t gpio_periph,uint32_t pin)
  28. {
  29. if((uint32_t)RESET != (GPIO_ISTAT(gpio_periph)&(pin))){
  30. return 1;
  31. }else{
  32. return 0;
  33. }
  34. }
  35. #define READ_HALL1() (hall_bit_get(HALL_1_GROUP, HALL_1_PIN))
  36. #define READ_HALL2() (hall_bit_get(HALL_2_GROUP, HALL_2_PIN))
  37. #define READ_HALL3() (hall_bit_get(HALL_3_GROUP, HALL_3_PIN))
  38. void mc_hall_init(void);
  39. int get_hall_stat(int samples);
  40. #endif /*_MC_HALL_H__ */