From 7943836c4a967e70ced14a2f4accf21a0469b238 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Sat, 2 Jun 2012 21:15:17 -0400 Subject: Bring back/tweak pwmWrite(). Works on F1, doesn't on F2. Will figure that out next. Signed-off-by: Marti Bolivar --- wirish/pwm.cpp | 13 ++++++++----- wirish/rules.mk | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'wirish') diff --git a/wirish/pwm.cpp b/wirish/pwm.cpp index a55f245..44884cd 100644 --- a/wirish/pwm.cpp +++ b/wirish/pwm.cpp @@ -2,6 +2,7 @@ * The MIT License * * Copyright (c) 2010 Perry Hung. + * Copyright (c) 2011, 2012 LeafLabs, LLC. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -25,7 +26,8 @@ *****************************************************************************/ /** - * @brief Arduino-style PWM implementation. + * @file wirish/pwm.cpp + * @brief Wiring-style pwmWrite(). */ #include @@ -36,10 +38,11 @@ #include void pwmWrite(uint8 pin, uint16 duty_cycle) { - timer_dev *dev = PIN_MAP[pin].timer_device; - if (pin >= BOARD_NR_GPIO_PINS || dev == NULL || dev->type == TIMER_BASIC) { + if (pin >= BOARD_NR_GPIO_PINS) { return; } - - timer_set_compare(dev, PIN_MAP[pin].timer_channel, duty_cycle); + timer_dev *dev = PIN_MAP[pin].timer_device; + uint8 cc_channel = PIN_MAP[pin].timer_channel; + ASSERT(dev && cc_channel); + timer_set_compare(dev, cc_channel, duty_cycle); } diff --git a/wirish/rules.mk b/wirish/rules.mk index 54c9180..176ba6a 100644 --- a/wirish/rules.mk +++ b/wirish/rules.mk @@ -25,6 +25,7 @@ cppSRCS_$(d) += cxxabi-compat.cpp cppSRCS_$(d) += HardwareSerial.cpp cppSRCS_$(d) += HardwareTimer.cpp cppSRCS_$(d) += Print.cpp +cppSRCS_$(d) += pwm.cpp cppSRCS_$(d) += wirish_analog.cpp cppSRCS_$(d) += wirish_digital.cpp cppSRCS_$(d) += wirish_math.cpp @@ -36,7 +37,6 @@ cppSRCS_$(d) += $(WIRISH_BOARD_PATH)/board.cpp # TODO: revise these appropriately F2 and put them back in: # HardwareSPI.cpp # usb_serial.cpp -# pwm.cpp # ext_interrupts.cpp sFILES_$(d) := $(sSRCS_$(d):%=$(d)/%) -- cgit v1.2.3