mirror of
https://github.com/alexhopeoconnor/firmware.git
synced 2026-10-17 00:51:30 +10:00
* logging: gate LOG_TRACE behind MESHTASTIC_TRACE_LOGGING, drop redundant reclock logs LOG_TRACE now compiles out by default so trace-level diagnostics cost no flash; enable with -DMESHTASTIC_TRACE_LOGGING. Portduino keeps it on for the traceFilename packet-trace feature. Remove the 66 caller-side I2C reclock/restore log lines in the telemetry sensors: ReClockI2C::setClock/restoreClock already log both frequencies internally (now at trace level, since they fire every sensor read). Also unify near-duplicate literals (colon/case/punctuation variants) so linker string dedup applies, and drop an information-free bare 'done'. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 * logging: demote chatty per-packet/per-poll DEBUG lines to trace level With LOG_TRACE compiled out by default, per-iteration chatter (packet bookkeeping, sensor poll values, e-ink refresh reasons, GPS pin states, UI runState traces) now costs no flash on device builds while remaining one -DMESHTASTIC_TRACE_LOGGING away. 108 lines demoted, 4 information- free lines removed; failure paths, drop reasons, and one-time init logs all stay at debug level. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 * logging: address CodeRabbit review on trace-gate PR - GPS: pass serial-derived buffers as %s args, never as format strings (untrusted bytes could contain % directives) - 0x%08x for packet id / NodeNum per convention (Router, CannedMessage, NeighborInfo); unsigned casts for size_t args; %u for uint32_t delta - EInk: async full-refresh begin/complete back to DEBUG (rare state transitions); per-frame SKIPPED lines stay trace Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 * logging: gate trace on the flag's value, not its presence -DMESHTASTIC_TRACE_LOGGING=0 previously *enabled* trace logging because the gate tested definedness. The flag now defaults per-platform (portduino 1, else 0) and both backends test the value, so =0 disables, =1 or a bare -D enables. Also cast tx_after-millis() to uint32_t for %u (millis() is unsigned long on native). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 * logging: clang-format rewrap after specifier widening Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 * Even fewer bytes! * logging: keep compile-gated debug lines at debug level; fix native-suite-count Lines already inside default-off #ifdef blocks (GPS_DEBUG, DEBUG_LOOP_TIMING) cost no flash and should stay visible at debug level when their gate is enabled, rather than also requiring MESHTASTIC_TRACE_LOGGING. test/native-suite-count lags the two test_event_channel_* suites added by #11045 (develop's Native Suite Count check has the same mismatch); bump 46 -> 47. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 * gps: route GPS_DEBUG diagnostics through a LOG_DEBUG_GPS() macro (#11414) Replaces 27 log-only #ifdef GPS_DEBUG blocks across GPS.cpp, PositionModule, MeshService, and GPSStatus.h with a single-line LOG_DEBUG_GPS() call (src/gps/GPSLog.h, modeled on LOG_MIGRATION: value-gated, ((void)0) when off). Blocks containing declarations, control flow, hexDump, or nested conditionals keep an explicit '#if GPS_DEBUG' guard. RTC.cpp's per-reading raw time dumps and per-candidate rejection chatter fold under the same gate; quality transitions and boot-time seeding stay at debug. Also fixes the '// define GPS_DEBUG' missing-# typo in two variant headers and updates all seven commented examples to the value form ('#define GPS_DEBUG 1') required by the value-based gate. Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 Co-authored-by: Claude <noreply@anthropic.com> * gps: declare RTC gmtime result as pointer to const (cppcheck) With the setTime debug dump gated behind GPS_DEBUG, all remaining uses of t are reads; cppcheck (constVariablePointer) now flags it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1 --------- Co-authored-by: Claude <noreply@anthropic.com>
99 lines
3.1 KiB
C++
99 lines
3.1 KiB
C++
#ifndef RECLOCK_I2C_
|
|
#define RECLOCK_I2C_
|
|
|
|
#include "../graphics/Screen.h"
|
|
#include "ScanI2CTwoWire.h"
|
|
#include <Wire.h>
|
|
#include <stdint.h>
|
|
|
|
/* Class to set and restore the I2C clock temporarily on a i2cBus
|
|
See https://github.com/arduino/Arduino/issues/11457
|
|
Currently, only ESP32 can getClock()
|
|
While all cores can setClock()
|
|
https://github.com/sandeepmistry/arduino-nRF5/blob/master/libraries/Wire/Wire.h#L50
|
|
https://github.com/earlephilhower/arduino-pico/blob/master/libraries/Wire/src/Wire.h#L60
|
|
https://github.com/stm32duino/Arduino_Core_STM32/blob/main/libraries/Wire/src/Wire.h#L103
|
|
For cases when I2C speed is different to the ones defined by sensors (see defines in sensor classes)
|
|
we need to reclock I2C and set it back to the previous established speed.
|
|
Only for cases where we can know it (ESP32 or known screen) we can do this.
|
|
*/
|
|
|
|
extern std::unique_ptr<graphics::Screen> screen;
|
|
|
|
class ReClockI2C
|
|
{
|
|
public:
|
|
void setup(TwoWire *i2cBus, ScanI2C::I2CPort port)
|
|
{
|
|
this->i2cBus = i2cBus;
|
|
this->port = port;
|
|
this->previousClock = 0;
|
|
}
|
|
|
|
bool setClock(uint32_t desiredClock)
|
|
{
|
|
uint32_t currentClock = this->getClock();
|
|
|
|
if (currentClock) {
|
|
LOG_TRACE("Current I2C frequency: %uHz", currentClock);
|
|
}
|
|
|
|
if (currentClock != desiredClock) {
|
|
LOG_TRACE("Changing I2C clock to %uHz", desiredClock);
|
|
this->i2cBus->setClock(desiredClock);
|
|
// If the clock is 0Hz, we still store it
|
|
// We'll check in restoreClock function
|
|
setPreviousClock(currentClock);
|
|
LOG_TRACE("Stored previous clock I2C clock: %uHz", this->previousClock);
|
|
return true;
|
|
}
|
|
|
|
LOG_TRACE("I2C clock was already %uHz. Skipping", desiredClock);
|
|
setPreviousClock(0);
|
|
return false;
|
|
}
|
|
|
|
bool restoreClock()
|
|
{
|
|
if (this->previousClock) {
|
|
LOG_TRACE("Restoring I2C clock to %uHz", this->previousClock);
|
|
i2cBus->setClock(this->previousClock);
|
|
setPreviousClock(0);
|
|
return true;
|
|
}
|
|
LOG_TRACE("I2C clock was unknown. Not restored");
|
|
return false;
|
|
}
|
|
|
|
private:
|
|
TwoWire *i2cBus{};
|
|
ScanI2C::I2CPort port{};
|
|
uint32_t previousClock = 0;
|
|
|
|
void setPreviousClock(uint32_t clock) { this->previousClock = clock; }
|
|
|
|
uint32_t getClock()
|
|
{
|
|
|
|
#ifdef CAN_GET_I2C_CLOCK
|
|
return this->i2cBus->getClock();
|
|
#elif HAS_SCREEN
|
|
if (screen) {
|
|
// If we get a non-zero response here, the screen has set a speed
|
|
uint32_t screenClock = 0;
|
|
ScanI2C::I2CPort screenPort = ScanI2C::I2CPort::NO_I2C;
|
|
screenClock = screen->getI2cFrequency();
|
|
screenPort = screen->getI2CPort();
|
|
// Check if i2c port is the same, and that we got a screenClock back (0 means the screen didn't set it)
|
|
if (screenClock && (screenPort == this->port)) {
|
|
LOG_DEBUG("Screen defined I2C frequency: %uHz", screenClock);
|
|
return screenClock;
|
|
}
|
|
}
|
|
#endif
|
|
return 0;
|
|
}
|
|
};
|
|
|
|
#endif
|