Skip to content

Add ICP-201xx barometer driver - #12249

Open
Target0815 wants to merge 2 commits into
iNavFlight:maintenance-10.xfrom
Target0815:feature/baro-icp201xx
Open

Target0815 wants to merge 2 commits into
iNavFlight:maintenance-10.xfrom
Target0815:feature/baro-icp201xx

Conversation

@Target0815

Copy link
Copy Markdown
Contributor

Summary

Driver for the TDK InvenSense ICP-201xx barometer (ICP-20100), ported from the ArduPilot driver (AP_Baro_ICP201XX).

  • I2C, address configurable per target (default 0x63)
  • runs the A1-silicon OTP boot sequence when needed
  • continuous mode (operation mode 1: 120 Hz ODR, 30 Hz bandwidth), FIFO read out at ~60 Hz and averaged
  • timeouts on all wait loops

Enabled per target with USE_BARO_ICP201XX (optionally ICP201XX_I2C_BUS and ICP201XX_I2C_ADDR).
New baro_hardware value ICP201XX, appended at the end of the list so existing values are unchanged.

Why

The ICP-20100 is used on the SIYI UniFC 6 PICO (#12248). The driver is submitted separately so the target PR only contains the board definition.

Testing

  • Tested on a SIYI UniFC 6 PICO (onboard ICP-20100 on I2C3): detection, pressure and temperature plausible, altitude stable on the bench and while driving.
  • No existing target enables the driver yet, so CI does not compile it. I build-tested it by temporarily enabling it on MATEKH743 (no warnings).
  • The target for the UniFC 6 PICO will follow in a separate PR.

The Configurator dropdown for baro_hardware will need the new ICP201XX entry; I can open a Configurator PR for that.

Driver for the TDK InvenSense ICP-201xx (ICP-20100) barometer, ported
from the ArduPilot driver (AP_Baro_ICP201XX).

- I2C, address configurable per target (default 0x63)
- runs the A1-silicon OTP boot sequence when needed
- continuous mode (operation mode 1: 120 Hz ODR, 30 Hz bandwidth),
  FIFO read out at ~60 Hz and averaged
- timeouts on all wait loops

Enabled per target with USE_BARO_ICP201XX (optionally ICP201XX_I2C_BUS
and ICP201XX_I2C_ADDR). New baro_hardware value: ICP201XX.

Tested on a SIYI UniFC 6 PICO (onboard ICP-20100 on I2C3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PRdGUnvzUZYkaXNehajWs8
@qodo-code-review

Copy link
Copy Markdown
Contributor

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Add ICP-201xx I2C barometer driver

✨ Enhancement 📝 Documentation ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

AI Description

• Add ICP-201xx detection, silicon-specific initialization, and FIFO-averaged pressure and
 temperature readings.
• Expose the sensor through target I2C configuration and the existing barometer selection setting.
• Document the new setting; board enablement will follow in a separate PR.
Merge Risk 🟡 Medium

Blast radius 🟡 Medium 💥 2 capabilities

  • 2 affected capabilities within one bounded functional scope: barometric sensing integration.
  • The changed driver supplies the common barometer pressure/temperature state, which the barometer pipeline converts to altitude and the navigation estimator consumes.
  • This is one bounded barometric sensing integration across driver, sensor pipeline, and estimator rather than separate technical-layer capabilities.
  • Telemetry consumes the same barometer state produced by the new driver, but its distinct end-to-end outcome is transmission of pressure/altitude values to an external telemetry consumer.
  • It remains in the same bounded barometric sensing integration as altitude estimation.
Behavioral complexity 🟡 Medium 🧩 Multiple interactions

  • The change is not merely a direct mapping.
  • Before, the selected barometer used an existing driver; after, this driver introduces FIFO packet accumulation, sign extension, averaging, pressure/temperature scaling, timed FIFO settling, retry loops, and separate A1/B2 boot behavior with OTP/register writes.
  • Before: no ICP201xx-specific state or silicon-version transition existed in this path.
  • After: detection must accept only the supported ID/version, A1 must complete the OTP/trim sequence while B2 skips it, the FIFO must be settled and flushed, and later reads must yield correctly ordered six-byte pressure/temperature packets.
  • New correctness condition: all these states and ordering constraints must agree so that only valid samples are published to the common barometer pipeline; a timeout or failed read must not be mistaken for a valid update.
  • The conversion is also a nontrivial bit-level transformation because signed 20-bit fields are reconstructed, averaged, and scaled into physical units.
  • The existing barometer scheduler and consumers are reused infrastructure; their existence is not counted as new complexity.
Potential damage 🟡 Medium 🩹 Incorrect results

  • A wrong pressure conversion or stale accepted sample changes baroCalculateAltitude and therefore the altitude/rate topic used by the navigation estimator.
  • Reverting the firmware restores the prior driver, but it cannot undo an incorrect altitude estimate already used during operation; no persistent state corruption or external financial effect is shown.
  • Usually recoverable by selecting a known-good barometer, rebooting/reconfiguring, and recalibrating the barometric reference after the faulty sensor path is removed.
  • During activation, flight-control behavior can remain incorrect until valid readings and calibration are restored.
Assessed commit 5722af6
Diagram

graph TD
  Config["Target I2C config"] --> Detect["Sensor detection"] --> Version{"Silicon version"}
  Version -->|A1| Boot["OTP trim boot"] --> Mode["Continuous mode"] --> FIFO["FIFO averaging"] --> Task["Barometer task"]
  Version -->|B2| Mode
Loading
High-Level Assessment

A driver using INAV’s existing bus registration, detection, and barometer callbacks is the best fit. Bringing in a standalone vendor driver would require additional integration without a clear benefit for this single sensor; the remaining priority is build and behavioral coverage when a target enables it.

Files changed (9) +471 / -2

Enhancement (5) +457 / -1
barometer_icp201xx.cImplement ICP-201xx detection and measurement +420/-0

Implement ICP-201xx detection and measurement

• Detects supported silicon, performs the A1 OTP trim boot sequence when required, and starts continuous sampling. Reads and averages FIFO packets, converts them to pressure and temperature, and exposes results through barometer callbacks with bounded initialization waits.

src/main/drivers/barometer/barometer_icp201xx.c

barometer_icp201xx.hDeclare ICP-201xx detection entry point +20/-0

Declare ICP-201xx detection entry point

• Declares the detector used by the barometer sensor layer.

src/main/drivers/barometer/barometer_icp201xx.h

bus.hAssign ICP-201xx bus device identifier +1/-0

Assign ICP-201xx bus device identifier

• Adds a hardware identifier for registering and locating the ICP-201xx bus device.

src/main/drivers/bus.h

barometer.cIntegrate ICP-201xx into barometer detection +14/-0

Integrate ICP-201xx into barometer detection

• Adds conditional ICP-201xx detection to the existing selection and autodetection chain.

src/main/sensors/barometer.c

barometer.hAdd ICP-201xx barometer enum value +2/-1

Add ICP-201xx barometer enum value

• Appends BARO_ICP201XX as value 14 and updates BARO_MAX without renumbering existing sensors.

src/main/sensors/barometer.h

Documentation (1) +1 / -0
Settings.mdDocument ICP201XX barometer selection +1/-0

Document ICP201XX barometer selection

• Adds ICP201XX to the documented baro_hardware choices.

docs/Settings.md

Other (3) +13 / -1
CMakeLists.txtInclude ICP-201xx driver sources +2/-0

Include ICP-201xx driver sources

• Adds the new driver source and header to the main source list.

src/main/CMakeLists.txt

settings.yamlExpose ICP201XX in baro_hardware +1/-1

Expose ICP201XX in baro_hardware

• Appends ICP201XX to the setting’s value list, preserving existing barometer setting values.

src/main/fc/settings.yaml

common_hardware.cRegister configurable ICP-201xx I2C device +10/-0

Register configurable ICP-201xx I2C device

• Registers the device when USE_BARO_ICP201XX is enabled, using BARO_I2C_BUS by default and allowing a target-specific bus and address.

src/main/target/common_hardware.c

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. A1 sensors can use incorrect calibration ✓ Resolved

Resolving commit: 5722af6

Resolution reason
Setup-step return values (modeSelect, writeReg, updateBits for OTP enable/reset and redundant-read
programming) are now checked; subsequent OTP trim reads are gated on success, and bootSequence
returns false if any step failed.
Description
bootSequence() ignores failures while enabling OTP access and programming its redundant-read
registers, so those failures do not affect ok. If a setup transaction fails but the later OTP
reads succeed, the driver can copy values read under incomplete configuration into the trim
registers and mark initialization complete.


Remediation recommended

2. A1 startup can leave OTP access enabled ✓ Resolved

Resolving commit: 5722af6

Resolution reason
Cleanup transactions (OTP disable, master lock, return to standby) now have their results captured
and included in the boot sequence's return value, so a failed cleanup is reported as failure instead
of success. All three are still attempted even if one fails.
Description
bootSequence() discards the results of disabling OTP access, locking the registers, and returning
to standby, then returns the earlier ok value. If one of those cleanup transactions fails after
the trim copy succeeds, deviceConfigure() proceeds as though the A1 startup sequence finished.

3. Failed reads leave altitude data stale ✓ Resolved

Resolving commit: 5722af6

Resolution reason
Detection now performs an initial measurement read (deviceReadMeasurement) after clearing icpState
and aborts detection (busDeviceDeInit, return false) if it fails, so no zero-initialized
pressure/temperature is published. Also checks flushFifo result and propagates OTP/bootSequence
failures.
Description
deviceReadMeasurement() returns false for an empty FIFO, an overfull FIFO, or a failed burst read
without invalidating icpState, while deviceCalculate() always copies that state. Because
baroUpdate() ignores the read result, those failures republish the previous pressure and
temperature; a failure before the first successful read publishes the zero-initialized values.

4. Unsettled samples can pass startup ✓ Resolved

Resolving commit: 5722af6

Resolution reason
deviceConfigure() now checks the return value of flushFifo() and returns false on failure, so the
subsequent waitFifo(busDev, 1, 100) only runs after a successful flush; settling samples can no
longer pass startup.
Description
deviceConfigure() ignores the result of the FIFO flush after waiting for the FIR filter to settle.
If that flush fails, the already-filled FIFO can satisfy the following one-packet wait immediately,
allowing detection to succeed without discarding the settling samples.

Grey Divider

Tip of the day
💡 Did you know, you can keep summaries lean with Findings visible per group, which tucks the rest behind a View link

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

- A1 boot sequence: OTP setup writes are checked before the trim
  values are read; the cleanup (OTP off, lock, standby) is always
  attempted and its result is part of the return value
- fail configuration if the FIFO flush after FIR settling fails
- read the first measurement during detection, so no uninitialised
  value is ever published

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PRdGUnvzUZYkaXNehajWs8
@Target0815

Copy link
Copy Markdown
Contributor Author

Thanks – fixed in 5722af6:
1./2./4. All bus transactions in the A1 boot sequence and the FIFO flush after FIR settling are now checked; the OTP cleanup is always attempted and included in the result.
3. The first measurement is now read during detection, so no uninitialised value can be published. Keeping the last valid sample when a FIFO read fails is the same behaviour as the other baro drivers (e.g. DPS310), so I left the shared barometer.c unchanged.

Re-tested on the UniFC 6 PICO.

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