diff options
author | Perry Hung <iperry@gmail.com> | 2010-10-12 20:58:48 -0400 |
---|---|---|
committer | Perry Hung <iperry@gmail.com> | 2010-10-12 20:59:46 -0400 |
commit | aa7a43efce35fa41d57f9858ee41be0c33e84709 (patch) | |
tree | d1ed6a43df75776dd35ee1ca8513bc5f7be47ce2 /wirish/wirish_digital.c | |
parent | fccf017f3a5aa7182080c1ed062ab46773a8f34a (diff) | |
download | librambutan-aa7a43efce35fa41d57f9858ee41be0c33e84709.tar.gz librambutan-aa7a43efce35fa41d57f9858ee41be0c33e84709.zip |
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
Diffstat (limited to 'wirish/wirish_digital.c')
-rw-r--r-- | wirish/wirish_digital.c | 16 |
1 files changed, 16 insertions, 0 deletions
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); + } + } } |