aboutsummaryrefslogtreecommitdiffstats
path: root/src/wiring
diff options
context:
space:
mode:
Diffstat (limited to 'src/wiring')
-rw-r--r--src/wiring/comm/HardwareSerial.cpp3
-rw-r--r--src/wiring/time.c23
-rw-r--r--src/wiring/time.h14
-rw-r--r--src/wiring/wiring.c9
4 files changed, 26 insertions, 23 deletions
diff --git a/src/wiring/comm/HardwareSerial.cpp b/src/wiring/comm/HardwareSerial.cpp
index 84eb4c7..3d0a0ce 100644
--- a/src/wiring/comm/HardwareSerial.cpp
+++ b/src/wiring/comm/HardwareSerial.cpp
@@ -27,6 +27,7 @@
#include "HardwareSerial.h"
#include "usart.h"
#include "gpio.h"
+#include "timers.h"
#define USART1_TX_PORT GPIOA_BASE
#define USART1_TX_PIN 9
@@ -75,6 +76,8 @@ void HardwareSerial::begin(uint32_t baud) {
case 2:
gpio_set_mode(USART2_TX_PORT, USART2_TX_PIN, GPIO_MODE_AF_OUTPUT_PP);
gpio_set_mode(USART2_RX_PORT, USART2_RX_PIN, GPIO_MODE_INPUT_FLOATING);
+ /* Turn off any pwm */
+ timers_disable_channel(2, 3);
break;
case 3:
gpio_set_mode(USART3_TX_PORT, USART3_TX_PIN, GPIO_MODE_AF_OUTPUT_PP);
diff --git a/src/wiring/time.c b/src/wiring/time.c
index 1a91b5e..164d978 100644
--- a/src/wiring/time.c
+++ b/src/wiring/time.c
@@ -28,7 +28,7 @@
#include "time.h"
#define CYCLES_PER_MICROSECOND 72
-#define THE_SECRET_TO_LIFE_THE_UNIVERSE_AND_EVERYTHING 42
+#define FUDGE 42
extern volatile uint32_t systick_timer_millis;
@@ -47,26 +47,13 @@ void delay(unsigned long ms)
}
-#define MAGIC 4096
-/* HZ = 1000
- * n HZ*/
+
+#if 1
void delayMicroseconds(uint32_t us) {
uint32_t target;
uint32_t last, cur, count;
-
-#if 0
- asm volatile("mov r0, %[count] \n\t"
-"1: \n\t"
- "subs r0, r0, #1 \n\t"
- "bne 1b"
- :
- : [count] "r" (count)
- : "r0", "cc");
-#endif
-
-#if 1
/* fudge factor hacky hack hack for function overhead */
- target = us * CYCLES_PER_MICROSECOND - THE_SECRET_TO_LIFE_THE_UNIVERSE_AND_EVERYTHING;
+ target = us * CYCLES_PER_MICROSECOND - FUDGE;
/* Get current count */
last = systick_get_count();
@@ -81,5 +68,5 @@ void delayMicroseconds(uint32_t us) {
}
last = cur;
}
-#endif
}
+#endif
diff --git a/src/wiring/time.h b/src/wiring/time.h
index a97310a..68b3901 100644
--- a/src/wiring/time.h
+++ b/src/wiring/time.h
@@ -41,6 +41,20 @@ void delay(unsigned long ms);
/* Delay for us microseconds */
void delayMicroseconds(uint32_t us);
+#if 0
+static inline void delay_us(uint32 us) {
+ us *= 12;
+ asm volatile("mov r0, %[us] \n\t"
+ "subs r0, #2 \n\t"
+"1: \n\t"
+ "subs r0, r0, #1 \n\t"
+ "bne 1b"
+ :
+ : [us] "r" (us)
+ : "r0", "cc");
+
+}
+#endif
#ifdef __cplusplus
} // extern "C"
#endif
diff --git a/src/wiring/wiring.c b/src/wiring/wiring.c
index cecca20..04de78a 100644
--- a/src/wiring/wiring.c
+++ b/src/wiring/wiring.c
@@ -47,13 +47,12 @@ void init(void) {
gpio_init();
- /* off for debug */
-// adc_init();
+ adc_init();
timer_init(1, 1);
-// timer_init(2, 1);
-// timer_init(3, 1);
-// timer_init(4, 1);
+ timer_init(2, 1);
+ timer_init(3, 1);
+ timer_init(4, 1);
}
void NVIC_Configuration(void) {