Skip to content
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

based on machine (pi5) set pwmchip to 2, Also set provider priority … #343

Merged
merged 4 commits into from
Apr 16, 2024
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pi4j.plugin.gpiod.provider.gpio.digital;


import com.pi4j.boardinfo.util.BoardInfoHelper;
import com.pi4j.context.Context;
import com.pi4j.exception.InitializeException;
import com.pi4j.exception.ShutdownException;
Expand Down Expand Up @@ -34,8 +36,14 @@ public DigitalInput create(DigitalInputConfig config) {

@Override
public int getPriority() {
// GpioD should be used if available
return 150;
// the gpioD driver should be higher priority when on Rp1 chip
int rval = 0;
if(BoardInfoHelper.usesRP1()) {
rval = 150;
}else{
rval = 150;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value is the same in both if cases?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in both are the same to match what Robert did for 2.5 So I did the update and did pay attention to the fact both legs were equal.
Fixed

}
return(rval);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* #L%
*/

import com.pi4j.boardinfo.util.BoardInfoHelper;
import com.pi4j.context.Context;
import com.pi4j.exception.InitializeException;
import com.pi4j.exception.ShutdownException;
Expand Down Expand Up @@ -67,8 +68,14 @@ public DigitalOutput create(DigitalOutputConfig config) {

@Override
public int getPriority() {
// GpioD should be used if available
return 150;
// the gpioD driver should be higher priority when on RP1 chip
int rval = 0;
if(BoardInfoHelper.usesRP1()) {
rval = 150;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be the same as above.
fixed

}else{
rval = 150;
}
return(rval);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
* #L%
*/


import com.pi4j.boardinfo.util.BoardInfoHelper;
import com.pi4j.extension.Plugin;
import com.pi4j.extension.PluginService;
import com.pi4j.plugin.linuxfs.internal.LinuxGpio;
Expand Down Expand Up @@ -108,7 +110,6 @@ public class LinuxFsPlugin implements Plugin {

public static String DEFAULT_GPIO_FILESYSTEM_PATH = LinuxGpio.DEFAULT_SYSTEM_PATH;
public static String DEFAULT_PWM_FILESYSTEM_PATH = LinuxPwm.DEFAULT_SYSTEM_PATH;
public static int DEFAULT_PWM_CHIP = LinuxPwm.DEFAULT_PWM_CHIP;

private Logger logger = LoggerFactory.getLogger(this.getClass());

Expand All @@ -121,7 +122,13 @@ public void initialize(PluginService service) {
// get Linux file system path for GPIO & PWM
String gpioFileSystemPath = DEFAULT_GPIO_FILESYSTEM_PATH;
String pwmFileSystemPath = DEFAULT_PWM_FILESYSTEM_PATH;
int pwmChip = DEFAULT_PWM_CHIP;

int pwmChip;
if(BoardInfoHelper.usesRP1()) {
pwmChip = LinuxPwm.DEFAULT_RP1_PWM_CHIP;
}else{
pwmChip = LinuxPwm.DEFAULT_LEGACY_PWM_CHIP;
}

// [GPIO] get overriding custom 'linux.gpio.system.path' setting from Pi4J context
if(service.context().properties().has("linux.gpio.system.path")){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,18 @@ public class LinuxPwm {
/** Constant <code>DEFAULT_SYSTEM_PATH="/sys/class/pwm"</code> */
public static String DEFAULT_SYSTEM_PATH = "/sys/class/pwm";

/** Constant <code>DEFAULT_PWM_CHIP=0</code> */
/** In Pi5 the chip is number 2 */
public static int DEFAULT_PWM_CHIP = 2;
/** Constant <code>DEFAULT_LEGACY_PWM_CHIP=0</code> */
/** In Pi Models Previous to RP1 the chip is number 0 */
public static int DEFAULT_LEGACY_PWM_CHIP = 0;

/** Constant <code>DEFAULT_RP1_PWM_CHIP=2</code> */
/** In RP1 the chip is number 2 */
public static int DEFAULT_RP1_PWM_CHIP = 2;

/** Constant <code>DEFAULT_PWM_CHIP=2</code> */
/** In RP1 the chip is number 2 */
public static int DEFAULT_PWM_CHIP = DEFAULT_RP1_PWM_CHIP;


protected final String systemPath;
protected final int chip;
Expand Down Expand Up @@ -77,7 +86,8 @@ public LinuxPwm(String systemPath, int chip, int address){
* @param systemPath a {@link String} object.
* @param address a int.
*/
public LinuxPwm(String systemPath, int address){

public LinuxPwm(String systemPath, int address) {
this(DEFAULT_SYSTEM_PATH, DEFAULT_PWM_CHIP, address);
}

Expand All @@ -90,6 +100,8 @@ public LinuxPwm(int address){
this(DEFAULT_SYSTEM_PATH, address);
}



/**
* <p>channels.</p>
* The number of PWM channels this chip supports (read-only).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
* #L%
*/

import com.pi4j.io.exception.IOAlreadyExistsException;

import com.pi4j.boardinfo.util.BoardInfoHelper;
import com.pi4j.io.gpio.digital.DigitalInput;
import com.pi4j.io.gpio.digital.DigitalInputConfig;
import com.pi4j.io.gpio.digital.DigitalInputProviderBase;
Expand All @@ -54,8 +55,14 @@ public LinuxFsDigitalInputProviderImpl(String gpioFileSystemPath) {

@Override
public int getPriority() {
// the linux FS DI driver should not be used over the pigpio
return 50;
// the linux FS Digital driver should be higher priority than Pigpio on RP1 chip
int rval = 0;
if(BoardInfoHelper.usesRP1()) {
rval = 100;
}else{
rval = 50;
}
return(rval);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
* #L%
*/

import com.pi4j.io.exception.IOAlreadyExistsException;

import com.pi4j.boardinfo.util.BoardInfoHelper;
import com.pi4j.io.gpio.digital.DigitalOutput;
import com.pi4j.io.gpio.digital.DigitalOutputConfig;
import com.pi4j.io.gpio.digital.DigitalOutputProviderBase;
Expand Down Expand Up @@ -55,8 +56,14 @@ public LinuxFsDigitalOutputProviderImpl(String gpioFileSystemPath) {

@Override
public int getPriority() {
// the linux FS DO driver should not be used over the pigpio
return 50;
// the linux FS Digital driver should be higher priority than Pigpio on RP1 chip.
int rval = 0;
if(BoardInfoHelper.usesRP1()) {
rval = 100;
}else{
rval = 50;
}
return(rval);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
* #L%
*/

import com.pi4j.io.exception.IOAlreadyExistsException;

import com.pi4j.boardinfo.util.BoardInfoHelper;
import com.pi4j.io.i2c.I2C;
import com.pi4j.io.i2c.I2CConfig;
import com.pi4j.io.i2c.I2CProviderBase;
Expand All @@ -47,8 +48,14 @@ public LinuxFsI2CProviderImpl() {

@Override
public int getPriority() {
// the linux FS I2C driver should be used over the pigpio
return 150;
// the linux FS driver should be higher priority when on RP1 chip
int rval = 0;
if(BoardInfoHelper.usesRP1()) {
rval = 150;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

}else{
rval = 150;
}
return(rval);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
* #L%
*/

import com.pi4j.io.exception.IOAlreadyExistsException;

import com.pi4j.boardinfo.util.BoardInfoHelper;
import com.pi4j.io.exception.IOException;
import com.pi4j.io.pwm.Pwm;
import com.pi4j.io.pwm.PwmConfig;
import com.pi4j.io.pwm.PwmProviderBase;
import com.pi4j.io.pwm.PwmType;
import com.pi4j.plugin.linuxfs.internal.LinuxPwm;

import static java.text.MessageFormat.format;

/**
Expand All @@ -60,8 +60,14 @@ public LinuxFsPwmProviderImpl(String pwmFileSystemPath, int pwmChip) {

@Override
public int getPriority() {
// the linux FS PWM driver should not be used over the pigpio
return 50;
// the linux FS PWM driver should be higher priority than Pigpio on RP1 chip
int rval = 0;
if(BoardInfoHelper.usesRP1()) {
rval = 100;
}else{
rval = 50;
}
return(rval);
}

/**
Expand All @@ -71,7 +77,11 @@ public LinuxFsPwmProviderImpl(String pwmFileSystemPath) {
this.id = ID;
this.name = NAME;
this.pwmFileSystemPath = pwmFileSystemPath;
this.pwmChip = LinuxPwm.DEFAULT_PWM_CHIP;
if(BoardInfoHelper.usesRP1()) {
this.pwmChip = LinuxPwm.DEFAULT_RP1_PWM_CHIP;
}else{
this.pwmChip = LinuxPwm.DEFAULT_LEGACY_PWM_CHIP;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
* #L%
*/

import com.pi4j.io.exception.IOAlreadyExistsException;

import com.pi4j.boardinfo.util.BoardInfoHelper;
import com.pi4j.io.gpio.digital.DigitalInput;
import com.pi4j.io.gpio.digital.DigitalInputConfig;
import com.pi4j.io.gpio.digital.DigitalInputProviderBase;
Expand Down Expand Up @@ -56,8 +57,14 @@ public PiGpioDigitalInputProviderImpl(PiGpio piGpio) {

@Override
public int getPriority() {
// the pigpio DI driver should be used over the default
return 100;
// the Pigpio driver should be higher priority when NOT on RP1 chip
int rval = 0;
if(!BoardInfoHelper.usesRP1()) {
rval = 100;
}else{
rval = 50;
}
return(rval);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
* #L%
*/

import com.pi4j.io.exception.IOAlreadyExistsException;

import com.pi4j.boardinfo.util.BoardInfoHelper;
import com.pi4j.io.gpio.digital.DigitalOutput;
import com.pi4j.io.gpio.digital.DigitalOutputConfig;
import com.pi4j.io.gpio.digital.DigitalOutputProviderBase;
Expand Down Expand Up @@ -56,8 +57,14 @@ public PiGpioDigitalOutputProviderImpl(PiGpio piGpio) {

@Override
public int getPriority() {
// the pigpio DO driver should be used over the default
return 100;
// the Pigpio driver should be higher priority when NOT on RP1 chip.
int rval = 0;
if(!BoardInfoHelper.usesRP1()) {
rval = 100;
}else{
rval = 50;
}
return(rval);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
* #L%
*/

import com.pi4j.io.exception.IOAlreadyExistsException;

import com.pi4j.boardinfo.util.BoardInfoHelper;
import com.pi4j.io.i2c.I2C;
import com.pi4j.io.i2c.I2CConfig;
import com.pi4j.io.i2c.I2CProviderBase;
Expand Down Expand Up @@ -56,8 +57,14 @@ public PiGpioI2CProviderImpl(PiGpio piGpio) {

@Override
public int getPriority() {
// the pigpio I2C driver should be used over the default
return 100;
// the Pigpio driver should be higher priority when NOT on RP1 chip
int rval = 0;
if(!BoardInfoHelper.usesRP1()) {
rval = 100;
}else{
rval = 50;
}
return(rval);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
* #L%
*/

import com.pi4j.io.exception.IOAlreadyExistsException;

import com.pi4j.boardinfo.util.BoardInfoHelper;
import com.pi4j.io.pwm.Pwm;
import com.pi4j.io.pwm.PwmConfig;
import com.pi4j.io.pwm.PwmProviderBase;
Expand Down Expand Up @@ -57,8 +58,14 @@ public PiGpioPwmProviderImpl(PiGpio piGpio) {

@Override
public int getPriority() {
// the pigpio PWM driver should be used over the default
return 100;
// the Pigpio driver should be higher priority when NOT on RP1 chip.
int rval = 0;
if(!BoardInfoHelper.usesRP1()) {
rval = 100;
}else{
rval = 50;
}
return(rval);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* #L%
*/

import com.pi4j.io.exception.IOAlreadyExistsException;
import com.pi4j.boardinfo.util.BoardInfoHelper;
import com.pi4j.io.serial.Serial;
import com.pi4j.io.serial.SerialConfig;
import com.pi4j.io.serial.SerialProviderBase;
Expand Down Expand Up @@ -56,8 +56,14 @@ public PiGpioSerialProviderImpl(PiGpio piGpio) {

@Override
public int getPriority() {
// the pigpio Serial driver should be used over the default
return 100;
// the Pigpio driver should be higher priority when NOT on Rp1 chip.
int rval = 0;
if(!BoardInfoHelper.usesRP1()) {
rval = 100;
}else{
rval = 50;
}
return(rval);
}

/**
Expand Down
Loading