Skip to content

Day 26 - Sensor Core Refactor

๐Ÿ“… Date

2026-04-XX


๐ŸŽฏ Goal

Refactor I2C sensor driver into:

  • Core + Bus architecture
  • Transport-independent design

๐Ÿ”ง What I Did

  • Introduced mysensor_bus_ops
  • Abstracted hardware access
  • Created mysensor_core.c
  • Created mysensor_i2c.c
  • Updated Makefile to multi-object module

๐Ÿงช Test Result

Driver probe

mysensor i2c probe start
mysensor_core probe start
IRQ registered
mysensor_core probed

Stress Test Summary

IRQ mode

  • irq_event_count = stable
  • no skips

Polling mode

  • poll_event_count matches expected
  • periodic update working

Hybrid mode

  • both IRQ and poll active
  • skip logic observed

Cooldown test

  • poll_skip_count increases significantly
  • confirms cooldown works

๐Ÿง  What I Learned

  • Separation of core vs transport is critical
  • bus_ops enables clean abstraction
  • IRQ + Polling interaction needs careful policy design
  • Cooldown is essential to avoid excessive updates

โš ๏ธ Issues Encountered

  • container_of type mismatch
  • header / struct inconsistency
  • register naming inconsistency

โœ… Fixes

  • unified struct mysensor_core
  • corrected container_of usage
  • standardized register naming

๐Ÿš€ Next Step

  • Add SPI support (mysensor_spi.c)
  • Verify core reusability