Skip to content

refactor(bus): naming cleanup phase 2 (type sweep + identifier consistency)#1111

Merged
nerdCopter merged 3 commits intoemuflight:masterfrom
nerdCopter:refactor/extDevice_t-phase2
Apr 21, 2026
Merged

refactor(bus): naming cleanup phase 2 (type sweep + identifier consistency)#1111
nerdCopter merged 3 commits intoemuflight:masterfrom
nerdCopter:refactor/extDevice_t-phase2

Conversation

@nerdCopter
Copy link
Copy Markdown
Member

@nerdCopter nerdCopter commented Apr 20, 2026

Continuation of #1108 (phase 1, now merged).

What this does

Three commits that complete the identifier rename started in phase 1:

  • G (bb15493fa5) — sweep busDevice_textDevice_t across tree, keep alias
  • H (c7ee1f82e2) — rename bus/busdev parameter and body identifiers to dev
  • H-bis (948ba74024) — drop the transitional busDevice_t typedef alias

No logic changes. After this series every driver signature and body uses extDevice_t *dev consistently, matching BF 4.5-maintenance naming.

Testing

  • Hover-tested on FOXEERF722V4 (STM32F7, MPU6000) at phase 2 tip (pre-rebase SHA; same code)
  • Build-verified on FOXEERF405, PYRODRONEF7, SKYSTARSF405AIO, HELIOSPRING

Relationship to later phases

Phase 3 (refactor/extDevice_t-bus-split) adds the bus-resource split infrastructure and is waiting for this to merge.

Summary by CodeRabbit

  • Refactor
    • Updated device abstraction API and interfaces across sensor drivers (gyroscope, accelerometer, barometer, compass), bus implementations (SPI, I2C), and peripheral drivers (flash, display, receiver) to use a standardized device structure for consistent hardware abstraction throughout the codebase.

nerdCopter and others added 3 commits April 20, 2026 09:42
Stage G of the extDevice_t refactor, phase 2 branch.

bus.h: primary struct tag renamed busDevice_s -> extDevice_s, primary typedef
       produces extDevice_t, mpuSlave master pointer typed const struct
       extDevice_s *. Kept `typedef extDevice_t busDevice_t;` as a transitional
       alias so any overlooked caller still compiles; the alias can be removed
       in a follow-up once the whole tree is visibly clean.

Function declarations in bus.h updated to take const extDevice_t *dev
parameter names (body-local parameter-name rename in bus.c / bus_spi.c /
bus_i2c_busdev.c and callers is cosmetic and deferred to a follow-up).

Global sweep: 49 other source + unit-test files, 174 insertions / 174
deletions, line-for-line. Only busDevice_t references that remain are the
typedef alias line and its comment in bus.h.

No behavioural change. Verified: make test + 5 targets rc=0, 0 new compiler
warnings (HELIOSPRING FOXEERF405 FOXEERF722V4 HGLRCF411 NBDHMBF4PRO).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…res and bodies

Stage H of the extDevice_t refactor, phase 2 branch. Mechanical identifier
cleanup to match BF 4.5-maintenance's `const extDevice_t *dev` convention.

Two passes:

1. `busdev` global rename (not an English word, safe). 19 files, renamed
   both active code and commented-out references for consistency.

2. `bus` syntactic-context rename. `bus` IS an English word, so used
   identifier-position sed patterns (\*bus\b / &bus\b / \bbus-> / (bus,)
   instead of \bbus\b globally. Comment uses like "serial bus", "APB1 bus",
   "SPI bus utilization" are preserved. 27 files.

compass.c single-file exception: compassDetect(magDev_t *dev) already has a
parameter named `dev`, so its local alias was renamed busdev -> extDev
instead of -> dev to avoid shadow + self-referencing init.

No behavioural change. 44 files, 733 insertions / 733 deletions (line-for-line).

Verified: make test + 5 targets rc=0, 0 new compiler warnings vs Stage A
baseline (HELIOSPRING FOXEERF405 FOXEERF722V4 HGLRCF411 NBDHMBF4PRO).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Stage H-bis. After Stage H migrated every caller off busDevice_t, the only
remaining reference was the transitional alias in bus.h itself. Remove it:
nothing in the tree depends on the name any longer.

bus.h shrinks by 7 lines (alias declaration + its explanatory comment block).

Full grep of src/: zero `\bbusDevice_t\b` matches anywhere after this commit.
The struct tag remains `struct extDevice_s`; the typedef remains `extDevice_t`.

Verified: make test + 5 targets rc=0, 0 new compiler warnings.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 20, 2026

📝 Walkthrough

Walkthrough

This pull request performs a widespread refactoring that renames the core device abstraction type from busDevice_t to extDevice_t throughout the codebase, updating function signatures, struct definitions, parameter names, and internal references across bus drivers, sensor drivers, and related systems.

Changes

Cohort / File(s) Summary
Core Bus Infrastructure
src/main/drivers/bus.h, src/main/drivers/bus.c
Renamed primary struct from busDevice_t to extDevice_t, updated function signatures (busWriteRegister, busReadRegisterBuffer, busReadRegister) to use extDevice_t *dev parameter, removed old typedef alias.
SPI Bus Driver
src/main/drivers/bus_spi.h, src/main/drivers/bus_spi.c
Updated SPI transaction functions (spiReadWriteBuf, spiWriteReg, spiReadRegBuf, spiReadReg, spiBusSetInstance, spiReadRegMsk) to accept extDevice_t *dev instead of busDevice_t *bus.
I2C Bus Driver
src/main/drivers/bus_i2c_busdev.h, src/main/drivers/bus_i2c_busdev.c
Updated I2C bus functions (i2cBusWriteRegister, i2cBusReadRegisterBuffer, i2cBusReadRegister) to accept extDevice_t *dev parameter.
Accelerometer/Gyroscope Drivers
src/main/drivers/accgyro/accgyro_imuf9001.*, accgyro_mpu.*, accgyro_spi_bmi160.*, accgyro_spi_bmi270.*, accgyro_spi_icm20649.*, accgyro_spi_icm20689.*, accgyro_spi_icm426xx.*, accgyro_spi_mpu6000.*, accgyro_spi_mpu6500.*, accgyro_spi_mpu9250.*
Updated all detect/init/read functions across multiple IMU drivers to accept extDevice_t *dev instead of busDevice_t *bus and rewired internal SPI/I2C register operations accordingly.
Barometer Drivers
src/main/drivers/barometer/barometer_bmp085.c, barometer_bmp280.*, barometer_lps.c, barometer_ms5611.c, barometer_qmp6988.c
Updated bus init/deinit/detect functions to use extDevice_t *dev, changed local variable types and all bus operation calls (busReadRegisterBuffer, busWriteRegister) to reference new device type.
Compass Drivers
src/main/drivers/compass/compass_ak8963.c, compass_ak8975.c, compass_hmc5883l.c, compass_lis3mdl.c, compass_qmc5883l.c
Updated bus initialization and register access paths to use extDevice_t *dev, changed local device pointers from busDevice_t to extDevice_t and updated all bus calls accordingly.
Display Driver
src/main/drivers/display_ug2864hsweg01.h, src/main/drivers/display_ug2864hsweg01.c
Updated OLED I2C helper functions and initialization to accept extDevice_t *dev, changed all I2C write operations to use new device type.
Flash Drivers
src/main/drivers/flash.c, src/main/drivers/flash_m25p16.c, src/main/drivers/flash_w25m.c
Updated SPI device initialization and transfer helpers to use extDevice_t instead of busDevice_t, rewired pin/instance access accordingly.
OSD Drivers
src/main/drivers/max7456.c, src/main/drivers/nbd7456.c
Replaced global device handle and all SPI/DMA/IO operations from busDevice_t to extDevice_t, updated transaction macros and divisor/pin configuration calls.
RX SPI Driver
src/main/drivers/rx/rx_spi.c
Updated static device handle and transfer macros from busDevice_t to extDevice_t, rewired chip-select and instance references.
Sensor Abstractions
src/main/sensors/compass.c, src/main/sensors/gyro.c, src/main/sensors/gyro.h, src/main/io/dashboard.c
Updated sensor bus accessor functions and local device variables to return/use extDevice_t instead of busDevice_t.
Unit Test Stubs
src/test/unit/baro_bmp085_unittest.cc.txt, baro_bmp280_unittest.cc, baro_ms5611_unittest.cc
Updated C-linkage stub signatures for busReadRegisterBuffer and busWriteRegister to accept extDevice_t* instead of busDevice_t*.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main objective: completing a naming cleanup by sweeping busDevice_t to extDevice_t and ensuring consistent identifier naming across the codebase.
Description check ✅ Passed The PR description comprehensively documents the three-phase refactoring effort with context, changes made, and testing verification, though it could be more concise and could better follow the repository template structure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Timed out fetching pipeline failures after 30000ms


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (4)
src/main/drivers/barometer/barometer_lps.c (1)

244-250: Use the local dev alias for the WHO_AM_I read.

lpsDetect() introduces dev for this exact purpose, but Line 250 still reaches through &baro->dev. This is functionally equivalent, but it leaves one naming-consistency miss in the sweep.

♻️ Proposed cleanup
-    lpsReadCommand(&baro->dev, LPS_WHO_AM_I, &temp, 1);
+    lpsReadCommand(dev, LPS_WHO_AM_I, &temp, 1);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/drivers/barometer/barometer_lps.c` around lines 244 - 250, The
WHO_AM_I read uses &baro->dev instead of the local alias dev introduced earlier;
update the lpsReadCommand call in lpsDetect (replace lpsReadCommand(&baro->dev,
LPS_WHO_AM_I, &temp, 1)) to use the local pointer (dev) so the call becomes
lpsReadCommand(dev, LPS_WHO_AM_I, &temp, 1), keeping naming consistent with
extDevice_t *dev and the preceding IO/ SPI setup.
src/main/drivers/compass/compass_lis3mdl.c (1)

129-134: Use the local dev alias for the detect read.

lis3mdlDetect() sets up dev, but Line 134 still passes &mag->dev. Keeping this as dev closes a residual identifier-consistency gap.

♻️ Proposed cleanup
-    bool ack = busReadRegisterBuffer(&mag->dev, LIS3MDL_REG_WHO_AM_I, &sig, 1);
+    bool ack = busReadRegisterBuffer(dev, LIS3MDL_REG_WHO_AM_I, &sig, 1);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/drivers/compass/compass_lis3mdl.c` around lines 129 - 134, The
detect routine lis3mdlDetect sets up a local alias extDevice_t *dev = &mag->dev
but the subsequent bus read still uses &mag->dev; change the call to
busReadRegisterBuffer to use the local alias (dev) instead of &mag->dev so
identifier usage is consistent: replace the argument passed to
busReadRegisterBuffer(..., LIS3MDL_REG_WHO_AM_I, &sig, 1) from &mag->dev to dev,
keeping the rest of the call and variables (sig, LIS3MDL_REG_WHO_AM_I,
busReadRegisterBuffer) unchanged.
src/main/drivers/compass/compass_hmc5883l.c (1)

217-233: Minor: use the local dev consistently throughout hmc5883lDetect.

Lines 222 and 230 still pass &mag->dev even though the function already has extDevice_t *dev = &mag->dev; on line 218 (used on lines 221/226/227). Functionally equivalent, but the mixed usage is easy to miss in future reads and defeats the point of the local.

♻️ Proposed fix
 `#ifdef` USE_MAG_SPI_HMC5883
     if (dev->busType == BUS_TYPE_SPI) {
-        hmc5883SpiInit(&mag->dev);
+        hmc5883SpiInit(dev);
     }
 `#endif`
 `#ifdef` USE_MAG_HMC5883
     if (dev->busType == BUS_TYPE_I2C && dev->busType_u.i2c.address == 0) {
         dev->busType_u.i2c.address = HMC5883_MAG_I2C_ADDRESS;
     }
 `#endif`
-    bool ack = busReadRegisterBuffer(&mag->dev, HMC58X3_REG_IDA, &sig, 1);
+    bool ack = busReadRegisterBuffer(dev, HMC58X3_REG_IDA, &sig, 1);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/drivers/compass/compass_hmc5883l.c` around lines 217 - 233, In
hmc5883lDetect, consistently use the local pointer dev instead of dereferencing
mag->dev in the calls; replace occurrences of &mag->dev passed to hmc5883SpiInit
and busReadRegisterBuffer with dev so hmc5883SpiInit(dev) and
busReadRegisterBuffer(dev, HMC58X3_REG_IDA, &sig, 1) use the already-defined
extDevice_t *dev = &mag->dev, keeping usage uniform with the other references to
dev in this function.
src/main/drivers/accgyro/accgyro_spi_mpu9250.c (1)

75-83: Dead-code initializer references a non-existent field.

Per bus.h, extDevice_t has no .spi member — SPI fields are nested under .busType_u.spi. The #if 0 guard keeps this from breaking the build, but since the XXX comment and the type were updated as part of this sweep, the initializer should either be corrected for consistency or the stub removed. As-is, anyone who enables this block for testing will immediately hit a compile error that's unrelated to what mpu9250SpiResetGyro is trying to demonstrate.

♻️ Proposed fix (correct the designator)
 `#ifdef` MPU9250_CS_PIN
-    extDevice_t dev = { .spi = { .csnPin = IOGetByTag(IO_TAG(MPU9250_CS_PIN)) } };
+    extDevice_t dev = { .busType = BUS_TYPE_SPI, .busType_u.spi.csnPin = IOGetByTag(IO_TAG(MPU9250_CS_PIN)) };
     mpu9250SpiWriteRegister(&dev, MPU_RA_PWR_MGMT_1, MPU9250_BIT_RESET);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/drivers/accgyro/accgyro_spi_mpu9250.c` around lines 75 - 83, The
dead code block uses an incorrect designator for extDevice_t (it references .spi
which no longer exists per bus.h); either remove the stub or update the
initializer to use the correct nested field (busType_u.spi) so it compiles if
enabled — e.g., change the initializer used when building an extDevice_t for
mpu9250SpiWriteRegister/MPU_RA_PWR_MGMT_1/MPU9250_BIT_RESET (or drop the whole
block and keep the comment) and ensure mpu9250SpiResetGyro callers use the
corrected extDevice_t layout.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/drivers/max7456.c`:
- Around line 193-194: The globals max7456BusDevice and dev are currently
external and collide with identical symbols in another compilation unit; mark
both declarations in this file as static to give them internal linkage (e.g.,
change extDevice_t max7456BusDevice; and extDevice_t *dev = &max7456BusDevice;
to static declarations). Also consider renaming the generic pointer symbol dev
to a file-local name like max7456Dev (still static) to further avoid accidental
collisions and improve clarity; update all uses of dev and max7456BusDevice in
this file accordingly.

In `@src/main/drivers/nbd7456.c`:
- Around line 193-194: The file-scope variables max7456BusDevice and dev
currently have external linkage and should be made internal to avoid linker
collisions; change the declarations of max7456BusDevice and the pointer dev in
nbd7456.c (and the identical pair in max7456.c) to use static (i.e., make
max7456BusDevice static and dev static pointing at &max7456BusDevice) so both
symbols have internal linkage and cannot collide across translation units.

---

Nitpick comments:
In `@src/main/drivers/accgyro/accgyro_spi_mpu9250.c`:
- Around line 75-83: The dead code block uses an incorrect designator for
extDevice_t (it references .spi which no longer exists per bus.h); either remove
the stub or update the initializer to use the correct nested field
(busType_u.spi) so it compiles if enabled — e.g., change the initializer used
when building an extDevice_t for
mpu9250SpiWriteRegister/MPU_RA_PWR_MGMT_1/MPU9250_BIT_RESET (or drop the whole
block and keep the comment) and ensure mpu9250SpiResetGyro callers use the
corrected extDevice_t layout.

In `@src/main/drivers/barometer/barometer_lps.c`:
- Around line 244-250: The WHO_AM_I read uses &baro->dev instead of the local
alias dev introduced earlier; update the lpsReadCommand call in lpsDetect
(replace lpsReadCommand(&baro->dev, LPS_WHO_AM_I, &temp, 1)) to use the local
pointer (dev) so the call becomes lpsReadCommand(dev, LPS_WHO_AM_I, &temp, 1),
keeping naming consistent with extDevice_t *dev and the preceding IO/ SPI setup.

In `@src/main/drivers/compass/compass_hmc5883l.c`:
- Around line 217-233: In hmc5883lDetect, consistently use the local pointer dev
instead of dereferencing mag->dev in the calls; replace occurrences of &mag->dev
passed to hmc5883SpiInit and busReadRegisterBuffer with dev so
hmc5883SpiInit(dev) and busReadRegisterBuffer(dev, HMC58X3_REG_IDA, &sig, 1) use
the already-defined extDevice_t *dev = &mag->dev, keeping usage uniform with the
other references to dev in this function.

In `@src/main/drivers/compass/compass_lis3mdl.c`:
- Around line 129-134: The detect routine lis3mdlDetect sets up a local alias
extDevice_t *dev = &mag->dev but the subsequent bus read still uses &mag->dev;
change the call to busReadRegisterBuffer to use the local alias (dev) instead of
&mag->dev so identifier usage is consistent: replace the argument passed to
busReadRegisterBuffer(..., LIS3MDL_REG_WHO_AM_I, &sig, 1) from &mag->dev to dev,
keeping the rest of the call and variables (sig, LIS3MDL_REG_WHO_AM_I,
busReadRegisterBuffer) unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7ffffd83-a7cc-499d-b0e1-ad1a955825e4

📥 Commits

Reviewing files that changed from the base of the PR and between cabd1b6 and 948ba74.

📒 Files selected for processing (51)
  • src/main/drivers/accgyro/accgyro_imuf9001.c
  • src/main/drivers/accgyro/accgyro_imuf9001.h
  • src/main/drivers/accgyro/accgyro_mpu.c
  • src/main/drivers/accgyro/accgyro_mpu.h
  • src/main/drivers/accgyro/accgyro_spi_bmi160.c
  • src/main/drivers/accgyro/accgyro_spi_bmi160.h
  • src/main/drivers/accgyro/accgyro_spi_bmi270.c
  • src/main/drivers/accgyro/accgyro_spi_bmi270.h
  • src/main/drivers/accgyro/accgyro_spi_icm20649.c
  • src/main/drivers/accgyro/accgyro_spi_icm20649.h
  • src/main/drivers/accgyro/accgyro_spi_icm20689.c
  • src/main/drivers/accgyro/accgyro_spi_icm20689.h
  • src/main/drivers/accgyro/accgyro_spi_icm426xx.c
  • src/main/drivers/accgyro/accgyro_spi_icm426xx.h
  • src/main/drivers/accgyro/accgyro_spi_mpu6000.c
  • src/main/drivers/accgyro/accgyro_spi_mpu6000.h
  • src/main/drivers/accgyro/accgyro_spi_mpu6500.c
  • src/main/drivers/accgyro/accgyro_spi_mpu6500.h
  • src/main/drivers/accgyro/accgyro_spi_mpu9250.c
  • src/main/drivers/accgyro/accgyro_spi_mpu9250.h
  • src/main/drivers/barometer/barometer_bmp085.c
  • src/main/drivers/barometer/barometer_bmp280.c
  • src/main/drivers/barometer/barometer_lps.c
  • src/main/drivers/barometer/barometer_ms5611.c
  • src/main/drivers/barometer/barometer_qmp6988.c
  • src/main/drivers/bus.c
  • src/main/drivers/bus.h
  • src/main/drivers/bus_i2c_busdev.c
  • src/main/drivers/bus_i2c_busdev.h
  • src/main/drivers/bus_spi.c
  • src/main/drivers/bus_spi.h
  • src/main/drivers/compass/compass_ak8963.c
  • src/main/drivers/compass/compass_ak8975.c
  • src/main/drivers/compass/compass_hmc5883l.c
  • src/main/drivers/compass/compass_lis3mdl.c
  • src/main/drivers/compass/compass_qmc5883l.c
  • src/main/drivers/display_ug2864hsweg01.c
  • src/main/drivers/display_ug2864hsweg01.h
  • src/main/drivers/flash.c
  • src/main/drivers/flash_m25p16.c
  • src/main/drivers/flash_w25m.c
  • src/main/drivers/max7456.c
  • src/main/drivers/nbd7456.c
  • src/main/drivers/rx/rx_spi.c
  • src/main/io/dashboard.c
  • src/main/sensors/compass.c
  • src/main/sensors/gyro.c
  • src/main/sensors/gyro.h
  • src/test/unit/baro_bmp085_unittest.cc.txt
  • src/test/unit/baro_bmp280_unittest.cc
  • src/test/unit/baro_ms5611_unittest.cc

Comment on lines +193 to +194
extDevice_t max7456BusDevice;
extDevice_t *dev = &max7456BusDevice;
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Look for any file-scope definition of `dev` with extDevice_t/busDevice_t type, and external references to max7456BusDevice.
rg -nP --type=c --type=cpp -C1 '^\s*(extern\s+)?(ext|bus)Device_t\s*\*?\s*dev\s*(=|;)'
echo '---'
rg -nP -C1 '\bmax7456BusDevice\b'

Repository: emuflight/EmuFlight

Length of output: 7096


Mark max7456BusDevice and dev static to avoid ODR violations and symbol collisions.

Both max7456BusDevice and dev are declared with external linkage in this file (lines 193–194). This same pair is also declared identically in src/main/drivers/nbd7456.c at lines 193–194, creating an ODR violation if both files are linked together. Additionally, dev is an extremely generic name that creates linker collision risk. Since both variables are used only within their respective files, they must be declared static.

♻️ Proposed fix
-extDevice_t max7456BusDevice;
-extDevice_t *dev = &max7456BusDevice;
+static extDevice_t max7456BusDevice;
+static extDevice_t *dev = &max7456BusDevice;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
extDevice_t max7456BusDevice;
extDevice_t *dev = &max7456BusDevice;
static extDevice_t max7456BusDevice;
static extDevice_t *dev = &max7456BusDevice;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/drivers/max7456.c` around lines 193 - 194, The globals
max7456BusDevice and dev are currently external and collide with identical
symbols in another compilation unit; mark both declarations in this file as
static to give them internal linkage (e.g., change extDevice_t max7456BusDevice;
and extDevice_t *dev = &max7456BusDevice; to static declarations). Also consider
renaming the generic pointer symbol dev to a file-local name like max7456Dev
(still static) to further avoid accidental collisions and improve clarity;
update all uses of dev and max7456BusDevice in this file accordingly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai, this is a refactor-only PR. This seems to be a pre-existing issue.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nerdCopter, you're correct — the diff confirms this PR only performs a mechanical type rename (busDevice_textDevice_t) and identifier rename (busdevdev). The missing static on max7456BusDevice and dev (and the corresponding issue in nbd7456.c) was already present before this PR and is outside its scope.

Would you like me to open a follow-up GitHub issue to track adding static to these declarations in both max7456.c and nbd7456.c?


🧠 Learnings used
Learnt from: nerdCopter
Repo: emuflight/EmuFlight PR: 0
File: :0-0
Timestamp: 2026-04-04T21:55:50.478Z
Learning: In the EmuFlight project (GitHub: emuflight/EmuFlight), issue `#1106` involves CLI AutoComplete stalls on HELIOSPRING/STRIXF10/MODE2FLUX boards caused by USB VCP write starvation under EXTI preemption. The proposed fix (disabling EXTI via `EXTIEnable()` in `cliEnter()` and re-enabling in `cliExit()`/`cliRebootEx()`) was initially rejected due to apparent "permanent gyro corruption requiring reflash." However, this regression was later identified as a pre-existing configurator CLI/MSP reconnect bug present in the EmuFlight configurator NWjs master branch (not just an Electron/Forge migration bug). The configurator fails to properly re-establish MSP polling after CLI exits; a reflash incidentally forces USB re-enumeration which triggers a clean reconnect, masking the real cause. The EXTI fix itself is logically sound and should be re-evaluated using firmware-independent gyro verification (raw MSP tool) rather than the buggy configurator.

Copy link
Copy Markdown
Member Author

@nerdCopter nerdCopter Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nerdCopter, thanks for sharing — #1112 is noted as the tracking issue for adding static to max7456BusDevice/dev in max7456.c and nbd7456.c. This review comment is resolved; the fix will be addressed as part of that follow-up.


🧠 Learnings used
Learnt from: nerdCopter
Repo: emuflight/EmuFlight PR: 0
File: :0-0
Timestamp: 2026-04-04T21:55:50.478Z
Learning: In the EmuFlight project (GitHub: emuflight/EmuFlight), issue `#1106` involves CLI AutoComplete stalls on HELIOSPRING/STRIXF10/MODE2FLUX boards caused by USB VCP write starvation under EXTI preemption. The proposed fix (disabling EXTI via `EXTIEnable()` in `cliEnter()` and re-enabling in `cliExit()`/`cliRebootEx()`) was initially rejected due to apparent "permanent gyro corruption requiring reflash." However, this regression was later identified as a pre-existing configurator CLI/MSP reconnect bug present in the EmuFlight configurator NWjs master branch (not just an Electron/Forge migration bug). The configurator fails to properly re-establish MSP polling after CLI exits; a reflash incidentally forces USB re-enumeration which triggers a clean reconnect, masking the real cause. The EXTI fix itself is logically sound and should be re-evaluated using firmware-independent gyro verification (raw MSP tool) rather than the buggy configurator.

Learnt from: nerdCopter
Repo: emuflight/EmuFlight PR: 0
File: :0-0
Timestamp: 2026-03-26T16:06:21.396Z
Learning: In the EmuFlight repository (emuflight/EmuFlight), the maintainer (nerdCopter) does not want follow-up GitHub issues created for GitHub Actions SHA pinning or cache key hardening suggestions. The preference is mutable version tags (e.g., v4, v5) and no issue tracking for this topic.

Learnt from: nerdCopter
Repo: emuflight/EmuFlight PR: 1099
File: .github/workflows/test.yml:21-38
Timestamp: 2026-03-26T14:11:55.128Z
Learning: In the EmuFlight repository (emuflight/EmuFlight), the maintainer prefers using mutable version tags (e.g., v4, v5) for GitHub Actions rather than pinning to full 40-character commit SHAs. Do not flag unpinned action versions as issues in this repository.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +193 to +194
extDevice_t max7456BusDevice;
extDevice_t *dev = &max7456BusDevice;
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify no other TU exports or externs a global `dev` that would collide / cross-link.
rg -nP --type=c --type=cpp --type=h '^\s*(extern\s+)?(const\s+)?\w[\w\s\*]*\bdev\s*(=|;)' -g '!**/nbd7456.c'
# Also list all non-static file-scope `dev` pointer/struct globals across drivers.
rg -nP -C1 '^\s*extDevice_t\s*\*?\s*dev\b'

Repository: emuflight/EmuFlight

Length of output: 9966


Make file-scope dev (and max7456BusDevice) static to avoid external-linkage collisions.

Both symbols are declared at file scope without static, so they have external linkage. Renaming busdevdev is safe within this translation unit, but a global named dev is a linker-collision hazard — any other TU that later introduces a global dev will fail to link or cross-link silently through an extern declaration. These are only used inside nbd7456.c, so internal linkage is the correct scope. The same issue exists identically in src/main/drivers/max7456.c at the same lines.

♻️ Proposed fix
-extDevice_t max7456BusDevice;
-extDevice_t *dev = &max7456BusDevice;
+static extDevice_t max7456BusDevice;
+static extDevice_t *dev = &max7456BusDevice;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
extDevice_t max7456BusDevice;
extDevice_t *dev = &max7456BusDevice;
static extDevice_t max7456BusDevice;
static extDevice_t *dev = &max7456BusDevice;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/drivers/nbd7456.c` around lines 193 - 194, The file-scope variables
max7456BusDevice and dev currently have external linkage and should be made
internal to avoid linker collisions; change the declarations of max7456BusDevice
and the pointer dev in nbd7456.c (and the identical pair in max7456.c) to use
static (i.e., make max7456BusDevice static and dev static pointing at
&max7456BusDevice) so both symbols have internal linkage and cannot collide
across translation units.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai, this is a refactor-only PR. This seems to be a pre-existing issue.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nerdCopter, you're right — looking at the diff, the original code already had busDevice_t max7456BusDevice; and busDevice_t *busdev = &max7456BusDevice; without static before this PR. This refactor only renamed the type and identifier; the external-linkage concern predates these changes.

Would you like me to open a follow-up issue to track adding static to these globals in both nbd7456.c and max7456.c as a separate cleanup task?


🧠 Learnings used
Learnt from: nerdCopter
Repo: emuflight/EmuFlight PR: 0
File: :0-0
Timestamp: 2026-04-04T21:55:50.478Z
Learning: In the EmuFlight project (GitHub: emuflight/EmuFlight), issue `#1106` involves CLI AutoComplete stalls on HELIOSPRING/STRIXF10/MODE2FLUX boards caused by USB VCP write starvation under EXTI preemption. The proposed fix (disabling EXTI via `EXTIEnable()` in `cliEnter()` and re-enabling in `cliExit()`/`cliRebootEx()`) was initially rejected due to apparent "permanent gyro corruption requiring reflash." However, this regression was later identified as a pre-existing configurator CLI/MSP reconnect bug present in the EmuFlight configurator NWjs master branch (not just an Electron/Forge migration bug). The configurator fails to properly re-establish MSP polling after CLI exits; a reflash incidentally forces USB re-enumeration which triggers a clean reconnect, masking the real cause. The EXTI fix itself is logically sound and should be re-evaluated using firmware-independent gyro verification (raw MSP tool) rather than the buggy configurator.

Copy link
Copy Markdown
Member Author

@nerdCopter nerdCopter Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nerdCopter, thanks for opening #1112 to track the static linkage cleanup for max7456BusDevice / dev in both nbd7456.c and max7456.c. That keeps this refactor PR focused and defers the pre-existing concern to the right place.


🧠 Learnings used
Learnt from: nerdCopter
Repo: emuflight/EmuFlight PR: 0
File: :0-0
Timestamp: 2026-04-04T21:55:50.478Z
Learning: In the EmuFlight project (GitHub: emuflight/EmuFlight), issue `#1106` involves CLI AutoComplete stalls on HELIOSPRING/STRIXF10/MODE2FLUX boards caused by USB VCP write starvation under EXTI preemption. The proposed fix (disabling EXTI via `EXTIEnable()` in `cliEnter()` and re-enabling in `cliExit()`/`cliRebootEx()`) was initially rejected due to apparent "permanent gyro corruption requiring reflash." However, this regression was later identified as a pre-existing configurator CLI/MSP reconnect bug present in the EmuFlight configurator NWjs master branch (not just an Electron/Forge migration bug). The configurator fails to properly re-establish MSP polling after CLI exits; a reflash incidentally forces USB re-enumeration which triggers a clean reconnect, masking the real cause. The EXTI fix itself is logically sound and should be re-evaluated using firmware-independent gyro verification (raw MSP tool) rather than the buggy configurator.

Learnt from: nerdCopter
Repo: emuflight/EmuFlight PR: 0
File: :0-0
Timestamp: 2026-03-26T16:06:21.396Z
Learning: In the EmuFlight repository (emuflight/EmuFlight), the maintainer (nerdCopter) does not want follow-up GitHub issues created for GitHub Actions SHA pinning or cache key hardening suggestions. The preference is mutable version tags (e.g., v4, v5) and no issue tracking for this topic.

Learnt from: nerdCopter
Repo: emuflight/EmuFlight PR: 1099
File: .github/workflows/test.yml:21-38
Timestamp: 2026-03-26T14:11:55.128Z
Learning: In the EmuFlight repository (emuflight/EmuFlight), the maintainer prefers using mutable version tags (e.g., v4, v5) for GitHub Actions rather than pinning to full 40-character commit SHAs. Do not flag unpinned action versions as issues in this repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant