2016-05-31 23:45:47 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) FIRST 2016. All Rights Reserved. */
|
|
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2016-07-13 20:29:28 -07:00
|
|
|
#include "HAL/handles/HandlesInternal.h"
|
2016-05-31 23:45:47 -07:00
|
|
|
|
|
|
|
|
namespace hal {
|
2016-08-12 13:45:28 -07:00
|
|
|
HAL_PortHandle createPortHandle(uint8_t channel, uint8_t module) {
|
2016-06-05 15:23:58 -07:00
|
|
|
// set last 8 bits, then shift to first 8 bits
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_PortHandle handle = static_cast<HAL_PortHandle>(HAL_HandleEnum::Port);
|
2016-06-05 15:23:58 -07:00
|
|
|
handle = handle << 24;
|
|
|
|
|
// shift module and add to 3rd set of 8 bits
|
|
|
|
|
int32_t temp = module;
|
|
|
|
|
temp = (temp << 8) & 0xff00;
|
|
|
|
|
handle += temp;
|
2016-08-12 13:45:28 -07:00
|
|
|
// add channel to last 8 bits
|
|
|
|
|
handle += channel;
|
2016-06-05 15:23:58 -07:00
|
|
|
return handle;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType) {
|
|
|
|
|
if (index < 0) return HAL_kInvalidHandle;
|
2016-06-05 07:29:47 -07:00
|
|
|
uint8_t hType = static_cast<uint8_t>(handleType);
|
2016-07-09 00:24:26 -07:00
|
|
|
if (hType == 0 || hType > 127) return HAL_kInvalidHandle;
|
2016-05-31 23:45:47 -07:00
|
|
|
// set last 8 bits, then shift to first 8 bits
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_Handle handle = hType;
|
2016-05-31 23:45:47 -07:00
|
|
|
handle = handle << 24;
|
|
|
|
|
// add index to set last 16 bits
|
|
|
|
|
handle += index;
|
|
|
|
|
return handle;
|
|
|
|
|
}
|
2016-07-10 17:47:44 -07:00
|
|
|
} // namespace hal
|