diff options
-rw-r--r-- | keyboards/k_type/i2c_master.c | 145 | ||||
-rw-r--r-- | keyboards/k_type/i2c_master.h | 127 | ||||
-rw-r--r-- | keyboards/k_type/is31fl3733.c | 231 | ||||
-rw-r--r-- | keyboards/k_type/is31fl3733.h | 251 | ||||
-rw-r--r-- | keyboards/k_type/k_type.c | 201 | ||||
-rw-r--r-- | keyboards/k_type/keymaps/andrew-fahmy/config.h | 52 | ||||
-rw-r--r-- | keyboards/k_type/keymaps/andrew-fahmy/keymap.c | 60 | ||||
-rw-r--r-- | keyboards/k_type/keymaps/andrew-fahmy/rules.mk | 1 | ||||
-rw-r--r-- | keyboards/k_type/keymaps/rgb/config.h | 25 | ||||
-rw-r--r-- | keyboards/k_type/keymaps/rgb/keymap.c | 4 | ||||
-rw-r--r-- | keyboards/k_type/keymaps/rgb/readme.md | 4 | ||||
-rw-r--r-- | keyboards/k_type/led.c | 53 | ||||
-rw-r--r-- | keyboards/k_type/mcuconf.h | 3 | ||||
-rw-r--r-- | keyboards/k_type/rules.mk | 4 |
14 files changed, 1058 insertions, 103 deletions
diff --git a/keyboards/k_type/i2c_master.c b/keyboards/k_type/i2c_master.c new file mode 100644 index 000000000..72d835a60 --- /dev/null +++ b/keyboards/k_type/i2c_master.c | |||
@@ -0,0 +1,145 @@ | |||
1 | /* Copyright 2018 Jack Humbert | ||
2 | * Copyright 2018 Yiancar | ||
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 | /* This library is only valid for STM32 processors. | ||
19 | * This library follows the convention of the AVR i2c_master library. | ||
20 | * As a result addresses are expected to be already shifted (addr << 1). | ||
21 | * I2CD1 is the default driver which corresponds to pins B6 and B7. This | ||
22 | * can be changed. | ||
23 | * Please ensure that HAL_USE_I2C is TRUE in the halconf.h file and that | ||
24 | * STM32_I2C_USE_I2C1 is TRUE in the mcuconf.h file. Pins B6 and B7 are used | ||
25 | * but using any other I2C pins should be trivial. | ||
26 | */ | ||
27 | #include "quantum.h" | ||
28 | #include "i2c_master.h" | ||
29 | #include "print.h" | ||
30 | #include <string.h> | ||
31 | #include <hal.h> | ||
32 | |||
33 | static uint8_t i2c_address; | ||
34 | |||
35 | I2CDriver *drivers[I2C_COUNT]; | ||
36 | |||
37 | static const I2CConfig i2cconfig = { | ||
38 | #if defined(USE_I2CV1_CONTRIB) | ||
39 | I2C1_CLOCK_SPEED, | ||
40 | #elif defined(USE_I2CV1) | ||
41 | I2C1_OPMODE, | ||
42 | I2C1_CLOCK_SPEED, | ||
43 | I2C1_DUTY_CYCLE, | ||
44 | #else | ||
45 | // This configures the I2C clock to 400khz assuming a 72Mhz clock | ||
46 | // For more info : https://www.st.com/en/embedded-software/stsw-stm32126.html | ||
47 | STM32_TIMINGR_PRESC(I2C1_TIMINGR_PRESC) | STM32_TIMINGR_SCLDEL(I2C1_TIMINGR_SCLDEL) | STM32_TIMINGR_SDADEL(I2C1_TIMINGR_SDADEL) | STM32_TIMINGR_SCLH(I2C1_TIMINGR_SCLH) | STM32_TIMINGR_SCLL(I2C1_TIMINGR_SCLL), 0, 0 | ||
48 | #endif | ||
49 | }; | ||
50 | |||
51 | static i2c_status_t chibios_to_qmk(const msg_t* status) { | ||
52 | switch (*status) { | ||
53 | case I2C_NO_ERROR: | ||
54 | return I2C_STATUS_SUCCESS; | ||
55 | case I2C_TIMEOUT: | ||
56 | return I2C_STATUS_TIMEOUT; | ||
57 | // I2C_BUS_ERROR, I2C_ARBITRATION_LOST, I2C_ACK_FAILURE, I2C_OVERRUN, I2C_PEC_ERROR, I2C_SMB_ALERT | ||
58 | default: | ||
59 | return I2C_STATUS_ERROR; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | __attribute__((weak)) void i2c_init(I2CDriver *driver, ioportid_t scl_port, ioportid_t sda_port, iopadid_t scl_pad, iopadid_t sda_pad) { | ||
64 | static uint8_t index = 0; | ||
65 | if (index < I2C_COUNT) { | ||
66 | |||
67 | // Try releasing special pins for a short time | ||
68 | palSetPadMode(scl_port, scl_pad, PAL_MODE_INPUT); | ||
69 | palSetPadMode(sda_port, sda_pad, PAL_MODE_INPUT); | ||
70 | |||
71 | chThdSleepMilliseconds(10); | ||
72 | |||
73 | #if defined(USE_GPIOV1) | ||
74 | palSetPadMode(scl_port, scl_pad, I2C1_SCL_PAL_MODE); | ||
75 | palSetPadMode(sda_port, sda_pad, I2C1_SDA_PAL_MODE); | ||
76 | #else | ||
77 | palSetPadMode(scl_port, scl_pad, PAL_MODE_ALTERNATE(I2C1_SCL_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN); | ||
78 | palSetPadMode(sda_port, sda_pad, PAL_MODE_ALTERNATE(I2C1_SDA_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN); | ||
79 | #endif | ||
80 | |||
81 | drivers[index++] = driver; | ||
82 | } | ||
83 | } | ||
84 | |||
85 | i2c_status_t i2c_start(uint8_t index, uint8_t address) { | ||
86 | if(index >= I2C_COUNT) { | ||
87 | return I2C_STATUS_ERROR; | ||
88 | } | ||
89 | i2c_address = address; | ||
90 | i2cStart(drivers[index], &i2cconfig); | ||
91 | return I2C_STATUS_SUCCESS; | ||
92 | } | ||
93 | |||
94 | i2c_status_t i2c_transmit(uint8_t index, uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout) { | ||
95 | if(index >= I2C_COUNT) { | ||
96 | return I2C_STATUS_ERROR; | ||
97 | } | ||
98 | i2c_address = address; | ||
99 | i2cStart(drivers[index], &i2cconfig); | ||
100 | msg_t status = i2cMasterTransmitTimeout(drivers[index], (i2c_address >> 1), data, length, 0, 0, TIME_MS2I(timeout)); | ||
101 | return chibios_to_qmk(&status); | ||
102 | } | ||
103 | |||
104 | i2c_status_t i2c_receive(uint8_t index, uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout) { | ||
105 | if(index >= I2C_COUNT) { | ||
106 | return I2C_STATUS_ERROR; | ||
107 | } | ||
108 | i2c_address = address; | ||
109 | i2cStart(drivers[index], &i2cconfig); | ||
110 | msg_t status = i2cMasterReceiveTimeout(drivers[index], (i2c_address >> 1), data, length, TIME_MS2I(timeout)); | ||
111 | return chibios_to_qmk(&status); | ||
112 | } | ||
113 | |||
114 | i2c_status_t i2c_writeReg(uint8_t index, uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout) { | ||
115 | if(index >= I2C_COUNT) { | ||
116 | return I2C_STATUS_ERROR; | ||
117 | } | ||
118 | i2c_address = devaddr; | ||
119 | i2cStart(drivers[index], &i2cconfig); | ||
120 | |||
121 | uint8_t complete_packet[length + 1]; | ||
122 | for (uint8_t i = 0; i < length; i++) { | ||
123 | complete_packet[i + 1] = data[i]; | ||
124 | } | ||
125 | complete_packet[0] = regaddr; | ||
126 | |||
127 | msg_t status = i2cMasterTransmitTimeout(drivers[index], (i2c_address >> 1), complete_packet, length + 1, 0, 0, TIME_MS2I(timeout)); | ||
128 | return chibios_to_qmk(&status); | ||
129 | } | ||
130 | |||
131 | i2c_status_t i2c_readReg(uint8_t index, uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout) { | ||
132 | if(index >= I2C_COUNT) { | ||
133 | return I2C_STATUS_ERROR; | ||
134 | } | ||
135 | i2c_address = devaddr; | ||
136 | i2cStart(drivers[index], &i2cconfig); | ||
137 | msg_t status = i2cMasterTransmitTimeout(drivers[index], (i2c_address >> 1), ®addr, 1, data, length, TIME_MS2I(timeout)); | ||
138 | return chibios_to_qmk(&status); | ||
139 | } | ||
140 | |||
141 | void i2c_stop(uint8_t index) { | ||
142 | if(index < I2C_COUNT) { | ||
143 | i2cStop(drivers[index]); | ||
144 | } | ||
145 | } | ||
diff --git a/keyboards/k_type/i2c_master.h b/keyboards/k_type/i2c_master.h new file mode 100644 index 000000000..5a7893fae --- /dev/null +++ b/keyboards/k_type/i2c_master.h | |||
@@ -0,0 +1,127 @@ | |||
1 | /* Copyright 2018 Jack Humbert | ||
2 | * Copyright 2018 Yiancar | ||
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 | /* This library follows the convention of the AVR i2c_master library. | ||
19 | * As a result addresses are expected to be already shifted (addr << 1). | ||
20 | * I2CD1 is the default driver which corresponds to pins B6 and B7. This | ||
21 | * can be changed. | ||
22 | * Please ensure that HAL_USE_I2C is TRUE in the halconf.h file and that | ||
23 | * STM32_I2C_USE_I2C1 is TRUE in the mcuconf.h file. | ||
24 | */ | ||
25 | #pragma once | ||
26 | |||
27 | #include <ch.h> | ||
28 | #include <hal.h> | ||
29 | |||
30 | #ifndef I2C_COUNT | ||
31 | # define I2C_COUNT 1 | ||
32 | #endif | ||
33 | |||
34 | #ifdef I2C1_BANK | ||
35 | # define I2C1_SCL_BANK I2C1_BANK | ||
36 | # define I2C1_SDA_BANK I2C1_BANK | ||
37 | #endif | ||
38 | |||
39 | #ifndef I2C1_SCL_BANK | ||
40 | # define I2C1_SCL_BANK GPIOB | ||
41 | #endif | ||
42 | |||
43 | #ifndef I2C1_SDA_BANK | ||
44 | # define I2C1_SDA_BANK GPIOB | ||
45 | #endif | ||
46 | |||
47 | |||
48 | #ifdef USE_I2C2 | ||
49 | # ifdef I2C2_BANK | ||
50 | # define I2C2_SCL_BANK I2C2_BANK | ||
51 | # define I2C2_SDA_BANK I2C2_BANK | ||
52 | # endif | ||
53 | # ifndef I2C2_SCL_BANK | ||
54 | # define I2C2_SCL_BANK GPIOC | ||
55 | # endif | ||
56 | # ifndef I2C2_SDA_BANK | ||
57 | # define I2C2_SDA_BANK GPIOC | ||
58 | # endif | ||
59 | #endif | ||
60 | |||
61 | #ifndef I2C1_SCL | ||
62 | # define I2C1_SCL 6 | ||
63 | #endif | ||
64 | #ifndef I2C1_SDA | ||
65 | # define I2C1_SDA 7 | ||
66 | #endif | ||
67 | |||
68 | #ifdef USE_I2CV1 | ||
69 | # ifndef I2C1_OPMODE | ||
70 | # define I2C1_OPMODE OPMODE_I2C | ||
71 | # endif | ||
72 | # ifndef I2C1_CLOCK_SPEED | ||
73 | # define I2C1_CLOCK_SPEED 100000 /* 400000 */ | ||
74 | # endif | ||
75 | # ifndef I2C1_DUTY_CYCLE | ||
76 | # define I2C1_DUTY_CYCLE STD_DUTY_CYCLE /* FAST_DUTY_CYCLE_2 */ | ||
77 | # endif | ||
78 | #else | ||
79 | // The default timing values below configures the I2C clock to 400khz assuming a 72Mhz clock | ||
80 | // For more info : https://www.st.com/en/embedded-software/stsw-stm32126.html | ||
81 | # ifndef I2C1_TIMINGR_PRESC | ||
82 | # define I2C1_TIMINGR_PRESC 0U | ||
83 | # endif | ||
84 | # ifndef I2C1_TIMINGR_SCLDEL | ||
85 | # define I2C1_TIMINGR_SCLDEL 7U | ||
86 | # endif | ||
87 | # ifndef I2C1_TIMINGR_SDADEL | ||
88 | # define I2C1_TIMINGR_SDADEL 0U | ||
89 | # endif | ||
90 | # ifndef I2C1_TIMINGR_SCLH | ||
91 | # define I2C1_TIMINGR_SCLH 38U | ||
92 | # endif | ||
93 | # ifndef I2C1_TIMINGR_SCLL | ||
94 | # define I2C1_TIMINGR_SCLL 129U | ||
95 | # endif | ||
96 | #endif | ||
97 | |||
98 | #ifdef USE_GPIOV1 | ||
99 | # ifndef I2C1_SCL_PAL_MODE | ||
100 | # define I2C1_SCL_PAL_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN | ||
101 | # endif | ||
102 | # ifndef I2C1_SDA_PAL_MODE | ||
103 | # define I2C1_SDA_PAL_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN | ||
104 | # endif | ||
105 | #else | ||
106 | // The default PAL alternate modes are used to signal that the pins are used for I2C | ||
107 | # ifndef I2C1_SCL_PAL_MODE | ||
108 | # define I2C1_SCL_PAL_MODE 4 | ||
109 | # endif | ||
110 | # ifndef I2C1_SDA_PAL_MODE | ||
111 | # define I2C1_SDA_PAL_MODE 4 | ||
112 | # endif | ||
113 | #endif | ||
114 | |||
115 | typedef int16_t i2c_status_t; | ||
116 | |||
117 | #define I2C_STATUS_SUCCESS (0) | ||
118 | #define I2C_STATUS_ERROR (-1) | ||
119 | #define I2C_STATUS_TIMEOUT (-2) | ||
120 | |||
121 | void i2c_init(I2CDriver *driver, ioportid_t scl_port, ioportid_t sda_port, iopadid_t scl_pad, iopadid_t sda_pad); | ||
122 | i2c_status_t i2c_start(uint8_t index, uint8_t address); | ||
123 | i2c_status_t i2c_transmit(uint8_t index, uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout); | ||
124 | i2c_status_t i2c_receive(uint8_t index, uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout); | ||
125 | i2c_status_t i2c_writeReg(uint8_t index, uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout); | ||
126 | i2c_status_t i2c_readReg(uint8_t index, uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout); | ||
127 | void i2c_stop(uint8_t index); | ||
diff --git a/keyboards/k_type/is31fl3733.c b/keyboards/k_type/is31fl3733.c new file mode 100644 index 000000000..8818a622b --- /dev/null +++ b/keyboards/k_type/is31fl3733.c | |||
@@ -0,0 +1,231 @@ | |||
1 | /* Copyright 2017 Jason Williams | ||
2 | * Copyright 2018 Jack Humbert | ||
3 | * Copyright 2018 Yiancar | ||
4 | * | ||
5 | * This program is free software: you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation, either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #include "is31fl3733.h" | ||
20 | #include "i2c_master.h" | ||
21 | #include "wait.h" | ||
22 | |||
23 | // This is a 7-bit address, that gets left-shifted and bit 0 | ||
24 | // set to 0 for write, 1 for read (as per I2C protocol) | ||
25 | // The address will vary depending on your wiring: | ||
26 | // 00 <-> GND | ||
27 | // 01 <-> SCL | ||
28 | // 10 <-> SDA | ||
29 | // 11 <-> VCC | ||
30 | // ADDR1 represents A1:A0 of the 7-bit address. | ||
31 | // ADDR2 represents A3:A2 of the 7-bit address. | ||
32 | // The result is: 0b101(ADDR2)(ADDR1) | ||
33 | #define ISSI_ADDR_DEFAULT 0x50 | ||
34 | |||
35 | #define ISSI_COMMANDREGISTER 0xFD | ||
36 | #define ISSI_COMMANDREGISTER_WRITELOCK 0xFE | ||
37 | #define ISSI_INTERRUPTMASKREGISTER 0xF0 | ||
38 | #define ISSI_INTERRUPTSTATUSREGISTER 0xF1 | ||
39 | |||
40 | #define ISSI_PAGE_LEDCONTROL 0x00 // PG0 | ||
41 | #define ISSI_PAGE_PWM 0x01 // PG1 | ||
42 | #define ISSI_PAGE_AUTOBREATH 0x02 // PG2 | ||
43 | #define ISSI_PAGE_FUNCTION 0x03 // PG3 | ||
44 | |||
45 | #define ISSI_REG_CONFIGURATION 0x00 // PG3 | ||
46 | #define ISSI_REG_GLOBALCURRENT 0x01 // PG3 | ||
47 | #define ISSI_REG_RESET 0x11 // PG3 | ||
48 | #define ISSI_REG_SWPULLUP 0x0F // PG3 | ||
49 | #define ISSI_REG_CSPULLUP 0x10 // PG3 | ||
50 | |||
51 | #ifndef ISSI_TIMEOUT | ||
52 | # define ISSI_TIMEOUT 100 | ||
53 | #endif | ||
54 | |||
55 | #ifndef ISSI_PERSISTENCE | ||
56 | # define ISSI_PERSISTENCE 0 | ||
57 | #endif | ||
58 | |||
59 | // Transfer buffer for TWITransmitData() | ||
60 | uint8_t g_twi_transfer_buffer[20]; | ||
61 | |||
62 | // These buffers match the IS31FL3733 PWM registers. | ||
63 | // The control buffers match the PG0 LED On/Off registers. | ||
64 | // Storing them like this is optimal for I2C transfers to the registers. | ||
65 | // We could optimize this and take out the unused registers from these | ||
66 | // buffers and the transfers in IS31FL3733_write_pwm_buffer() but it's | ||
67 | // probably not worth the extra complexity. | ||
68 | uint8_t g_pwm_buffer[DRIVER_COUNT][192]; | ||
69 | bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; | ||
70 | |||
71 | uint8_t g_led_control_registers[DRIVER_COUNT][24] = {{0}, {0}}; | ||
72 | bool g_led_control_registers_update_required[DRIVER_COUNT] = {false}; | ||
73 | |||
74 | bool IS31FL3733_write_register(uint8_t index, uint8_t addr, uint8_t reg, uint8_t data) { | ||
75 | // If the transaction fails function returns false. | ||
76 | g_twi_transfer_buffer[0] = reg; | ||
77 | g_twi_transfer_buffer[1] = data; | ||
78 | |||
79 | #if ISSI_PERSISTENCE > 0 | ||
80 | for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { | ||
81 | if (i2c_transmit(index, addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) != 0) { | ||
82 | return false; | ||
83 | } | ||
84 | } | ||
85 | #else | ||
86 | if (i2c_transmit(index, addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) != 0) { | ||
87 | return false; | ||
88 | } | ||
89 | #endif | ||
90 | return true; | ||
91 | } | ||
92 | |||
93 | bool IS31FL3733_write_pwm_buffer(uint8_t index, uint8_t addr, uint8_t *pwm_buffer) { | ||
94 | // Assumes PG1 is already selected. | ||
95 | // If any of the transactions fails function returns false. | ||
96 | // Transmit PWM registers in 12 transfers of 16 bytes. | ||
97 | // g_twi_transfer_buffer[] is 20 bytes | ||
98 | |||
99 | // Iterate over the pwm_buffer contents at 16 byte intervals. | ||
100 | for (int i = 0; i < 192; i += 16) { | ||
101 | g_twi_transfer_buffer[0] = i; | ||
102 | // Copy the data from i to i+15. | ||
103 | // Device will auto-increment register for data after the first byte | ||
104 | // Thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer. | ||
105 | for (int j = 0; j < 16; j++) { | ||
106 | g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j]; | ||
107 | } | ||
108 | |||
109 | #if ISSI_PERSISTENCE > 0 | ||
110 | for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) { | ||
111 | if (i2c_transmit(index, addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) != 0) { | ||
112 | return false; | ||
113 | } | ||
114 | } | ||
115 | #else | ||
116 | if (i2c_transmit(index, addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) != 0) { | ||
117 | return false; | ||
118 | } | ||
119 | #endif | ||
120 | } | ||
121 | return true; | ||
122 | } | ||
123 | |||
124 | void IS31FL3733_init(uint8_t bus, uint8_t addr, uint8_t sync) { | ||
125 | // In order to avoid the LEDs being driven with garbage data | ||
126 | // in the LED driver's PWM registers, shutdown is enabled last. | ||
127 | // Set up the mode and other settings, clear the PWM registers, | ||
128 | // then disable software shutdown. | ||
129 | // Sync is passed so set it according to the datasheet. | ||
130 | |||
131 | // Unlock the command register. | ||
132 | IS31FL3733_write_register(bus, addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); | ||
133 | // Select PG0 | ||
134 | IS31FL3733_write_register(bus, addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); | ||
135 | // Turn off all LEDs. | ||
136 | for (int i = 0x00; i <= 0x17; i++) { | ||
137 | IS31FL3733_write_register(bus, addr, i, 0x00); | ||
138 | } | ||
139 | // Unlock the command register. | ||
140 | IS31FL3733_write_register(bus, addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); | ||
141 | // Select PG1 | ||
142 | IS31FL3733_write_register(bus, addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); | ||
143 | // Set PWM on all LEDs to 0 | ||
144 | // No need to setup Breath registers to PWM as that is the default. | ||
145 | for (int i = 0x00; i <= 0xBF; i++) { | ||
146 | IS31FL3733_write_register(bus, addr, i, 0x00); | ||
147 | } | ||
148 | // Unlock the command register. | ||
149 | IS31FL3733_write_register(bus, addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); | ||
150 | // Select PG3 | ||
151 | IS31FL3733_write_register(bus, addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION); | ||
152 | // Set global current to maximum. | ||
153 | IS31FL3733_write_register(bus, addr, ISSI_REG_GLOBALCURRENT, 0xFF); | ||
154 | // Disable software shutdown. | ||
155 | IS31FL3733_write_register(bus, addr, ISSI_REG_CONFIGURATION, (sync << 6) | 0x01); | ||
156 | // Wait 10ms to ensure the device has woken up. | ||
157 | wait_ms(10); | ||
158 | } | ||
159 | |||
160 | void IS31FL3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { | ||
161 | if (index >= 0 && index < DRIVER_LED_TOTAL) { | ||
162 | is31_led led = g_is31_leds[index]; | ||
163 | |||
164 | g_pwm_buffer[led.driver][led.r] = red; | ||
165 | g_pwm_buffer[led.driver][led.g] = green; | ||
166 | g_pwm_buffer[led.driver][led.b] = blue; | ||
167 | g_pwm_buffer_update_required[led.driver] = true; | ||
168 | } | ||
169 | } | ||
170 | |||
171 | void IS31FL3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { | ||
172 | for (int i = 0; i < DRIVER_LED_TOTAL; i++) { | ||
173 | IS31FL3733_set_color(i, red, green, blue); | ||
174 | } | ||
175 | } | ||
176 | |||
177 | void IS31FL3733_set_led_control_register(uint8_t index, bool red, bool green, bool blue) { | ||
178 | is31_led led = g_is31_leds[index]; | ||
179 | |||
180 | uint8_t control_register_r = led.r / 8; | ||
181 | uint8_t control_register_g = led.g / 8; | ||
182 | uint8_t control_register_b = led.b / 8; | ||
183 | uint8_t bit_r = led.r % 8; | ||
184 | uint8_t bit_g = led.g % 8; | ||
185 | uint8_t bit_b = led.b % 8; | ||
186 | |||
187 | if (red) { | ||
188 | g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r); | ||
189 | } else { | ||
190 | g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r); | ||
191 | } | ||
192 | if (green) { | ||
193 | g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g); | ||
194 | } else { | ||
195 | g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g); | ||
196 | } | ||
197 | if (blue) { | ||
198 | g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b); | ||
199 | } else { | ||
200 | g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b); | ||
201 | } | ||
202 | |||
203 | g_led_control_registers_update_required[led.driver] = true; | ||
204 | } | ||
205 | |||
206 | void IS31FL3733_update_pwm_buffers(uint8_t addr, uint8_t index) { | ||
207 | if (g_pwm_buffer_update_required[index]) { | ||
208 | // Firstly we need to unlock the command register and select PG1. | ||
209 | IS31FL3733_write_register(index, addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); | ||
210 | IS31FL3733_write_register(index, addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM); | ||
211 | |||
212 | // If any of the transactions fail we risk writing dirty PG0, | ||
213 | // refresh page 0 just in case. | ||
214 | if (!IS31FL3733_write_pwm_buffer(index, addr, g_pwm_buffer[index])) { | ||
215 | g_led_control_registers_update_required[index] = true; | ||
216 | } | ||
217 | } | ||
218 | g_pwm_buffer_update_required[index] = false; | ||
219 | } | ||
220 | |||
221 | void IS31FL3733_update_led_control_registers(uint8_t addr, uint8_t index) { | ||
222 | if (g_led_control_registers_update_required[index]) { | ||
223 | // Firstly we need to unlock the command register and select PG0 | ||
224 | IS31FL3733_write_register(index, addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5); | ||
225 | IS31FL3733_write_register(index, addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL); | ||
226 | for (int i = 0; i < 24; i++) { | ||
227 | IS31FL3733_write_register(index, addr, i, g_led_control_registers[index][i]); | ||
228 | } | ||
229 | } | ||
230 | g_led_control_registers_update_required[index] = false; | ||
231 | } | ||
diff --git a/keyboards/k_type/is31fl3733.h b/keyboards/k_type/is31fl3733.h new file mode 100644 index 000000000..272bcdc41 --- /dev/null +++ b/keyboards/k_type/is31fl3733.h | |||
@@ -0,0 +1,251 @@ | |||
1 | /* Copyright 2017 Jason Williams | ||
2 | * Copyright 2018 Jack Humbert | ||
3 | * Copyright 2018 Yiancar | ||
4 | * | ||
5 | * This program is free software: you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation, either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #pragma once | ||
20 | |||
21 | #include <stdint.h> | ||
22 | #include <stdbool.h> | ||
23 | |||
24 | typedef struct is31_led { | ||
25 | uint8_t driver : 2; | ||
26 | uint8_t r; | ||
27 | uint8_t g; | ||
28 | uint8_t b; | ||
29 | } __attribute__((packed)) is31_led; | ||
30 | |||
31 | extern const is31_led g_is31_leds[DRIVER_LED_TOTAL]; | ||
32 | |||
33 | void IS31FL3733_init(uint8_t bus, uint8_t addr, uint8_t sync); | ||
34 | bool IS31FL3733_write_register(uint8_t index, uint8_t addr, uint8_t reg, uint8_t data); | ||
35 | bool IS31FL3733_write_pwm_buffer(uint8_t index, uint8_t addr, uint8_t *pwm_buffer); | ||
36 | |||
37 | void IS31FL3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); | ||
38 | void IS31FL3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue); | ||
39 | |||
40 | void IS31FL3733_set_led_control_register(uint8_t index, bool red, bool green, bool blue); | ||
41 | |||
42 | // This should not be called from an interrupt | ||
43 | // (eg. from a timer interrupt). | ||
44 | // Call this while idle (in between matrix scans). | ||
45 | // If the buffer is dirty, it will update the driver with the buffer. | ||
46 | void IS31FL3733_update_pwm_buffers(uint8_t addr, uint8_t index); // index is the driver index | ||
47 | void IS31FL3733_update_led_control_registers(uint8_t addr, uint8_t index); | ||
48 | |||
49 | #define A_1 0x00 | ||
50 | #define A_2 0x01 | ||
51 | #define A_3 0x02 | ||
52 | #define A_4 0x03 | ||
53 | #define A_5 0x04 | ||
54 | #define A_6 0x05 | ||
55 | #define A_7 0x06 | ||
56 | #define A_8 0x07 | ||
57 | #define A_9 0x08 | ||
58 | #define A_10 0x09 | ||
59 | #define A_11 0x0A | ||
60 | #define A_12 0x0B | ||
61 | #define A_13 0x0C | ||
62 | #define A_14 0x0D | ||
63 | #define A_15 0x0E | ||
64 | #define A_16 0x0F | ||
65 | |||
66 | #define B_1 0x10 | ||
67 | #define B_2 0x11 | ||
68 | #define B_3 0x12 | ||
69 | #define B_4 0x13 | ||
70 | #define B_5 0x14 | ||
71 | #define B_6 0x15 | ||
72 | #define B_7 0x16 | ||
73 | #define B_8 0x17 | ||
74 | #define B_9 0x18 | ||
75 | #define B_10 0x19 | ||
76 | #define B_11 0x1A | ||
77 | #define B_12 0x1B | ||
78 | #define B_13 0x1C | ||
79 | #define B_14 0x1D | ||
80 | #define B_15 0x1E | ||
81 | #define B_16 0x1F | ||
82 | |||
83 | #define C_1 0x20 | ||
84 | #define C_2 0x21 | ||
85 | #define C_3 0x22 | ||
86 | #define C_4 0x23 | ||
87 | #define C_5 0x24 | ||
88 | #define C_6 0x25 | ||
89 | #define C_7 0x26 | ||
90 | #define C_8 0x27 | ||
91 | #define C_9 0x28 | ||
92 | #define C_10 0x29 | ||
93 | #define C_11 0x2A | ||
94 | #define C_12 0x2B | ||
95 | #define C_13 0x2C | ||
96 | #define C_14 0x2D | ||
97 | #define C_15 0x2E | ||
98 | #define C_16 0x2F | ||
99 | |||
100 | #define D_1 0x30 | ||
101 | #define D_2 0x31 | ||
102 | #define D_3 0x32 | ||
103 | #define D_4 0x33 | ||
104 | #define D_5 0x34 | ||
105 | #define D_6 0x35 | ||
106 | #define D_7 0x36 | ||
107 | #define D_8 0x37 | ||
108 | #define D_9 0x38 | ||
109 | #define D_10 0x39 | ||
110 | #define D_11 0x3A | ||
111 | #define D_12 0x3B | ||
112 | #define D_13 0x3C | ||
113 | #define D_14 0x3D | ||
114 | #define D_15 0x3E | ||
115 | #define D_16 0x3F | ||
116 | |||
117 | #define E_1 0x40 | ||
118 | #define E_2 0x41 | ||
119 | #define E_3 0x42 | ||
120 | #define E_4 0x43 | ||
121 | #define E_5 0x44 | ||
122 | #define E_6 0x45 | ||
123 | #define E_7 0x46 | ||
124 | #define E_8 0x47 | ||
125 | #define E_9 0x48 | ||
126 | #define E_10 0x49 | ||
127 | #define E_11 0x4A | ||
128 | #define E_12 0x4B | ||
129 | #define E_13 0x4C | ||
130 | #define E_14 0x4D | ||
131 | #define E_15 0x4E | ||
132 | #define E_16 0x4F | ||
133 | |||
134 | #define F_1 0x50 | ||
135 | #define F_2 0x51 | ||
136 | #define F_3 0x52 | ||
137 | #define F_4 0x53 | ||
138 | #define F_5 0x54 | ||
139 | #define F_6 0x55 | ||
140 | #define F_7 0x56 | ||
141 | #define F_8 0x57 | ||
142 | #define F_9 0x58 | ||
143 | #define F_10 0x59 | ||
144 | #define F_11 0x5A | ||
145 | #define F_12 0x5B | ||
146 | #define F_13 0x5C | ||
147 | #define F_14 0x5D | ||
148 | #define F_15 0x5E | ||
149 | #define F_16 0x5F | ||
150 | |||
151 | #define G_1 0x60 | ||
152 | #define G_2 0x61 | ||
153 | #define G_3 0x62 | ||
154 | #define G_4 0x63 | ||
155 | #define G_5 0x64 | ||
156 | #define G_6 0x65 | ||
157 | #define G_7 0x66 | ||
158 | #define G_8 0x67 | ||
159 | #define G_9 0x68 | ||
160 | #define G_10 0x69 | ||
161 | #define G_11 0x6A | ||
162 | #define G_12 0x6B | ||
163 | #define G_13 0x6C | ||
164 | #define G_14 0x6D | ||
165 | #define G_15 0x6E | ||
166 | #define G_16 0x6F | ||
167 | |||
168 | #define H_1 0x70 | ||
169 | #define H_2 0x71 | ||
170 | #define H_3 0x72 | ||
171 | #define H_4 0x73 | ||
172 | #define H_5 0x74 | ||
173 | #define H_6 0x75 | ||
174 | #define H_7 0x76 | ||
175 | #define H_8 0x77 | ||
176 | #define H_9 0x78 | ||
177 | #define H_10 0x79 | ||
178 | #define H_11 0x7A | ||
179 | #define H_12 0x7B | ||
180 | #define H_13 0x7C | ||
181 | #define H_14 0x7D | ||
182 | #define H_15 0x7E | ||
183 | #define H_16 0x7F | ||
184 | |||
185 | #define I_1 0x80 | ||
186 | #define I_2 0x81 | ||
187 | #define I_3 0x82 | ||
188 | #define I_4 0x83 | ||
189 | #define I_5 0x84 | ||
190 | #define I_6 0x85 | ||
191 | #define I_7 0x86 | ||
192 | #define I_8 0x87 | ||
193 | #define I_9 0x88 | ||
194 | #define I_10 0x89 | ||
195 | #define I_11 0x8A | ||
196 | #define I_12 0x8B | ||
197 | #define I_13 0x8C | ||
198 | #define I_14 0x8D | ||
199 | #define I_15 0x8E | ||
200 | #define I_16 0x8F | ||
201 | |||
202 | #define J_1 0x90 | ||
203 | #define J_2 0x91 | ||
204 | #define J_3 0x92 | ||
205 | #define J_4 0x93 | ||
206 | #define J_5 0x94 | ||
207 | #define J_6 0x95 | ||
208 | #define J_7 0x96 | ||
209 | #define J_8 0x97 | ||
210 | #define J_9 0x98 | ||
211 | #define J_10 0x99 | ||
212 | #define J_11 0x9A | ||
213 | #define J_12 0x9B | ||
214 | #define J_13 0x9C | ||
215 | #define J_14 0x9D | ||
216 | #define J_15 0x9E | ||
217 | #define J_16 0x9F | ||
218 | |||
219 | #define K_1 0xA0 | ||
220 | #define K_2 0xA1 | ||
221 | #define K_3 0xA2 | ||
222 | #define K_4 0xA3 | ||
223 | #define K_5 0xA4 | ||
224 | #define K_6 0xA5 | ||
225 | #define K_7 0xA6 | ||
226 | #define K_8 0xA7 | ||
227 | #define K_9 0xA8 | ||
228 | #define K_10 0xA9 | ||
229 | #define K_11 0xAA | ||
230 | #define K_12 0xAB | ||
231 | #define K_13 0xAC | ||
232 | #define K_14 0xAD | ||
233 | #define K_15 0xAE | ||
234 | #define K_16 0xAF | ||
235 | |||
236 | #define L_1 0xB0 | ||
237 | #define L_2 0xB1 | ||
238 | #define L_3 0xB2 | ||
239 | #define L_4 0xB3 | ||
240 | #define L_5 0xB4 | ||
241 | #define L_6 0xB5 | ||
242 | #define L_7 0xB6 | ||
243 | #define L_8 0xB7 | ||
244 | #define L_9 0xB8 | ||
245 | #define L_10 0xB9 | ||
246 | #define L_11 0xBA | ||
247 | #define L_12 0xBB | ||
248 | #define L_13 0xBC | ||
249 | #define L_14 0xBD | ||
250 | #define L_15 0xBE | ||
251 | #define L_16 0xBF | ||
diff --git a/keyboards/k_type/k_type.c b/keyboards/k_type/k_type.c index ae62f0e72..567ad2843 100644 --- a/keyboards/k_type/k_type.c +++ b/keyboards/k_type/k_type.c | |||
@@ -17,6 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
17 | 17 | ||
18 | #include "k_type.h" | 18 | #include "k_type.h" |
19 | 19 | ||
20 | #include "is31fl3733.h" | ||
21 | |||
20 | #ifdef RGB_MATRIX_ENABLE | 22 | #ifdef RGB_MATRIX_ENABLE |
21 | const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { | 23 | const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { |
22 | { 0, B_1, A_1, C_1 }, | 24 | { 0, B_1, A_1, C_1 }, |
@@ -45,11 +47,11 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { | |||
45 | { 0, E_7, D_7, F_7 }, | 47 | { 0, E_7, D_7, F_7 }, |
46 | { 0, E_8, D_8, F_8 }, | 48 | { 0, E_8, D_8, F_8 }, |
47 | { 0, E_9, D_9, F_9 }, | 49 | { 0, E_9, D_9, F_9 }, |
48 | { 0, E_10, D_1, F_10 }, | 50 | { 0, E_10, D_10, F_10 }, |
49 | { 0, E_11, D_1, F_11 }, | 51 | { 0, E_11, D_11, F_11 }, |
50 | { 0, E_12, D_1, F_12 }, | 52 | { 0, E_12, D_12, F_12 }, |
51 | { 0, E_13, D_1, F_13 }, | 53 | { 0, E_13, D_13, F_13 }, |
52 | { 0, E_14, D_1, F_14 }, | 54 | { 0, E_14, D_14, F_14 }, |
53 | { 0, E_15, D_15, F_15 }, | 55 | { 0, E_15, D_15, F_15 }, |
54 | { 0, E_16, D_16, F_16 }, | 56 | { 0, E_16, D_16, F_16 }, |
55 | 57 | ||
@@ -62,11 +64,11 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { | |||
62 | { 0, H_7, G_7, I_7 }, | 64 | { 0, H_7, G_7, I_7 }, |
63 | { 0, H_8, G_8, I_8 }, | 65 | { 0, H_8, G_8, I_8 }, |
64 | { 0, H_9, G_9, I_9 }, | 66 | { 0, H_9, G_9, I_9 }, |
65 | { 0, H_10, G_1, I_10 }, | 67 | { 0, H_10, G_10, I_10 }, |
66 | { 0, H_11, G_1, I_11 }, | 68 | { 0, H_11, G_11, I_11 }, |
67 | { 0, H_12, G_1, I_12 }, | 69 | { 0, H_12, G_12, I_12 }, |
68 | { 0, H_13, G_1, I_13 }, | 70 | { 0, H_13, G_13, I_13 }, |
69 | { 0, H_14, G_1, I_14 }, | 71 | { 0, H_14, G_14, I_14 }, |
70 | { 0, H_15, G_15, I_15 }, | 72 | { 0, H_15, G_15, I_15 }, |
71 | { 0, H_16, G_16, I_16 }, | 73 | { 0, H_16, G_16, I_16 }, |
72 | 74 | ||
@@ -79,106 +81,123 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { | |||
79 | { 0, K_7, J_7, L_7 }, | 81 | { 0, K_7, J_7, L_7 }, |
80 | { 0, K_8, J_8, L_8 }, | 82 | { 0, K_8, J_8, L_8 }, |
81 | { 0, K_9, J_9, L_9 }, | 83 | { 0, K_9, J_9, L_9 }, |
82 | { 0, K_10, J_1, L_10 }, | 84 | { 0, K_10, J_10, L_10 }, |
83 | { 0, K_11, J_1, L_11 }, | 85 | { 0, K_11, J_11, L_11 }, |
84 | { 0, K_12, J_1, L_12 }, | 86 | { 0, K_12, J_12, L_12 }, |
85 | { 0, K_13, J_1, L_13 }, | 87 | { 0, K_13, J_13, L_13 }, |
86 | { 0, K_14, J_1, L_14 }, | 88 | { 0, K_14, J_14, L_14 }, |
87 | { 0, K_15, J_15, L_15 }, | 89 | { 0, K_15, J_15, L_15 }, |
88 | { 0, K_16, J_16, L_16 }, | 90 | { 0, K_16, J_16, L_16 }, |
89 | 91 | ||
90 | // Driver 2 is on I2C2 - currently not usable with i2c_master | 92 | // Driver 2 is on I2C2 - currently not usable with i2c_master |
91 | //{ 1, B_1, A_1, C_1 }, | 93 | { 1, B_1, A_1, C_1 }, |
92 | //{ 1, B_2, A_2, C_2 }, | 94 | { 1, B_2, A_2, C_2 }, |
93 | //{ 1, B_3, A_3, C_3 }, | 95 | { 1, B_3, A_3, C_3 }, |
94 | //{ 1, B_4, A_4, C_4 }, | 96 | { 1, B_4, A_4, C_4 }, |
95 | //{ 1, B_5, A_5, C_5 }, | 97 | { 1, B_5, A_5, C_5 }, |
96 | //{ 1, B_6, A_6, C_6 }, | 98 | { 1, B_6, A_6, C_6 }, |
97 | //{ 1, B_7, A_7, C_7 }, | 99 | { 1, B_7, A_7, C_7 }, |
98 | //{ 1, B_8, A_8, C_8 }, | 100 | { 1, B_8, A_8, C_8 }, |
99 | //{ 1, B_9, A_9, C_9 }, | 101 | { 1, B_9, A_9, C_9 }, |
100 | //{ 1, B_10, A_10, C_10 }, | 102 | { 1, B_10, A_10, C_10 }, |
101 | //{ 1, B_11, A_11, C_11 }, | 103 | { 1, B_11, A_11, C_11 }, |
102 | //{ 1, B_12, A_12, C_12 }, | 104 | { 1, B_12, A_12, C_12 }, |
103 | //{ 1, B_13, A_13, C_13 }, | 105 | { 1, B_13, A_13, C_13 }, |
104 | //{ 1, B_14, A_14, C_14 }, | 106 | { 1, B_14, A_14, C_14 }, |
105 | //{ 1, B_15, A_15, C_15 }, | 107 | { 1, B_15, A_15, C_15 }, |
106 | //{ 1, B_16, A_16, C_16 }, | 108 | { 1, B_16, A_16, C_16 }, |
107 | 109 | ||
108 | //{ 1, E_1, D_1, F_1 }, | 110 | { 1, E_1, D_1, F_1 }, |
109 | //{ 1, E_2, D_2, F_2 }, | 111 | { 1, E_2, D_2, F_2 }, |
110 | //{ 1, E_3, D_3, F_3 }, | 112 | { 1, E_3, D_3, F_3 }, |
111 | //{ 1, E_4, D_4, F_4 }, | 113 | { 1, E_4, D_4, F_4 }, |
112 | //{ 1, E_5, D_5, F_5 }, | 114 | { 1, E_5, D_5, F_5 }, |
113 | //{ 1, E_6, D_6, F_6 }, | 115 | { 1, E_6, D_6, F_6 }, |
114 | //{ 1, E_7, D_7, F_7 }, | 116 | { 1, E_7, D_7, F_7 }, |
115 | //{ 1, E_8, D_8, F_8 }, | 117 | { 1, E_8, D_8, F_8 }, |
116 | //{ 1, E_9, D_9, F_9 }, | 118 | { 1, E_9, D_9, F_9 }, |
117 | //{ 1, E_10, D_1, F_10 }, | 119 | { 1, E_10, D_10, F_10 }, |
118 | //{ 1, E_11, D_1, F_11 }, | 120 | { 1, E_11, D_11, F_11 }, |
119 | //{ 1, E_12, D_1, F_12 }, | 121 | { 1, E_12, D_12, F_12 }, |
120 | //{ 1, E_13, D_1, F_13 }, | 122 | { 1, E_13, D_13, F_13 }, |
121 | //{ 1, E_14, D_1, F_14 }, | 123 | { 1, E_14, D_14, F_14 }, |
122 | //{ 1, E_15, D_15, F_15 }, | 124 | { 1, E_15, D_15, F_15 }, |
123 | //{ 1, E_16, D_16, F_16 }, | 125 | { 1, E_16, D_16, F_16 }, |
124 | 126 | ||
125 | //{ 1, H_1, G_1, I_1 }, | 127 | { 1, H_1, G_1, I_1 }, |
126 | //{ 1, H_2, G_2, I_2 }, | 128 | { 1, H_2, G_2, I_2 }, |
127 | //{ 1, H_3, G_3, I_3 }, | 129 | { 1, H_3, G_3, I_3 }, |
128 | //{ 1, H_4, G_4, I_4 }, | 130 | { 1, H_4, G_4, I_4 }, |
129 | //{ 1, H_5, G_5, I_5 }, | 131 | { 1, H_5, G_5, I_5 }, |
130 | //{ 1, H_6, G_6, I_6 }, | 132 | { 1, H_6, G_6, I_6 }, |
131 | //{ 1, H_7, G_7, I_7 }, | 133 | { 1, H_7, G_7, I_7 }, |
132 | //{ 1, H_8, G_8, I_8 }, | 134 | { 1, H_8, G_8, I_8 }, |
133 | //{ 1, H_9, G_9, I_9 }, | 135 | { 1, H_9, G_9, I_9 }, |
134 | //{ 1, H_10, G_1, I_10 }, | 136 | { 1, H_10, G_10, I_10 }, |
135 | //{ 1, H_11, G_1, I_11 }, | 137 | { 1, H_11, G_11, I_11 }, |
136 | //{ 1, H_12, G_1, I_12 }, | 138 | { 1, H_12, G_12, I_12 }, |
137 | //{ 1, H_13, G_1, I_13 }, | 139 | { 1, H_13, G_13, I_13 }, |
138 | //{ 1, H_14, G_1, I_14 }, | 140 | { 1, H_14, G_14, I_14 }, |
139 | //{ 1, H_15, G_15, I_15 }, | 141 | { 1, H_15, G_15, I_15 }, |
140 | //{ 1, H_16, G_16, I_16 }, | 142 | { 1, H_16, G_16, I_16 }, |
141 | 143 | ||
142 | //{ 1, K_1, J_1, L_1 }, | 144 | { 1, K_1, J_1, L_1 }, |
143 | //{ 1, K_2, J_2, L_2 }, | 145 | { 1, K_2, J_2, L_2 }, |
144 | //{ 1, K_3, J_3, L_3 }, | 146 | { 1, K_3, J_3, L_3 }, |
145 | //{ 1, K_4, J_4, L_4 }, | 147 | { 1, K_4, J_4, L_4 }, |
146 | //{ 1, K_5, J_5, L_5 }, | 148 | { 1, K_5, J_5, L_5 }, |
147 | //{ 1, K_6, J_6, L_6 }, | 149 | { 1, K_6, J_6, L_6 }, |
148 | //{ 1, K_7, J_7, L_7 } | 150 | { 1, K_7, J_7, L_7 } |
149 | }; | 151 | }; |
150 | 152 | ||
151 | led_config_t g_led_config = { | 153 | led_config_t g_led_config = { |
152 | { | 154 | { |
153 | // Key Matrix to LED Index | 155 | // Key Matrix to LED Index |
154 | { 0, 10, 20, 29, 38, 47, 57, NO_LED, NO_LED, NO_LED }, | 156 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, |
155 | { 1, 11, 21, NO_LED, 39, 48, 58, NO_LED, NO_LED, NO_LED }, | 157 | { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }, |
156 | { 2, 12, 22, 30, 40, 49, 59, NO_LED, NO_LED, NO_LED }, | 158 | { 20, 21, 22, 23, 24, 25, 26, 27, 28, NO_LED }, |
157 | { 3, 13, 23, 31, 41, 50, 60, NO_LED, NO_LED, NO_LED }, | 159 | { 29, NO_LED, 30, 31, 32, 33, 34, 35, 36, 37 }, |
158 | { 4, 14, 24, 32, 42, 51, 61, NO_LED, NO_LED, NO_LED }, | 160 | { 38, 39, 40, 41, 42, 43, 44, 45, 46, NO_LED }, |
159 | { 5, 15, 25, 33, 43, 52, NO_LED, NO_LED, NO_LED, NO_LED }, | 161 | { 47, 48, 49, 50, 51, 52, 53, 54, 55, 56 }, |
160 | { 6, 16, 26, 34, 44, 53, 62, NO_LED, NO_LED, NO_LED }, | 162 | { 57, 58, 59, 60, 61, NO_LED, 62, NO_LED, 63, NO_LED }, |
161 | { 7, 17, 27, 35, 45, 54, NO_LED, NO_LED, NO_LED, NO_LED }, | 163 | { 64, 65, 66, 67, 68, 69, 70, 71, 72, 73 }, |
162 | { 8, 18, 28, 36, 46, 55, 63, NO_LED, NO_LED, NO_LED }, | 164 | { NO_LED, 74, NO_LED, 75, 76, 77, 78, 79, 80, 81 }, |
163 | { 9, 19, NO_LED, 37, NO_LED, 56, NO_LED, NO_LED, NO_LED, NO_LED } | 165 | { 82, 83, 84, 85, 86, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED } |
164 | }, { | 166 | }, { |
165 | // LED Index to Physical Position | 167 | // LED Index to Physical Position |
168 | // Key LED | ||
166 | { 0, 0 }, { 26.35, 0 }, { 39.53, 0 }, { 52.71, 0 }, { 65.88, 0 }, { 79.06, 0 }, { 92.24, 0 }, { 105.41, 0 }, { 118.59, 0 }, { 131.77, 0 }, { 144.94, 0 }, { 158.12, 0 }, { 171.29, 0 }, { 197.65, 0 }, { 210.82, 0 }, { 224, 0 }, | 169 | { 0, 0 }, { 26.35, 0 }, { 39.53, 0 }, { 52.71, 0 }, { 65.88, 0 }, { 79.06, 0 }, { 92.24, 0 }, { 105.41, 0 }, { 118.59, 0 }, { 131.77, 0 }, { 144.94, 0 }, { 158.12, 0 }, { 171.29, 0 }, { 197.65, 0 }, { 210.82, 0 }, { 224, 0 }, |
167 | 170 | ||
168 | { 0, 21.33 }, { 13.18, 21.33 }, { 26.35, 21.33 }, { 39.53, 21.33 }, { 52.71, 21.33 }, { 65.88, 21.33 }, { 79.06, 21.33 }, { 92.24, 21.33 }, { 105.41, 21.33 }, { 118.59, 21.33 }, { 131.77, 21.33 }, { 144.94, 21.33 }, { 158.12, 21.33 }, { 171.29, 21.33 }, { 197.65, 21.33 }, { 210.82, 21.33 }, { 224, 21.33 }, | 171 | { 0, 21.33 }, { 13.18, 21.33 }, { 26.35, 21.33 }, { 39.53, 21.33 }, { 52.71, 21.33 }, { 65.88, 21.33 }, { 79.06, 21.33 }, { 92.24, 21.33 }, { 105.41, 21.33 }, { 118.59, 21.33 }, { 131.77, 21.33 }, { 144.94, 21.33 }, { 158.12, 21.33 }, { 171.29, 21.33 }, { 197.65, 21.33 }, { 210.82, 21.33 }, { 224, 21.33 }, |
169 | { 0, 32 }, { 13.18, 32 }, { 26.35, 32 }, { 39.53, 32 }, { 52.71, 32 }, { 65.88, 32 }, { 79.06, 32 }, { 92.24, 32 }, { 105.41, 32 }, { 118.59, 32 }, { 131.77, 32 }, { 144.94, 32 }, { 158.12, 32 }, { 171.29, 32 }, { 197.65, 32 }, { 210.82, 32 }, { 224, 32 }, | 172 | { 0, 32 }, { 13.18, 32 }, { 26.35, 32 }, { 39.53, 32 }, { 52.71, 32 }, { 65.88, 32 }, { 79.06, 32 }, { 92.24, 32 }, { 105.41, 32 }, { 118.59, 32 }, { 131.77, 32 }, { 144.94, 32 }, { 158.12, 32 }, { 171.29, 32 }, { 197.65, 32 }, { 210.82, 32 }, { 224, 32 }, |
170 | { 0, 42.67 }, { 13.18, 42.67 }, { 26.35, 42.67 }, { 39.53, 42.67 }, { 52.71, 42.67 }, { 65.88, 42.67 }, { 79.06, 42.67 }, { 92.24, 42.67 }, { 105.41, 42.67 }, { 118.59, 42.67 }, { 131.77, 42.67 }, { 144.94, 42.67 }, { 171.29, 42.67 }, | 173 | { 0, 42.67 }, { 13.18, 42.67 }, { 26.35, 42.67 }, { 39.53, 42.67 }, { 52.71, 42.67 }, { 65.88, 42.67 }, { 79.06, 42.67 }, { 92.24, 42.67 }, { 105.41, 42.67 }, { 118.59, 42.67 }, { 131.77, 42.67 }, { 144.94, 42.67 }, { 171.29, 42.67 }, |
171 | { 0, 53.33 }, //{ 26.35, 53.33 }, { 39.53, 53.33 }, { 52.71, 53.33 }, { 65.88, 53.33 }, { 79.06, 53.33 }, { 92.24, 53.33 }, { 105.41, 53.33 }, { 118.59, 53.33 }, { 131.77, 53.33 }, { 144.94, 53.33 }, { 171.29, 53.33 }, { 210.82, 53.33 }, | 174 | { 0, 53.33 }, { 26.35, 53.33 }, { 39.53, 53.33 }, { 52.71, 53.33 }, { 65.88, 53.33 }, { 79.06, 53.33 }, { 92.24, 53.33 }, { 105.41, 53.33 }, { 118.59, 53.33 }, { 131.77, 53.33 }, { 144.94, 53.33 }, { 171.29, 53.33 }, { 210.82, 53.33 }, |
172 | //{ 0, 64 }, { 13.18, 64 }, { 26.35, 64 }, { 79.06, 64 }, { 131.77, 64 }, { 144.94, 64 }, { 158.12, 64 }, { 171.29, 64 }, { 197.65, 64 }, { 210.82, 64 }, { 224, 64 } | 175 | { 0, 64 }, { 13.18, 64 }, { 26.35, 64 }, { 79.06, 64 }, { 131.77, 64 }, { 144.94, 64 }, { 158.12, 64 }, { 171.29, 64 }, { 197.65, 64 }, { 210.82, 64 }, { 224, 64 }, |
176 | |||
177 | // Underglow LED | ||
178 | { 224, 64 }, { 206.77, 64 }, { 189.54, 64 }, { 172.31, 64 }, { 155.08, 64 }, { 137.85, 64 }, { 120.61, 64 }, { 103.38, 64 }, { 86.15, 64 }, { 68.92, 64 }, { 51.69, 64 }, { 34.46, 64 }, { 17.23, 64 }, { 0, 64 }, | ||
179 | { 0, 42.67 }, { 0, 21.33 }, | ||
180 | { 0, 0 }, { 17.23, 0 }, { 34.46, 0 }, { 51.69, 0 }, { 68.92, 0 }, { 86.15, 0 }, { 103.38, 0 }, { 120.61, 0 }, { 137.85, 0 }, { 155.08, 0 }, { 172.31, 0 }, { 189.54, 0 }, { 206.77, 0 }, { 224, 0 }, | ||
181 | { 224, 21.33 }, { 224, 42.67 } | ||
173 | }, { | 182 | }, { |
174 | // LED Index to Flag | 183 | // LED Index to Flag |
175 | 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | 184 | //Key LED |
185 | 1, 4, 4, 4, 4, 1, 1, 1, 1, 4, 4, 4, 4, 1, 1, 1, | ||
186 | |||
187 | 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 4, 4, 4, | ||
188 | 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | ||
189 | 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, | ||
190 | 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, | ||
191 | 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, | ||
192 | |||
193 | // Underglow LED | ||
194 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | ||
195 | |||
196 | 2, 2, | ||
197 | |||
198 | 2, 2, | ||
176 | 199 | ||
177 | 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | 200 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
178 | 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | ||
179 | 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, | ||
180 | 1, //4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, | ||
181 | //1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1 | ||
182 | } | 201 | } |
183 | }; | 202 | }; |
184 | #endif | 203 | #endif |
diff --git a/keyboards/k_type/keymaps/andrew-fahmy/config.h b/keyboards/k_type/keymaps/andrew-fahmy/config.h new file mode 100644 index 000000000..47d20119e --- /dev/null +++ b/keyboards/k_type/keymaps/andrew-fahmy/config.h | |||
@@ -0,0 +1,52 @@ | |||
1 | /* Copyright 2021 Andrew Fahmy | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #pragma once | ||
18 | |||
19 | |||
20 | #ifdef RGB_MATRIX_ENABLE | ||
21 | // # define RGB_MATRIX_FRAMEBUFFER_EFFECTS | ||
22 | // # define RGB_MATRIX_KEYPRESSES | ||
23 | # define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_RAINDROPS | ||
24 | |||
25 | # define DEBUG_MATRIX_SCAN_RATE | ||
26 | |||
27 | # define RGB_MATRIX_LED_FLUSH_LIMIT 100 | ||
28 | // # define RGB_MATRIX_LED_PROCESS_LIMIT 2 | ||
29 | |||
30 | // i2c_master defines | ||
31 | # define I2C_COUNT 2 | ||
32 | |||
33 | # define I2C1_BANK GPIOB | ||
34 | # define I2C1_SCL 0 // A2 on pinout = B0 | ||
35 | # define I2C1_SDA 1 // A2 on pinout = B1 | ||
36 | # define I2C1_SCL_PAL_MODE PAL_MODE_ALTERNATIVE_2 | ||
37 | # define I2C1_SDA_PAL_MODE PAL_MODE_ALTERNATIVE_2 | ||
38 | |||
39 | # define USE_I2C2 | ||
40 | # define I2C2_BANK GPIOC | ||
41 | # define I2C2_SCL 10 // A2 on pinout = C10 | ||
42 | # define I2C2_SDA 11 // A2 on pinout = C11 | ||
43 | # define I2C2_SCL_PAL_MODE PAL_MODE_ALTERNATIVE_2 | ||
44 | # define I2C2_SDA_PAL_MODE PAL_MODE_ALTERNATIVE_2 | ||
45 | |||
46 | # define DRIVER_ADDR_1 0b1010000 | ||
47 | # define DRIVER_ADDR_2 0b1010000 | ||
48 | # define DRIVER_COUNT 2 | ||
49 | # define DRIVER_1_LED_TOTAL 64 | ||
50 | # define DRIVER_2_LED_TOTAL 55 | ||
51 | # define DRIVER_LED_TOTAL (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL) | ||
52 | #endif | ||
diff --git a/keyboards/k_type/keymaps/andrew-fahmy/keymap.c b/keyboards/k_type/keymaps/andrew-fahmy/keymap.c new file mode 100644 index 000000000..53460516c --- /dev/null +++ b/keyboards/k_type/keymaps/andrew-fahmy/keymap.c | |||
@@ -0,0 +1,60 @@ | |||
1 | /* Copyright 2021 Andrew Fahmy | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include QMK_KEYBOARD_H | ||
18 | |||
19 | enum layer_names { | ||
20 | _MAIN, | ||
21 | _L1 | ||
22 | }; | ||
23 | |||
24 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
25 | [_MAIN] = LAYOUT_tkl_ansi( | ||
26 | KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PSCR, KC_SLCK, KC_PAUS, | ||
27 | |||
28 | KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_INS, KC_HOME, KC_PGUP, | ||
29 | KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL, KC_END, KC_PGDN, | ||
30 | MO(_L1), KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, | ||
31 | KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, | ||
32 | KC_LCTL, _______, KC_LALT, KC_SPC, KC_RALT, MO(_L1), KC_APP, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT | ||
33 | ), | ||
34 | [_L1] = LAYOUT_tkl_ansi( | ||
35 | EEP_RST, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_TOG, RGB_MOD, _______, | ||
36 | |||
37 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_SPD, RGB_SPI, _______, RGB_HUI, RGB_SAI, RGB_VAI, | ||
38 | _______, KC_MPRV, KC_MPLY, KC_MNXT, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_HUD, RGB_SAD, RGB_VAD, | ||
39 | _______, KC_MUTE, KC_VOLD, KC_VOLU, _______, _______, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, _______, _______, _______, | ||
40 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, | ||
41 | _______, KC_LGUI, _______, _______, _______, _______, _______, _______, _______, _______, _______ | ||
42 | ) | ||
43 | }; | ||
44 | |||
45 | void keyboard_post_init_user(void) { | ||
46 | // Customise these values to desired behaviour | ||
47 | // debug_enable=true; | ||
48 | // debug_matrix=true; | ||
49 | // debug_keyboard=true; | ||
50 | // debug_mouse=true; | ||
51 | } | ||
52 | |||
53 | #ifdef RGB_MATRIX_ENABLE | ||
54 | // Turn off SDB | ||
55 | void keyboard_pre_init_user() { | ||
56 | palSetPadMode(GPIOB, 16, PAL_MODE_OUTPUT_PUSHPULL); | ||
57 | palSetPad(GPIOB, 16); | ||
58 | } | ||
59 | |||
60 | #endif | ||
diff --git a/keyboards/k_type/keymaps/andrew-fahmy/rules.mk b/keyboards/k_type/keymaps/andrew-fahmy/rules.mk new file mode 100644 index 000000000..aad92997d --- /dev/null +++ b/keyboards/k_type/keymaps/andrew-fahmy/rules.mk | |||
@@ -0,0 +1 @@ | |||
RGB_MATRIX_ENABLE = yes | |||
diff --git a/keyboards/k_type/keymaps/rgb/config.h b/keyboards/k_type/keymaps/rgb/config.h index 206b76f2b..4c5d23454 100644 --- a/keyboards/k_type/keymaps/rgb/config.h +++ b/keyboards/k_type/keymaps/rgb/config.h | |||
@@ -2,22 +2,31 @@ | |||
2 | 2 | ||
3 | #ifdef RGB_MATRIX_ENABLE | 3 | #ifdef RGB_MATRIX_ENABLE |
4 | # define RGB_MATRIX_KEYPRESSES | 4 | # define RGB_MATRIX_KEYPRESSES |
5 | # define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_CYCLE_ALL | 5 | # define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_SOLID_COLOR |
6 | |||
7 | # define RGB_MATRIX_LED_FLUSH_LIMIT 100 | ||
8 | |||
6 | 9 | ||
7 | // i2c_master defines | 10 | // i2c_master defines |
11 | # define I2C_COUNT 2 | ||
12 | |||
13 | # define I2C1_BANK GPIOB | ||
8 | # define I2C1_SCL 0 // A2 on pinout = B0 | 14 | # define I2C1_SCL 0 // A2 on pinout = B0 |
9 | # define I2C1_SDA 1 // A2 on pinout = B1 | 15 | # define I2C1_SDA 1 // A2 on pinout = B1 |
10 | # define I2C1_SCL_PAL_MODE PAL_MODE_ALTERNATIVE_2 | 16 | # define I2C1_SCL_PAL_MODE PAL_MODE_ALTERNATIVE_2 |
11 | # define I2C1_SDA_PAL_MODE PAL_MODE_ALTERNATIVE_2 | 17 | # define I2C1_SDA_PAL_MODE PAL_MODE_ALTERNATIVE_2 |
12 | //# define I2C2_SCL 10 // A2 on pinout = C10 | 18 | |
13 | //# define I2C2_SDA 11 // A2 on pinout = C11 | 19 | # define USE_I2C2 |
14 | //# define I2C2_SCL_PAL_MODE PAL_MODE_ALTERNATIVE_2 | 20 | # define I2C2_BANK GPIOC |
15 | //# define I2C2_SDA_PAL_MODE PAL_MODE_ALTERNATIVE_2 | 21 | # define I2C2_SCL 10 // A2 on pinout = C10 |
22 | # define I2C2_SDA 11 // A2 on pinout = C11 | ||
23 | # define I2C2_SCL_PAL_MODE PAL_MODE_ALTERNATIVE_2 | ||
24 | # define I2C2_SDA_PAL_MODE PAL_MODE_ALTERNATIVE_2 | ||
16 | 25 | ||
17 | # define DRIVER_ADDR_1 0b1010000 | 26 | # define DRIVER_ADDR_1 0b1010000 |
18 | # define DRIVER_ADDR_2 0b1010001 | 27 | # define DRIVER_ADDR_2 0b1010000 |
19 | # define DRIVER_COUNT 2 | 28 | # define DRIVER_COUNT 2 |
20 | # define DRIVER_1_LED_TOTAL 64 | 29 | # define DRIVER_1_LED_TOTAL 64 |
21 | //# define DRIVER_2_LED_TOTAL 55 | 30 | # define DRIVER_2_LED_TOTAL 55 |
22 | # define DRIVER_LED_TOTAL DRIVER_1_LED_TOTAL | 31 | # define DRIVER_LED_TOTAL (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL) |
23 | #endif | 32 | #endif |
diff --git a/keyboards/k_type/keymaps/rgb/keymap.c b/keyboards/k_type/keymaps/rgb/keymap.c index 4ed15e5d6..88f5eaa37 100644 --- a/keyboards/k_type/keymaps/rgb/keymap.c +++ b/keyboards/k_type/keymaps/rgb/keymap.c | |||
@@ -8,12 +8,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
8 | KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL, KC_END, KC_PGDN, | 8 | KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL, KC_END, KC_PGDN, |
9 | KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, | 9 | KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, |
10 | KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, | 10 | KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, |
11 | KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, KC_RGUI, MO(1), KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT | 11 | KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(1), KC_APP, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT |
12 | ), | 12 | ), |
13 | [1] = LAYOUT_tkl_ansi( | 13 | [1] = LAYOUT_tkl_ansi( |
14 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_TOG, RGB_MOD, _______, | 14 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_TOG, RGB_MOD, _______, |
15 | 15 | ||
16 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_HUI, RGB_SAI, RGB_VAI, | 16 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_SPD, RGB_SPI, _______, RGB_HUI, RGB_SAI, RGB_VAI, |
17 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_HUD, RGB_SAD, RGB_VAD, | 17 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_HUD, RGB_SAD, RGB_VAD, |
18 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, | 18 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, |
19 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, | 19 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, |
diff --git a/keyboards/k_type/keymaps/rgb/readme.md b/keyboards/k_type/keymaps/rgb/readme.md index 794052c57..330321976 100644 --- a/keyboards/k_type/keymaps/rgb/readme.md +++ b/keyboards/k_type/keymaps/rgb/readme.md | |||
@@ -2,4 +2,6 @@ | |||
2 | 2 | ||
3 | This is an experimental keymap adding support for RGB Matrix on the K-Type. | 3 | This is an experimental keymap adding support for RGB Matrix on the K-Type. |
4 | 4 | ||
5 | The board has two IS31FL3733 LED controllers, but they are each on different I2C buses, which QMK's `i2c_master` implementation currently does not support. As a result, all the keys after the left shift will not be lit. | 5 | The keyboard should now support full RGB lightings. The lighting animations are running at 10 fps for performance reasons. |
6 | You can configure this by changing the `RGB_MATRIX_LED_FLUSH_LIMIT` inside the `config.h` file to a lower value. | ||
7 | For example `RGB_MATRIX_LED_FLUSH_LIMIT 16` would mean that the animations run every 16 ms or at 60 fps. | ||
diff --git a/keyboards/k_type/led.c b/keyboards/k_type/led.c new file mode 100644 index 000000000..421a7f944 --- /dev/null +++ b/keyboards/k_type/led.c | |||
@@ -0,0 +1,53 @@ | |||
1 | /* Copyright 2021 Andrew Fahmy | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include <rgb_matrix.h> | ||
18 | #include "i2c_master.h" | ||
19 | #include "is31fl3733.h" | ||
20 | |||
21 | |||
22 | |||
23 | static void init(void) { | ||
24 | i2c_init(&I2CD1, I2C1_SCL_BANK, I2C1_SDA_BANK, I2C1_SCL, I2C1_SDA); | ||
25 | IS31FL3733_init(0, DRIVER_ADDR_1, 0); | ||
26 | # ifdef USE_I2C2 | ||
27 | i2c_init(&I2CD2, I2C2_SCL_BANK, I2C2_SDA_BANK, I2C2_SCL, I2C2_SDA); | ||
28 | IS31FL3733_init(1, DRIVER_ADDR_2, 0); | ||
29 | # endif | ||
30 | for (int index = 0; index < DRIVER_LED_TOTAL; index++) { | ||
31 | bool enabled = true; | ||
32 | // This only caches it for later | ||
33 | IS31FL3733_set_led_control_register(index, enabled, enabled, enabled); | ||
34 | } | ||
35 | IS31FL3733_update_led_control_registers(DRIVER_ADDR_1, 0); | ||
36 | # ifdef USE_I2C2 | ||
37 | IS31FL3733_update_led_control_registers(DRIVER_ADDR_2, 1); | ||
38 | # endif | ||
39 | } | ||
40 | |||
41 | static void flush(void) { | ||
42 | IS31FL3733_update_pwm_buffers(DRIVER_ADDR_1, 0); | ||
43 | # ifdef USE_I2C2 | ||
44 | IS31FL3733_update_pwm_buffers(DRIVER_ADDR_2, 1); | ||
45 | # endif | ||
46 | } | ||
47 | |||
48 | const rgb_matrix_driver_t rgb_matrix_driver = { | ||
49 | .init = init, | ||
50 | .flush = flush, | ||
51 | .set_color = IS31FL3733_set_color, | ||
52 | .set_color_all = IS31FL3733_set_color_all, | ||
53 | }; \ No newline at end of file | ||
diff --git a/keyboards/k_type/mcuconf.h b/keyboards/k_type/mcuconf.h index 28f3c6cda..1d9ecf610 100644 --- a/keyboards/k_type/mcuconf.h +++ b/keyboards/k_type/mcuconf.h | |||
@@ -51,4 +51,7 @@ | |||
51 | #define KINETIS_I2C_USE_I2C0 TRUE | 51 | #define KINETIS_I2C_USE_I2C0 TRUE |
52 | #define KINETIS_I2C_I2C0_PRIORITY 4 | 52 | #define KINETIS_I2C_I2C0_PRIORITY 4 |
53 | 53 | ||
54 | #define KINETIS_I2C_USE_I2C1 TRUE | ||
55 | #define KINETIS_I2C_I2C0_PRIORITY 4 | ||
56 | |||
54 | #endif /* _MCUCONF_H_ */ | 57 | #endif /* _MCUCONF_H_ */ |
diff --git a/keyboards/k_type/rules.mk b/keyboards/k_type/rules.mk index 18b6e3c8d..8f02bede4 100644 --- a/keyboards/k_type/rules.mk +++ b/keyboards/k_type/rules.mk | |||
@@ -27,7 +27,9 @@ RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow | |||
27 | BLUETOOTH_ENABLE = no # Enable Bluetooth | 27 | BLUETOOTH_ENABLE = no # Enable Bluetooth |
28 | AUDIO_ENABLE = no # Audio output | 28 | AUDIO_ENABLE = no # Audio output |
29 | RGB_MATRIX_ENABLE = no | 29 | RGB_MATRIX_ENABLE = no |
30 | RGB_MATRIX_DRIVER = IS31FL3733 | 30 | RGB_MATRIX_DRIVER = custom |
31 | |||
32 | SRC += i2c_master.c is31fl3733.c led.c | ||
31 | 33 | ||
32 | LAYOUTS = tkl_ansi | 34 | LAYOUTS = tkl_ansi |
33 | 35 | ||