drv_pwm.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef __drv_pwm_h__
  2. #define __drv_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 (sizeof(array) / sizeof(uint16_t))
  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 PWM_SetChannels(uint32_t channel_1, uint32_t channel_2, uint32_t channel_3, uint32_t channel_4);
  36. //设置PWM的中断回调函数
  37. void PWM_SetIRQ(nrfx_pwm_handler_t pwm_callback, uint8_t irq_priority);
  38. //设置PWM的基础时钟
  39. void PWM_SetBaseClock(nrf_pwm_clk_t clock);
  40. //设置PWM的计数模式
  41. void PWM_SetCountMode(nrf_pwm_mode_t count_mode);
  42. //设置PWM的最大的占空比阈值
  43. void PWM_SetDutyCycleThreshold(uint16_t Max_duty_cycle_value);
  44. //设置PWM的序列的推进模式,定义下一个cycle的进行方式。
  45. void PWM_SetSequenceStepMode(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 PWM_SetSimplePwmPlayBack(nrf_pwm_sequence_t *pwm_sequence, uint16_t playback_count, uint32_t flags);
  56. #endif