diff --git a/os/hal/include/i2c.h b/os/hal/include/i2c.h index b2df49899..066ee4a5f 100644 --- a/os/hal/include/i2c.h +++ b/os/hal/include/i2c.h @@ -146,8 +146,7 @@ struct I2CSlaveConfig{ i2cblock_t *rxbuf; /*!< Pointer to receive buffer. */ i2cblock_t *txbuf; /*!< Pointer to transmit buffer.*/ - /* Status Change @p EventSource.*/ - EventSource *sevent; + EventSource *sevent; /*!< Status Change @p EventSource.*/ }; diff --git a/os/hal/platforms/STM32/i2c_lld.c b/os/hal/platforms/STM32/i2c_lld.c index e59ef8d45..ba6225ba9 100644 --- a/os/hal/platforms/STM32/i2c_lld.c +++ b/os/hal/platforms/STM32/i2c_lld.c @@ -514,35 +514,35 @@ void i2c_lld_stop(I2CDriver *i2cp) { /** * @brief Transmits data ever the I2C bus as master. * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr Slave device address. Bits 0-9 contain slave - * device address. Bit 15 must be set to 1 if 10-bit - * addressing modes used. Otherwise keep it cleared. - * Bits 10-14 unused. - * @param[in] txbytes number of bytes to be transmited - * @param[in] rxbytes number of bytes to be received + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] slave_addr Slave device address. Bits 0-9 contain slave + * device address. Bit 15 must be set to 1 if 10-bit + * addressing modes used. Otherwise keep it cleared. + * Bits 10-14 unused. + * @param[in] txbytes number of bytes to be transmited + * @param[in] rxbytes number of bytes to be received * */ void i2c_lld_master_transmit(I2CDriver *i2cp, uint16_t slave_addr, size_t txbytes, size_t rxbytes) { - i2cp->slave_addr = slave_addr; - i2cp->txbytes = txbytes; - i2cp->rxbytes = rxbytes; + i2cp->slave_addr = slave_addr; + i2cp->txbytes = txbytes; + i2cp->rxbytes = rxbytes; // enable ERR, EVT & BUF ITs i2cp->id_i2c->CR2 |= (I2C_CR2_ITERREN|I2C_CR2_ITEVTEN|I2C_CR2_ITBUFEN); i2cp->id_i2c->CR1 &= ~I2C_CR1_POS; if(slave_addr & 0x8000){// 10-bit mode used - // add the two msb of 10-bit address to the header - i2cp->slave_addr1 = ((slave_addr >>7) & 0x0006); - // add the header bits with LSB = 0 -> write - i2cp->slave_addr1 |= 0xF0; - // the remaining 8 bit of 10-bit address - i2cp->slave_addr2 = slave_addr & 0x00FF; + // add the two msb of 10-bit address to the header + i2cp->slave_addr1 = ((slave_addr >>7) & 0x0006); + // add the header bits with LSB = 0 -> write + i2cp->slave_addr1 |= 0xF0; + // the remaining 8 bit of 10-bit address + i2cp->slave_addr2 = slave_addr & 0x00FF; } else{ - // LSB = 0 -> write - i2cp->slave_addr1 = ((slave_addr <<1) & 0x00FE); + // LSB = 0 -> write + i2cp->slave_addr1 = ((slave_addr <<1) & 0x00FE); } i2cp->flags = 0; @@ -563,13 +563,13 @@ void i2c_lld_master_transmit(I2CDriver *i2cp, uint16_t slave_addr, size_t txbyte /** * @brief Receives data from the I2C bus. * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr Slave device address. Bits 0-9 contain slave - * device address. Bit 15 must be set to 1 if 10-bit - * addressing modes used. Otherwise keep it cleared. - * Bits 10-14 unused. - * @param[in] txbytes number of bytes to be transmited - * @param[in] rxbytes number of bytes to be received + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] slave_addr Slave device address. Bits 0-9 contain slave + * device address. Bit 15 must be set to 1 if 10-bit + * addressing modes used. Otherwise keep it cleared. + * Bits 10-14 unused. + * @param[in] txbytes number of bytes to be transmited + * @param[in] rxbytes number of bytes to be received * */ void i2c_lld_master_receive(I2CDriver *i2cp, uint16_t slave_addr, size_t rxbytes){ @@ -582,12 +582,12 @@ void i2c_lld_master_receive(I2CDriver *i2cp, uint16_t slave_addr, size_t rxbytes i2cp->id_i2c->CR1 &= ~I2C_CR1_POS; if(slave_addr & 0x8000){// 10-bit mode used - // add the two msb of 10-bit address to the header - i2cp->slave_addr1 = ((slave_addr >>7) & 0x0006); - // add the header bits (the LSB -> 1 will be add to second - i2cp->slave_addr1 |= 0xF0; - // the remaining 8 bit of 10-bit address - i2cp->slave_addr2 = slave_addr & 0x00FF; + // add the two msb of 10-bit address to the header + i2cp->slave_addr1 = ((slave_addr >>7) & 0x0006); + // add the header bits (the LSB -> 1 will be add to second + i2cp->slave_addr1 |= 0xF0; + // the remaining 8 bit of 10-bit address + i2cp->slave_addr2 = slave_addr & 0x00FF; } else{ // LSB = 1 -> receive diff --git a/os/hal/platforms/STM32/i2c_lld.h b/os/hal/platforms/STM32/i2c_lld.h index 66ee95dd9..0ad317876 100644 --- a/os/hal/platforms/STM32/i2c_lld.h +++ b/os/hal/platforms/STM32/i2c_lld.h @@ -163,17 +163,17 @@ struct I2CDriver{ */ const I2CSlaveConfig *id_slave_config; - 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. */ + 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.*/ + i2cflags_t errors; /*!< Error flags.*/ + i2cflags_t flags; /*!< State flags.*/ - uint16_t slave_addr; /*!< Current slave address. */ - uint8_t slave_addr1; /*!< 7-bit address of the slave with r\w bit.*/ - uint8_t slave_addr2; /*!< Used in 10-bit address mode. */ + uint16_t slave_addr; /*!< Current slave address. */ + uint8_t slave_addr1;/*!< 7-bit address of the slave with r\w bit.*/ + uint8_t slave_addr2;/*!< Used in 10-bit address mode. */ /*********** End of the mandatory fields. **********************************/ diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 56e2f4484..75541494f 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -135,14 +135,14 @@ void i2cStop(I2CDriver *i2cp) { /** * @brief Sends data ever the I2C bus. * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] i2cscfg pointer to the @p I2C slave config - * @param[in] slave_addr Slave device address. Bits 0-9 contain slave - * device address. Bit 15 must be set to 1 if 10-bit - * addressing modes used. Otherwise keep it cleared. - * Bits 10-14 unused. - * @param[in] txbytes number of bytes to be transmited - * @param[in] rxbytes number of bytes to be received + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] i2cscfg pointer to the @p I2C slave config + * @param[in] slave_addr Slave device address. Bits 0-9 contain slave + * device address. Bit 15 must be set to 1 if 10-bit + * addressing modes used. Otherwise keep it cleared. + * Bits 10-14 unused. + * @param[in] txbytes number of bytes to be transmited + * @param[in] rxbytes number of bytes to be received */ void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, size_t txbytes, size_t rxbytes) { @@ -183,13 +183,13 @@ void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t /** * @brief Receives data from the I2C bus. * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] i2cscfg pointer to the @p I2C slave config - * @param[in] slave_addr Slave device address. Bits 0-9 contain slave - * device address. Bit 15 must be set to 1 if 10-bit - * addressing modes used. Otherwise keep it cleared. - * Bits 10-14 unused. - * @param[in] txbytes number of bytes to be transmited + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] i2cscfg pointer to the @p I2C slave config + * @param[in] slave_addr Slave device address. Bits 0-9 contain slave + * device address. Bit 15 must be set to 1 if 10-bit + * addressing modes used. Otherwise keep it cleared. + * Bits 10-14 unused. + * @param[in] txbytes number of bytes to be transmited */ void i2cMasterReceive(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, size_t rxbytes){ @@ -251,7 +251,7 @@ void i2cAddFlagsI(I2CDriver *i2cp, i2cflags_t mask) { chDbgCheck(i2cp != NULL, "i2cAddFlagsI"); i2cp->errors |= mask; - chEvtBroadcastI(&i2cp->id_slave_config->sevent); + chEvtBroadcastI(&i2cp->sevent); } /**