SYS:
在工程开头,用于初始化时钟和初始化自动配置的GPIO
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr); //初始化IO
定时器:
//定时器初始化
void TIMER_Init(void)
{
ftm_state_t ftmStateStruct;//建立定时器结构体
FTM_DRV_Init(INST_FLEXTIMER_MC1, &flexTimer_mc1_InitConfig,&ftmStateStruct);//定时器初始化
//参数1:中断类型;参数2:中断函数;参数3:中断函数的参数,用不到使用(isr_t*)0U
INT_SYS_InstallHandler(FTM0_Ovf_Reload_IRQn,&ftmTimerISR,(isr_t*)0U);//定时器中断初始化
INT_SYS_EnableIRQ(FTM0_Ovf_Reload_IRQn);//使能定时器中断
FTM_DRV_InitCounter(INST_FLEXTIMER_MC1, &flexTimer_mc1_TimerConfig);//初始化计数器
FTM_DRV_CounterStart(INST_FLEXTIMER_MC1);//启动计数器
}
PWM:
void PWM_Init(void){
ftm_state_t ftmpwmStateStruct;//建立定时器结构体
FTM_DRV_Init(INST_FLEXTIMER_PWM1, &flexTimer_pwm1_InitConfig,&ftmpwmStateStruct);
FTM_DRV_InitPwm(INST_FLEXTIMER_PWM1, &flexTimer_pwm1_PwmConfig);
}
//PWM设置
void PWM_Set(uint32_t instance,uint8_t channel,uint32_t duty){
FTM_DRV_UpdatePwmChannel(instance, channel , FTM_PWM_UPDATE_IN_TICKS, duty, 0U, true);//MAX4000
}
ADC:
uint16_t adcRawValue=0;
void adc_Init(void){
ADC_DRV_ConfigConverter(INST_ADCONV1, &adConv1_ConvConfig0);//ADC初始化
ADC_DRV_AutoCalibration(INST_ADCONV1);//自校准
}
void adc_get_value(void){
ADC_DRV_ConfigChan(INST_ADCONV1, 0U, &adConv1_ChnConfig0);//选择通道
ADC_DRV_WaitConvDone(INST_ADCONV1);//等待转换
ADC_DRV_GetChanResult(INST_ADCONV1, 0U, &adcRawValue);//获得值
}
EXTI:
void PTB_EXT_IRQ(void){
uint32_t flag=(PINS_DRV_GetPortIntFlag(PORTB) >>2)&0x1; //获得PTB2的中断标志
if(flag){
}
PINS_DRV_ClearPortIntFlagCmd(PORTB);//清除标志
}
void EXTI_Init(void){
PINS_DRV_SetPinIntSel(PORTB,2,PORT_INT_RISING_EDGE); //上升沿触发
INT_SYS_InstallHandler(PORTB_IRQn,&PTB_EXT_IRQ,NULL);//初始化EXTI
INT_SYS_EnableIRQ(PORTB_IRQn);//使能EXTI
}
GPIO置位:
#define LED0_toggle PINS_DRV_TogglePins(PTD, 1 << 0)
#define LED1_toggle PINS_DRV_TogglePins(PTD, 1 << 1)
#define LED2_toggle PINS_DRV_TogglePins(PTD, 1 << 15)
#define LED3_toggle PINS_DRV_TogglePins(PTD, 1 << 16)