diff options
Diffstat (limited to 'quantum/split_common/i2c.h')
-rw-r--r-- | quantum/split_common/i2c.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/quantum/split_common/i2c.h b/quantum/split_common/i2c.h new file mode 100644 index 000000000..b4c72bde0 --- /dev/null +++ b/quantum/split_common/i2c.h | |||
@@ -0,0 +1,60 @@ | |||
1 | #ifndef I2C_H | ||
2 | #define I2C_H | ||
3 | |||
4 | #include <stdint.h> | ||
5 | |||
6 | #ifndef F_CPU | ||
7 | #define F_CPU 16000000UL | ||
8 | #endif | ||
9 | |||
10 | #define I2C_READ 1 | ||
11 | #define I2C_WRITE 0 | ||
12 | |||
13 | #define I2C_ACK 1 | ||
14 | #define I2C_NACK 0 | ||
15 | |||
16 | // Address location defines (Keymap should be last, as it's size is dynamic) | ||
17 | #define I2C_BACKLIT_START 0x00 | ||
18 | // Need 4 bytes for RGB (32 bit) | ||
19 | #define I2C_RGB_START 0x01 | ||
20 | #define I2C_KEYMAP_START 0x06 | ||
21 | |||
22 | // Slave buffer (8bit per) | ||
23 | // Rows per hand + backlit space + rgb space | ||
24 | // TODO : Make this dynamically sized | ||
25 | #define SLAVE_BUFFER_SIZE 0x20 | ||
26 | |||
27 | // i2c SCL clock frequency | ||
28 | #define SCL_CLOCK 400000L | ||
29 | |||
30 | // Support 8bits right now (8 cols) will need to edit to take higher (code exists in delta split?) | ||
31 | extern volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE]; | ||
32 | |||
33 | void i2c_master_init(void); | ||
34 | uint8_t i2c_master_start(uint8_t address); | ||
35 | void i2c_master_stop(void); | ||
36 | uint8_t i2c_master_write(uint8_t data); | ||
37 | uint8_t i2c_master_write_data(void *const TXdata, uint8_t dataLen); | ||
38 | uint8_t i2c_master_read(int); | ||
39 | void i2c_reset_state(void); | ||
40 | void i2c_slave_init(uint8_t address); | ||
41 | |||
42 | |||
43 | static inline unsigned char i2c_start_read(unsigned char addr) { | ||
44 | return i2c_master_start((addr << 1) | I2C_READ); | ||
45 | } | ||
46 | |||
47 | static inline unsigned char i2c_start_write(unsigned char addr) { | ||
48 | return i2c_master_start((addr << 1) | I2C_WRITE); | ||
49 | } | ||
50 | |||
51 | // from SSD1306 scrips | ||
52 | extern unsigned char i2c_rep_start(unsigned char addr); | ||
53 | extern void i2c_start_wait(unsigned char addr); | ||
54 | extern unsigned char i2c_readAck(void); | ||
55 | extern unsigned char i2c_readNak(void); | ||
56 | extern unsigned char i2c_read(unsigned char ack); | ||
57 | |||
58 | #define i2c_read(ack) (ack) ? i2c_readAck() : i2c_readNak(); | ||
59 | |||
60 | #endif | ||