From 76b26c2df56343b7fae7178654f32a48de27cfb2 Mon Sep 17 00:00:00 2001 From: Thad House Date: Wed, 18 Jul 2018 20:39:05 -0700 Subject: [PATCH] HAL_InitializePWMPort: Check for MXP port (#1195) Previously all channels were incorrectly handled as MXP channels. Closes #1182 --- hal/src/main/native/athena/PWM.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hal/src/main/native/athena/PWM.cpp b/hal/src/main/native/athena/PWM.cpp index 13da5da368..7b249ba1f4 100644 --- a/hal/src/main/native/athena/PWM.cpp +++ b/hal/src/main/native/athena/PWM.cpp @@ -104,11 +104,13 @@ HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle, port->channel = origChannel; - int32_t bitToSet = 1 << remapMXPPWMChannel(port->channel); - uint16_t specialFunctions = - digitalSystem->readEnableMXPSpecialFunction(status); - digitalSystem->writeEnableMXPSpecialFunction(specialFunctions | bitToSet, - status); + if (port->channel > tPWM::kNumHdrRegisters - 1) { + int32_t bitToSet = 1 << remapMXPPWMChannel(port->channel); + uint16_t specialFunctions = + digitalSystem->readEnableMXPSpecialFunction(status); + digitalSystem->writeEnableMXPSpecialFunction(specialFunctions | bitToSet, + status); + } // Defaults to allow an always valid config. HAL_SetPWMConfig(handle, 2.0, 1.501, 1.5, 1.499, 1.0, status);