feat(pm5): hf tune --rgb / lf tune --rgb - antenna RGB as a tuning meter

Adds an opt-in `--rgb` flag to the continuous `hf tune` / `lf tune` commands that
mirrors the antenna tuning level on the PM5 antenna RGB LED: blue = low, green =
mid, red = high, tracking the on-screen bar so you can find coupling (e.g. an
implant) by feel without watching the screen.

The colour is computed client-side from the same per-iteration voltage / running
peak the bar uses (so it matches the bar and auto-scales), and pushed to the
device via a new dumb CMD_PM5_RGB_SET {r,g,b}. That command is handled (#ifdef
PM5) by a dedicated AT32 RGB HAL module, common_arm/rgb/{rgb_apis.h,
rgb_hw_at32.c} (RgbLedSet(), I2C controller @ 0x48), wired into the armsrc
Makefile/CMake as SRC_RGB for PM5 only - so no other platform is affected and no
hardware code lands in shared files.
This commit is contained in:
Nemanja Nedeljkovic authored and Philippe Teuwen committed 2026-08-20 11:55:55 +02:00
1 parent ad4a94b1a5
commit 6507b8f36b
12 files changed
+142 -2

No files matched your search

+30
View File
@@ -21,6 +21,7 @@
#include "cmdparser.h" // command_t
#include "cliparser.h" // parse
#include "comms.h" // clearCommandBuffer
#include "util.h" // set_rgb
#include "lfdemod.h" // computeSignalProperties
#include "cmdhf14a.h" // ISO14443-A
#include "cmdhf14b.h" // ISO14443-B
@@ -298,6 +299,22 @@ int CmdHFSearch(const char *Cmd) {
return res;
}
// Mirror an antenna tuning level on the PM5 antenna RGB LED. `volt` is scaled
// relative to the running peak (`v_max`), so the colour tracks the on-screen bar:
// blue = low, green = mid, red = high.
static void tune_rgb_update(uint32_t volt, uint32_t v_max) {
uint32_t t = (v_max > 0) ? (volt * 510 / v_max) : 0;
if (t > 510) {
t = 510;
}
if (t < 255) { // blue -> green
set_rgb(0, (uint8_t)t, (uint8_t)(255 - t));
} else { // green -> red
t -= 255;
set_rgb((uint8_t)t, (uint8_t)(255 - t), 0);
}
}
int CmdHFTune(const char *Cmd) {
CLIParserContext *ctx;
@@ -315,6 +332,7 @@ int CmdHFTune(const char *Cmd) {
arg_lit0(NULL, "mix", "mixed style"),
arg_lit0(NULL, "value", "values style"),
arg_lit0("v", "verbose", "verbose output"),
arg_lit0(NULL, "rgb", "(PM5) mirror the tuning level on the antenna RGB LED"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
@@ -323,8 +341,14 @@ int CmdHFTune(const char *Cmd) {
bool is_mix = arg_get_lit(ctx, 3);
bool is_value = arg_get_lit(ctx, 4);
bool verbose = arg_get_lit(ctx, 5);
bool use_rgb = arg_get_lit(ctx, 6);
CLIParserFree(ctx);
if (use_rgb && (IfPm5() == false)) {
PrintAndLogEx(WARNING, "`--rgb` is only supported on Proxmark5; ignoring");
use_rgb = false;
}
if ((is_bar + is_mix + is_value) > 1) {
PrintAndLogEx(ERR, "Select only one output style");
return PM3_EINVARG;
@@ -397,6 +421,12 @@ int CmdHFTune(const char *Cmd) {
v_count++;
}
print_progress(volt, v_max, style);
if (use_rgb) {
tune_rgb_update(volt, v_max);
}
}
if (use_rgb) {
set_rgb(0, 0, 0); // turn the LED off on exit
}
mode[0] = 3;
+30
View File
@@ -28,6 +28,7 @@
#include "cmdparser.h" // command_t
#include "comms.h"
#include "util.h" // set_rgb
#include "commonutil.h" // ARRAYLEN
#include "lfdemod.h" // device/client demods of LF signals
#include "ui.h" // for show graph controls
@@ -107,6 +108,22 @@ int lfsim_wait_check(uint32_t cmd) {
return PM3_SUCCESS;
}
// Mirror an antenna tuning level on the PM5 antenna RGB LED. `volt` is scaled
// relative to the running peak (`v_max`), so the colour tracks the on-screen bar:
// blue = low, green = mid, red = high.
static void tune_rgb_update(uint32_t volt, uint32_t v_max) {
uint32_t t = (v_max > 0) ? (volt * 510 / v_max) : 0;
if (t > 510) {
t = 510;
}
if (t < 255) { // blue -> green
set_rgb(0, (uint8_t)t, (uint8_t)(255 - t));
} else { // green -> red
t -= 255;
set_rgb((uint8_t)t, (uint8_t)(255 - t), 0);
}
}
static int CmdLFTune(const char *Cmd) {
CLIParserContext *ctx;
@@ -128,6 +145,7 @@ static int CmdLFTune(const char *Cmd) {
arg_lit0(NULL, "mix", "mixed style"),
arg_lit0(NULL, "value", "values style"),
arg_lit0("v", "verbose", "verbose output"),
arg_lit0(NULL, "rgb", "(PM5) mirror the tuning level on the antenna RGB LED"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
@@ -139,8 +157,14 @@ static int CmdLFTune(const char *Cmd) {
bool is_mix = arg_get_lit(ctx, 5);
bool is_value = arg_get_lit(ctx, 6);
bool verbose = arg_get_lit(ctx, 7);
bool use_rgb = arg_get_lit(ctx, 8);
CLIParserFree(ctx);
if (use_rgb && (IfPm5() == false)) {
PrintAndLogEx(WARNING, "`--rgb` is only supported on Proxmark5; ignoring");
use_rgb = false;
}
if (divisor < 19) {
PrintAndLogEx(ERR, "divisor must be between 19 and 255");
return PM3_EINVARG;
@@ -232,6 +256,12 @@ static int CmdLFTune(const char *Cmd) {
v_count++;
}
print_progress(volt, v_max, style);
if (use_rgb) {
tune_rgb_update(volt, v_max);
}
}
if (use_rgb) {
set_rgb(0, 0, 0); // turn the LED off on exit
}
params[0] = 3;
+14
View File
@@ -33,6 +33,8 @@
#include <time.h> // Mingw
#include "ui.h" // PrintAndLog
#include "comms.h" // SendCommandNG / WaitForResponseTimeout (set_rgb)
#include "pm3_cmd.h" // CMD_PM5_RGB_SET
#define UTIL_BUFFER_SIZE_SPRINT 8196
// global client debug variable
@@ -2048,3 +2050,15 @@ int str_copy_without_whitespace(const char *src, char *dst, size_t dst_size, siz
*dst_len = out;
return PM3_SUCCESS;
}
void set_rgb(uint8_t r, uint8_t g, uint8_t b) {
struct {
uint8_t r;
uint8_t g;
uint8_t b;
} PACKED payload = { r, g, b };
clearCommandBuffer();
SendCommandNG(CMD_PM5_RGB_SET, (uint8_t *)&payload, sizeof(payload));
PacketResponseNG resp;
WaitForResponseTimeout(CMD_PM5_RGB_SET, &resp, 200);
}
+6
View File
@@ -231,4 +231,10 @@ void str_unescape_newlines_inplace(char *s);
*/
int str_copy_without_whitespace(const char *src, char *dst, size_t dst_size, size_t *dst_len);
/**
* @brief Set the antenna RGB LED colour (Proxmark5). No-op reply on devices
* without an RGB LED. Sends CMD_PM5_RGB_SET and waits briefly for the ack.
*/
void set_rgb(uint8_t r, uint8_t g, uint8_t b);
#endif