From 2714628baf4c2e4e9b67ef6993d2d75633c784ec Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 30 Aug 2026 11:29:39 +0200 Subject: [PATCH] swap to bigbuf_calloc in pcf7939 Write on device side to lessen RAM footprint, Thanks Claude! --- CHANGELOG.md | 1 + armsrc/pcf7931.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0fecf6c9..6772cddc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] +- Changed `lf pcf7931` - now use bigbuf_calloc and much smaller array (@iceman1001) - Changed `hf 15 sniff` - now uses bigbuf_calloc and lessen ram footprint on device (@iceman1001) - Added individual json dump formats for ht2, ht1, htS, htU. No more .bin files either for hitag (@iceman1001) - Change NG: iso14a_raw_cmd_t, convert hf 14a raw, dual-mode reader handler (@iceman1001) diff --git a/armsrc/pcf7931.c b/armsrc/pcf7931.c index 186552703..1a69eb0b6 100644 --- a/armsrc/pcf7931.c +++ b/armsrc/pcf7931.c @@ -27,6 +27,12 @@ #include "string.h" #define T0_PCF 8 //period for the pcf7931 in us + +// Entries in the data frame array. Every AddBit/AddByte/AddPattern call appends 3 entries, +// and a write frame is 2 patterns + 77 bits + 1 pattern = 80 calls = 240 entries. 256 leaves +// the trailing zero the "tab[u] != 0" scans terminate on, and matches the uint8_t cursor in +// AddBitPCF7931, which cannot address past 255 anyway. +#define PCF7931_FRAME_ENTRIES 256 #define ALLOC 16 // IIR filter consts @@ -437,7 +443,7 @@ static void RealWritePCF7931( uint8_t address, uint8_t byte, uint8_t data, bool ledcontrol) { - uint32_t tab[1024] = {0}; // data times frame + uint32_t tab[PCF7931_FRAME_ENTRIES] = {0}; // data times frame uint32_t u = 0; uint8_t parity = 0; @@ -553,7 +559,9 @@ void SendCmdPCF7931(uint32_t *tab, bool ledcontrol) { if (ledcontrol) LED_A_ON(); // rescale the values to match the time of the timer below. - for (u = 0; u < 500; ++u) { + // stop at the terminating zero like the loops below do, the caller's array + // is only as long as the frame needs + for (u = 0; tab[u] != 0; ++u) { tab[u] = (tab[u] * 3) / 2; }