Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.diozero.internal.board.raspberrypi;
/*
* #%L
* Organisation: diozero
* Project: Device I/O Zero - Core
* Filename: RaspberryPiBoardInfoProvider.java
*
* This file is part of the diozero project. More information about this project
* can be found at http://www.diozero.com/
* %%
* Copyright (C) 2016 - 2020 diozero
* %%
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* #L%
*/
import java.util.HashMap;
import java.util.Map;
import org.tinylog.Logger;
import com.diozero.api.PinInfo;
import com.diozero.internal.provider.MmapGpioInterface;
import com.diozero.util.BoardInfo;
import com.diozero.util.BoardInfoProvider;
/**
* See this c library.
* See also this table of revisions.
*/
public class RaspberryPiBoardInfoProvider implements BoardInfoProvider {
public static final String MAKE = "RaspberryPi";
private static final String BCM_HARDWARE_PREFIX = "BCM";
public static final String MODEL_A = "A";
public static final String MODEL_B = "B";
public static final String MODEL_A_PLUS = "A+";
public static final String MODEL_B_PLUS = "B+";
public static final String MODEL_2B = "2B";
public static final String MODEL_ALPHA = "Alpha";
public static final String COMPUTE_MODULE = "CM";
public static final String MODEL_3B = "3B";
public static final String MODEL_3B_PLUS = "3B+";
public static final String MODEL_3A_PLUS = "3A+";
public static final String MODEL_4B = "4B";
public static final String MODEL_ZERO = "Zero";
public static final String COMPUTE_MODULE_3 = "CM3";
public static final String COMPUTE_MODULE_3_PLUS = "CM3+";
public static final String MODEL_ZERO_W = "ZeroW";
private static Map MODELS;
static {
MODELS = new HashMap<>();
MODELS.put(Integer.valueOf(0), MODEL_A);
MODELS.put(Integer.valueOf(1), MODEL_B);
MODELS.put(Integer.valueOf(2), MODEL_A_PLUS);
MODELS.put(Integer.valueOf(3), MODEL_B_PLUS);
MODELS.put(Integer.valueOf(4), MODEL_2B);
MODELS.put(Integer.valueOf(5), MODEL_ALPHA);
MODELS.put(Integer.valueOf(6), COMPUTE_MODULE);
MODELS.put(Integer.valueOf(8), MODEL_3B);
MODELS.put(Integer.valueOf(9), MODEL_ZERO);
MODELS.put(Integer.valueOf(10), COMPUTE_MODULE_3);
MODELS.put(Integer.valueOf(12), MODEL_ZERO_W);
MODELS.put(Integer.valueOf(13), MODEL_3B_PLUS);
MODELS.put(Integer.valueOf(14), MODEL_3A_PLUS);
MODELS.put(Integer.valueOf(16), COMPUTE_MODULE_3_PLUS);
MODELS.put(Integer.valueOf(17), MODEL_4B);
}
private static final String PCB_REV_1_0 = "1.0";
private static final String PCB_REV_1_1 = "1.1";
private static final String PCB_REV_1_2 = "1.2";
private static final String PCB_REV_2_0 = "2.0";
private static Map MEMORY;
static {
MEMORY = new HashMap<>();
MEMORY.put(Integer.valueOf(0), Integer.valueOf(256));
MEMORY.put(Integer.valueOf(1), Integer.valueOf(512));
MEMORY.put(Integer.valueOf(2), Integer.valueOf(1024));
MEMORY.put(Integer.valueOf(3), Integer.valueOf(2048));
MEMORY.put(Integer.valueOf(4), Integer.valueOf(4096));
}
private static final String SONY = "Sony";
private static final String EGOMAN = "Egoman";
private static final String EMBEST = "Embest";
private static final String SONY_JAPAN = "Sony Japan";
private static final String EMBEST_2 = "Embest-2";
private static final String STADIUM = "Stadium";
private static final String QISDA = "Qisda";
private static Map MANUFACTURERS;
static {
MANUFACTURERS = new HashMap<>();
MANUFACTURERS.put(Integer.valueOf(0), SONY);
MANUFACTURERS.put(Integer.valueOf(1), EGOMAN);
MANUFACTURERS.put(Integer.valueOf(2), EMBEST);
MANUFACTURERS.put(Integer.valueOf(3), SONY_JAPAN);
MANUFACTURERS.put(Integer.valueOf(4), EMBEST_2);
MANUFACTURERS.put(Integer.valueOf(5), STADIUM);
MANUFACTURERS.put(Integer.valueOf(99), QISDA);
}
private static final String BCM2835 = "BCM2835";
private static final String BCM2836 = "BCM2836";
private static final String BCM2837 = "BCM2837";
private static final String BCM2711 = "BCM2711";
private static Map PROCESSORS;
static {
PROCESSORS = new HashMap<>();
PROCESSORS.put(Integer.valueOf(0), BCM2835);
PROCESSORS.put(Integer.valueOf(1), BCM2836);
PROCESSORS.put(Integer.valueOf(2), BCM2837);
PROCESSORS.put(Integer.valueOf(3), BCM2711);
}
private static Map PI_BOARDS;
static {
PI_BOARDS = new HashMap<>();
PI_BOARDS.put("0002", new PiBRev1BoardInfo("0002", PCB_REV_1_0, 256, EGOMAN));
PI_BOARDS.put("0003", new PiBRev1BoardInfo("0003", PCB_REV_1_1, 256, EGOMAN));
PI_BOARDS.put("0004", new PiABRev2BoardInfo("0004", MODEL_B, 256, SONY));
PI_BOARDS.put("0005", new PiABRev2BoardInfo("0005", MODEL_B, 256, QISDA));
PI_BOARDS.put("0006", new PiABRev2BoardInfo("0006", MODEL_B, 256, EGOMAN));
PI_BOARDS.put("0007", new PiABRev2BoardInfo("0007", MODEL_A, 256, EGOMAN));
PI_BOARDS.put("0008", new PiABRev2BoardInfo("0008", MODEL_A, 256, SONY));
PI_BOARDS.put("0009", new PiABRev2BoardInfo("0009", MODEL_A, 256, QISDA));
PI_BOARDS.put("000d", new PiABRev2BoardInfo("000d", MODEL_B, 512, EGOMAN));
PI_BOARDS.put("000e", new PiABRev2BoardInfo("000e", MODEL_B, 512, SONY));
PI_BOARDS.put("000f", new PiABRev2BoardInfo("000f", MODEL_B, 512, QISDA));
PI_BOARDS.put("0010", new PiABPlusBoardInfo("0010", MODEL_B_PLUS, PCB_REV_1_2, 512, SONY, BCM2835));
PI_BOARDS.put("0011", new PiComputeModuleBoardInfo("0011", 512, SONY, BCM2835));
PI_BOARDS.put("0012", new PiABPlusBoardInfo("0012", MODEL_A_PLUS, PCB_REV_1_2, 256, SONY, BCM2835));
PI_BOARDS.put("0013", new PiABPlusBoardInfo("0013", MODEL_B_PLUS, PCB_REV_1_2, 512, EGOMAN, BCM2835));
PI_BOARDS.put("0014", new PiComputeModuleBoardInfo("0014", 512, EMBEST, BCM2835));
// Unknown as to whether this has 256MB or 512MB RAM
PI_BOARDS.put("0015", new PiABPlusBoardInfo("0015", MODEL_A_PLUS, PCB_REV_1_1, 256, EMBEST, BCM2835));
}
@Override
public BoardInfo lookup(String hardware, String revision, Integer memoryKb) {
if (hardware == null || revision == null) {
return null;
}
if (! hardware.startsWith(BCM_HARDWARE_PREFIX) || revision.length() < 4) {
return null;
}
try {
int rev_int = Integer.parseInt(revision, 16);
// With the release of the Raspberry Pi 2, there is a new encoding of the
// Revision field in /proc/cpuinfo
if ((rev_int & (1 << 23)) != 0) {
String pcb_revision;
int pcb_rev = rev_int & 0x0F;
switch (pcb_rev) {
case 0:
pcb_revision = PCB_REV_1_0;
break;
case 1:
pcb_revision = PCB_REV_1_1;
break;
case 2:
pcb_revision = PCB_REV_2_0;
break;
default:
pcb_revision = "1." + pcb_rev;
}
int model = (rev_int & (0xFF << 4)) >> 4;
int proc = (rev_int & (0x0F << 12)) >> 12;
int mfr = (rev_int & (0x0F << 16)) >> 16;
int mem = (rev_int & (0x07 << 20)) >> 20;
//boolean warranty_void = (revision & (0x03 << 24)) != 0;
String model_val = MODELS.get(Integer.valueOf(model));
if (model_val == null) {
Logger.warn("Unknown Pi model: " + model);
model_val = "UNKNOWN-" + model;
}
String proc_val = PROCESSORS.get(Integer.valueOf(proc));
if (proc_val == null) {
Logger.warn("Unknown Pi processor: " + proc);
proc_val = "UNKNOWN-" + proc;
}
String mfr_val = MANUFACTURERS.get(Integer.valueOf(mfr));
if (mfr_val == null) {
Logger.warn("Unknown Pi manufacturer: " + mfr);
mfr_val = "UNKNOWN-" + mfr;
}
Integer mem_val = MEMORY.get(Integer.valueOf(mem));
if (mem_val == null) {
Logger.warn("Unknown Pi memory value: " + mem);
mem_val = Integer.valueOf(0);
}
return new PiABPlusBoardInfo(revision, model_val, pcb_revision,
mem_val.intValue(), mfr_val, proc_val);
}
} catch (NumberFormatException nfe) {
// Ignore
}
return PI_BOARDS.get(revision.substring(revision.length()-4));
}
/**
*