[hal] Set error status for I2C port out of range (#3603)

Closes #1369.
This commit is contained in:
Tyler Veness
2021-09-26 10:38:17 -07:00
committed by GitHub
parent 95dd20a151
commit af295879fb

View File

@@ -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;
}