Skip to content

Commit

Permalink
Repaired reading in RaspberryPi and setting up correct signal (closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
mijaros committed Jan 7, 2016
1 parent e90c6d4 commit bf02769
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ public class BBBDigitalOutput extends AbstractDigitalOutput {

public BBBDigitalOutput(Pin pin) {
super(pin);

BeagleBonePin bbbPin = (BeagleBonePin) getPin();
int value = NativeGpio.digitalRead(bbbPin.getPortNumeric(), bbbPin.getIndexOnPort());

if (value == NativeGpio.HIGH) {
setSignal(Signal.High);
} else {
setSignal(Signal.Low);
}
}

protected void setupImpl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public abstract class AbstractBCM {

public abstract int getGPIOClear();

public abstract int getGPIORead();

public abstract int getRegisterSize();

public MemoryMap getGpioMemory() {
if (gpioMemory == null) {
gpioMemory = new MemoryMap("/dev/mem", this.getGPIOBase(), 4096, 0);
Expand Down Expand Up @@ -71,21 +75,21 @@ public void cleanup() {
}

public void configureAsInput(int gpio) {
long address = (gpio / 10) * 4;
long address = (gpio / 10) * getRegisterSize();
int value = this.getGpioMemory().getIntValueAt(address);
value &= ~(7 << getGpioRegisterOffset(gpio));
this.getGpioMemory().setIntValue(address, value);
}

public void configureAsOutput(int gpio) {
long address = (gpio / 10) * 4;
long address = (gpio / 10) * getRegisterSize();
int value = this.getGpioMemory().getIntValueAt(address);
value |= (1 << getGpioRegisterOffset(gpio));
this.getGpioMemory().setIntValue(address, value);
}

public void configureAlternateFunction(int gpio, int alt) {
long address = (gpio / 10) * 4;
long address = (gpio / 10) * getRegisterSize();
int value = this.getGpioMemory().getIntValueAt(address);
value |= (((alt) <= 3 ? (alt) + 4 : (alt) == 4 ? 3 : 2) << (gpio % 10) * 3);
this.getGpioMemory().setIntValue(address, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ public class BCM2835 extends AbstractBCM {
public static final int GPIO_BASE = (BCM_PERI_BASE + 0x200000);
public static final int PWM_BASE = (BCM_PERI_BASE + 0x20C000);
public static final int CLOCK_BASE = (BCM_PERI_BASE + 0x101000);
public static final int REGISTER_SIZE = 4;

public static final int PWMCLK_CNTL = 40 * 4;
public static final int PWMCLK_DIV = 41 * 4;
public static final int PWMCLK_CNTL = 40 * REGISTER_SIZE;
public static final int PWMCLK_DIV = 41 * REGISTER_SIZE;

public static final int PWM_CTL = 0;
public static final int PWM_RNG1 = 4 * 4;
public static final int PWM_DAT1 = 5 * 4;
public static final int PWM_RNG1 = 4 * REGISTER_SIZE;
public static final int PWM_DAT1 = 5 * REGISTER_SIZE;

public static final int GPIO_SET = 7 * REGISTER_SIZE;
public static final int GPIO_CLEAR = 10 * REGISTER_SIZE;
public static final int GPIO_READ = 13 * REGISTER_SIZE;

public static final int GPIO_SET = 7 * 4;
public static final int GPIO_CLEAR = 10 * 4;

@Override
public int getBCMPeriBase() {
Expand Down Expand Up @@ -71,8 +74,18 @@ public int getGPIOSet() {
return GPIO_SET;
}

@Override
public int getGPIORead() {
return GPIO_READ;
}

@Override
public int getGPIOClear() {
return GPIO_CLEAR;
}

@Override
public int getRegisterSize() {
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ public class BCM2836 extends AbstractBCM {
public static final int GPIO_BASE = (BCM_PERI_BASE + 0x200000);
public static final int PWM_BASE = (BCM_PERI_BASE + 0x20C000);
public static final int CLOCK_BASE = (BCM_PERI_BASE + 0x101000);
public static final int REGISTER_SIZE = 4;

public static final int PWMCLK_CNTL = 40 * 4;
public static final int PWMCLK_DIV = 41 * 4;
public static final int PWMCLK_CNTL = 40 * REGISTER_SIZE;
public static final int PWMCLK_DIV = 41 * REGISTER_SIZE;

public static final int PWM_CTL = 0;
public static final int PWM_RNG1 = 4 * 4;
public static final int PWM_DAT1 = 5 * 4;
public static final int PWM_RNG1 = 4 * REGISTER_SIZE;
public static final int PWM_DAT1 = 5 * REGISTER_SIZE;

public static final int GPIO_SET = 7 * 4;
public static final int GPIO_CLEAR = 10 * 4;
public static final int GPIO_SET = 7 * REGISTER_SIZE;
public static final int GPIO_CLEAR = 10 * REGISTER_SIZE;
public static final int GPIO_READ = 13 * REGISTER_SIZE;

@Override
public int getBCMPeriBase() {
Expand Down Expand Up @@ -75,4 +77,14 @@ public int getGPIOSet() {
public int getGPIOClear() {
return GPIO_CLEAR;
}

@Override
public int getGPIORead() {
return GPIO_READ;
}

@Override
public int getRegisterSize() {
return REGISTER_SIZE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected void setupImpl() {

public Signal read() {
int address = 1 << getRaspiPin().getGpioNumber();
return Signal.fromNumericValue(BCM.getGpioMemory().getIntValueAt(address));
return Signal.fromNumericValue(BCM.getGpioMemory().getIntValueAt(BCM.getGPIORead()) & address);
}

public void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ protected void setupImpl() {
RaspberryPiPin pin = (RaspberryPiPin) getPin();
BCM.configureAsInput(pin.getGpioNumber());
BCM.configureAsOutput(pin.getGpioNumber());
int address = 1 << pin.getGpioNumber();
Signal s = Signal.fromNumericValue(BCM.getGpioMemory().getIntValueAt(BCM.getGPIORead()) & address);
setSignal(s);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,8 @@ public void awaitBlinkingStopped() {
}

protected abstract void applySignalImpl(Signal signal);

protected void setSignal(Signal signal) {
this.signal = signal;
}
}

0 comments on commit bf02769

Please sign in to comment.