]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/split_common/i2c.h
Convert split_common to use generic GPIO api
[qmk_firmware.git] / quantum / split_common / i2c.h
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 #ifndef SCL_CLOCK
29 #define SCL_CLOCK  100000L
30 #endif
31
32 // Support 8bits right now (8 cols) will need to edit to take higher (code exists in delta split?)
33 extern volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE];
34
35 void i2c_master_init(void);
36 uint8_t i2c_master_start(uint8_t address);
37 void i2c_master_stop(void);
38 uint8_t i2c_master_write(uint8_t data);
39 uint8_t i2c_master_write_data(void *const TXdata, uint8_t dataLen);
40 uint8_t i2c_master_read(int);
41 void i2c_reset_state(void);
42 void i2c_slave_init(uint8_t address);
43
44
45 static inline unsigned char i2c_start_read(unsigned char addr) {
46   return i2c_master_start((addr << 1) | I2C_READ);
47 }
48
49 static inline unsigned char i2c_start_write(unsigned char addr) {
50   return i2c_master_start((addr << 1) | I2C_WRITE);
51 }
52
53 // from SSD1306 scrips
54 extern unsigned char i2c_rep_start(unsigned char addr);
55 extern void i2c_start_wait(unsigned char addr);
56 extern unsigned char i2c_readAck(void);
57 extern unsigned char i2c_readNak(void);
58 extern unsigned char i2c_read(unsigned char ack);
59
60 #define i2c_read(ack)  (ack) ? i2c_readAck() : i2c_readNak();
61
62 #endif