diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2022-04-16 20:44:24 +0200 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2022-04-16 21:01:57 +0200 |
commit | 4ba824dab86433bb5295878f2380a9bd9536d67e (patch) | |
tree | 0b8a25c8c65b350f2e2266c9992a385c0ec9c681 /i2c/i2c.h | |
parent | 32df2ae55601f1ad135247ad79a913514d018032 (diff) |
i2c: stm32: Add v2 support.
Diffstat (limited to 'i2c/i2c.h')
-rw-r--r-- | i2c/i2c.h | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/i2c/i2c.h b/i2c/i2c.h deleted file mode 100644 index a2fde32..0000000 --- a/i2c/i2c.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef I2C_H -#define I2C_H - -#include <stdint.h> -#include <interrupt/interrupt.h> - -struct I2C_reg_t { - volatile uint32_t CR1; - volatile uint32_t CR2; - volatile uint32_t OAR1; - volatile uint32_t OAR2; - volatile uint32_t DR; - volatile uint32_t SR1; - volatile uint32_t SR2; - volatile uint32_t CCR; - volatile uint32_t TRISE; -}; - -class I2C_t { - private: - 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; - - public: - I2C_reg_t& reg; - const uint32_t clk; - - I2C_t(uint32_t reg_addr, uint32_t bus_clk) : reg(*(I2C_reg_t*)reg_addr), clk(bus_clk) { - reading = writing = 0; - } - - void irq_ev(); - void irq_er(); - - void handle_error(); - - 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); -}; - -#if defined(STM32F1) -extern I2C_t I2C1; -extern I2C_t I2C2; -#elif defined(STM32F4) -extern I2C_t I2C1; -extern I2C_t I2C2; -extern I2C_t I2C3; -#endif - -typedef I2C_t I2C; - -#endif |