mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2026-09-16 01:55:52 +00:00
CHANGE: Battery temp to Temp (gauge), ADD: Dim green LED when on battery only
This commit is contained in:
committed by
Philippe Teuwen
parent
9e0de43ddc
commit
4d529bc4d7
@@ -3,7 +3,7 @@
|
||||
|
||||
# By default PM3 RDV4 image is generated.
|
||||
# Comment the line below and uncomment further down according to which device you have
|
||||
PLATFORM=PM3RDV4
|
||||
PLATFORM=PM5
|
||||
|
||||
# For PM3 RDV1, RDV2, Easy or rysccorps etc
|
||||
# uncomment the line below
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "fpga_apis.h"
|
||||
#include "rssi_apis.h"
|
||||
#include "rgb_apis.h"
|
||||
#include "gpio_apis.h" // gpio_vusb_setup / Gpio_VUSB_Read (USB-present detection)
|
||||
#include "string.h"
|
||||
#include "printf.h"
|
||||
#include "legicrf.h"
|
||||
@@ -397,6 +398,56 @@ static void bwm_detect_and_init(void) {
|
||||
|
||||
#endif // WITH_BWM_STATUS
|
||||
|
||||
#ifdef WITH_PM5_PWR_LED
|
||||
// "Alive on battery" indicator. When the PM5 runs on battery (USB unplugged) it
|
||||
// otherwise gives no sign it is on, so users leave it draining. This lights the
|
||||
// antenna RGB a dim green while on battery, and turns it off when on USB (where the
|
||||
// cable already signals power). Throttled + edge-triggered to avoid I2C spam and to
|
||||
// yield the RGB to hf/lf tune (which sets g_rgb_external while it owns the LED).
|
||||
#ifndef PM5_PWR_LED_PERIOD_MS
|
||||
#define PM5_PWR_LED_PERIOD_MS 1000 // re-evaluate at most once a second
|
||||
#endif
|
||||
|
||||
// Set by CMD_PM5_RGB_SET so the indicator backs off while tune controls the RGB.
|
||||
volatile bool g_rgb_external = false;
|
||||
|
||||
static bool s_pwr_led_setup = false;
|
||||
|
||||
static void bwm_power_led_check(void) {
|
||||
static uint32_t last_tick = 0;
|
||||
static int last_state = -1; // -1 unknown, 0 = off/USB, 1 = green/battery
|
||||
|
||||
if ((last_tick != 0) && (GetTickCountDelta(last_tick) < PM5_PWR_LED_PERIOD_MS)) {
|
||||
return;
|
||||
}
|
||||
last_tick = GetTickCount();
|
||||
|
||||
// While tune (or any external RGB user) owns the LED, do nothing and force a
|
||||
// refresh next time it is released.
|
||||
if (g_rgb_external) {
|
||||
last_state = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (s_pwr_led_setup == false) {
|
||||
gpio_vusb_setup();
|
||||
s_pwr_led_setup = true;
|
||||
}
|
||||
|
||||
int on_battery = (Gpio_VUSB_Read() == false) ? 1 : 0;
|
||||
if (on_battery == last_state) {
|
||||
return; // edge-triggered: only write RGB when the state changes
|
||||
}
|
||||
last_state = on_battery;
|
||||
|
||||
if (on_battery) {
|
||||
RgbLedSet(0, 8, 0); // dim green: alive, on battery
|
||||
} else {
|
||||
RgbLedSet(0, 0, 0); // on USB: off (cable already signals power)
|
||||
}
|
||||
}
|
||||
#endif // WITH_PM5_PWR_LED
|
||||
|
||||
#ifdef WITH_LCD
|
||||
#include "LCD_disabled.h"
|
||||
#endif
|
||||
@@ -3960,6 +4011,11 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
} PACKED;
|
||||
struct p *payload = (struct p *)packet->data.asBytes;
|
||||
RgbLedSet(payload->r, payload->g, payload->b);
|
||||
#ifdef WITH_PM5_PWR_LED
|
||||
// tune (or any external RGB user) now owns the LED; back the power
|
||||
// indicator off. A non-zero colour claims it; all-zero releases it.
|
||||
g_rgb_external = (payload->r || payload->g || payload->b);
|
||||
#endif
|
||||
reply_ng(CMD_PM5_RGB_SET, PM3_SUCCESS, NULL, 0);
|
||||
break;
|
||||
}
|
||||
@@ -4073,6 +4129,10 @@ void __attribute__((noreturn)) AppMain(void) {
|
||||
for (;;) {
|
||||
WDT_HIT();
|
||||
|
||||
#ifdef WITH_PM5_PWR_LED
|
||||
bwm_power_led_check();
|
||||
#endif
|
||||
|
||||
if (*_stack_start != 0xdeadbeef) {
|
||||
Dbprintf("DEBUG: increase stack size, currently " _YELLOW_("%d") " bytes", (uint32_t)_stack_end - (uint32_t)_stack_start);
|
||||
Dbprintf("Stack overflow detected");
|
||||
|
||||
@@ -178,7 +178,7 @@ else ifeq ($(PLATFORM),PM5)
|
||||
FPGA_BITSTREAMS = fpga_pm3_hf.bit # TODO DXL 虽然可以不把打包比特流,但是还是得把FPGA的版本信息给生成,让EXE依赖。
|
||||
SKIP_FPGA_EMBED = true # important!!! disable the fpga bit files pack to arm!
|
||||
SKIP_COMPRESSION = true # Skip data section compress. The new mcu has enough flash space.
|
||||
PLATFORM_DEFS = -DWITH_FLASH -DPM5 -DCHIP_AT32F435_37 -DWITH_BWM_STATUS # TODO 暂时不要编译i2c -DWITH_SMARTCARD
|
||||
PLATFORM_DEFS = -DWITH_FLASH -DPM5 -DCHIP_AT32F435_37 -DWITH_BWM_STATUS -DWITH_PM5_PWR_LED # TODO 暂时不要编译i2c -DWITH_SMARTCARD
|
||||
# -DWITH_BWM_LOWBATT_BEEP ===== if you want audible alert ====
|
||||
PLTNAME = Proxmark5
|
||||
PLATFORM_FPGA = GW1NR-LV2MG49GC6/i5
|
||||
|
||||
Reference in New Issue
Block a user