dshot.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #ifndef __DSHOT_H
  2. #define __DSHOT_H
  3. #include "stm32f4xx.h"
  4. #define ESC_CMD_BUFFER_LEN 18
  5. #define ESC_BIT_0 26
  6. #define ESC_BIT_1 52
  7. #define PWM3_PORT GPIOB
  8. #define PWM3_PIN GPIO_Pin_6
  9. #define PWM3_PinSource GPIO_PinSource6
  10. #define PWM3_GPIO_AF GPIO_AF_TIM4
  11. #define PWM4_PORT GPIOA
  12. #define PWM4_PIN GPIO_Pin_7
  13. #define PWM4_PinSource GPIO_PinSource7
  14. #define PWM4_GPIO_AF GPIO_AF_TIM3
  15. #define PWM5_PORT GPIOB
  16. #define PWM5_PIN GPIO_Pin_4
  17. #define PWM5_PinSource GPIO_PinSource4
  18. #define PWM5_GPIO_AF GPIO_AF_TIM3
  19. #define PWM6_PORT GPIOB
  20. #define PWM6_PIN GPIO_Pin_0
  21. #define PWM6_PinSource GPIO_PinSource0
  22. #define PWM6_GPIO_AF GPIO_AF_TIM3
  23. #define PWM7_PORT GPIOB
  24. #define PWM7_PIN GPIO_Pin_7
  25. #define PWM7_PinSource GPIO_PinSource7
  26. #define PWM7_GPIO_AF GPIO_AF_TIM4
  27. #define PWM8_PORT GPIOA
  28. #define PWM8_PIN GPIO_Pin_5
  29. #define PWM8_PinSource GPIO_PinSource5
  30. #define PWM8_GPIO_AF GPIO_AF_TIM2
  31. void pwmWriteDigital(u32 *esc_cmd, u16 value, DMA_Stream_TypeDef *DMA_Streamx);
  32. //void Dshot_GPIO_Config(u32 RCC_APBnPeriphn, GPIO_TypeDef *GPIOx,u16 PIN ,u8 GPIO_AF, u8 GPIO_PinSource);
  33. void Dshot_GPIO_Config(u32 RCC_APBnPeriphn, GPIO_TypeDef *GPIOx,u16 PIN, u8 GPIO_PinSource, u8 GPIO_AF);
  34. void DSHOT_DMA_Config(TIM_TypeDef* TIMx,uint16_t TIM_DMASource, DMA_Stream_TypeDef *DMA_Streamx,u32 chx,u32 par,u32 mar);
  35. void Dshot_NVIC_Config(u8 NVIC_IRQChannel, u8 pre, u8 sub);
  36. void Dshot_TIM_Config(void(*ClockCMD)(uint32_t, FunctionalState),u32 RCC_APBnPeriphn, //APB时钟使能设置
  37. TIM_TypeDef* TIMx, u16 psc, u16 per, //dshot频率设置
  38. void(*TIM_OCInit)(TIM_TypeDef*, TIM_OCInitTypeDef*), //OC通道设置
  39. void(*TIM_OCPreloadConfig)(TIM_TypeDef*, uint16_t)); //OC通道使能
  40. #endif
  41. //#define PWM1_PORT GPIOB
  42. //#define PWM1_PIN GPIO_Pin_6
  43. //#define PWM1_PinSource GPIO_PinSource6
  44. //#define PWM1_TIM TIM4
  45. //#define PWM1_GPIO_AF GPIO_AF_TIM4
  46. //#define PWM1_ClockCmd() RCC_AHB1PeriphClockCmd(RCC_APB1Periph_TIM4|RCC_AHB1Periph_GPIOB, ENABLE)
  47. //#define PWM1_OCInit(x) {TIM_OC1Init(PWM1_TIM, &TIM_OCInitStructure);TIM_OC1PreloadConfig(PWM1_TIM, TIM_OCPreload_Enable);}
  48. //#define PWM1_DMA_Stream DMA1_Stream0
  49. //#define PWM1_DMA_Stream_IRQn DMA1_Stream0_IRQn
  50. //#define PWM2_PORT GPIOB
  51. //#define PWM2_PIN GPIO_Pin_7
  52. //#define PWM2_PinSource GPIO_PinSource7
  53. //#define PWM2_TIM TIM4
  54. //#define PWM2_GPIO_AF GPIO_AF_TIM4
  55. //#define PWM2_ClockCmd() RCC_AHB1PeriphClockCmd(RCC_APB1Periph_TIM4|RCC_AHB1Periph_GPIOB, ENABLE)
  56. //#define PWM2_OCInit(x) {TIM_OC2Init(PWM2_TIM, &TIM_OCInitStructure);TIM_OC2PreloadConfig(PWM2_TIM, TIM_OCPreload_Enable);}
  57. //#define PWM2_DMA_Stream DMA1_Stream3
  58. //#define PWM2_DMA_Stream_IRQn DMA1_Stream3_IRQn
  59. //#define PWM3_PORT GPIOA
  60. //#define PWM3_PIN GPIO_Pin_7
  61. //#define PWM3_PinSource GPIO_PinSource7
  62. //#define PWM3_TIM TIM3
  63. //#define PWM3_GPIO_AF GPIO_AF_TIM3
  64. //#define PWM3_ClockCmd() RCC_AHB1PeriphClockCmd(RCC_APB1Periph_TIM3|RCC_AHB1Periph_GPIOA, ENABLE)
  65. //#define PWM3_OCInit(x) {TIM_OC2Init(PWM1_TIM, &TIM_OCInitStructure);TIM_OC2PreloadConfig(PWM3_TIM, TIM_OCPreload_Enable);}
  66. //#define PWM3_DMA_Stream DMA1_Stream5
  67. //#define PWM3_DMA_Stream_IRQn DMA1_Stream5_IRQn
  68. //#define PWM4_PORT GPIOA
  69. //#define PWM4_PIN GPIO_Pin_5
  70. //#define PWM4_PinSource GPIO_PinSource5
  71. //#define PWM4_TIM TIM2
  72. //#define PWM4_GPIO_AF GPIO_AF_TIM2
  73. //#define PWM4_ClockCmd() RCC_AHB1PeriphClockCmd(RCC_APB1Periph_TIM2|RCC_AHB1Periph_GPIOA, ENABLE)
  74. //#define PWM4_OCInit(x) {TIM_OC1Init(PWM4_TIM, &TIM_OCInitStructure);TIM_OC1PreloadConfig(PWM4_TIM, TIM_OCPreload_Enable);}
  75. //#define PWM4_DMA_Stream DMA1_Stream5
  76. //#define PWM4_DMA_Stream_IRQn DMA1_Stream5_IRQn