Skip to content

Dev#1

Merged
ZR233 merged 9 commits intomainfrom
dev
Nov 2, 2025
Merged

Dev#1
ZR233 merged 9 commits intomainfrom
dev

Conversation

@ZR233
Copy link
Member

@ZR233 ZR233 commented Nov 2, 2025

变更描述

简洁明了地描述这个 PR 的变更内容。

变更类型

请选择适用的选项:
This pull request introduces significant refactoring and feature enhancements to the serial driver crate, focusing on improved architecture for UART interfaces, streamlined trait usage, and better support for multiple platforms. The changes modernize the codebase by introducing enum-based dispatch for sender/receiver traits, revising the PL011 and NS16550 UART implementations, and updating configuration and test logic to work with these new abstractions.

Architecture and Trait Refactoring

  • Introduced Sender and Reciever enums with enum_dispatch to unify and abstract over different UART implementations, and replaced previous trait implementations with new RawSender and RawReciever traits for more flexible and type-safe serial communication. (src/lib.rs, src/lib.rsR63-R142)
  • Refactored PL011 UART implementation to use new sender/receiver abstractions, added boxed constructor methods, and split out interrupt handler logic; replaced the previous Register trait implementation with the new InterfaceRaw trait. (src/pl011.rs, [1] [2] [3] [4] [5]

NS16550 UART Improvements

  • Changed MMIO and PIO implementations to use new trait signatures and constructors, supporting register width configuration and boxed interface creation, and removed legacy methods. (src/ns16550/mmio.rs, [1]; src/ns16550/pio.rs, [2] [3]

Platform and Dependency Updates

  • Updated target architecture in .vscode/settings.json and .cargo/config.toml to aarch64-unknown-none-softfloat for better cross-platform support; revised dependencies in Cargo.toml to use newer versions and added enum_dispatch. (.vscode/settings.json, [1]; .cargo/config.toml, [2]; Cargo.toml, [3]

Test Suite Modernization

  • Updated test logic to use new sender/receiver trait methods (write_bytes, read_bytes), replaced legacy methods, and added a utility to clean receive buffers for compatibility with the new interface. (tests/test.rs, [1] [2] [3] [4] [5] [6] [7] [8]

Minor Cleanups

These changes collectively modernize the codebase, improve maintainability, and provide a more robust and flexible foundation for embedded serial communication across different platforms.

  • Bug 修复
  • 新功能
  • 代码重构
  • 文档更新
  • 性能优化
  • 测试改进
  • 其他

测试

描述你如何测试了这些变更:

  • 单元测试通过
  • 集成测试通过
  • 手动测试完成
  • 添加了新的测试用例

检查清单

请确认以下项目:

  • 代码遵循项目的代码风格
  • 添加了必要的文档
  • 更新了 CHANGELOG.md(如果适用)
  • 所有测试都通过
  • 没有引入新的警告
  • 理解了这些变更的影响

相关 Issue

如果这个 PR 解决了某个 issue,请在这里引用:

Closes #

附加信息

在这里添加任何其他审查者需要知道的信息。

ZR233 added 5 commits November 2, 2025 14:04
- Updated version in Cargo.toml from 0.2.4 to 0.3.0.
- Changed rdif-serial dependency to a local path.
- Refactored `write_reg` method in `Kind` trait and its implementations to take `&self` instead of `&mut self`.
- Updated `Ns16550` struct to include IRQ, TX, and RX handlers.
- Implemented `InterfaceRaw` for `Ns16550` to manage IRQ and data transmission.
- Added `Pl011Sender`, `Pl011Reciever`, and `Pl011IrqHandler` structs with appropriate methods for handling UART operations.
- Removed unused methods and cleaned up code for better readability and maintainability.
…terface

- Add configurable register width parameter to MMIO interface
- Add boxed constructors for dynamic trait object creation
- Refactor receiver interface to return Option<Result> instead of Result<Option>
- Improve error handling consistency across UART implementations
- Fix overrun error handling in bulk read operations
@ZR233 ZR233 requested a review from Copilot November 2, 2025 11:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the serial driver interface to version 0.3.0, migrating from the old rdif-serial v0.5.4 to v0.6.0 API. The major changes include:

  • Redesigned the interface to split serial port into separate Sender, Receiver, and IrqHandler components
  • Introduced enum_dispatch for efficient trait dispatch across different driver types
  • Updated method names for consistency (write_bytes, read_bytes, base_addr)
  • Removed deprecated methods and simplified the API surface

Reviewed Changes

Copilot reviewed 10 out of 12 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/test.rs Updated test code to use new API methods, added clean_rx helper function, removed unused helper functions
src/pl011.rs Refactored PL011 driver to implement new interface with split sender/receiver pattern
src/ns16550/mod.rs Major restructuring to implement new InterfaceRaw trait and split components
src/ns16550/mmio.rs Updated MMIO interface to support configurable register width and new factory methods
src/ns16550/pio.rs Updated port-based interface methods and signatures
src/ns16550/registers.rs Removed outdated comment
src/lib.rs Added enum_dispatch based Sender/Receiver enums with unified traits
Cargo.toml Version bump to 0.3.0, updated dependencies

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

let mut bytes = b"TX mask test".as_slice();
while !bytes.is_empty() {
let n = tx.send(bytes).unwrap();
let n = tx.write_bytes(bytes);
Copy link

Copilot AI Nov 2, 2025

Choose a reason for hiding this comment

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

The return value of write_bytes is not checked. If n is 0 (transmission failed), this will result in an infinite loop. Consider adding a check: if n == 0 { panic!(\"Failed to write bytes\"); }.

Suggested change
let n = tx.write_bytes(bytes);
let n = tx.write_bytes(bytes);
if n == 0 {
panic!("Failed to write bytes");
}

Copilot uses AI. Check for mistakes.

while !bytes.is_empty() {
let n = tx.send(bytes).unwrap();
let n = tx.write_bytes(bytes);
Copy link

Copilot AI Nov 2, 2025

Choose a reason for hiding this comment

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

Same issue as line 167: the return value is not checked for zero, which could cause an infinite loop if transmission fails.

Suggested change
let n = tx.write_bytes(bytes);
let n = tx.write_bytes(bytes);
if n == 0 {
info!("Error: tx.write_bytes returned 0, transmission may have failed. Breaking out of loop to avoid infinite loop.");
break;
}

Copilot uses AI. Check for mistakes.
ZR233 and others added 4 commits November 2, 2025 19:50
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@ZR233 ZR233 merged commit f4d0b69 into main Nov 2, 2025
4 checks passed
@ZR233 ZR233 deleted the dev branch November 2, 2025 11:57
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.

2 participants