From 2de70e6f2d5c7217ec0a0f318e999a0644d9db0d Mon Sep 17 00:00:00 2001
From: Dasky <32983009+daskygit@users.noreply.github.com>
Date: Mon, 30 May 2022 23:04:50 +0100
Subject: [PATCH] Add uf2-split-* make targets. (#17257)

---
 docs/feature_split_keyboard.md | 3 +++
 docs/flashing.md               | 4 ++++
 lib/python/qmk/cli/flash.py    | 2 ++
 platforms/chibios/flash.mk     | 8 ++++++--
 4 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/docs/feature_split_keyboard.md b/docs/feature_split_keyboard.md
index 6ef70bf788..4fac083974 100644
--- a/docs/feature_split_keyboard.md
+++ b/docs/feature_split_keyboard.md
@@ -141,6 +141,9 @@ Next, you will have to flash the EEPROM files once for the correct hand to the c
 * ARM controllers with a DFU compatible bootloader (e.g. Proton-C):
   * `:dfu-util-split-left`
   * `:dfu-util-split-right`
+* ARM controllers with a UF2 compatible bootloader:
+  * `:uf2-split-left`
+  * `:uf2-split-right`
 
 Example:
 
diff --git a/docs/flashing.md b/docs/flashing.md
index ae31f9c621..a4610cae8c 100644
--- a/docs/flashing.md
+++ b/docs/flashing.md
@@ -358,3 +358,7 @@ CLI Flashing sequence:
 2. Wait for the OS to detect the device
 3. Flash via QMK CLI eg. `qmk flash --keyboard handwired/onekey/blackpill_f411_tinyuf2 --keymap default`
 4. Wait for the keyboard to become available
+
+### `make` Targets
+
+* `:uf2-split-left` and `:uf2-split-right`: Flashes the firmware but also sets the handedness setting in EEPROM by generating a side specific firmware.
diff --git a/lib/python/qmk/cli/flash.py b/lib/python/qmk/cli/flash.py
index 28e48a4101..3ff4a318df 100644
--- a/lib/python/qmk/cli/flash.py
+++ b/lib/python/qmk/cli/flash.py
@@ -33,6 +33,8 @@ def print_bootloader_help():
     cli.echo('\tdfu-split-right')
     cli.echo('\tdfu-util-split-left')
     cli.echo('\tdfu-util-split-right')
+    cli.echo('\tuf2-split-left')
+    cli.echo('\tuf2-split-right')
     cli.echo('For more info, visit https://docs.qmk.fm/#/flashing')
 
 
diff --git a/platforms/chibios/flash.mk b/platforms/chibios/flash.mk
index a91ef2cf35..86bbc22943 100644
--- a/platforms/chibios/flash.mk
+++ b/platforms/chibios/flash.mk
@@ -54,11 +54,11 @@ endef
 
 # TODO: Remove once ARM has a way to configure EECONFIG_HANDEDNESS
 #       within the emulated eeprom via dfu-util or another tool
-ifneq (,$(filter $(MAKECMDGOALS),dfu-util-split-left))
+ifneq (,$(filter $(MAKECMDGOALS), dfu-util-split-left uf2-split-left))
     OPT_DEFS += -DINIT_EE_HANDS_LEFT
 endif
 
-ifneq (,$(filter $(MAKECMDGOALS),dfu-util-split-right))
+ifneq (,$(filter $(MAKECMDGOALS), dfu-util-split-right uf2-split-right))
     OPT_DEFS += -DINIT_EE_HANDS_RIGHT
 endif
 
@@ -66,6 +66,10 @@ dfu-util-split-left: dfu-util
 
 dfu-util-split-right: dfu-util
 
+uf2-split-left: flash
+
+uf2-split-right: flash
+
 ST_LINK_CLI ?= st-link_cli
 ST_LINK_ARGS ?=