From 13f57feaefac015c2d14d4b5f08e5c365c3b6e67 Mon Sep 17 00:00:00 2001 From: talorion Date: Tue, 25 Aug 2020 23:41:34 +0200 Subject: [PATCH] pwmout - GD32F4XX - add read methods for period and pulsewidth --- .../TARGET_GD32F4XX/pwmout_api.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/targets/TARGET_GigaDevice/TARGET_GD32F4XX/pwmout_api.c b/targets/TARGET_GigaDevice/TARGET_GD32F4XX/pwmout_api.c index d23d2daa3a..45d5eed670 100644 --- a/targets/TARGET_GigaDevice/TARGET_GD32F4XX/pwmout_api.c +++ b/targets/TARGET_GigaDevice/TARGET_GD32F4XX/pwmout_api.c @@ -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;