Move PWM allocation to HAL to allow for checking against DIO allocation

Re-number MXP DIO to match pinout (include SPI and I2C pins) (fixes artf2664)
Change PWM MXP mapping to accommodate DIO re-mapping
This re-implementation also fixes artf2668 for C++ and Java
Change the test bench to reflect this change also

Change-Id: If30bd6a85a9f1f619fbde06a4ecd595a15fd28f7
This commit is contained in:
Kevin O'Connor
2014-08-05 17:27:43 -04:00
committed by Thomas Clark
parent deb335d96d
commit 59473ab7a7
9 changed files with 105 additions and 41 deletions

View File

@@ -37,8 +37,6 @@ import edu.wpi.first.wpilibj.hal.HALUtil;
* 0 = disabled (i.e. PWM output is held low)
*/
public class PWM extends SensorBase implements LiveWindowSendable {
private static Resource allocated = new Resource( kPwmChannels);
/**
* Represents the amount to multiply the minimum servo-pulse pwm period by.
*/
@@ -113,12 +111,6 @@ public class PWM extends SensorBase implements LiveWindowSendable {
*/
private void initPWM(final int channel) {
checkPWMChannel(channel);
try {
allocated.allocate(channel);
} catch (CheckedAllocationException e) {
throw new AllocationException(
"PWM channel " + channel + " is already allocated");
}
m_channel = channel;
ByteBuffer status = ByteBuffer.allocateDirect(4);
@@ -127,6 +119,13 @@ public class PWM extends SensorBase implements LiveWindowSendable {
m_port = DIOJNI.initializeDigitalPort(DIOJNI.getPort((byte) m_channel), status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
if (!PWMJNI.allocatePWMChannel(m_port, status.asIntBuffer()))
{
throw new AllocationException(
"PWM channel " + channel + " is already allocated");
}
HALUtil.checkStatus(status.asIntBuffer());
PWMJNI.setPWM(m_port, (short) 0, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
@@ -156,10 +155,11 @@ public class PWM extends SensorBase implements LiveWindowSendable {
PWMJNI.setPWM(m_port, (short) 0, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
PWMJNI.freeDIO(m_port, status.asIntBuffer());
PWMJNI.freePWMChannel(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
allocated.free(m_channel);
PWMJNI.freeDIO(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**

View File

@@ -7,6 +7,8 @@ import edu.wpi.first.wpilibj.SensorBase;
public class PWMJNI extends DIOJNI {
public static native boolean allocatePWMChannel(ByteBuffer digital_port_pointer, IntBuffer status);
public static native void freePWMChannel(ByteBuffer digital_port_pointer, IntBuffer status);
public static native void setPWM(ByteBuffer digital_port_pointer, short value, IntBuffer status);
public static native short getPWM(ByteBuffer digital_port_pointer, IntBuffer status);
public static native void setPWMPeriodScale(ByteBuffer digital_port_pointer, int squelchMask, IntBuffer status);