From aa7a43efce35fa41d57f9858ee41be0c33e84709 Mon Sep 17 00:00:00 2001 From: Perry Hung Date: Tue, 12 Oct 2010 20:58:48 -0400 Subject: Add selective enabling of channels for pwm channels pinMode(PWM) turns the channel on, other modes should turn it off Fixes bug with conflicting timer for spi1 and timer. This is not well-tested. Conflicts: libmaple/timers.c --- wirish/wirish_digital.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'wirish/wirish_digital.c') diff --git a/wirish/wirish_digital.c b/wirish/wirish_digital.c index f4868da..9298b60 100644 --- a/wirish/wirish_digital.c +++ b/wirish/wirish_digital.c @@ -31,6 +31,7 @@ void pinMode(uint8 pin, WiringPinMode mode) { uint8 outputMode; + uint32 pwm = 0; if (pin >= NR_GPIO_PINS) { return; @@ -58,9 +59,11 @@ void pinMode(uint8 pin, WiringPinMode mode) { break; case PWM: outputMode = GPIO_MODE_AF_OUTPUT_PP; + pwm = 1; break; case PWM_OPEN_DRAIN: outputMode = GPIO_MODE_AF_OUTPUT_OD; + pwm = 1; break; default: ASSERT(0); @@ -68,6 +71,19 @@ void pinMode(uint8 pin, WiringPinMode mode) { } gpio_set_mode(PIN_MAP[pin].port, PIN_MAP[pin].pin, outputMode); + + if (PIN_MAP[pin].timer_num != TIMER_INVALID) { + /* enable/disable timer channels if we're switching into or out of pwm */ + if (pwm) { + timer_set_mode(PIN_MAP[pin].timer_num, + PIN_MAP[pin].timer_chan, + TIMER_PWM); + } else { + timer_set_mode(PIN_MAP[pin].timer_num, + PIN_MAP[pin].timer_chan, + TIMER_DISABLED); + } + } } -- cgit v1.2.3