aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--os/hal/platforms/STM32/i2c_lld.c15
-rw-r--r--os/hal/platforms/STM32/i2c_lld.h6
-rw-r--r--os/hal/src/i2c.c2
3 files changed, 14 insertions, 9 deletions
diff --git a/os/hal/platforms/STM32/i2c_lld.c b/os/hal/platforms/STM32/i2c_lld.c
index 729e14eb3..e59ef8d45 100644
--- a/os/hal/platforms/STM32/i2c_lld.c
+++ b/os/hal/platforms/STM32/i2c_lld.c
@@ -42,7 +42,8 @@ static uint32_t i2c_get_event(I2CDriver *i2cp){
}
static void i2c_serve_event_interrupt(I2CDriver *i2cp) {
- static __IO uint8_t *txBuffp, *rxBuffp, *datap;
+#define txBuffp (i2cp->txBuffp)
+#define rxBuffp (i2cp->rxBuffp)
I2C_TypeDef *dp = i2cp->id_i2c;
@@ -71,26 +72,24 @@ static void i2c_serve_event_interrupt(I2CDriver *i2cp) {
}
//Initialize the transmit buffer pointer
txBuffp = (uint8_t*)i2cp->id_slave_config->txbuf;
- datap = txBuffp;
- txBuffp++;
i2cp->txbytes--;
/* If no further data to be sent, disable the I2C ITBUF in order to not have a TxE interrupt */
if(i2cp->txbytes == 0) {
dp->CR2 &= (uint16_t)~I2C_CR2_ITBUFEN;
}
//EV8_1 write the first data
- dp->DR = *datap;
+ dp->DR = *txBuffp;
+ txBuffp++;
break;
case I2C_EV8_MASTER_BYTE_TRANSMITTING:
if(i2cp->txbytes > 0) {
- datap = txBuffp;
- txBuffp++;
i2cp->txbytes--;
if(i2cp->txbytes == 0) {
/* If no further data to be sent, disable the ITBUF in order to not have a TxE interrupt */
dp->CR2 &= (uint16_t)~I2C_CR2_ITBUFEN;
}
- dp->DR = *datap;
+ dp->DR = *txBuffp;
+ txBuffp++;
}
break;
case I2C_EV8_2_MASTER_BYTE_TRANSMITTED:
@@ -195,6 +194,8 @@ static void i2c_serve_event_interrupt(I2CDriver *i2cp) {
}
break;
}
+#undef rxBuffp
+#undef txBuffp
}
static void i2c_serve_error_interrupt(I2CDriver *i2cp) {
diff --git a/os/hal/platforms/STM32/i2c_lld.h b/os/hal/platforms/STM32/i2c_lld.h
index c3df51b07..66ee95dd9 100644
--- a/os/hal/platforms/STM32/i2c_lld.h
+++ b/os/hal/platforms/STM32/i2c_lld.h
@@ -163,8 +163,10 @@ struct I2CDriver{
*/
const I2CSlaveConfig *id_slave_config;
- size_t txbytes; /*!< Number of bytes to transmitted. */
- size_t rxbytes; /*!< Number of bytes to received. */
+ size_t txbytes; /*!< Number of bytes to be transmitted. */
+ size_t rxbytes; /*!< Number of bytes to be received. */
+ uint8_t *rxBuffp; /*!< Pointer to the current byte in slave rx buffer. */
+ uint8_t *txBuffp; /*!< Pointer to the current byte in slave tx buffer. */
i2cflags_t errors; /*!< Error flags.*/
i2cflags_t flags; /*!< State flags.*/
diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c
index 4e3f5e5b9..56e2f4484 100644
--- a/os/hal/src/i2c.c
+++ b/os/hal/src/i2c.c
@@ -69,6 +69,8 @@ void i2cObjectInit(I2CDriver *i2cp) {
i2cp->id_state = I2C_STOP;
i2cp->id_config = NULL;
+ i2cp->rxBuffp = NULL;
+ i2cp->txBuffp = NULL;
i2cp->id_slave_config = NULL;
#if I2C_USE_WAIT