SPI and I2C simulator (#662)

* Creating SPI and I2C simulation abilities

* Update the callback helpers to support different function callback
types
* Create callback type that uses a buffer
* Created I2C/SPI data classes that manage the callbacks and don't do
much of anything else

* Ran format, cleaned up some issues
This commit is contained in:
PJ Reiniger
2017-10-19 02:01:58 -04:00
committed by Peter Johnson
parent be77f9cb26
commit 3c842d8234
13 changed files with 784 additions and 94 deletions

View File

@@ -7,20 +7,30 @@
#include "HAL/I2C.h"
#include "MockData/I2CDataInternal.h"
using namespace hal;
extern "C" {
void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {}
void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {
SimI2CData[port].SetInitialized(true);
}
int32_t HAL_TransactionI2C(HAL_I2CPort port, int32_t deviceAddress,
uint8_t* dataToSend, int32_t sendSize,
uint8_t* dataReceived, int32_t receiveSize) {
SimI2CData[port].Write(deviceAddress, dataToSend, sendSize);
SimI2CData[port].Read(deviceAddress, dataReceived, receiveSize);
return 0;
}
int32_t HAL_WriteI2C(HAL_I2CPort port, int32_t deviceAddress,
uint8_t* dataToSend, int32_t sendSize) {
SimI2CData[port].Write(deviceAddress, dataToSend, sendSize);
return 0;
}
int32_t HAL_ReadI2C(HAL_I2CPort port, int32_t deviceAddress, uint8_t* buffer,
int32_t count) {
SimI2CData[port].Read(deviceAddress, buffer, count);
return 0;
}
void HAL_CloseI2C(HAL_I2CPort port) {}
void HAL_CloseI2C(HAL_I2CPort port) { SimI2CData[port].SetInitialized(false); }
} // extern "C"