Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
42dc6cd
Fix type consistency and add const qualifiers
FredM67 Jan 8, 2026
2fc5ae0
Optimize integer types and use CMSIS bit-field access
FredM67 Jan 8, 2026
58354f2
Merge branch 'main' into feature/type-consistency-fixes
FredM67 Jan 8, 2026
fb5f102
Fix I2C bus state initialization using bitwise operation for clarity
FredM67 Jan 9, 2026
ec55c1b
Merge branch 'main' into feature/type-consistency-fixes
FredM67 Jan 11, 2026
12d8fa9
Add utilUtoa and strnCatUint for unsigned conversions
FredM67 Jan 11, 2026
0cdd8be
Fix type consistency in EEPROM and related modules
FredM67 Jan 11, 2026
57a42b7
Fix type consistency across multiple modules
FredM67 Jan 11, 2026
14640b7
Fix signed/unsigned loop counter warnings
FredM67 Jan 11, 2026
47ac0a3
Change CT remap arrays from int8_t to uint8_t
FredM67 Jan 11, 2026
1253206
Merge branch 'main' into feature/type-consistency-fixes
FredM67 Jan 13, 2026
49ea0db
Fix type inconsistencies after merge with main
FredM67 Jan 13, 2026
82e8405
Continue type consistency improvements
FredM67 Jan 13, 2026
9a146fc
Use size_t for opaIdx array index parameters
FredM67 Jan 13, 2026
e347a55
Fix types and unsigned literals in emon32.c
FredM67 Jan 13, 2026
33a04a0
Type consistency fixes in configuration and emon_CM
FredM67 Jan 13, 2026
55b1d38
Change pulse count storage from uint64_t to uint32_t
FredM67 Jan 13, 2026
f47bd49
Type consistency and minor optimizations
FredM67 Jan 13, 2026
7c28b68
Use size_t for array index loop counter in pulseConfigure
FredM67 Jan 13, 2026
16b0424
Merge branch 'main' into feature/type-consistency-fixes
FredM67 Jan 14, 2026
cefff83
Fix printf format specifiers and use size_t for indices
FredM67 Jan 14, 2026
d0ba529
Type consistency fixes for loop counters and literals
FredM67 Jan 14, 2026
34ceb4e
Merge branch 'main' into feature/type-consistency-fixes
FredM67 Jan 14, 2026
11f5ed9
Fix merge from main
FredM67 Jan 14, 2026
6743b97
Refactor utilItoa to use utilUtoa as core function
FredM67 Jan 14, 2026
3d9f54a
Add utilAtoui for unsigned string-to-integer conversion
FredM67 Jan 14, 2026
f33bb3b
Use unions for type-safe integer width access
FredM67 Jan 14, 2026
54c79dc
Fix remaining conversion warnings with union type-punning
FredM67 Jan 14, 2026
542f8a4
Add missing const qualifiers to match header declarations
FredM67 Jan 15, 2026
d81584d
Add const to input-only pointer parameter in calibrationPhase
FredM67 Jan 15, 2026
59c7b8b
Use size_t for array index loop counters
FredM67 Jan 15, 2026
714f408
Merge remote-tracking branch 'upstream/main' into feature/type-consis…
FredM67 Jan 15, 2026
c5b34cd
Use optimized assembly square functions for RMS calculations
FredM67 Jan 15, 2026
95d5914
Add smul64 signed 32x32->64 bit multiply assembly function
FredM67 Jan 15, 2026
e4b9ec3
Use smul64 for power calculations in ecmInjectSample
FredM67 Jan 15, 2026
cb284d4
Use usqr64 for numSamplesSqr in ecmProcessSet
FredM67 Jan 15, 2026
ff730bc
Place asm math functions in RAM for faster execution
FredM67 Jan 15, 2026
906849c
Fix channel number output format: use %u instead of %x
FredM67 Jan 15, 2026
83cb9aa
Update SERIAL_COMMANDS.md documentation
FredM67 Jan 15, 2026
1aec5d2
Merge branch 'main' into feature/type-consistency-fixes
FredM67 Jan 16, 2026
f8724c9
Merge branch 'feature/type-consistency-fixes' of github.com:FredM67/e…
FredM67 Jan 16, 2026
c147c62
Fix SIZE_MAX...
FredM67 Jan 16, 2026
2b8b927
Fix type inconsistency for validByte in eepromWriteWL function
FredM67 Jan 16, 2026
41c5d43
Fix type inconsistency in calibrationPhase function
FredM67 Jan 17, 2026
c8dfda1
Fix type consistency by using const for variables in calcRMS function
FredM67 Jan 17, 2026
030df70
Fix type inconsistency by using const for idxInjPrev in ecmFilterSamp…
FredM67 Jan 17, 2026
582aa8a
Merge branch 'main' into feature/type-consistency-fixes
FredM67 Jan 17, 2026
185c75c
Merge branch 'main' into feature/type-consistency-fixes
FredM67 Jan 20, 2026
0ffce2f
[Fix] Correct type casting for pin value in pulseUpdate function
FredM67 Jan 20, 2026
a92c237
[Fix] Remove unused resetReq variable in configuration.c
FredM67 Jan 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ CFLAGS += -funsigned-char -funsigned-bitfields
CFLAGS += -Wuninitialized
CFLAGS += -Wshadow -Wdouble-promotion -Wundef
CFLAGS += -mcpu=cortex-m0plus -mthumb
CFLAGS += -Wconversion -Wsign-conversion
CFLAGS += -MD -MP -MT $(BUILD)/$(*F).o -MF $(BUILD)/$(@F).d

LDFLAGS += -mcpu=cortex-m0plus -mthumb
Expand All @@ -32,12 +33,12 @@ LDFLAGS += -Wl,--print-memory-usage
LDFLAGS += -Wl,--script=./linker/samd21j17.ld

INCLUDES += \
-I./include/samd21 \
-I./third_party/printf \
-I./third_party/qfplib \
-I./third_party/RFM69 \
-I./third_party/tinyusb/src \
-I./third_party/tinyusb/src/device \
-isystem ./include/samd21 \
-isystem ./third_party/printf \
-isystem ./third_party/qfplib \
-isystem ./third_party/RFM69 \
-isystem ./third_party/tinyusb/src \
-isystem ./third_party/tinyusb/src/device \
-I./src/

SRCS += $(wildcard ./src/*.c) \
Expand Down
2 changes: 1 addition & 1 deletion src/board_def.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ const uint8_t pinsADC[][2] = {{GRP_ADC_VMID, PIN_ADC_VMID},
/* Remapping for analog CT inputs. This maps the 0-indexed CT physical pin to
* the logical pin. For example, physical CT1 is the 4th CT sampled so:
* ainRemap[0] = 3. */
const int_fast8_t ainRemap[NUM_CT] = {3, 4, 7, 1, 2, 11, 5, 6, 8, 9, 10, 0};
const uint8_t ainRemap[NUM_CT] = {3, 4, 7, 1, 2, 11, 5, 6, 8, 9, 10, 0};
6 changes: 3 additions & 3 deletions src/board_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@

/* EEPROM */
/* Top of EEPROM address, not including R/W bit */
#define EEPROM_BASE_ADDR 0x50
#define EEPROM_BASE_ADDR 0x50u
/* Maximum number of bytes in a single page */
#define EEPROM_PAGE_SIZE 16u
/* Worst case EEPROM write time (microseconds) */
#define EEPROM_WR_TIME 5000ul
/* Size of configuration area */
#define EEPROM_CONFIG_SIZE 256
#define EEPROM_CONFIG_SIZE 256u
/* Size of the EEPROM in bytes */
#define EEPROM_SIZE 1024
#define EEPROM_SIZE 1024u
/* Offset of wear levelled area */
#define EEPROM_WL_OFFSET (EEPROM_CONFIG_SIZE)

Expand Down
67 changes: 32 additions & 35 deletions src/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static void configDefault(void);
static void configEchoQueueChar(const uint8_t c);
static void configEchoQueueStr(const char *s);
static void configInitialiseNVM(void);
static int32_t configTimeToCycles(const float time, const int32_t mainsFreq);
static uint16_t configTimeToCycles(const float time, const uint32_t mainsFreq);
static bool configureAnalog(void);
static bool configureAssumed(void);
static void configureBackup(void);
Expand All @@ -68,7 +68,7 @@ static bool configureSerialLog(void);
static void enterBootloader(void);
static uint32_t getBoardRevision(void);
static char *getLastReset(void);
static void inBufferClear(int32_t n);
static void inBufferClear(size_t n);
static void printSettingCT(const int32_t ch);
static void printSettingDatalog(void);
static void printSettingJSON(void);
Expand Down Expand Up @@ -350,10 +350,9 @@ static void configureBackup(void) {
serialPuts("{");
/* {board_info} dict */
serialPuts("\"board_info\":{");
printf_("\"revision\":%d,", (int32_t)getBoardRevision());
printf_("\"serial\":\"0x%02x%02x%02x%02x\",", (uint32_t)getUniqueID(0),
(uint32_t)getUniqueID(1), (uint32_t)getUniqueID(2),
(uint32_t)getUniqueID(3));
printf_("\"revision\":%ld,", getBoardRevision());
printf_("\"serial\":\"0x%02lx%02lx%02lx%02lx\",", getUniqueID(0),
getUniqueID(1), getUniqueID(2), getUniqueID(3));
printf_("\"fw\":\"%d.%d.%d\"},", VERSION_FW_MAJ, VERSION_FW_MIN,
VERSION_FW_REV);

Expand Down Expand Up @@ -425,7 +424,7 @@ static bool configureGroupID(void) {
}

config.baseCfg.dataGrp = convI.val;
printf_("rfGroup = %d\r\n", (int32_t)convI.val);
printf_("rfGroup = %ld\r\n", convI.val);
return true;
}

Expand Down Expand Up @@ -628,7 +627,7 @@ static bool configureRFPower(void) {
}

config.dataTxCfg.rfmPwr = convI.val;
printf_("rfPower = %d\r\n", (int32_t)convI.val);
printf_("rfPower = %ld\r\n", convI.val);
return true;
}

Expand Down Expand Up @@ -707,18 +706,18 @@ uint32_t getUniqueID(int32_t idx) {
return *(volatile uint32_t *)id_addr_lut[idx];
}

static void inBufferClear(int32_t n) {
static void inBufferClear(size_t n) {
inBufferIdx = 0;
(void)memset(inBuffer, 0, n);
}

static void printSettingCT(const int32_t ch) {
printf_("iCal%d = ", (ch + 1));
printf_("iCal%ld = ", (ch + 1));
putFloat(config.ctCfg[ch].ctCal, 0);
printf_(", iLead%d = ", (ch + 1));
printf_(", iLead%ld = ", (ch + 1));
putFloat(config.ctCfg[ch].phase, 0);
printf_(", iActive%d = %s", (ch + 1), config.ctCfg[ch].ctActive ? "1" : "0");
printf_(", v1Chan%d = %d, v2Chan%d = %d\r\n", (ch + 1),
printf_(", iActive%ld = %s", (ch + 1), config.ctCfg[ch].ctActive ? "1" : "0");
printf_(", v1Chan%ld = %d, v2Chan%ld = %d\r\n", (ch + 1),
(config.ctCfg[ch].vChan1 + 1), (ch + 1),
(config.ctCfg[ch].vChan2 + 1));
}
Expand All @@ -734,7 +733,7 @@ static void printSettingJSON(void) {
}

static void printSettingOPA(const int32_t ch) {
printf_("opa%d = ", (ch + 1));
printf_("opa%ld = ", (ch + 1));

/* OneWire */
if ('o' == config.opaCfg[ch].func) {
Expand Down Expand Up @@ -778,17 +777,17 @@ static void printSettingRFFreq(void) {
}

static void printSettingV(const int32_t ch) {
printf_("vCal%d = ", (ch + 1));
printf_("vCal%ld = ", (ch + 1));
putFloat(config.voltageCfg[ch].voltageCal, 0);
printf_(", vActive%d = %s\r\n", (ch + 1),
printf_(", vActive%ld = %s\r\n", (ch + 1),
config.voltageCfg[ch].vActive ? "1" : "0");
}

static void printAccumulators(void) {
Emon32Cumulative_t cumulative;
eepromWLStatus_t status;
bool eepromOK;
int32_t idx;
uint32_t idx;

status = eepromReadWL(&cumulative, &idx);
eepromOK = (EEPROM_WL_OK == status);
Expand All @@ -799,15 +798,15 @@ static void printAccumulators(void) {
} else if (!eepromOK) {
serialPuts(" (no valid NVM data)");
}
printf_(" [%d]:\r\n", idx);
printf_(" [%lu]:\r\n", idx);

for (uint32_t i = 0; i < NUM_CT; i++) {
int32_t wh = eepromOK ? cumulative.wattHour[i] : 0;
printf_(" E%ld = %ld Wh\r\n", (i + 1), wh);
uint32_t wh = eepromOK ? cumulative.wattHour[i] : 0;
printf_(" E%lu = %lu Wh\r\n", (i + 1), wh);
}
for (uint32_t i = 0; i < NUM_OPA; i++) {
uint32_t pulse = eepromOK ? cumulative.pulseCnt[i] : 0;
printf_(" pulse%d = %" PRIu32 "\r\n", (i + 1), pulse);
printf_(" pulse%lu = %lu\r\n", (i + 1), pulse);
}
serialPuts("\r\n");
}
Expand Down Expand Up @@ -849,7 +848,7 @@ static void printSettingsHR(void) {

for (uint32_t i = 0; i < NUM_OPA; i++) {
bool enabled = config.opaCfg[i].opaActive;
printf_("OPA %d (%sactive)\r\n", (i + 1), enabled ? "" : "in");
printf_("OPA %lu (%sactive)\r\n", (i + 1), enabled ? "" : "in");
if ('o' == config.opaCfg[i].func) {
serialPuts(" - OneWire interface\r\n");
} else {
Expand Down Expand Up @@ -883,13 +882,13 @@ static void printSettingsHR(void) {
serialPuts(
"+=====+=========+========+=============+=========+======+======+\r\n");
for (int32_t i = 0; i < NUM_V; i++) {
printf_("| %2d | V %2d | %c | ", (i + 1), (i + 1),
printf_("| %2ld | V %2ld | %c | ", (i + 1), (i + 1),
(config.voltageCfg[i].vActive ? 'Y' : 'N'));
putFloat(config.voltageCfg[i].voltageCal, 6);
serialPuts(" | | | |\r\n");
}
for (int32_t i = 0; i < NUM_CT; i++) {
printf_("| %2d | CT %2d | %c | ", (i + 1 + NUM_V), (i + 1),
printf_("| %2ld | CT %2ld | %c | ", (i + 1 + NUM_V), (i + 1),
(config.ctCfg[i].ctActive ? 'Y' : 'N'));
putFloat(config.ctCfg[i].ctCal, 6);
serialPuts(" | ");
Expand All @@ -902,7 +901,7 @@ static void printSettingsHR(void) {

static void printSettingsKV(void) {
serialPuts("hardware = emonPi3\r\n");
printf_("hardware_rev = %" PRIu32 "\r\n", getBoardRevision());
printf_("hardware_rev = %lu\r\n", getBoardRevision());
printf_("version = %d.%d.%d\r\n", VERSION_FW_MAJ, VERSION_FW_MIN,
VERSION_FW_REV);
printf_("commit = %s\r\n", emon32_build_info().revision);
Expand Down Expand Up @@ -948,8 +947,7 @@ static void printUptime(void) {
tMinutes = tMinutes % 60;
tHours = tHours % 24;

printf_("%" PRIu32 "d %" PRIu32 "h %" PRIu32 "m %" PRIu32 "s\r\n", tDays,
tHours, tMinutes, tSeconds);
printf_("%lud %luh %lum %lus\r\n", tDays, tHours, tMinutes, tSeconds);
}

/*! @brief Check if waiting for confirmation and handle if yes
Expand Down Expand Up @@ -1010,7 +1008,7 @@ static void handleConfirmation(char c) {
case CONFIRM_ZERO_ACCUM_INDIVIDUAL:
if ('y' == c) {
Emon32Cumulative_t cumulative;
int32_t idx;
uint32_t idx;
/* Read current NVM data */
if (EEPROM_WL_OK == eepromReadWL(&cumulative, &idx)) {
/* Clear the specific accumulator */
Expand Down Expand Up @@ -1211,11 +1209,10 @@ void configFirmwareBoardInfo(void) {
serialPuts("\033c==== emonPi3 | emonTx6 ====\r\n\r\n");

serialPuts("> Board:\r\n");
printf_(" - emonPi3/emonTx6 (arch. rev. %" PRIu32 ")\r\n",
getBoardRevision());
printf_(" - Serial : 0x%02x%02x%02x%02x\r\n", (uint32_t)getUniqueID(0),
(uint32_t)getUniqueID(1), (uint32_t)getUniqueID(2),
(uint32_t)getUniqueID(3));
printf_(" - emonPi3/emonTx6 (arch. rev. %lu)\r\n", getBoardRevision());
printf_(" - Serial : 0x%02lx%02lx%02lx%02lx\r\n",
(uint32_t)getUniqueID(0), (uint32_t)getUniqueID(1),
(uint32_t)getUniqueID(2), (uint32_t)getUniqueID(3));
printf_(" - Last reset: %s\r\n", getLastReset());
serialPuts(" - Uptime : ");
printUptime();
Expand Down Expand Up @@ -1472,8 +1469,8 @@ void configProcessCmd(void) {

bool configUnsavedChanges(void) { return unsavedChange; }

int32_t configTimeToCycles(const float time, const int32_t mainsFreq) {
return qfp_float2uint(qfp_fmul(time, qfp_int2float(mainsFreq)));
uint16_t configTimeToCycles(const float time, const uint32_t mainsFreq) {
return (uint16_t)qfp_float2uint(qfp_fmul(time, qfp_int2float(mainsFreq)));
}

VersionInfo_t configVersion(void) {
Expand Down
Loading