Skip to content

Commit

Permalink
Review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
tzarc committed Jun 16, 2022
1 parent 2de1988 commit 3342e85
Show file tree
Hide file tree
Showing 23 changed files with 129 additions and 116 deletions.
24 changes: 4 additions & 20 deletions keyboards/tzarc/djinn/djinn_usbpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,10 @@ const char* usbpd_str(usbpd_allowance_t allowance) {
void usbpd_update(void) {
static uint32_t last_read = 0;
if (timer_elapsed32(last_read) > 250) {
last_read = timer_read32();
switch (usbpd_get_allowance()) {
case USBPD_500MA:
if (kb_state.current_setting != USBPD_500MA) {
dprintf("Transitioning UCPD1 %s -> %s\n", usbpd_str(kb_state.current_setting), usbpd_str(USBPD_500MA));
kb_state.current_setting = USBPD_500MA;
}
break;
case USBPD_1500MA:
if (kb_state.current_setting != USBPD_1500MA) {
dprintf("Transitioning UCPD1 %s -> %s\n", usbpd_str(kb_state.current_setting), usbpd_str(USBPD_1500MA));
kb_state.current_setting = USBPD_1500MA;
}
break;
case USBPD_3000MA:
if (kb_state.current_setting != USBPD_3000MA) {
dprintf("Transitioning UCPD1 %s -> %s\n", usbpd_str(kb_state.current_setting), usbpd_str(USBPD_3000MA));
kb_state.current_setting = USBPD_3000MA;
}
break;
usbpd_allowance_t allowance = usbpd_get_allowance();
if (kb_state.current_setting != allowance) {
dprintf("Transitioning UCPD1 %s -> %s\n", usbpd_str(kb_state.current_setting), usbpd_str(allowance));
kb_state.current_setting = allowance;
}
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
// Copyright 2018-2022 Nick Brassel (@tzarc)
// SPDX-License-Identifier: GPL-2.0-or-later
#include "djinn.qgf.c"
#include "lock-caps-ON.qgf.c"
#include "lock-scrl-ON.qgf.c"
#include "lock-num-ON.qgf.c"
#include "lock-caps-OFF.qgf.c"
#include "lock-scrl-OFF.qgf.c"
#include "lock-num-OFF.qgf.c"
#include "thintel15.qff.c"
#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;
Expand Down Expand Up @@ -200,7 +213,7 @@ void draw_ui_user(void) {
if (hue_redraw || scan_redraw) {
static int max_scans_xpos = 0;
xpos = 16;
snprintf_(buf, sizeof(buf), "scans: %d", (int)user_state.scan_rate);
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;
Expand Down Expand Up @@ -234,4 +247,61 @@ void draw_ui_user(void) {
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");
}
}
}
}
19 changes: 19 additions & 0 deletions keyboards/tzarc/djinn/graphics/theme_djinn_default.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2018-2022 Nick Brassel (@tzarc)
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

//----------------------------------------------------------
// Sync

#pragma pack(push)
#pragma pack(1)
typedef struct theme_runtime_config {
uint32_t scan_rate;
} theme_runtime_config;
#pragma pack(pop)

extern theme_runtime_config theme_state;

void theme_init(void);
void theme_state_update(void);
void theme_state_sync(void);
2 changes: 1 addition & 1 deletion keyboards/tzarc/djinn/keymaps/default/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define RGB_MATRIX_FRAMEBUFFER_EFFECTS

// Allow for an extra sync command over the split
#define SPLIT_TRANSACTION_IDS_USER USER_DATA_SYNC
#define SPLIT_TRANSACTION_IDS_USER THEME_DATA_SYNC

// RGB Effects
#define ENABLE_RGB_MATRIX_ALPHAS_MODS
Expand Down
84 changes: 10 additions & 74 deletions keyboards/tzarc/djinn/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
// 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 "backlight.h"
#include "qp.h"
#include <printf.h>
#include "transactions.h"
#include "split_util.h"
#include "theme_djinn_default.h"

// Layer definitions
enum { _QWERTY, _LOWER, _RAISE, _ADJUST };
Expand Down Expand Up @@ -95,81 +88,24 @@ const char *current_layer_name(void) {
}

//----------------------------------------------------------
// Sync

#pragma pack(push)
#pragma pack(1)
typedef struct user_runtime_config {
uint32_t scan_rate;
} user_runtime_config;
#pragma pack(pop)

user_runtime_config user_state;

void rpc_user_sync_callback(uint8_t m2s_size, const void *m2s_buffer, uint8_t s2m_size, void *s2m_buffer) {
if (m2s_size == sizeof(user_state)) {
memcpy(&user_state, m2s_buffer, m2s_size);
}
}
// Overrides

void keyboard_post_init_user(void) {
// Register keyboard state sync split transaction
transaction_register_rpc(USER_DATA_SYNC, rpc_user_sync_callback);

// Reset the initial shared data value between master and slave
memset(&user_state, 0, sizeof(user_state));
#ifdef DJINN_DEFAULT_THEME
// Initialise the theme
theme_init();
#endif // DJINN_DEFAULT_THEME

void keyboard_post_init_display(void);
keyboard_post_init_display();
}

void user_state_update(void) {
if (is_keyboard_master()) {
// Keep the scan rate in sync
user_state.scan_rate = get_matrix_scan_rate();
}
}

void user_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 user_runtime_config last_user_state;
static uint32_t last_sync;
bool needs_sync = false;

// Check if the state values are different
if (memcmp(&user_state, &last_user_state, sizeof(user_runtime_config))) {
needs_sync = true;
memcpy(&last_user_state, &user_state, sizeof(user_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(USER_DATA_SYNC, sizeof(user_runtime_config), &user_state)) {
last_sync = timer_read32();
} else {
dprint("Failed to perform rpc call\n");
}
}
}
}

void housekeeping_task_user(void) {
#ifdef DJINN_DEFAULT_THEME
// Update kb_state so we can send to slave
user_state_update();
theme_state_update();

// Data sync from master to slave
user_state_sync();
theme_state_sync();
#endif // DJINN_DEFAULT_THEME
}

//----------------------------------------------------------
// Display theme

#include "theme_djinn_default.inl.c"
12 changes: 1 addition & 11 deletions keyboards/tzarc/djinn/keymaps/default/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,4 @@ DEBUG_MATRIX_SCAN_RATE_ENABLE ?= api
ENCODER_MAP_ENABLE = yes
SWAP_HANDS_ENABLE = no

VPATH += \
$(KEYBOARD_PATH_5)/graphics \
$(KEYBOARD_PATH_5)/graphics/src \
$(KEYBOARD_PATH_4)/graphics \
$(KEYBOARD_PATH_4)/graphics/src \
$(KEYBOARD_PATH_3)/graphics \
$(KEYBOARD_PATH_3)/graphics/src \
$(KEYBOARD_PATH_2)/graphics \
$(KEYBOARD_PATH_2)/graphics/src \
$(KEYBOARD_PATH_1)/graphics \
$(KEYBOARD_PATH_1)/graphics/src
DJINN_DEFAULT_THEME = yes
14 changes: 14 additions & 0 deletions keyboards/tzarc/djinn/post_rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ifeq ($(DJINN_DEFAULT_THEME),yes)
OPT_DEFS += -DDJINN_DEFAULT_THEME
VPATH += keyboards/tzarc/djinn/graphics
SRC += \
theme_djinn_default.c \
djinn.qgf.c \
lock-caps-ON.qgf.c \
lock-scrl-ON.qgf.c \
lock-num-ON.qgf.c \
lock-caps-OFF.qgf.c \
lock-scrl-OFF.qgf.c \
lock-num-OFF.qgf.c \
thintel15.qff.c
endif

0 comments on commit 3342e85

Please sign in to comment.