aboutsummaryrefslogtreecommitdiffstats
path: root/wirish/comm/HardwareSerial.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
commit61db54f52f32e63c895d775982fbcdcb67f2dde6 (patch)
treeb0513c712b5888ab0a4e6613fdee3db606b61aaf /wirish/comm/HardwareSerial.cpp
parent6bc8cb7c1181e8005019e4ce1f2bea956c44e044 (diff)
downloadlibrambutan-61db54f52f32e63c895d775982fbcdcb67f2dde6.tar.gz
librambutan-61db54f52f32e63c895d775982fbcdcb67f2dde6.zip
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/comm/HardwareSerial.cpp')
-rw-r--r--wirish/comm/HardwareSerial.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/wirish/comm/HardwareSerial.cpp b/wirish/comm/HardwareSerial.cpp
index 08252d8..97a5ec3 100644
--- a/wirish/comm/HardwareSerial.cpp
+++ b/wirish/comm/HardwareSerial.cpp
@@ -31,12 +31,10 @@
#include "wirish.h"
#include "HardwareSerial.h"
#include "usart.h"
-#include "gpio.h"
-#include "timers.h"
-HardwareSerial Serial1(USART1, 4500000UL, GPIOA, 9,10, TIMER1, 2);
-HardwareSerial Serial2(USART2, 2250000UL, GPIOA, 2, 3, TIMER2, 3);
-HardwareSerial Serial3(USART3, 2250000UL, GPIOB, 10,11, TIMER_INVALID, 0);
+HardwareSerial Serial1(USART1, 4500000UL, GPIOA, 9, 10, TIMER1, 2);
+HardwareSerial Serial2(USART2, 2250000UL, GPIOA, 2, 3, TIMER2, 3);
+HardwareSerial Serial3(USART3, 2250000UL, GPIOB, 10, 11, NULL, 0);
// TODO: High density device ports
HardwareSerial::HardwareSerial(uint8 usart_num,
@@ -44,15 +42,15 @@ HardwareSerial::HardwareSerial(uint8 usart_num,
gpio_dev *gpio_device,
uint8 tx_pin,
uint8 rx_pin,
- timer_dev_num timer_num,
- uint8 compare_num) {
+ timer_dev *timer_device,
+ uint8 channel_num) {
this->usart_num = usart_num;
this->max_baud = max_baud;
this->gpio_device = gpio_device;
this->tx_pin = tx_pin;
this->rx_pin = rx_pin;
- this->timer_num = timer_num;
- this->compare_num = compare_num;
+ this->timer_device = timer_device;
+ this->channel_num = channel_num;
}
uint8 HardwareSerial::read(void) {
@@ -75,9 +73,9 @@ void HardwareSerial::begin(uint32 baud) {
gpio_set_mode(gpio_device, tx_pin, GPIO_AF_OUTPUT_PP);
gpio_set_mode(gpio_device, rx_pin, GPIO_INPUT_FLOATING);
- if (timer_num != TIMER_INVALID) {
+ if (timer_device != NULL) {
/* turn off any pwm if there's a conflict on this usart */
- timer_set_mode(timer_num, compare_num, TIMER_DISABLED);
+ timer_set_mode(timer_device, channel_num, TIMER_DISABLED);
}
usart_init(usart_num, baud);