Skip to content

refactor: Split daplink_flash into daplink_bridge + daplink_flash layers. #256

@nedseb

Description

@nedseb

Description

The current daplink_flash module mixes low-level bridge communication (I2C, status, error, config zone) with high-level flash file operations (read, write, filename). This makes it harder to extend and creates a tight coupling between flash operations and bridge management.

Proposed architecture

steami_config  ─┐
                ├──→  daplink_bridge  ──→  I2C (F103)
daplink_flash  ─┘

daplink_bridge (new — low-level bridge communication)

Handles all direct I2C communication with the STM32F103 DAPLink interface:

  • device_id() — WHO_AM_I register
  • _status() / _error() / busy() — status and error registers
  • _wait_busy() — busy polling
  • _read_reg() / _write_reg() — raw register access
  • read_config() / write_config() / clear_config() — config zone operations

daplink_flash (refactored — high-level flash file operations)

Uses daplink_bridge for I2C access, focuses on file operations:

  • set_filename() / get_filename() — 8.3 filename management
  • clear_flash() — erase file data
  • write() / write_line() — append data to file
  • read() / read_sector() — read file data

steami_config (unchanged — uses bridge directly)

Already uses only config zone operations. Will import from daplink_bridge instead of daplink_flash.

Migration

# Before
from daplink_flash import DaplinkFlash
flash = DaplinkFlash(i2c)
flash.device_id()
flash.write_line("data")
flash.write_config(json_data)

# After
from daplink_bridge import DaplinkBridge
from daplink_flash import DaplinkFlash

bridge = DaplinkBridge(i2c)
flash = DaplinkFlash(bridge)        # takes bridge, not i2c
config = SteamiConfig(bridge)       # takes bridge, not flash

bridge.device_id()
flash.write_line("data")
bridge.write_config(json_data)

Tasks

  • Create lib/daplink_bridge/ module with low-level bridge class
  • Refactor daplink_flash to use DaplinkBridge internally
  • Update steami_config to take a DaplinkBridge instead of DaplinkFlash
  • Update all examples (show_config, calibrate_temperature, calibrate_magnetometer, etc.)
  • Update tests (mock scenarios + hardware scenarios)
  • Update READMEs
  • Add daplink_bridge to firmware manifest.py

Impact

  • Breaking change for steami_config constructor (takes bridge instead of flash)
  • daplink_flash constructor changes (takes bridge instead of i2c)
  • All examples need updating
  • No firmware change needed (same I2C protocol)

Related

Metadata

Metadata

Assignees

Labels

refactorNettoyage/harmonisation sans changement fonctionnelreleased

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions