Skip to content

Make it possible to force a specific board model + improvements in setting usesRP1 #453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/pi4j-library-gpiod/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-library</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<relativePath>../pi4j-library/pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion libraries/pi4j-library-linuxfs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<artifactId>pi4j-library</artifactId>
<groupId>com.pi4j</groupId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<relativePath>../pi4j-library/pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion libraries/pi4j-library-pigpio/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<artifactId>pi4j-library</artifactId>
<groupId>com.pi4j</groupId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<relativePath>../pi4j-library/pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion libraries/pi4j-library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>pi4j-parent</artifactId>
<groupId>com.pi4j</groupId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion pi4j-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-parent</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public enum BoardModel {
Cpu.ARM1176JZF_S, 1,
List.of(700),
List.of(256 * 1024, 512 * 1024),
List.of("Amount of memory changed to 512Mb on 20160810")),
List.of("Amount of memory changed to 512Mb on 20160810"),
false),
MODEL_3_A_PLUS("Raspberry Pi 3 Model A+", SINGLE_BOARD_COMPUTER,
List.of("9020e0", "9020e1"),
PiModel.MODEL_A,
Expand All @@ -75,7 +76,9 @@ public enum BoardModel {
Soc.BCM2837B0,
Cpu.CORTEX_A53, 4,
List.of(1400),
List.of(512 * 1024)),
List.of(512 * 1024),
new ArrayList<>(),
false),
MODEL_1_B("Raspberry Pi 1 Model B", SINGLE_BOARD_COMPUTER,
List.of("0002", "0003", "0004", "0005", "0006", "000d", "000e", "000f"),
PiModel.MODEL_B,
Expand All @@ -85,7 +88,8 @@ public enum BoardModel {
Cpu.ARM1176JZF_S, 1,
List.of(700),
List.of(256 * 1024, 512 * 1024),
List.of("Amount of memory changed to 512Mb on 20121015")),
List.of("Amount of memory changed to 512Mb on 20121015"),
false),
MODEL_1_B_PLUS("Raspberry Pi 1 Model B+", SINGLE_BOARD_COMPUTER,
List.of("0010", "0013", "900032"),
PiModel.MODEL_B,
Expand Down Expand Up @@ -157,7 +161,9 @@ public enum BoardModel {
Soc.BCM2712,
Cpu.CORTEX_A76, 4,
List.of(2400),
List.of(2048 * 1024, 4096 * 1024, 8192 * 1024, 16384 * 1024)),
List.of(2048 * 1024, 4096 * 1024, 8192 * 1024, 16384 * 1024),
new ArrayList<>(),
true),
MODEL_500("Raspberry Pi 500", ALL_IN_ONE_COMPUTER,
List.of("d04190"),
PiModel.MODEL_B,
Expand All @@ -169,7 +175,8 @@ public enum BoardModel {
List.of(8192 * 1024),
List.of(
"20241209: Confirmed by Jeff Geerling who has evaluation version: d04190."
)),
),
true),
COMPUTE_1("Compute Module 1", STACK_ON_COMPUTER,
List.of("0011", "0014", "900061"),
PiModel.COMPUTE,
Expand Down Expand Up @@ -231,7 +238,8 @@ public enum BoardModel {
"20241129: Confirmed by Jeff Geerling who has evaluation version: c04180 for the 4Gb version.",
"When compared with Compute 4, we can assume the other boards should have be a, b, d.",
"Will be further completed or modified when more info is available."
)),
),
true),
ZERO_PCB_1_2("Raspberry Pi Zero PCB V1.2", SINGLE_BOARD_COMPUTER,
List.of("900092", "920092"),
PiModel.ZERO,
Expand Down Expand Up @@ -286,7 +294,8 @@ public enum BoardModel {
Cpu.CORTEX_MO_PLUS, 1,
List.of(133),
List.of(264 + 2048),
List.of("Same form factor as PICO but with Wi-Fi")),
List.of("Same form factor as PICO but with Wi-Fi"),
false),
PICO_2("Raspberry Pi Pico 2", MICROCONTROLLER,
new ArrayList<>(),
PiModel.PICO,
Expand All @@ -305,6 +314,29 @@ public enum BoardModel {
Cpu.CORTEX_M33, 1,
List.of(150),
List.of(520 + 4096)),
// Generic model, this can be used to force the library
// to load Raspberry Pi plugins on other board types
GENERIC("Generic board compatible with Raspberry Pi 4", SINGLE_BOARD_COMPUTER,
new ArrayList<>(),
PiModel.MODEL_B,
HeaderVersion.TYPE_3,
LocalDate.now(),
Soc.UNKNOWN,
Cpu.UNKNOWN, 4,
new ArrayList<>(),
new ArrayList<>()),
GENERIC_RP1("Generic board compatible with Raspberry Pi 5", SINGLE_BOARD_COMPUTER,
new ArrayList<>(),
PiModel.MODEL_B,
HeaderVersion.TYPE_3,
LocalDate.now(),
Soc.UNKNOWN,
Cpu.UNKNOWN, 4,
new ArrayList<>(),
new ArrayList<>(),
new ArrayList<>(),
true),
// Unknown model
UNKNOWN("Unknown", BoardType.UNKNOWN,
new ArrayList<>(),
PiModel.UNKNOWN,
Expand All @@ -329,6 +361,7 @@ public enum BoardModel {
private final List<Integer> versionsProcessorSpeedInMhz;
private final List<Integer> versionsMemoryInKb;
private final List<String> remarks;
private final Boolean usesRP1;

/**
* Constructor for creating a {@code BoardModel} without remarks.
Expand All @@ -350,7 +383,7 @@ public enum BoardModel {
Soc soc, Cpu cpu, Integer numberOfCpu,
List<Integer> versionsProcessorSpeedInMhz, List<Integer> versionsMemoryInKb) {
this(label, boardType, boardCodes, model, headerVersion, releaseDate, soc, cpu, numberOfCpu,
versionsProcessorSpeedInMhz, versionsMemoryInKb, new ArrayList<>());
versionsProcessorSpeedInMhz, versionsMemoryInKb, new ArrayList<>(), false);
}

/**
Expand All @@ -368,12 +401,14 @@ public enum BoardModel {
* @param versionsProcessorSpeedInMhz list of processor speeds in MHz
* @param versionsMemoryInKb list of memory sizes in KB
* @param remarks any remarks or notes about the board
* @param usesRP1 board contains the RP1 chip to control GPIOs
*/
BoardModel(String label, BoardType boardType, List<String> boardCodes,
PiModel model, HeaderVersion headerVersion, LocalDate releaseDate,
Soc soc, Cpu cpu, Integer numberOfCpu,
List<Integer> versionsProcessorSpeedInMhz, List<Integer> versionsMemoryInKb,
List<String> remarks) {
List<String> remarks,
Boolean usesRP1) {
this.label = label;
this.boardType = boardType;
this.boardCodes = boardCodes;
Expand All @@ -386,6 +421,7 @@ public enum BoardModel {
this.versionsProcessorSpeedInMhz = versionsProcessorSpeedInMhz;
this.versionsMemoryInKb = versionsMemoryInKb;
this.remarks = remarks;
this.usesRP1 = usesRP1;
}

/**
Expand Down Expand Up @@ -540,4 +576,11 @@ public List<Float> getVersionsMemoryInGb() {
public List<String> getRemarks() {
return remarks;
}

/**
* @return board contains the RP1 chip to control GPIOs
*/
public boolean usesRP1() {
return usesRP1;
}
}
12 changes: 11 additions & 1 deletion pi4j-core/src/main/java/com/pi4j/boardinfo/model/BoardInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public class BoardInfo {

private final BoardModel boardModel;
private BoardModel boardModel;
private final OperatingSystem operatingSystem;
private final JavaInfo javaInfo;

Expand All @@ -51,6 +51,16 @@ public BoardInfo(BoardModel boardModel, OperatingSystem operatingSystem, JavaInf
this.javaInfo = javaInfo;
}

/**
* Sets the model of the board. To be used when the detected board is not correct,
* or to force a specific model e.g. on Orange Pi, or during testing.
*
* @param boardModel
*/
public void setBoardModel(BoardModel boardModel) {
this.boardModel = boardModel;
}

/**
* Gets the model of the board.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ private BoardInfoHelper() {
this.boardInfo = detectBoardInfo(os, java);
}

/**
* Sets the model of the board. To be used when the detected board is not correct,
* or to force a specific model e.g. on Orange Pi, or during testing.
*
* @param boardModel
*/
public void setBoardModel(BoardModel boardModel) {
this.boardInfo.setBoardModel(boardModel);
}

/**
* Returns the current instance of {@code BoardInfoHelper}, which contains board information.
*
Expand Down Expand Up @@ -163,9 +173,7 @@ private BoardInfo detectBoardInfo(OperatingSystem os, JavaInfo java) {
* @return {@code true} if the board is a Raspberry Pi Model 5B, otherwise {@code false}.
*/
public static boolean usesRP1() {
return current().getBoardModel() == BoardModel.MODEL_5_B
|| current().getBoardModel() == BoardModel.MODEL_500
|| current().getBoardModel() == BoardModel.COMPUTE_5;
return current().getBoardModel().usesRP1();
}

/**
Expand Down
38 changes: 35 additions & 3 deletions pi4j-core/src/test/java/com/pi4j/boardinfo/model/ModelTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.pi4j.boardinfo.model;

import com.pi4j.boardinfo.definition.BoardModel;
import com.pi4j.boardinfo.util.BoardInfoHelper;
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.*;

class ModelTest {

Expand Down Expand Up @@ -49,7 +50,6 @@ void testBoardReadingParsing() {
);
}


@Test
void testMemoryParsing() {
var memory = new JvmMemory(Runtime.getRuntime());
Expand All @@ -61,4 +61,36 @@ void testMemoryParsing() {
() -> assertEquals(memory.getTotal() / 1024.0 / 1024.0, memory.getTotalInMb(), "Total memory in MB")
);
}

@Test
void testRP1() {
assertAll(
() -> assertFalse(BoardModel.MODEL_1_B.usesRP1(), "MODEL_1_B"),
() -> assertTrue(BoardModel.MODEL_5_B.usesRP1(), "MODEL_5_B"),
() -> assertTrue(BoardModel.MODEL_500.usesRP1(), "MODEL_500"),
() -> assertTrue(BoardModel.COMPUTE_5.usesRP1(), "COMPUTE_5"),
() -> assertFalse(BoardModel.GENERIC.usesRP1(), "GENERIC"),
() -> assertTrue(BoardModel.GENERIC_RP1.usesRP1(), "GENERIC_RP1")
);
}

@Test
void testBoardModelOverwrite() {
var boardInfo = BoardInfoHelper.current();

boardInfo.setBoardModel(BoardModel.MODEL_500);
assertEquals(BoardModel.MODEL_500, boardInfo.getBoardModel());
assertTrue(BoardInfoHelper.runningOnRaspberryPi());
assertTrue(BoardInfoHelper.usesRP1());

boardInfo.setBoardModel(BoardModel.GENERIC);
assertEquals(BoardModel.GENERIC, boardInfo.getBoardModel());
assertTrue(BoardInfoHelper.runningOnRaspberryPi());
assertFalse(BoardInfoHelper.usesRP1());

boardInfo.setBoardModel(BoardModel.GENERIC_RP1);
assertEquals(BoardModel.GENERIC_RP1, boardInfo.getBoardModel());
assertTrue(BoardInfoHelper.runningOnRaspberryPi());
assertTrue(BoardInfoHelper.usesRP1());
}
}
2 changes: 1 addition & 1 deletion pi4j-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>pi4j-parent</artifactId>
<groupId>com.pi4j</groupId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pi4j-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>pi4j-parent</artifactId>
<groupId>com.pi4j</groupId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion plugins/pi4j-plugin-gpiod/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<relativePath>../pi4j-plugin/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion plugins/pi4j-plugin-linuxfs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<relativePath>../pi4j-plugin/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion plugins/pi4j-plugin-mock/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>pi4j-plugin</artifactId>
<groupId>com.pi4j</groupId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<relativePath>../pi4j-plugin/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion plugins/pi4j-plugin-pigpio/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>pi4j-plugin</artifactId>
<groupId>com.pi4j</groupId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<relativePath>../pi4j-plugin/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion plugins/pi4j-plugin-raspberrypi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>pi4j-plugin</artifactId>
<groupId>com.pi4j</groupId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<relativePath>../pi4j-plugin/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion plugins/pi4j-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>pi4j-parent</artifactId>
<groupId>com.pi4j</groupId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-parent</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<name>Pi4J :: Parent POM</name>
<description>Parent Maven POM for the Pi4J Project</description>
<url>https://pi4j.com</url>
Expand Down