Fixed the issue that the tide65 keyboard does not work properly when powered by battery only in wired mode

This commit is contained in:
sdk 2024-08-19 16:27:14 +08:00
parent 49060b5f89
commit 8af4355646
6 changed files with 125 additions and 28 deletions

View File

@ -27,11 +27,13 @@
#define HS_RGB_BLINK_INDEX_BT2 42
#define HS_RGB_BLINK_INDEX_BT3 41
#define HS_RGB_BLINK_INDEX_2G4 34
#define HS_RGB_BLINK_INDEX_USB 39
#define HS_LBACK_COLOR_BT1 RGB_BLUE
#define HS_LBACK_COLOR_BT2 RGB_BLUE
#define HS_LBACK_COLOR_BT3 RGB_BLUE
#define HS_LBACK_COLOR_2G4 RGB_GREEN
#define HS_LBACK_COLOR_UBS RGB_WHITE
#define HS_PAIR_COLOR_BT1 RGB_BLUE
#define HS_PAIR_COLOR_BT2 RGB_BLUE

View File

@ -194,13 +194,13 @@
"val" :153,
"speed" :204
},
"sleep": false,
"timeout": 300000
"sleep": true,
"timeout": 60000
},
"tap_keycode_delay": 10,
"url": "https://www.epomaker.com",
"usb": {
"device_version": "0.2.0",
"device_version": "0.3.0",
"force_nkro": true,
"pid": "0xE463",
"suspend_wakeup_delay": 1000,

View File

@ -5,6 +5,8 @@
#ifdef WIRELESS_ENABLE
# include "wireless.h"
# include "usb_main.h"
# include "lowpower.h"
#endif
typedef union {
@ -56,6 +58,7 @@ bool charging_state = false;
bool bat_full_flag = false;
bool enable_bat_indicators = true;
uint32_t bat_indicator_cnt = true;
static uint32_t ee_clr_timer = 0;
void eeconfig_confinfo_update(uint32_t raw) {
@ -99,8 +102,8 @@ void keyboard_post_init_kb(void) {
#endif
#ifdef USB_POWER_EN_PIN
gpio_set_pin_output(USB_POWER_EN_PIN);
gpio_write_pin_low(USB_POWER_EN_PIN);
gpio_set_pin_output(USB_POWER_EN_PIN);
#endif
#ifdef HS_BAT_CABLE_PIN
@ -113,6 +116,7 @@ void keyboard_post_init_kb(void) {
#ifdef WIRELESS_ENABLE
wireless_init();
wireless_devs_change(!confinfo.devs, confinfo.devs, false);
post_init_timer = timer_read32();
#endif
@ -153,6 +157,15 @@ void suspend_wakeup_init_kb(void) {
suspend_wakeup_init_user();
}
bool lpwr_is_allow_timeout_hook(void) {
if (wireless_get_current_devs() == DEVS_USB) {
return false;
}
return true;
}
void wireless_post_task(void) {
// auto switching devs
@ -269,8 +282,10 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case EE_CLR:{
if (record->event.pressed){
hs_reset_settings();
if (record->event.pressed) {
ee_clr_timer = timer_read32();
} else {
ee_clr_timer = 0;
}
return false;
break;
@ -587,7 +602,7 @@ void bat_indicators(void) {
} else if (charging_state) {
battery_process_time = 0;
rgb_matrix_hs_bat_set(HS_MATRIX_BLINK_INDEX_BAT, (RGB){RGB_RED}, 300, 0xFF);
rgb_matrix_set_color(HS_MATRIX_BLINK_INDEX_BAT, RGB_RED);
} else if (*md_getp_bat() <= BATTERY_CAPACITY_LOW) {
rgb_matrix_hs_bat_set(HS_MATRIX_BLINK_INDEX_BAT, (RGB){RGB_RED}, 250, 1);
@ -654,28 +669,55 @@ bool rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {
return false;
}
if (ee_clr_timer && timer_elapsed32(ee_clr_timer) > 3000) {
hs_reset_settings();
ee_clr_timer = 0;
}
extern RGB rgb_matrix_ws2812_array[HS_RGB_INDICATOR_COUNT];
uint8_t r,g,b;
r = rgb_matrix_ws2812_array[1].r;
g = rgb_matrix_ws2812_array[1].g;
b = rgb_matrix_ws2812_array[1].b;
rgb_matrix_set_color(2,r,g,b);
if ((*md_getp_state() == MD_STATE_CONNECTED) || USB_DRIVER.state == USB_ACTIVE)
{
if (host_keyboard_led_state().caps_lock)
rgb_matrix_set_color(HS_RGB_INDEX_CAPS, RGB_WHITE);
if (!keymap_is_mac_system() && keymap_config.no_gui)
rgb_matrix_set_color(HS_RGB_INDEX_WIN_LOCK, RGB_WHITE);
}
# ifdef WIRELESS_ENABLE
rgb_matrix_wls_indicator();
if (enable_bat_indicators) {
if (enable_bat_indicators && !inqbat_flag) {
rgb_matrix_hs_bat();
bat_indicators();
bat_indicator_cnt = timer_read32();
}
if(!enable_bat_indicators){
if(timer_elapsed32(bat_indicator_cnt) > 3000){
if (!enable_bat_indicators) {
if (timer_elapsed32(bat_indicator_cnt) > 2000){
enable_bat_indicators = true;
bat_indicator_cnt = timer_read32();
}
}
if (confinfo.devs == DEVS_USB){
if (USB_DRIVER.state != USB_ACTIVE) {
if(enable_bat_indicators){
rgb_matrix_hs_indicator_set(HS_RGB_BLINK_INDEX_USB, (RGB){HS_LBACK_COLOR_UBS}, 500, 1);
}
} else {
lpwr_set_state(LPWR_WAKEUP);
}
}
# endif
rgb_matrix_hs_indicator();
@ -720,6 +762,10 @@ void hs_reset_settings(void) {
eeconfig_update_keymap(keymap_config.raw);
#endif
#if defined(WIRELESS_ENABLE)
wireless_devs_change(wireless_get_current_devs(), DEVS_USB, false);
#endif
if (hs_reset_settings_user() != true) {
return;
}

View File

@ -2,7 +2,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "quantum.h"
#include "lowpower.h"
#include "wireless.h"
#include "usb_main.h"
#ifndef LPWR_TIMEOUT
# define LPWR_TIMEOUT 300000 // 5min
@ -132,6 +133,12 @@ bool lpwr_is_allow_timeout(void) {
uint32_t timeout = lpwr_timeout_value_read();
if (lpwr_is_allow_timeout_hook() != true) {
manual_timeout = false;
return false;
}
if ((wireless_get_current_devs() == DEVS_USB) && (USB_DRIVER.state == USB_ACTIVE)) {
manual_timeout = false;
return false;
}

View File

@ -6,6 +6,10 @@
#include "usb_main.h"
#include "transport.h"
#ifndef USB_POWER_DOWN_DELAY
# define USB_POWER_DOWN_DELAY 3000
#endif
extern host_driver_t chibios_driver;
extern host_driver_t wireless_driver;
@ -92,6 +96,7 @@ transport_t get_transport(void) {
void usb_remote_wakeup(void) {
#ifdef USB_REMOTE_USE_QMK
if (USB_DRIVER.state == USB_SUSPENDED) {
dprintln("suspending keyboard");
while (USB_DRIVER.state == USB_SUSPENDED) {
@ -100,7 +105,7 @@ void usb_remote_wakeup(void) {
/* Remote wakeup */
if ((USB_DRIVER.status & 2U) && suspend_wakeup_condition()) {
usbWakeupHost(&USB_DRIVER);
#if USB_SUSPEND_WAKEUP_DELAY > 0
# if USB_SUSPEND_WAKEUP_DELAY > 0
// Some hubs, kvm switches, and monitors do
// weird things, with USB device state bouncing
// around wildly on wakeup, yielding race
@ -108,9 +113,55 @@ void usb_remote_wakeup(void) {
//
// Pause for a while to let things settle...
wait_ms(USB_SUSPEND_WAKEUP_DELAY);
#endif
# endif
}
}
/* Woken up */
}
#else
static uint32_t suspend_timer = 0x00;
if ((USB_DRIVER.state == USB_SUSPENDED)) {
if (!suspend_timer) suspend_timer = sync_timer_read32();
if (sync_timer_elapsed32(suspend_timer) >= USB_POWER_DOWN_DELAY) {
suspend_timer = 0x00;
suspend_power_down();
}
} else {
suspend_timer = 0x00;
}
#endif
}
#ifndef USB_REMOTE_USE_QMK
void usb_remote_host(void) {
if (USB_DRIVER.state == USB_SUSPENDED) {
if ((USB_DRIVER.status & 2U) && suspend_wakeup_condition()) {
usbWakeupHost(&USB_DRIVER);
# if USB_SUSPEND_WAKEUP_DELAY > 0
// Some hubs, kvm switches, and monitors do
// weird things, with USB device state bouncing
// around wildly on wakeup, yielding race
// conditions that can corrupt the keyboard state.
//
// Pause for a while to let things settle...
wait_ms(USB_SUSPEND_WAKEUP_DELAY);
# endif
}
# if !defined(USB_REMOTE_USE_QMK) && USB_POWER_DOWN_DELAY
suspend_wakeup_init();
# endif
}
}
bool process_action_kb(keyrecord_t *record) {
(void)record;
if (get_transport() == TRANSPORT_USB){
usb_remote_host();
}
return true;
}
#endif

View File

@ -211,15 +211,6 @@ uint8_t wireless_get_current_devs(void) {
return wls_devs;
}
bool lpwr_is_allow_timeout_hook(void) {
if (wls_devs == DEVS_USB) {
return false;
}
return true;
}
void wireless_pre_task(void) __attribute__((weak));
void wireless_pre_task(void) {}