Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Develop/2.0.pinninginfo #451

Closed
wants to merge 4 commits into from
Closed
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
50 changes: 50 additions & 0 deletions pi4j-core/src/main/java/com/pi4j/io/gpio/Header.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.pi4j.io.gpio;

import java.util.ArrayList;
import java.util.List;

/**
* Describes the pinning layout of a header.
*/
public class Header {
private final int numberOfPins;
private final List<HeaderPin> headerPins;

/**
* Constructor.
*
* @param numberOfPins The number of pins on the connector.
*/
public Header(final int numberOfPins) {
this.numberOfPins = numberOfPins;
this.headerPins = new ArrayList<>(numberOfPins);
}

/**
* Add a pin to the list.
*
* @param pinNumber
* @param wiringPiNumber
* @param name
* @param description
* @param pin
*/
public void addHeaderPin(final int pinNumber, final Integer wiringPiNumber, final String name, final String description, final Pin pin) {
if (pinNumber > this.numberOfPins) {
throw new IllegalArgumentException("The given pin number exceeds the size of " + this.numberOfPins);
}

if (pinNumber < 1) {
throw new IllegalArgumentException("The pin number needs to start at 1");
}

this.headerPins.add(pinNumber - 1, new HeaderPin(pinNumber, wiringPiNumber, name, description, pin));
}

/**
* @return The list of pins in this header.
*/
public List<HeaderPin> getPins() {
return this.headerPins;
}
}
64 changes: 64 additions & 0 deletions pi4j-core/src/main/java/com/pi4j/io/gpio/HeaderPin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.pi4j.io.gpio;

/**
* Describes a pin in the header.
*/
public class HeaderPin {
private final int pinNumber;
private final Integer wiringPiNumber;
private final String name;
private final String info;
private final Pin pin;

/**
* Constructor.
*
* @param pinNumber Number of the pin, starting at 1.
* @param wiringPiNumber Number of the pin according to the Pi4J/WiringPi GPIO numbering scheme.
* @param name Name of the pin.
* @param info Info of the pin.
* @param pin The type of pin.
*/
public HeaderPin(final int pinNumber, final Integer wiringPiNumber, final String name, final String info, final Pin pin) {
this.pinNumber = pinNumber;
this.wiringPiNumber = wiringPiNumber;
this.name = name;
this.info = info;
this.pin = pin;
}

/**
* @return The pin number, starting at 1.
*/
public int getPinNumber() {
return pinNumber;
}

/**
* @return Number of the pin according to the Pi4J/WiringPi GPIO numbering scheme.
*/
public Integer getWiringPiNumber() {
return wiringPiNumber;
}

/**
* @return Name of the pin.
*/
public String getName() {
return name;
}

/**
* @return Info of the pin.
*/
public String getInfo() {
return info;
}

/**
* @return The type of pin.
*/
public Pin getPin() {
return pin;
}
}
50 changes: 50 additions & 0 deletions pi4j-core/src/main/java/com/pi4j/io/gpio/PowerPin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.pi4j.io.gpio;

/*
* #%L
* **********************************************************************
* ORGANIZATION : Pi4J
* PROJECT : Pi4J :: Java Library (Core)
* FILENAME : RaspiPin.java
*
* This file is part of the Pi4J project. More information about
* this project can be found here: https://pi4j.com/
* **********************************************************************
* %%
* Copyright (C) 2012 - 2019 Pi4J
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

/**
* Power Pi pin definitions for (default) WiringPi pin numbering scheme.
*
* @author Frank Delporte (<a href="https://www.webtechie.be">https://www.webtechie.be</a>)
*/
public enum PowerPin implements Pin {

POWER_3_3("3.3 VDC"),
POWER_5_0("5.0 VDC"),
GROUND("Ground");

private final String name;

PowerPin(final String name) {
this.name = name;
}

public String getName() {
return this.name;
}
}
97 changes: 97 additions & 0 deletions pi4j-core/src/main/java/com/pi4j/io/gpio/RaspiPin.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,101 @@ public static Pin[] allPins(SystemInfo.BoardType board) {
// return pins collection
return pins.toArray(new Pin[0]);
}

/**
* Returns a {@link Header} object with the pin list of the header.
*
* @param board
* @return
*/
public static Header getHeader(SystemInfo.BoardType board) {
Header header = null;

switch (board) {
case RaspberryPi_A:
case RaspberryPi_B_Rev1:
case RaspberryPi_B_Rev2:
header = new Header(26);

header.addHeaderPin(1, null, "3.3 VDC", "Power", PowerPin.POWER_3_3);
header.addHeaderPin(2, null, "5.0 VDC", "Power", PowerPin.POWER_5_0);
header.addHeaderPin(3, 8, "SDA0", "(I2C)", null);
header.addHeaderPin(4, null, "DNC", "", null);
header.addHeaderPin(5, 9, "SCL0", "(I2C)", null);
header.addHeaderPin(6, null, "Ground", "", PowerPin.GROUND);
header.addHeaderPin(7, 7, "GPIO 7", "", RaspiPin.GPIO_07);
header.addHeaderPin(8, 15, "TxD", "(UART)", null);
header.addHeaderPin(9, null, "DNC", "", null);
header.addHeaderPin(10, 16, "RxD", "(UART)", null);
header.addHeaderPin(11, 0, "GPIO 0", "", RaspiPin.GPIO_00);
header.addHeaderPin(12, 1, "GPIO 1", "", RaspiPin.GPIO_01);
header.addHeaderPin(13, 2, "GPIO 2", "", RaspiPin.GPIO_02);
header.addHeaderPin(14, null, "DNC", "", null);
header.addHeaderPin(15, 3, "GPIO 3", "", RaspiPin.GPIO_03);
header.addHeaderPin(16, 4, "GPIO 4", "", RaspiPin.GPIO_04);
header.addHeaderPin(17, null, "DNC", "", null);
header.addHeaderPin(18, 5, "GPIO 5", "", RaspiPin.GPIO_05);
header.addHeaderPin(19, 12, "MOSI", "(SPI)", null);
header.addHeaderPin(20, null, "DNC", "", null);
header.addHeaderPin(21, 13, "MISO", "", null);
header.addHeaderPin(22, 6, "GPIO 6", "", RaspiPin.GPIO_06);
header.addHeaderPin(23, 14, "SCLK", "", null);
header.addHeaderPin(24, 10, "CE0", "", null);
header.addHeaderPin(25, null, "DNC", "", null);
header.addHeaderPin(26, 11, "CE1", "", null);
case RaspberryPi_A_Plus:
case RaspberryPi_B_Plus:
case RaspberryPi_2B:
case RaspberryPi_3B:
case RaspberryPi_3B_Plus:
case RaspberryPi_Zero:
case RaspberryPi_ZeroW:
header = new Header(40);

header.addHeaderPin(1, null, "3.3 VDC", "Power", PowerPin.POWER_3_3);
header.addHeaderPin(2, null, "5.0 VDC", "Power", PowerPin.POWER_5_0);
header.addHeaderPin(3, 8, "GPIO 8", "SDA1 (I2C)", RaspiPin.GPIO_08);
header.addHeaderPin(4, null, "5.0 VDC", "Power", PowerPin.POWER_5_0);
header.addHeaderPin(5, 9, "GPIO 9", "SCL1 (I2C)", RaspiPin.GPIO_09);
header.addHeaderPin(6, null, "Ground", "", PowerPin.GROUND);
header.addHeaderPin(7, 7, "GPIO 7", "GPCLK0", RaspiPin.GPIO_07);
header.addHeaderPin(8, 15, "GPIO 15", "TxD (UART)", RaspiPin.GPIO_15);
header.addHeaderPin(9, null, "Ground", "", PowerPin.GROUND);
header.addHeaderPin(10, 16, "GPIO 16", "RxD (UART)", RaspiPin.GPIO_16);
header.addHeaderPin(11, 0, "GPIO 0", "", RaspiPin.GPIO_00);
header.addHeaderPin(12, 1, "GPIO 1", "PCM_CLK/PWM0", RaspiPin.GPIO_01);
header.addHeaderPin(13, 2, "GPIO 2", "", RaspiPin.GPIO_02);
header.addHeaderPin(14, null, "Ground", "", PowerPin.GROUND);
header.addHeaderPin(15, 3, "GPIO 3", "", RaspiPin.GPIO_03);
header.addHeaderPin(16, 4, "GPIO 4", "", RaspiPin.GPIO_04);
header.addHeaderPin(17, null, "3.3 VDC", "Power", PowerPin.POWER_3_3);
header.addHeaderPin(18, 5, "GPIO 5", "", RaspiPin.GPIO_05);
header.addHeaderPin(19, 12, "GPIO 12", "MOSI (SPI)", RaspiPin.GPIO_12);
header.addHeaderPin(20, null, "Ground", "", PowerPin.GROUND);
header.addHeaderPin(21, 13, "GPIO 13", "MISO (SPI)", RaspiPin.GPIO_13);
header.addHeaderPin(22, 6, "GPIO 6", "", RaspiPin.GPIO_06);
header.addHeaderPin(23, 14, "GPIO 14", "SCLK (SPI)", RaspiPin.GPIO_14);
header.addHeaderPin(24, 10, "GPIO 10", "CE0 (SPI)", RaspiPin.GPIO_10);
header.addHeaderPin(25, null, "Ground", "", PowerPin.GROUND);
header.addHeaderPin(26, 11, "GPIO 11", "CE1 (SPI)", RaspiPin.GPIO_11);
header.addHeaderPin(27, 30, "SDA0", "I2C ID EEPROM", null);
header.addHeaderPin(28, 31, "SCL0", "I2C ID EEPROM", null);
header.addHeaderPin(29, 21, "GPIO 21", "GPCLK1", RaspiPin.GPIO_21);
header.addHeaderPin(30, null, "Ground", "", PowerPin.GROUND);
header.addHeaderPin(31, 22, "GPIO 22", "GPCL2", RaspiPin.GPIO_22);
header.addHeaderPin(32, 26, "GPIO 26", "PWM0", RaspiPin.GPIO_26);
header.addHeaderPin(33, 23, "GPIO 23", "PWM1", RaspiPin.GPIO_23);
header.addHeaderPin(34, null, "Ground", "", PowerPin.GROUND);
header.addHeaderPin(35, 24, "GPIO 24", "PCM_FS/PWM1", RaspiPin.GPIO_24);
header.addHeaderPin(36, 27, "GPIO 27", "", RaspiPin.GPIO_27);
header.addHeaderPin(37, 25, "GPIO 25", "", RaspiPin.GPIO_25);
header.addHeaderPin(38, 28, "GPIO 28", "PCM_DIN", RaspiPin.GPIO_28);
header.addHeaderPin(39, null, "Ground", "", PowerPin.GROUND);
header.addHeaderPin(40, 29, "GPIO 29", "PCM_DOUT", RaspiPin.GPIO_29);

return header;
}

return header;
}
}