From 2d1755b9dd984aaf30dd7f6534af767d5460e363 Mon Sep 17 00:00:00 2001
From: Pascal Engeler <engelerp@phys.ethz.ch>
Date: Fri, 9 Jun 2023 23:30:38 +0200
Subject: [PATCH] Added a timer

---
 firmware/drivers/ptimer/ptimer.cpp | 11 +++++++++++
 firmware/drivers/ptimer/ptimer.hpp | 11 +++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 firmware/drivers/ptimer/ptimer.cpp
 create mode 100644 firmware/drivers/ptimer/ptimer.hpp

diff --git a/firmware/drivers/ptimer/ptimer.cpp b/firmware/drivers/ptimer/ptimer.cpp
new file mode 100644
index 0000000..09c510c
--- /dev/null
+++ b/firmware/drivers/ptimer/ptimer.cpp
@@ -0,0 +1,11 @@
+#include <ptimer.hpp>
+
+unsigned long PTimer::start_t_ = 0;
+
+void PTimer::start(){
+    start_t_ = micros();
+}
+
+unsigned long PTimer::elapsed(){
+    return static_cast<unsigned long>(micros - start_t_);;
+}
diff --git a/firmware/drivers/ptimer/ptimer.hpp b/firmware/drivers/ptimer/ptimer.hpp
new file mode 100644
index 0000000..de4f843
--- /dev/null
+++ b/firmware/drivers/ptimer/ptimer.hpp
@@ -0,0 +1,11 @@
+#ifndef PTIMER_HPP_INCLUDED
+#define PTIMER_HPP_INCLUDED
+class PTimer{
+public:
+    static void start();
+    //returns the elapsed time in microseconds
+    static unsigned long elapsed() const;
+private:
+    static unsigned long start_t_;
+};
+#endif
-- 
GitLab