]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/protocol/arm_atsam/i2c_master.h
Massdrop keyboard support (#3780)
[qmk_firmware.git] / tmk_core / protocol / arm_atsam / i2c_master.h
1 /*
2 Copyright 2018 Massdrop Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef _I2C_MASTER_H_
19 #define _I2C_MASTER_H_
20
21 #ifndef MD_BOOTLOADER
22
23 #include "samd51j18a.h"
24 #include "issi3733_driver.h"
25 #include "config.h"
26
27 __attribute__((__aligned__(16)))
28 DmacDescriptor dmac_desc;
29 __attribute__((__aligned__(16)))
30 DmacDescriptor dmac_desc_wb;
31
32 uint8_t I2C3733_Init_Control(void);
33 uint8_t I2C3733_Init_Drivers(void);
34 void I2C3733_Control_Set(uint8_t state);
35 void I2C_DMAC_LED_Init(void);
36
37 #define I2C_Q_SIZE              100
38
39 #define I2C_Q_NA                100
40 #define I2C_Q_CRWL              101
41 #define I2C_Q_PAGE_SELECT       102
42 #define I2C_Q_PWM               103
43 #define I2C_Q_GCR               104
44 #define I2C_Q_ONOFF             105
45
46 #define I2C_DMA_MAX_SEND        255
47
48 extern volatile uint8_t i2c_led_q_running;
49
50 #define I2C_LED_Q_PWM(a)    { \
51                                 if (i2c_led_q_request_room(7)) \
52                                 { \
53                                     i2c_led_q_add(I2C_Q_CRWL); \
54                                     i2c_led_q_add(a); \
55                                     i2c_led_q_add(I2C_Q_PAGE_SELECT); \
56                                     i2c_led_q_add(a); \
57                                     i2c_led_q_add(ISSI3733_PG_PWM); \
58                                     i2c_led_q_add(I2C_Q_PWM); \
59                                     i2c_led_q_add(a); \
60                                 } \
61                             }
62
63 #define I2C_LED_Q_GCR(a)    { \
64                                 if (i2c_led_q_request_room(7)) \
65                                 { \
66                                     i2c_led_q_add(I2C_Q_CRWL); \
67                                     i2c_led_q_add(a); \
68                                     i2c_led_q_add(I2C_Q_PAGE_SELECT); \
69                                     i2c_led_q_add(a); \
70                                     i2c_led_q_add(ISSI3733_PG_FN); \
71                                     i2c_led_q_add(I2C_Q_GCR); \
72                                     i2c_led_q_add(a); \
73                                 } \
74                             }
75
76 #define I2C_LED_Q_ONOFF(a)  { \
77                                 if (i2c_led_q_request_room(7)) \
78                                 { \
79                                     i2c_led_q_add(I2C_Q_CRWL); \
80                                     i2c_led_q_add(a); \
81                                     i2c_led_q_add(I2C_Q_PAGE_SELECT); \
82                                     i2c_led_q_add(a); \
83                                     i2c_led_q_add(ISSI3733_PG_ONOFF); \
84                                     i2c_led_q_add(I2C_Q_ONOFF); \
85                                     i2c_led_q_add(a); \
86                                 } \
87                             }
88
89
90 void i2c_led_q_init(void);
91 void i2c_led_q_add(uint8_t cmd);
92 void i2c_led_q_s_advance(void);
93 uint8_t i2c_led_q_size(void);
94 uint8_t i2c_led_q_request_room(uint8_t request_size);
95 uint8_t i2c_led_q_run(void);
96
97 void i2c1_init(void);
98 uint8_t i2c1_transmit(uint8_t address, uint8_t *data, uint16_t length, uint16_t timeout);
99 void i2c1_stop(void);
100
101 #endif //MD_BOOTLOADER
102
103 void i2c0_init(void);
104 uint8_t i2c0_transmit(uint8_t address, uint8_t *data, uint16_t length, uint16_t timeout);
105 void i2c0_stop(void);
106
107 #endif // _I2C_MASTER_H_
108