summaryrefslogtreecommitdiff
path: root/keyboards/input_club/k_type
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/input_club/k_type')
-rw-r--r--keyboards/input_club/k_type/config.h6
-rw-r--r--keyboards/input_club/k_type/is31fl3733-dual.c140
-rw-r--r--keyboards/input_club/k_type/is31fl3733-dual.h37
-rw-r--r--keyboards/input_club/k_type/k_type-rgbdriver.c10
-rw-r--r--keyboards/input_club/k_type/k_type.c17
-rw-r--r--keyboards/input_club/k_type/post_rules.mk5
-rw-r--r--keyboards/input_club/k_type/rules.mk5
7 files changed, 127 insertions, 93 deletions
diff --git a/keyboards/input_club/k_type/config.h b/keyboards/input_club/k_type/config.h
index 2a4c7d057c..b3365bd0af 100644
--- a/keyboards/input_club/k_type/config.h
+++ b/keyboards/input_club/k_type/config.h
@@ -103,9 +103,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# define I2C2_SCL_PAL_MODE PAL_MODE_ALTERNATIVE_2
# define I2C2_SDA_PAL_MODE PAL_MODE_ALTERNATIVE_2
-# define DRIVER_ADDR_1 0b1010000
-# define DRIVER_ADDR_2 0b1010000
-# define DRIVER_COUNT 2
+# define DRIVER_ADDR_1 IS31FL3733_I2C_ADDRESS_GND_GND
+# define DRIVER_ADDR_2 IS31FL3733_I2C_ADDRESS_GND_GND
+# define IS31FL3733_DRIVER_COUNT 2
# define DRIVER_1_LED_TOTAL 64
# define DRIVER_2_LED_TOTAL 55
# define RGB_MATRIX_LED_COUNT (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)
diff --git a/keyboards/input_club/k_type/is31fl3733-dual.c b/keyboards/input_club/k_type/is31fl3733-dual.c
index 2dec2b0a26..ea523eea1f 100644
--- a/keyboards/input_club/k_type/is31fl3733-dual.c
+++ b/keyboards/input_club/k_type/is31fl3733-dual.c
@@ -16,46 +16,48 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifdef RGB_MATRIX_ENABLE
-
#include "is31fl3733-dual.h"
#include "i2c_master.h"
#include "wait.h"
-// This is a 7-bit address, that gets left-shifted and bit 0
-// set to 0 for write, 1 for read (as per I2C protocol)
-// The address will vary depending on your wiring:
-// 00 <-> GND
-// 01 <-> SCL
-// 10 <-> SDA
-// 11 <-> VCC
-// ADDR1 represents A1:A0 of the 7-bit address.
-// ADDR2 represents A3:A2 of the 7-bit address.
-// The result is: 0b101(ADDR2)(ADDR1)
-#define ISSI_ADDR_DEFAULT 0x50
-
-#define ISSI_COMMANDREGISTER 0xFD
-#define ISSI_COMMANDREGISTER_WRITELOCK 0xFE
-#define ISSI_INTERRUPTMASKREGISTER 0xF0
-#define ISSI_INTERRUPTSTATUSREGISTER 0xF1
-
-#define ISSI_PAGE_LEDCONTROL 0x00 // PG0
-#define ISSI_PAGE_PWM 0x01 // PG1
-#define ISSI_PAGE_AUTOBREATH 0x02 // PG2
-#define ISSI_PAGE_FUNCTION 0x03 // PG3
-
-#define ISSI_REG_CONFIGURATION 0x00 // PG3
-#define ISSI_REG_GLOBALCURRENT 0x01 // PG3
-#define ISSI_REG_RESET 0x11 // PG3
-#define ISSI_REG_SWPULLUP 0x0F // PG3
-#define ISSI_REG_CSPULLUP 0x10 // PG3
-
-#ifndef ISSI_TIMEOUT
-# define ISSI_TIMEOUT 5000
+#define IS31FL3733_COMMANDREGISTER 0xFD
+#define IS31FL3733_COMMANDREGISTER_WRITELOCK 0xFE
+#define IS31FL3733_INTERRUPTMASKREGISTER 0xF0
+#define IS31FL3733_INTERRUPTSTATUSREGISTER 0xF1
+
+#define IS31FL3733_PAGE_LEDCONTROL 0x00 // PG0
+#define IS31FL3733_PAGE_PWM 0x01 // PG1
+#define IS31FL3733_PAGE_AUTOBREATH 0x02 // PG2
+#define IS31FL3733_PAGE_FUNCTION 0x03 // PG3
+
+#define IS31FL3733_REG_CONFIGURATION 0x00 // PG3
+#define IS31FL3733_REG_GLOBALCURRENT 0x01 // PG3
+#define IS31FL3733_REG_RESET 0x11 // PG3
+#define IS31FL3733_REG_SWPULLUP 0x0F // PG3
+#define IS31FL3733_REG_CSPULLUP 0x10 // PG3
+
+#ifndef IS31FL3733_I2C_TIMEOUT
+# define IS31FL3733_I2C_TIMEOUT 100
+#endif
+
+#ifndef IS31FL3733_I2C_PERSISTENCE
+# define IS31FL3733_I2C_PERSISTENCE 0
+#endif
+
+#ifndef IS31FL3733_PWM_FREQUENCY
+# define IS31FL3733_PWM_FREQUENCY IS31FL3733_PWM_FREQUENCY_8K4_HZ // PFS - IS31FL3733B only
+#endif
+
+#ifndef IS31FL3733_SWPULLUP
+# define IS31FL3733_SWPULLUP IS31FL3733_PUR_0R
+#endif
+
+#ifndef IS31FL3733_CSPULLUP
+# define IS31FL3733_CSPULLUP IS31FL3733_PUR_0R
#endif
-#ifndef ISSI_PERSISTENCE
-# define ISSI_PERSISTENCE 0
+#ifndef IS31FL3733_GLOBALCURRENT
+# define IS31FL3733_GLOBALCURRENT 0xFF
#endif
// Transfer buffer for TWITransmitData()
@@ -67,25 +69,25 @@ uint8_t g_twi_transfer_buffer[20];
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3733_write_pwm_buffer() but it's
// probably not worth the extra complexity.
-uint8_t g_pwm_buffer[DRIVER_COUNT][192];
-bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
+uint8_t g_pwm_buffer[IS31FL3733_DRIVER_COUNT][192];
+bool g_pwm_buffer_update_required[IS31FL3733_DRIVER_COUNT] = {false};
-uint8_t g_led_control_registers[DRIVER_COUNT][24] = {{0}, {0}};
-bool g_led_control_registers_update_required[DRIVER_COUNT] = {false};
+uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][24] = {{0}, {0}};
+bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT] = {false};
bool is31fl3733_write_register(uint8_t index, uint8_t addr, uint8_t reg, uint8_t data) {
// If the transaction fails function returns false.
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
-#if ISSI_PERSISTENCE > 0
- for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
- if (i2c_transmit(index, addr << 1, g_twi_transfer_buffer, 2, TIME_US2I(ISSI_TIMEOUT)) != 0) {
+#if IS31FL3733_I2C_PERSISTENCE > 0
+ for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) {
+ if (i2c_transmit(index, addr << 1, g_twi_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
}
#else
- if (i2c_transmit(index, addr << 1, g_twi_transfer_buffer, 2, TIME_US2I(ISSI_TIMEOUT)) != 0) {
+ if (i2c_transmit(index, addr << 1, g_twi_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
#endif
@@ -108,14 +110,14 @@ bool is31fl3733_write_pwm_buffer(uint8_t index, uint8_t addr, uint8_t *pwm_buffe
g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
}
-#if ISSI_PERSISTENCE > 0
- for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
- if (i2c_transmit(index, addr << 1, g_twi_transfer_buffer, 17, TIME_US2I(ISSI_TIMEOUT)) != 0) {
+#if IS31FL3733_I2C_PERSISTENCE > 0
+ for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) {
+ if (i2c_transmit(index, addr << 1, g_twi_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
}
#else
- if (i2c_transmit(index, addr << 1, g_twi_transfer_buffer, 17, TIME_US2I(ISSI_TIMEOUT)) != 0) {
+ if (i2c_transmit(index, addr << 1, g_twi_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
#endif
@@ -131,38 +133,52 @@ void is31fl3733_init(uint8_t bus, uint8_t addr, uint8_t sync) {
// Sync is passed so set it according to the datasheet.
// Unlock the command register.
- is31fl3733_write_register(bus, addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+ is31fl3733_write_register(bus, addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5);
+
// Select PG0
- is31fl3733_write_register(bus, addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
+ is31fl3733_write_register(bus, addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL);
// Turn off all LEDs.
for (int i = 0x00; i <= 0x17; i++) {
is31fl3733_write_register(bus, addr, i, 0x00);
}
+
// Unlock the command register.
- is31fl3733_write_register(bus, addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+ is31fl3733_write_register(bus, addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5);
+
// Select PG1
- is31fl3733_write_register(bus, addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
+ is31fl3733_write_register(bus, addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_PWM);
// Set PWM on all LEDs to 0
// No need to setup Breath registers to PWM as that is the default.
for (int i = 0x00; i <= 0xBF; i++) {
is31fl3733_write_register(bus, addr, i, 0x00);
}
+
// Unlock the command register.
- is31fl3733_write_register(bus, addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+ is31fl3733_write_register(bus, addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5);
+
// Select PG3
- is31fl3733_write_register(bus, addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION);
+ is31fl3733_write_register(bus, addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_FUNCTION);
+ // Set de-ghost pull-up resistors (SWx)
+ is31fl3733_write_register(bus, addr, IS31FL3733_REG_SWPULLUP, IS31FL3733_SWPULLUP);
+ // Set de-ghost pull-down resistors (CSx)
+ is31fl3733_write_register(bus, addr, IS31FL3733_REG_CSPULLUP, IS31FL3733_CSPULLUP);
// Set global current to maximum.
- is31fl3733_write_register(bus, addr, ISSI_REG_GLOBALCURRENT, 0xFF);
+ is31fl3733_write_register(bus, addr, IS31FL3733_REG_GLOBALCURRENT, IS31FL3733_GLOBALCURRENT);
// Disable software shutdown.
- is31fl3733_write_register(bus, addr, ISSI_REG_CONFIGURATION, (sync << 6) | 0x01);
+ is31fl3733_write_register(bus, addr, IS31FL3733_REG_CONFIGURATION, ((sync & 0b11) << 6) | ((IS31FL3733_PWM_FREQUENCY & 0b111) << 3) | 0x01);
+
// Wait 10ms to ensure the device has woken up.
wait_ms(10);
}
void is31fl3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
+ is31fl3733_led_t led;
if (index >= 0 && index < RGB_MATRIX_LED_COUNT) {
- is31_led led = g_is31_leds[index];
+ memcpy_P(&led, (&g_is31fl3733_leds[index]), sizeof(led));
+ if (g_pwm_buffer[led.driver][led.r] == red && g_pwm_buffer[led.driver][led.g] == green && g_pwm_buffer[led.driver][led.b] == blue) {
+ return;
+ }
g_pwm_buffer[led.driver][led.r] = red;
g_pwm_buffer[led.driver][led.g] = green;
g_pwm_buffer[led.driver][led.b] = blue;
@@ -177,7 +193,8 @@ void is31fl3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
}
void is31fl3733_set_led_control_register(uint8_t index, bool red, bool green, bool blue) {
- is31_led led = g_is31_leds[index];
+ is31fl3733_led_t led;
+ memcpy_P(&led, (&g_is31fl3733_leds[index]), sizeof(led));
uint8_t control_register_r = led.r / 8;
uint8_t control_register_g = led.g / 8;
@@ -208,8 +225,8 @@ void is31fl3733_set_led_control_register(uint8_t index, bool red, bool green, bo
void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
// Firstly we need to unlock the command register and select PG1.
- is31fl3733_write_register(index, addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
- is31fl3733_write_register(index, addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
+ is31fl3733_write_register(index, addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5);
+ is31fl3733_write_register(index, addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_PWM);
// If any of the transactions fail we risk writing dirty PG0,
// refresh page 0 just in case.
@@ -223,14 +240,11 @@ void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index) {
void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index) {
if (g_led_control_registers_update_required[index]) {
// Firstly we need to unlock the command register and select PG0
- is31fl3733_write_register(index, addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
- is31fl3733_write_register(index, addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
+ is31fl3733_write_register(index, addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5);
+ is31fl3733_write_register(index, addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL);
for (int i = 0; i < 24; i++) {
is31fl3733_write_register(index, addr, i, g_led_control_registers[index][i]);
}
}
g_led_control_registers_update_required[index] = false;
}
-
-
-#endif
diff --git a/keyboards/input_club/k_type/is31fl3733-dual.h b/keyboards/input_club/k_type/is31fl3733-dual.h
index 1becefbf93..7a43bc49f4 100644
--- a/keyboards/input_club/k_type/is31fl3733-dual.h
+++ b/keyboards/input_club/k_type/is31fl3733-dual.h
@@ -22,14 +22,31 @@
#include <stdbool.h>
#include "progmem.h"
-typedef struct is31_led {
+#define IS31FL3733_I2C_ADDRESS_GND_GND 0x50
+#define IS31FL3733_I2C_ADDRESS_GND_SCL 0x51
+#define IS31FL3733_I2C_ADDRESS_GND_SDA 0x52
+#define IS31FL3733_I2C_ADDRESS_GND_VCC 0x53
+#define IS31FL3733_I2C_ADDRESS_SCL_GND 0x54
+#define IS31FL3733_I2C_ADDRESS_SCL_SCL 0x55
+#define IS31FL3733_I2C_ADDRESS_SCL_SDA 0x56
+#define IS31FL3733_I2C_ADDRESS_SCL_VCC 0x57
+#define IS31FL3733_I2C_ADDRESS_SDA_GND 0x58
+#define IS31FL3733_I2C_ADDRESS_SDA_SCL 0x59
+#define IS31FL3733_I2C_ADDRESS_SDA_SDA 0x5A
+#define IS31FL3733_I2C_ADDRESS_SDA_VCC 0x5B
+#define IS31FL3733_I2C_ADDRESS_VCC_GND 0x5C
+#define IS31FL3733_I2C_ADDRESS_VCC_SCL 0x5D
+#define IS31FL3733_I2C_ADDRESS_VCC_SDA 0x5E
+#define IS31FL3733_I2C_ADDRESS_VCC_VCC 0x5F
+
+typedef struct is31fl3733_led_t {
uint8_t driver : 2;
uint8_t r;
uint8_t g;
uint8_t b;
-} __attribute__((packed)) is31_led;
+} __attribute__((packed)) is31fl3733_led_t;
-extern const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT];
+extern const is31fl3733_led_t PROGMEM g_is31fl3733_leds[RGB_MATRIX_LED_COUNT];
void is31fl3733_init(uint8_t bus, uint8_t addr, uint8_t sync);
bool is31fl3733_write_register(uint8_t index, uint8_t addr, uint8_t reg, uint8_t data);
@@ -47,6 +64,20 @@ void is31fl3733_set_led_control_register(uint8_t index, bool red, bool green, bo
void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index); // index is the driver index
void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index);
+#define IS31FL3733_PUR_0R 0x00 // No PUR resistor
+#define IS31FL3733_PUR_05KR 0x02 // 0.5k Ohm resistor in t_NOL
+#define IS31FL3733_PUR_3KR 0x03 // 3.0k Ohm resistor on all the time
+#define IS31FL3733_PUR_4KR 0x04 // 4.0k Ohm resistor on all the time
+#define IS31FL3733_PUR_8KR 0x05 // 8.0k Ohm resistor on all the time
+#define IS31FL3733_PUR_16KR 0x06 // 16k Ohm resistor on all the time
+#define IS31FL3733_PUR_32KR 0x07 // 32k Ohm resistor in t_NOL
+
+#define IS31FL3733_PWM_FREQUENCY_8K4_HZ 0x00
+#define IS31FL3733_PWM_FREQUENCY_4K2_HZ 0x01
+#define IS31FL3733_PWM_FREQUENCY_26K7_HZ 0x02
+#define IS31FL3733_PWM_FREQUENCY_2K1_HZ 0x03
+#define IS31FL3733_PWM_FREQUENCY_1K05_HZ 0x04
+
#define A_1 0x00
#define A_2 0x01
#define A_3 0x02
diff --git a/keyboards/input_club/k_type/k_type-rgbdriver.c b/keyboards/input_club/k_type/k_type-rgbdriver.c
index dc5d4abd67..18cdb3cda3 100644
--- a/keyboards/input_club/k_type/k_type-rgbdriver.c
+++ b/keyboards/input_club/k_type/k_type-rgbdriver.c
@@ -15,11 +15,10 @@
*/
#ifdef RGB_MATRIX_ENABLE
-
-#include "rgb_matrix.h"
-#include "i2c_master.h"
-#include "is31fl3733-dual.h"
-#include "gpio.h"
+# include "rgb_matrix.h"
+# include "i2c_master.h"
+# include "is31fl3733-dual.h"
+# include "gpio.h"
static void init(void) {
i2c_init(&I2CD1, I2C1_SCL_PIN, I2C1_SDA_PIN);
@@ -52,5 +51,4 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
.set_color = is31fl3733_set_color,
.set_color_all = is31fl3733_set_color_all,
};
-
#endif
diff --git a/keyboards/input_club/k_type/k_type.c b/keyboards/input_club/k_type/k_type.c
index 23a3895408..c6d06b51dc 100644
--- a/keyboards/input_club/k_type/k_type.c
+++ b/keyboards/input_club/k_type/k_type.c
@@ -18,11 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "quantum.h"
#ifdef RGB_MATRIX_ENABLE
+# include "is31fl3733-dual.h"
-#include "is31fl3733-dual.h"
-
-
-const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT] = {
+const is31fl3733_led_t PROGMEM g_is31fl3733_leds[RGB_MATRIX_LED_COUNT] = {
{ 0, B_1, A_1, C_1 },
{ 0, B_2, A_2, C_2 },
{ 0, B_3, A_3, C_3 },
@@ -202,15 +200,12 @@ led_config_t g_led_config = {
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
}
};
-#endif
-
void keyboard_pre_init_kb(void) {
-#ifdef RGB_MATRIX_ENABLE
// Turn on LED controller
setPinOutput(B16);
writePinHigh(B16);
-#endif
+
keyboard_pre_init_user();
}
@@ -218,17 +213,13 @@ void matrix_init_kb(void) {
// put your keyboard start-up code here
// runs once when the firmware starts up
-#ifdef RGB_MATRIX_ENABLE
/*
* Since K20x is stuck with a 32 byte EEPROM (see tmk_core/common/chibios/eeprom_teensy.c),
* and neither led_matrix_eeconfig.speed or .flags fit in this boundary, just force their values to default on boot.
*/
-# if !defined(RGB_MATRIX_DEFAULT_SPD)
-# define RGB_MATRIX_DEFAULT_SPD UINT8_MAX / 2
-# endif
rgb_matrix_set_speed(RGB_MATRIX_DEFAULT_SPD),
rgb_matrix_set_flags(LED_FLAG_ALL);
-#endif
matrix_init_user();
}
+#endif
diff --git a/keyboards/input_club/k_type/post_rules.mk b/keyboards/input_club/k_type/post_rules.mk
new file mode 100644
index 0000000000..897e422b05
--- /dev/null
+++ b/keyboards/input_club/k_type/post_rules.mk
@@ -0,0 +1,5 @@
+ifeq ($(strip $(RGB_MATRIX_ENABLE)), yes)
+ # Additional files for RGB lighting
+ SRC += k_type-rgbdriver.c
+ QUANTUM_LIB_SRC += i2c_master.c is31fl3733-dual.c
+endif
diff --git a/keyboards/input_club/k_type/rules.mk b/keyboards/input_club/k_type/rules.mk
index d7776bb755..684de50562 100644
--- a/keyboards/input_club/k_type/rules.mk
+++ b/keyboards/input_club/k_type/rules.mk
@@ -13,8 +13,3 @@ AUDIO_ENABLE = no # Audio output
# RGB options
RGB_MATRIX_ENABLE = no
-
-# Additional files for RGB lighting
-SRC += k_type-rgbdriver.c
-QUANTUM_LIB_SRC += i2c_master.c is31fl3733-dual.c
-