Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement connection manager. #1031

Merged
merged 35 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2b85e95
Light entire matrix at the beginning of switch test mode.
kareltucek Dec 26, 2024
1d53ce4
Fix touchpad presses.
kareltucek Dec 26, 2024
ca6d687
Merge pull request #1064 from UltimateHackingKeyboard/fix_touchpad_wa…
mondalaci Dec 27, 2024
930c4e5
Fade uhk80 leds gradually.
kareltucek Dec 27, 2024
eb12223
Merge pull request #1067 from UltimateHackingKeyboard/fade_rgb
mondalaci Dec 27, 2024
35b1310
Fix exit from test led mode for uhk60.
kareltucek Dec 27, 2024
c27a406
Reload uhk60 keymap even in key switch mode if needed.
kareltucek Dec 28, 2024
332557f
Require valid messages to be non-empty.
kareltucek Dec 29, 2024
aca35f4
Auxiliary changes.
kareltucek Dec 29, 2024
ce69d89
Reload ansi/iso flag when hyardware config is written.
kareltucek Dec 30, 2024
ead30c6
Merge pull request #1062 from UltimateHackingKeyboard/chance_test_led…
mondalaci Dec 31, 2024
73a9430
Make pairing screen always on.
kareltucek Dec 31, 2024
7d48a9d
Reduce audible noise, and expose related settings for experimentation…
mondalaci Jan 1, 2025
560418b
Merge pull request #1070 from UltimateHackingKeyboard/keep_pairing_sc…
mondalaci Jan 1, 2025
d5bd220
Fix build for dongle.
kareltucek Jan 1, 2025
61a8ab3
Merge pull request #1071 from UltimateHackingKeyboard/reduce-audible-…
mondalaci Jan 1, 2025
05f971b
Implement connection manager.
kareltucek Dec 21, 2024
aca8da2
Add some debug commands, fix some GetNewPairings problems.
kareltucek Dec 22, 2024
adaf2ba
Fix address matching.
kareltucek Dec 22, 2024
367ecf5
Add some logging.
kareltucek Dec 22, 2024
15f0d33
Fix advertisement restart.
kareltucek Dec 22, 2024
3cf2b9d
Make connections work even when there is no config.
kareltucek Dec 30, 2024
00be7ca
Clean up advertisement and scanning mess.
kareltucek Dec 31, 2024
9cd1179
Fix layer switcher warning.
kareltucek Dec 31, 2024
3913d06
Distinguish oob pairing from hid ble pairing.
kareltucek Dec 30, 2024
f230601
Changes towards improving ble reliability.
kareltucek Dec 31, 2024
11395e2
Fix some pairing issues.
kareltucek Dec 31, 2024
7df9800
Cancel pairing flag.
kareltucek Dec 31, 2024
cfb40f9
Reallocate connections when host connections id change.
kareltucek Dec 31, 2024
4f08101
Fix 0 peerId, add `uhk connections` cmd, fix some bugs.
kareltucek Jan 3, 2025
5c07a46
Rewrite bt connection initiation sequence.
kareltucek Jan 3, 2025
fe16966
create parallel HID applications for USB and BLE
benedekkupper Jan 8, 2025
8a13f98
Connect parallel routing c2usb implementation.
kareltucek Jan 9, 2025
f511201
Support caps/num/scroll lock in host routing.
kareltucek Jan 9, 2025
f6648bd
Refresh target widget when user config is applied.
kareltucek Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,16 @@ function processArguments() {
DEVICES="$DEVICES uhk-80-left uhk-80-right uhk-dongle"
shift
;;
clean|setup|update|build|make|flash|flashUsb|shell|release)
clean|setup|update|build|make|flash|shell|release)
ACTIONS="$ACTIONS $1"
TARGET_TMUX_SESSION=$BUILD_SESSION_NAME
shift
;;
flashUsb)
ACTIONS="$ACTIONS make $1"
TARGET_TMUX_SESSION=$BUILD_SESSION_NAME
shift
;;
addrline)
shift
ADDR=$1
Expand Down Expand Up @@ -374,7 +379,7 @@ function run() {
if [ `echo $DEVICES | wc -w` -gt 1 ]
then
runPerDevice
elif [ `echo $DEVICES | wc -w` -eq 0 ]
elif [ `echo $DEVICES | wc -w` -le 1 ]
then
performActions $DEVICES
else
Expand Down
7 changes: 7 additions & 0 deletions device/prj.conf.overlays/nrf_shared.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ CONFIG_BT_SMP=y

CONFIG_BT_L2CAP_TX_BUF_COUNT=5

# Todo: place these where they belong
# config for right half host switching
CONFIG_BT_MAX_CONN=4
CONFIG_BT_CTLR_SDC_PERIPHERAL_COUNT=3
CONFIG_BT_FILTER_ACCEPT_LIST=y


# negotiate larger MTU for NUS
CONFIG_BT_USER_DATA_LEN_UPDATE=y
CONFIG_BT_BUF_ACL_RX_SIZE=251
Expand Down
2 changes: 1 addition & 1 deletion device/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ set(usb_cpp_sources
usb/command_app.cpp
usb/controls_app.cpp
usb/gamepad_app.cpp
usb/hid_battery_app.cpp
usb/keyboard_app.cpp
usb/mouse_app.cpp
usb/usb_compatibility.cpp
Expand All @@ -29,6 +28,7 @@ if(NOT CONFIG_BOARD_UHK_60_RIGHT)
bt_conn.c
bt_manager.c
bt_pair.c
connections.c
debug_eventloop_timing.c
device_state.c
flash.c
Expand Down
53 changes: 47 additions & 6 deletions device/src/bt_advertise.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include "bt_advertise.h"
#include <bluetooth/services/nus.h>
#include <zephyr/bluetooth/gatt.h>
#include "bt_conn.h"
#include "connections.h"
#include "device.h"
#include "event_scheduler.h"
#include "bt_scan.h"

#undef DEVICE_NAME
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
Expand Down Expand Up @@ -38,8 +42,24 @@ static const struct bt_data sdHid[] = {SD_HID_DATA};

static const struct bt_data sdNusHid[] = {SD_NUS_DATA SD_HID_DATA};

void BtAdvertise_Start(uint8_t adv_type)
static struct bt_le_adv_param advertisementParams[] = BT_LE_ADV_CONN;

static void setFilters() {
bt_le_filter_accept_list_clear();
if (DEVICE_IS_UHK80_RIGHT) {
if (BtConn_UnusedPeripheralConnectionCount() <= 1 && SelectedHostConnectionId != ConnectionId_Invalid) {
bt_le_filter_accept_list_add(&HostConnection(SelectedHostConnectionId)->bleAddress);
advertisementParams->options = BT_LE_ADV_OPT_FILTER_CONN;
} else {
advertisementParams->options = BT_LE_ADV_OPT_NONE;
}
}
}

uint8_t BtAdvertise_Start(uint8_t adv_type)
{
setFilters();

int err;
const char *adv_type_string;
if (adv_type == (ADVERTISE_NUS | ADVERTISE_HID)) {
Expand All @@ -54,33 +74,54 @@ void BtAdvertise_Start(uint8_t adv_type)
err = bt_le_adv_start(BT_LE_ADV_CONN, adHid, ARRAY_SIZE(adHid), sdHid, ARRAY_SIZE(sdHid));
} else {
printk("Attempted to start advertising without any type! Ignoring.\n");
return;
return 0;
}

if (err == 0) {
printk("%s advertising successfully started\n", adv_type_string);
return 0;
} else if (err == -EALREADY) {
printk("%s advertising continued\n", adv_type_string);
return 0;
} else {
printk("%s advertising failed to start (err %d)\n", adv_type_string, err);
printk("%s advertising failed to start (err %d), free connections: %d\n", adv_type_string, err, BtConn_UnusedPeripheralConnectionCount());
return err;
}
}

void BtAdvertise_Stop() {
int err = bt_le_adv_stop();
if (err) {
printk("Advertising failed to stop (err %d)\n", err);
} else {
printk("Advertising successfully stopped\n");
}
}

static uint8_t connectedHidCount() {
uint8_t connectedHids = 0;
for (uint8_t peerId = PeerIdFirstHost; peerId <= PeerIdLastHost; peerId++) {
if (Peers[peerId].conn && Connections_Type(Peers[peerId].connectionId) == ConnectionType_BtHid) {
connectedHids++;
}
}
return connectedHids;
}

uint8_t BtAdvertise_Type() {
switch (DEVICE_ID) {
case DeviceId_Uhk80_Left:
return ADVERTISE_NUS;
case DeviceId_Uhk80_Right:
return ADVERTISE_NUS | ADVERTISE_HID;
if (BtConn_UnusedPeripheralConnectionCount() > 0) {
if (connectedHidCount() > 0) {
return ADVERTISE_NUS;
} else {
return ADVERTISE_NUS | ADVERTISE_HID;
}
} else {
printk("Current slot count %d, not advertising\n", BtConn_UnusedPeripheralConnectionCount());
BtConn_ListCurrentConnections();
return 0;
}
case DeviceId_Uhk_Dongle:
return 0;
default:
Expand Down
2 changes: 1 addition & 1 deletion device/src/bt_advertise.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// Functions:

void BtAdvertise_Start(uint8_t adv_type);
uint8_t BtAdvertise_Start(uint8_t adv_type);
void BtAdvertise_Stop();
uint8_t BtAdvertise_Type();

Expand Down
Loading