Add wireless functionality for tide65

This commit is contained in:
sdk66 2024-07-29 18:36:11 +08:00
parent ec5a9767d2
commit a48c084042
8 changed files with 1027 additions and 44 deletions

View File

@ -0,0 +1,77 @@
// Copyright 2024 SDK (@sdk66)
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#ifdef WIRELESS_ENABLE
# define LPWR_TIMEOUT RGB_MATRIX_TIMEOUT
#endif
#define USB_POWER_EN_PIN B1 //USB ENABLE pin
#define LED_POWER_EN_PIN A5 //LED ENABLE pin
#define HS_BAT_CABLE_PIN A7 //USB insertion detection pin
#define BAT_FULL_PIN A15
#define BAT_FULL_STATE 1
/* Battery */
#define BATTERY_CAPACITY_LOW 15
#define BATTERY_CAPACITY_STOP 0
#define HS_RGB_INDICATOR_COUNT 69
#define HS_RGB_BAT_COUNT 1
#define RGB_MATRIX_BAT_INDEX_MAP {11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
/* Device Connection RGB Indicator Light Index And Color */
#define HS_RGB_BLINK_INDEX_BT1 43
#define HS_RGB_BLINK_INDEX_BT2 42
#define HS_RGB_BLINK_INDEX_BT3 41
#define HS_RGB_BLINK_INDEX_2G4 34
#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_PAIR_COLOR_BT1 RGB_BLUE
#define HS_PAIR_COLOR_BT2 RGB_BLUE
#define HS_PAIR_COLOR_BT3 RGB_BLUE
#define HS_PAIR_COLOR_2G4 RGB_GREEN
/* Status Indicator Lamp */
#define HS_MATRIX_BLINK_INDEX_BAT 57
#define HS_RGB_INDEX_CAPS 8
#define HS_RGB_INDEX_WIN_LOCK 5
#define HS_RGB_BLINK_INDEX_VAI 29
#define HS_RGB_BLINK_INDEX_VAD 28
#define HS_RGB_BLINK_INDEX_SPI 27
#define HS_RGB_BLINK_INDEX_SPD 56
#define HS_RGB_BLINK_INDEX_WIN 44
#define HS_RGB_BLINK_INDEX_MAC 45
/* UART */
#define SERIAL_DRIVER SD3
#define SD1_TX_PIN C10
#define SD1_RX_PIN C11
/* Encoder */
#define ENCODER_MAP_KEY_DELAY 1
/* SPI */
#define SPI_DRIVER SPIDQ
#define SPI_SCK_PIN B3
#define SPI_MOSI_PIN B5
#define SPI_MISO_PIN B4
/* Flash */
#define EXTERNAL_FLASH_SPI_SLAVE_SELECT_PIN C12
#define WEAR_LEVELING_LOGICAL_SIZE (WEAR_LEVELING_BACKING_SIZE / 2)
/* RGB Matrix */
#define WS2812_BYTE_ORDER WS2812_BYTE_ORDER_RGB
#define RGB_MATRIX_FRAMEBUFFER_EFFECTS
#define RGB_MATRIX_KEYPRESSES
/* WS2812 */
#define WS2812_SPI_DRIVER SPIDM2
#define WS2812_SPI_DIVISOR 32

View File

@ -0,0 +1,10 @@
// Copyright 2024 SDK (@sdk66)
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#define HAL_USE_SERIAL TRUE
#define HAL_USE_SPI TRUE
#define PAL_USE_CALLBACKS TRUE
#include_next <halconf.h>

View File

@ -1,21 +1,68 @@
{ {
"manufacturer": "HS", "manufacturer": "EPOMAKER",
"keyboard_name": "EPOMAKER TIDE 65", "keyboard_name": "TIDE65",
"maintainer": "sdk66", "maintainer": "sdk66",
"bootloader": "wb32-dfu", "bootloader": "wb32-dfu",
"bootmagic": {
"matrix": [0, 0]
},
"debounce": 1,
"diode_direction": "ROW2COL", "diode_direction": "ROW2COL",
"eeprom": {
"driver": "wear_leveling",
"wear_leveling": {
"backing_size": 4096,
"driver": "spi_flash"
}
},
"encoder": { "encoder": {
"rotary": [ "rotary": [
{"pin_a": "B7", "pin_b": "B6"} {"pin_a": "B7", "pin_b": "B6"}
] ]
}, },
"features": { "features": {
"bootmagic": true, "combo": false,
"encoder": true, "command": false,
"console": false,
"extrakey": true, "extrakey": true,
"mousekey": true, "mousekey": true,
"nkro": true, "nkro": true,
"rgb_matrix": true "rgb_matrix": true,
"deferred_exec": true,
"rgblight": false,
"encoder": true
},
"keycodes": [
{
"key": "KC_USB"
},
{
"key": "KC_BT1"
},
{
"key": "KC_BT2"
},
{
"key": "KC_BT3"
},
{
"key": "KC_BT4"
},
{
"key": "KC_BT5"
},
{
"key": "KC_2G4"
},
{
"key": "KC_BATQ"
},
{
"key": "KC_FTOG"
}
],
"dynamic_keymap": {
"layer_count": 9
}, },
"matrix_pins": { "matrix_pins": {
"cols": ["C0", "C1", "C2", "C3", "A6", "B10", "B11", "B12", "B13", "B14", "A10", "C6", "C7", "C8", "C9"], "cols": ["C0", "C1", "C2", "C3", "A6", "B10", "B11", "B12", "B13", "B14", "A10", "C6", "C7", "C8", "C9"],
@ -55,6 +102,7 @@
"rainbow_moving_chevron": true, "rainbow_moving_chevron": true,
"rainbow_pinwheels": true, "rainbow_pinwheels": true,
"raindrops": true, "raindrops": true,
"solid_color": true,
"solid_multisplash": true, "solid_multisplash": true,
"solid_reactive": true, "solid_reactive": true,
"solid_reactive_cross": true, "solid_reactive_cross": true,
@ -139,18 +187,29 @@
{"matrix": [4, 12], "x": 192, "y": 64, "flags": 4}, {"matrix": [4, 12], "x": 192, "y": 64, "flags": 4},
{"matrix": [4, 13], "x": 208, "y": 64, "flags": 4}, {"matrix": [4, 13], "x": 208, "y": 64, "flags": 4},
{"matrix": [4, 14], "x": 224, "y": 64, "flags": 4} {"matrix": [4, 14], "x": 224, "y": 64, "flags": 4}
] ],
"max_brightness": 200,
"val_steps": 40,
"speed_steps": 51,
"default": {
"val" :153,
"speed" :204
},
"sleep": false,
"timeout": 300000
}, },
"url": "", "tap_keycode_delay": 10,
"url": "https://www.epomaker.com",
"usb": { "usb": {
"device_version": "0.0.1", "device_version": "0.2.0",
"force_nkro": true, "force_nkro": true,
"pid": "0xE463", "pid": "0xE463",
"suspend_wakeup_delay": 1000, "suspend_wakeup_delay": 1000,
"vid": "0x342D" "vid": "0x342D"
}, },
"ws2812": { "ws2812": {
"pin": "B15" "pin": "B15",
"driver": "spi"
}, },
"layouts": { "layouts": {
"LAYOUT": { "LAYOUT": {

View File

@ -6,21 +6,27 @@
// clang-format off // clang-format off
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT( /* Base */ [0] = LAYOUT(
KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_MUTE, KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_MUTE,
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL, KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_PGUP,
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGUP, KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGDN,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_PGDN, KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_END,
KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_SPC, KC_SPC, KC_SPC, KC_RALT, MO(1), KC_LEFT, KC_DOWN, KC_RGHT KC_LCTL, KC_LCMD, KC_LALT, KC_SPC, KC_SPC, KC_SPC, KC_SPC, KC_RALT, MO(1), KC_LEFT, KC_DOWN, KC_RGHT
), ),
[1] = LAYOUT( /* Base */ [1] = LAYOUT(
KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_SCRL, _______, _______, _______, KC_BT1, KC_BT2, KC_BT3, _______, KC_USB, _______, _______, _______, _______, KC_2G4, KC_HOME, KC_SCRL, RGB_MOD, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_PSCR, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_PSCR, KC_BATQ, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_TOG, _______, _______, _______, _______, _______, _______, RGB_HUI, _______, _______, _______, RGB_VAI, _______,
_______, GU_TOGG, _______, EE_CLR, EE_CLR, EE_CLR, EE_CLR, _______, _______, _______, _______, _______ _______, GU_TOGG, _______, EE_CLR, EE_CLR, EE_CLR, EE_CLR, KC_RCTL, _______, RGB_SPD, RGB_VAD, RGB_SPI
) ),
}; };
#ifdef ENCODER_MAP_ENABLE
const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
[0] = {ENCODER_CCW_CW(KC_VOLD, KC_VOLU)},
[1] = {ENCODER_CCW_CW(_______, _______)},
};
#endif
// clang-format on // clang-format on

View File

@ -3,31 +3,106 @@
#include QMK_KEYBOARD_H #include QMK_KEYBOARD_H
enum layers {
_BL = 0,
_FL,
_MBL,
_MFL,
_FBL,
_FFL,
_FMBL,
_FMFL,
_DEFA
};
// clang-format off // clang-format off
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT( /* Base */ [_BL] = LAYOUT( /* win Base */
KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_MUTE, KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_MUTE,
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL, KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_PGUP,
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGUP, KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGDN,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_PGDN, KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_END,
KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_SPC, KC_SPC, KC_SPC, KC_RALT, MO(1), KC_LEFT, KC_DOWN, KC_RGHT KC_LCTL, KC_LCMD, KC_LALT, KC_SPC, KC_SPC, KC_SPC, KC_SPC, KC_RALT, MO(_FL), KC_LEFT, KC_DOWN, KC_RGHT
), ),
[_FL] = LAYOUT( /* win FN */
KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______,
_______, KC_BT1, KC_BT2, KC_BT3, _______, KC_USB, _______, _______, _______, _______, KC_2G4, KC_HOME, KC_SCRL, RGB_MOD, _______,
_______, KC_NO, TO(_MBL), _______, _______, _______, _______, _______, _______, _______, _______, KC_PSCR, KC_BATQ, _______,
_______, RGB_TOG, _______, _______, _______, _______, _______, _______, RGB_HUI, _______, _______, MO(_DEFA),RGB_VAI, _______,
KC_FTOG, GU_TOGG, _______, EE_CLR, EE_CLR, EE_CLR, EE_CLR, KC_RCTL, _______, RGB_SPD, RGB_VAD, RGB_SPI
),
[_MBL] = LAYOUT(
KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_MUTE,
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_PGUP,
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGDN,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_END,
KC_LCTL, KC_LALT, KC_LCMD, KC_SPC, KC_SPC, KC_SPC, KC_SPC, KC_RCMD, MO(_MFL), KC_LEFT, KC_DOWN, KC_RGHT
),
[_MFL] = LAYOUT(
KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______,
_______, KC_BT1, KC_BT2, KC_BT3, _______, KC_USB, _______, _______, _______, _______, KC_2G4, KC_HOME, KC_SCRL, RGB_MOD, _______,
_______, TO(_BL), KC_NO, _______, _______, _______, _______, _______, _______, _______, _______, KC_PSCR, KC_BATQ, _______,
_______, RGB_TOG, _______, _______, _______, _______, _______, _______, RGB_HUI, _______, _______, MO(_DEFA),RGB_VAI, _______,
KC_FTOG, _______, _______, EE_CLR, EE_CLR, EE_CLR, EE_CLR, KC_RCTL, _______, RGB_SPD, RGB_VAD, RGB_SPI
),
[_FBL] = LAYOUT(
KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_BSPC, KC_MUTE,
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_PGUP,
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGDN,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_END,
KC_LCTL, KC_LCMD, KC_LALT, KC_SPC, KC_SPC, KC_SPC, KC_SPC, KC_RALT, MO(_FFL), KC_LEFT, KC_DOWN, KC_RGHT
),
[_FFL] = LAYOUT(
KC_GRV, KC_MYCM, KC_WHOM, KC_MAIL, KC_CALC, KC_MSEL, KC_MSTP, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, _______, _______,
_______, KC_BT1, KC_BT2, KC_BT3, _______, KC_USB, _______, _______, _______, _______, KC_2G4, KC_HOME, KC_SCRL, RGB_MOD, _______,
_______, KC_NO, TO(_FMBL),_______, _______, _______, _______, _______, _______, _______, _______, KC_PSCR, KC_BATQ, _______,
_______, RGB_TOG, _______, _______, _______, _______, _______, _______, RGB_HUI, _______, _______, MO(_DEFA),RGB_VAI, _______,
KC_FTOG, GU_TOGG, _______, EE_CLR, EE_CLR, EE_CLR, EE_CLR, KC_RCTL, _______, RGB_SPD, RGB_VAD, RGB_SPI
),
[_FMBL] = LAYOUT(
KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_BSPC, KC_MUTE,
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_PGUP,
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGDN,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_END,
KC_LCTL, KC_LALT, KC_LCMD, KC_SPC, KC_SPC, KC_SPC, KC_SPC, KC_RCMD, MO(_FMFL),KC_LEFT, KC_DOWN, KC_RGHT
),
[_FMFL] = LAYOUT(
KC_GRV, KC_BRID, KC_BRIU, KC_F3, KC_F4, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, _______, _______,
_______, KC_BT1, KC_BT2, KC_BT3, _______, KC_USB, _______, _______, _______, _______, KC_2G4, KC_HOME, KC_SCRL, RGB_MOD, _______,
_______, TO(_FBL), KC_NO, _______, _______, _______, _______, _______, _______, _______, _______, KC_PSCR, KC_BATQ, _______,
_______, RGB_TOG, _______, _______, _______, _______, _______, _______, RGB_HUI, _______, _______, MO(_DEFA),RGB_VAI, _______,
KC_FTOG, _______, _______, EE_CLR, EE_CLR, EE_CLR, EE_CLR, KC_RCTL, _______, RGB_SPD, RGB_VAD, RGB_SPI
),
[_DEFA] = LAYOUT(
KC_TILD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, QK_BOOT,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
),
[1] = LAYOUT( /* Base */
KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_SCRL, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_PSCR, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, GU_TOGG, _______, EE_CLR, EE_CLR, EE_CLR, EE_CLR, _______, _______, _______, _______, _______
)
}; };
#ifdef ENCODER_MAP_ENABLE #ifdef ENCODER_MAP_ENABLE
const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
[0] = {ENCODER_CCW_CW(KC_VOLD, KC_VOLU)}, [0] = {ENCODER_CCW_CW(KC_VOLD, KC_VOLU)},
[1] = {ENCODER_CCW_CW(_______, _______)}, [1] = {ENCODER_CCW_CW(_______, _______)},
[2] = {ENCODER_CCW_CW(_______, _______)},
[3] = {ENCODER_CCW_CW(_______, _______)},
[4] = {ENCODER_CCW_CW(_______, _______)},
[5] = {ENCODER_CCW_CW(_______, _______)},
[6] = {ENCODER_CCW_CW(_______, _______)},
[7] = {ENCODER_CCW_CW(_______, _______)},
[8] = {ENCODER_CCW_CW(_______, _______)}
}; };
#endif #endif
// clang-format on // clang-format on

View File

@ -0,0 +1,38 @@
// Copyright 2024 SDK (@sdk66)
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include_next <mcuconf.h>
#undef WB32_USB_HOST_WAKEUP_DURATION
#define WB32_USB_HOST_WAKEUP_DURATION 2
#undef WB32_SERIAL_USE_UART3
#define WB32_SERIAL_USE_UART3 TRUE
#undef WB32_SPI_USE_SPIM2
#define WB32_SPI_USE_SPIM2 TRUE
#undef WB32_SPI_USE_QSPI
#define WB32_SPI_USE_QSPI TRUE
// The interrupt priority of the WS2812 driver must be higher than that of other SPI devices.
#undef WB32_SPI_SPIM2_IRQ_PRIORITY
#define WB32_SPI_SPIM2_IRQ_PRIORITY 9
#undef WB32_SPI_QSPI_IRQ_PRIORITY
#define WB32_SPI_QSPI_IRQ_PRIORITY 10
#undef WB32_SERIAL_UART3_PRIORITY
#define WB32_SERIAL_UART3_PRIORITY 8
/* system clock set to 96Mhz */
#undef WB32_PLLDIV_VALUE
#define WB32_PLLDIV_VALUE 2
#undef WB32_PLLMUL_VALUE
#define WB32_PLLMUL_VALUE 16
#undef WB32_USBPRE
#define WB32_USBPRE WB32_USBPRE_DIV2

View File

@ -0,0 +1 @@
include keyboards/linker/wireless/wireless.mk

View File

@ -1,10 +1,727 @@
// Copyright 2024 SDK (@sdk66) // Copyright 2024 SDK (@sdk66)
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include "quantum.h" #include QMK_KEYBOARD_H
void keyboard_pre_init_kb(void) { #ifdef WIRELESS_ENABLE
gpio_set_pin_output(A5); # include "wireless.h"
gpio_write_pin_high(A5); #endif
keyboard_pre_init_user();
typedef union {
uint32_t raw;
struct {
uint8_t flag : 1;
uint8_t devs : 3;
};
} confinfo_t;
confinfo_t confinfo;
enum layers {
_BL = 0,
_FL,
_MBL,
_MFL,
_FBL,
_FFL,
_FMBL,
_FMFL,
_DEFA
};
typedef struct {
bool active;
uint32_t timer;
uint32_t interval;
uint32_t times;
uint8_t index;
RGB rgb;
} hs_rgb_indicator_t;
hs_rgb_indicator_t hs_rgb_indicators[HS_RGB_INDICATOR_COUNT];
hs_rgb_indicator_t hs_rgb_bat[HS_RGB_BAT_COUNT];
void bat_indicators(void);
void rgb_blink_dir(void);
void hs_reset_settings(void);
void rgb_matrix_hs_indicator(void);
void rgb_matrix_hs_indicator_set(uint8_t index, RGB rgb, uint32_t interval, uint8_t times);
#define keymap_is_mac_system() ((get_highest_layer(default_layer_state) == _MBL) || (get_highest_layer(default_layer_state) == _FMBL))
#define keymap_is_base_layer() ((get_highest_layer(default_layer_state) == _BL) || (get_highest_layer(default_layer_state) == _MBL))
uint32_t post_init_timer = 0x00;
bool inqbat_flag = false;
bool mac_status = false;
bool charging_state = false;
bool bat_full_flag = false;
bool enable_bat_indicators = true;
uint32_t bat_indicator_cnt = true;
void eeconfig_confinfo_update(uint32_t raw) {
eeconfig_update_kb(raw);
}
uint32_t eeconfig_confinfo_read(void) {
return eeconfig_read_kb();
}
void eeconfig_confinfo_default(void) {
confinfo.flag = true;
#ifdef WIRELESS_ENABLE
confinfo.devs = DEVS_USB;
#endif
eeconfig_confinfo_update(confinfo.raw);
}
void eeconfig_confinfo_init(void) {
confinfo.raw = eeconfig_confinfo_read();
if (!confinfo.raw) {
eeconfig_confinfo_default();
}
}
void keyboard_post_init_kb(void) {
#ifdef CONSOLE_ENABLE
debug_enable = true;
#endif
eeconfig_confinfo_init();
#ifdef LED_POWER_EN_PIN
gpio_set_pin_output(LED_POWER_EN_PIN);
gpio_write_pin_high(LED_POWER_EN_PIN);
#endif
#ifdef USB_POWER_EN_PIN
gpio_set_pin_output(USB_POWER_EN_PIN);
gpio_write_pin_low(USB_POWER_EN_PIN);
#endif
#ifdef HS_BAT_CABLE_PIN
setPinInputHigh(HS_BAT_CABLE_PIN);
#endif
#ifdef BAT_FULL_PIN
setPinInputHigh(BAT_FULL_PIN);
#endif
#ifdef WIRELESS_ENABLE
wireless_init();
post_init_timer = timer_read32();
#endif
keyboard_post_init_user();
}
#ifdef WIRELESS_ENABLE
void usb_power_connect(void) {
# ifdef USB_POWER_EN_PIN
gpio_write_pin_low(USB_POWER_EN_PIN);
# endif
}
void usb_power_disconnect(void) {
# ifdef USB_POWER_EN_PIN
gpio_write_pin_high(USB_POWER_EN_PIN);
# endif
}
void suspend_power_down_kb(void) {
# ifdef LED_POWER_EN_PIN
gpio_write_pin_low(LED_POWER_EN_PIN);
# endif
suspend_power_down_user();
}
void suspend_wakeup_init_kb(void) {
# ifdef LED_POWER_EN_PIN
gpio_write_pin_high(LED_POWER_EN_PIN);
# endif
wireless_devs_change(wireless_get_current_devs(), wireless_get_current_devs(), false);
suspend_wakeup_init_user();
}
void wireless_post_task(void) {
// auto switching devs
if (post_init_timer && timer_elapsed32(post_init_timer) >= 100) {
md_send_devctrl(MD_SND_CMD_DEVCTRL_FW_VERSION); // get the module fw version.
md_send_devctrl(MD_SND_CMD_DEVCTRL_SLEEP_BT_EN); // timeout 30min to sleep in bt mode, enable
md_send_devctrl(MD_SND_CMD_DEVCTRL_SLEEP_2G4_EN); // timeout 30min to sleep in 2.4g mode, enable
wireless_devs_change(!confinfo.devs, confinfo.devs, false);
post_init_timer = 0x00;
}
}
uint32_t wls_process_long_press(uint32_t trigger_time, void *cb_arg) {
uint16_t keycode = *((uint16_t *)cb_arg);
switch (keycode) {
case KC_BT1: {
wireless_devs_change(wireless_get_current_devs(), DEVS_BT1, true);
} break;
case KC_BT2: {
wireless_devs_change(wireless_get_current_devs(), DEVS_BT2, true);
} break;
case KC_BT3: {
wireless_devs_change(wireless_get_current_devs(), DEVS_BT3, true);
} break;
case KC_BT4: {
wireless_devs_change(wireless_get_current_devs(), DEVS_BT4, true);
} break;
case KC_BT5: {
wireless_devs_change(wireless_get_current_devs(), DEVS_BT5, true);
} break;
case KC_2G4: {
wireless_devs_change(wireless_get_current_devs(), DEVS_2G4, true);
} break;
case EE_CLR: {
} break;
default:
break;
}
return 0;
}
bool process_record_wls(uint16_t keycode, keyrecord_t *record) {
static uint16_t keycode_shadow = 0x00;
static deferred_token wls_process_long_press_token = INVALID_DEFERRED_TOKEN;
keycode_shadow = keycode;
# ifndef WLS_KEYCODE_PAIR_TIME
# define WLS_KEYCODE_PAIR_TIME 3000
# endif
# define WLS_KEYCODE_EXEC(wls_dev) \
do { \
if (record->event.pressed) { \
wireless_devs_change(wireless_get_current_devs(), wls_dev, false); \
if (wls_process_long_press_token == INVALID_DEFERRED_TOKEN) { \
wls_process_long_press_token = defer_exec(WLS_KEYCODE_PAIR_TIME, wls_process_long_press, &keycode_shadow); \
} \
} else { \
cancel_deferred_exec(wls_process_long_press_token); \
wls_process_long_press_token = INVALID_DEFERRED_TOKEN; \
} \
} while (false)
switch (keycode) {
case KC_BT1: {
WLS_KEYCODE_EXEC(DEVS_BT1);
} break;
case KC_BT2: {
WLS_KEYCODE_EXEC(DEVS_BT2);
} break;
case KC_BT3: {
WLS_KEYCODE_EXEC(DEVS_BT3);
} break;
case KC_BT4: {
WLS_KEYCODE_EXEC(DEVS_BT4);
} break;
case KC_BT5: {
WLS_KEYCODE_EXEC(DEVS_BT5);
} break;
case KC_2G4: {
WLS_KEYCODE_EXEC(DEVS_2G4);
} break;
case KC_USB: {
if (record->event.pressed) {
wireless_devs_change(wireless_get_current_devs(), DEVS_USB, false);
}
} break;
case KC_BATQ: {
inqbat_flag = record->event.pressed;
} break;
default:
return true;
}
return false;
}
#endif
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
if (process_record_user(keycode, record) != true) {
return false;
}
#ifdef WIRELESS_ENABLE
if (process_record_wls(keycode, record) != true) {
return false;
}
#endif
switch (keycode) {
case EE_CLR:{
if (record->event.pressed){
hs_reset_settings();
}
return false;
break;
}
case KC_FTOG:{
if (record->event.pressed)
{
mac_status = keymap_is_mac_system();
if (keymap_is_base_layer()) {
if (mac_status) {
set_single_persistent_default_layer(_FMBL);
layer_move(0);
} else {
set_single_persistent_default_layer(_FBL);
layer_move(0);
}
} else {
if (mac_status) {
set_single_persistent_default_layer(_MBL);
layer_move(0);
} else {
set_single_persistent_default_layer(_BL);
layer_move(0);
}
}
}
return false;
break;
}
case KC_TILD:{
if (record->event.pressed){
register_code(KC_LSFT);
register_code(KC_GRV);
}else{
unregister_code(KC_LSFT);
unregister_code(KC_GRV);
}
return false;
break;
}
case RGB_SPI:{
if (record->event.pressed) {
if (rgb_matrix_get_speed() >= (RGB_MATRIX_SPD_STEP * 5)) {
rgb_blink_dir();
}
}
return true;
} break;
case RGB_SPD: {
if (record->event.pressed) {
if (rgb_matrix_get_speed() <= RGB_MATRIX_SPD_STEP) {
rgb_blink_dir();
rgb_matrix_set_speed(RGB_MATRIX_SPD_STEP);
return false;
}
}
return true;
} break;
case RGB_VAI: {
if (record->event.pressed) {
if (rgb_matrix_get_val() >= (RGB_MATRIX_MAXIMUM_BRIGHTNESS - RGB_MATRIX_VAL_STEP)) {
rgb_blink_dir();
}
}
return true;
} break;
case RGB_VAD: {
if (record->event.pressed) {
if (rgb_matrix_get_val() <= RGB_MATRIX_VAL_STEP) {
rgb_blink_dir();
rgb_matrix_set_color_all(0x00, 0x00, 0x00);
}
}
return true;
} break;
case TO(_BL): {
if (record->event.pressed) {
rgb_matrix_hs_indicator_set(HS_RGB_BLINK_INDEX_WIN, (RGB){RGB_WHITE}, 250, 3);
if (keymap_is_mac_system()) {
set_single_persistent_default_layer(_BL);
layer_move(0);
}
}
return false;
} break;
case TO(_MBL): {
if (record->event.pressed) {
rgb_matrix_hs_indicator_set(HS_RGB_BLINK_INDEX_MAC, (RGB){RGB_WHITE}, 250, 3);
if (!keymap_is_mac_system()) {
set_single_persistent_default_layer(_MBL);
layer_move(0);
}
}
return false;
} break;
case TO(_FBL): {
if (record->event.pressed) {
rgb_matrix_hs_indicator_set(HS_RGB_BLINK_INDEX_WIN, (RGB){RGB_WHITE}, 250, 3);
if (keymap_is_mac_system()) {
set_single_persistent_default_layer(_FBL);
layer_move(0);
}
}
return false;
} break;
case TO(_FMBL): {
if (record->event.pressed) {
rgb_matrix_hs_indicator_set(HS_RGB_BLINK_INDEX_MAC, (RGB){RGB_WHITE}, 250, 3);
if (!keymap_is_mac_system()) {
set_single_persistent_default_layer(_FMBL);
layer_move(0);
}
}
return false;
} break;
default:
return true;
}
return false;
}
#ifdef RGB_MATRIX_ENABLE
# ifdef WIRELESS_ENABLE
bool wls_rgb_indicator_reset = false;
uint32_t wls_rgb_indicator_timer = 0x00;
uint32_t wls_rgb_indicator_interval = 0;
uint32_t wls_rgb_indicator_times = 0;
uint32_t wls_rgb_indicator_index = 0;
RGB wls_rgb_indicator_rgb = {0};
void rgb_matrix_wls_indicator_set(uint8_t index, RGB rgb, uint32_t interval, uint8_t times) {
wls_rgb_indicator_timer = timer_read32();
wls_rgb_indicator_index = index;
wls_rgb_indicator_interval = interval;
wls_rgb_indicator_times = times * 2;
wls_rgb_indicator_rgb = rgb;
}
void wireless_devs_change_kb(uint8_t old_devs, uint8_t new_devs, bool reset) {
wls_rgb_indicator_reset = reset;
if (confinfo.devs != wireless_get_current_devs()) {
confinfo.devs = wireless_get_current_devs();
eeconfig_confinfo_update(confinfo.raw);
}
switch (new_devs) {
case DEVS_BT1: {
if (reset) {
rgb_matrix_wls_indicator_set(HS_RGB_BLINK_INDEX_BT1, (RGB){HS_LBACK_COLOR_BT1}, 200, 1);
} else {
rgb_matrix_wls_indicator_set(HS_RGB_BLINK_INDEX_BT1, (RGB){HS_PAIR_COLOR_BT1}, 500, 1);
}
} break;
case DEVS_BT2: {
if (reset) {
rgb_matrix_wls_indicator_set(HS_RGB_BLINK_INDEX_BT2, (RGB){HS_LBACK_COLOR_BT2}, 200, 1);
} else {
rgb_matrix_wls_indicator_set(HS_RGB_BLINK_INDEX_BT2, (RGB){HS_PAIR_COLOR_BT2}, 500, 1);
}
} break;
case DEVS_BT3: {
if (reset) {
rgb_matrix_wls_indicator_set(HS_RGB_BLINK_INDEX_BT3, (RGB){HS_LBACK_COLOR_BT3}, 200, 1);
} else {
rgb_matrix_wls_indicator_set(HS_RGB_BLINK_INDEX_BT3, (RGB){HS_PAIR_COLOR_BT3}, 500, 1);
}
} break;
case DEVS_BT4: {
if (reset) {
rgb_matrix_wls_indicator_set(41, (RGB){RGB_BLUE}, 200, 1);
} else {
rgb_matrix_wls_indicator_set(41, (RGB){RGB_BLUE}, 500, 1);
}
} break;
case DEVS_BT5: {
if (reset) {
rgb_matrix_wls_indicator_set(42, (RGB){RGB_BLUE}, 200, 1);
} else {
rgb_matrix_wls_indicator_set(42, (RGB){RGB_BLUE}, 500, 1);
}
} break;
case DEVS_2G4: {
if (reset) {
rgb_matrix_wls_indicator_set(HS_RGB_BLINK_INDEX_2G4, (RGB){HS_LBACK_COLOR_2G4}, 200, 1);
} else {
rgb_matrix_wls_indicator_set(HS_RGB_BLINK_INDEX_2G4, (RGB){HS_LBACK_COLOR_2G4}, 500, 1);
}
} break;
default:
break;
}
}
bool rgb_matrix_wls_indicator_cb(void) {
if (*md_getp_state() != MD_STATE_CONNECTED) {
wireless_devs_change_kb(wireless_get_current_devs(), wireless_get_current_devs(), wls_rgb_indicator_reset);
return true;
}
// refresh led
led_wakeup();
return false;
}
void rgb_matrix_wls_indicator(void) {
if (wls_rgb_indicator_timer) {
if (timer_elapsed32(wls_rgb_indicator_timer) >= wls_rgb_indicator_interval) {
wls_rgb_indicator_timer = timer_read32();
if (wls_rgb_indicator_times) {
wls_rgb_indicator_times--;
}
if (wls_rgb_indicator_times <= 0) {
wls_rgb_indicator_timer = 0x00;
if (rgb_matrix_wls_indicator_cb() != true) {
return;
}
}
}
if (wls_rgb_indicator_times % 2) {
rgb_matrix_set_color(wls_rgb_indicator_index, wls_rgb_indicator_rgb.r, wls_rgb_indicator_rgb.g, wls_rgb_indicator_rgb.b);
} else {
rgb_matrix_set_color(wls_rgb_indicator_index, 0x00, 0x00, 0x00);
}
}
if (inqbat_flag) {
rgb_matrix_set_color_all(0x00, 0x00, 0x00);
for (uint8_t i = 0; i < 10; i++) {
uint8_t mi_index[10] = RGB_MATRIX_BAT_INDEX_MAP;
if (i < (*md_getp_bat() / 10)) {
if (*md_getp_bat() >= 50) {
rgb_matrix_set_color(mi_index[i], RGB_GREEN);
} else if (*md_getp_bat() >= 30) {
rgb_matrix_set_color(mi_index[i], RGB_YELLOW);
} else {
rgb_matrix_set_color(mi_index[i], RGB_RED);
}
} else {
rgb_matrix_set_color(mi_index[i], 0x00, 0x00, 0x00);
}
}
}
}
void rgb_matrix_hs_bat_set(uint8_t index, RGB rgb, uint32_t interval, uint8_t times) {
for (int i = 0; i < HS_RGB_BAT_COUNT; i++) {
if (!hs_rgb_bat[i].active) {
hs_rgb_bat[i].active = true;
hs_rgb_bat[i].timer = timer_read32();
hs_rgb_bat[i].interval = interval;
hs_rgb_bat[i].times = times * 2;
hs_rgb_bat[i].index = index;
hs_rgb_bat[i].rgb = rgb;
break;
}
}
}
void rgb_matrix_hs_bat(void) {
for (int i = 0; i < HS_RGB_BAT_COUNT; i++) {
if (hs_rgb_bat[i].active) {
if (timer_elapsed32(hs_rgb_bat[i].timer) >= hs_rgb_bat[i].interval) {
hs_rgb_bat[i].timer = timer_read32();
if (hs_rgb_bat[i].times) {
hs_rgb_bat[i].times--;
}
if (hs_rgb_bat[i].times <= 0) {
hs_rgb_bat[i].active = false;
hs_rgb_bat[i].timer = 0x00;
}
}
if (hs_rgb_bat[i].times % 2) {
rgb_matrix_set_color(hs_rgb_bat[i].index, hs_rgb_bat[i].rgb.r, hs_rgb_bat[i].rgb.g, hs_rgb_bat[i].rgb.b);
} else {
rgb_matrix_set_color(hs_rgb_bat[i].index, 0x00, 0x00, 0x00);
}
}
}
}
void bat_indicators(void) {
static uint32_t battery_process_time = 0;
if (charging_state && (bat_full_flag)) {
battery_process_time = 0;
} else if (charging_state) {
battery_process_time = 0;
rgb_matrix_hs_bat_set(HS_MATRIX_BLINK_INDEX_BAT, (RGB){RGB_RED}, 300, 0xFF);
} else if (*md_getp_bat() <= BATTERY_CAPACITY_LOW) {
rgb_matrix_hs_bat_set(HS_MATRIX_BLINK_INDEX_BAT, (RGB){RGB_RED}, 250, 1);
if (*md_getp_bat() <= BATTERY_CAPACITY_STOP) {
if (!battery_process_time) {
battery_process_time = timer_read32();
}
if (battery_process_time && timer_elapsed32(battery_process_time) > 30000) {
battery_process_time = 0;
lpwr_set_timeout_manual(false);
}
}
} else {
battery_process_time = 0;
}
}
# endif
void rgb_matrix_hs_indicator_set(uint8_t index, RGB rgb, uint32_t interval, uint8_t times) {
for (int i = 0; i < HS_RGB_INDICATOR_COUNT; i++) {
if (!hs_rgb_indicators[i].active) {
hs_rgb_indicators[i].active = true;
hs_rgb_indicators[i].timer = timer_read32();
hs_rgb_indicators[i].interval = interval;
hs_rgb_indicators[i].times = times * 2;
hs_rgb_indicators[i].index = index;
hs_rgb_indicators[i].rgb = rgb;
break;
}
}
}
void rgb_matrix_hs_indicator(void) {
for (int i = 0; i < HS_RGB_INDICATOR_COUNT; i++) {
if (hs_rgb_indicators[i].active) {
if (timer_elapsed32(hs_rgb_indicators[i].timer) >= hs_rgb_indicators[i].interval) {
hs_rgb_indicators[i].timer = timer_read32();
if (hs_rgb_indicators[i].times) {
hs_rgb_indicators[i].times--;
}
if (hs_rgb_indicators[i].times <= 0) {
hs_rgb_indicators[i].active = false;
hs_rgb_indicators[i].timer = 0x00;
}
}
if (hs_rgb_indicators[i].times % 2) {
rgb_matrix_set_color(hs_rgb_indicators[i].index, hs_rgb_indicators[i].rgb.r, hs_rgb_indicators[i].rgb.g, hs_rgb_indicators[i].rgb.b);
} else {
rgb_matrix_set_color(hs_rgb_indicators[i].index, 0x00, 0x00, 0x00);
}
}
}
}
bool rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {
if (rgb_matrix_indicators_advanced_user(led_min, led_max) != true) {
return false;
}
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) {
rgb_matrix_hs_bat();
bat_indicators();
bat_indicator_cnt = timer_read32();
}
if(!enable_bat_indicators){
if(timer_elapsed32(bat_indicator_cnt) > 3000){
enable_bat_indicators = true;
bat_indicator_cnt = timer_read32();
}
}
# endif
rgb_matrix_hs_indicator();
#ifdef HS_BAT_CABLE_PIN
charging_state = readPin(HS_BAT_CABLE_PIN);
#endif
#ifdef BAT_FULL_PIN
bat_full_flag = readPin(BAT_FULL_PIN);
#endif
return true;
}
#endif
void rgb_blink_dir(void){
rgb_matrix_hs_indicator_set(HS_RGB_BLINK_INDEX_VAI, (RGB){RGB_WHITE}, 250, 3);
rgb_matrix_hs_indicator_set(HS_RGB_BLINK_INDEX_VAD, (RGB){RGB_WHITE}, 250, 3);
rgb_matrix_hs_indicator_set(HS_RGB_BLINK_INDEX_SPI, (RGB){RGB_WHITE}, 250, 3);
rgb_matrix_hs_indicator_set(HS_RGB_BLINK_INDEX_SPD, (RGB){RGB_WHITE}, 250, 3);
}
bool hs_reset_settings_user(void) {
for(uint8_t i = 0; i < HS_RGB_INDICATOR_COUNT; i ++){
rgb_matrix_hs_indicator_set(i, (RGB){RGB_WHITE}, 250, 3);
}
return true;
}
void hs_reset_settings(void) {
enable_bat_indicators = false;
eeconfig_init();
eeconfig_update_rgb_matrix_default();
keymap_config.raw = eeconfig_read_keymap();
#if defined(NKRO_ENABLE) && defined(FORCE_NKRO)
keymap_config.nkro = 1;
eeconfig_update_keymap(keymap_config.raw);
#endif
if (hs_reset_settings_user() != true) {
return;
}
keyboard_post_init_kb();
} }