Skip to content

Commit a2cd773

Browse files
authored
Various fixes/improvements in I2C slave (#2995)
***NO_CI***
1 parent f043b45 commit a2cd773

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

targets/ESP32/_nanoCLR/System.Device.I2c.Slave/sys_dev_i2c_slave_native_System_Device_I2c_I2cSlaveDevice.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ void UninitializePalI2cSlave(NF_PAL_I2CSLAVE *palI2cSlave)
4646
{
4747
if (palI2cSlave && palI2cSlave->I2cSlaveWorkerTask)
4848
{
49+
i2c_reset_tx_fifo(palI2cSlave->BusNum);
50+
i2c_reset_rx_fifo(palI2cSlave->BusNum);
51+
4952
// delete driver
5053
i2c_driver_delete(palI2cSlave->BusNum);
5154

@@ -87,6 +90,9 @@ void I2cSlaveTxWorkerTask(void *pvParameters)
8790
// get PAL UART from task parameters
8891
NF_PAL_I2CSLAVE *palI2c = (NF_PAL_I2CSLAVE *)pvParameters;
8992

93+
// reset TX fifo before the operation
94+
i2c_reset_tx_fifo(palI2c->BusNum);
95+
9096
// write data to I2C slave
9197
palI2c->BytesTransferred =
9298
i2c_slave_write_buffer(palI2c->BusNum, palI2c->Buffer, palI2c->RequestedBytes, palI2c->TimeoutTicks);
@@ -179,6 +185,10 @@ HRESULT Library_sys_dev_i2c_slave_native_System_Device_I2c_I2cSlaveDevice::Nativ
179185
palI2c->RequestedBytes = 0;
180186
palI2c->BytesTransferred = 0;
181187
palI2c->TimeoutTicks = 0;
188+
189+
// reset buffers, just in case
190+
i2c_reset_tx_fifo(bus);
191+
i2c_reset_rx_fifo(bus);
182192
}
183193

184194
NANOCLR_NOCLEANUP();
@@ -482,7 +492,7 @@ HRESULT Library_sys_dev_i2c_slave_native_System_Device_I2c_I2cSlaveDevice::
482492

483493
NANOCLR_CLEANUP();
484494

485-
if (FAILED(hr) && hr != CLR_E_THREAD_WAITING)
495+
if (hr != CLR_E_THREAD_WAITING)
486496
{
487497
if (palI2c != NULL && palI2c->Buffer != NULL)
488498
{

0 commit comments

Comments
 (0)