diff options
author | lokher <lokher@gmail.com> | 2022-12-06 17:04:10 +0800 |
---|---|---|
committer | lokher <lokher@gmail.com> | 2022-12-06 17:04:10 +0800 |
commit | 27fc28fd2ff52e079a5bc58d6aaea4c752420615 (patch) | |
tree | 7ac943fb1ba4f430a7220efd18f66f6a77205c30 /keyboards/tzarc/djinn | |
parent | e736133392fe6427cfb995da0787337189828272 (diff) | |
parent | 2709b6ed616f8012ff4cfd3ee69a822a8d188351 (diff) |
Merge upstream master
Diffstat (limited to 'keyboards/tzarc/djinn')
-rw-r--r-- | keyboards/tzarc/djinn/djinn.c | 233 | ||||
-rw-r--r-- | keyboards/tzarc/djinn/djinn_portscan_matrix.c | 117 | ||||
-rw-r--r-- | keyboards/tzarc/djinn/graphics/theme_djinn_default.c | 307 | ||||
-rw-r--r-- | keyboards/tzarc/djinn/keymaps/default/keymap.c | 107 | ||||
-rw-r--r-- | keyboards/tzarc/djinn/rev1/config.h | 35 | ||||
-rw-r--r-- | keyboards/tzarc/djinn/rev2/config.h | 47 |
6 files changed, 846 insertions, 0 deletions
diff --git a/keyboards/tzarc/djinn/djinn.c b/keyboards/tzarc/djinn/djinn.c new file mode 100644 index 0000000000..93b1ee775e --- /dev/null +++ b/keyboards/tzarc/djinn/djinn.c @@ -0,0 +1,233 @@ +// Copyright 2018-2022 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#include <string.h> +#include "quantum.h" +#include <hal_pal.h> +#include "djinn.h" +#include "serial.h" +#include "split_util.h" +#include "qp.h" + +painter_device_t lcd; + +// clang-format off +#ifdef SWAP_HANDS_ENABLE +const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = { + { { 6, 6 }, { 5, 6 }, { 4, 6 }, { 3, 6 }, { 2, 6 }, { 1, 6 }, { 0, 6 } }, + { { 6, 7 }, { 5, 7 }, { 4, 7 }, { 3, 7 }, { 2, 7 }, { 1, 7 }, { 0, 7 } }, + { { 6, 8 }, { 5, 8 }, { 4, 8 }, { 3, 8 }, { 2, 8 }, { 1, 8 }, { 0, 8 } }, + { { 6, 9 }, { 5, 9 }, { 4, 9 }, { 3, 9 }, { 2, 9 }, { 1, 9 }, { 0, 9 } }, + { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 6, 10 }, { 5, 10 }, { 4, 10 }, { 3, 10 } }, + { { 0, 0 }, { 6, 11 }, { 5, 11 }, { 4, 11 }, { 3, 11 }, { 2, 11 }, { 1, 11 } }, + + { { 6, 0 }, { 5, 0 }, { 4, 0 }, { 3, 0 }, { 2, 0 }, { 1, 0 }, { 0, 0 } }, + { { 6, 1 }, { 5, 1 }, { 4, 1 }, { 3, 1 }, { 2, 1 }, { 1, 1 }, { 0, 1 } }, + { { 6, 2 }, { 5, 2 }, { 4, 2 }, { 3, 2 }, { 2, 2 }, { 1, 2 }, { 0, 2 } }, + { { 6, 3 }, { 5, 3 }, { 4, 3 }, { 3, 3 }, { 2, 3 }, { 1, 3 }, { 0, 3 } }, + { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 6, 4 }, { 5, 4 }, { 4, 4 }, { 3, 4 } }, + { { 0, 0 }, { 6, 5 }, { 5, 5 }, { 4, 5 }, { 3, 5 }, { 2, 5 }, { 1, 5 } }, +}; +# ifdef ENCODER_MAP_ENABLE +const uint8_t PROGMEM encoder_hand_swap_config[NUM_ENCODERS] = { 1, 0 }; +# endif // ENCODER_MAP_ENABLE +#endif // SWAP_HANDS_ENABLE +// clang-format on + +void board_init(void) { + usbpd_init(); +} + +//---------------------------------------------------------- +// Initialisation + +void keyboard_post_init_kb(void) { + // Register keyboard state sync split transaction + transaction_register_rpc(RPC_ID_SYNC_STATE_KB, kb_state_sync_slave); + + // Reset the initial shared data value between master and slave + memset(&kb_state, 0, sizeof(kb_state)); + + // Turn off increased current limits + setPinOutput(RGB_CURR_1500mA_OK_PIN); + writePinLow(RGB_CURR_1500mA_OK_PIN); + setPinOutput(RGB_CURR_3000mA_OK_PIN); + writePinLow(RGB_CURR_3000mA_OK_PIN); + + // Turn on the RGB + setPinOutput(RGB_POWER_ENABLE_PIN); + writePinHigh(RGB_POWER_ENABLE_PIN); + +#ifdef EXTERNAL_FLASH_SPI_SLAVE_SELECT_PIN + setPinOutput(EXTERNAL_FLASH_SPI_SLAVE_SELECT_PIN); + writePinHigh(EXTERNAL_FLASH_SPI_SLAVE_SELECT_PIN); +#endif // EXTERNAL_FLASH_SPI_SLAVE_SELECT_PIN + + // Turn on the LCD + setPinOutput(LCD_POWER_ENABLE_PIN); + writePinHigh(LCD_POWER_ENABLE_PIN); + + // Let the LCD get some power... + wait_ms(150); + + // Initialise the LCD + lcd = qp_ili9341_make_spi_device(240, 320, LCD_CS_PIN, LCD_DC_PIN, LCD_RST_PIN, 4, 0); + qp_init(lcd, QP_ROTATION_0); + + // Turn on the LCD and clear the display + kb_state.lcd_power = 1; + qp_power(lcd, true); + qp_rect(lcd, 0, 0, 239, 319, HSV_BLACK, true); + + // Turn on the LCD backlight + backlight_enable(); + backlight_level(BACKLIGHT_LEVELS); + + // Allow for user post-init + keyboard_post_init_user(); +} + +//---------------------------------------------------------- +// RGB brightness scaling dependent on USBPD state + +#if defined(RGB_MATRIX_ENABLE) +RGB rgb_matrix_hsv_to_rgb(HSV hsv) { + float scale; + +# ifdef DJINN_SUPPORTS_3A_FUSE + // The updated BOM on the Djinn has properly-spec'ed fuses -- 1500mA/3000mA hold current + switch (kb_state.current_setting) { + default: + case USBPD_500MA: + scale = 0.35f; + break; + case USBPD_1500MA: + scale = 0.75f; + break; + case USBPD_3000MA: + scale = 1.0f; + break; + } +# else + // The original BOM on the Djinn had wrongly-spec'ed fuses -- 750mA/1500mA hold current + switch (kb_state.current_setting) { + default: + case USBPD_500MA: + case USBPD_1500MA: + scale = 0.35f; + break; + case USBPD_3000MA: + scale = 0.75f; + break; + } +# endif + + hsv.v = (uint8_t)(hsv.v * scale); + return hsv_to_rgb(hsv); +} +#endif + +//---------------------------------------------------------- +// UI Placeholder, implemented in themes + +__attribute__((weak)) void draw_ui_user(bool force_redraw) {} + +//---------------------------------------------------------- +// Housekeeping + +void housekeeping_task_kb(void) { + // Update kb_state so we can send to slave + kb_state_update(); + + // Data sync from master to slave + kb_state_sync(); + + // Work out if we've changed our current limit, update the limiter circuit switches + static uint8_t current_setting = USBPD_500MA; + if (current_setting != kb_state.current_setting) { + current_setting = kb_state.current_setting; + +#ifdef DJINN_SUPPORTS_3A_FUSE + // The updated BOM on the Djinn has properly-spec'ed fuses -- 1500mA/3000mA hold current + switch (current_setting) { + default: + case USBPD_500MA: + writePinLow(RGB_CURR_1500mA_OK_PIN); + writePinLow(RGB_CURR_3000mA_OK_PIN); + break; + case USBPD_1500MA: + writePinHigh(RGB_CURR_1500mA_OK_PIN); + writePinLow(RGB_CURR_3000mA_OK_PIN); + break; + case USBPD_3000MA: + writePinHigh(RGB_CURR_1500mA_OK_PIN); + writePinHigh(RGB_CURR_3000mA_OK_PIN); + break; + } +#else + // The original BOM on the Djinn had wrongly-spec'ed fuses -- 750mA/1500mA hold current + switch (current_setting) { + default: + case USBPD_500MA: + case USBPD_1500MA: + writePinLow(RGB_CURR_1500mA_OK_PIN); + writePinLow(RGB_CURR_3000mA_OK_PIN); + break; + case USBPD_3000MA: + writePinHigh(RGB_CURR_1500mA_OK_PIN); + writePinLow(RGB_CURR_3000mA_OK_PIN); + break; + } +#endif + + // If we've changed the current limit, toggle rgb off and on if it was on, to force a brightness update on all LEDs + if (is_keyboard_master() && rgb_matrix_is_enabled()) { + rgb_matrix_disable_noeeprom(); + rgb_matrix_enable_noeeprom(); + } + } + + // Turn on/off the LCD + static bool lcd_on = false; + if (lcd_on != (bool)kb_state.lcd_power) { + lcd_on = (bool)kb_state.lcd_power; + qp_power(lcd, lcd_on); + } + + // Enable/disable RGB + if (lcd_on) { + // Turn on RGB + writePinHigh(RGB_POWER_ENABLE_PIN); + // Modify the RGB state if different to the LCD state + if (rgb_matrix_is_enabled() != lcd_on) { + // Wait for a small amount of time to allow the RGB capacitors to charge, before enabling RGB output + wait_ms(10); + // Enable RGB + rgb_matrix_enable_noeeprom(); + } + } else { + // Turn off RGB + writePinLow(RGB_POWER_ENABLE_PIN); + // Disable the PWM output for the RGB + if (rgb_matrix_is_enabled() != lcd_on) { + rgb_matrix_disable_noeeprom(); + } + } + + // Match the backlight to the LCD state + if (is_keyboard_master() && is_backlight_enabled() != lcd_on) { + if (lcd_on) + backlight_enable(); + else + backlight_disable(); + } + + // Draw the UI + if (kb_state.lcd_power) { + draw_ui_user(false); + } + + // Go into low-scan interrupt-based mode if we haven't had any matrix activity in the last 250 milliseconds + if (last_input_activity_elapsed() > 250) { + matrix_wait_for_interrupt(); + } +} diff --git a/keyboards/tzarc/djinn/djinn_portscan_matrix.c b/keyboards/tzarc/djinn/djinn_portscan_matrix.c new file mode 100644 index 0000000000..6fcfd48bba --- /dev/null +++ b/keyboards/tzarc/djinn/djinn_portscan_matrix.c @@ -0,0 +1,117 @@ +// Copyright 2018-2022 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#include "quantum.h" +#include <hal_pal.h> +#include "djinn.h" + +#define GPIOB_BITMASK (1 << 13 | 1 << 14 | 1 << 15) // B13, B14, B15 +#define GPIOB_OFFSET 13 +#define GPIOB_COUNT 3 +#define GPIOC_BITMASK (1 << 6 | 1 << 7 | 1 << 8) // C6, C7, C8 +#define GPIOC_OFFSET 6 + +// Pin definitions +static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; +static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; + +void matrix_wait_for_pin(pin_t pin, uint8_t target_state) { + rtcnt_t start = chSysGetRealtimeCounterX(); + rtcnt_t end = start + 5000; + while (chSysIsCounterWithinX(chSysGetRealtimeCounterX(), start, end)) { + if (readPin(pin) == target_state) { + break; + } + } +} + +void matrix_wait_for_port(stm32_gpio_t *port, uint32_t target_bitmask) { + rtcnt_t start = chSysGetRealtimeCounterX(); + rtcnt_t end = start + 5000; + while (chSysIsCounterWithinX(chSysGetRealtimeCounterX(), start, end)) { + if ((palReadPort(port) & target_bitmask) == target_bitmask) { + break; + } + } +} + +void matrix_init_custom(void) { + for (int i = 0; i < MATRIX_ROWS; ++i) { + setPinInputHigh(row_pins[i]); + } + for (int i = 0; i < MATRIX_COLS; ++i) { + setPinInputHigh(col_pins[i]); + } +} + +bool matrix_scan_custom(matrix_row_t current_matrix[]) { + static matrix_row_t temp_matrix[MATRIX_ROWS] = {0}; + + for (int current_col = 0; current_col < MATRIX_COLS; ++current_col) { + // Keep track of the pin we're working with + pin_t curr_col_pin = col_pins[current_col]; + + // Setup the output column pin + setPinOutput(curr_col_pin); + writePinLow(curr_col_pin); + matrix_wait_for_pin(curr_col_pin, 0); + + // Read the row ports + uint32_t gpio_b = palReadPort(GPIOB); + uint32_t gpio_c = palReadPort(GPIOC); + + // Unselect the row pin + setPinInputHigh(curr_col_pin); + + // Construct the packed bitmask for the pins + uint32_t readback = ~(((gpio_b & GPIOB_BITMASK) >> GPIOB_OFFSET) | (((gpio_c & GPIOC_BITMASK) >> GPIOC_OFFSET) << GPIOB_COUNT)); + + // Inject values into the matrix + for (int i = 0; i < MATRIX_ROWS; ++i) { + if (readback & (1 << i)) { + temp_matrix[i] |= (1ul << current_col); + } else { + temp_matrix[i] &= ~(1ul << current_col); + } + } + + // Wait for readback of the unselected column to go high + matrix_wait_for_pin(curr_col_pin, 1); + + // Wait for readback of each port to go high -- unselecting the row would have been completed + matrix_wait_for_port(GPIOB, GPIOB_BITMASK); + matrix_wait_for_port(GPIOC, GPIOC_BITMASK); + } + + // Check if we've changed, return the last-read data + bool changed = memcmp(current_matrix, temp_matrix, sizeof(temp_matrix)) != 0; + if (changed) { + memcpy(current_matrix, temp_matrix, sizeof(temp_matrix)); + } + return changed; +} + +void matrix_wait_for_interrupt(void) { + // Set up row/col pins and attach callback + for (int i = 0; i < ARRAY_SIZE(col_pins); ++i) { + setPinOutput(col_pins[i]); + writePinLow(col_pins[i]); + } + for (int i = 0; i < ARRAY_SIZE(row_pins); ++i) { + setPinInputHigh(row_pins[i]); + palEnableLineEvent(row_pins[i], PAL_EVENT_MODE_BOTH_EDGES); + } + + // Wait for an interrupt + __WFI(); + + // Now that the interrupt has woken us up, reset all the row/col pins back to defaults + for (int i = 0; i < ARRAY_SIZE(row_pins); ++i) { + palDisableLineEvent(row_pins[i]); + writePinHigh(row_pins[i]); + setPinInputHigh(row_pins[i]); + } + for (int i = 0; i < ARRAY_SIZE(col_pins); ++i) { + writePinHigh(col_pins[i]); + setPinInputHigh(col_pins[i]); + } +}
\ No newline at end of file diff --git a/keyboards/tzarc/djinn/graphics/theme_djinn_default.c b/keyboards/tzarc/djinn/graphics/theme_djinn_default.c new file mode 100644 index 0000000000..c9863f2285 --- /dev/null +++ b/keyboards/tzarc/djinn/graphics/theme_djinn_default.c @@ -0,0 +1,307 @@ +// Copyright 2018-2022 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#include QMK_KEYBOARD_H +#include <hal.h> +#include <string.h> +#include <ctype.h> +#include <printf.h> +#include "qp.h" +#include "backlight.h" +#include "transactions.h" +#include "split_util.h" + +#include "djinn.h" +#include "theme_djinn_default.h" + +#include "djinn.qgf.h" +#include "lock-caps-ON.qgf.h" +#include "lock-scrl-ON.qgf.h" +#include "lock-num-ON.qgf.h" +#include "lock-caps-OFF.qgf.h" +#include "lock-scrl-OFF.qgf.h" +#include "lock-num-OFF.qgf.h" +#include "thintel15.qff.h" + +static painter_image_handle_t djinn_logo; +static painter_image_handle_t lock_caps_on; +static painter_image_handle_t lock_caps_off; +static painter_image_handle_t lock_num_on; +static painter_image_handle_t lock_num_off; +static painter_image_handle_t lock_scrl_on; +static painter_image_handle_t lock_scrl_off; +static painter_font_handle_t thintel; + +//---------------------------------------------------------- +// RGB Matrix naming +#if defined(RGB_MATRIX_ENABLE) +# include <rgb_matrix.h> + +# if defined(RGB_MATRIX_EFFECT) +# undef RGB_MATRIX_EFFECT +# endif // defined(RGB_MATRIX_EFFECT) + +# define RGB_MATRIX_EFFECT(x) RGB_MATRIX_EFFECT_##x, +enum { + RGB_MATRIX_EFFECT_NONE, +# include "rgb_matrix_effects.inc" +# undef RGB_MATRIX_EFFECT +# ifdef RGB_MATRIX_CUSTOM_KB +# include "rgb_matrix_kb.inc" +# endif +# ifdef RGB_MATRIX_CUSTOM_USER +# include "rgb_matrix_user.inc" +# endif +}; + +# define RGB_MATRIX_EFFECT(x) \ + case RGB_MATRIX_EFFECT_##x: \ + return #x; +const char *rgb_matrix_name(uint8_t effect) { + switch (effect) { + case RGB_MATRIX_EFFECT_NONE: + return "NONE"; +# include "rgb_matrix_effects.inc" +# undef RGB_MATRIX_EFFECT +# ifdef RGB_MATRIX_CUSTOM_KB +# include "rgb_matrix_kb.inc" +# endif +# ifdef RGB_MATRIX_CUSTOM_USER +# include "rgb_matrix_user.inc" +# endif + default: + return "UNKNOWN"; + } +} +#endif // defined(RGB_MATRIX_ENABLE) + +//---------------------------------------------------------- +// UI Initialisation +void keyboard_post_init_display(void) { + djinn_logo = qp_load_image_mem(gfx_djinn); + lock_caps_on = qp_load_image_mem(gfx_lock_caps_ON); + lock_caps_off = qp_load_image_mem(gfx_lock_caps_OFF); + lock_num_on = qp_load_image_mem(gfx_lock_num_ON); + lock_num_off = qp_load_image_mem(gfx_lock_num_OFF); + lock_scrl_on = qp_load_image_mem(gfx_lock_scrl_ON); + lock_scrl_off = qp_load_image_mem(gfx_lock_scrl_OFF); + thintel = qp_load_font_mem(font_thintel15); +} + +//---------------------------------------------------------- +// UI Drawing +void draw_ui_user(bool force_redraw) { + bool hue_redraw = force_redraw; + static uint16_t last_hue = 0xFFFF; +#if defined(RGB_MATRIX_ENABLE) + uint16_t curr_hue = rgb_matrix_get_hue(); +#else // defined(RGB_MATRIX_ENABLE) + uint16_t curr_hue = 0; +#endif // defined(RGB_MATRIX_ENABLE) + if (last_hue != curr_hue) { + last_hue = curr_hue; + hue_redraw = true; + } + + bool layer_state_redraw = false; + static uint32_t last_layer_state = 0; + if (last_layer_state != layer_state) { + last_layer_state = layer_state; + layer_state_redraw = true; + } + + bool power_state_redraw = false; + static usbpd_allowance_t last_current_state = (usbpd_allowance_t)(~0); + if (last_current_state != kb_state.current_setting) { + last_current_state = kb_state.current_setting; + power_state_redraw = true; + } + + bool scan_redraw = false; + static uint32_t last_scan_update = 0; + if (timer_elapsed32(last_scan_update) > 125) { + last_scan_update = timer_read32(); + scan_redraw = true; + } + + bool wpm_redraw = false; + static uint32_t last_wpm_update = 0; + if (timer_elapsed32(last_wpm_update) > 125) { + last_wpm_update = timer_read32(); + wpm_redraw = true; + } + +#if defined(RGB_MATRIX_ENABLE) + bool rgb_effect_redraw = false; + static uint16_t last_effect = 0xFFFF; + uint8_t curr_effect = rgb_matrix_config.mode; + if (last_effect != curr_effect) { + last_effect = curr_effect; + rgb_effect_redraw = true; + } +#endif // defined(RGB_MATRIX_ENABLE) + + // Show the Djinn logo and two vertical bars on both sides + if (hue_redraw) { + qp_drawimage_recolor(lcd, 120 - djinn_logo->width / 2, 32, djinn_logo, curr_hue, 255, 255, curr_hue, 255, 0); + qp_rect(lcd, 0, 0, 8, 319, curr_hue, 255, 255, true); + qp_rect(lcd, 231, 0, 239, 319, curr_hue, 255, 255, true); + } + + int ypos = 4; + + // Show layer info on the left side + if (is_keyboard_left()) { + char buf[64] = {0}; + int xpos = 16; + +#if defined(RGB_MATRIX_ENABLE) + if (hue_redraw || rgb_effect_redraw) { + static int max_rgb_xpos = 0; + xpos = 16; + snprintf(buf, sizeof(buf), "rgb: %s", rgb_matrix_name(curr_effect)); + + for (int i = 5; i < sizeof(buf); ++i) { + if (buf[i] == 0) + break; + else if (buf[i] == '_') + buf[i] = ' '; + else if (buf[i - 1] == ' ') + buf[i] = toupper(buf[i]); + else if (buf[i - 1] != ' ') + buf[i] = tolower(buf[i]); + } + + xpos += qp_drawtext_recolor(lcd, xpos, ypos, thintel, buf, curr_hue, 255, 255, curr_hue, 255, 0); + if (max_rgb_xpos < xpos) { + max_rgb_xpos = xpos; + } + qp_rect(lcd, xpos, ypos, max_rgb_xpos, ypos + thintel->line_height, 0, 0, 0, true); + } + + ypos += thintel->line_height + 4; +#endif // defined(RGB_MATRIX_ENABLE) + + if (hue_redraw || layer_state_redraw) { + extern const char *current_layer_name(void); + const char *layer_name = current_layer_name(); + + static int max_layer_xpos = 0; + xpos = 16; + snprintf(buf, sizeof(buf), "layer: %s", layer_name); + xpos += qp_drawtext_recolor(lcd, xpos, ypos, thintel, buf, curr_hue, 255, 255, curr_hue, 255, 0); + if (max_layer_xpos < xpos) { + max_layer_xpos = xpos; + } + qp_rect(lcd, xpos, ypos, max_layer_xpos, ypos + thintel->line_height, 0, 0, 0, true); + } + + ypos += thintel->line_height + 4; + + if (hue_redraw || power_state_redraw) { + static int max_power_xpos = 0; + xpos = 16; + snprintf(buf, sizeof(buf), "power: %s", usbpd_str(kb_state.current_setting)); + xpos += qp_drawtext_recolor(lcd, xpos, ypos, thintel, buf, curr_hue, 255, 255, curr_hue, 255, 0); + if (max_power_xpos < xpos) { + max_power_xpos = xpos; + } + qp_rect(lcd, xpos, ypos, max_power_xpos, ypos + thintel->line_height, 0, 0, 0, true); + } + + ypos += thintel->line_height + 4; + + if (hue_redraw || scan_redraw) { + static int max_scans_xpos = 0; + xpos = 16; + snprintf(buf, sizeof(buf), "scans: %d", (int)theme_state.scan_rate); + xpos += qp_drawtext_recolor(lcd, xpos, ypos, thintel, buf, curr_hue, 255, 255, curr_hue, 255, 0); + if (max_scans_xpos < xpos) { + max_scans_xpos = xpos; + } + qp_rect(lcd, xpos, ypos, max_scans_xpos, ypos + thintel->line_height, 0, 0, 0, true); + } + + ypos += thintel->line_height + 4; + + if (hue_redraw || wpm_redraw) { + static int max_wpm_xpos = 0; + xpos = 16; + snprintf(buf, sizeof(buf), "wpm: %d", (int)get_current_wpm()); + xpos += qp_drawtext_recolor(lcd, xpos, ypos, thintel, buf, curr_hue, 255, 255, curr_hue, 255, 0); + if (max_wpm_xpos < xpos) { + max_wpm_xpos = xpos; + } + qp_rect(lcd, xpos, ypos, max_wpm_xpos, ypos + thintel->line_height, 0, 0, 0, true); + } + + ypos += thintel->line_height + 4; + } + + // Show LED lock indicators on the right side + if (!is_keyboard_left()) { + static led_t last_led_state = {0}; + if (hue_redraw || last_led_state.raw != host_keyboard_led_state().raw) { + last_led_state.raw = host_keyboard_led_state().raw; + qp_drawimage_recolor(lcd, 239 - 12 - (32 * 3), 0, last_led_state.caps_lock ? lock_caps_on : lock_caps_off, curr_hue, 255, last_led_state.caps_lock ? 255 : 32, curr_hue, 255, 0); + qp_drawimage_recolor(lcd, 239 - 12 - (32 * 2), 0, last_led_state.num_lock ? lock_num_on : lock_num_off, curr_hue, 255, last_led_state.num_lock ? 255 : 32, curr_hue, 255, 0); + qp_drawimage_recolor(lcd, 239 - 12 - (32 * 1), 0, last_led_state.scroll_lock ? lock_scrl_on : lock_scrl_off, curr_hue, 255, last_led_state.scroll_lock ? 255 : 32, curr_hue, 255, 0); + } + } +} + +//---------------------------------------------------------- +// Sync + +theme_runtime_config theme_state; + +void rpc_theme_sync_callback(uint8_t m2s_size, const void *m2s_buffer, uint8_t s2m_size, void *s2m_buffer) { + if (m2s_size == sizeof(theme_state)) { + memcpy(&theme_state, m2s_buffer, m2s_size); + } +} + +void theme_init(void) { + // Register keyboard state sync split transaction + transaction_register_rpc(THEME_DATA_SYNC, rpc_theme_sync_callback); + + // Reset the initial shared data value between master and slave + memset(&theme_state, 0, sizeof(theme_state)); +} + +void theme_state_update(void) { + if (is_keyboard_master()) { + // Keep the scan rate in sync + theme_state.scan_rate = get_matrix_scan_rate(); + } +} + +void theme_state_sync(void) { + if (!is_transport_connected()) return; + + if (is_keyboard_master()) { + // Keep track of the last state, so that we can tell if we need to propagate to slave + static theme_runtime_config last_theme_state; + static uint32_t last_sync; + bool needs_sync = false; + + // Check if the state values are different + if (memcmp(&theme_state, &last_theme_state, sizeof(theme_runtime_config))) { + needs_sync = true; + memcpy(&last_theme_state, &theme_state, sizeof(theme_runtime_config)); + } + + // Send to slave every 125ms regardless of state change + if (timer_elapsed32(last_sync) > 125) { + needs_sync = true; + } + + // Perform the sync if requested + if (needs_sync) { + if (transaction_rpc_send(THEME_DATA_SYNC, sizeof(theme_runtime_config), &theme_state)) { + last_sync = timer_read32(); + } else { + dprint("Failed to perform rpc call\n"); + } + } + } +} diff --git a/keyboards/tzarc/djinn/keymaps/default/keymap.c b/keyboards/tzarc/djinn/keymaps/default/keymap.c new file mode 100644 index 0000000000..65b494cf32 --- /dev/null +++ b/keyboards/tzarc/djinn/keymaps/default/keymap.c @@ -0,0 +1,107 @@ +// Copyright 2018-2022 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#include QMK_KEYBOARD_H +#include "theme_djinn_default.h" + +// Layer definitions +enum { _QWERTY, _LOWER, _RAISE, _ADJUST }; + +//---------------------------------------------------------- +// Key map + +// clang-format off +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [_QWERTY] = LAYOUT_all( + KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_GRV, KC_DEL, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_LBRC, KC_RBRC, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLS, + KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_HOME, KC_PGUP, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_END, KC_PGDN, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT, + KC_LGUI, MO(_LOWER),KC_SPC, KC_NO, KC_NO, KC_SPC, MO(_RAISE),KC_LALT, + RGB_RMOD, RGB_MOD, + KC_UP, KC_UP, + KC_LEFT, _______, KC_RIGHT, KC_LEFT, _______, KC_RIGHT, + KC_DOWN, KC_DOWN + ), + [_LOWER] = LAYOUT_all( + KC_F12, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, _______, _______, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, + _______, _______, KC_UP, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, KC_LEFT, KC_DOWN, KC_RIGHT,_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, + BL_DOWN, BL_UP, + _______, _______, + _______, _______, _______, _______, _______, _______, + _______, _______ + ), + [_RAISE] = LAYOUT_all( + KC_F12, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, _______, _______, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, + _______,_______, KC_UP, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______,KC_LEFT, KC_DOWN, KC_RIGHT,_______, KC_UNDS, KC_NO, KC_NO, KC_EQL, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, KC_MINS, KC_NO, KC_NO, KC_PLUS, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, + _______, _______, + _______, _______, _______, _______, _______, _______, + _______, _______ + ), + [_ADJUST] = LAYOUT_all( + _______, KC_CAPS, KC_NUM, KC_SCRL, _______, _______, _______, _______, _______, _______, _______, DB_TOGG, EE_CLR, QK_BOOT, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, + _______, _______, + _______, _______, _______, _______, _______, _______, + _______, _______ + ) +}; +// clang-format on + +//---------------------------------------------------------- +// Encoder map + +// clang-format off +const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][2] = { + [_QWERTY] = { ENCODER_CCW_CW(KC_MS_WH_UP, KC_MS_WH_DOWN), ENCODER_CCW_CW(KC_VOLD, KC_VOLU) }, + [_LOWER] = { ENCODER_CCW_CW(RGB_HUD, RGB_HUI), ENCODER_CCW_CW(RGB_SAD, RGB_SAI) }, + [_RAISE] = { ENCODER_CCW_CW(RGB_VAD, RGB_VAI), ENCODER_CCW_CW(RGB_SPD, RGB_SPI) }, + [_ADJUST] = { ENCODER_CCW_CW(RGB_RMOD, RGB_MOD), ENCODER_CCW_CW(KC_LEFT, KC_RIGHT) }, +}; +// clang-format on + +//---------------------------------------------------------- +// Layer naming + +const char *current_layer_name(void) { + switch (get_highest_layer(layer_state)) { + case _QWERTY: + return "qwerty"; + case _LOWER: + return "lower"; + case _RAISE: + return "raise"; + case _ADJUST: + return "adjust"; + } + return "unknown"; +} + +//---------------------------------------------------------- +// Overrides + +void keyboard_post_init_user(void) { + // Initialise the theme + theme_init(); + + void keyboard_post_init_display(void); + keyboard_post_init_display(); +} + +void housekeeping_task_user(void) { + // Update kb_state so we can send to slave + theme_state_update(); + + // Data sync from master to slave + theme_state_sync(); +} diff --git a/keyboards/tzarc/djinn/rev1/config.h b/keyboards/tzarc/djinn/rev1/config.h new file mode 100644 index 0000000000..6f001cbd0c --- /dev/null +++ b/keyboards/tzarc/djinn/rev1/config.h @@ -0,0 +1,35 @@ +// Copyright 2018-2022 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#pragma once + +// Limit the backlight brightness +#ifndef BACKLIGHT_LIMIT_VAL +# define BACKLIGHT_LIMIT_VAL 144 +#endif // BACKLIGHT_LIMIT_VAL + +// Split configuration +#define SPLIT_HAND_PIN B11 +#ifdef USE_PLUG_DETECT_PIN +# define USB_VBUS_PIN B12 +#endif +#define SERIAL_USART_DRIVER SD3 +#define SERIAL_USART_TX_PAL_MODE 7 +#define SOFT_SERIAL_PIN B9 +#ifndef SERIAL_USART_SPEED +# define SERIAL_USART_SPEED 640000 +#endif // SERIAL_USART_SPEED + +// RGB configuration +#define RGBLED_NUM 84 +#define RGB_MATRIX_LED_COUNT 84 +#define RGB_MATRIX_SPLIT \ + { 42, 42 } +#define RGB_POWER_ENABLE_PIN B1 +#define RGB_CURR_1500mA_OK_PIN B0 +#define RGB_CURR_3000mA_OK_PIN C5 + +// EEPROM configuration +#define EXTERNAL_EEPROM_SPI_SLAVE_SELECT_PIN B5 +#define EXTERNAL_EEPROM_SPI_CLOCK_DIVISOR 8 // (160MHz/8) => 20MHz +#define EXTERNAL_EEPROM_BYTE_COUNT 8192 +#define EXTERNAL_EEPROM_PAGE_SIZE 64 // it's FRAM, so it doesn't actually matter, this just sets the RAM buffer size diff --git a/keyboards/tzarc/djinn/rev2/config.h b/keyboards/tzarc/djinn/rev2/config.h new file mode 100644 index 0000000000..b0deb6d991 --- /dev/null +++ b/keyboards/tzarc/djinn/rev2/config.h @@ -0,0 +1,47 @@ +// Copyright 2018-2022 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#pragma once + +// Limit the backlight brightness +#ifndef BACKLIGHT_LIMIT_VAL +# define BACKLIGHT_LIMIT_VAL 144 +#endif // BACKLIGHT_LIMIT_VAL + +// Split configuration +#define SPLIT_HAND_PIN B9 +#define USB_VBUS_PIN B12 +#define SERIAL_USART_DRIVER SD3 +#define SERIAL_USART_PIN_SWAP +#define SERIAL_USART_TX_PIN B10 +#define SERIAL_USART_TX_PAL_MODE 7 +#define SERIAL_USART_RX_PIN B11 +#define SERIAL_USART_RX_PAL_MODE 7 +#ifndef SERIAL_USART_SPEED +# define SERIAL_USART_SPEED 1200000 +#endif // SERIAL_USART_SPEED +#define SERIAL_USART_FULL_DUPLEX + +// RGB configuration +#define RGBLED_NUM 86 +#define RGB_MATRIX_LED_COUNT 86 +#define RGB_MATRIX_SPLIT \ + { 43, 43 } +#define RGB_POWER_ENABLE_PIN B0 +#define RGB_CURR_1500mA_OK_PIN C5 +#define RGB_CURR_3000mA_OK_PIN C4 + +// EEPROM configuration +#define EXTERNAL_EEPROM_SPI_SLAVE_SELECT_PIN B5 +#define EXTERNAL_EEPROM_SPI_CLOCK_DIVISOR 8 // (160MHz/8) => 20MHz +#define EXTERNAL_EEPROM_BYTE_COUNT 8192 +#define EXTERNAL_EEPROM_PAGE_SIZE 64 // it's FRAM, so it doesn't actually matter, this just sets the RAM buffer size + +// External flash config +#define EXTERNAL_FLASH_SPI_MODE 3 +#define EXTERNAL_FLASH_SPI_SLAVE_SELECT_PIN A8 +#define EXTERNAL_FLASH_SPI_CLOCK_DIVISOR 4 // (160MHz/4) => 40MHz +#define EXTERNAL_FLASH_SIZE (4 * 1024 * 1024) // 32Mb/4MB capacity + +// Fault indicators +#define BOARD_POWER_FAULT_PIN C9 +#define RGB_POWER_FAULT_PIN C4 |