mc_hall_gpio.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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_FOC_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. #define HALL1 READ_HALL1()
  39. #define HALL2 READ_HALL2()
  40. #define HALL3 READ_HALL3()
  41. typedef struct _hall_io {
  42. u8 hall[3];
  43. u32 hall_time;
  44. u8 is_edged;
  45. }hall_io_t;
  46. void mc_hall_init(void);
  47. int get_hall_stat(int samples);
  48. u32 hall_get_hwcount(u8 *hall);
  49. #endif /*_MC_HALL_H__ */