@@ -237,7 +237,6 @@ __STATIC_INLINE void set_port_ch1(i2c_port_t sda, i2c_port_t scl);
237
237
__STATIC_INLINE void set_port_ch2 (i2c_port_t sda , i2c_port_t scl );
238
238
__STATIC_INLINE void set_port_ch3 (i2c_port_t sda , i2c_port_t scl );
239
239
__STATIC_INLINE void set_port_ch4 (i2c_port_t sda , i2c_port_t scl );
240
- __STATIC_INLINE uint32_t set_i2c (uint8_t ch , uint32_t * p_irqn );
241
240
__STATIC_INLINE void reset_asynch (_i2c_t * p_obj );
242
241
__STATIC_INLINE int32_t wait_status (_i2c_t * p_obj );
243
242
static void i2c_irq_handler (_i2c_t * p_obj );
@@ -574,7 +573,7 @@ __STATIC_INLINE void set_port_ch4(i2c_port_t sda, i2c_port_t scl)
574
573
* @note -
575
574
*/
576
575
/*--------------------------------------------------*/
577
- __STATIC_INLINE uint32_t set_i2c (uint8_t ch , uint32_t * p_irqn )
576
+ uint32_t set_i2c (uint8_t ch , uint32_t * p_irqn )
578
577
{
579
578
uint32_t instance = 0 ;
580
579
@@ -725,7 +724,7 @@ static void i2c_irq_handler(_i2c_t *p_obj)
725
724
}
726
725
else
727
726
{
728
- if (p_obj -> tx_buff .pos < p_obj -> tx_buff .length )
727
+ if (( p_obj -> tx_buff .pos < p_obj -> tx_buff .length ) || ( p_obj -> tx_buff . length == 0 ) )
729
728
{
730
729
if (p_obj -> tx_buff .pos == 0 )
731
730
{
@@ -740,16 +739,7 @@ static void i2c_irq_handler(_i2c_t *p_obj)
740
739
}
741
740
else if (p_obj -> rx_buff .length != 0 )
742
741
{
743
- if (p_obj -> tx_buff .pos == 0 )
744
- {
745
- p_obj -> info .asynch .event = (I2C_EVENT_ERROR | I2C_EVENT_ERROR_NO_SLAVE );
746
- p_obj -> info .asynch .state = I2C_TRANSFER_STATE_IDLE ;
747
- }
748
- else
749
- {
750
- p_obj -> info .asynch .event = (I2C_EVENT_ERROR | I2C_EVENT_TRANSFER_EARLY_NACK );
751
- p_obj -> info .asynch .state = I2C_TRANSFER_STATE_IDLE ;
752
- }
742
+ I2C_start_condition (& p_obj -> i2c , (p_obj -> info .asynch .address | 1U ));
753
743
}
754
744
else
755
745
{
@@ -1470,35 +1460,32 @@ TXZ_Result i2c_transfer_asynch_t(_i2c_t *p_obj, uint8_t *p_tx, int32_t tx_length
1470
1460
1471
1461
if (p_obj -> info .asynch .state == I2C_TRANSFER_STATE_IDLE )
1472
1462
{
1473
- if (((p_tx != I2C_NULL ) && (tx_length > 0 )) || ((p_rx != I2C_NULL ) && (rx_length > 0 )))
1463
+ reset_asynch (p_obj );
1464
+ I2C_clear_int_status (& p_obj -> i2c );
1465
+ clear_irq (p_obj -> info .irqn );
1466
+ p_obj -> info .asynch .address = (uint32_t )address ;
1467
+ p_obj -> info .asynch .event = 0 ;
1468
+ p_obj -> info .asynch .stop = (uint32_t )stop ;
1469
+ p_obj -> tx_buff .p_buffer = p_tx ;
1470
+ p_obj -> tx_buff .length = (uint32_t )tx_length ;
1471
+ p_obj -> tx_buff .pos = 0 ;
1472
+ p_obj -> rx_buff .p_buffer = p_rx ;
1473
+ p_obj -> rx_buff .length = (uint32_t )rx_length ;
1474
+ p_obj -> rx_buff .pos = 0 ;
1475
+ p_obj -> info .asynch .state = I2C_TRANSFER_STATE_BUSY ;
1476
+ I2C_enable_interrupt (& p_obj -> i2c );
1477
+ if ((tx_length == 0 ) && (rx_length != 0 ))
1474
1478
{
1475
- reset_asynch (p_obj );
1476
- I2C_clear_int_status (& p_obj -> i2c );
1477
- clear_irq (p_obj -> info .irqn );
1478
- p_obj -> info .asynch .address = (uint32_t )address ;
1479
- p_obj -> info .asynch .event = 0 ;
1480
- p_obj -> info .asynch .stop = (uint32_t )stop ;
1481
- p_obj -> tx_buff .p_buffer = p_tx ;
1482
- p_obj -> tx_buff .length = (uint32_t )tx_length ;
1483
- p_obj -> tx_buff .pos = 0 ;
1484
- p_obj -> rx_buff .p_buffer = p_rx ;
1485
- p_obj -> rx_buff .length = (uint32_t )rx_length ;
1486
- p_obj -> rx_buff .pos = 0 ;
1487
- p_obj -> info .asynch .state = I2C_TRANSFER_STATE_BUSY ;
1488
- I2C_enable_interrupt (& p_obj -> i2c );
1489
- if ((tx_length == 0 ) && (rx_length != 0 ))
1490
- {
1491
- I2C_start_condition (& p_obj -> i2c , (uint32_t )((uint32_t )address | 1U ));
1492
- }
1493
- else
1494
- {
1495
- I2C_start_condition (& p_obj -> i2c , (uint32_t )address );
1496
- }
1497
- p_obj -> info .bus_free = 0 ;
1498
- p_obj -> info .start = 0 ;
1499
- enable_irq (p_obj -> info .irqn );
1500
- result = TXZ_SUCCESS ;
1479
+ I2C_start_condition (& p_obj -> i2c , (uint32_t )((uint32_t )address | 1U ));
1501
1480
}
1481
+ else
1482
+ {
1483
+ I2C_start_condition (& p_obj -> i2c , (uint32_t )address );
1484
+ }
1485
+ p_obj -> info .bus_free = 0 ;
1486
+ p_obj -> info .start = 0 ;
1487
+ enable_irq (p_obj -> info .irqn );
1488
+ result = TXZ_SUCCESS ;
1502
1489
}
1503
1490
return (result );
1504
1491
}
0 commit comments