Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 5b06471

Browse files
committed
Fix compatibility with ESP32
1 parent ddc661f commit 5b06471

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

src/OPTIGATrustX.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ int32_t IFX_OPTIGA_TrustX::begin(TwoWire& CustomWire)
185185
CmdLib_GetMaxCommsBufferSize();
186186
ret = 0;
187187
active = true;
188-
}
188+
}else {
189+
Serial.print(ret, HEX);
190+
}
189191

190192
} while (0);
191193

src/optiga_trustx/CommandLib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ typedef enum eFragSeq_d
388388
eContinue = 0x02
389389
}eFragSeq_d;
390390

391-
static host_lib_status_t optiga_comms_status;
391+
volatile static host_lib_status_t optiga_comms_status;
392392

393393
//lint --e{715, 818} suppress "This is ignored as app_event_handler_t handler function prototype requires this argument.This will be used for object based implementation"
394394
static void optiga_comms_event_handler(void* upper_layer_ctx, host_lib_status_t event)

src/optiga_trustx/pal_i2c_arduino.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,24 @@ pal_status_t pal_i2c_write(pal_i2c_t* p_i2c_context,uint8_t* p_data , uint16_t l
177177

178178
i2c->beginTransmission(p_i2c_context->slave_address);
179179
i2c->write(p_data, length);
180-
ack = i2c->endTransmission(TRUE);
180+
ack = i2c->endTransmission(true);
181181

182182
if (ack == 0) {
183183
upper_layer_handler(p_i2c_context->upper_layer_ctx, PAL_I2C_EVENT_SUCCESS);
184184
status = PAL_STATUS_SUCCESS;
185+
/*
186+
Serial.print("-> ");
187+
for(int i = 0; i < length; i++)
188+
{
189+
Serial.print("0x");
190+
Serial.print(p_data[i], HEX);
191+
Serial.print(" ");
192+
}
193+
Serial.print("\n");
194+
*/
185195
} else {
186196
upper_layer_handler(p_i2c_context->upper_layer_ctx, PAL_I2C_EVENT_ERROR);
197+
//Serial.print("~->\n");
187198
}
188199
}while(0);
189200

@@ -229,7 +240,7 @@ pal_status_t pal_i2c_read(pal_i2c_t* p_i2c_context , uint8_t* p_data , uint16_t
229240
pal_status_t status = PAL_STATUS_FAILURE;
230241
TwoWire * i2c = NULL;
231242
uint16_t rx_len = 0;
232-
uint16_t bytes = 0;
243+
int bytes = length;
233244

234245
do {
235246
if (p_i2c_context == NULL)
@@ -241,10 +252,11 @@ pal_status_t pal_i2c_read(pal_i2c_t* p_i2c_context , uint8_t* p_data , uint16_t
241252
i2c = (TwoWire *)p_i2c_context->p_i2c_hw_config;
242253

243254
i2c->beginTransmission(p_i2c_context->slave_address);
244-
bytes = i2c->requestFrom((uint16_t)p_i2c_context->slave_address, length);
255+
bytes = i2c->requestFrom((int)p_i2c_context->slave_address, bytes);
245256

246257
if (bytes == 0)
247258
{
259+
//Serial.print("~<\n");
248260
upper_layer_handler(p_i2c_context->upper_layer_ctx, PAL_I2C_EVENT_ERROR);
249261
break;
250262
}
@@ -259,8 +271,19 @@ pal_status_t pal_i2c_read(pal_i2c_t* p_i2c_context , uint8_t* p_data , uint16_t
259271
{
260272
upper_layer_handler(p_i2c_context->upper_layer_ctx, PAL_I2C_EVENT_SUCCESS);
261273
status = PAL_STATUS_SUCCESS;
274+
/*
275+
Serial.print("<- ");
276+
for(int i = 0; i < rx_len; i++)
277+
{
278+
Serial.print("0x");
279+
Serial.print(p_data[i], HEX);
280+
Serial.print(" ");
281+
}
282+
Serial.print("\n");
283+
*/
262284
}
263285
else {
286+
//Serial.print("~<-\n");
264287
upper_layer_handler(p_i2c_context->upper_layer_ctx, PAL_I2C_EVENT_ERROR);
265288
}
266289

0 commit comments

Comments
 (0)