#ifndef __bsp_pwm_h__
#define __bsp_pwm_h__
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#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

#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 SetPwm_Channels(uint32_t channel_1, uint32_t channel_2, uint32_t channel_3, uint32_t channel_4);
//设置PWM的中断回调函数
void SetPwm_IRQ(nrfx_pwm_handler_t pwm_callback, uint8_t irq_priority);
//设置PWM的基础时钟
void SetPwm_BaseClock(nrf_pwm_clk_t clock);
//设置PWM的计数模式
void SetPwm_CountMode(nrf_pwm_mode_t count_mode);
//设置PWM的最大的占空比阈值
void SetPwm_DutyCycleThreshold(uint16_t Max_duty_cycle_value);
//设置PWM的序列的推进模式,定义下一个cycle的进行方式。
void SetPwm_SequenceStepMode(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 SetSimplePwmPlayBack(nrf_pwm_sequence_t *pwm_sequence, uint16_t playback_count, uint32_t flags);

#endif
