pwmout - GD32F4XX - add read methods for period and pulsewidth

pull/13492/head
talorion 2020-08-25 23:41:34 +02:00 committed by Gregor Mayramhof
parent a67e8d1c07
commit 13f57feaef
1 changed files with 33 additions and 0 deletions

View File

@ -194,6 +194,11 @@ void pwmout_period_us(pwmout_t *obj, int us)
timer_enable(obj->pwm);
}
int pwmout_read_period_us(pwmout_t *obj)
{
return TIMER_CAR(obj->pwm);
}
/** Set the PWM pulsewidth specified in seconds, keeping the period the same.
*
* @param obj The pwmout object
@ -234,6 +239,34 @@ void pwmout_pulsewidth_us(pwmout_t *obj, int us)
timer_channel_output_pulse_value_config(obj->pwm, obj->ch, pulse);
}
int pwmout_read_pulsewidth_us(pwmout_t *obj)
{
uint16_t pulse = 0;
switch (obj->ch) {
case TIMER_CH_0:
pulse = TIMER_CH0CV(obj->pwm);
break;
case TIMER_CH_1:
pulse = TIMER_CH1CV(obj->pwm);
break;
case TIMER_CH_2:
pulse = TIMER_CH2CV(obj->pwm);
break;
case TIMER_CH_3:
pulse = TIMER_CH3CV(obj->pwm);
break;
default:
error("Error: pwm channel error! \r\n");
}
return pulse;
}
static uint32_t timer_get_clock(uint32_t timer_periph)
{
uint32_t timerclk;