Revision code parsing for board detection#682
Merged
FDelporte merged 6 commits intoJun 30, 2026
Conversation
Introduce RevisionCode, a parser for the Raspberry Pi 32-bit revision code format (NOQuuuWuFMMMCCCCPPPPTTTTTTTTRRRR). Both new-style codes (identified by bit 23) and old-style codes are supported. New-style codes are decoded by extracting structured bit fields for memory size, processor, and board type. Old-style codes are matched against known revision code tables. Update BoardModel.getByBoardCode() to attempt structured identification via RevisionCode before falling back to legacy string matching. Add BoardModel.getByRevisionCode(RevisionCode) which switches on the decoded board type and, where necessary, disambiguates on PCB revision or memory size. This aligns board identification with the Raspberry Pi foundation's recommended best practices for revision code usage, ensuring that new board revisions of existing types are identified correctly without requiring a code change. - Add RevisionCode with nested MemorySize, Processor, and Type enums - Add RevisionCodeTest with full coverage of new-style and old-style parsing, field extraction, string input handling, and edge cases - Update BoardModel.getByBoardCode() to delegate to RevisionCode - Add BoardModel.getByRevisionCode(RevisionCode) - Add BoardModelTest cases for getByRevisionCode()
Contributor
Author
|
Working on fixing the cognitive complexity/duplication called out by sonar. |
- extracting a common interface, RevisionCodeEnum`, for internal enumerations of RevisionCode - creating a new fromNewStyleCode() method that generically returns an enum constant whose bit field value matches the extracted field of a new-style revision code based on a given shift and mask - creating a new fromOldStyleCode() method that generically returns an enum constant whose old-style revision code list contains the given revision code
…detection' into revision-code-parsing-for-board-detection
Contributor
Author
I think I've got that fixed. Slight refactor on RevisionCode. |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds structured parsing of Raspberry Pi 32-bit revision codes and uses the decoded fields to improve BoardModel detection, reducing reliance on hardcoded legacy string matching.
Changes:
- Introduces
RevisionCodewith enums to decode new-style and old-style revision codes. - Adds
BoardModel.getByRevisionCode(RevisionCode)and updatesgetByBoardCode()to prefer structured decoding before legacy lookup. - Adds/extends unit tests for revision-code parsing and board-model resolution.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| pi4j-core/src/main/java/com/pi4j/boardinfo/definition/RevisionCode.java | New revision-code parser and field decoders (memory/processor/type/revision). |
| pi4j-core/src/main/java/com/pi4j/boardinfo/definition/BoardModel.java | Adds structured RevisionCode-based board detection and integrates it into getByBoardCode(). |
| pi4j-core/src/test/java/com/pi4j/boardinfo/definition/RevisionCodeTest.java | New tests covering parsing, field extraction, and edge cases. |
| pi4j-core/src/test/java/com/pi4j/boardinfo/definition/BoardModelTest.java | Adds test cases for BoardModel.getByRevisionCode(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Refactor RevisionCode.of(String) to do more initial checking on the given String. - Update MemorySize.getOldStyleRevisionCodes(), Type.getOldStyleRevisionCodes(), and Processor.getOldStyleRevisionCodes() methods to return a copy of the internal array of each respective enum rather than a reference to the internal array itself. - Fix formatting in BoardModel.getByBoardCode(). - Update RevisionCodeTest to more thoroughly test the RevisionCode class, especially around input validation for the of() method. Also added a test for the equals(), hashCode(), and toString() methods.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Introduce RevisionCode, a parser for the Raspberry Pi 32-bit revision
code format (NOQuuuWuFMMMCCCCPPPPTTTTTTTTRRRR). Both new-style codes
(identified by bit 23) and old-style codes are supported. New-style
codes are decoded by extracting structured bit fields for memory size,
processor, and board type. Old-style codes are matched against known
revision code tables.
Update
BoardModel.getByBoardCode()to attempt structured identificationvia
RevisionCodebefore falling back to legacy string matching. AddBoardModel.getByRevisionCode(RevisionCode)which switches on the decodedboard type and, where necessary, disambiguates on PCB revision or memory
size.
This aligns board identification with the Raspberry Pi foundation's
recommended best practices for revision code usage, ensuring that new
board revisions of existing types are identified correctly without
requiring a code change.
RevisionCodewith nestedMemorySize,Processor, andTypeenumsRevisionCodeTestwith full coverage of new-style and old-styleparsing, field extraction, string input handling, and edge cases
BoardModel.getByRevisionCode(RevisionCode)BoardModelTestcases forgetByRevisionCode()BoardModel.getByBoardCode()to delegate toRevisionCodeandBoardModel.getByRevisionCode()See discussion here: #679