From 54f65b430c1fc737ffdf9522f7d18344f1d44403 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Thu, 9 Oct 2014 12:46:13 +0200 Subject: [PATCH] Use second value in config field to select the timer control channel. --- drivers/timers.c | 6 +++--- include/drivers/timers.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/timers.c b/drivers/timers.c index ae9d621..c66cee2 100644 --- a/drivers/timers.c +++ b/drivers/timers.c @@ -200,14 +200,14 @@ int timer_setup(uint32_t timer_num, struct timer_config* conf) } break; case LPC_TIMER_MODE_PWM: - if (conf->match[3] == 0) { + if (conf->match[ conf->config[1] ] == 0) { return -EINVAL; /* Force use of Channel 3 for PWM cycle length */ } /* Activate selected PWM channels 0 to 2 */ timer->regs->pwm_ctrl = (conf->config[0] & 0x07); /* Use Channel 3 for PWM cycle length as recommended in the manual */ - timer->regs->match_ctrl &= ~(LPC_TIMER_MATCH_ERASE(3)); - timer->regs->match_ctrl |= (LPC_TIMER_RESET_ON_MATCH << LPC_TIMER_MATCH_SHIFT(3)); + timer->regs->match_ctrl &= ~(LPC_TIMER_MATCH_ERASE(conf->config[1])); + timer->regs->match_ctrl |= (LPC_TIMER_RESET_ON_MATCH << LPC_TIMER_MATCH_SHIFT(conf->config[1])); for (i = 0; i < NUM_CHANS; i++) { timer->regs->match_reg[i] = conf->match[i]; } diff --git a/include/drivers/timers.h b/include/drivers/timers.h index fcce461..51acf48 100644 --- a/include/drivers/timers.h +++ b/include/drivers/timers.h @@ -52,7 +52,8 @@ enum lpc_timer_mode { /* Structure used to pass parameters to configure a timer */ /* Notes: - * In counter or PWM mode, the config is done using config[0] + * In counter or PWM mode, the config is done using config[0] for enabled channels and config[1] holds + * the channel number used to control PWM cycle. * The field "reset_on_capture" must be set to LPC_COUNTER_CLEAR_ON_EVENT_EN ored with one * of the LPC_COUNTER_CLEAR_ON_CHAN*_* to activate the clear timer on event functionality */ -- 2.43.0