Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/release-publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ cd $RELEASE_DIRECTORY
ABSOLUTE_RELEASE_DIRECTORY=$(pwd)

# Make a working directory
TEMPORARY_DIRECTORY=${ABSOLUTE_RELEASE_DIRECTORY}/tmp
TEMPORARY_DIRECTORY=${ABSOLUTE_RELEASE_DIRECTORY}/.tmp
rm -rf $TEMPORARY_DIRECTORY
mkdir $TEMPORARY_DIRECTORY

Expand Down
67 changes: 46 additions & 21 deletions user/tests/integration/wiring/no_fixture_i2c/i2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,27 @@ hal_i2c_config_t acquireWire1Buffer()

test(I2C_00_hal_init_default_buffer)
{
hal_i2c_lock(HAL_I2C_INTERFACE1, nullptr);
SCOPE_GUARD({
hal_i2c_unlock(HAL_I2C_INTERFACE1, nullptr);
});
// Initializing the HAL with a null config is allowed and should allocate system defaults
assertEqual(hal_i2c_init(HAL_I2C_INTERFACE1, nullptr), (int)SYSTEM_ERROR_NONE);
if (!hal_i2c_is_enabled(HAL_I2C_INTERFACE1, nullptr)) {
assertEqual(hal_i2c_init(HAL_I2C_INTERFACE1, nullptr), (int)SYSTEM_ERROR_NONE);
} else {
assertEqual(hal_i2c_init(HAL_I2C_INTERFACE1, nullptr), (int)SYSTEM_ERROR_INVALID_ARGUMENT);
}

#if (PLATFORM_ID == PLATFORM_TRACKER) || (PLATFORM_ID == PLATFORM_TRACKERM)
// Tracker platforms should have buffers at least 512 bytes large, allocated by the system on startup
// IE trying to re-initialize the HAL with same size should fail
hal_i2c_config_t smallBuffers = allocateWireConfig(TRACKER_MINIMUM_BUFFER_SIZE);
hal_i2c_interface_t largeBufferInterface = (PLATFORM_ID == PLATFORM_TRACKER) ? HAL_I2C_INTERFACE2 : HAL_I2C_INTERFACE1;
hal_i2c_lock(largeBufferInterface, nullptr);
SCOPE_GUARD({
hal_i2c_unlock(largeBufferInterface, nullptr);
});

assertEqual(hal_i2c_init(largeBufferInterface, &smallBuffers), (int)SYSTEM_ERROR_NOT_ENOUGH_DATA);
freeWireBuffers(&smallBuffers);
#endif
Expand All @@ -73,6 +86,10 @@ test(I2C_00_hal_init_default_buffer)
test(I2C_01_test_acquire_wire_buffer) {
// Construct TwoWire object with user acquireWireBuffer() configuration structures, which should re-initialize the I2C HAL
Wire.begin();
hal_i2c_lock(HAL_I2C_INTERFACE1, nullptr);
SCOPE_GUARD({
hal_i2c_unlock(HAL_I2C_INTERFACE1, nullptr);
});

// Attempt to re-initialize the HAL with different sized buffers to implicitly determine if the user buffers were used by the HAL
// System Defaults < User values from acquireWireBuffer < Values used here to re-initialize the HAL
Expand All @@ -89,13 +106,15 @@ test(I2C_01_test_acquire_wire_buffer) {

// Reinitializing with a NULL config is not allowed
assertEqual(hal_i2c_init(HAL_I2C_INTERFACE1, nullptr), (int)SYSTEM_ERROR_INVALID_ARGUMENT);

hal_i2c_end(HAL_I2C_INTERFACE1, nullptr);
}

#if Wiring_Wire1
test(I2C_02_test_acquire_wire1_buffer) {
Wire1.begin();
hal_i2c_lock(HAL_I2C_INTERFACE2, nullptr);
SCOPE_GUARD({
hal_i2c_unlock(HAL_I2C_INTERFACE2, nullptr);
});
hal_i2c_config_t wire1SmallerBuffers = allocateWireConfig(WIRE1_ACQUIRE_BUFFER_SIZE);
assertEqual(hal_i2c_init(HAL_I2C_INTERFACE2, &wire1SmallerBuffers), (int)SYSTEM_ERROR_NOT_ENOUGH_DATA);
freeWireBuffers(&wire1SmallerBuffers);
Expand All @@ -105,18 +124,14 @@ test(I2C_02_test_acquire_wire1_buffer) {
freeWireBuffers(&wire1LargerBuffers);

assertEqual(hal_i2c_init(HAL_I2C_INTERFACE2, nullptr), (int)SYSTEM_ERROR_INVALID_ARGUMENT);

hal_i2c_end(HAL_I2C_INTERFACE2, nullptr);
}
#endif

#if HAL_PLATFORM_EXTERNAL_RTC
test(I2C_04_long_read_rtc)
test(I2C_03_long_read_rtc)
{
// Test > 32 byte reads by reading from AM18x5 RTC peripheral
Wire1.begin();

// Read full register range
// Read beyond full register range
const uint8_t REGISTER_RANGE = 64;
uint8_t longReadBuffer[REGISTER_RANGE] = {};
uint8_t readLength = REGISTER_RANGE;
Expand All @@ -131,6 +146,13 @@ test(I2C_04_long_read_rtc)
uint8_t rtcAddress = HAL_PLATFORM_EXTERNAL_RTC_I2C_ADDR;
uint8_t rtcRegister = 0x00;

hal_i2c_begin(wireInterface, I2C_MODE_MASTER, 0x00, NULL);

hal_i2c_lock(wireInterface, nullptr);
SCOPE_GUARD({
hal_i2c_unlock(wireInterface, nullptr);
});

hal_i2c_begin_transmission(wireInterface, rtcAddress, NULL);
hal_i2c_write(wireInterface, rtcRegister, NULL);
hal_i2c_end_transmission(wireInterface, true, NULL);
Expand All @@ -144,7 +166,7 @@ test(I2C_04_long_read_rtc)
longReadBuffer[i] = (uint8_t)hal_i2c_read(wireInterface, NULL);
}

// Log.info("I2C_04_long_read_rtc result %d\n", bytesAvailable);
// Log.info("I2C_03_long_read_rtc result %d\n", bytesAvailable);
// Log.dump(long_read_buffer, bytesAvailable);
// Log.info(" \n");

Expand All @@ -156,18 +178,13 @@ test(I2C_04_long_read_rtc)

#if (HAL_PLATFORM_POWER_MANAGEMENT_OPTIONAL == 0) && (HAL_PLATFORM_PMIC_BQ24195)

test(I2C_05_long_read_pmic)
test(I2C_04_long_read_pmic)
{
// Test > 32 byte reads by reading from BQ24195 PMIC peripheral.
// The device only has 10 registers to read, but should not NAK reads for more data
#if HAL_PLATFORM_PMIC_BQ24195_I2C == HAL_I2C_INTERFACE1
Wire.begin();
#elif HAL_PLATFORM_PMIC_BQ24195_I2C == HAL_I2C_INTERFACE2
Wire1.begin();
#endif

// Read full register range
const uint8_t REGISTER_RANGE = 64;
// Read beyond full register range
const uint8_t REGISTER_RANGE = 34;
uint8_t longReadBuffer[REGISTER_RANGE] = {};
uint8_t readLength = REGISTER_RANGE;

Expand All @@ -177,10 +194,18 @@ test(I2C_05_long_read_pmic)

hal_i2c_interface_t wireInterface = HAL_PLATFORM_PMIC_BQ24195_I2C;
uint8_t pmicAddress = PMIC_ADDRESS;
uint8_t rtcRegister = 0x00;
uint8_t pmicRegister = 0x00;

hal_i2c_lock(wireInterface, nullptr);
SCOPE_GUARD({
hal_i2c_unlock(wireInterface, nullptr);
});

hal_i2c_begin(wireInterface, I2C_MODE_MASTER, 0x00, NULL);
assertTrue(hal_i2c_is_enabled(wireInterface, nullptr));

hal_i2c_begin_transmission(wireInterface, pmicAddress, NULL);
hal_i2c_write(wireInterface, rtcRegister, NULL);
hal_i2c_write(wireInterface, pmicRegister, NULL);
hal_i2c_end_transmission(wireInterface, true, NULL);
auto config = WireTransmission(pmicAddress).quantity(readLength).stop(true).halConfig();
hal_i2c_request_ex(wireInterface, &config, nullptr);
Expand All @@ -192,7 +217,7 @@ test(I2C_05_long_read_pmic)
longReadBuffer[i] = (uint8_t)hal_i2c_read(wireInterface, NULL);
}

// Log.info("I2C_05_long_read_pmic result %ld\n", bytesAvailable);
// Log.info("I2C_04_long_read_pmic result %ld\n", bytesAvailable);
// Log.dump(longReadBuffer, bytesAvailable);
// Log.info(" \n");

Expand Down