QMK/keyboards/betalupi_voyager/betalupi_voyager.c

222 lines
5.3 KiB
C

#include "betalupi_voyager.h"
#include "raw_hid.h"
keyboard_config_t keyboard_config;
bool mcp23018_leds[2] = {0, 0};
bool is_launching = false;
void voyager_led_task(void) {
if (is_launching) {
STATUS_LED_1(false);
STATUS_LED_2(false);
STATUS_LED_3(false);
STATUS_LED_4(false);
wait_ms(250);
STATUS_LED_1(true);
STATUS_LED_2(true);
wait_ms(250);
STATUS_LED_3(true);
STATUS_LED_4(true);
wait_ms(250);
STATUS_LED_1(false);
STATUS_LED_2(false);
wait_ms(250);
STATUS_LED_3(false);
STATUS_LED_4(false);
wait_ms(250);
is_launching = false;
layer_state_set_kb(layer_state);
}
}
static THD_WORKING_AREA(waLEDThread, 128);
static THD_FUNCTION(LEDThread, arg) {
(void)arg;
chRegSetThreadName("LEDThread");
while (true) {
voyager_led_task();
}
}
void keyboard_pre_init_kb(void) {
// Initialize Reset pins
setPinInput(A8);
setPinOutput(A9);
writePinLow(A9);
setPinOutput(B5);
setPinOutput(B4);
setPinOutput(B3);
writePinLow(B5);
writePinLow(B4);
writePinLow(B3);
chThdCreateStatic(waLEDThread, sizeof(waLEDThread), NORMALPRIO - 16, LEDThread, NULL);
keyboard_pre_init_user();
rgb_matrix_set_flags(LED_FLAG_NONE);
rgb_matrix_set_color_all(0, 0, 0);
}
layer_state_t layer_state_set_kb(layer_state_t state) {
state = layer_state_set_user(state);
return state;
}
#ifdef RGB_MATRIX_ENABLE
// clang-format off
const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
* | | G location
* | | | B location
* | | | | */
{0, C2_2, C1_2, C4_3},
{0, C2_3, C1_3, C3_3},
{0, C2_4, C1_4, C3_4},
{0, C2_5, C1_5, C3_5},
{0, C2_6, C1_6, C3_6},
{0, C2_7, C1_7, C3_7},
{0, C2_8, C1_8, C3_8},
{0, C8_1, C7_1, C9_1},
{0, C8_2, C7_2, C9_2},
{0, C8_3, C7_3, C9_3},
{0, C8_4, C7_4, C9_4},
{0, C8_5, C7_5, C9_5},
{0, C8_6, C7_6, C9_6},
{0, C2_10, C1_10, C4_11},
{0, C2_11, C1_11, C3_11},
{0, C2_12, C1_12, C3_12},
{0, C2_13, C1_13, C3_13},
{0, C2_14, C1_14, C3_14},
{0, C2_15, C1_15, C3_15},
{0, C2_16, C1_16, C3_16},
{0, C8_9, C7_9, C9_9},
{0, C8_10, C7_10, C9_10},
{0, C8_11, C7_11, C9_11},
{0, C8_12, C7_12, C9_12},
{0, C8_13, C7_13, C9_13},
{0, C8_14, C7_14, C9_14},
{1, C2_7, C1_7, C3_7},
{1, C2_6, C1_6, C3_6},
{1, C2_5, C1_5, C3_5},
{1, C2_4, C1_4, C3_4},
{1, C2_3, C1_3, C3_3},
{1, C2_2, C1_2, C4_3},
{1, C8_5, C7_5, C9_5},
{1, C8_4, C7_4, C9_4},
{1, C8_3, C7_3, C9_3},
{1, C8_2, C7_2, C9_2},
{1, C8_1, C7_1, C9_1},
{1, C2_8, C1_8, C3_8},
{1, C2_14, C1_14, C3_14},
{1, C2_13, C1_13, C3_13},
{1, C2_12, C1_12, C3_12},
{1, C2_11, C1_11, C3_11},
{1, C2_10, C1_10, C4_11},
{1, C8_6, C7_6, C9_6},
{1, C8_12, C7_12, C9_12},
{1, C8_11, C7_11, C9_11},
{1, C8_10, C7_10, C9_10},
{1, C8_9, C7_9, C9_9},
{1, C2_16, C1_16, C3_16},
{1, C2_15, C1_15, C3_15},
{1, C8_14, C7_14, C9_14},
{1, C8_13, C7_13, C9_13},
};
led_config_t g_led_config = { {
{ NO_LED, 0, 1, 2, 3, 4, 5 },
{ NO_LED, 6, 7, 8, 9, 10, 11 },
{ NO_LED, 12, 13, 14, 15, 16, 17 },
{ NO_LED, 18, 19, 20, 21, 22, NO_LED },
{ NO_LED, NO_LED, NO_LED, NO_LED, 23, NO_LED, NO_LED },
{ 24, 25, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED },
{ 26, 27, 28, 29, 30, 31, NO_LED },
{ 32, 33, 34, 35, 36, 37, NO_LED },
{ 38, 39, 40, 41, 42, 43, NO_LED },
{ NO_LED, 45, 46, 47, 48, 49, NO_LED },
{ NO_LED, NO_LED, 44, NO_LED, NO_LED, NO_LED, NO_LED },
{ NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, 50, 51 },
}, {
{0, 10}, {17, 10}, {34,8}, {52, 5}, {69, 8}, {86, 10},
{0, 21}, {17, 21}, {34, 19}, {52, 17}, {69, 19}, {86, 21},
{0, 32}, {17, 32}, {34, 30}, {52, 28}, {69, 30}, {86, 32},
{0, 43}, {17, 43}, {34, 41}, {52, 39}, {69, 41}, {86, 43},
{86, 53}, {96, 58},
{138, 10}, {155, 10}, {172, 8}, {190, 5}, {207, 8}, {224, 10},
{138, 21}, {155, 21}, {172, 19}, {190, 17}, {207, 19}, {224, 21},
{138, 32}, {155, 32}, {172, 30}, {190, 28}, {207, 30}, {224, 32},
{138, 43}, {155,43}, {172, 41}, {190, 39}, {207, 41}, {224, 43},
{128, 58}, {138, 53}
}, {
1, 4, 4, 4, 4, 4,
1, 4, 4, 4, 4, 4,
1, 4, 4, 4, 4, 4,
1, 4, 4, 4, 4, 4,
1, 1, 4, 4, 4, 4,
4, 1, 4, 4, 4, 4,
4, 1, 4, 4, 4, 4,
4, 1, 4, 4, 4, 4,
4, 1, 1, 1
} };
// clang-format on
#endif
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
if (!process_record_user(keycode, record)) {
return false;
}
switch (keycode) {
#ifdef RGB_MATRIX_ENABLE
case RGB_TOG:
if (record->event.pressed) {
switch (rgb_matrix_get_flags()) {
case LED_FLAG_ALL: {
rgb_matrix_set_flags(LED_FLAG_NONE);
rgb_matrix_set_color_all(0, 0, 0);
} break;
default: {
rgb_matrix_set_flags(LED_FLAG_ALL);
} break;
}
}
return false;
#endif
}
return true;
}
void matrix_init_kb(void) {
keyboard_config.raw = eeconfig_read_kb();
if (!keyboard_config.led_level && !keyboard_config.led_level_res) {
keyboard_config.led_level = true;
keyboard_config.led_level_res = 0b11;
eeconfig_update_kb(keyboard_config.raw);
}
matrix_init_user();
}
void eeconfig_init_kb(void) { // EEPROM is getting reset!
keyboard_config.raw = 0;
keyboard_config.led_level = true;
keyboard_config.led_level_res = 0b11;
keyboard_config.disable_layer_led = false;
eeconfig_update_kb(keyboard_config.raw);
eeconfig_init_user();
}