diff options
Diffstat (limited to 'hal/i2c.h')
-rw-r--r-- | hal/i2c.h | 40 |
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 |