qmk_userspace/users/halcyon_modules/halcyon.c
2025-01-07 11:01:46 +01:00

205 lines
6.8 KiB
C

// Copyright 2024 splitkb.com (support@splitkb.com)
// SPDX-License-Identifier: GPL-2.0-or-later
#include "halcyon.h"
#include "transactions.h"
#include "split_util.h"
#include "_wait.h"
__attribute__((weak)) bool module_post_init_kb(void) {
return module_post_init_user();
}
__attribute__((weak)) bool module_housekeeping_task_kb(void) {
return module_housekeeping_task_user();
}
__attribute__((weak)) bool display_module_housekeeping_task_kb(bool second_display) {
return display_module_housekeeping_task_user(second_display);
}
__attribute__((weak)) bool module_post_init_user(void) {
return true;
}
__attribute__((weak)) bool module_housekeeping_task_user(void) {
return true;
}
__attribute__((weak)) bool display_module_housekeeping_task_user(bool second_display) {
return true;
}
module_t module_master;
module_t module;
#ifdef HLC_NONE
module_t module = hlc_none;
#endif
#ifdef HLC_CIRQUE_TRACKPAD
module_t module = hlc_cirque_trackpad;
#endif
#ifdef HLC_ENCODER
module_t module = hlc_encoder;
#endif
#ifdef HLC_TFT_DISPLAY
module_t module = hlc_tft_display;
#endif
bool backlight_off = false;
// Timeout handling
void backlight_wakeup(void) {
backlight_off = false;
backlight_enable();
if (get_backlight_level() == 0) {
backlight_level(BACKLIGHT_LEVELS);
}
}
// Timeout handling
void backlight_suspend(void) {
backlight_off = true;
backlight_disable();
}
void module_sync_slave_handler(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) {
if (initiator2target_buffer_size == sizeof(module)) {
memcpy(&module_master, initiator2target_buffer, sizeof(module_master));
}
}
void keyboard_post_init_kb(void) {
// Register module sync split transaction
transaction_register_rpc(MODULE_SYNC, module_sync_slave_handler);
// Do any post init for modules
module_post_init_kb();
// User post init
keyboard_post_init_user();
}
void housekeeping_task_kb(void) {
if (is_keyboard_master()) {
static bool synced = false;
if (!synced) {
if(is_transport_connected()) {
transaction_rpc_send(MODULE_SYNC, sizeof(module), &module); // Sync to slave
wait_ms(10);
// Good moment to make sure the backlight wakes up after boot for both halves
backlight_wakeup();
synced = true;
}
}
display_module_housekeeping_task_kb(false); // Is master so can never be the second display
}
if (!is_keyboard_master()) {
display_module_housekeeping_task_kb(module_master == hlc_tft_display);
}
// Backlight feature
if (last_input_activity_elapsed() <= HLC_BACKLIGHT_TIMEOUT) {
if (backlight_off) {
backlight_wakeup();
}
} else {
if (!backlight_off) {
backlight_suspend();
}
}
module_housekeeping_task_kb();
housekeeping_task_user();
}
report_mouse_t pointing_device_task_combined_kb(report_mouse_t left_report, report_mouse_t right_report) {
// Only runs on master
// Fixes the following bug: If master is right and master is NOT a cirque trackpad, the inputs would be inverted.
if(module != hlc_cirque_trackpad && !is_keyboard_left()) {
mouse_xy_report_t x = left_report.x;
mouse_xy_report_t y = left_report.y;
left_report.x = -x;
left_report.y = -y;
}
return pointing_device_task_combined_user(left_report, right_report);
}
// Kyria
#if PRODUCT_ID == 0x7FCE
#ifdef RGB_MATRIX_ENABLE
#include "rgb_matrix.h"
led_config_t g_led_config = {
{
{ NO_LED, 25, 26, 27, 28, 29, 30 },
{ NO_LED, 19, 20, 21, 22, 23, 24 },
{ 11, 13, 14, 15, 16, 17, 18 },
{ 6, 8, 9, 12, 10, 7, NO_LED },
{ NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED },
{ NO_LED, 56, 57, 58, 59, 60, 61 },
{ NO_LED, 50, 51, 52, 53, 54, 55 },
{ 42, 44, 45, 46, 47, 48, 49 },
{ 37, 39, 40, 43, 41, 38, NO_LED },
{ NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED },
},
{ {75, 2}, {50, 1}, {14, 4}, {25, 45}, {58, 49}, {94, 53}, {94, 64}, {79, 60}, {65, 53}, {51, 49}, {36, 49}, {101, 49}, {87, 45}, {72, 38}, {58, 34}, {43, 30}, {29, 34}, {14, 41}, {0, 41}, {72, 23}, {58, 19}, {43, 15}, {29, 19}, {14, 26}, {0, 26}, {72, 8}, {58, 4}, {43, 0}, {29, 4}, {14, 11}, {0, 11}, {149, 2}, {174, 1}, {210, 4}, {199, 45}, {166, 49}, {130, 53}, {130, 64}, {145, 60}, {159, 53}, {173, 49}, {188, 49}, {123, 49}, {137, 45}, {152, 38}, {166, 34}, {181, 30}, {195, 34}, {210, 41}, {224, 41}, {152, 23}, {166, 19}, {181, 15}, {195, 19}, {210, 26}, {224, 26}, {152, 8}, {166, 4}, {181, 0}, {195, 4}, {210, 11}, {224, 11} },
{ 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 },
};
#endif
#ifdef MATRIX_MASKED
const matrix_row_t matrix_mask[] = {
0b1111110,
0b1111110,
0b1111111,
0b0111111,
0b0011111,
0b1111110,
0b1111110,
0b1111111,
0b0111111,
0b0011111,
};
#endif
#endif
// Lily58
#if PRODUCT_ID == 0xEA1D
#ifdef RGB_MATRIX_ENABLE
#include "rgb_matrix.h"
led_config_t g_led_config = {
{
{ 5, 6, 7, 8, 9, 10 },
{ 11, 12, 13, 14, 15, 16 },
{ 17, 18, 19, 20, 21, 22 },
{ 23, 24, 25, 26, 27, 28 },
{ NO_LED, 29, 30, 31, 32, 33 },
{ NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED },
{ 44, 43, 42, 41, 40, 39 },
{ 50, 49, 48, 47, 46, 45 },
{ 56, 55, 54, 53, 52, 51 },
{ 63, 62, 61, 60, 59, 58 },
{ NO_LED, 57, 67, 66, 65, 64 },
{ NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED },
},
{ {51, 13}, {22, 18}, {22, 53}, {58, 60}, {87, 56}, {0, 8}, {14, 6}, {29, 2}, {43, 0}, {58, 2}, {72, 4}, {0, 23}, {14, 21}, {29, 17}, {43, 15}, {58, 17}, {72, 19}, {0, 38}, {14, 36}, {29, 32}, {43, 30}, {58, 32}, {72, 34}, {0, 53}, {14, 51}, {29, 47}, {43, 45}, {58, 47}, {72, 49}, {87, 41}, {36, 62}, {51, 62}, {65, 64}, {87, 64}, {173, 13}, {202, 18}, {202, 53}, {166, 60}, {137, 56}, {152, 4}, {166, 2}, {181, 0}, {195, 2}, {210, 6}, {224, 8}, {152, 19}, {166, 17}, {181, 15}, {195, 17}, {210, 21}, {224, 23}, {152, 34}, {166, 32}, {181, 30}, {195, 32}, {210, 36}, {224, 38}, {137, 41}, {152, 49}, {166, 47}, {181, 45}, {195, 47}, {210, 51}, {224, 53}, {137, 64}, {159, 64}, {173, 62}, {188, 62} },
{ 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 },
};
#endif
#ifdef MATRIX_MASKED
const matrix_row_t matrix_mask[] = {
0b111111,
0b111111,
0b111111,
0b111111,
0b111110,
0b011111,
0b111111,
0b111111,
0b111111,
0b111111,
0b111110,
0b011111,
};
#endif
#endif