Skip to content

Commit

Permalink
commit halo75 and update qmk
Browse files Browse the repository at this point in the history
  • Loading branch information
nuphy-src committed Jun 12, 2024
1 parent 07b64a6 commit 3570dd9
Show file tree
Hide file tree
Showing 49 changed files with 5,466 additions and 883 deletions.
2 changes: 1 addition & 1 deletion keyboards/nuphy/air60_v2/ansi/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"usb":{
"vid": "0x19F5",
"pid": "0x3255",
"device_version": "0.0.1",
"device_version": "1.0.2",
"no_startup_check": true
},
"features": {
Expand Down
4 changes: 2 additions & 2 deletions keyboards/nuphy/air60_v2/ansi/rf.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ extern host_driver_t *m_host_driver;
extern uint8_t host_mode;
extern uint8_t rf_blink_cnt;
extern uint16_t rf_link_show_time;
extern uint32_t rf_linking_time;
extern uint32_t no_act_time;
extern uint16_t rf_linking_time;
extern uint16_t no_act_time;
extern bool f_send_channel;
extern bool f_dial_sw_init_ok;

Expand Down
18 changes: 14 additions & 4 deletions keyboards/nuphy/air75_v2/ansi/ansi.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "ansi.h"
#include "usb_main.h"
#include "rf_driver.h"

user_config_t user_config;
DEV_INFO_STRUCT dev_info = {
Expand All @@ -25,6 +26,7 @@ DEV_INFO_STRUCT dev_info = {
.rf_state = RF_IDLE,
};

bool f_uart_ack = 0;
bool f_bat_hold = 0;
bool f_sys_show = 0;
bool f_sleep_show = 0;
Expand All @@ -34,6 +36,13 @@ bool f_rf_sw_press = 0;
bool f_dev_reset_press = 0;
bool f_rgb_test_press = 0;
bool f_bat_num_show = 0;
bool f_rf_hand_ok = 0;
bool f_goto_sleep = 0;
bool f_rf_read_data_ok = 0;
bool f_rf_sts_sysc_ok = 0;
bool f_rf_new_adv_ok = 0;
bool f_rf_reset = 0;
bool f_wakeup_prepare = 0;

uint16_t rf_linking_time = 0;
uint16_t rf_link_show_time = 0;
Expand All @@ -48,6 +57,7 @@ host_driver_t *m_host_driver = 0;

extern bool f_rf_new_adv_ok;
extern report_keyboard_t *keyboard_report;
extern report_nkro_t *nkro_report;
extern uint8_t bitkb_report_buf[32];
extern uint8_t bytekb_report_buf[8];
extern uint8_t side_mode;
Expand Down Expand Up @@ -197,8 +207,8 @@ void break_all_key(void) {
clear_keyboard();

keymap_config.nkro = 1;
memset(keyboard_report, 0, sizeof(report_keyboard_t));
host_keyboard_send(keyboard_report);
memset(nkro_report, 0, sizeof(report_nkro_t));
host_nkro_send(nkro_report);
wait_ms(10);

keymap_config.nkro = 0;
Expand Down Expand Up @@ -241,7 +251,7 @@ void switch_dev_link(uint8_t mode) {
} else {
host_mode = HOST_RF_TYPE;

host_set_driver(0);
host_set_driver(&rf_host_driver);
}
}

Expand Down Expand Up @@ -314,7 +324,7 @@ void dial_sw_scan(void) {
f_first = false;

if (dev_info.link_mode != LINK_USB) {
host_set_driver(0);
host_set_driver(&rf_host_driver);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion keyboards/nuphy/air75_v2/ansi/ansi.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ typedef enum {

#define RF_LONG_PRESS_DELAY 30
#define DEV_RESET_PRESS_DELAY 30
#define RGB_TEST_PRESS_DELAY 30
#define RGB_TEST_PRESS_DELAY 30

typedef struct
{
Expand Down
2 changes: 1 addition & 1 deletion keyboards/nuphy/air75_v2/ansi/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define EECONFIG_USER_DATA_SIZE 8

#define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT
#define RGB_DISABLE_WHEN_USB_SUSPENDED
#define RGB_MATRIX_SLEEP
2 changes: 1 addition & 1 deletion keyboards/nuphy/air75_v2/ansi/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"usb":{
"vid": "0x19F5",
"pid": "0x3246",
"device_version": "0.0.2",
"device_version": "1.0.3",
"no_startup_check": true
},
"features": {
Expand Down
167 changes: 100 additions & 67 deletions keyboards/nuphy/air75_v2/ansi/rf.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "ansi.h"
#include "uart.h" // qmk uart.h
#include "uart.h" // qmk uart.h
#include "rf_driver.h"

USART_MGR_STRUCT Usart_Mgr;
#define RX_SBYTE Usart_Mgr.RXDBuf[0]
Expand All @@ -25,20 +26,18 @@ USART_MGR_STRUCT Usart_Mgr;
#define RX_LEN Usart_Mgr.RXDBuf[3]
#define RX_DAT Usart_Mgr.RXDBuf[4]

bool f_uart_ack = 0;
bool f_rf_read_data_ok = 0;
bool f_rf_sts_sysc_ok = 0;
bool f_rf_new_adv_ok = 0;
bool f_rf_reset = 0;
bool f_rf_hand_ok = 0;
bool f_goto_sleep = 0;
bool f_wakeup_prepare = 0;
extern bool f_uart_ack;
extern bool f_rf_read_data_ok;
extern bool f_rf_sts_sysc_ok;
extern bool f_rf_new_adv_ok;
extern bool f_rf_reset;
extern bool f_rf_hand_ok;
extern bool f_goto_sleep;

uint8_t uart_bit_report_buf[32] = {0};
uint8_t func_tab[32] = {0};
uint8_t bitkb_report_buf[32] = {0};
uint8_t bytekb_report_buf[8] = {0};
uint8_t mouse_report_buf[5] = {0};
uint16_t conkb_report = 0;
uint16_t syskb_report = 0;
uint8_t sync_lost = 0;
Expand All @@ -63,42 +62,10 @@ void uart_receive_pro(void);
void break_all_key(void);
uint16_t host_last_consumer_usage(void);

/**
* @brief Uart send consumer keys report.
* @note Call in host.c
*/
void uart_send_consumer_report(void) {
no_act_time = 0;
conkb_report = host_last_consumer_usage();
uart_send_report(CMD_RPT_CONSUME, (uint8_t *)(&conkb_report), 2);
}

/**
* @brief Uart send mouse keys report.
* @note Call in host.c
*/
void uart_send_mouse_report(void) {
report_mouse_t mouse_report = mousekey_get_report();

no_act_time = 0;
memcpy(mouse_report_buf, &mouse_report.buttons, 5);
uart_send_report(CMD_RPT_MS, mouse_report_buf, 5);
}

/**
* @brief Uart send system keys report.
* @note Call in host.c
*/
void uart_send_system_report(void) {
no_act_time = 0;
syskb_report = host_last_system_usage();
uart_send_report(CMD_RPT_SYS, (uint8_t *)(&syskb_report), 2);
}

/**
* @brief Uart auto nkey send
*/
bool f_f_bit_kb_act = 0;
bool f_bit_kb_act = 0;
static void uart_auto_nkey_send(uint8_t *pre_bit_report, uint8_t *now_bit_report, uint8_t size)
{
uint8_t i, j, byte_index;
Expand All @@ -124,8 +91,6 @@ static void uart_auto_nkey_send(uint8_t *pre_bit_report, uint8_t *now_bit_report
break;
}
}


if (byte_index >= 8) {
uart_bit_report_buf[i] |= offset_mask;
f_bit_send = 1;
Expand All @@ -136,7 +101,6 @@ static void uart_auto_nkey_send(uint8_t *pre_bit_report, uint8_t *now_bit_report
bytekb_report_buf[byte_index] = 0;
f_byte_send = 1;
break;
;
}
}
if (byte_index >= 8) {
Expand All @@ -151,7 +115,7 @@ static void uart_auto_nkey_send(uint8_t *pre_bit_report, uint8_t *now_bit_report
}

if (f_bit_send) {
f_f_bit_kb_act = 1;
f_bit_kb_act = 1;
uart_send_report(CMD_RPT_BIT_KB, uart_bit_report_buf, 16);
}

Expand All @@ -163,7 +127,6 @@ static void uart_auto_nkey_send(uint8_t *pre_bit_report, uint8_t *now_bit_report

/**
* @brief Uart send keys report.
* @note Call in host.c
*/
void uart_send_report_func(void)
{
Expand All @@ -172,34 +135,69 @@ void uart_send_report_func(void)
if (dev_info.link_mode == LINK_USB) return;
keyboard_protocol = 1;

if(keymap_config.nkro)
keyboard_report->nkro.mods = get_mods() | get_weak_mods();

if ((dev_info.sys_sw_state == SYS_SW_MAC) && (memcmp(bytekb_report_buf, keyboard_report->raw, 8))) {
no_act_time = 0;
keyboard_report->raw[1] = 0;
memcpy(bytekb_report_buf, keyboard_report->raw, 8);
uart_send_report(CMD_RPT_BYTE_KB, bytekb_report_buf, 8);
}
else if ((dev_info.sys_sw_state == SYS_SW_WIN) && (memcmp(bitkb_report_buf, &keyboard_report->nkro.mods, KEYBOARD_REPORT_BITS+1))) {
no_act_time = 0;
uart_auto_nkey_send(bitkb_report_buf, &keyboard_report->nkro.mods, KEYBOARD_REPORT_BITS+1);
memcpy(&bitkb_report_buf[0], &keyboard_report->nkro.mods, KEYBOARD_REPORT_BITS+1);
}
else if (timer_elapsed32(interval_timer) > 100) {
if (timer_elapsed32(interval_timer) > 50) {
interval_timer = timer_read32();
if (no_act_time <= 200) {
if (no_act_time <= 2000) {
uart_send_report(CMD_RPT_BYTE_KB, bytekb_report_buf, 8);
wait_us(200);

if(f_f_bit_kb_act)
if(f_bit_kb_act)
uart_send_report(CMD_RPT_BIT_KB, uart_bit_report_buf, 16);
}
else {
f_f_bit_kb_act = 0;
f_bit_kb_act = 0;
}
}
}

/**
* @brief Uart send consumer keys report.
* @note Call in rf_driver.c
*/
void uart_send_consumer_report(report_extra_t *report) {
no_act_time = 0;
uart_send_report(CMD_RPT_CONSUME, (uint8_t *)(&report->usage), 2);
}

/**
* @brief Uart send mouse keys report.
* @note Call in rf_driver.c
*/
void uart_send_mouse_report(report_mouse_t *report) {
no_act_time = 0;
uart_send_report(CMD_RPT_MS, &report->buttons, 5);
}

/**
* @brief Uart send system keys report.
* @note Call in rf_driver.c
*/
void uart_send_system_report(report_extra_t *report) {
no_act_time = 0;
uart_send_report(CMD_RPT_SYS, (uint8_t *)(&report->usage), 2);
}

/**
* @brief Uart send byte keys report.
* @note Call in rf_driver.c
*/
void uart_send_report_keyboard(report_keyboard_t *report) {
no_act_time = 0;
report->reserved = 0;
uart_send_report(CMD_RPT_BYTE_KB, &report->mods, 8);
memcpy(bytekb_report_buf, &report->mods, 8);
}

/**
* @brief Uart send bit keys report.
* @note Call in rf_driver.c
*/
void uart_send_report_nkro(report_nkro_t *report) {
no_act_time = 0;
uart_auto_nkey_send(bitkb_report_buf, &nkro_report->mods, NKRO_REPORT_BITS + 1);
memcpy(&bitkb_report_buf[0], &nkro_report->mods, NKRO_REPORT_BITS + 1);
}

/**
* @brief Parsing the data received from the RF module.
*/
Expand Down Expand Up @@ -396,6 +394,35 @@ uint8_t uart_send_cmd(uint8_t cmd, uint8_t wait_ack, uint8_t delayms) {
break;
}

case CMD_SET_24G_NAME: {
Usart_Mgr.TXDBuf[3] = 44; // uart data len
Usart_Mgr.TXDBuf[4] = 44; // name valid len
Usart_Mgr.TXDBuf[5] = 3; // 固定
Usart_Mgr.TXDBuf[6] = 'N';
Usart_Mgr.TXDBuf[8] = 'u';
Usart_Mgr.TXDBuf[10] = 'P';
Usart_Mgr.TXDBuf[12] = 'h';
Usart_Mgr.TXDBuf[14] = 'y';
Usart_Mgr.TXDBuf[16] = ' ';
Usart_Mgr.TXDBuf[18] = 'A';
Usart_Mgr.TXDBuf[20] = 'i';
Usart_Mgr.TXDBuf[22] = 'r';
Usart_Mgr.TXDBuf[24] = '7';
Usart_Mgr.TXDBuf[26] = '5';
Usart_Mgr.TXDBuf[28] = ' ';
Usart_Mgr.TXDBuf[30] = 'V';
Usart_Mgr.TXDBuf[32] = '2';
Usart_Mgr.TXDBuf[34] = ' ';
Usart_Mgr.TXDBuf[36] = 'D';
Usart_Mgr.TXDBuf[38] = 'o';
Usart_Mgr.TXDBuf[40] = 'n';
Usart_Mgr.TXDBuf[42] = 'g';
Usart_Mgr.TXDBuf[44] = 'l';
Usart_Mgr.TXDBuf[46] = 'e';
Usart_Mgr.TXDBuf[48] = get_checksum(Usart_Mgr.TXDBuf + 4, Usart_Mgr.TXDBuf[3]); // sum
break;
}

case CMD_READ_DATA: {
Usart_Mgr.TXDBuf[3] = 2;
Usart_Mgr.TXDBuf[4] = 0x00;
Expand Down Expand Up @@ -467,7 +494,7 @@ void dev_sts_sync(void) {
if (host_mode != HOST_RF_TYPE) {
host_mode = HOST_RF_TYPE;
break_all_key();
host_set_driver(0);
host_set_driver(&rf_host_driver);
}

if (dev_info.rf_state != RF_CONNECT) {
Expand All @@ -487,6 +514,10 @@ void dev_sts_sync(void) {
if (link_state_temp != RF_CONNECT) {
link_state_temp = RF_CONNECT;
rf_link_show_time = 0;
if (dev_info.link_mode == LINK_RF_24) {
uart_send_cmd(CMD_SET_24G_NAME, 10, 30);
}

}
}
}
Expand Down Expand Up @@ -643,4 +674,6 @@ void rf_device_init(void) {
}

uart_send_cmd(CMD_SET_NAME, 10, 20);

uart_send_cmd(CMD_SET_24G_NAME, 10, 20);
}
Loading

0 comments on commit 3570dd9

Please sign in to comment.