summaryrefslogtreecommitdiff
path: root/hal/i2c.h
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2011-11-19 17:21:31 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2011-11-19 19:23:33 +0100
commit025a38a1f743fd9e89cbd477abe3f79a8d098097 (patch)
treea1f20c1b6a7f6c418bee641da923ab3d0d7208fe /hal/i2c.h
parent9e5875f2908c1ce506e7c5712ccabc379f911360 (diff)
Moved os and hal related files into subdirectories.
Diffstat (limited to 'hal/i2c.h')
-rw-r--r--hal/i2c.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/hal/i2c.h b/hal/i2c.h
new file mode 100644
index 0000000..3d58056
--- /dev/null
+++ b/hal/i2c.h
@@ -0,0 +1,40 @@
+#ifndef I2C_H
+#define I2C_H
+
+#include <stdint.h>
+
+#include "interrupt.h"
+
+class I2C {
+ friend void interrupt<Interrupt::I2C1_EV>();
+ friend void interrupt<Interrupt::I2C1_ER>();
+
+ private:
+ static I2C* self;
+
+ volatile uint8_t addr;
+ volatile uint8_t writing;
+ volatile uint8_t reading;
+ volatile uint8_t* write_p;
+ volatile uint8_t* read_p;
+
+ volatile bool busy;
+
+ void irq_ev();
+ void irq_er();
+ void handle_error();
+
+ public:
+ I2C() {
+ self = this;
+ }
+
+ void enable();
+
+ void write_reg(uint8_t addr_, uint8_t reg, uint8_t data);
+ void read_reg(uint8_t addr_, uint8_t reg, uint8_t len, uint8_t* buf);
+};
+
+
+
+#endif