summaryrefslogtreecommitdiff
path: root/drivers/gps.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gps.cpp')
-rw-r--r--drivers/gps.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/drivers/gps.cpp b/drivers/gps.cpp
new file mode 100644
index 0000000..1ae3684
--- /dev/null
+++ b/drivers/gps.cpp
@@ -0,0 +1,40 @@
+#include "gps.h"
+
+GPS* GPS::self;
+
+template<>
+void interrupt<Interrupt::USART3>() {
+ GPS::self->irq();
+}
+
+void GPS::irq() {
+
+ uint8_t c = USART3.DR;
+
+ if(!incomplete_msg) {
+ incomplete_msg = msg_pool.create();
+
+ if(!incomplete_msg) {
+ return;
+ }
+ }
+
+ if(incomplete_msg->n == 0 && c != '$') {
+ return;
+ }
+
+ if(incomplete_msg->n >= 128) {
+ incomplete_msg->n = 0;
+ return;
+ }
+
+ incomplete_msg->buf[incomplete_msg->n++] = c;
+
+ if(c == '\n') {
+ GPIOB.ODR ^= 1 << 1;
+
+ const_cast<P<GPSMsg>&>(complete_msg) = incomplete_msg;
+ incomplete_msg.reset();
+ complete = true;
+ }
+}