Skip to content

Commit ff5e239

Browse files
author
fpr
committed
Update I2C STM32F1 core and library to match with new HAL release 1.1.1
Signed-off-by: fpr <[email protected]>
1 parent fb0ae75 commit ff5e239

File tree

2 files changed

+0
-80
lines changed

2 files changed

+0
-80
lines changed

cores/arduino/stm32/twi.c

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
563505
void 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
/**

libraries/Wire/Wire.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,13 @@ void TwoWire::begin(uint8_t address)
8181

8282
i2c_custom_init(&_i2c,I2C_100KHz,I2C_ADDRESSINGMODE_7BIT,ownAddress,master);
8383

84-
#ifndef STM32F1xx
8584
if(master == false){
8685
// i2c_attachSlaveTxEvent(&_i2c, reinterpret_cast<void(*)(i2c_t*)>(&TwoWire::onRequestService));
8786
// i2c_attachSlaveRxEvent(&_i2c, reinterpret_cast<void(*)(i2c_t*, uint8_t*, int)>(&TwoWire::onReceiveService));
8887

8988
i2c_attachSlaveTxEvent(&_i2c, onRequestService);
9089
i2c_attachSlaveRxEvent(&_i2c, onReceiveService);
9190
}
92-
#endif
9391
}
9492

9593
void TwoWire::begin(int address)
@@ -111,8 +109,6 @@ uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddres
111109
{
112110
UNUSED(sendStop);
113111
if (master == true) {
114-
//NOTE: do not work with STM32F1xx boards (latest HAL version: 1.0.4)
115-
#ifndef STM32F1xx
116112
if (isize > 0) {
117113
// send internal address; this mode allows sending a repeated start to access
118114
// some devices' internal registers. This function is executed by the hardware
@@ -131,10 +127,6 @@ uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddres
131127
}
132128
endTransmission(false);
133129
}
134-
#else
135-
UNUSED(iaddress);
136-
UNUSED(isize);
137-
#endif /* !STM32F1xx */
138130

139131
// clamp to buffer length
140132
if(quantity > BUFFER_LENGTH){
@@ -377,22 +369,12 @@ void TwoWire::onRequestService(void)
377369
void TwoWire::onReceive( void (*function)(int) )
378370
{
379371
user_onReceive = function;
380-
381-
#ifdef STM32F1xx
382-
//Enable slave receive IT
383-
i2c_attachSlaveRxEvent(&_i2c, onReceiveService);
384-
#endif
385372
}
386373

387374
// sets function called on slave read
388375
void TwoWire::onRequest( void (*function)(void) )
389376
{
390377
user_onRequest = function;
391-
392-
#ifdef STM32F1xx
393-
//Enable slave transmit IT
394-
i2c_attachSlaveTxEvent(&_i2c, onRequestService);
395-
#endif
396378
}
397379

398380
// Preinstantiate Objects //////////////////////////////////////////////////////

0 commit comments

Comments
 (0)