Switches HAL to fixed length signed integers, and adds our own HAL_Bool Type (#155)

* Switches HAL to fixed length signed integers, and adds our own HAL_Bool type

* Replaces HAL Floats with Doubles

Doubles are just as fast as floats with optimizations turned on, so
switches to all doubles. All made doubles for consistency.

* Prepends HAL/ to HAL include files. Also fixes some range errors
This commit is contained in:
Thad House
2016-07-12 10:45:14 -07:00
committed by Peter Johnson
parent 4a98e68815
commit b51e85ae26
89 changed files with 900 additions and 795 deletions

View File

@@ -18,7 +18,7 @@ using namespace hal;
namespace {
struct Counter {
tCounter* counter;
uint32_t index;
uint8_t index;
};
}
@@ -39,12 +39,12 @@ HAL_CounterHandle HAL_InitializeCounter(HAL_Counter_Mode mode, int32_t* index,
*status = HAL_HANDLE_ERROR;
return HAL_kInvalidHandle;
}
*index = static_cast<uint32_t>(getHandleIndex(handle));
counter->index = static_cast<uint8_t>(getHandleIndex(handle));
*index = counter->index;
counter->counter = tCounter::create(*index, status);
counter->counter = tCounter::create(counter->index, status);
counter->counter->writeConfig_Mode(mode, status);
counter->counter->writeTimerConfig_AverageSize(1, status);
counter->index = *index;
return handle;
}
@@ -82,7 +82,7 @@ void HAL_SetCounterUpSource(HAL_CounterHandle counter_handle,
}
bool routingAnalogTrigger = false;
uint32_t routingPin = 0;
uint8_t routingPin = 0;
uint8_t routingModule = 0;
bool success =
remapDigitalSource(digitalSourceHandle, analogTriggerType, routingPin,
@@ -110,7 +110,7 @@ void HAL_SetCounterUpSource(HAL_CounterHandle counter_handle,
* Set the up source to either detect rising edges or falling edges.
*/
void HAL_SetCounterUpSourceEdge(HAL_CounterHandle counter_handle,
bool risingEdge, bool fallingEdge,
HAL_Bool risingEdge, HAL_Bool fallingEdge,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
@@ -151,7 +151,7 @@ void HAL_SetCounterDownSource(HAL_CounterHandle counter_handle,
*status = HAL_HANDLE_ERROR;
return;
}
unsigned char mode = counter->counter->readConfig_Mode(status);
uint8_t mode = counter->counter->readConfig_Mode(status);
if (mode != HAL_Counter_kTwoPulse && mode != HAL_Counter_kExternalDirection) {
// TODO: wpi_setWPIErrorWithContext(ParameterOutOfRange, "Counter only
// supports DownSource in TwoPulse and ExternalDirection modes.");
@@ -160,7 +160,7 @@ void HAL_SetCounterDownSource(HAL_CounterHandle counter_handle,
}
bool routingAnalogTrigger = false;
uint32_t routingPin = 0;
uint8_t routingPin = 0;
uint8_t routingModule = 0;
bool success =
remapDigitalSource(digitalSourceHandle, analogTriggerType, routingPin,
@@ -184,7 +184,7 @@ void HAL_SetCounterDownSource(HAL_CounterHandle counter_handle,
* Set the down source to either detect rising edges or falling edges.
*/
void HAL_SetCounterDownSourceEdge(HAL_CounterHandle counter_handle,
bool risingEdge, bool fallingEdge,
HAL_Bool risingEdge, HAL_Bool fallingEdge,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
@@ -246,7 +246,7 @@ void HAL_SetCounterExternalDirectionMode(HAL_CounterHandle counter_handle,
* Counts up on both rising and falling edges.
*/
void HAL_SetCounterSemiPeriodMode(HAL_CounterHandle counter_handle,
bool highSemiPeriod, int32_t* status) {
HAL_Bool highSemiPeriod, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -300,7 +300,7 @@ int32_t HAL_GetCounterSamplesToAverage(HAL_CounterHandle counter_handle,
* @param samplesToAverage The number of samples to average from 1 to 127.
*/
void HAL_SetCounterSamplesToAverage(HAL_CounterHandle counter_handle,
int samplesToAverage, int32_t* status) {
int32_t samplesToAverage, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -365,7 +365,8 @@ double HAL_GetCounterPeriod(HAL_CounterHandle counter_handle, int32_t* status) {
period = static_cast<double>(output.Period << 1) /
static_cast<double>(output.Count);
}
return period * 2.5e-8; // result * timebase (currently 40ns)
return static_cast<double>(period *
2.5e-8); // result * timebase (currently 25ns)
}
/**
@@ -401,7 +402,7 @@ void HAL_SetCounterMaxPeriod(HAL_CounterHandle counter_handle, double maxPeriod,
* at the end of an average and there are no samples to average).
*/
void HAL_SetCounterUpdateWhenEmpty(HAL_CounterHandle counter_handle,
bool enabled, int32_t* status) {
HAL_Bool enabled, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -418,7 +419,8 @@ void HAL_SetCounterUpdateWhenEmpty(HAL_CounterHandle counter_handle,
* @return Returns true if the most recent counter period exceeds the MaxPeriod
* value set by SetMaxPeriod.
*/
bool HAL_GetCounterStopped(HAL_CounterHandle counter_handle, int32_t* status) {
HAL_Bool HAL_GetCounterStopped(HAL_CounterHandle counter_handle,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -431,8 +433,8 @@ bool HAL_GetCounterStopped(HAL_CounterHandle counter_handle, int32_t* status) {
* The last direction the counter value changed.
* @return The last direction the counter value changed.
*/
bool HAL_GetCounterDirection(HAL_CounterHandle counter_handle,
int32_t* status) {
HAL_Bool HAL_GetCounterDirection(HAL_CounterHandle counter_handle,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -449,7 +451,8 @@ bool HAL_GetCounterDirection(HAL_CounterHandle counter_handle,
* @param reverseDirection true if the value counted should be negated.
*/
void HAL_SetCounterReverseDirection(HAL_CounterHandle counter_handle,
bool reverseDirection, int32_t* status) {
HAL_Bool reverseDirection,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;