@@ -427,12 +427,7 @@ void i2c_attachSlaveRxEvent(i2c_t *obj, void (*function)(uint8_t*, int) )
427427 return ;
428428
429429 obj -> i2c_onSlaveReceive = function ;
430- #ifdef STM32F1xx
431- obj -> i2cTxRxBufferSize = 0 ;
432- HAL_I2C_Slave_Receive_IT (& (obj -> handle ), obj -> i2cTxRxBuffer , I2C_TXRX_BUFFER_SIZE );
433- #else
434430 HAL_I2C_EnableListen_IT (& (obj -> handle ));
435- #endif
436431}
437432
438433/** @brief sets function called before a slave write operation
@@ -446,60 +441,9 @@ void i2c_attachSlaveTxEvent(i2c_t *obj, void (*function)(void) )
446441 return ;
447442
448443 obj -> i2c_onSlaveTransmit = function ;
449- #ifdef STM32F1xx
450- /* Fill i2c buffer with data to transmit otherwize the buffer will be empty
451- when master will read the data for the first time */
452- obj -> i2cTxRxBufferSize = 0 ;
453- obj -> i2c_onSlaveTransmit ();
454- HAL_I2C_Slave_Transmit_IT (& (obj -> handle ), obj -> i2cTxRxBuffer , obj -> i2cTxRxBufferSize );
455- #else
456444 HAL_I2C_EnableListen_IT (& (obj -> handle ));
457- #endif
458- }
459-
460- #ifdef STM32F1xx
461-
462- /** @brief Slave Tx Transfer completed callback.
463- * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
464- * the configuration information for the specified I2C.
465- * @retval None
466- */
467- void HAL_I2C_SlaveTxCpltCallback (I2C_HandleTypeDef * hi2c )
468- {
469- i2c_t * obj = get_i2c_obj (hi2c );
470-
471- if (NULL != obj -> i2c_onSlaveTransmit ) {
472- // reset buffer size and fill buffer with new data before the next Tx
473- obj -> i2cTxRxBufferSize = 0 ;
474- obj -> i2c_onSlaveTransmit ();
475- HAL_I2C_Slave_Transmit_IT (hi2c , obj -> i2cTxRxBuffer , obj -> i2cTxRxBufferSize );
476- }
477- }
478-
479- /**
480- * @brief Slave Rx Transfer completed callback.
481- * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
482- * the configuration information for the specified I2C.
483- * @retval None
484- */
485- void HAL_I2C_SlaveRxCpltCallback (I2C_HandleTypeDef * hi2c )
486- {
487- uint8_t nbData = 0 ;
488- i2c_t * obj = get_i2c_obj (hi2c );
489-
490- if (NULL != obj -> i2c_onSlaveReceive ) {
491- nbData = I2C_TXRX_BUFFER_SIZE - obj -> handle .XferCount ;
492-
493- if (nbData != 0 ) {
494- obj -> i2c_onSlaveReceive (obj -> i2cTxRxBuffer , nbData );
495- }
496-
497- HAL_I2C_Slave_Receive_IT (hi2c , obj -> i2cTxRxBuffer , I2C_TXRX_BUFFER_SIZE );
498- }
499445}
500446
501- #else /* Others */
502-
503447/**
504448 * @brief Slave Address Match callback.
505449 * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
@@ -552,8 +496,6 @@ void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef *hi2c)
552496 HAL_I2C_EnableListen_IT (hi2c );
553497}
554498
555- #endif /* STM32F1xx */
556-
557499/**
558500 * @brief I2C error callback.
559501 * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
@@ -562,11 +504,7 @@ void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef *hi2c)
562504 */
563505void HAL_I2C_ErrorCallback (I2C_HandleTypeDef * hi2c )
564506{
565- #ifdef STM32F1xx
566- UNUSED (hi2c );
567- #else
568507 HAL_I2C_EnableListen_IT (hi2c );
569- #endif
570508}
571509
572510/**
0 commit comments