Skip to content

refactor: split header-only drivers into source + header files#2368

Open
xunwen-art wants to merge 10 commits intocommaai:masterfrom
xunwen-art:master
Open

refactor: split header-only drivers into source + header files#2368
xunwen-art wants to merge 10 commits intocommaai:masterfrom
xunwen-art:master

Conversation

@xunwen-art
Copy link

Summary

Refactor all header-only driver files into separate source (.c) and header (.h) files.

Changes

Split 17 driver files:

  • bootkick, can_common, clock_source, fake_siren, fan, fdcan
  • gpio, harness, interrupts, led, pwm, registers
  • simple_watchdog, spi, timers, uart, usb

Benefits

  • Cleaner code organization
  • Easier to add new drivers
  • Better separation of interface and implementation
  • Reduced compilation dependencies

Testing

  • Minimal changes to function signatures
  • All function implementations preserved
  • Header files now contain only declarations and #define

Fixes #2171

xunwen-art added 5 commits March 5, 2026 01:36
Split all header-only driver files into separate .c and .h files:
- bootkick, can_common, clock_source, fake_siren, fan, fdcan
- gpio, harness, interrupts, led, pwm, registers
- simple_watchdog, spi, timers, uart, usb

Changes:
- Move function implementations to .c files
- Keep function declarations and #define in .h files
- Add proper include guards to all header files
- Add necessary #include directives

Addresses commaai#2171
- Move fan_state_t struct and extern fan_state to fan.h
- Move REGISTER_INTERRUPT macro and interrupt struct to interrupts.h
- This fixes compilation errors where llfan.h and llusb.h
  couldn't find these definitions
- Move REGISTER_INTERRUPT macro to interrupts.h
- Add extern declarations for uart_ring buffers in uart.h
- Remove duplicate interrupt definitions from drivers.h
…larations

- Add driver_sources list to SConscript for both bootstub and main builds
- Add harness_t struct and extern harness to harness.h
- Add SPI_IRQ_RATE, SPI_BUF_SIZE and extern declarations to spi.h
@xunwen-art
Copy link
Author

这个重构比预期更复杂,需要更多时间来修复构建系统问题。原始代码使用 header-only 模式,所有 driver 代码在编译时通过 bootstub.c 或 main.c 直接 include。改为 source + header 模式需要修改 SConscript 来正确编译 .c 文件,并处理 scons 的对象文件命名冲突。

我会继续研究这个问题,并在准备好后重新提交。

@xunwen-art xunwen-art closed this Mar 5, 2026
@xunwen-art xunwen-art reopened this Mar 5, 2026
xunwen-art added 5 commits March 5, 2026 15:33
SCons was complaining about 'Two environments with different actions'
because bootstub and main both compile driver sources with different
flags (-DBOOTSTUB vs no flag). Now bootstub uses a separate output
directory for its driver object files.
Now these headers include drivers.h which contains the struct definitions
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.

[$500 Bounty] Refactor panda to use source + header file structure

1 participant