Make HAL headers C-compatible (#1177)

Also fix the return type of HAL_IsNewControlData() and HAL_MatchType's type.

Since UsageReporting is intended to be namespaced, it is hidden when this is being used in C.

Fixes: #476
Closes: #535
Ref: #1122
This commit is contained in:
David Vo
2018-07-08 15:18:03 +10:00
committed by Peter Johnson
parent 3818a8b3b6
commit ad3e2d7d3b
13 changed files with 57 additions and 18 deletions

View File

@@ -307,7 +307,7 @@ void HAL_ObserveUserProgramTest(void) {
FRC_NetworkCommunication_observeUserProgramTest();
}
bool HAL_IsNewControlData(void) {
HAL_Bool HAL_IsNewControlData(void) {
// There is a rollover error condition here. At Packet# = n * (uintmax), this
// will return false when instead it should return true. However, this at a
// 20ms rate occurs once every 2.7 years of DS connected runtime, so not

View File

@@ -9,14 +9,16 @@
#include "HAL/Types.h"
// clang-format off
/**
* The acceptable accelerometer ranges.
*/
enum HAL_AccelerometerRange : int32_t {
HAL_ENUM(HAL_AccelerometerRange) {
HAL_AccelerometerRange_k2G = 0,
HAL_AccelerometerRange_k4G = 1,
HAL_AccelerometerRange_k8G = 2,
};
// clang-format on
#ifdef __cplusplus
extern "C" {

View File

@@ -11,15 +11,17 @@
#include "HAL/Types.h"
// clang-format off
/**
* The type of analog trigger to trigger on.
*/
enum HAL_AnalogTriggerType : int32_t {
HAL_ENUM(HAL_AnalogTriggerType) {
HAL_Trigger_kInWindow = 0,
HAL_Trigger_kState = 1,
HAL_Trigger_kRisingPulse = 2,
HAL_Trigger_kFallingPulse = 3
};
// clang-format on
#ifdef __cplusplus
extern "C" {

View File

@@ -11,12 +11,13 @@
#include "HAL/Types.h"
// clang-format off
/**
* The CAN device type.
*
* Teams should use HAL_CAN_Dev_kMiscellaneous
*/
enum HAL_CANDeviceType : int32_t {
HAL_ENUM(HAL_CANDeviceType) {
HAL_CAN_Dev_kBroadcast = 0,
HAL_CAN_Dev_kRobotController = 1,
HAL_CAN_Dev_kMotorController = 2,
@@ -36,7 +37,7 @@ enum HAL_CANDeviceType : int32_t {
*
* Teams should use HAL_CAN_Man_kTeamUse.
*/
enum HAL_CANManufacturer : int32_t {
HAL_ENUM(HAL_CANManufacturer) {
HAL_CAN_Man_kBroadcast = 0,
HAL_CAN_Man_kNI = 1,
HAL_CAN_Man_kLM = 2,
@@ -45,6 +46,7 @@ enum HAL_CANManufacturer : int32_t {
HAL_CAN_Man_kMS = 7,
HAL_CAN_Man_kTeamUse = 8,
};
// clang-format on
#ifdef __cplusplus
extern "C" {

View File

@@ -12,15 +12,17 @@
#include "HAL/AnalogTrigger.h"
#include "HAL/Types.h"
// clang-format off
/**
* The counter mode.
*/
enum HAL_Counter_Mode : int32_t {
HAL_ENUM(HAL_Counter_Mode) {
HAL_Counter_kTwoPulse = 0,
HAL_Counter_kSemiperiod = 1,
HAL_Counter_kPulseLength = 2,
HAL_Counter_kExternalDirection = 3
};
// clang-format on
#ifdef __cplusplus
extern "C" {

View File

@@ -9,8 +9,6 @@
#include <stdint.h>
#include <cstddef>
#include "HAL/Types.h"
#define HAL_IO_CONFIG_DATA_SIZE 32
@@ -37,8 +35,10 @@ struct HAL_ControlWord {
uint32_t dsAttached : 1;
uint32_t control_reserved : 26;
};
typedef struct HAL_ControlWord HAL_ControlWord;
enum HAL_AllianceStationID : int32_t {
// clang-format off
HAL_ENUM(HAL_AllianceStationID) {
HAL_AllianceStationID_kRed1,
HAL_AllianceStationID_kRed2,
HAL_AllianceStationID_kRed3,
@@ -47,12 +47,13 @@ enum HAL_AllianceStationID : int32_t {
HAL_AllianceStationID_kBlue3,
};
enum HAL_MatchType {
HAL_ENUM(HAL_MatchType) {
HAL_kMatchType_none,
HAL_kMatchType_practice,
HAL_kMatchType_qualification,
HAL_kMatchType_elimination,
};
// clang-format on
/* The maximum number of axes that will be stored in a single HALJoystickAxes
* struct. This is used for allocating buffers, not bounds checking, since
@@ -65,16 +66,19 @@ struct HAL_JoystickAxes {
int16_t count;
float axes[HAL_kMaxJoystickAxes];
};
typedef struct HAL_JoystickAxes HAL_JoystickAxes;
struct HAL_JoystickPOVs {
int16_t count;
int16_t povs[HAL_kMaxJoystickPOVs];
};
typedef struct HAL_JoystickPOVs HAL_JoystickPOVs;
struct HAL_JoystickButtons {
uint32_t buttons;
uint8_t count;
};
typedef struct HAL_JoystickButtons HAL_JoystickButtons;
struct HAL_JoystickDescriptor {
uint8_t isXbox;
@@ -85,6 +89,7 @@ struct HAL_JoystickDescriptor {
uint8_t buttonCount;
uint8_t povCount;
};
typedef struct HAL_JoystickDescriptor HAL_JoystickDescriptor;
struct HAL_MatchInfo {
char* eventName;
@@ -93,6 +98,7 @@ struct HAL_MatchInfo {
uint8_t replayNumber;
char* gameSpecificMessage;
};
typedef struct HAL_MatchInfo HAL_MatchInfo;
#ifdef __cplusplus
extern "C" {
@@ -286,7 +292,7 @@ void HAL_ReleaseDSMutex(void);
*
* @return true if the control data has been updated since the last call
*/
bool HAL_IsNewControlData(void);
HAL_Bool HAL_IsNewControlData(void);
/**
* Waits for the newest DS packet to arrive. Note that this is a blocking call.

View File

@@ -12,10 +12,11 @@
#include "HAL/AnalogTrigger.h"
#include "HAL/Types.h"
// clang-format off
/**
* The type of index pulse for the encoder.
*/
enum HAL_EncoderIndexingType : int32_t {
HAL_ENUM(HAL_EncoderIndexingType) {
HAL_kResetWhileHigh,
HAL_kResetWhileLow,
HAL_kResetOnFallingEdge,
@@ -25,11 +26,12 @@ enum HAL_EncoderIndexingType : int32_t {
/**
* The encoding scaling of the encoder.
*/
enum HAL_EncoderEncodingType : int32_t {
HAL_ENUM(HAL_EncoderEncodingType) {
HAL_Encoder_k1X,
HAL_Encoder_k2X,
HAL_Encoder_k4X
};
// clang-format on
#ifdef __cplusplus
extern "C" {

View File

@@ -39,11 +39,16 @@
#endif // HAL_USE_LABVIEW
#include "HAL/Types.h"
#ifdef __cplusplus
#include "UsageReporting.h"
namespace HALUsageReporting = nUsageReporting;
#endif
enum HAL_RuntimeType : int32_t { HAL_Athena, HAL_Mock };
// clang-format off
HAL_ENUM(HAL_RuntimeType) { HAL_Athena, HAL_Mock };
// clang-format on
#ifdef __cplusplus
extern "C" {

View File

@@ -9,7 +9,11 @@
#include <stdint.h>
enum HAL_I2CPort : int32_t { HAL_I2C_kOnboard = 0, HAL_I2C_kMXP };
#include "HAL/Types.h"
// clang-format off
HAL_ENUM(HAL_I2CPort) { HAL_I2C_kOnboard = 0, HAL_I2C_kMXP };
// clang-format on
#ifdef __cplusplus
extern "C" {

View File

@@ -12,13 +12,15 @@
#include "HAL/AnalogTrigger.h"
#include "HAL/Types.h"
enum HAL_SPIPort : int32_t {
// clang-format off
HAL_ENUM(HAL_SPIPort) {
HAL_SPI_kOnboardCS0 = 0,
HAL_SPI_kOnboardCS1,
HAL_SPI_kOnboardCS2,
HAL_SPI_kOnboardCS3,
HAL_SPI_kMXP
};
// clang-format on
#ifdef __cplusplus
extern "C" {

View File

@@ -9,12 +9,16 @@
#include <stdint.h>
enum HAL_SerialPort : int32_t {
#include "HAL/Types.h"
// clang-format off
HAL_ENUM(HAL_SerialPort) {
HAL_SerialPort_Onboard = 0,
HAL_SerialPort_MXP = 1,
HAL_SerialPort_USB1 = 2,
HAL_SerialPort_USB2 = 3
};
// clang-format on
#ifdef __cplusplus
extern "C" {

View File

@@ -48,3 +48,11 @@ typedef HAL_Handle HAL_CANHandle;
typedef HAL_CANHandle HAL_PDPHandle;
typedef int32_t HAL_Bool;
#ifdef __cplusplus
#define HAL_ENUM(name) enum name : int32_t
#else
#define HAL_ENUM(name) \
typedef int32_t name; \
enum name
#endif

View File

@@ -204,7 +204,7 @@ static void InitLastCountKey(void) {
}
#endif
bool HAL_IsNewControlData(void) {
HAL_Bool HAL_IsNewControlData(void) {
#ifdef __APPLE__
pthread_once(&lastCountKeyOnce, InitLastCountKey);
int* lastCountPtr = static_cast<int*>(pthread_getspecific(lastCountKey));