diff --git a/keyboards/nuphy/halo75_v2/ansi/ansi.c b/keyboards/nuphy/halo75_v2/ansi/ansi.c index 8e01b95cc9a7..96f1a5f074b0 100644 --- a/keyboards/nuphy/halo75_v2/ansi/ansi.c +++ b/keyboards/nuphy/halo75_v2/ansi/ansi.c @@ -18,6 +18,7 @@ along with this program. If not, see . #include "ansi.h" #include "usb_main.h" #include "rf_driver.h" +#include "ble_cmd.h" user_config_t user_config; @@ -414,6 +415,9 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { return false; } no_act_time = 0; + if (process_record_ble_cmd(keycode, record->event.pressed)) { + return false; + } switch (keycode) { case RF_DFU: if (record->event.pressed) { @@ -727,7 +731,9 @@ void m_londing_eeprom_data(void) user_config.ee_side_rgb = side_rgb; user_config.ee_side_colour = side_colour; f_dev_sleep_enable = true; - eeconfig_update_user_datablock(&user_config); + f_ble_cmd_enabled = false; + user_config.ee_ble_cmd_slot = LINK_BT_1; + eeconfig_update_user_datablock(&user_config); } else { side_mode_a = user_config.ee_side_mode_a; side_mode_b = user_config.ee_side_mode_b; @@ -735,6 +741,10 @@ void m_londing_eeprom_data(void) side_speed = user_config.ee_side_speed; side_rgb = user_config.ee_side_rgb; side_colour = user_config.ee_side_colour; + // Sanitize ee_ble_cmd_slot in case EEPROM was written before this field existed + if (user_config.ee_ble_cmd_slot < LINK_BT_1 || user_config.ee_ble_cmd_slot > LINK_BT_3) { + user_config.ee_ble_cmd_slot = LINK_BT_1; + } } } @@ -744,14 +754,20 @@ void m_londing_eeprom_data(void) */ void keyboard_post_init_kb(void) { - m_gpio_init(); + m_gpio_init(); + m_londing_eeprom_data(); rf_uart_init(); wait_ms(500); rf_device_init(); m_break_all_key(); - m_londing_eeprom_data(); m_power_on_dial_sw_scan(); + + // Force it here so dev_sts_sync() sends CMD_SET_LINK(BLE slot) if enabled. + if (f_ble_cmd_enabled && dev_info.link_mode == LINK_USB) { + f_send_channel = 1; + } + keyboard_post_init_user(); rf_link_show_time = 0; diff --git a/keyboards/nuphy/halo75_v2/ansi/ansi.h b/keyboards/nuphy/halo75_v2/ansi/ansi.h index 9a2c393bb521..e0d101e920e7 100644 --- a/keyboards/nuphy/halo75_v2/ansi/ansi.h +++ b/keyboards/nuphy/halo75_v2/ansi/ansi.h @@ -31,6 +31,39 @@ enum custom_keycodes { SIDE_HUI, SIDE_SPI, SIDE_SPD, + + BLE_CMD_0, + BLE_CMD_1, + BLE_CMD_2, + BLE_CMD_3, + BLE_CMD_4, + BLE_CMD_5, + BLE_CMD_6, + BLE_CMD_7, + BLE_CMD_8, + BLE_CMD_9, + BLE_CMD_10, + BLE_CMD_11, + BLE_CMD_12, + BLE_CMD_13, + BLE_CMD_14, + BLE_CMD_15, + BLE_CMD_16, + BLE_CMD_17, + BLE_CMD_18, + BLE_CMD_19, + BLE_CMD_20, + BLE_CMD_21, + BLE_CMD_22, + BLE_CMD_23, + BLE_CMD_24, + BLE_CMD_25, + BLE_CMD_26, + BLE_CMD_27, + BLE_CMD_28, + BLE_CMD_29, + BLE_CMD_30, + BLE_CMD_31, }; extern uint8_t m_sleep_led; @@ -199,8 +232,10 @@ typedef struct uint8_t ee_side_speed; uint8_t ee_side_rgb; uint8_t ee_side_colour; - m_8bit ee_dev_config; + m_8bit ee_dev_config; + uint8_t ee_ble_cmd_slot; // BLE slot used for BLE commands: LINK_BT_1/2/3 } user_config_t; extern user_config_t user_config; -#define f_dev_sleep_enable user_config.ee_dev_config.bit0 \ No newline at end of file +#define f_dev_sleep_enable user_config.ee_dev_config.bit0 +#define f_ble_cmd_enabled user_config.ee_dev_config.bit1 \ No newline at end of file diff --git a/keyboards/nuphy/halo75_v2/ansi/ble_cmd.c b/keyboards/nuphy/halo75_v2/ansi/ble_cmd.c new file mode 100644 index 000000000000..2814494209b7 --- /dev/null +++ b/keyboards/nuphy/halo75_v2/ansi/ble_cmd.c @@ -0,0 +1,118 @@ +#include "ansi.h" +#include "ble_cmd.h" + +// rf.c +extern void UART_Send_Bytes(uint8_t *Buffer, uint32_t Length); +extern uint8_t get_checksum(uint8_t *buf, uint8_t len); + +// ansi.c +extern bool f_dial_sw_init_ok; +extern DEV_INFO_STRUCT dev_info; +extern user_config_t user_config; + +// ------------------------------------------------------------------------- +// Internal: send a consumer HID report directly via UART to the nRF module. +// Bypasses uart_send_report()'s link_mode and rf_state guards intentionally — +// we want the nRF to forward this over BLE regardless of the main link mode. +// ------------------------------------------------------------------------- +static void ble_cmd_send(uint16_t usage) { + if (!f_dial_sw_init_ok) return; + + uint8_t buf[7]; + buf[0] = UART_HEAD; // 0x5A + buf[1] = CMD_RPT_CONSUME; // 0xE3 + buf[2] = 0x01; + buf[3] = 2; // payload length + buf[4] = (uint8_t)(usage & 0xFF); + buf[5] = (uint8_t)(usage >> 8); + buf[6] = get_checksum(&buf[4], 2); + UART_Send_Bytes(buf, 7); +} + +// ------------------------------------------------------------------------- +// Public API +// ------------------------------------------------------------------------- + +bool process_record_ble_cmd(uint16_t keycode, bool pressed) { + if (keycode < BLE_CMD_0 || keycode > BLE_CMD_31) return false; + + // Consume the keycode even when disabled/wrong mode to prevent passthrough + if (!f_ble_cmd_enabled) return true; + if (dev_info.link_mode != LINK_USB) return true; + + uint8_t cmd_id = keycode - BLE_CMD_0; + ble_cmd_send(pressed ? (uint16_t)(BLE_CMD_BASE + cmd_id) : 0x0000); + return true; +} + +uint8_t ble_cmd_sync_mode(void) { + if (f_ble_cmd_enabled && dev_info.link_mode == LINK_USB) { + return user_config.ee_ble_cmd_slot; + } + return dev_info.link_mode; +} + +bool ble_cmd_accepts_sync(uint8_t mode) { + return f_ble_cmd_enabled && + dev_info.link_mode == LINK_USB && + mode == user_config.ee_ble_cmd_slot; +} + +// ------------------------------------------------------------------------- +// VIA custom value callback (only compiled when VIA_ENABLE = yes) +// ------------------------------------------------------------------------- +#ifdef VIA_ENABLE +#include "via.h" + +void via_custom_value_command_kb(uint8_t *data, uint8_t length) { + // data = [ command_id, channel_id, value_id, value... ] + if (data[1] != BLE_CMD_VIA_CHANNEL) { + data[0] = id_unhandled; + return; + } + + uint8_t command_id = data[0]; + uint8_t value_id = data[2]; + + switch (command_id) { + case id_custom_get_value: + switch (value_id) { + case BLE_CMD_VIA_ENABLED: + data[3] = f_ble_cmd_enabled ? 1 : 0; + break; + case BLE_CMD_VIA_SLOT: + // VIA dropdown is 0-based: 0=BLE1, 1=BLE2, 2=BLE3 + data[3] = user_config.ee_ble_cmd_slot - LINK_BT_1; + break; + default: + data[0] = id_unhandled; + break; + } + break; + + case id_custom_set_value: + switch (value_id) { + case BLE_CMD_VIA_ENABLED: + f_ble_cmd_enabled = data[3] ? true : false; + break; + case BLE_CMD_VIA_SLOT: + if (data[3] <= 2) { + user_config.ee_ble_cmd_slot = LINK_BT_1 + data[3]; + } + break; + default: + data[0] = id_unhandled; + break; + } + break; + + case id_custom_save: + eeconfig_update_user_datablock(&user_config); + break; + + default: + data[0] = id_unhandled; + break; + } +} +#endif // VIA_ENABLE diff --git a/keyboards/nuphy/halo75_v2/ansi/ble_cmd.h b/keyboards/nuphy/halo75_v2/ansi/ble_cmd.h new file mode 100644 index 000000000000..2b5a75379d89 --- /dev/null +++ b/keyboards/nuphy/halo75_v2/ansi/ble_cmd.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include + +// Consumer HID usage base for BLE commands. +// Values 0xF000-0xF01F are vendor-defined / unassigned in the Consumer page. +#define BLE_CMD_BASE 0xF000 +#define BLE_CMD_COUNT 32 + +// VIA custom channel and value IDs +#define BLE_CMD_VIA_CHANNEL 6 +#define BLE_CMD_VIA_ENABLED 1 +#define BLE_CMD_VIA_SLOT 2 + +// Called from process_record_kb() before the switch statement. +// Returns true if the keycode was a BLE_CMD and was consumed. +bool process_record_ble_cmd(uint16_t keycode, bool pressed); + +// Returns the link mode to report to the nRF module in CMD_RF_STS_SYSC. +// When BLE cmd is enabled and keyboard is on USB, returns the configured BLE slot +// so the nRF module stays connected over BLE. +uint8_t ble_cmd_sync_mode(void); + +// Returns true if 'mode' is the BLE slot we're using for commands. +// Used in RF_Protocol_Receive to accept the nRF sync response without triggering +// the error counter that would fight the BLE connection. +bool ble_cmd_accepts_sync(uint8_t mode); diff --git a/keyboards/nuphy/halo75_v2/ansi/config.h b/keyboards/nuphy/halo75_v2/ansi/config.h index 2a2694e70785..c9901325cf82 100644 --- a/keyboards/nuphy/halo75_v2/ansi/config.h +++ b/keyboards/nuphy/halo75_v2/ansi/config.h @@ -72,7 +72,7 @@ along with this program. If not, see . #define DRIVER_2_LED_TOTAL 64 #define RGB_MATRIX_LED_COUNT (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL) -#define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_CUSTOM_position_mode +#define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_NONE #define RGB_DEFAULT_COLOUR 168 #define RGB_MATRIX_SLEEP // turn off effects when suspended diff --git a/keyboards/nuphy/halo75_v2/ansi/keymaps/via/NuPhy Halo75 via3.json b/keyboards/nuphy/halo75_v2/ansi/keymaps/via/NuPhy Halo75 via3.json index b312b2e31517..2636ef8f6754 100644 --- a/keyboards/nuphy/halo75_v2/ansi/keymaps/via/NuPhy Halo75 via3.json +++ b/keyboards/nuphy/halo75_v2/ansi/keymaps/via/NuPhy Halo75 via3.json @@ -1,197 +1,511 @@ { - "name": "NuPhy Halo75", - "vendorId": "0x19F5", - "productId": "0x32F5", - "matrix": { - "rows": 6, - "cols": 17 - }, - "layouts": { - "keymap": [ - ["0,0","0,1","0,2","0,3","0,4","0,5","0,6","0,7","0,8","0,9","0,10","0,11","0,12","0,13","0,14","0,15"], - ["1,0","1,1","1,2","1,3","1,4","1,5","1,6","1,7","1,8","1,9","1,10","1,11","1,12",{"w":2},"1,13","1,15"], - [{"w":1.5},"2,0","2,1","2,2","2,3","2,4","2,5","2,6","2,7","2,8","2,9","2,10","2,11","2,12",{"w":1.5},"2,13","2,15"], - [{"w":1.75},"3,0","3,1","3,2","3,3","3,4","3,5","3,6","3,7","3,8","3,9","3,10","3,11",{"w":2.25},"3,13","3,15"], - [{"w":2.25},"4,0","4,2","4,3","4,4","4,5","4,6","4,7","4,8","4,9","4,10","4,11",{"w":1.75},"4,13","4,14","4,15"], - [{"w":1.25},"5,0",{"w":1.25},"5,1",{"w":1.25},"5,2",{"w":6.25},"5,6",{"w":1.25},"5,9",{"w":1.25},"5,10",{"x":0.5},"5,13","5,14","5,15"] - ] - }, - "menus": [ - { - "label": "Lighting", - "content": [ - { - "label": "Backlight", - "content": [ - { - "label": "Brightness", - "type": "range", - "options": [0, 255], - "content": ["id_qmk_rgb_matrix_brightness", 3, 1] - }, - { - "label": "Effect", - "type": "dropdown", - "content": ["id_qmk_rgb_matrix_effect", 3, 2], - "options": [ - "All Off", - "Solid Color", - "Gradient Up/Down", - "Gradient Left/Right", - "Breathing", - "Band Sat.", - "Band Val.", - "Pinwheel Sat.", - "Pinwheel Val.", - "Spiral Sat.", - "Spiral Val.", - "Cycle All", - "Cycle Left/Right", - "Cycle Up/Down", - "Rainbow Moving Chevron", - "Cycle Out/In", - "Cycle Out/In Dual", - "Cycle Pinwheel", - "Cycle Spiral", - "Dual Beacon", - "Rainbow Beacon", - "Rainbow Pinwheels", - "Raindrops", - "Jellybean Raindrops", - "Hue Breathing", - "Hue Pendulum", - "Hue Wave", - "Typing Heatmap", - "Digital Rain", - "Reactive Simple", - "Reactive", - "Reactive Wide", - "Reactive Multiwide", - "Reactive Cross", - "Reactive Multicross", - "Reactive Nexus", - "Reactive MultiNexus", - "Splash", - "MultiSplash", - "Solid Splash", - "Solid MultiSplash", - "game_mode", - "position_mode" - ] - }, - { - "showIf": "{id_qmk_rgb_matrix_effect} != 0", - "label": "Effect Speed", - "type": "range", - "options": [0, 255], - "content": ["id_qmk_rgb_matrix_effect_speed", 3, 3] - }, - { - "showIf": "{id_qmk_rgb_matrix_effect} != 0", - "label": "Color", - "type": "color", - "content": ["id_qmk_rgb_matrix_color", 3, 4] - } - ] - } - ] - } - ], -"keycodes": [ - "qmk_lighting" -], -"customKeycodes": [ - { - "name": "RF\nDFU", - "title": "RF DFU" - }, - { - "name": "Link\nUSB", - "title": "Link USB" - }, - { - "name": "Link\nRF", - "title": "Link RF" - }, - { - "name": "Link\nBLE_1", - "title": "Link BLE_1" - }, - { - "name": "Link\nBLE_2", - "title": "Link BLE_2" - }, - { - "name": "Link\nBLE_3", - "title": "Link BLE_3" - }, - { - "name": "Mac\nTask", - "title": "Mac Task" - }, - { - "name": "Mac\nSearch", - "title": "Mac Search" - }, - { - "name": "Mac\nVoice", - "title": "Mac Siri Voice" - }, - { - "name": "Mac\nConsole", - "title": "Mac Console" - }, - { - "name": "Mac\nDnt", - "title": "Mac Dnt" - }, - { - "name": "Print\nWhole", - "title": "PrintWhole" - }, - { - "name": "Print\nArea", - "title": "PrintArea" - }, - { - "name": "Dev\nReset", - "title": "Device Reset" - }, - { - "name": "Sleep\nMode", - "title": "Auto Sleep" - }, - { - "name": "Bat\nShow", - "title": "Battery Show" - }, - { - "name": "Side\nLight+", - "title": "Side Light +" - }, - { - "name": "Side\nLight-", - "title": "Side Light -" - }, - { - "name": "Side\nMode_A", - "title": "Side Next Mode" - }, - { - "name": "Side\nMode_B", - "title": "Side Next Mode" - }, - { - "name": "Side\nColor", - "title": "Side Next Color" - }, - { - "name": "Side\nFast", - "title": "Side Speed +" - }, - { - "name": "Side\nSlow", - "title": "Side Speed -" - } -] -} + "name": "NuPhy Halo75", + "vendorId": "0x19F5", + "productId": "0x32F5", + "matrix": { + "rows": 6, + "cols": 17 + }, + "layouts": { + "keymap": [ + [ + "0,0", + "0,1", + "0,2", + "0,3", + "0,4", + "0,5", + "0,6", + "0,7", + "0,8", + "0,9", + "0,10", + "0,11", + "0,12", + "0,13", + "0,14", + "0,15" + ], + [ + "1,0", + "1,1", + "1,2", + "1,3", + "1,4", + "1,5", + "1,6", + "1,7", + "1,8", + "1,9", + "1,10", + "1,11", + "1,12", + { + "w": 2 + }, + "1,13", + "1,15" + ], + [ + { + "w": 1.5 + }, + "2,0", + "2,1", + "2,2", + "2,3", + "2,4", + "2,5", + "2,6", + "2,7", + "2,8", + "2,9", + "2,10", + "2,11", + "2,12", + { + "w": 1.5 + }, + "2,13", + "2,15" + ], + [ + { + "w": 1.75 + }, + "3,0", + "3,1", + "3,2", + "3,3", + "3,4", + "3,5", + "3,6", + "3,7", + "3,8", + "3,9", + "3,10", + "3,11", + { + "w": 2.25 + }, + "3,13", + "3,15" + ], + [ + { + "w": 2.25 + }, + "4,0", + "4,2", + "4,3", + "4,4", + "4,5", + "4,6", + "4,7", + "4,8", + "4,9", + "4,10", + "4,11", + { + "w": 1.75 + }, + "4,13", + "4,14", + "4,15" + ], + [ + { + "w": 1.25 + }, + "5,0", + { + "w": 1.25 + }, + "5,1", + { + "w": 1.25 + }, + "5,2", + { + "w": 6.25 + }, + "5,6", + { + "w": 1.25 + }, + "5,9", + { + "w": 1.25 + }, + "5,10", + { + "x": 0.5 + }, + "5,13", + "5,14", + "5,15" + ] + ] + }, + "menus": [ + { + "label": "Lighting", + "content": [ + { + "label": "Backlight", + "content": [ + { + "label": "Brightness", + "type": "range", + "options": [ + 0, + 255 + ], + "content": [ + "id_qmk_rgb_matrix_brightness", + 3, + 1 + ] + }, + { + "label": "Effect", + "type": "dropdown", + "content": [ + "id_qmk_rgb_matrix_effect", + 3, + 2 + ], + "options": [ + "All Off", + "Solid Color", + "Gradient Up/Down", + "Gradient Left/Right", + "Breathing", + "Band Sat.", + "Band Val.", + "Pinwheel Sat.", + "Pinwheel Val.", + "Spiral Sat.", + "Spiral Val.", + "Cycle All", + "Cycle Left/Right", + "Cycle Up/Down", + "Rainbow Moving Chevron", + "Cycle Out/In", + "Cycle Out/In Dual", + "Cycle Pinwheel", + "Cycle Spiral", + "Dual Beacon", + "Rainbow Beacon", + "Rainbow Pinwheels", + "Raindrops", + "Jellybean Raindrops", + "Hue Breathing", + "Hue Pendulum", + "Hue Wave", + "Typing Heatmap", + "Digital Rain", + "Reactive Simple", + "Reactive", + "Reactive Wide", + "Reactive Multiwide", + "Reactive Cross", + "Reactive Multicross", + "Reactive Nexus", + "Reactive MultiNexus", + "Splash", + "MultiSplash", + "Solid Splash", + "Solid MultiSplash", + "game_mode", + "position_mode" + ] + }, + { + "showIf": "{id_qmk_rgb_matrix_effect} != 0", + "label": "Effect Speed", + "type": "range", + "options": [ + 0, + 255 + ], + "content": [ + "id_qmk_rgb_matrix_effect_speed", + 3, + 3 + ] + }, + { + "showIf": "{id_qmk_rgb_matrix_effect} != 0", + "label": "Color", + "type": "color", + "content": [ + "id_qmk_rgb_matrix_color", + 3, + 4 + ] + } + ] + } + ] + }, + { + "label": "BLE Command", + "content": [ + { + "label": "BLE Command", + "content": [ + { + "label": "Enable", + "type": "toggle", + "content": [ + "id_custom_ble_cmd_enabled", + 6, + 1 + ] + }, + { + "label": "BLE Slot", + "type": "dropdown", + "content": [ + "id_custom_ble_cmd_slot", + 6, + 2 + ], + "options": [ + "BLE 1", + "BLE 2", + "BLE 3" + ] + } + ] + } + ] + } + ], + "keycodes": [ + "qmk_lighting" + ], + "customKeycodes": [ + { + "name": "RF\nDFU", + "title": "RF DFU" + }, + { + "name": "Link\nUSB", + "title": "Link USB" + }, + { + "name": "Link\nRF", + "title": "Link RF" + }, + { + "name": "Link\nBLE_1", + "title": "Link BLE_1" + }, + { + "name": "Link\nBLE_2", + "title": "Link BLE_2" + }, + { + "name": "Link\nBLE_3", + "title": "Link BLE_3" + }, + { + "name": "Mac\nTask", + "title": "Mac Task" + }, + { + "name": "Mac\nSearch", + "title": "Mac Search" + }, + { + "name": "Mac\nVoice", + "title": "Mac Siri Voice" + }, + { + "name": "Mac\nConsole", + "title": "Mac Console" + }, + { + "name": "Mac\nDnt", + "title": "Mac Dnt" + }, + { + "name": "Print\nWhole", + "title": "PrintWhole" + }, + { + "name": "Print\nArea", + "title": "PrintArea" + }, + { + "name": "Dev\nReset", + "title": "Device Reset" + }, + { + "name": "Sleep\nMode", + "title": "Auto Sleep" + }, + { + "name": "Bat\nShow", + "title": "Battery Show" + }, + { + "name": "Side\nLight+", + "title": "Side Light +" + }, + { + "name": "Side\nLight-", + "title": "Side Light -" + }, + { + "name": "Side\nMode_A", + "title": "Side Next Mode" + }, + { + "name": "Side\nMode_B", + "title": "Side Next Mode" + }, + { + "name": "Side\nColor", + "title": "Side Next Color" + }, + { + "name": "Side\nFast", + "title": "Side Speed +" + }, + { + "name": "Side\nSlow", + "title": "Side Speed -" + }, + { + "name": "BLE\nCMD 0", + "title": "BLE Command 0" + }, + { + "name": "BLE\nCMD 1", + "title": "BLE Command 1" + }, + { + "name": "BLE\nCMD 2", + "title": "BLE Command 2" + }, + { + "name": "BLE\nCMD 3", + "title": "BLE Command 3" + }, + { + "name": "BLE\nCMD 4", + "title": "BLE Command 4" + }, + { + "name": "BLE\nCMD 5", + "title": "BLE Command 5" + }, + { + "name": "BLE\nCMD 6", + "title": "BLE Command 6" + }, + { + "name": "BLE\nCMD 7", + "title": "BLE Command 7" + }, + { + "name": "BLE\nCMD 8", + "title": "BLE Command 8" + }, + { + "name": "BLE\nCMD 9", + "title": "BLE Command 9" + }, + { + "name": "BLE\nCMD 10", + "title": "BLE Command 10" + }, + { + "name": "BLE\nCMD 11", + "title": "BLE Command 11" + }, + { + "name": "BLE\nCMD 12", + "title": "BLE Command 12" + }, + { + "name": "BLE\nCMD 13", + "title": "BLE Command 13" + }, + { + "name": "BLE\nCMD 14", + "title": "BLE Command 14" + }, + { + "name": "BLE\nCMD 15", + "title": "BLE Command 15" + }, + { + "name": "BLE\nCMD 16", + "title": "BLE Command 16" + }, + { + "name": "BLE\nCMD 17", + "title": "BLE Command 17" + }, + { + "name": "BLE\nCMD 18", + "title": "BLE Command 18" + }, + { + "name": "BLE\nCMD 19", + "title": "BLE Command 19" + }, + { + "name": "BLE\nCMD 20", + "title": "BLE Command 20" + }, + { + "name": "BLE\nCMD 21", + "title": "BLE Command 21" + }, + { + "name": "BLE\nCMD 22", + "title": "BLE Command 22" + }, + { + "name": "BLE\nCMD 23", + "title": "BLE Command 23" + }, + { + "name": "BLE\nCMD 24", + "title": "BLE Command 24" + }, + { + "name": "BLE\nCMD 25", + "title": "BLE Command 25" + }, + { + "name": "BLE\nCMD 26", + "title": "BLE Command 26" + }, + { + "name": "BLE\nCMD 27", + "title": "BLE Command 27" + }, + { + "name": "BLE\nCMD 28", + "title": "BLE Command 28" + }, + { + "name": "BLE\nCMD 29", + "title": "BLE Command 29" + }, + { + "name": "BLE\nCMD 30", + "title": "BLE Command 30" + }, + { + "name": "BLE\nCMD 31", + "title": "BLE Command 31" + } + ] +} \ No newline at end of file diff --git a/keyboards/nuphy/halo75_v2/ansi/rf.c b/keyboards/nuphy/halo75_v2/ansi/rf.c index 688d45a6295c..c9a8b1f8f3a5 100644 --- a/keyboards/nuphy/halo75_v2/ansi/rf.c +++ b/keyboards/nuphy/halo75_v2/ansi/rf.c @@ -17,6 +17,8 @@ along with this program. If not, see . #include "ansi.h" #include "uart.h" // qmk uart.h #include "rf_driver.h" +#include "ble_cmd.h" +#include "print.h" USART_MGR_STRUCT Usart_Mgr; #define RX_SBYTE Usart_Mgr.RXDBuf[0] @@ -250,7 +252,14 @@ void RF_Protocol_Receive(void) { case CMD_RF_STS_SYSC: { static uint8_t error_cnt = 0; - if (dev_info.link_mode == Usart_Mgr.RXDBuf[4]) { + uint8_t expected = ble_cmd_sync_mode(); + static uint8_t last_rx = 0xff; + if (Usart_Mgr.RXDBuf[4] != last_rx || error_cnt >= 5) { + last_rx = Usart_Mgr.RXDBuf[4]; + dprintf("[ble_cmd] SYSC rx=%u exp=%u err=%u rf=%u\n", + Usart_Mgr.RXDBuf[4], expected, error_cnt, dev_info.rf_state); + } + if (Usart_Mgr.RXDBuf[4] == expected) { error_cnt = 0; dev_info.rf_state = Usart_Mgr.RXDBuf[5]; @@ -336,17 +345,21 @@ uint8_t uart_send_cmd(uint8_t cmd, uint8_t wait_ack, uint8_t delayms) { } case CMD_RF_STS_SYSC: { + uint8_t sync_mode = ble_cmd_sync_mode(); Usart_Mgr.TXDBuf[3] = 1; - Usart_Mgr.TXDBuf[4] = dev_info.link_mode; - Usart_Mgr.TXDBuf[5] = dev_info.link_mode; + Usart_Mgr.TXDBuf[4] = sync_mode; + Usart_Mgr.TXDBuf[5] = sync_mode; break; } case CMD_SET_LINK: { + uint8_t link_mode = ble_cmd_sync_mode(); + dprintf("[ble_cmd] CMD_SET_LINK: link_mode=%u dev_link=%u ble_cmd=%u\n", + link_mode, dev_info.link_mode, (uint8_t)f_ble_cmd_enabled); dev_info.rf_state = RF_LINKING; Usart_Mgr.TXDBuf[3] = 1; - Usart_Mgr.TXDBuf[4] = dev_info.link_mode; - Usart_Mgr.TXDBuf[5] = dev_info.link_mode; + Usart_Mgr.TXDBuf[4] = link_mode; + Usart_Mgr.TXDBuf[5] = link_mode; rf_linking_time = 0; disconnect_delay = 0xff; diff --git a/keyboards/nuphy/halo75_v2/ansi/rules.mk b/keyboards/nuphy/halo75_v2/ansi/rules.mk index f34d2ee0a492..33445266e1fd 100644 --- a/keyboards/nuphy/halo75_v2/ansi/rules.mk +++ b/keyboards/nuphy/halo75_v2/ansi/rules.mk @@ -1,3 +1,3 @@ -SRC += side.c rf.c sleep.c rf_driver.c +SRC += side.c rf.c sleep.c rf_driver.c ble_cmd.c UART_DRIVER_REQUIRED = yes RGB_MATRIX_CUSTOM_USER = yes diff --git a/shell.nix b/shell.nix index 88822b0b17e8..e93e9a84d7b5 100644 --- a/shell.nix +++ b/shell.nix @@ -1,72 +1,36 @@ -let - # We specify sources via Niv: use "niv update nixpkgs" to update nixpkgs, for example. - sources = import ./util/nix/sources.nix { }; -in -# However, if you want to override Niv's inputs, this will let you do that. -{ pkgs ? import sources.nixpkgs { } -, poetry2nix ? pkgs.callPackage (import sources.poetry2nix) { } -, avr ? true -, arm ? true -, teensy ? true }: -with pkgs; -let - avrlibc = pkgsCross.avr.libcCross; - - avr_incflags = [ - "-isystem ${avrlibc}/avr/include" - "-B${avrlibc}/avr/lib/avr5" - "-L${avrlibc}/avr/lib/avr5" - "-B${avrlibc}/avr/lib/avr35" - "-L${avrlibc}/avr/lib/avr35" - "-B${avrlibc}/avr/lib/avr51" - "-L${avrlibc}/avr/lib/avr51" - ]; - - # Builds the python env based on nix/pyproject.toml and - # nix/poetry.lock Use the "poetry update --lock", "poetry add - # --lock" etc. in the nix folder to adjust the contents of those - # files if the requirements*.txt files change - pythonEnv = poetry2nix.mkPoetryEnv { - projectDir = ./util/nix; - overrides = poetry2nix.overrides.withDefaults (self: super: { - qmk = super.qmk.overridePythonAttrs(old: { - # Allow QMK CLI to run "qmk" as a subprocess (the wrapper changes - # $PATH and breaks these invocations). - dontWrapPythonPrograms = true; +{ pkgs ? import { } }: - # Fix "qmk setup" to use the Python interpreter from the environment - # when invoking "qmk doctor" (sys.executable gets its value from - # $NIX_PYTHONEXECUTABLE, which is set by the "qmk" wrapper from the - # Python environment, so "qmk doctor" then runs with the proper - # $NIX_PYTHONPATH too, because sys.executable actually points to - # another wrapper from the same Python environment). - postPatch = '' - substituteInPlace qmk_cli/subcommands/setup.py \ - --replace "[Path(sys.argv[0]).as_posix()" \ - "[Path(sys.executable).as_posix(), Path(sys.argv[0]).as_posix()" - ''; - }); - }); - }; +let + pythonEnv = pkgs.python3.withPackages (ps: with ps; [ + appdirs + argcomplete + colorama + dotty-dict + hid + hjson + jsonschema + milc + pygments + pyserial + pyusb + pillow + ]); in -mkShell { +pkgs.mkShell { name = "qmk-firmware"; - buildInputs = [ clang-tools_11 dfu-programmer dfu-util diffutils git pythonEnv niv ] - ++ lib.optional avr [ - pkgsCross.avr.buildPackages.binutils - pkgsCross.avr.buildPackages.gcc8 - avrlibc - avrdude - ] - ++ lib.optional arm [ gcc-arm-embedded ] - ++ lib.optional teensy [ teensy-loader-cli ]; + buildInputs = with pkgs; [ + qmk + pythonEnv + gcc-arm-embedded + dfu-util + dfu-programmer + git + gnumake + ]; - AVR_CFLAGS = lib.optional avr avr_incflags; - AVR_ASFLAGS = lib.optional avr avr_incflags; shellHook = '' # Prevent the avr-gcc wrapper from picking up host GCC flags - # like -iframework, which is problematic on Darwin unset NIX_CFLAGS_COMPILE_FOR_TARGET ''; }