bsp_pwm.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef __bsp_pwm_h__
  2. #define __bsp_pwm_h__
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. #include <string.h>
  6. #include "sdk_common.h"
  7. #include "SEGGER_RTT.h"
  8. #include "usr_config.h"
  9. #include "nrf_drv_pwm.h"
  10. /**************************************
  11. DEFINECTION
  12. */
  13. #define PWM_SEQUENCE_VALUES_LEN(seq_values) NRF_PWM_VALUES_LENGTH(seq_values) //SEQUENCE_VALUES_LEN
  14. #define PWM_FLAG_STOP NRF_DRV_PWM_FLAG_STOP //PLAYBACK_MODE
  15. #define PWM_FLAG_LOOP NRF_DRV_PWM_FLAG_LOOP //PLAYBACK_MODE
  16. #define PWM_FLAG_SIGNAL_END_SEQ0 NRF_DRV_PWM_FLAG_SIGNAL_END_SEQ0 //PLAYBACK_MODE
  17. #define PWM_FLAG_SIGNAL_END_SEQ1 NRF_DRV_PWM_FLAG_SIGNAL_END_SEQ1 //PLAYBACK_MODE
  18. #define PWM_FLAG_NO_EVT_FINISHED NRF_DRV_PWM_FLAG_NO_EVT_FINISHED //PLAYBACK_MODE
  19. #define PWM_FLAG_START_VIA_TASK NRF_DRV_PWM_FLAG_START_VIA_TASK //PLAYBACK_MODE
  20. /**************************************
  21. STRUCTION
  22. */
  23. typedef struct
  24. {
  25. uint16_t channel_0; ///< Duty cycle value for channel 0.
  26. uint16_t channel_1; ///< Duty cycle value for channel 1.
  27. uint16_t channel_2; ///< Duty cycle value for channel 2.
  28. uint16_t channel_3; ///< Duty cycle value for channel 3.
  29. } pwm_values_individual_t;
  30. typedef uint16_t pwm_values_common_t;
  31. /**************************************
  32. API
  33. */
  34. //设置PWM的引脚通道
  35. void SetPwm_Channels(uint32_t channel_1, uint32_t channel_2, uint32_t channel_3, uint32_t channel_4);
  36. //设置PWM的中断回调函数
  37. void SetPwm_IRQ(nrfx_pwm_handler_t pwm_callback, uint8_t irq_priority);
  38. //设置PWM的基础时钟
  39. void SetPwm_BaseClock(nrf_pwm_clk_t clock);
  40. //设置PWM的计数模式
  41. void SetPwm_CountMode(nrf_pwm_mode_t count_mode);
  42. //设置PWM的最大的占空比阈值
  43. void SetPwm_DutyCycleThreshold(uint16_t Max_duty_cycle_value);
  44. //设置PWM的序列的推进模式,定义下一个cycle的进行方式。
  45. void SetPwm_SequenceStepMode(nrf_pwm_dec_step_t step_mode);
  46. //PWM 的初始化
  47. void Pwm_Initialize(void);
  48. //PWM 的未初始化
  49. void Pwm_UnInitialize(void);
  50. //设置一个独立通道序列
  51. nrf_pwm_sequence_t* Pwm_SetIndSequence(pwm_values_individual_t *p_seqValues, uint16_t seqValues_length, uint32_t seqValues_repeats, uint32_t seqValues_end_delay);
  52. //设置一个共用通道序列
  53. nrf_pwm_sequence_t* Pwm_SetComSequence(pwm_values_common_t *p_seqValues, uint16_t seqValues_length, uint32_t seqValues_repeats, uint32_t seqValues_end_delay);
  54. //设置PWM的指定单个序列的播放
  55. uint32_t SetSimplePwmPlayBack(nrf_pwm_sequence_t *pwm_sequence, uint16_t playback_count, uint32_t flags);
  56. /****************************************************************************************************************************************************************************/
  57. //设置PWM1的引脚通道
  58. void SetPwm1_Channels(uint32_t channel_1, uint32_t channel_2, uint32_t channel_3, uint32_t channel_4);
  59. //设置PWM1的中断回调函数
  60. void SetPwm1_IRQ(nrfx_pwm_handler_t pwm_callback, uint8_t irq_priority);
  61. //设置PWM1的基础时钟
  62. void SetPwm1_BaseClock(nrf_pwm_clk_t clock);
  63. //设置PWM1的计数模式
  64. void SetPwm1_CountMode(nrf_pwm_mode_t count_mode);
  65. //设置PWM1的最大的占空比阈值
  66. void SetPwm1_DutyCycleThreshold(uint16_t Max_duty_cycle_value);
  67. //设置PWM1的序列的推进模式,定义下一个cycle的进行方式。
  68. void SetPwm1_SequenceStepMode(nrf_pwm_dec_step_t step_mode);
  69. //PWM1 的初始化
  70. void Pwm1_Initialize(void);
  71. //PWM1 的未初始化
  72. void Pwm1_UnInitialize(void);
  73. //设置一个独立通道序列
  74. nrf_pwm_sequence_t* Pwm1_SetIndSequence(pwm_values_individual_t *p_seqValues, uint16_t seqValues_length, uint32_t seqValues_repeats, uint32_t seqValues_end_delay);
  75. //设置一个共用通道序列
  76. nrf_pwm_sequence_t* Pwm1_SetComSequence(pwm_values_common_t *p_seqValues, uint16_t seqValues_length, uint32_t seqValues_repeats, uint32_t seqValues_end_delay);
  77. //设置PWM1的指定单个序列的播放
  78. uint32_t SetSimplePwm1PlayBack(nrf_pwm_sequence_t *pwm_sequence, uint16_t playback_count, uint32_t flags);
  79. #endif