From af295879fbc3d937ce30687b39b0479e41d4da9a Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Sun, 26 Sep 2021 10:38:17 -0700 Subject: [PATCH] [hal] Set error status for I2C port out of range (#3603) Closes #1369. --- hal/src/main/native/athena/I2C.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/hal/src/main/native/athena/I2C.cpp b/hal/src/main/native/athena/I2C.cpp index 6e7f89bead..93e280efc6 100644 --- a/hal/src/main/native/athena/I2C.cpp +++ b/hal/src/main/native/athena/I2C.cpp @@ -16,6 +16,7 @@ #include "DigitalInternal.h" #include "HALInitializer.h" +#include "HALInternal.h" #include "hal/DIO.h" #include "hal/HAL.h" @@ -46,7 +47,9 @@ void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) { } if (port < 0 || port > 1) { - // Set port out of range error here + *status = RESOURCE_OUT_OF_RANGE; + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for I2C", 0, 1, + port); return; } @@ -92,7 +95,9 @@ int32_t HAL_TransactionI2C(HAL_I2CPort port, int32_t deviceAddress, const uint8_t* dataToSend, int32_t sendSize, uint8_t* dataReceived, int32_t receiveSize) { if (port < 0 || port > 1) { - // Set port out of range error here + int32_t status = 0; + hal::SetLastErrorIndexOutOfRange(&status, "Invalid Index for I2C", 0, 1, + port); return -1; } @@ -122,7 +127,9 @@ int32_t HAL_TransactionI2C(HAL_I2CPort port, int32_t deviceAddress, int32_t HAL_WriteI2C(HAL_I2CPort port, int32_t deviceAddress, const uint8_t* dataToSend, int32_t sendSize) { if (port < 0 || port > 1) { - // Set port out of range error here + int32_t status = 0; + hal::SetLastErrorIndexOutOfRange(&status, "Invalid Index for I2C", 0, 1, + port); return -1; } @@ -148,7 +155,9 @@ int32_t HAL_WriteI2C(HAL_I2CPort port, int32_t deviceAddress, int32_t HAL_ReadI2C(HAL_I2CPort port, int32_t deviceAddress, uint8_t* buffer, int32_t count) { if (port < 0 || port > 1) { - // Set port out of range error here + int32_t status = 0; + hal::SetLastErrorIndexOutOfRange(&status, "Invalid Index for I2C", 0, 1, + port); return -1; } @@ -173,7 +182,9 @@ int32_t HAL_ReadI2C(HAL_I2CPort port, int32_t deviceAddress, uint8_t* buffer, void HAL_CloseI2C(HAL_I2CPort port) { if (port < 0 || port > 1) { - // Set port out of range error here + int32_t status = 0; + hal::SetLastErrorIndexOutOfRange(&status, "Invalid Index for I2C", 0, 1, + port); return; }