From e42fe1a592318661bad4bcef8e469d58b007b389 Mon Sep 17 00:00:00 2001 From: Frank Delporte Date: Mon, 25 Mar 2019 14:15:00 +0100 Subject: [PATCH 1/4] https://github.com/Pi4J/pi4j/issues/450 - adding a powerpin to be able to extend pinning scheme --- .../main/java/com/pi4j/io/gpio/PowerPin.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 pi4j-core/src/main/java/com/pi4j/io/gpio/PowerPin.java diff --git a/pi4j-core/src/main/java/com/pi4j/io/gpio/PowerPin.java b/pi4j-core/src/main/java/com/pi4j/io/gpio/PowerPin.java new file mode 100644 index 000000000..2d45c6bf6 --- /dev/null +++ b/pi4j-core/src/main/java/com/pi4j/io/gpio/PowerPin.java @@ -0,0 +1,56 @@ +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% + */ + + +import com.pi4j.system.SystemInfo; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; + +/** + * Power Pi pin definitions for (default) WiringPi pin numbering scheme. + * + * @author Frank Delporte (https://www.webtechie.be) + */ +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; + } +} From f925d66016b65fd566e82a87207bcfc77dca8c5e Mon Sep 17 00:00:00 2001 From: Frank Delporte Date: Mon, 25 Mar 2019 23:32:37 +0100 Subject: [PATCH 2/4] Adding header info into the library --- .../main/java/com/pi4j/io/gpio/HeaderPin.java | 64 +++++++++++++++++++ .../main/java/com/pi4j/io/gpio/PowerPin.java | 6 -- 2 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 pi4j-core/src/main/java/com/pi4j/io/gpio/HeaderPin.java diff --git a/pi4j-core/src/main/java/com/pi4j/io/gpio/HeaderPin.java b/pi4j-core/src/main/java/com/pi4j/io/gpio/HeaderPin.java new file mode 100644 index 000000000..3a976fa28 --- /dev/null +++ b/pi4j-core/src/main/java/com/pi4j/io/gpio/HeaderPin.java @@ -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; + } +} diff --git a/pi4j-core/src/main/java/com/pi4j/io/gpio/PowerPin.java b/pi4j-core/src/main/java/com/pi4j/io/gpio/PowerPin.java index 2d45c6bf6..2d20d5fb7 100644 --- a/pi4j-core/src/main/java/com/pi4j/io/gpio/PowerPin.java +++ b/pi4j-core/src/main/java/com/pi4j/io/gpio/PowerPin.java @@ -27,12 +27,6 @@ * #L% */ - -import com.pi4j.system.SystemInfo; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; - /** * Power Pi pin definitions for (default) WiringPi pin numbering scheme. * From 3808bc514bbf267ed82ed84a9fbfe3c9914e174f Mon Sep 17 00:00:00 2001 From: Frank Delporte Date: Mon, 25 Mar 2019 23:36:32 +0100 Subject: [PATCH 3/4] Added header definitions --- .../main/java/com/pi4j/io/gpio/Header.java | 50 ++++++++++ .../main/java/com/pi4j/io/gpio/RaspiPin.java | 98 +++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 pi4j-core/src/main/java/com/pi4j/io/gpio/Header.java diff --git a/pi4j-core/src/main/java/com/pi4j/io/gpio/Header.java b/pi4j-core/src/main/java/com/pi4j/io/gpio/Header.java new file mode 100644 index 000000000..615fe10fb --- /dev/null +++ b/pi4j-core/src/main/java/com/pi4j/io/gpio/Header.java @@ -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 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 getPins() { + return this.headerPins; + } +} diff --git a/pi4j-core/src/main/java/com/pi4j/io/gpio/RaspiPin.java b/pi4j-core/src/main/java/com/pi4j/io/gpio/RaspiPin.java index 7ef5ab79d..389645dff 100644 --- a/pi4j-core/src/main/java/com/pi4j/io/gpio/RaspiPin.java +++ b/pi4j-core/src/main/java/com/pi4j/io/gpio/RaspiPin.java @@ -30,6 +30,7 @@ import com.pi4j.system.SystemInfo; +import java.lang.FdLibm.Pow; import java.util.ArrayList; import java.util.EnumSet; import java.util.List; @@ -175,4 +176,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; + } } From a11473c13690874552ad0ddc9d434203e11d745e Mon Sep 17 00:00:00 2001 From: Frank Delporte Date: Mon, 25 Mar 2019 23:37:54 +0100 Subject: [PATCH 4/4] Removed unneeded import --- pi4j-core/src/main/java/com/pi4j/io/gpio/RaspiPin.java | 1 - 1 file changed, 1 deletion(-) diff --git a/pi4j-core/src/main/java/com/pi4j/io/gpio/RaspiPin.java b/pi4j-core/src/main/java/com/pi4j/io/gpio/RaspiPin.java index 389645dff..8c5b96d0c 100644 --- a/pi4j-core/src/main/java/com/pi4j/io/gpio/RaspiPin.java +++ b/pi4j-core/src/main/java/com/pi4j/io/gpio/RaspiPin.java @@ -30,7 +30,6 @@ import com.pi4j.system.SystemInfo; -import java.lang.FdLibm.Pow; import java.util.ArrayList; import java.util.EnumSet; import java.util.List;