aboutsummaryrefslogtreecommitdiff
path: root/wirish/pwm.cpp
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-03-22 16:59:29 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2011-03-24 07:25:14 -0400
commit296b1188bfb8cf28466b95f1dd0fde309b1f9399 (patch)
treeb0ed2b9fecb2da85266e6b2b88c6fe31bb0ca2c8 /wirish/pwm.cpp
parent68b57d90007a234e6a2fc82f6b9402fb6b77ef34 (diff)
Initial timer refactor.
Basic PWM works. Had some problems in testing that might be due to USART bugs. HardwareTimer has been removed from the build for now; I will re-implement it in terms of the new libmaple API, but consider it deprecated. Let's come up with something better. Servo is implemented in terms of HardwareTimer, so it also has been temporarily removed from the build. pwmWrite() likely got a little bit less inefficient due to indirection, but the PIN_MAPs shrank by a pointer per PinMapping.
Diffstat (limited to 'wirish/pwm.cpp')
-rw-r--r--wirish/pwm.cpp22
1 files changed, 8 insertions, 14 deletions
diff --git a/wirish/pwm.cpp b/wirish/pwm.cpp
index 072e4cd..6b09cef 100644
--- a/wirish/pwm.cpp
+++ b/wirish/pwm.cpp
@@ -23,26 +23,20 @@
*****************************************************************************/
/**
- * @brief Arduino-compatible PWM implementation.
+ * @brief Arduino-style PWM implementation.
*/
-#include "wirish.h"
-#include "timers.h"
-#include "io.h"
+#include "libmaple_types.h"
+#include "timer.h"
+
+#include "boards.h"
#include "pwm.h"
void pwmWrite(uint8 pin, uint16 duty_cycle) {
- TimerCCR ccr;
-
- if (pin >= NR_GPIO_PINS) {
- return;
- }
-
- ccr = PIN_MAP[pin].timer_ccr;
-
- if (ccr == 0) {
+ timer_dev *dev = PIN_MAP[pin].timer_device;
+ if (pin >= NR_GPIO_PINS || dev == NULL || dev->type == TIMER_BASIC) {
return;
}
- timer_pwm_write_ccr(ccr, duty_cycle);
+ timer_set_compare(dev, PIN_MAP[pin].timer_chan, duty_cycle);
}