#ifndef __drv_pwm_h__ #define __drv_pwm_h__ #include #include #include #include "sdk_common.h" #include "SEGGER_RTT.h" #include "usr_config.h" #include "nrf_drv_pwm.h" /************************************** DEFINECTION */ #define PWM_SEQUENCE_VALUES_LEN(seq_values) NRF_PWM_VALUES_LENGTH(seq_values) //SEQUENCE_VALUES_LEN (sizeof(array) / sizeof(uint16_t)) #define PWM_FLAG_STOP NRF_DRV_PWM_FLAG_STOP //PLAYBACK_MODE #define PWM_FLAG_LOOP NRF_DRV_PWM_FLAG_LOOP //PLAYBACK_MODE #define PWM_FLAG_SIGNAL_END_SEQ0 NRF_DRV_PWM_FLAG_SIGNAL_END_SEQ0 //PLAYBACK_MODE #define PWM_FLAG_SIGNAL_END_SEQ1 NRF_DRV_PWM_FLAG_SIGNAL_END_SEQ1 //PLAYBACK_MODE #define PWM_FLAG_NO_EVT_FINISHED NRF_DRV_PWM_FLAG_NO_EVT_FINISHED //PLAYBACK_MODE #define PWM_FLAG_START_VIA_TASK NRF_DRV_PWM_FLAG_START_VIA_TASK //PLAYBACK_MODE /************************************** STRUCTION */ typedef struct { uint16_t channel_0; ///< Duty cycle value for channel 0. uint16_t channel_1; ///< Duty cycle value for channel 1. uint16_t channel_2; ///< Duty cycle value for channel 2. uint16_t channel_3; ///< Duty cycle value for channel 3. } pwm_values_individual_t; typedef uint16_t pwm_values_common_t; /************************************** API */ //设置PWM的引脚通道 void PWM_SetChannels(uint32_t channel_1, uint32_t channel_2, uint32_t channel_3, uint32_t channel_4); //设置PWM的中断回调函数 void PWM_SetIRQ(nrfx_pwm_handler_t pwm_callback, uint8_t irq_priority); //设置PWM的基础时钟 void PWM_SetBaseClock(nrf_pwm_clk_t clock); //设置PWM的计数模式 void PWM_SetCountMode(nrf_pwm_mode_t count_mode); //设置PWM的最大的占空比阈值 void PWM_SetDutyCycleThreshold(uint16_t Max_duty_cycle_value); //设置PWM的序列的推进模式,定义下一个cycle的进行方式。 void PWM_SetSequenceStepMode(nrf_pwm_dec_step_t step_mode); //PWM 的初始化 void PWM_Initialize(void); //PWM 的未初始化 void PWM_UnInitialize(void); //设置一个独立通道序列 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); //设置一个共用通道序列 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); //设置PWM的指定单个序列的播放 uint32_t PWM_SetSimplePwmPlayBack(nrf_pwm_sequence_t *pwm_sequence, uint16_t playback_count, uint32_t flags); #endif